Skip to content

Commit

Permalink
configure default nameservers
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Aug 22, 2019
1 parent 3c455ff commit e4f543d
Show file tree
Hide file tree
Showing 8 changed files with 591 additions and 513 deletions.
13 changes: 6 additions & 7 deletions baseTemplate/templates/baseTemplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
<link rel="stylesheet" type="text/css" href="https://www.jsdelivr.com/package/npm/fontawesome">



<script type="text/javascript" src="{% static 'baseTemplate/assets/js-core/jquery-core.min.js' %}"></script>
<script type="text/javascript">
$(window).load(function () {
Expand Down Expand Up @@ -319,7 +318,7 @@
</div>
</div>
<a class="header-btn" id="logout-btn" href="{% url 'logout' %}" title="{% trans 'Logout' %}">
<i class="glyph-icon icon-power-off"></i>
<i class="glyph-icon icon-power-off"></i>
</a>


Expand Down Expand Up @@ -374,7 +373,7 @@
title="{% trans 'Create New User' %}"><span>{% trans "Create New User" %}</span></a>
</li>
<li class="listUsers"><a href="{% url 'listUsers' %}"
title="{% trans 'List Users' %}"><span>{% trans "List Users" %}</span></a>
title="{% trans 'List Users' %}"><span>{% trans "List Users" %}</span></a>
</li>
<li><a href="{% url 'modifyUsers' %}"
title="{% trans 'Modify User' %}"><span>{% trans "Modify User" %}</span></a></li>
Expand Down Expand Up @@ -437,7 +436,7 @@
title="{% trans 'Create Package' %}"><span>{% trans "Create Package" %}</span></a>
</li>
<li class="listPackages"><a href="{% url 'listPackages' %}"
title="{% trans 'List Packages' %}"><span>{% trans "List Packages" %}</span></a>
title="{% trans 'List Packages' %}"><span>{% trans "List Packages" %}</span></a>
</li>
<li class="deletePackage"><a href="{% url 'deletePackage' %}"
title="{% trans 'Delete Package' %}"><span>{% trans "Delete Package" %}</span></a>
Expand Down Expand Up @@ -486,8 +485,8 @@
<li class="createNameServer"><a href="{% url 'createNameserver' %}"
title="{% trans 'Create Nameserver' %}"><span>{% trans "Create Nameserver" %}</span></a>
</li>
<!--<li class="createNameServer"><a href="{% url 'configureDefaultNameServers' %}"
title="{% trans 'Configure Default Nameservers' %}"><span>{% trans "CConfigure Default Nameservers" %}</span></a>-->
<li class="serverACL"><a href="{% url 'configureDefaultNameServers' %}"
title="{% trans 'Configure Default Nameservers' %}"><span>{% trans "Config Default Nameservers" %}</span></a>
</li>
<li class="createDNSZone"><a href="{% url 'createDNSZone' %}"
title="{% trans 'Create DNS Zone' %}"><span>{% trans "Create DNS Zone" %}</span></a>
Expand Down Expand Up @@ -515,7 +514,7 @@
title="{% trans 'Create Email Account' %}"><span>{% trans "Create Email" %}</span></a>
</li>
<li class="listEmails"><a href="{% url 'listEmails' %}"
title="{% trans 'List Emails' %}"><span>{% trans "List Emails" %}</span></a>
title="{% trans 'List Emails' %}"><span>{% trans "List Emails" %}</span></a>
</li>
<li class="deleteEmail"><a href="{% url 'deleteEmailAccount' %}"
title="{% trans 'Delete Email Account' %}"><span>{% trans "Delete Email" %}</span></a>
Expand Down
73 changes: 69 additions & 4 deletions dns/dnsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from manageServices.models import PDNSStatus

class DNSManager:
defaultNameServersPath = '/home/cyberpanel/defaultNameservers'

def loadDNSHome(self, request = None, userID = None):
try:
Expand Down Expand Up @@ -495,15 +496,79 @@ def configureDefaultNameServers(self, request=None, userID=None):
try:
currentACL = ACLManager.loadedACL(userID)

if ACLManager.currentContextPermission(currentACL, 'deleteZone') == 0:
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()

if not os.path.exists('/home/cyberpanel/powerdns'):
return render(request, 'dns/addDeleteDNSRecords.html', {"status": 0})

domainsList = ACLManager.findAllDomains(currentACL, userID)
data = {}
data['domainsList'] = ACLManager.findAllDomains(currentACL, userID)
data['status'] = 1

if os.path.exists(DNSManager.defaultNameServersPath):
nsData = open(DNSManager.defaultNameServersPath, 'r').readlines()
try:
data['firstNS'] = nsData[0]
except:
pass
try:
data['secondNS'] = nsData[1]
except:
pass
try:
data['thirdNS'] = nsData[2]
except:
pass
try:
data['forthNS'] = nsData[3]
except:
pass

return render(request, 'dns/configureDefaultNameServers.html', data)

return render(request, 'dns/configureDefaultNameServers.html', {"domainsList": domainsList, "status": 1})
except BaseException, msg:
return HttpResponse(str(msg))


def saveNSConfigurations(self, userID = None, data = None):
try:
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson()

nsContent = ''

try:
nsContent = '%s\n%s\n%s\n%s\n' % (data['firstNS'], data['secondNS'], data['thirdNS'], data['forthNS'])
except:
try:
nsContent = '%s\n%s\n%s\n' % (data['firstNS'], data['secondNS'], data['thirdNS'])
except:
try:
nsContent = '%s\n%s\n' % (data['firstNS'], data['secondNS'])
except:
try:
nsContent = '%s\n' % (data['firstNS'])
except:
pass


writeToFile = open(DNSManager.defaultNameServersPath, 'w')
writeToFile.write(nsContent.rstrip('\n'))
writeToFile.close()


final_dic = {'status': 1, 'error_message': "None"}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)

except BaseException, msg:
return HttpResponse(str(msg))
final_dic = {'status': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
Loading

0 comments on commit e4f543d

Please sign in to comment.