diff --git a/databases/databaseManager.py b/databases/databaseManager.py index aced68386..721129317 100755 --- a/databases/databaseManager.py +++ b/databases/databaseManager.py @@ -5,7 +5,7 @@ import django sys.path.append('/usr/local/CyberCP') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") django.setup() -from django.shortcuts import render, redirect +from django.shortcuts import render from django.http import HttpResponse import json from plogical.acl import ACLManager diff --git a/databases/tests.py b/databases/tests.py index 5982e6bcd..fa91e5394 100755 --- a/databases/tests.py +++ b/databases/tests.py @@ -2,5 +2,74 @@ from __future__ import unicode_literals from django.test import TestCase +import json +import requests +import urllib3 +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + +urllib3.disable_warnings() + # Create your tests here. + + +class TestDatabases(TestCase): + httpClient = requests.Session() + + def MakeRequest(self, endPoint, data): + json_data = json.dumps(data) + path = 'https://cyberpanel.xyz:8090/%s' % (endPoint) + result = TestDatabases.httpClient.post(path, data=json_data, verify=False) + return json.loads(result.text) + + def MakeRequestRaw(self, path): + result = requests.get(path) + return str(result.text) + + def setUp(self): + ## Verify login + + data_ret = {'username': 'admin', 'password': '1234567'} + response = self.MakeRequest('verifyLogin', data_ret) + self.assertEqual(response['loginStatus'], 1) + + def test_submitDBCreation(self): + ## Create Package + + data_ret = {'databaseWebsite': 'cyberpanel.xyz', 'dbName': 'hello', 'dbUsername': 'hello', + 'dbPassword': 'helloworld', 'webUserName': 'admin'} + + response = self.MakeRequest('dataBases/submitDBCreation', data_ret) + logging.writeToFile(str(response)) + + self.assertEqual(response['status'], 1) + + ## Modify Package + + data_ret = {'packageName': 'admin_HelloWorld', 'diskSpace': 500, 'bandwidth': 50, + 'dataBases': 500, 'ftpAccounts': 50, 'emails': 50, 'allowedDomains': 50, 'allowFullDomain': 1} + + response = self.MakeRequest('packages/saveChanges', data_ret) + logging.writeToFile(str(response)) + + self.assertEqual(response['status'], 1) + + ## Modify Confirm + + data_ret = {'packageName': 'admin_HelloWorld'} + + response = self.MakeRequest('packages/submitModify', data_ret) + logging.writeToFile(str(response)) + + self.assertEqual(response['modifyStatus'], 1) + self.assertEqual(response['dataBases'], 500) + self.assertEqual(response['diskSpace'], 500) + + ## Delete Package + + data_ret = {'packageName': 'admin_HelloWorld'} + + response = self.MakeRequest('packages/submitDelete', data_ret) + logging.writeToFile(str(response)) + + self.assertEqual(response['status'], 1) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index b0bc609e3..1cd433c3d 100755 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -290,17 +290,17 @@ class virtualHostUtilities: return 0, str(msg) @staticmethod - def getAccessLogs(fileName, page): + def getAccessLogs(fileName, page, externalApp): try: if os.path.islink(fileName): print "0, %s file is symlinked." % (fileName) return 0 - numberOfTotalLines = int(subprocess.check_output(["wc", "-l", fileName]).split(" ")[0]) + numberOfTotalLines = int(ProcessUtilities.outputExecutioner('wc -l %s' % (fileName), externalApp).split(" ")[0]) if numberOfTotalLines < 25: - data = subprocess.check_output(["cat", fileName]) + data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), externalApp) else: if page == 1: end = numberOfTotalLines @@ -309,8 +309,7 @@ class virtualHostUtilities: start = 1 startingAndEnding = "'" + str(start) + "," + str(end) + "p'" command = "sed -n " + startingAndEnding + " " + fileName - proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) - data = proc.stdout.read() + data = ProcessUtilities.outputExecutioner(command, externalApp) else: end = numberOfTotalLines - ((page - 1) * 25) start = end - 24 @@ -318,26 +317,28 @@ class virtualHostUtilities: start = 1 startingAndEnding = "'" + str(start) + "," + str(end) + "p'" command = "sed -n " + startingAndEnding + " " + fileName - proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) - data = proc.stdout.read() + data = ProcessUtilities.outputExecutioner(command, externalApp) print data + return data except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [getAccessLogs]") print "1,None" + return "1,None" @staticmethod - def getErrorLogs(fileName, page): + def getErrorLogs(fileName, page, externalApp): try: if os.path.islink(fileName): print "0, %s file is symlinked." % (fileName) return 0 - numberOfTotalLines = int(subprocess.check_output(["wc", "-l", fileName]).split(" ")[0]) + numberOfTotalLines = int( + ProcessUtilities.outputExecutioner('wc -l %s' % (fileName), externalApp).split(" ")[0]) if numberOfTotalLines < 25: - data = subprocess.check_output(["cat", fileName]) + data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), externalApp) else: if page == 1: end = numberOfTotalLines @@ -346,8 +347,7 @@ class virtualHostUtilities: start = 1 startingAndEnding = "'" + str(start) + "," + str(end) + "p'" command = "sed -n " + startingAndEnding + " " + fileName - proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) - data = proc.stdout.read() + data = ProcessUtilities.outputExecutioner(command, externalApp) else: end = numberOfTotalLines - ((page - 1) * 25) start = end - 24 @@ -355,13 +355,14 @@ class virtualHostUtilities: start = 1 startingAndEnding = "'" + str(start) + "," + str(end) + "p'" command = "sed -n " + startingAndEnding + " " + fileName - proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) - data = proc.stdout.read() + data = ProcessUtilities.outputExecutioner(command, externalApp) print data + return data except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [getErrorLogs]") print "1,None" + return "1,None" @staticmethod def saveVHostConfigs(fileName, tempPath): diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 123761cd8..52095acdd 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -856,9 +856,7 @@ class WebsiteManager: ## get Logs website = Websites.objects.get(domain=self.domain) - execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" - execPath = execPath + " getAccessLogs --path " + fileName + " --page " + str(page) - output = ProcessUtilities.outputExecutioner(execPath, website.externalApp) + output = virtualHostUtilities.getAccessLogs(fileName, page, website.externalApp) if output.find("1,None") > -1: final_json = json.dumps( @@ -916,10 +914,7 @@ class WebsiteManager: ## get Logs website = Websites.objects.get(domain=self.domain) - execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" - execPath = execPath + " getErrorLogs --path " + fileName + " --page " + str(page) - - output = ProcessUtilities.outputExecutioner(execPath, website.externalApp) + output = virtualHostUtilities.getErrorLogs(fileName, page, website.externalApp) if output.find("1,None") > -1: final_json = json.dumps(