diff --git a/dns/static/dns/dns.js b/dns/static/dns/dns.js index cc19e3c84..3071300e1 100644 --- a/dns/static/dns/dns.js +++ b/dns/static/dns/dns.js @@ -47,7 +47,7 @@ app.controller('createNameserver', function($scope,$http) { function ListInitialDatas(response) { - if(response.data.NSCreation == 1){ + if(response.data.NSCreation === 1){ $scope.createNameserverLoading = true; $scope.nameserverCreationFailed = true; $scope.nameserverCreated = false; @@ -119,7 +119,7 @@ app.controller('createDNSZone', function($scope,$http) { function ListInitialDatas(response) { - if(response.data.zoneCreation == 1){ + if(response.data.zoneCreation === 1){ $scope.createDNSZoneLoading = true; $scope.dnsZoneCreationFailed = true; $scope.dnsZoneCreated = false; @@ -160,23 +160,46 @@ app.controller('createDNSZone', function($scope,$http) { app.controller('addModifyDNSRecords', function($scope,$http) { - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = true; - $scope.couldNotAddRecord = true; - $scope.recordValueDefault = false; - $scope.recordValueMX = true; - $scope.recordValueAAAA = true; - $scope.recordValueCNAME = true; - $scope.recordValueSPF = true; - $scope.recordValueTXT = true; + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = true; + $scope.couldNotAddRecord = true; + $scope.recordValueDefault = false; + + // Hide records boxes + $(".aaaaRecord").hide(); + $(".cNameRecord").hide(); + $(".mxRecord").hide(); + $(".txtRecord").hide(); + $(".spfRecord").hide(); + $(".nsRecord").hide(); + $(".soaRecord").hide(); + $(".srvRecord").hide(); + + + + + + var currentSelection = "aRecord"; + $("#"+currentSelection).addClass("active"); + + $scope.fetchRecordsTabs = function (recordType) { + $("#"+currentSelection).removeClass("active"); + $("."+currentSelection).hide(); + $scope.recordsLoading = false; + currentSelection = recordType; + $("#"+currentSelection).addClass("active"); + $("."+currentSelection).show(); + populateCurrentRecords(); + }; + $scope.fetchRecords = function(){ @@ -186,7 +209,7 @@ app.controller('addModifyDNSRecords', function($scope,$http) { }; - $scope.addDNSRecord = function(){ + $scope.addDNSRecord = function(type){ $scope.recordsLoading = false; @@ -194,56 +217,82 @@ app.controller('addModifyDNSRecords', function($scope,$http) { url = "/dns/addDNSRecord"; - var selectedZone = $scope.selectedZone; - var recordName = $scope.recordName; - var recordType = $scope.recordType; - - //specific values - - var recordContentMX = ""; - var recordContentA = ""; - var recordContentAAAA = ""; - var recordContentCNAME = ""; - var recordContentSPF = ""; - var recordContentTXT = ""; - - - // Record specific values - if($scope.recordType=="MX"){ - recordContentMX = $scope.recordContentMX; + var data = {}; + + if(type === "MX"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentMX = $scope.recordContentMX; + data.priority = $scope.priority; + data.ttl = $scope.ttl; + data.recordType = type; } - else if($scope.recordType=="A"){ - recordContentA = $scope.recordContentA; + else if(type === "A"){ + + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentA = $scope.recordContentA; + data.ttl = $scope.ttl; + data.recordType = type; + } - else if($scope.recordType=="AAAA"){ - recordContentAAAA = $scope.recordContentAAAA; + else if(type === "AAAA"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentAAAA = $scope.recordContentAAAA; + data.ttl = $scope.ttl; + data.recordType = type; } - else if($scope.recordType=="CNAME"){ - recordContentCNAME = $scope.recordContentCNAME; + else if(type === "CNAME"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentCNAME = $scope.recordContentCNAME; + data.ttl = $scope.ttl; + data.recordType = type; } - else if($scope.recordType=="SPF"){ - recordContentSPF = $scope.recordContentSPF; + else if(type === "SPF"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentSPF = $scope.recordContentSPF; + data.ttl = $scope.ttl; + data.recordType = type; } - else if($scope.recordType=="TXT"){ - recordContentTXT = $scope.recordContentTXT; + else if(type === "SOA"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.selectedZone; + data.recordContentSOA = $scope.recordContentSOA; + data.ttl = $scope.ttl; + data.recordType = type; + } + else if(type === "TXT"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentTXT = $scope.recordContentTXT; + data.ttl = $scope.ttl; + data.recordType = type; + } + else if(type === "NS"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.selectedZone; + data.recordContentNS = $scope.recordContentNS; + data.ttl = $scope.ttl; + data.recordType = type; + } + else if(type === "SRV"){ + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentSRV = $scope.recordContentSRV; + data.priority = $scope.priority; + data.ttl = $scope.ttl; + data.recordType = type; } - var data = { - selectedZone:selectedZone, - recordName:recordName, - recordType:recordType, - recordContentA:recordContentA, - recordContentMX:recordContentMX, - recordContentAAAA:recordContentAAAA, - recordContentCNAME:recordContentCNAME, - recordContentSPF:recordContentSPF, - recordContentTXT:recordContentTXT, - }; + var config = { headers : { @@ -258,7 +307,7 @@ app.controller('addModifyDNSRecords', function($scope,$http) { function ListInitialDatas(response) { - if(response.data.add_status == 1){ + if(response.data.add_status === 1){ populateCurrentRecords(); @@ -313,6 +362,7 @@ app.controller('addModifyDNSRecords', function($scope,$http) { var data = { selectedZone:selectedZone, + currentSelection:currentSelection }; var config = { @@ -327,9 +377,7 @@ app.controller('addModifyDNSRecords', function($scope,$http) { function ListInitialDatas(response) { - - - if(response.data.fetchStatus == 1){ + if(response.data.fetchStatus === 1){ $scope.records = JSON.parse(response.data.data); @@ -378,7 +426,6 @@ app.controller('addModifyDNSRecords', function($scope,$http) { }; - $scope.deleteRecord = function(id){ @@ -469,66 +516,6 @@ app.controller('addModifyDNSRecords', function($scope,$http) { - // MX Record Settings - - $scope.detectType = function(){ - - - if($scope.recordType=="MX") - { - $scope.recordValueDefault = true; - $scope.recordValueMX = false; - $scope.recordValueAAAA = true; - $scope.recordValueCNAME = true; - $scope.recordValueSPF = true; - $scope.recordValueTXT = true; - } - else if($scope.recordType=="A"){ - $scope.recordValueDefault = false; - $scope.recordValueMX = true; - $scope.recordValueAAAA = true; - $scope.recordValueCNAME = true; - $scope.recordValueSPF = true; - $scope.recordValueTXT = true; - } - else if($scope.recordType=="AAAA"){ - $scope.recordValueDefault = true; - $scope.recordValueMX = true; - $scope.recordValueAAAA = false; - $scope.recordValueCNAME = true; - $scope.recordValueSPF = true; - $scope.recordValueTXT = true; - } - else if($scope.recordType=="CNAME"){ - $scope.recordValueDefault = true; - $scope.recordValueMX = true; - $scope.recordValueAAAA = true; - $scope.recordValueCNAME = false; - $scope.recordValueSPF = true; - $scope.recordValueTXT = true; - } - else if($scope.recordType=="SPF"){ - $scope.recordValueDefault = true; - $scope.recordValueMX = true; - $scope.recordValueAAAA = true; - $scope.recordValueCNAME = true; - $scope.recordValueSPF = false; - $scope.recordValueTXT = true; - } - else if($scope.recordType=="TXT"){ - $scope.recordValueDefault = true; - $scope.recordValueMX = true; - $scope.recordValueAAAA = true; - $scope.recordValueCNAME = true; - $scope.recordValueSPF = true; - $scope.recordValueTXT = false; - } - - - }; - - - }); /* Java script code to delete DNS Zone */ @@ -549,7 +536,7 @@ app.controller('deleteDNSZone', function($scope,$http) { $scope.deleteZoneButton = false; $scope.deleteFailure = true; $scope.deleteSuccess = true; - } + }; $scope.deleteZoneFinal = function(){ diff --git a/dns/templates/dns/addDeleteDNSRecords.html b/dns/templates/dns/addDeleteDNSRecords.html index 67a84076d..8df918ef8 100644 --- a/dns/templates/dns/addDeleteDNSRecords.html +++ b/dns/templates/dns/addDeleteDNSRecords.html @@ -38,78 +38,243 @@
-
- -
+
+ +
-
- -
+ - +
+ +
-
- -
+
+ +
- - - - - -
- -
- - - - - - -
- -
- - - - - - -
- -
- - - - - -
- -
- - - - - -
- -
- - +
+ +
-
- -
+
+ +
+ + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + + +
+ +
+ + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + +
+ +
+ + + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
+ + + +
@@ -129,6 +294,7 @@ {% trans "ID" %} {% trans "Type" %} {% trans "Name" %} + {% trans "TTL" %} {% trans "Value" %} {% trans "Priority" %} {% trans "Delete" %} @@ -139,6 +305,7 @@ + diff --git a/dns/views.py b/dns/views.py index c5be1afc6..64286a937 100644 --- a/dns/views.py +++ b/dns/views.py @@ -289,6 +289,7 @@ def getCurrentRecordsForDomain(request): data = json.loads(request.body) zoneDomain = data['selectedZone'] + currentSelection = data['currentSelection'] domain = Domains.objects.get(name=zoneDomain) @@ -297,21 +298,46 @@ def getCurrentRecordsForDomain(request): json_data = "[" checker = 0 - for items in records: - if items.type == "SOA": - continue - dic = {'id': items.id, - 'type': items.type, - 'name': items.name, - 'content': items.content, - 'priority': items.prio - } + fetchType = "" - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 + if currentSelection == 'aRecord': + fetchType = 'A' + elif currentSelection == 'aaaaRecord': + fetchType = 'AAAA' + elif currentSelection == 'cNameRecord': + fetchType = 'CNAME' + elif currentSelection == 'mxRecord': + fetchType = 'MX' + elif currentSelection == 'txtRecord': + fetchType = 'TXT' + elif currentSelection == 'spfRecord': + fetchType = 'SPF' + elif currentSelection == 'nsRecord': + fetchType = 'NS' + elif currentSelection == 'soaRecord': + fetchType = 'SOA' + elif currentSelection == 'srvRecord': + fetchType = 'SRV' + + + for items in records: + if items.type == fetchType: + dic = {'id': items.id, + 'type': items.type, + 'name': items.name, + 'content': items.content, + 'priority': items.prio, + 'ttl':items.ttl + } + + + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) else: - json_data = json_data + ',' + json.dumps(dic) + continue json_data = json_data + ']' @@ -339,6 +365,7 @@ def addDNSRecord(request): zoneDomain = data['selectedZone'] recordType = data['recordType'] recordName = data['recordName'] + ttl = int(data['ttl']) #admin = Administrator.objects.get(pk=val) @@ -363,7 +390,7 @@ def addDNSRecord(request): name=value, type="A", content=recordContentA, - ttl=3600, + ttl=ttl, prio=0, disabled=0, auth=1 ) @@ -379,13 +406,14 @@ def addDNSRecord(request): value = recordName + "." + zoneDomain recordContentMX = data['recordContentMX'] + priority = data['priority'] record = Records(domainOwner=zone, domain_id=zone.id, - name=zoneDomain, + name=value, type="MX", - content=value, - ttl=3600, - prio=recordContentMX, + content=recordContentMX, + ttl=ttl, + prio=priority, disabled=0, auth=1) record.save() @@ -407,12 +435,11 @@ def addDNSRecord(request): name=value, type="AAAA", content=recordContentAAAA, - ttl=3600, + ttl=ttl, prio=0, disabled=0, auth=1 ) record.save() - elif recordType == "CNAME": if recordName == "@": @@ -429,13 +456,11 @@ def addDNSRecord(request): name=value, type="CNAME", content=recordContentCNAME, - ttl=3600, + ttl=ttl, prio=0, disabled=0, auth=1 ) record.save() - - elif recordType == "SPF": if recordName == "@": @@ -452,13 +477,11 @@ def addDNSRecord(request): name=value, type="SPF", content=recordContentSPF, - ttl=3600, + ttl=ttl, prio=0, disabled=0, auth=1 ) record.save() - - elif recordType == "TXT": if recordName == "@": @@ -475,11 +498,70 @@ def addDNSRecord(request): name=value, type="TXT", content=recordContentTXT, - ttl=3600, + ttl=ttl, prio=0, disabled=0, auth=1 ) record.save() + elif recordType == "SOA": + + recordContentSOA = data['recordContentSOA'] + + records = Records(domainOwner=zone, + domain_id=zone.id, + name=zoneDomain, + type="SOA", + content=recordContentSOA, + ttl=ttl, + prio=0, + disabled=0, + auth=1) + records.save() + elif recordType == "NS": + + recordContentNS = data['recordContentNS'] + + if recordContentNS == "@": + recordContentNS = "ns1." + zoneDomain + ## re.match + elif match(r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?', recordContentNS, M | I): + recordContentNS = recordContentNS + else: + recordContentNS = recordContentNS + "." + zoneDomain + + record = Records(domainOwner=zone, + domain_id=zone.id, + name=zoneDomain, + type="NS", + content=recordContentNS, + ttl=ttl, + prio=0, + disabled=0, + auth=1) + record.save() + elif recordType == "SRV": + + if recordName == "@": + value = zoneDomain + ## re.match + elif match(r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?', recordName, M | I): + value = recordName + else: + value = recordName + "." + zoneDomain + + recordContentSRV = data['recordContentSRV'] + priority = data['priority'] + + record = Records(domainOwner=zone, + domain_id=zone.id, + name=value, + type="SRV", + content=recordContentSRV, + ttl=ttl, + prio=priority, + disabled=0, + auth=1) + record.save() final_dic = {'add_status': 1, 'error_message': "None"} @@ -487,7 +569,6 @@ def addDNSRecord(request): return HttpResponse(final_json) - except BaseException,msg: final_dic = {'add_status': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) diff --git a/install/FileManager/.idea/workspace.xml b/install/FileManager/.idea/workspace.xml index 439ec97b1..22a227462 100644 --- a/install/FileManager/.idea/workspace.xml +++ b/install/FileManager/.idea/workspace.xml @@ -14,8 +14,8 @@ - - + + @@ -37,7 +37,7 @@ - + @@ -164,25 +164,26 @@ + - - + - + - + @@ -205,6 +206,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -258,24 +288,17 @@ - + - - - - - - - - + - - + + diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index 26fcbaafc..7a52a9fe1 100644 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -12,14 +12,22 @@ from backupUtilities import backupUtilities class backupSchedule: + @staticmethod + def remoteBackupLogging(fileName, message): + try: + file = open(fileName,'a') + file.writelines("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] "+ message + "\n") + file.close() + except IOError,msg: + return "Can not write to error file." + @staticmethod - def createBackup(virtualHost, ipAddress,writeToFile,port): + def createBackup(virtualHost, ipAddress, backupLogPath , port): try: - writeToFile.writelines("["+time.strftime("%I-%M-%S-%a-%b-%Y")+"]"+" Preparing to create backup for: "+virtualHost+"\n") - writeToFile.writelines("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "]" + " Backup started for: " + virtualHost + "\n") + backupSchedule.remoteBackupLogging(backupLogPath, "Preparing to create backup for: "+virtualHost) + backupSchedule.remoteBackupLogging(backupLogPath, "Backup started for: " + virtualHost) finalData = json.dumps({'websiteToBeBacked': virtualHost}) r = requests.post("http://localhost:5003/backup/submitBackupCreation", data=finalData) @@ -37,33 +45,45 @@ class backupSchedule: elif data['abort'] == 1: break - writeToFile.writelines("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "]" + " Backup created for:" + virtualHost + "\n") + backupSchedule.remoteBackupLogging(backupLogPath, "Backup created for: " + virtualHost) - writeToFile.writelines("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "]" + " Preparing to send backup for: " + virtualHost +" to "+ipAddress+ "\n") - writeToFile.flush() + ## Prepping to send backup. - backupSchedule.sendBackup(backupPath+".tar.gz", ipAddress,writeToFile,port) + backupSchedule.remoteBackupLogging(backupLogPath, "Preparing to send backup for: " + virtualHost +" to " + ipAddress) - writeToFile.writelines("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "]" + " Backup for: " + virtualHost + " is sent to " + ipAddress + "\n") + backupSchedule.sendBackup(backupPath+".tar.gz", ipAddress, backupLogPath, port) - writeToFile.writelines("\n") - writeToFile.writelines("\n") + backupSchedule.remoteBackupLogging(backupLogPath, "Backup for: " + virtualHost + " is sent to " + ipAddress) - writeToFile.writelines("#####################################") + ## Backup sent. - writeToFile.writelines("\n") - writeToFile.writelines("\n") + + backupSchedule.remoteBackupLogging(backupLogPath, "") + backupSchedule.remoteBackupLogging(backupLogPath, "") + + backupSchedule.remoteBackupLogging(backupLogPath, "#################################################") + + backupSchedule.remoteBackupLogging(backupLogPath, "") + backupSchedule.remoteBackupLogging(backupLogPath, "") except BaseException,msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createBackup]") @staticmethod - def sendBackup(backupPath, IPAddress, writeToFile,port): + def sendBackup(backupPath, IPAddress, backupLogPath , port): try: - command = "sudo scp -o StrictHostKeyChecking=no -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/"+ time.strftime("%a-%b") + "/" + + ## IPAddress of local server + + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddressLocal = ipData.split('\n', 1)[0] + + ## + + writeToFile = open(backupLogPath, "a") + command = "sudo scp -o StrictHostKeyChecking=no -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/" + ipAddressLocal + "/" + time.strftime("%a-%b") + "/" subprocess.call(shlex.split(command), stdout=writeToFile) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]") @@ -75,43 +95,46 @@ class backupSchedule: backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%I-%M-%S-%a-%b-%Y") - writeToFile = open(backupLogPath,"a") + backupSchedule.remoteBackupLogging(backupLogPath,"#################################################") + backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%I-%M-%S-%a-%b-%Y")) + backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n") - writeToFile.writelines("#################################################\n") - writeToFile.writelines(" Backup log for: " +time.strftime("%I-%M-%S-%a-%b-%Y")+"\n") - writeToFile.writelines("#################################################\n") + backupSchedule.remoteBackupLogging(backupLogPath, "") + backupSchedule.remoteBackupLogging(backupLogPath, "") - writeToFile.writelines("\n") - writeToFile.writelines("\n") + ## IP of Remote server. data = open(destinations,'r').readlines() ipAddress = data[0].strip("\n") port = data[1].strip("\n") + ## IPAddress of local server + + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddressLocal = ipData.split('\n', 1)[0] if backupUtilities.checkIfHostIsUp(ipAddress) == 1: checkConn = backupUtilities.checkConnection(ipAddress) if checkConn[0] == 0: - writeToFile.writelines("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "]" + " Connection to:" + ipAddress+" Failed, please resetup this destination from CyberPanel, aborting." + "\n") + backupSchedule.remoteBackupLogging(backupLogPath, "Connection to: " + ipAddress+ " Failed, please resetup this destination from CyberPanel, aborting.") return 0 else: ## Create backup dir on remote server - command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir /home/backup/" + time.strftime("%a-%b") + command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir -p /home/backup/"+ ipAddressLocal + "/" + time.strftime("%a-%b") subprocess.call(shlex.split(command)) - pass else: - writeToFile.writelines("[" + time.strftime( - "%I-%M-%S-%a-%b-%Y") + "]" + " Host: " + ipAddress + " is down, aborting." + "\n") + backupSchedule.remoteBackupLogging(backupLogPath, "Host: " + ipAddress + " is down, aborting.") return 0 for virtualHost in os.listdir("/home"): - if virtualHost == "vmail" or virtualHost == "cyberpanel" or virtualHost =="backup": + if virtualHost == "vmail" or virtualHost == "cyberpanel" or virtualHost == "backup": continue - backupSchedule.createBackup(virtualHost,ipAddress,writeToFile,port) + backupSchedule.createBackup(virtualHost, ipAddress, backupLogPath, port) except BaseException,msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [prepare]") diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 8eafb2519..4ce235a46 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -1,111 +1,93 @@ -import time import thread import tarfile import os import shlex import subprocess -from shutil import rmtree +import shutil import requests +import json class Upgrade: logPath = "/usr/local/lscp/logs/upgradeLog" + @staticmethod + def downloadLink(): + url = "https://cyberpanel.net/version.txt" + r = requests.get(url, verify=True) + data = json.loads(r.text) + version_number = str(data['version']) + version_build = str(data['build']) + return (version_number + "." + version_build + ".tar.gz") + + @staticmethod - def upgrade(currentVersion,currentBuild): + def upgrade(): - upgradeLog = open(Upgrade.logPath,"w") + os.chdir("/usr/local") - if os.path.exists("/usr/local/CyberCP.tar.gz"): - path = "/usr/local/CyberCP.tar.gz" - command = 'wget http://cyberpanel.net/CyberCP.tar.gz' - tarOpen = "CyberCP.tar.gz" - else: - path = "/usr/local/CyberPanel.1.4.tar.gz" - command = 'wget http://cyberpanel.net/CyberPanel.1.4.tar.gz' - tarOpen = "CyberPanel.1.4.tar.gz" + versionNumbring = Upgrade.downloadLink() + + ## Download latest version. + + command = "wget https://cyberpanel.net/CyberPanel." + versionNumbring + subprocess.call(shlex.split(command)) + + ## Backup settings file. + + shutil.copy("/usr/local/CyberCP/CyberCP/settings.py","/usr/local/settings.py") + + ## Remove Core Files + + command = "rm -rf /usr/local/CyberCP" + subprocess.call(shlex.split(command)) + + ## Extract Latest files + + command = "tar zxf CyberPanel." + versionNumbring + subprocess.call(shlex.split(command)) + + ## Copy settings file + + shutil.copy("/usr/local/settings.py", "/usr/local/CyberCP/CyberCP/") + + ## Move static files + + command = "rm -rf /usr/local/lscp/cyberpanel/static" + subprocess.call(shlex.split(command)) + + command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel" + subprocess.call(shlex.split(command)) + + ## Copy File manager files + + command = "rm -rf /usr/local/lsws/Example/html/FileManager" + subprocess.call(shlex.split(command)) + + command = "mv /usr/local/CyberCP/install/FileManager /usr/local/lsws/Example/html" + subprocess.call(shlex.split(command)) + ## Install TLDExtract - settings = "/usr/local/CyberCP/CyberCP/settings.py" + command = "pip install tldextract" + subprocess.call(shlex.split(command)) - try: - data = open(settings,'r').readlines() - except: - pass + ## Change File manager permissions - if os.path.exists(path): - os.remove(path) + command = "chmod -R 777 /usr/local/lsws/Example/html/FileManager" + subprocess.call(shlex.split(command)) - if os.path.exists("/usr/local/CyberCP"): - rmtree("/usr/local/CyberCP") + ## Restart Gunicorn - ## Downloading CyberCP - - upgradeLog.writelines("Started download for latest Version.. \n") - - - cmd = shlex.split(command) - - res = subprocess.call(cmd) - - - ## Extracting latest version - - - upgradeLog.writelines("Extracting Latest version.. \n") - - tar = tarfile.open(tarOpen) - tar.extractall("/usr/local") - tar.close() - - if os.path.exists("/usr/local/lscp/cyberpanel/static"): - rmtree("/usr/local/lscp/cyberpanel/static") - - command = 'mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel' - - cmd = shlex.split(command) - - res = subprocess.call(cmd) - - - ## Adjusting settings - - try: - upgradeLog.writelines("Fixing Settings.. \n") - - writeToFile = open(settings,'w') - - for items in data: - writeToFile.writelines(items) - - writeToFile.close() - except: - pass - - command = 'systemctl restart gunicorn.socket' - - cmd = shlex.split(command) - - res = subprocess.call(cmd) - - - upgradeLog.writelines("Upgrade Completed") + command = "systemctl restart gunicorn.socket" + subprocess.call(shlex.split(command)) + ## Upgrade version r = requests.post("http://localhost:5003/base/upgradeVersion") - upgradeLog.writelines(r.text+"\n") - - upgradeLog.close() - - - print("Upgrade Completed.") - @staticmethod - def initiateUpgrade(currentVersion,currentBuild): - thread.start_new_thread(Upgrade.upgrade, (currentVersion, currentBuild)) - -Upgrade.upgrade("1","1") \ No newline at end of file +Upgrade.upgrade() \ No newline at end of file