Skip to content

Commit

Permalink
trying to fix #1139
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Jan 9, 2024
1 parent 5a55ce7 commit dc6a5af
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 46 deletions.
17 changes: 15 additions & 2 deletions baseTemplate/static/baseTemplate/custom-js/system-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -620,6 +632,7 @@ app.controller('versionManagment', function ($scope, $http, $timeout) {


function ListInitialDatas(response) {
console.log(response.data.upgradeLog);


if (response.data.upgradeStatus === 1) {
Expand Down
13 changes: 7 additions & 6 deletions baseTemplate/templates/baseTemplate/versionManagment.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -47,13 +47,13 @@ <h2>{% trans "Version Management" %}</h2>
<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>

Expand Down Expand Up @@ -135,14 +135,15 @@ <h3 class="title-hero">
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,
Expand Down
39 changes: 11 additions & 28 deletions baseTemplate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -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})
Expand Down
33 changes: 23 additions & 10 deletions plogical/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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..")

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dc6a5af

Please sign in to comment.