Skip to content

Commit

Permalink
Merge pull request #1140 from xmok/check-ttl-before-add-or-update-dns
Browse files Browse the repository at this point in the history
make sure TTL is 0-86400 inclusive when add or update
  • Loading branch information
usmannasir authored Oct 26, 2023
2 parents b98f979 + 41392b6 commit 045cd65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
12 changes: 12 additions & 0 deletions dns/dnsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def addDNSRecord(self, userID = None, data = None):
recordType = data['recordType']
recordName = data['recordName']
ttl = int(data['ttl'])
if ttl < 0:
raise ValueError("TTL: The item must be greater than 0")
elif ttl > 86400:
raise ValueError("TTL: The item must be lesser than 86401")

admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnershipZone(zoneDomain, admin, currentACL) == 1:
Expand Down Expand Up @@ -444,6 +448,10 @@ def updateRecord(self, userID = None, data = None):

if data['ttlNow'] != None:
record.ttl = int(data['ttlNow'])
if record.ttl < 0:
raise ValueError("TTL: The item must be greater than 0")
elif record.ttl > 86400:
raise ValueError("TTL: The item must be lesser than 86401")

if data['priorityNow'] != None:
record.prio = int(data['priorityNow'])
Expand Down Expand Up @@ -826,6 +834,10 @@ def addDNSRecordCloudFlare(self, userID = None, data = None):
recordType = data['recordType']
recordName = data['recordName']
ttl = int(data['ttl'])
if ttl < 0:
raise ValueError("TTL: The item must be greater than 0")
elif ttl > 86400:
raise ValueError("TTL: The item must be lesser than 86401")

admin = Administrator.objects.get(pk=userID)
self.admin = admin
Expand Down
20 changes: 10 additions & 10 deletions dns/templates/dns/addDeleteDNSRecords.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 aRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -114,7 +114,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 aaaaRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -141,7 +141,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 cNameRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -167,7 +167,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-2 mxRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand Down Expand Up @@ -199,7 +199,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 spfRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -226,7 +226,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 txtRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -253,7 +253,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 soaRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -280,7 +280,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-3 nsRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand All @@ -307,7 +307,7 @@ <h3>{% trans "PowerDNS is disabled." %}
</div>

<div class="col-sm-2 srvRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>

Expand Down Expand Up @@ -337,7 +337,7 @@ <h3>{% trans "PowerDNS is disabled." %}
ng-model="recordName">
</div>
<div class="col-sm-3 caaRecord">
<input placeholder="{% trans 'TTL' %}" type="number" class="form-control"
<input placeholder="{% trans 'TTL' %}" type="number" min="0" max="86400" class="form-control"
ng-model="ttl" required>
</div>
<div class="col-sm-3 caaRecord">
Expand Down

0 comments on commit 045cd65

Please sign in to comment.