mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 22:06:05 +01:00
allow cp port change, ref: https://feedback.cyberpanel.net/b/requests/p/change-port-change-default-username-add-recaptcha-in-login-page-or-change-url-login-page
This commit is contained in:
@@ -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 @@ 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 = []
|
||||
|
||||
@@ -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({
|
||||
@@ -1010,3 +1014,55 @@ 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'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
66
serverStatus/templates/serverStatus/changeCyberPanelPort.html
Executable file
66
serverStatus/templates/serverStatus/changeCyberPanelPort.html
Executable file
@@ -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 @@ 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'),
|
||||
|
||||
]
|
||||
@@ -1097,3 +1097,82 @@ def lockStatus(request):
|
||||
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)
|
||||
return HttpResponse(json_data)
|
||||
@@ -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({
|
||||
@@ -1010,3 +1014,55 @@ 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'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user