diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index c7c46dd3a..ca13177fc 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -767,6 +767,9 @@
  • {% trans "Services Status" %}
  • +
  • {% trans "Change Port" %} +
  • {% trans "Package Manager" %}
  • diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 84cb278ed..3e5b512cb 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -19,6 +19,7 @@ class ProcessUtilities(multi.Thread): ubuntu20 = 3 server_address = '/usr/local/lscpd/admin/comm.sock' token = "unset" + portPath = '/usr/local/lscp/conf/bind.conf' def __init__(self, function, extraArgs): multi.Thread.__init__(self) @@ -32,6 +33,16 @@ class ProcessUtilities(multi.Thread): except BaseException as msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]') + @staticmethod + def fetchCurrentPort(): + command = 'cat %s' % (ProcessUtilities.portPath) + port = ProcessUtilities.outputExecutioner(command) + + if port.find('*') > -1: + return port.split(':')[1].rstrip('\n') + else: + return '8090' + @staticmethod def getLitespeedProcessNumber(): finalListOfProcesses = [] diff --git a/serverStatus/static/serverStatus/serverStatus.js b/serverStatus/static/serverStatus/serverStatus.js index 8a89159d6..61e42219d 100755 --- a/serverStatus/static/serverStatus/serverStatus.js +++ b/serverStatus/static/serverStatus/serverStatus.js @@ -824,6 +824,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -867,6 +868,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -909,6 +911,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -997,6 +1000,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -1009,4 +1013,56 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }; +}); + +app.controller('changePort', function ($scope, $http, $timeout) { + + $scope.cyberpanelLoading = true; + + $scope.changeCPPort = function () { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + port: $scope.port + }; + + dataurl = "/serverstatus/submitPortChange"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Port changed, open CyberPanel on new port.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Success!', + text: 'Port changed, open CyberPanel on new port.', + type: 'success' + }); + } + + + }; + }); \ No newline at end of file diff --git a/serverStatus/templates/serverStatus/changeCyberPanelPort.html b/serverStatus/templates/serverStatus/changeCyberPanelPort.html new file mode 100755 index 000000000..1a5e359d6 --- /dev/null +++ b/serverStatus/templates/serverStatus/changeCyberPanelPort.html @@ -0,0 +1,66 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Change CyberPanel Access Port - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + +
    +
    +

    {% trans "CyberPanel Port" %}

    +

    {% trans "On this page you can change CyberPanel port. Once port is change you will not be able to access this page, kindly open CyberPanel via new port." %}

    +
    +
    + +
    +
    +
    +
    +

    + {% trans "Change CyberPanel Port" %} +

    + +
    +
    +
    + +
    + +
    + +
    + +
    +
    + +
    + +
    + + +
    +
    + + +
    +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    + + +{% endblock %} diff --git a/serverStatus/urls.py b/serverStatus/urls.py index 86fd8638d..c3b6eadc5 100755 --- a/serverStatus/urls.py +++ b/serverStatus/urls.py @@ -23,5 +23,7 @@ urlpatterns = [ url(r'^fetchPackageDetails$', views.fetchPackageDetails, name='fetchPackageDetails'), url(r'^updatePackage$', views.updatePackage, name='updatePackage'), url(r'^lockStatus$', views.lockStatus, name='lockStatus'), + url(r'^CyberPanelPort$', views.CyberPanelPort, name='CyberPanelPort'), + url(r'^submitPortChange$', views.submitPortChange, name='submitPortChange'), ] \ No newline at end of file diff --git a/serverStatus/views.py b/serverStatus/views.py index 9d9a7f5a8..aa048059a 100755 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -1093,6 +1093,85 @@ def lockStatus(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + +def CyberPanelPort(request): + try: + userID = request.session['userID'] + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + port = ProcessUtilities.fetchCurrentPort() + + return render(request, 'serverStatus/changeCyberPanelPort.html', {'port': port}) + + except KeyError as msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[CyberPanelPort]") + return redirect(loadLoginPage) + + +def submitPortChange(request): + try: + + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + data = json.loads(request.body) + port = data['port'] + + ## First Add Port to available firewall + from plogical.firewallUtilities import FirewallUtilities + from firewall.firewallManager import FirewallManager + from firewall.models import FirewallRules + + csfPath = '/etc/csf' + + if os.path.exists(csfPath): + fm = FirewallManager(request) + dataIn = {'protocol': 'TCP_IN', 'ports': port} + fm.modifyPorts(dataIn) + dataIn = {'protocol': 'TCP_OUT', 'ports': port} + fm.modifyPorts(dataIn) + else: + try: + updateFW = FirewallRules.objects.get(name="CPCustomPort") + FirewallUtilities.deleteRule("tcp", updateFW.port, "0.0.0.0/0") + updateFW.port = port + updateFW.save() + FirewallUtilities.addRule('tcp', port, "0.0.0.0/0") + except: + try: + newFireWallRule = FirewallRules(name="SSHCustom", port=port, proto="tcp") + newFireWallRule.save() + FirewallUtilities.addRule('tcp', port, "0.0.0.0/0") + command = 'firewall-cmd --permanent --remove-service=ssh' + ProcessUtilities.executioner(command) + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + + command = "echo '*:%s' > /usr/local/lscp/conf/bind.conf" % (port) + ProcessUtilities.executioner(command) + + ProcessUtilities.executioner('systemctl restart lscpd') + + data_ret = {'status': 1,} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: data_ret = {'status': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) diff --git a/static/serverStatus/serverStatus.js b/static/serverStatus/serverStatus.js index 8a89159d6..61e42219d 100644 --- a/static/serverStatus/serverStatus.js +++ b/static/serverStatus/serverStatus.js @@ -824,6 +824,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -867,6 +868,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -909,6 +911,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -997,6 +1000,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }); } } + function cantLoadInitialData(response) { $scope.cyberpanelLoading = true; new PNotify({ @@ -1009,4 +1013,56 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }; +}); + +app.controller('changePort', function ($scope, $http, $timeout) { + + $scope.cyberpanelLoading = true; + + $scope.changeCPPort = function () { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + port: $scope.port + }; + + dataurl = "/serverstatus/submitPortChange"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Port changed, open CyberPanel on new port.', + type: 'success' + }); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Success!', + text: 'Port changed, open CyberPanel on new port.', + type: 'success' + }); + } + + + }; + }); \ No newline at end of file