Skip to content
Permalink
Browse files
  • Loading branch information
usmannasir committed Aug 15, 2020
1 parent 06deeea commit 74b8f8cae21a8479c6faa49f4db6207e1f25b22a
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 0 deletions.
@@ -767,6 +767,9 @@
<li><a href="{% url 'services' %}"
title="{% trans 'Services Status' %}"><span>{% trans "Services Status" %}</span></a>
</li>
<li><a href="{% url 'CyberPanelPort' %}"
title="{% trans 'Change CyberPanel Port' %}"><span>{% trans "Change Port" %}</span></a>
</li>
<li><a href="{% url 'packageManager' %}"
title="{% trans 'Package Manager' %}"><span>{% trans "Package Manager" %}</span></a>
</li>
@@ -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 @@ def run(self):
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 = []
@@ -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'
});
}


};

});
@@ -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 %}
<!-- Current language: {{ LANGUAGE_CODE }} -->


<div class="container">
<div id="page-title">
<h2>{% trans "CyberPanel Port" %}</h2>
<p>{% 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." %}</p>
</div>
</div>

<div class="row">
<div class="panel panel-body">
<div ng-controller="changePort" class="example-box-wrapper">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Change CyberPanel Port" %} <img ng-hide="cyberpanelLoading"
src="/static/images/loading.gif">
</h3>

<div class="content-box-wrapper">
<div class="row">
<div class="col-md-12">

<form action="/" class="form-horizontal bordered-row">

<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Port" %}</label>
<div class="col-sm-6" ng-init="port={{ port }}">
<input name="port" type="text" class="form-control" ng-model="port"
required>
</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="changeCPPort()"
class="btn btn-primary btn-lg">{% trans "Change" %}</button>

</div>
<div class="col-sm-4">


</div>
</div>

</form>
</div>


</div>
</div>
</div>
</div>
</div>
</div>


{% endblock %}
@@ -23,5 +23,7 @@
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'),

]
@@ -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)
@@ -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'
});
}


};

});

0 comments on commit 74b8f8c

Please sign in to comment.