diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 426a8ba27..0b59ee3f8 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -566,6 +566,23 @@ +
  • + + + {% trans "Manage Services" %} + + +
  • + + diff --git a/ftp/templates/ftp/createFTPAccount.html b/ftp/templates/ftp/createFTPAccount.html index 6d57abfcc..5bed384ee 100644 --- a/ftp/templates/ftp/createFTPAccount.html +++ b/ftp/templates/ftp/createFTPAccount.html @@ -20,6 +20,18 @@
    + {% if not status %} + +
    +

    {% trans "PureFTPD is disabled." %} +

    +
    + + + {% else %}
    @@ -96,6 +108,8 @@
    + {% endif %} + diff --git a/ftp/templates/ftp/deleteFTPAccount.html b/ftp/templates/ftp/deleteFTPAccount.html index f224339fd..15739df95 100644 --- a/ftp/templates/ftp/deleteFTPAccount.html +++ b/ftp/templates/ftp/deleteFTPAccount.html @@ -19,6 +19,18 @@
    + {% if not status %} + +
    +

    {% trans "PureFTPD is disabled." %} +

    +
    + + + {% else %}
    @@ -87,6 +99,8 @@
    + {% endif %} + diff --git a/ftp/templates/ftp/listFTPAccounts.html b/ftp/templates/ftp/listFTPAccounts.html index c1caf6062..3851eb9bb 100644 --- a/ftp/templates/ftp/listFTPAccounts.html +++ b/ftp/templates/ftp/listFTPAccounts.html @@ -20,6 +20,18 @@
    + {% if not status %} + +
    +

    {% trans "PureFTPD is disabled." %} +

    +
    + + + {% else %}
    @@ -110,6 +122,8 @@
    + {% endif %} + diff --git a/ftp/views.py b/ftp/views.py index 562a17fa0..f3b26c2af 100644 --- a/ftp/views.py +++ b/ftp/views.py @@ -13,6 +13,7 @@ import subprocess from plogical.virtualHostUtilities import virtualHostUtilities import shlex from plogical.ftpUtilities import FTPUtilities +import os # Create your views here. def loadFTPHome(request): @@ -29,6 +30,9 @@ def createFTPAccount(request): try: admin = Administrator.objects.get(pk=val) + if not os.path.exists('/home/cyberpanel/pureftpd'): + return render(request, "ftp/createFTPAccount.html", {"status": 0}) + if admin.type == 1: websites = Websites.objects.all() websitesName = [] @@ -55,7 +59,7 @@ def createFTPAccount(request): for items in websites: websitesName.append(items.domain) - return render(request, 'ftp/createFTPAccount.html', {'websiteList':websitesName,'admin':admin.userName}) + return render(request, 'ftp/createFTPAccount.html', {'websiteList':websitesName,'admin':admin.userName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) @@ -124,7 +128,10 @@ def deleteFTPAccount(request): try: val = request.session['userID'] try: - admin = Administrator.objects.get(pk=request.session['userID']) + admin = Administrator.objects.get(pk=val) + + if not os.path.exists('/home/cyberpanel/pureftpd'): + return render(request, "ftp/deleteFTPAccount.html", {"status": 0}) if admin.type == 1: websites = Websites.objects.all() @@ -152,7 +159,7 @@ def deleteFTPAccount(request): for items in websites: websitesName.append(items.domain) - return render(request, 'ftp/deleteFTPAccount.html', {'websiteList':websitesName}) + return render(request, 'ftp/deleteFTPAccount.html', {'websiteList':websitesName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) @@ -249,6 +256,9 @@ def listFTPAccounts(request): try: admin = Administrator.objects.get(pk=val) + if not os.path.exists('/home/cyberpanel/pureftpd'): + return render(request, "ftp/listFTPAccounts.html", {"status": 0}) + if admin.type == 1: websites = Websites.objects.all() websitesName = [] @@ -275,7 +285,7 @@ def listFTPAccounts(request): for items in websites: websitesName.append(items.domain) - return render(request, 'ftp/listFTPAccounts.html', {'websiteList':websitesName}) + return render(request, 'ftp/listFTPAccounts.html', {'websiteList':websitesName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) diff --git a/install/install.py b/install/install.py index 03044f7d6..c1fc8a9a6 100644 --- a/install/install.py +++ b/install/install.py @@ -687,8 +687,8 @@ class preFlightsChecks: count = 0 while (1): - command = "wget http://cyberpanel.net/CyberPanel.1.7.0.tar.gz" - #command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz" + #command = "wget http://cyberpanel.net/CyberPanel.1.7.0.tar.gz" + command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz" res = subprocess.call(shlex.split(command)) if res == 1: @@ -707,8 +707,8 @@ class preFlightsChecks: count = 0 while(1): - command = "tar zxf CyberPanel.1.7.0.tar.gz" - #command = "tar zxf CyberPanelTemp.tar.gz" + #command = "tar zxf CyberPanel.1.7.0.tar.gz" + command = "tar zxf CyberPanelTemp.tar.gz" res = subprocess.call(shlex.split(command)) @@ -2818,6 +2818,85 @@ milter_default_action = accept logging.InstallLog.writeToFile(str(msg) + " [setupVirtualEnv]") return 0 + @staticmethod + def enableDisableDNS(state): + try: + servicePath = '/home/cyberpanel/powerdns' + + if state == 'Off': + + command = 'sudo systemctl stop pdns' + subprocess.call(shlex.split(command)) + + command = 'sudo systemctl disable pdns' + subprocess.call(shlex.split(command)) + + try: + os.remove(servicePath) + except: + pass + + else: + writeToFile = open(servicePath, 'w+') + writeToFile.close() + + except OSError, msg: + logging.InstallLog.writeToFile(str(msg) + " [enableDisableDNS]") + return 0 + + @staticmethod + def enableDisableEmail(state): + try: + servicePath = '/home/cyberpanel/postfix' + + if state == 'Off': + + command = 'sudo systemctl stop postfix' + subprocess.call(shlex.split(command)) + + command = 'sudo systemctl disable postfix' + subprocess.call(shlex.split(command)) + + try: + os.remove(servicePath) + except: + pass + + else: + writeToFile = open(servicePath, 'w+') + writeToFile.close() + + except OSError, msg: + logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]") + return 0 + + @staticmethod + def enableDisableFTP(state): + try: + servicePath = '/home/cyberpanel/pureftpd' + + if state == 'Off': + + command = 'sudo systemctl stop pure-ftpd' + subprocess.call(shlex.split(command)) + + command = 'sudo systemctl disable pure-ftpd' + subprocess.call(shlex.split(command)) + + try: + os.remove(servicePath) + except: + pass + + else: + writeToFile = open(servicePath, 'w+') + writeToFile.close() + + except OSError, msg: + logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]") + return 0 + + @@ -2826,6 +2905,9 @@ def main(): parser = argparse.ArgumentParser(description='CyberPanel Installer') parser.add_argument('publicip', help='Please enter public IP for your VPS or dedicated server.') parser.add_argument('--mysql', help='Specify number of MySQL instances to be used.') + parser.add_argument('--postfix', help='Enable or disable Email Service.') + parser.add_argument('--powerdns', help='Enable or disable DNS Service.') + parser.add_argument('--ftp', help='Enable or disable ftp Service.') args = parser.parse_args() logging.InstallLog.writeToFile("Starting CyberPanel installation..") @@ -2906,7 +2988,24 @@ def main(): checks.modSecPreReqs() checks.setupVirtualEnv() checks.setupPHPAndComposer() - checks.installation_successfull() + + try: + postfix = args.postfix + checks.enableDisableEmail(postfix) + except: + checks.enableDisableEmail('On') + + try: + powerdns = args.powerdns + checks.enableDisableDNS(powerdns) + except: + checks.enableDisableDNS('On') + + try: + ftp = args.ftp + checks.enableDisableFTP(ftp) + except: + checks.enableDisableFTP('On') logging.InstallLog.writeToFile("CyberPanel installation successfully completed!") diff --git a/manageServices/static/manageServices/manageServices.js b/manageServices/static/manageServices/manageServices.js index b05f712d8..4cbee2c59 100644 --- a/manageServices/static/manageServices/manageServices.js +++ b/manageServices/static/manageServices/manageServices.js @@ -263,5 +263,135 @@ app.controller('postfix', function($scope, $http, $timeout, $window) { }); +/* Java script code */ + + +/* Java script code */ + +app.controller('pureFTPD', function($scope, $http, $timeout, $window) { + + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + var serviceStatus = false; + + + $('#serviceStatus').change(function() { + serviceStatus = $(this).prop('checked'); + }); + + fetchPDNSStatus('pureftpd'); + function fetchPDNSStatus(service){ + + $scope.serviceLoading = false; + + $('#serviceStatus').bootstrapToggle('off'); + + url = "/manageservices/fetchStatus"; + + var data = { + 'service' : service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + if (response.data.installCheck === 1) { + $('#serviceStatus').bootstrapToggle('on'); + } + + }else{ + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } + + + $scope.saveStatus = function (service) { + + $scope.serviceLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + + url = "/manageservices/saveStatus"; + + var data = { + status:serviceStatus, + service: service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; + + } + else{ + $scope.errorMessage = response.data.error_message; + + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + + }; + +}); /* Java script code */ \ No newline at end of file diff --git a/manageServices/templates/manageServices/managePostfix.html b/manageServices/templates/manageServices/managePostfix.html index 586cfa6da..21ca7f5cd 100644 --- a/manageServices/templates/manageServices/managePostfix.html +++ b/manageServices/templates/manageServices/managePostfix.html @@ -10,7 +10,7 @@
    -

    {% trans "Manage Email Server (Postfix)!" %} - {% trans "Emai Limits Docs" %}

    +

    {% trans "Manage Email Server (Postfix)!" %} - {% trans "Services Docs" %}

    {% trans "Enable or disable Email services. " %}

    diff --git a/manageServices/templates/manageServices/managePowerDNS.html b/manageServices/templates/manageServices/managePowerDNS.html index db53699b3..a1335ce3e 100644 --- a/manageServices/templates/manageServices/managePowerDNS.html +++ b/manageServices/templates/manageServices/managePowerDNS.html @@ -10,7 +10,7 @@
    -

    {% trans "Manage PowerDNS!" %} - {% trans "Emai Limits Docs" %}

    +

    {% trans "Manage PowerDNS!" %} - {% trans "Services Docs" %}

    {% trans "Enable or disable DNS services. " %}

    diff --git a/manageServices/templates/manageServices/managePureFtpd.html b/manageServices/templates/manageServices/managePureFtpd.html new file mode 100644 index 000000000..0fc9d1810 --- /dev/null +++ b/manageServices/templates/manageServices/managePureFtpd.html @@ -0,0 +1,91 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Manage FTP Server (Pure FTPD) - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + + +
    +
    +

    {% trans "Manage FTP Server (Pure FTPD)!" %} - {% trans "Services Docs" %}

    +

    {% trans "Enable or disable FTP services. " %}

    +
    + + {% if status %} + +
    +
    +

    + {% trans "Manage PureFTPD" %} +

    + +
    +
    + +
    +
    + +
    + +
    + +
    +
    + + +
    + +
    + + +
    +
    + + + +
    + +
    + +
    +

    {% trans "Error message: " %} {$ errorMessage $}

    +
    + +
    +

    {% trans "Changes successfully applied." %}

    +
    + +
    +

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

    +
    + +
    +
    + + +
    +
    + + + +
    +
    +
    +
    + + {% else %} + +
    +

    {% trans "Only administrator can manage services." %}

    +
    + + {% endif %} + + +
    + + +{% endblock %} \ No newline at end of file diff --git a/manageServices/urls.py b/manageServices/urls.py index 0f574ca4c..23f3a31bf 100644 --- a/manageServices/urls.py +++ b/manageServices/urls.py @@ -4,6 +4,9 @@ import views urlpatterns = [ url(r'^managePowerDNS$', views.managePowerDNS, name='managePowerDNS'), url(r'^managePostfix$', views.managePostfix, name='managePostfix'), + url(r'^managePureFtpd$', views.managePureFtpd, name='managePureFtpd'), + + url(r'^fetchStatus$', views.fetchStatus, name='fetchStatus'), url(r'^saveStatus$', views.saveStatus, name='saveStatus'), ] \ No newline at end of file diff --git a/manageServices/views.py b/manageServices/views.py index 1276dc274..cf0ccc5eb 100644 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -51,6 +51,23 @@ def managePostfix(request): except KeyError: return redirect(loadLoginPage) +def managePureFtpd(request): + try: + val = request.session['userID'] + try: + admin = Administrator.objects.get(pk=val) + + if admin.type == 1: + return render(request, 'manageServices/managePureFtpd.html', {"status": 1}) + else: + return render(request, 'manageServices/managePureFtpd.html', {"status": 0}) + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse("See CyberCP main log file.") + + except KeyError: + return redirect(loadLoginPage) def fetchStatus(request): try: @@ -89,7 +106,15 @@ def fetchStatus(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) - + elif service == 'pureftpd': + if os.path.exists('/home/cyberpanel/pureftpd'): + data_ret = {'status': 1, 'error_message': 'None', 'installCheck': 1} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 1, 'error_message': 'None', 'installCheck': 0} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) except BaseException,msg: data_ret = {'status': 0, 'error_message': str(msg)} @@ -129,9 +154,15 @@ def saveStatus(request): writeToFile.close() command = 'sudo systemctl start pdns' subprocess.call(shlex.split(command)) + + else: command = 'sudo systemctl stop pdns' subprocess.call(shlex.split(command)) + + command = 'sudo systemctl disable pdns' + subprocess.call(shlex.split(command)) + try: os.remove(servicePath) except: @@ -149,6 +180,30 @@ def saveStatus(request): else: command = 'sudo systemctl stop postfix' subprocess.call(shlex.split(command)) + + command = 'sudo systemctl disable postfix' + subprocess.call(shlex.split(command)) + + try: + os.remove(servicePath) + except: + pass + + elif service == 'pureftpd': + + servicePath = '/home/cyberpanel/pureftpd' + if status == True: + writeToFile = open(servicePath, 'w+') + writeToFile.close() + command = 'sudo systemctl start pure-ftpd' + subprocess.call(shlex.split(command)) + else: + command = 'sudo systemctl stop pure-ftpd' + subprocess.call(shlex.split(command)) + + command = 'sudo systemctl disable pure-ftpd' + subprocess.call(shlex.split(command)) + try: os.remove(servicePath) except: diff --git a/static/manageServices/manageServices.js b/static/manageServices/manageServices.js index b05f712d8..4cbee2c59 100644 --- a/static/manageServices/manageServices.js +++ b/static/manageServices/manageServices.js @@ -263,5 +263,135 @@ app.controller('postfix', function($scope, $http, $timeout, $window) { }); +/* Java script code */ + + +/* Java script code */ + +app.controller('pureFTPD', function($scope, $http, $timeout, $window) { + + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + var serviceStatus = false; + + + $('#serviceStatus').change(function() { + serviceStatus = $(this).prop('checked'); + }); + + fetchPDNSStatus('pureftpd'); + function fetchPDNSStatus(service){ + + $scope.serviceLoading = false; + + $('#serviceStatus').bootstrapToggle('off'); + + url = "/manageservices/fetchStatus"; + + var data = { + 'service' : service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + if (response.data.installCheck === 1) { + $('#serviceStatus').bootstrapToggle('on'); + } + + }else{ + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } + + + $scope.saveStatus = function (service) { + + $scope.serviceLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + + url = "/manageservices/saveStatus"; + + var data = { + status:serviceStatus, + service: service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; + + } + else{ + $scope.errorMessage = response.data.error_message; + + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + + }; + +}); /* Java script code */ \ No newline at end of file