Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
follow PEP 8 style guide
  • Loading branch information
Istiak Ferdous committed Oct 15, 2021
1 parent 633aa05 commit f39c8fc
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 194 deletions.
8 changes: 4 additions & 4 deletions ApachController/BackupUtil.py
@@ -1,9 +1,11 @@
import smtplib
import time
import argparse
import subprocess, shlex
import subprocess
import shlex
import os


class BackupUtil:

@staticmethod
Expand Down Expand Up @@ -53,8 +55,6 @@ def MoveAllBackups():
subprocess.call(command, shell=True)




def main():

parser = argparse.ArgumentParser(description='CyberPanel Backup tool.')
Expand All @@ -70,4 +70,4 @@ def main():


if __name__ == "__main__":
main()
main()
54 changes: 32 additions & 22 deletions api/views.py
Expand Up @@ -23,6 +23,7 @@
from userManagment.views import submitUserDeletion as duc
# Create your views here.


@csrf_exempt
def verifyConn(request):
try:
Expand Down Expand Up @@ -53,6 +54,7 @@ def verifyConn(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def createWebsite(request):
data = json.loads(request.body)
Expand All @@ -68,6 +70,7 @@ def createWebsite(request):
wm = WebsiteManager()
return wm.createWebsiteAPI(json.loads(request.body))


@csrf_exempt
def getPackagesListAPI(request):
data = json.loads(request.body)
Expand All @@ -82,10 +85,11 @@ def getPackagesListAPI(request):
pm = PackagesManager()
return pm.listPackagesAPI(data)
else:
data_ret = {"status": 0,'error_message': "Could not authorize access to API"}
data_ret = {"status": 0, 'error_message': "Could not authorize access to API"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def getUserInfo(request):
try:
Expand Down Expand Up @@ -132,6 +136,7 @@ def getUserInfo(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def changeUserPassAPI(request):
try:
Expand Down Expand Up @@ -160,7 +165,6 @@ def changeUserPassAPI(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


websiteOwn = Administrator.objects.get(userName=websiteOwner)
websiteOwn.password = hashPassword.hash_password(ownerPassword)
websiteOwn.save()
Expand All @@ -174,6 +178,7 @@ def changeUserPassAPI(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def submitUserDeletion(request):
try:
Expand Down Expand Up @@ -205,6 +210,7 @@ def submitUserDeletion(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def changePackageAPI(request):
try:
Expand Down Expand Up @@ -232,7 +238,6 @@ def changePackageAPI(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


website = Websites.objects.get(domain=websiteName)
pack = Package.objects.get(packageName=packageName)

Expand All @@ -248,6 +253,7 @@ def changePackageAPI(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def deleteWebsite(request):
try:
Expand Down Expand Up @@ -293,6 +299,7 @@ def deleteWebsite(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def submitWebsiteStatus(request):
try:
Expand Down Expand Up @@ -324,6 +331,7 @@ def submitWebsiteStatus(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def loginAPI(request):
try:
Expand All @@ -348,6 +356,7 @@ def loginAPI(request):
json_data = json.dumps(data)
return HttpResponse(json_data)


@csrf_exempt
def fetchSSHkey(request):
try:
Expand All @@ -365,32 +374,33 @@ def fetchSSHkey(request):

if hashPassword.check_password(admin.password, password):

pubKey = os.path.join("/root",".ssh",'cyberpanel.pub')
pubKey = os.path.join("/root", ".ssh", 'cyberpanel.pub')
execPath = "cat " + pubKey
data = ProcessUtilities.outputExecutioner(execPath)

data_ret = {
'status': 1,
'pubKeyStatus': 1,
'error_message': "None",
'pubKey':data
'pubKey': data
}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {
'status' : 0,
'status': 0,
'pubKeyStatus': 0,
'error_message': "Could not authorize access to API."
}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

except BaseException as msg:
data = {'status' : 0, 'pubKeyStatus': 0,'error_message': str(msg)}
data = {'status': 0, 'pubKeyStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)


@csrf_exempt
def remoteTransfer(request):
try:
Expand All @@ -400,7 +410,6 @@ def remoteTransfer(request):
username = data['username']
password = data['password']


admin = Administrator.objects.get(userName=username)

if admin.api == 0:
Expand All @@ -418,7 +427,7 @@ def remoteTransfer(request):

mailUtilities.checkHome()
path = "/home/cyberpanel/accounts-" + str(randint(1000, 9999))
writeToFile = open(path,'w')
writeToFile = open(path, 'w')

for items in accountsToTransfer:
writeToFile.writelines(items + "\n")
Expand All @@ -439,10 +448,11 @@ def remoteTransfer(request):
return HttpResponse(json_data)

except BaseException as msg:
data = {'transferStatus': 0,'error_message': str(msg)}
data = {'transferStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)


@csrf_exempt
def fetchAccountsFromRemoteServer(request):
try:
Expand Down Expand Up @@ -489,10 +499,11 @@ def fetchAccountsFromRemoteServer(request):
return HttpResponse(json_data)

except BaseException as msg:
data = {'fetchStatus': 0,'error_message': str(msg)}
data = {'fetchStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)


@csrf_exempt
def FetchRemoteTransferStatus(request):
try:
Expand All @@ -511,10 +522,9 @@ def FetchRemoteTransferStatus(request):
dir = "/home/backup/transfer-"+str(data['dir'])+"/backup_log"

try:
command = "cat "+ dir
command = f"cat {dir}"
status = ProcessUtilities.outputExecutioner(command)


if hashPassword.check_password(admin.password, password):

final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": status})
Expand All @@ -527,13 +537,12 @@ def FetchRemoteTransferStatus(request):
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": "Just started.."})
return HttpResponse(final_json)



except BaseException as msg:
data = {'fetchStatus': 0,'error_message': str(msg)}
data = {'fetchStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)


@csrf_exempt
def cancelRemoteTransfer(request):
try:
Expand All @@ -551,8 +560,6 @@ def cancelRemoteTransfer(request):

dir = "/home/backup/transfer-"+str(data['dir'])



if hashPassword.check_password(admin.password, password):

path = dir + "/pid"
Expand All @@ -575,12 +582,12 @@ def cancelRemoteTransfer(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


except BaseException as msg:
data = {'cancelStatus': 1, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)


@csrf_exempt
def cyberPanelVersion(request):
try:
Expand All @@ -591,7 +598,6 @@ def cyberPanelVersion(request):
adminUser = data['username']
adminPass = data['password']


admin = Administrator.objects.get(userName=adminUser)

if admin.api == 0:
Expand All @@ -606,8 +612,8 @@ def cyberPanelVersion(request):
data_ret = {
"getVersion": 1,
'error_message': "none",
'currentVersion':Version.currentVersion,
'build':Version.build
'currentVersion': Version.currentVersion,
'build': Version.build
}

json_data = json.dumps(data_ret)
Expand All @@ -628,6 +634,7 @@ def cyberPanelVersion(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def runAWSBackups(request):
try:
Expand All @@ -641,6 +648,7 @@ def runAWSBackups(request):
except BaseException as msg:
logging.writeToFile(str(msg) + ' [API.runAWSBackups]')


@csrf_exempt
def submitUserCreation(request):
try:
Expand Down Expand Up @@ -672,6 +680,7 @@ def submitUserCreation(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def addFirewallRule(request):
try:
Expand Down Expand Up @@ -705,6 +714,7 @@ def addFirewallRule(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def deleteFirewallRule(request):
try:
Expand Down

0 comments on commit f39c8fc

Please sign in to comment.