From 1071ae6ec5c68139d9e6ab4bc3d862c7bd0c302e Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Sat, 5 May 2018 00:10:05 +0500 Subject: [PATCH] Initial Domain Alias. --- dns/views.py | 5 +- static/images/icons/web-domain.png | Bin 0 -> 2832 bytes static/websiteFunctions/websiteFunctions.js | 1 + .../websiteFunctions/websiteFunctions.js | 17 +++ .../websiteFunctions/domainAlias.html | 141 ++++++++++++++++++ .../templates/websiteFunctions/website.html | 21 ++- websiteFunctions/urls.py | 5 + websiteFunctions/views.py | 50 ++++++- 8 files changed, 232 insertions(+), 8 deletions(-) create mode 100644 static/images/icons/web-domain.png create mode 100644 websiteFunctions/templates/websiteFunctions/domainAlias.html diff --git a/dns/views.py b/dns/views.py index 64286a937..1a32bacbb 100644 --- a/dns/views.py +++ b/dns/views.py @@ -295,8 +295,6 @@ def getCurrentRecordsForDomain(request): records = Records.objects.filter(domain_id=domain.id) - json_data = "[" - checker = 0 fetchType = "" @@ -319,6 +317,9 @@ def getCurrentRecordsForDomain(request): elif currentSelection == 'srvRecord': fetchType = 'SRV' + json_data = "[" + checker = 0 + for items in records: if items.type == fetchType: diff --git a/static/images/icons/web-domain.png b/static/images/icons/web-domain.png new file mode 100644 index 0000000000000000000000000000000000000000..37c5a02538bcc5578c133d04ebc43949b163cbc6 GIT binary patch literal 2832 zcmV+r3-9!aP)(rTcT&jIJBVBc^tFB1ZqAj#SeQcdote_QL0eP$i)Pf)c0s*lI zF>?10;7UvgbOoZ-?@VTr-?{hv&iUqde~)v{l?Z}>L?W>TqJcobp5Hbafb+msK@ffc za0QA0;c@y%B$6wDs|45s{4pRPfQ1Vd;O_4JVEjI0XlQ6afA_BVyGEnon{U41zn3oq zBuIc85{bkkAt3?Pea`E2ItmL5x!cmxYX-VFJLBo;Y4)1(@^S_a9B5K@`}S=b8yj(P zaWN?`E-uE-&JMX;F1Bej8dk-`0948VkN*Ap3o3VaNyi%#5)w#BN#SNg!>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ialw29i@#DwI$jAT?gCXZKGdX|Z zg19eu5OiwZYWJs(%aA^w1j~{3M{{2)|RIp~v8u8zgc39Hdmp6$-g0;0ZF)=ZG z^2sNprlyjbnkrrw5)wjia4=J+P2*qRe@|gyA#2yJ#m2^lL*IVeX`Qhk2;A+W&e<#h z?Zfchci%Ou#I{43yJ+;JNtBhBGh_O60HUL#X}o>gpzimz#f!=Yc#y2@Z1VE*@Eka>Q|F6gud`Xw>mX-|D%9M z>NMCJctU`s4X`w%K*i0QH+y7FeN>>)Xxitj3h~uhUteE-KW7du4{3s + +
+
+

{% trans "Domain Aliases" %}

+

{% trans "With Domain Aliases you can visit example.com using example.net and view the same content." %}

+
+ +
+
+

+ {% trans "Domain Aliases" %} +

+
+ + +
+ + +
+
+ +
+
+ + + + + + + + + + + + + + {% if noAlias == 1 %} + + {% for alias in aliases %} + + + + + + + + + {% endfor %} + {% else %} + + + + + + + + {% endif %} + + +
{% trans "Master Domain" %}{% trans "Alias" %}{% trans "File System Path" %}{% trans "SSL" %}{% trans "Delete" %}
{{ masterDomain }}{{ alias }}{{ path }} + +
{{ masterDomain }}{% trans 'Domain Aliases not found.' %}
+ + + +
+ + + +
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+
+ + +
+ +
+ +
+
+
+ +
+ +
+
+

{% trans "Operation failed. Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Alias successfully created." %}

+
+
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+
+ +
+ + + + + + + +
+
+
+ + +
+ + +{% endblock %} \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/website.html b/websiteFunctions/templates/websiteFunctions/website.html index f48ee3a47..a2bb97e91 100644 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -258,7 +258,7 @@
-
+
@@ -269,7 +269,7 @@
-
+
@@ -279,8 +279,18 @@
+
+ + + + + {% trans "Domain Alias" %} + -
+
+ + +
@@ -668,6 +678,7 @@
+

{% trans "Current rewrite rules in the file fetched." %}

@@ -806,7 +817,7 @@
-
+ -
+
diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index bb792c247..2bfc315e9 100644 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -67,4 +67,9 @@ urlpatterns = [ url(r'^addNewCron',views.addNewCron,name="addNewCron"), + ## Domain Alias + + url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/domainAlias$', views.domainAlias, name='domainAlias'), + + ] \ No newline at end of file diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index ed58ab6bb..7d6a1ac4b 100644 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -2611,4 +2611,52 @@ def addNewCron(request): except KeyError, msg: status = {"addNewCron": 0, "error": "Not Logged in"} final_json = json.dumps(status) - return HttpResponse(final_json) \ No newline at end of file + return HttpResponse(final_json) + + +def domainAlias(request,domain): + try: + val = request.session['userID'] + try: + admin = Administrator.objects.get(pk=request.session['userID']) + + confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + + + path = "/home/" + domain + "/public_html" + + + listenerTrueCheck = 0 + noAlias = 0 + aliases = [] + + for items in httpdConfig: + if items.find("listener Default{") > -1 or items.find("Default {") > -1: + listenerTrueCheck = 1 + continue + if listenerTrueCheck == 1: + if items.find(domain) > -1 and items.find('map') > -1: + data = filter(None, items.split(" ")) + if data[1] == domain: + length = len(data) + if length == 3: + break + else: + noAlias = 1 + for i in range(3, length): + aliases.append(data[i]) + + return render(request, 'websiteFunctions/domainAlias.html', { + 'masterDomain': domain, + 'aliases':aliases, + 'path':path, + 'noAlias':noAlias + }) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse(str(msg)) + except KeyError: + return redirect(loadLoginPage) \ No newline at end of file