Skip to content

Commit 74b8f8c

Browse files

File tree

7 files changed

+273
-0
lines changed

7 files changed

+273
-0
lines changed

baseTemplate/templates/baseTemplate/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@
767767
<li><a href="{% url 'services' %}"
768768
title="{% trans 'Services Status' %}"><span>{% trans "Services Status" %}</span></a>
769769
</li>
770+
<li><a href="{% url 'CyberPanelPort' %}"
771+
title="{% trans 'Change CyberPanel Port' %}"><span>{% trans "Change Port" %}</span></a>
772+
</li>
770773
<li><a href="{% url 'packageManager' %}"
771774
title="{% trans 'Package Manager' %}"><span>{% trans "Package Manager" %}</span></a>
772775
</li>

plogical/processUtilities.py

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ProcessUtilities(multi.Thread):
1919
ubuntu20 = 3
2020
server_address = '/usr/local/lscpd/admin/comm.sock'
2121
token = "unset"
22+
portPath = '/usr/local/lscp/conf/bind.conf'
2223

2324
def __init__(self, function, extraArgs):
2425
multi.Thread.__init__(self)
@@ -32,6 +33,16 @@ def run(self):
3233
except BaseException as msg:
3334
logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]')
3435

36+
@staticmethod
37+
def fetchCurrentPort():
38+
command = 'cat %s' % (ProcessUtilities.portPath)
39+
port = ProcessUtilities.outputExecutioner(command)
40+
41+
if port.find('*') > -1:
42+
return port.split(':')[1].rstrip('\n')
43+
else:
44+
return '8090'
45+
3546
@staticmethod
3647
def getLitespeedProcessNumber():
3748
finalListOfProcesses = []

serverStatus/static/serverStatus/serverStatus.js

