From dc6a5af761d0f6c272a434c31300782985c0a861 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Tue, 9 Jan 2024 19:35:50 +0500 Subject: [PATCH] trying to fix https://github.com/usmannasir/cyberpanel/pull/1139 --- .../baseTemplate/custom-js/system-status.js | 17 +++++++- .../baseTemplate/versionManagment.html | 13 ++++--- baseTemplate/views.py | 39 ++++++------------- plogical/upgrade.py | 33 +++++++++++----- 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/baseTemplate/static/baseTemplate/custom-js/system-status.js b/baseTemplate/static/baseTemplate/custom-js/system-status.js index eef20641f..9fe052f0a 100644 --- a/baseTemplate/static/baseTemplate/custom-js/system-status.js +++ b/baseTemplate/static/baseTemplate/custom-js/system-status.js @@ -564,10 +564,22 @@ app.controller('versionManagment', function ($scope, $http, $timeout) { $scope.updateFinish = true; $scope.couldNotConnect = true; + var data = { + branchSelect: document.getElementById("branchSelect").value, - url = "/base/upgrade"; + }; - $http.get(url).then(ListInitialData, cantLoadInitialData); + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + + url = "/base/upgrade"; + $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) { diff --git a/baseTemplate/templates/baseTemplate/versionManagment.html b/baseTemplate/templates/baseTemplate/versionManagment.html index a7d15313f..0f5c07d08 100755 --- a/baseTemplate/templates/baseTemplate/versionManagment.html +++ b/baseTemplate/templates/baseTemplate/versionManagment.html @@ -31,7 +31,7 @@ } -
+

{% trans "Version Management" %}

{% trans "Here you can manage versions and check for updates to CyberPanel" %}

@@ -47,13 +47,13 @@

{% trans "Version Management" %}

CyberPanel

-
+
- +
- +
@@ -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, diff --git a/baseTemplate/views.py b/baseTemplate/views.py index 7cf6d0d98..ee32c75af 100755 --- a/baseTemplate/views.py +++ b/baseTemplate/views.py @@ -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: - pass - - command = 'wget http://cyberpanel.net/upgrade.py' - - cmd = shlex.split(command) - - res = subprocess.call(cmd) - - vers = version.objects.get(pk=1) + data = json.loads(request.body) - from plogical.upgrade import Upgrade + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson('fetchStatus', 0) - 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}) diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 05376d97e..36dcf9d1b 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -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 @@ def stdOut(message, do_exit=0): 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 @@ def applyLoginSystemMigrations(): 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 @@ def downloadAndUpgrade(versionNumbring, branch): def installLSCPD(branch): try: - if branch.find('SoftUpgrade') == -1: + if Upgrade.SoftUpgrade == 0: Upgrade.stdOut("Starting LSCPD installation..") @@ -2472,7 +2480,7 @@ def generate_pass(length=14): 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 @@ def UpdateConfigOfCustomACL(): @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 @@ def upgrade(branch): ### 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 @@ def upgrade(branch): 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)