mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 05:45:59 +01:00
bug fix: fetch logs
This commit is contained in:
@@ -5,7 +5,7 @@ import django
|
|||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
django.setup()
|
django.setup()
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
import json
|
import json
|
||||||
from plogical.acl import ACLManager
|
from plogical.acl import ACLManager
|
||||||
|
|||||||
@@ -2,5 +2,74 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.test import TestCase
|
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.
|
# 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)
|
||||||
|
|||||||
@@ -290,17 +290,17 @@ class virtualHostUtilities:
|
|||||||
return 0, str(msg)
|
return 0, str(msg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getAccessLogs(fileName, page):
|
def getAccessLogs(fileName, page, externalApp):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if os.path.islink(fileName):
|
if os.path.islink(fileName):
|
||||||
print "0, %s file is symlinked." % (fileName)
|
print "0, %s file is symlinked." % (fileName)
|
||||||
return 0
|
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:
|
if numberOfTotalLines < 25:
|
||||||
data = subprocess.check_output(["cat", fileName])
|
data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), externalApp)
|
||||||
else:
|
else:
|
||||||
if page == 1:
|
if page == 1:
|
||||||
end = numberOfTotalLines
|
end = numberOfTotalLines
|
||||||
@@ -309,8 +309,7 @@ class virtualHostUtilities:
|
|||||||
start = 1
|
start = 1
|
||||||
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
||||||
command = "sed -n " + startingAndEnding + " " + fileName
|
command = "sed -n " + startingAndEnding + " " + fileName
|
||||||
proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
|
data = ProcessUtilities.outputExecutioner(command, externalApp)
|
||||||
data = proc.stdout.read()
|
|
||||||
else:
|
else:
|
||||||
end = numberOfTotalLines - ((page - 1) * 25)
|
end = numberOfTotalLines - ((page - 1) * 25)
|
||||||
start = end - 24
|
start = end - 24
|
||||||
@@ -318,26 +317,28 @@ class virtualHostUtilities:
|
|||||||
start = 1
|
start = 1
|
||||||
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
||||||
command = "sed -n " + startingAndEnding + " " + fileName
|
command = "sed -n " + startingAndEnding + " " + fileName
|
||||||
proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
|
data = ProcessUtilities.outputExecutioner(command, externalApp)
|
||||||
data = proc.stdout.read()
|
|
||||||
print data
|
print data
|
||||||
|
return data
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
str(msg) + " [getAccessLogs]")
|
str(msg) + " [getAccessLogs]")
|
||||||
print "1,None"
|
print "1,None"
|
||||||
|
return "1,None"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getErrorLogs(fileName, page):
|
def getErrorLogs(fileName, page, externalApp):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if os.path.islink(fileName):
|
if os.path.islink(fileName):
|
||||||
print "0, %s file is symlinked." % (fileName)
|
print "0, %s file is symlinked." % (fileName)
|
||||||
return 0
|
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:
|
if numberOfTotalLines < 25:
|
||||||
data = subprocess.check_output(["cat", fileName])
|
data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), externalApp)
|
||||||
else:
|
else:
|
||||||
if page == 1:
|
if page == 1:
|
||||||
end = numberOfTotalLines
|
end = numberOfTotalLines
|
||||||
@@ -346,8 +347,7 @@ class virtualHostUtilities:
|
|||||||
start = 1
|
start = 1
|
||||||
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
||||||
command = "sed -n " + startingAndEnding + " " + fileName
|
command = "sed -n " + startingAndEnding + " " + fileName
|
||||||
proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
|
data = ProcessUtilities.outputExecutioner(command, externalApp)
|
||||||
data = proc.stdout.read()
|
|
||||||
else:
|
else:
|
||||||
end = numberOfTotalLines - ((page - 1) * 25)
|
end = numberOfTotalLines - ((page - 1) * 25)
|
||||||
start = end - 24
|
start = end - 24
|
||||||
@@ -355,13 +355,14 @@ class virtualHostUtilities:
|
|||||||
start = 1
|
start = 1
|
||||||
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
|
||||||
command = "sed -n " + startingAndEnding + " " + fileName
|
command = "sed -n " + startingAndEnding + " " + fileName
|
||||||
proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
|
data = ProcessUtilities.outputExecutioner(command, externalApp)
|
||||||
data = proc.stdout.read()
|
|
||||||
print data
|
print data
|
||||||
|
return data
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(
|
logging.CyberCPLogFileWriter.writeToFile(
|
||||||
str(msg) + " [getErrorLogs]")
|
str(msg) + " [getErrorLogs]")
|
||||||
print "1,None"
|
print "1,None"
|
||||||
|
return "1,None"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def saveVHostConfigs(fileName, tempPath):
|
def saveVHostConfigs(fileName, tempPath):
|
||||||
|
|||||||
@@ -856,9 +856,7 @@ class WebsiteManager:
|
|||||||
## get Logs
|
## get Logs
|
||||||
website = Websites.objects.get(domain=self.domain)
|
website = Websites.objects.get(domain=self.domain)
|
||||||
|
|
||||||
execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
output = virtualHostUtilities.getAccessLogs(fileName, page, website.externalApp)
|
||||||
execPath = execPath + " getAccessLogs --path " + fileName + " --page " + str(page)
|
|
||||||
output = ProcessUtilities.outputExecutioner(execPath, website.externalApp)
|
|
||||||
|
|
||||||
if output.find("1,None") > -1:
|
if output.find("1,None") > -1:
|
||||||
final_json = json.dumps(
|
final_json = json.dumps(
|
||||||
@@ -916,10 +914,7 @@ class WebsiteManager:
|
|||||||
## get Logs
|
## get Logs
|
||||||
website = Websites.objects.get(domain=self.domain)
|
website = Websites.objects.get(domain=self.domain)
|
||||||
|
|
||||||
execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
output = virtualHostUtilities.getErrorLogs(fileName, page, website.externalApp)
|
||||||
execPath = execPath + " getErrorLogs --path " + fileName + " --page " + str(page)
|
|
||||||
|
|
||||||
output = ProcessUtilities.outputExecutioner(execPath, website.externalApp)
|
|
||||||
|
|
||||||
if output.find("1,None") > -1:
|
if output.find("1,None") > -1:
|
||||||
final_json = json.dumps(
|
final_json = json.dumps(
|
||||||
|
|||||||
Reference in New Issue
Block a user