+56
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
824824
});
825825
}
826826
}
827+
827828
function cantLoadInitialData(response) {
828829
$scope.cyberpanelLoading = true;
829830
new PNotify({
@@ -867,6 +868,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
867868
});
868869
}
869870
}
871+
870872
function cantLoadInitialData(response) {
871873
$scope.cyberpanelLoading = true;
872874
new PNotify({
@@ -909,6 +911,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
909911
});
910912
}
911913
}
914+
912915
function cantLoadInitialData(response) {
913916
$scope.cyberpanelLoading = true;
914917
new PNotify({
@@ -997,6 +1000,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
9971000
});
9981001
}
9991002
}
1003+
10001004
function cantLoadInitialData(response) {
10011005
$scope.cyberpanelLoading = true;
10021006
new PNotify({
@@ -1009,4 +1013,56 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
10091013

10101014
};
10111015

1016+
});
1017+
1018+
app.controller('changePort', function ($scope, $http, $timeout) {
1019+
1020+
$scope.cyberpanelLoading = true;
1021+
1022+
$scope.changeCPPort = function () {
1023+
$scope.cyberpanelLoading = false;
1024+
1025+
var config = {
1026+
headers: {
1027+
'X-CSRFToken': getCookie('csrftoken')
1028+
}
1029+
};
1030+
1031+
var data = {
1032+
port: $scope.port
1033+
};
1034+
1035+
dataurl = "/serverstatus/submitPortChange";
1036+
1037+
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
1038+
1039+
function ListInitialData(response) {
1040+
$scope.cyberpanelLoading = true;
1041+
if (response.data.status === 1) {
1042+
new PNotify({
1043+
title: 'Success!',
1044+
text: 'Port changed, open CyberPanel on new port.',
1045+
type: 'success'
1046+
});
1047+
} else {
1048+
new PNotify({
1049+
title: 'Error!',
1050+
text: response.data.error_message,
1051+
type: 'error'
1052+
});
1053+
}
1054+
}
1055+
1056+
function cantLoadInitialData(response) {
1057+
$scope.cyberpanelLoading = true;
1058+
new PNotify({
1059+
title: 'Success!',
1060+
text: 'Port changed, open CyberPanel on new port.',
1061+
type: 'success'
1062+
});
1063+
}
1064+
1065+
1066+
};
1067+
10121068
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{% extends "baseTemplate/index.html" %}
2+
{% load i18n %}
3+
{% block title %}{% trans "Change CyberPanel Access Port - CyberPanel" %}{% endblock %}
4+
{% block content %}
5+
6+
{% load static %}
7+
{% get_current_language as LANGUAGE_CODE %}
8+
<!-- Current language: {{ LANGUAGE_CODE }} -->
9+
10+
11+
<div class="container">
12+
<div id="page-title">
13+
<h2>{% trans "CyberPanel Port" %}</h2>
14+
<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>
15+
</div>
16+
</div>
17+
18+
<div class="row">
19+
<div class="panel panel-body">
20+
<div ng-controller="changePort" class="example-box-wrapper">
21+
<div class="panel-body">
22+
<h3 class="content-box-header">
23+
{% trans "Change CyberPanel Port" %} <img ng-hide="cyberpanelLoading"
24+
src="/static/images/loading.gif">
25+
</h3>
26+
27+
<div class="content-box-wrapper">
28+
<div class="row">
29+
<div class="col-md-12">
30+
31+
<form action="/" class="form-horizontal bordered-row">
32+
33+
<div class="form-group">
34+
<label class="col-sm-3 control-label">{% trans "Port" %}</label>
35+
<div class="col-sm-6" ng-init="port={{ port }}">
36+
<input name="port" type="text" class="form-control" ng-model="port"
37+
required>
38+
</div>
39+
</div>
40+
41+
<div class="form-group">
42+
<label class="col-sm-3 control-label"></label>
43+
<div class="col-sm-4">
44+
<button type="button" ng-click="changeCPPort()"
45+
class="btn btn-primary btn-lg">{% trans "Change" %}</button>
46+
47+
</div>
48+
<div class="col-sm-4">
49+
50+
51+
</div>
52+
</div>
53+
54+
</form>
55+
</div>
56+
57+
58+
</div>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
</div>
64+
65+
66+
{% endblock %}

serverStatus/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@
2323
url(r'^fetchPackageDetails$', views.fetchPackageDetails, name='fetchPackageDetails'),
2424
url(r'^updatePackage$', views.updatePackage, name='updatePackage'),
2525
url(r'^lockStatus$', views.lockStatus, name='lockStatus'),
26+
url(r'^CyberPanelPort$', views.CyberPanelPort, name='CyberPanelPort'),
27+
url(r'^submitPortChange$', views.submitPortChange, name='submitPortChange'),
2628

2729
]

serverStatus/views.py

+79
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,85 @@ def lockStatus(request):
10931093
json_data = json.dumps(data_ret)
10941094
return HttpResponse(json_data)
10951095

1096+
except BaseException as msg:
1097+
data_ret = {'status': 0, 'error_message': str(msg)}
1098+
json_data = json.dumps(data_ret)
1099+
return HttpResponse(json_data)
1100+
1101+
1102+
def CyberPanelPort(request):
1103+
try:
1104+
userID = request.session['userID']
1105+
1106+
currentACL = ACLManager.loadedACL(userID)
1107+
1108+
if currentACL['admin'] == 1:
1109+
pass
1110+
else:
1111+
return ACLManager.loadError()
1112+
1113+
port = ProcessUtilities.fetchCurrentPort()
1114+
1115+
return render(request, 'serverStatus/changeCyberPanelPort.html', {'port': port})
1116+
1117+
except KeyError as msg:
1118+
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[CyberPanelPort]")
1119+
return redirect(loadLoginPage)
1120+
1121+
1122+
def submitPortChange(request):
1123+
try:
1124+
1125+
userID = request.session['userID']
1126+
currentACL = ACLManager.loadedACL(userID)
1127+
1128+
if currentACL['admin'] == 1:
1129+
pass
1130+
else:
1131+
return ACLManager.loadError()
1132+
1133+
data = json.loads(request.body)
1134+
port = data['port']
1135+
1136+
## First Add Port to available firewall
1137+
from plogical.firewallUtilities import FirewallUtilities
1138+
from firewall.firewallManager import FirewallManager
1139+
from firewall.models import FirewallRules
1140+
1141+
csfPath = '/etc/csf'
1142+
1143+
if os.path.exists(csfPath):
1144+
fm = FirewallManager(request)
1145+
dataIn = {'protocol': 'TCP_IN', 'ports': port}
1146+
fm.modifyPorts(dataIn)
1147+
dataIn = {'protocol': 'TCP_OUT', 'ports': port}
1148+
fm.modifyPorts(dataIn)
1149+
else:
1150+
try:
1151+
updateFW = FirewallRules.objects.get(name="CPCustomPort")
1152+
FirewallUtilities.deleteRule("tcp", updateFW.port, "0.0.0.0/0")
1153+
updateFW.port = port
1154+
updateFW.save()
1155+
FirewallUtilities.addRule('tcp', port, "0.0.0.0/0")
1156+
except:
1157+
try:
1158+
newFireWallRule = FirewallRules(name="SSHCustom", port=port, proto="tcp")
1159+
newFireWallRule.save()
1160+
FirewallUtilities.addRule('tcp', port, "0.0.0.0/0")
1161+
command = 'firewall-cmd --permanent --remove-service=ssh'
1162+
ProcessUtilities.executioner(command)
1163+
except BaseException as msg:
1164+
logging.CyberCPLogFileWriter.writeToFile(str(msg))
1165+
1166+
command = "echo '*:%s' > /usr/local/lscp/conf/bind.conf" % (port)
1167+
ProcessUtilities.executioner(command)
1168+
1169+
ProcessUtilities.executioner('systemctl restart lscpd')
1170+
1171+
data_ret = {'status': 1,}
1172+
json_data = json.dumps(data_ret)
1173+
return HttpResponse(json_data)
1174+
10961175
except BaseException as msg:
10971176
data_ret = {'status': 0, 'error_message': str(msg)}
10981177
json_data = json.dumps(data_ret)

static/serverStatus/serverStatus.js

+56
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
824824
});
825825
}
826826
}
827+
827828
function cantLoadInitialData(response) {
828829
$scope.cyberpanelLoading = true;
829830
new PNotify({
@@ -867,6 +868,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
867868
});
868869
}
869870
}
871+
870872
function cantLoadInitialData(response) {
871873
$scope.cyberpanelLoading = true;
872874
new PNotify({
@@ -909,6 +911,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
909911
});
910912
}
911913
}
914+
912915
function cantLoadInitialData(response) {
913916
$scope.cyberpanelLoading = true;
914917
new PNotify({
@@ -997,6 +1000,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
9971000
});
9981001
}
9991002
}
1003+
10001004
function cantLoadInitialData(response) {
10011005
$scope.cyberpanelLoading = true;
10021006
new PNotify({
@@ -1009,4 +1013,56 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
10091013

10101014
};
10111015

1016+
});
1017+
1018+
app.controller('changePort', function ($scope, $http, $timeout) {
1019+
1020+
$scope.cyberpanelLoading = true;
1021+
1022+
$scope.changeCPPort = function () {
1023+
$scope.cyberpanelLoading = false;
1024+
1025+
var config = {
1026+
headers: {
1027+
'X-CSRFToken': getCookie('csrftoken')
1028+
}
1029+
};
1030+
1031+
var data = {
1032+
port: $scope.port
1033+
};
1034+
1035+
dataurl = "/serverstatus/submitPortChange";
1036+
1037+
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
1038+
1039+
function ListInitialData(response) {
1040+
$scope.cyberpanelLoading = true;
1041+
if (response.data.status === 1) {
1042+
new PNotify({
1043+
title: 'Success!',
1044+
text: 'Port changed, open CyberPanel on new port.',
1045+
type: 'success'
1046+
});
1047+
} else {
1048+
new PNotify({
1049+
title: 'Error!',
1050+
text: response.data.error_message,
1051+
type: 'error'
1052+
});
1053+
}
1054+
}
1055+
1056+
function cantLoadInitialData(response) {
1057+
$scope.cyberpanelLoading = true;
1058+
new PNotify({
1059+
title: 'Success!',
1060+
text: 'Port changed, open CyberPanel on new port.',
1061+
type: 'success'
1062+
});
1063+
}
1064+
1065+
1066+
};
1067+
10121068
});

0 commit comments

Comments
 (0)