bug fix: fetch status

This commit is contained in:
Usman Nasir
2021-09-01 14:20:09 +05:00
parent c3a0cf459e
commit 1b5f0515b9

View File

@@ -78,7 +78,8 @@ class WebsiteManager:
def CreateNewDomain(self, request=None, userID=None, data=None): def CreateNewDomain(self, request=None, userID=None, data=None):
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID) websitesName = ACLManager.findAllSites(currentACL, userID)
proc = httpProc(request, 'websiteFunctions/createDomain.html', {'websiteList': websitesName, 'phps': PHPManager.findPHPVersions()}) proc = httpProc(request, 'websiteFunctions/createDomain.html',
{'websiteList': websitesName, 'phps': PHPManager.findPHPVersions()})
return proc.render() return proc.render()
def siteState(self, request=None, userID=None, data=None): def siteState(self, request=None, userID=None, data=None):
@@ -183,8 +184,6 @@ class WebsiteManager:
except: except:
externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:5] + str(randint(1000, 9999)) externalApp = "".join(re.findall("[a-zA-Z]+", domain))[:5] + str(randint(1000, 9999))
try: try:
counter = 0 counter = 0
while 1: while 1:
@@ -216,7 +215,8 @@ class WebsiteManager:
" --administratorEmail " + adminEmail + " --phpVersion '" + phpSelection + \ " --administratorEmail " + adminEmail + " --phpVersion '" + phpSelection + \
"' --virtualHostUser " + externalApp + " --ssl " + str(data['ssl']) + " --dkimCheck " \ "' --virtualHostUser " + externalApp + " --ssl " + str(data['ssl']) + " --dkimCheck " \
+ str(data['dkimCheck']) + " --openBasedir " + str(data['openBasedir']) + \ + str(data['dkimCheck']) + " --openBasedir " + str(data['openBasedir']) + \
' --websiteOwner "' + websiteOwner + '" --package "' + packageName + '" --tempStatusPath ' + tempStatusPath + " --apache " + apacheBackend + " --mailDomain %s" % (mailDomain) ' --websiteOwner "' + websiteOwner + '" --package "' + packageName + '" --tempStatusPath ' + tempStatusPath + " --apache " + apacheBackend + " --mailDomain %s" % (
mailDomain)
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
time.sleep(2) time.sleep(2)
@@ -244,7 +244,6 @@ class WebsiteManager:
path = data['path'] path = data['path']
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
if not validators.domain(domain): if not validators.domain(domain):
data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."} data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
@@ -441,9 +440,9 @@ class WebsiteManager:
DiskUsage, DiskUsagePercentage, bwInMB, bwUsage = virtualHostUtilities.FindStats(items) DiskUsage, DiskUsagePercentage, bwInMB, bwUsage = virtualHostUtilities.FindStats(items)
diskUsed = "%sMB" % str(DiskUsage) diskUsed = "%sMB" % str(DiskUsage)
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress, dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state, 'diskUsed': diskUsed} 'admin': items.admin.userName, 'package': items.package.packageName, 'state': state,
'diskUsed': diskUsed}
if checker == 0: if checker == 0:
json_data = json_data + json.dumps(dic) json_data = json_data + json.dumps(dic)
@@ -471,8 +470,10 @@ class WebsiteManager:
for items in childs: for items in childs:
dic = {'domain': items.domain, 'masterDomain': items.master.domain, 'adminEmail': items.master.adminEmail, 'ipAddress': ipAddress, dic = {'domain': items.domain, 'masterDomain': items.master.domain, 'adminEmail': items.master.adminEmail,
'admin': items.master.admin.userName, 'package': items.master.package.packageName, 'path': items.path} 'ipAddress': ipAddress,
'admin': items.master.admin.userName, 'package': items.master.package.packageName,
'path': items.path}
if checker == 0: if checker == 0:
json_data = json_data + json.dumps(dic) json_data = json_data + json.dumps(dic)
@@ -556,7 +557,8 @@ class WebsiteManager:
return ACLManager.loadErrorJson('websiteDeleteStatus', 0) return ACLManager.loadErrorJson('websiteDeleteStatus', 0)
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " deleteDomain --virtualHostName " + websiteName + ' --DeleteDocRoot %s' % (str(DeleteDocRoot)) execPath = execPath + " deleteDomain --virtualHostName " + websiteName + ' --DeleteDocRoot %s' % (
str(DeleteDocRoot))
ProcessUtilities.outputExecutioner(execPath) ProcessUtilities.outputExecutioner(execPath)
data_ret = {'status': 1, 'websiteDeleteStatus': 1, 'error_message': "None"} data_ret = {'status': 1, 'websiteDeleteStatus': 1, 'error_message': "None"}
@@ -972,7 +974,6 @@ class WebsiteManager:
Data['viewSSL'] = 0 Data['viewSSL'] = 0
logging.CyberCPLogFileWriter.writeToFile(str(msg)) logging.CyberCPLogFileWriter.writeToFile(str(msg))
proc = httpProc(request, 'websiteFunctions/launchChild.html', Data) proc = httpProc(request, 'websiteFunctions/launchChild.html', Data)
return proc.render() return proc.render()
else: else:
@@ -1006,7 +1007,8 @@ class WebsiteManager:
if output.find("1,None") > -1: if output.find("1,None") > -1:
final_json = json.dumps( final_json = json.dumps(
{'status': 0, 'logstatus': 0, 'error_message': "Not able to fetch logs, see CyberPanel main log file, Error: %s" % (output)}) {'status': 0, 'logstatus': 0,
'error_message': "Not able to fetch logs, see CyberPanel main log file, Error: %s" % (output)})
return HttpResponse(final_json) return HttpResponse(final_json)
## get log ends here. ## get log ends here.
@@ -1100,7 +1102,8 @@ class WebsiteManager:
else: else:
command = 'redis-cli get "vhost:%s"' % (self.domain) command = 'redis-cli get "vhost:%s"' % (self.domain)
configData = ProcessUtilities.outputExecutioner(command) configData = ProcessUtilities.outputExecutioner(command)
configData = '#### This configuration is fetched from redis as Redis-Mass Hosting is being used.\n%s' % (configData) configData = '#### This configuration is fetched from redis as Redis-Mass Hosting is being used.\n%s' % (
configData)
status = {'status': 1, "configstatus": 1, "configData": configData} status = {'status': 1, "configstatus": 1, "configData": configData}
final_json = json.dumps(status) final_json = json.dumps(status)
@@ -1153,7 +1156,8 @@ class WebsiteManager:
## save configuration data ends ## save configuration data ends
else: else:
command = "redis-cli set vhost:%s '%s'" % (self.domain, configData.replace('#### This configuration is fetched from redis as Redis-Mass Hosting is being used.\n', '')) command = "redis-cli set vhost:%s '%s'" % (self.domain, configData.replace(
'#### This configuration is fetched from redis as Redis-Mass Hosting is being used.\n', ''))
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
status = {"configstatus": 1} status = {"configstatus": 1}
@@ -1161,7 +1165,6 @@ class WebsiteManager:
final_json = json.dumps(status) final_json = json.dumps(status)
return HttpResponse(final_json) return HttpResponse(final_json)
def getRewriteRules(self, userID=None, data=None): def getRewriteRules(self, userID=None, data=None):
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
@@ -1586,7 +1589,6 @@ class WebsiteManager:
execPath = execPath + " addNewCron --externalApp " + website.externalApp + " --finalCron '" + finalCron + "'" execPath = execPath + " addNewCron --externalApp " + website.externalApp + " --finalCron '" + finalCron + "'"
output = ProcessUtilities.outputExecutioner(execPath, website.externalApp) output = ProcessUtilities.outputExecutioner(execPath, website.externalApp)
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20: if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
command = 'chmod 600 %s' % (cronPath) command = 'chmod 600 %s' % (cronPath)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
@@ -1833,8 +1835,10 @@ class WebsiteManager:
try: try:
statusFile = data['statusFile'] statusFile = data['statusFile']
if (statusFile[:16] == "/home/cyberpanel" or statusFile[:4] == '/tmp' or statusFile[:18] == '/usr/local/CyberCP') \ if (statusFile[:18] != "/home/cyberpanel/." or statusFile[:16] == "/home/cyberpanel" or statusFile[:4] == '/tmp' or statusFile[
and statusFile != '/usr/local/CyberCP/CyberCP/settings.py' and statusFile.find('..') == -1 and statusFile != '/home/cyberpanel/.my.cnf': :18] == '/usr/local/CyberCP') \
and statusFile != '/usr/local/CyberCP/CyberCP/settings.py' and statusFile.find(
'..') == -1 and statusFile != '/home/cyberpanel/.my.cnf' and statusFile != '/home/cyberpanel/.bashrc' and statusFile != '/home/cyberpanel/.bash_logout' and statusFile != '/home/cyberpanel/.profile':
pass pass
else: else:
data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "100", data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "100",
@@ -2364,7 +2368,8 @@ StrictHostKeyChecking no
diskUsed = "%sMB" % str(DiskUsage) diskUsed = "%sMB" % str(DiskUsage)
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress, dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state, 'diskUsed': diskUsed} 'admin': items.admin.userName, 'package': items.package.packageName, 'state': state,
'diskUsed': diskUsed}
if checker == 0: if checker == 0:
json_data = json_data + json.dumps(dic) json_data = json_data + json.dumps(dic)
@@ -2404,7 +2409,8 @@ StrictHostKeyChecking no
diskUsed = "%sMB" % str(DiskUsage) diskUsed = "%sMB" % str(DiskUsage)
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress, dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state, 'diskUsed': diskUsed} 'admin': items.admin.userName, 'package': items.package.packageName, 'state': state,
'diskUsed': diskUsed}
if checker == 0: if checker == 0:
json_data = json_data + json.dumps(dic) json_data = json_data + json.dumps(dic)
@@ -2653,7 +2659,6 @@ StrictHostKeyChecking no
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
def setupStaging(self, request=None, userID=None, data=None): def setupStaging(self, request=None, userID=None, data=None):
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
@@ -2683,7 +2688,6 @@ StrictHostKeyChecking no
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
if not validators.domain(data['domainName']): if not validators.domain(data['domainName']):
data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."} data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
@@ -2694,7 +2698,6 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson('status', 0) return ACLManager.loadErrorJson('status', 0)
extraArgs = {} extraArgs = {}
extraArgs['domain'] = data['domainName'] extraArgs['domain'] = data['domainName']
extraArgs['masterDomain'] = data['masterDomain'] extraArgs['masterDomain'] = data['masterDomain']
@@ -2742,7 +2745,6 @@ StrictHostKeyChecking no
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
if not validators.domain(data['childDomain']): if not validators.domain(data['childDomain']):
data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."} data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Invalid domain."}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
@@ -2755,7 +2757,6 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson('status', 0) return ACLManager.loadErrorJson('status', 0)
extraArgs = {} extraArgs = {}
extraArgs['childDomain'] = data['childDomain'] extraArgs['childDomain'] = data['childDomain']
try: try:
@@ -2773,7 +2774,6 @@ StrictHostKeyChecking no
extraArgs['admin'] = admin extraArgs['admin'] = admin
tempStatusPath = "/tmp/" + str(randint(1000, 9999)) tempStatusPath = "/tmp/" + str(randint(1000, 9999))
writeToFile = open(tempStatusPath, 'a') writeToFile = open(tempStatusPath, 'a')
message = 'Syncing process has started..,5' message = 'Syncing process has started..,5'
@@ -2991,7 +2991,6 @@ StrictHostKeyChecking no
except BaseException as msg: except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile('%s. [folderCheck:3002]' % (str(msg))) logging.CyberCPLogFileWriter.writeToFile('%s. [folderCheck:3002]' % (str(msg)))
return 0 return 0
def fetchFolderDetails(self, userID=None, data=None): def fetchFolderDetails(self, userID=None, data=None):
@@ -3013,12 +3012,11 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson() return ACLManager.loadErrorJson()
gitPath = '%s/.git' % (self.folder) gitPath = '%s/.git' % (self.folder)
command = 'ls -la %s' % (gitPath) command = 'ls -la %s' % (gitPath)
if ProcessUtilities.outputExecutioner(command, self.externalAppLocal).find(
if ProcessUtilities.outputExecutioner(command, self.externalAppLocal).find('No such file or directory') > -1: 'No such file or directory') > -1:
command = 'cat /home/%s/.ssh/%s.pub' % (self.masterDomain, self.externalAppLocal) command = 'cat /home/%s/.ssh/%s.pub' % (self.masterDomain, self.externalAppLocal)
deploymentKey = ProcessUtilities.outputExecutioner(command, self.externalAppLocal) deploymentKey = ProcessUtilities.outputExecutioner(command, self.externalAppLocal)
@@ -3077,9 +3075,11 @@ StrictHostKeyChecking no
webHookURL = 'https://%s:%s/websites/%s/webhook' % (ACLManager.fetchIP(), port, self.domain) webHookURL = 'https://%s:%s/websites/%s/webhook' % (ACLManager.fetchIP(), port, self.domain)
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey,
'remote': remote, 'remoteResult': remoteResult, 'totalCommits': totalCommits, 'home': self.home, 'remote': remote, 'remoteResult': remoteResult, 'totalCommits': totalCommits,
'home': self.home,
'webHookURL': webHookURL, 'autoCommitCurrent': self.autoCommitCurrent, 'webHookURL': webHookURL, 'autoCommitCurrent': self.autoCommitCurrent,
'autoPushCurrent':self.autoPushCurrent, 'emailLogsCurrent': self.emailLogsCurrent, 'commands': self.commands, "webhookCommandCurrent": self.webhookCommandCurrent} 'autoPushCurrent': self.autoPushCurrent, 'emailLogsCurrent': self.emailLogsCurrent,
'commands': self.commands, "webhookCommandCurrent": self.webhookCommandCurrent}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -3108,7 +3108,6 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson() return ACLManager.loadErrorJson()
command = 'git -C %s init' % (self.folder) command = 'git -C %s init' % (self.folder)
result = ProcessUtilities.outputExecutioner(command) result = ProcessUtilities.outputExecutioner(command)
@@ -3188,7 +3187,8 @@ StrictHostKeyChecking no
### set default ssh key ### set default ssh key
command = 'git -C %s config --local core.sshCommand "ssh -i /home/%s/.ssh/%s -o "StrictHostKeyChecking=no""' % (self.folder, self.masterDomain, self.externalAppLocal) command = 'git -C %s config --local core.sshCommand "ssh -i /home/%s/.ssh/%s -o "StrictHostKeyChecking=no""' % (
self.folder, self.masterDomain, self.externalAppLocal)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
## Check if remote exists ## Check if remote exists
@@ -3199,9 +3199,11 @@ StrictHostKeyChecking no
## Set new remote ## Set new remote
if remoteResult.find('origin') == -1: if remoteResult.find('origin') == -1:
command = 'git -C %s remote add origin git@%s:%s/%s.git' % (self.folder, self.gitHost, self.gitUsername, self.gitReponame) command = 'git -C %s remote add origin git@%s:%s/%s.git' % (
self.folder, self.gitHost, self.gitUsername, self.gitReponame)
else: else:
command = 'git -C %s remote set-url origin git@%s:%s/%s.git' % (self.folder, self.gitHost, self.gitUsername, self.gitReponame) command = 'git -C %s remote set-url origin git@%s:%s/%s.git' % (
self.folder, self.gitHost, self.gitUsername, self.gitReponame)
possibleError = ProcessUtilities.outputExecutioner(command) possibleError = ProcessUtilities.outputExecutioner(command)
@@ -3259,9 +3261,9 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson('status', 'Invalid characters in your input.') return ACLManager.loadErrorJson('status', 'Invalid characters in your input.')
if self.branchName.find('*') > -1: if self.branchName.find('*') > -1:
data_ret = {'status': 0, 'commandStatus': 'Already on this branch.', 'error_message': 'Already on this branch.'} data_ret = {'status': 0, 'commandStatus': 'Already on this branch.',
'error_message': 'Already on this branch.'}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -3331,7 +3333,6 @@ StrictHostKeyChecking no
fm = FileManager(None, None) fm = FileManager(None, None)
fm.fixPermissions(self.masterDomain) fm.fixPermissions(self.masterDomain)
data_ret = {'status': 1, 'commandStatus': commandStatus} data_ret = {'status': 1, 'commandStatus': commandStatus}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -3365,16 +3366,13 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson('status', 0) return ACLManager.loadErrorJson('status', 0)
# security check # security check
if ACLManager.validateInput(self.commitMessage): if ACLManager.validateInput(self.commitMessage):
pass pass
else: else:
return ACLManager.loadErrorJson() return ACLManager.loadErrorJson()
## Check if remote exists ## Check if remote exists
command = 'git -C %s add -A' % (self.folder) command = 'git -C %s add -A' % (self.folder)
@@ -3388,7 +3386,8 @@ StrictHostKeyChecking no
try: try:
if self.commands != 'NONE': if self.commands != 'NONE':
GitLogs(owner=self.masterWebsite, type='INFO', message='Running commands after successful git commit..').save() GitLogs(owner=self.masterWebsite, type='INFO',
message='Running commands after successful git commit..').save()
if self.commands.find('\n') > -1: if self.commands.find('\n') > -1:
commands = self.commands.split('\n') commands = self.commands.split('\n')
@@ -3442,7 +3441,6 @@ StrictHostKeyChecking no
self.domain = data['domain'] self.domain = data['domain']
self.folder = data['folder'] self.folder = data['folder']
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass pass
else: else:
@@ -3455,7 +3453,6 @@ StrictHostKeyChecking no
### set default ssh key ### set default ssh key
command = 'git -C %s config --local core.sshCommand "ssh -i /home/%s/.ssh/%s -o "StrictHostKeyChecking=no""' % ( command = 'git -C %s config --local core.sshCommand "ssh -i /home/%s/.ssh/%s -o "StrictHostKeyChecking=no""' % (
self.folder, self.masterDomain, self.externalAppLocal) self.folder, self.masterDomain, self.externalAppLocal)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
@@ -3496,7 +3493,6 @@ StrictHostKeyChecking no
self.domain = data['domain'] self.domain = data['domain']
self.folder = data['folder'] self.folder = data['folder']
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass pass
else: else:
@@ -3523,14 +3519,16 @@ StrictHostKeyChecking no
currentBranch = ProcessUtilities.outputExecutioner(command, 'root', False).rstrip('\n') currentBranch = ProcessUtilities.outputExecutioner(command, 'root', False).rstrip('\n')
if currentBranch.find('fatal: ambiguous argument') > -1: if currentBranch.find('fatal: ambiguous argument') > -1:
data_ret = {'status': 0, 'error_message': 'You need to commit first.', 'commandStatus': 'You need to commit first.'} data_ret = {'status': 0, 'error_message': 'You need to commit first.',
'commandStatus': 'You need to commit first.'}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
command = 'git -C %s push --set-upstream origin %s' % (self.folder, currentBranch) command = 'git -C %s push --set-upstream origin %s' % (self.folder, currentBranch)
commandStatus = ProcessUtilities.outputExecutioner(command, 'root', False) commandStatus = ProcessUtilities.outputExecutioner(command, 'root', False)
if commandStatus.find('Everything up-to-date') == -1 and commandStatus.find('rejected') == -1 and commandStatus.find('Permission denied') == -1: if commandStatus.find('Everything up-to-date') == -1 and commandStatus.find(
'rejected') == -1 and commandStatus.find('Permission denied') == -1:
data_ret = {'status': 1, 'commandStatus': commandStatus} data_ret = {'status': 1, 'commandStatus': commandStatus}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -3561,7 +3559,6 @@ StrictHostKeyChecking no
except: except:
self.overrideData = False self.overrideData = False
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass pass
else: else:
@@ -3587,7 +3584,6 @@ StrictHostKeyChecking no
if not validators.domain(self.gitHost): if not validators.domain(self.gitHost):
return ACLManager.loadErrorJson('status', 'Invalid characters in your input.') return ACLManager.loadErrorJson('status', 'Invalid characters in your input.')
## Security check ## Security check
if ACLManager.validateInput(self.gitUsername) and ACLManager.validateInput(self.gitReponame): if ACLManager.validateInput(self.gitUsername) and ACLManager.validateInput(self.gitReponame):
@@ -3597,14 +3593,14 @@ StrictHostKeyChecking no
## ##
if self.overrideData: if self.overrideData:
command = 'rm -rf %s' % (self.folder) command = 'rm -rf %s' % (self.folder)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
## Set defauly key ## Set defauly key
command = 'git config --global core.sshCommand "ssh -i /home/%s/.ssh/%s -o "StrictHostKeyChecking=no""' % (self.masterDomain, self.externalAppLocal) command = 'git config --global core.sshCommand "ssh -i /home/%s/.ssh/%s -o "StrictHostKeyChecking=no""' % (
self.masterDomain, self.externalAppLocal)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
## ##
@@ -3654,7 +3650,6 @@ StrictHostKeyChecking no
self.domain = data['domain'] self.domain = data['domain']
self.folder = data['folder'] self.folder = data['folder']
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass pass
else: else:
@@ -3700,7 +3695,6 @@ StrictHostKeyChecking no
self.domain = data['domain'] self.domain = data['domain']
self.folder = data['folder'] self.folder = data['folder']
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass pass
else: else:
@@ -3738,7 +3732,6 @@ StrictHostKeyChecking no
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass pass
else: else:
@@ -3901,10 +3894,10 @@ StrictHostKeyChecking no
else: else:
return ACLManager.loadErrorJson('status', 'Invalid characters in your input.') return ACLManager.loadErrorJson('status', 'Invalid characters in your input.')
command = 'git -C %s show %s -- %s/%s' % (self.folder, self.commit, self.folder, self.file.strip('\n').strip(' ')) command = 'git -C %s show %s -- %s/%s' % (
self.folder, self.commit, self.folder, self.file.strip('\n').strip(' '))
fileChangedContent = ProcessUtilities.outputExecutioner(command).split('\n') fileChangedContent = ProcessUtilities.outputExecutioner(command).split('\n')
initialNumber = 0 initialNumber = 0
## Find initial line numbers ## Find initial line numbers
for items in fileChangedContent: for items in fileChangedContent:
@@ -3921,26 +3914,33 @@ StrictHostKeyChecking no
lineNumber = int(fileChangedContent[initialNumber].split('+')[1].split(' ')[0]) lineNumber = int(fileChangedContent[initialNumber].split('+')[1].split(' ')[0])
fileLen = len(fileChangedContent) fileLen = len(fileChangedContent)
finalConent = '<tr><td style="border-top: none;color:blue">%s</td><td style="border-top: none;"><p style="color:blue">%s</p></td></tr>' % ('#', fileChangedContent[initialNumber]) finalConent = '<tr><td style="border-top: none;color:blue">%s</td><td style="border-top: none;"><p style="color:blue">%s</p></td></tr>' % (
'#', fileChangedContent[initialNumber])
for i in range(initialNumber + 1, fileLen - 1): for i in range(initialNumber + 1, fileLen - 1):
if fileChangedContent[i][0] == '@': if fileChangedContent[i][0] == '@':
lineNumber = int(fileChangedContent[i].split('+')[1].split(',')[0]) lineNumber = int(fileChangedContent[i].split('+')[1].split(',')[0])
finalConent = finalConent + '<tr><td style="border-top: none;color:blue">%s</td><td style="border-top: none;"><p style="color:blue">%s</p></td></tr>' % ('#', fileChangedContent[i]) finalConent = finalConent + '<tr><td style="border-top: none;color:blue">%s</td><td style="border-top: none;"><p style="color:blue">%s</p></td></tr>' % (
'#', fileChangedContent[i])
continue continue
else: else:
if fileChangedContent[i][0] == '+': if fileChangedContent[i][0] == '+':
content = '<p style="color:green">%s</p>' % (fileChangedContent[i].replace('<', "&lt;").replace('>', "&gt;")) content = '<p style="color:green">%s</p>' % (
finalConent = finalConent + '<tr style="color:green"><td style="border-top: none;">%s</td><td style="border-top: none;">%s</td></tr>' % (str(lineNumber), content) fileChangedContent[i].replace('<', "&lt;").replace('>', "&gt;"))
finalConent = finalConent + '<tr style="color:green"><td style="border-top: none;">%s</td><td style="border-top: none;">%s</td></tr>' % (
str(lineNumber), content)
lineNumber = lineNumber + 1 lineNumber = lineNumber + 1
elif fileChangedContent[i][0] == '-': elif fileChangedContent[i][0] == '-':
content = '<p style="color:red">%s</p>' % (fileChangedContent[i].replace('<', "&lt;").replace('>', "&gt;")) content = '<p style="color:red">%s</p>' % (
finalConent = finalConent + '<tr style="color:red"><td style="border-top: none;">%s</td><td style="border-top: none;">%s</td></tr>' % (str(lineNumber), content) fileChangedContent[i].replace('<', "&lt;").replace('>', "&gt;"))
finalConent = finalConent + '<tr style="color:red"><td style="border-top: none;">%s</td><td style="border-top: none;">%s</td></tr>' % (
str(lineNumber), content)
lineNumber = lineNumber + 1 lineNumber = lineNumber + 1
else: else:
content = '<p>%s</p>' % (fileChangedContent[i].replace('<', "&lt;").replace('>', "&gt;")) content = '<p>%s</p>' % (fileChangedContent[i].replace('<', "&lt;").replace('>', "&gt;"))
finalConent = finalConent + '<tr><td style="border-top: none;">%s</td><td style="border-top: none;">%s</td></tr>' % (str(lineNumber), content) finalConent = finalConent + '<tr><td style="border-top: none;">%s</td><td style="border-top: none;">%s</td></tr>' % (
str(lineNumber), content)
lineNumber = lineNumber + 1 lineNumber = lineNumber + 1
data_ret = {'status': 1, 'fileChangedContent': finalConent} data_ret = {'status': 1, 'fileChangedContent': finalConent}
@@ -4142,7 +4142,8 @@ StrictHostKeyChecking no
if gitConf['webhookCommand']: if gitConf['webhookCommand']:
if gitConf['commands'] != 'NONE': if gitConf['commands'] != 'NONE':
GitLogs(owner=self.web, type='INFO', message='Running commands after successful git commit..').save() GitLogs(owner=self.web, type='INFO',
message='Running commands after successful git commit..').save()
if gitConf['commands'].find('\n') > -1: if gitConf['commands'].find('\n') > -1:
commands = gitConf['commands'].split('\n') commands = gitConf['commands'].split('\n')
@@ -4151,14 +4152,16 @@ StrictHostKeyChecking no
GitLogs(owner=self.web, type='INFO', GitLogs(owner=self.web, type='INFO',
message='Running: %s' % (command)).save() message='Running: %s' % (command)).save()
result = ProcessUtilities.outputExecutioner(command, self.web.externalApp, None, self.folder) result = ProcessUtilities.outputExecutioner(command, self.web.externalApp, None,
self.folder)
GitLogs(owner=self.web, type='INFO', GitLogs(owner=self.web, type='INFO',
message='Result: %s' % (result)).save() message='Result: %s' % (result)).save()
else: else:
GitLogs(owner=self.web, type='INFO', GitLogs(owner=self.web, type='INFO',
message='Running: %s' % (gitConf['commands'])).save() message='Running: %s' % (gitConf['commands'])).save()
result = ProcessUtilities.outputExecutioner(gitConf['commands'], self.web.externalApp, None, self.folder) result = ProcessUtilities.outputExecutioner(gitConf['commands'],
self.web.externalApp, None, self.folder)
GitLogs(owner=self.web, type='INFO', GitLogs(owner=self.web, type='INFO',
message='Result: %s' % (result)).save() message='Result: %s' % (result)).save()