This commit is contained in:
usmannasir
2024-01-09 19:35:50 +05:00
parent 932433b777
commit f200327f0a
4 changed files with 56 additions and 46 deletions

View File

@@ -564,10 +564,22 @@ app.controller('versionManagment', function ($scope, $http, $timeout) {
$scope.updateFinish = true;
$scope.couldNotConnect = true;
var data = {
branchSelect: document.getElementById("branchSelect").value,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
url = "/base/upgrade";
$http.get(url).then(ListInitialData, cantLoadInitialData);
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
@@ -620,6 +632,7 @@ app.controller('versionManagment', function ($scope, $http, $timeout) {
function ListInitialDatas(response) {
console.log(response.data.upgradeLog);
if (response.data.upgradeStatus === 1) {

View File

@@ -31,7 +31,7 @@
}
</style>
<div class="container">
<div class="container" ng-controller="versionManagment">
<div id="page-title">
<h2>{% trans "Version Management" %}</h2>
<p>{% trans "Here you can manage versions and check for updates to CyberPanel" %}</p>
@@ -47,13 +47,13 @@
<h3 class="title-hero">
CyberPanel
</h3>
<div ng-controller="versionManagment" class="example-box-wrapper">
<div class="example-box-wrapper">
<div class="form-group">
<label for="branchSelect">{% trans "Select Branch:" %}</label>
<select id="branchSelect" class="button-style"></select>
<select ng-model="branchSelect" id="branchSelect" class="button-style"></select>
</div>
<div class="form-group">
<button type="submit" onclick="upgradeCyberPanel()" class="button-style">{% trans "Upgrade CyberPanel to selected branch" %}</button>
<button type="submit" ng-click="upgrade()" class="button-style">{% trans "Upgrade CyberPanel to selected branch" %}</button>
<button type="submit" onclick="refreshPage()" class="button-style line-over">{% trans "Refresh page" %}</button>
</div>
@@ -135,14 +135,15 @@
var selectedBranch = document.getElementById("branchSelect").value;
// Use the shell script URL based on the selected branch
var shellScriptUrl = `https://raw.githubusercontent.com/usmannasir/cyberpanel/${selectedBranch}/cyberpanel_upgrade.sh`;
var shellScriptUrl = selectedBranch;
if (confirm("Are you sure you want to upgrade to the selected branch from the remote script?")) {
// Use fetch to trigger a server-side action (execute shell script)
fetch('/upgrade', {
fetch('/base/upgrade', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCookie('csrftoken')
},
body: JSON.stringify({
scriptUrl: shellScriptUrl,

View File

@@ -192,31 +192,22 @@ def versionManagment(request):
def upgrade(request):
try:
admin = request.session['userID']
currentACL = ACLManager.loadedACL(admin)
try:
os.remove('upgrade.py')
except:
data = json.loads(request.body)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson('fetchStatus', 0)
command = 'wget http://cyberpanel.net/upgrade.py'
cmd = shlex.split(command)
res = subprocess.call(cmd)
vers = version.objects.get(pk=1)
from plogical.upgrade import Upgrade
Upgrade.initiateUpgrade(vers.currentVersion, vers.build)
command = f'/usr/local/CyberPanel/bin/python /usr/local/CyberCP/plogical/upgrade.py "SoftUpgrade,{data["branchSelect"]}"'
ProcessUtilities.popenExecutioner(command)
adminData = {"upgrade": 1}
json_data = json.dumps(adminData)
return HttpResponse(json_data)
except KeyError:
adminData = {"upgrade": 1, "error_message": "Please login or refresh this page."}
json_data = json.dumps(adminData)
@@ -228,11 +219,12 @@ def upgradeStatus(request):
val = request.session['userID']
try:
if request.method == 'POST':
from plogical.upgrade import Upgrade
path = "/usr/local/lscp/logs/upgradeLog"
path = Upgrade.LogPathNew
try:
upgradeLog = open(path, "r").read()
upgradeLog = ProcessUtilities.outputExecutioner(f'cat {path}')
except:
final_json = json.dumps({'finished': 0, 'upgradeStatus': 1,
'error_message': "None",
@@ -241,15 +233,6 @@ def upgradeStatus(request):
if upgradeLog.find("Upgrade Completed") > -1:
vers = version.objects.get(pk=1)
getVersion = requests.get('https://cyberpanel.net/version.txt')
latest = getVersion.json()
vers.currentVersion = latest['version']
vers.build = latest['build']
vers.save()
os.remove(path)
final_json = json.dumps({'finished': 1, 'upgradeStatus': 1,
'error_message': "None",
'upgradeLog': upgradeLog})

View File

@@ -39,6 +39,8 @@ class Upgrade:
openEulerPath = '/etc/openEuler-release'
FromCloud = 0
SnappyVersion = '2.28.1'
LogPathNew = '/home/cyberpanel/upgrade_logs'
SoftUpgrade = 0
AdminACL = '{"adminStatus":1, "versionManagement": 1, "createNewUser": 1, "listUsers": 1, "deleteUser":1 , "resellerCenter": 1, ' \
'"changeUserACL": 1, "createWebsite": 1, "modifyWebsite": 1, "suspendWebsite": 1, "deleteWebsite": 1, ' \
@@ -113,6 +115,10 @@ class Upgrade:
print(("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "] #########################################################################\n"))
WriteToFile = open(Upgrade.LogPathNew, 'a')
WriteToFile.write(message)
WriteToFile.close()
if do_exit:
if Upgrade.FromCloud == 0:
os._exit(0)
@@ -1142,11 +1148,13 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
if Upgrade.FindOperatingSytem() == Ubuntu22:
### If ftp not installed then upgrade will fail so this command should not do exit
command = "sed -i 's/MYSQLCrypt md5/MYSQLCrypt crypt/g' /etc/pure-ftpd/db/mysql.conf"
Upgrade.executioner(command, command, 1)
Upgrade.executioner(command, command, 0)
command = "systemctl restart pure-ftpd-mysql.service"
Upgrade.executioner(command, command, 1)
Upgrade.executioner(command, command, 0)
try:
connection.close()
@@ -2145,7 +2153,7 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
def installLSCPD(branch):
try:
if branch.find('SoftUpgrade') == -1:
if Upgrade.SoftUpgrade == 0:
Upgrade.stdOut("Starting LSCPD installation..")
@@ -2472,7 +2480,7 @@ echo $oConfig->Save() ? 'Done' : 'Error';
Upgrade.stdOut("Permissions updated.")
except BaseException as msg:
Upgrade.stdOut(str(msg) + " [installLSCPD]")
Upgrade.stdOut(str(msg) + " [fixPermissions]")
@staticmethod
def AutoUpgradeAcme():
@@ -2906,6 +2914,10 @@ vmail
@staticmethod
def upgrade(branch):
if branch.find('SoftUpgrade') > -1:
Upgrade.SoftUpgrade = 1
branch = branch.split(',')[1]
# Upgrade.stdOut("Upgrades are currently disabled")
# return 0
@@ -2945,7 +2957,7 @@ vmail
### if this is a soft upgrade from front end do not stop lscpd, as lscpd is controlling the front end
if branch.find('SoftUpgrade') == -1:
if Upgrade.SoftUpgrade == 0:
command = "systemctl stop lscpd"
Upgrade.executioner(command, 'stop lscpd', 0)
@@ -3035,11 +3047,12 @@ vmail
command = 'cp /usr/local/lsws/lsphp80/bin/lsphp %s' % (phpPath)
Upgrade.executioner(command, 0)
try:
command = "systemctl start lscpd"
Upgrade.executioner(command, 'Start LSCPD', 0)
except:
pass
if Upgrade.SoftUpgrade == 0:
try:
command = "systemctl start lscpd"
Upgrade.executioner(command, 'Start LSCPD', 0)
except:
pass
command = 'csf -uf'
Upgrade.executioner(command, 'fix csf if there', 0)