diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index f87a70cbe..c73ceeaf2 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -410,6 +410,9 @@
  • {% trans "List Websites" %}
  • +
  • {% trans "List Child Domains" %} +
  • {% trans "Modify Website" %}
  • diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index c02d78505..4dc95911a 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -376,6 +376,156 @@ app.controller('listWebsites', function ($scope, $http) { }; +}); + +app.controller('listChildDomainsMain', function ($scope, $http) { + + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.getFurtherWebsitesFromDB = function () { + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + + dataurl = "/websites/fetchChildDomainsMain"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + if (response.data.listWebSiteStatus === 1) { + + $scope.WebSitesList = JSON.parse(response.data.data); + $scope.pagination = response.data.pagination; + $scope.clients = JSON.parse(response.data.data); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message; + + } + } + + function cantLoadInitialData(response) { + } + + + }; + $scope.getFurtherWebsitesFromDB(); + + $scope.cyberPanelLoading = true; + + $scope.issueSSL = function (virtualHost) { + $scope.cyberPanelLoading = false; + + var url = "/manageSSL/issueSSL"; + + + var data = { + virtualHost: virtualHost + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.SSL === 1) { + new PNotify({ + title: 'Success!', + text: 'SSL successfully issued.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + $scope.cyberPanelLoading = true; + + $scope.searchWebsites = function () { + + $scope.cyberPanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + patternAdded: $scope.patternAdded + }; + + dataurl = "/websites/searchWebsites"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + + function ListInitialData(response) { + $scope.cyberPanelLoading = true; + if (response.data.listWebSiteStatus === 1) { + + var finalData = JSON.parse(response.data.data); + $scope.WebSitesList = finalData; + $("#listFail").hide(); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + } + } + + function cantLoadInitialData(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Connect disrupted, refresh the page.', + type: 'error' + }); + } + + + }; + + }); /* Java script code to list accounts ends here */ diff --git a/websiteFunctions/templates/websiteFunctions/listChildDomains.html b/websiteFunctions/templates/websiteFunctions/listChildDomains.html new file mode 100755 index 000000000..06d738d57 --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/listChildDomains.html @@ -0,0 +1,151 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Child Domains - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + + +
    + +
    +

    {% trans "List Child Domains" %}

    +

    {% trans "On this page you can launch, list, modify and delete child domains from your server." %}

    +
    + +
    + +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    + +
    +
    + + +
    +
    + + +
    +
    + + Issue SSL +
    +
    +
    + +
    + + +
    +
    + + +
    + +
    + + Convert to Website +
    + +
    + + +
    + +
    +

    {% trans "Cannot list websites. Error message:" %} {$ errorMessage $}

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + +{% endblock %} diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index c59d536cb..7d9500173 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ url(r'^$', views.loadWebsitesHome, name='loadWebsitesHome'), url(r'^createWebsite$', views.createWebsite, name='createWebsite'), url(r'^listWebsites$', views.listWebsites, name='listWebsites'), + url(r'^listChildDomains$', views.listChildDomains, name='listChildDomains'), url(r'^modifyWebsite$', views.modifyWebsite, name='modifyWebsite'), url(r'^deleteWebsite$', views.deleteWebsite, name='deleteWebsite'), url(r'^siteState$', views.siteState, name='siteState'), @@ -18,6 +19,7 @@ urlpatterns = [ url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'), url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'), url(r'^fetchWebsitesList$', views.fetchWebsitesList, name='fetchWebsitesList'), + url(r'^fetchChildDomainsMain$', views.fetchChildDomainsMain, name='fetchChildDomainsMain'), url(r'^searchWebsites$', views.searchWebsites, name='searchWebsites'), url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'), url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 45a8068fc..d908519d6 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -61,6 +61,14 @@ def listWebsites(request): except KeyError: return redirect(loadLoginPage) +def listChildDomains(request): + try: + userID = request.session['userID'] + wm = WebsiteManager() + return wm.listChildDomains(request, userID) + except KeyError: + return redirect(loadLoginPage) + def submitWebsiteCreation(request): try: userID = request.session['userID'] @@ -133,6 +141,14 @@ def fetchWebsitesList(request): except KeyError: return redirect(loadLoginPage) +def fetchChildDomainsMain(request): + try: + userID = request.session['userID'] + wm = WebsiteManager() + return wm.fetchChildDomainsMain(userID, json.loads(request.body)) + except KeyError: + return redirect(loadLoginPage) + def submitWebsiteDeletion(request): try: userID = request.session['userID'] diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index fe6f08cc9..007502745 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -115,6 +115,15 @@ class WebsiteManager: except BaseException as msg: return HttpResponse(str(msg)) + def listChildDomains(self, request=None, userID=None, data=None): + try: + currentACL = ACLManager.loadedACL(userID) + pagination = self.websitePagination(currentACL, userID) + + return render(request, 'websiteFunctions/listChildDomains.html', {"pagination": pagination}) + except BaseException as msg: + return HttpResponse(str(msg)) + def listCron(self, request=None, userID=None, data=None): try: currentACL = ACLManager.loadedACL(userID) @@ -355,6 +364,32 @@ class WebsiteManager: json_data = json.dumps(dic) return HttpResponse(json_data) + def fetchChildDomainsMain(self, userID=None, data=None): + try: + currentACL = ACLManager.loadedACL(userID) + pageNumber = int(data['page']) + recordsToShow = int(data['recordsToShow']) + + endPageNumber, finalPageNumber = self.recordsPointer(pageNumber, recordsToShow) + websites = ACLManager.findWebsiteObjects(currentACL, userID) + childDomains = [] + + for web in websites: + for child in web.childdomains_set.all(): + childDomains.append(child) + + pagination = self.getPagination(len(childDomains), recordsToShow) + json_data = self.findChildsListJson(childDomains[finalPageNumber:endPageNumber]) + + final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data, + 'pagination': pagination} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except BaseException as msg: + dic = {'status': 1, 'listWebSiteStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(dic) + return HttpResponse(json_data) + def findWebsitesListJson(self, websites): json_data = "[" @@ -390,6 +425,35 @@ class WebsiteManager: return json_data + def findChildsListJson(self, childs): + + json_data = "[" + checker = 0 + + try: + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddress = ipData.split('\n', 1)[0] + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" + str(msg)) + ipAddress = "192.168.100.1" + + for items in childs: + + dic = {'domain': items.domain, 'masterDomain': items.master.domain, 'adminEmail': items.master.adminEmail, 'ipAddress': ipAddress, + 'admin': items.master.admin.userName, 'package': items.master.package.packageName, 'path': items.path} + + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + + json_data = json_data + ']' + + return json_data + def recordsPointer(self, page, toShow): finalPageNumber = ((page * toShow)) - toShow endPageNumber = finalPageNumber + toShow