2017-10-24 19:16:36 +05:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-12-10 15:09:10 +05:00
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
from django.shortcuts import render, redirect
|
2017-10-24 19:16:36 +05:00
|
|
|
from django.http import HttpResponse
|
|
|
|
|
import plogical.CyberCPLogFileWriter as logging
|
|
|
|
|
from loginSystem.views import loadLoginPage
|
|
|
|
|
import json
|
|
|
|
|
import subprocess
|
2018-01-13 21:41:22 +05:00
|
|
|
import psutil
|
|
|
|
|
import socket
|
2018-08-18 00:39:10 +05:00
|
|
|
from plogical.acl import ACLManager
|
2018-11-08 12:11:42 +05:00
|
|
|
import os
|
2018-11-09 22:01:28 +05:00
|
|
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
|
|
|
|
import time
|
2019-12-12 08:46:07 +05:00
|
|
|
import serverStatusUtil
|
2018-11-09 22:01:28 +05:00
|
|
|
from plogical.processUtilities import ProcessUtilities
|
2018-12-13 04:23:08 +05:00
|
|
|
from plogical.httpProc import httpProc
|
2019-04-15 15:54:23 +05:00
|
|
|
from plogical.installUtilities import installUtilities
|
2019-01-09 00:07:36 +05:00
|
|
|
|
|
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
# Create your views here.
|
|
|
|
|
|
2019-11-02 19:29:02 +05:00
|
|
|
NOTHING = 0
|
|
|
|
|
BUNDLE = 2
|
|
|
|
|
EXPIRE = 3
|
|
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
def serverStatusHome(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
2019-01-09 00:07:36 +05:00
|
|
|
return render(request, 'serverStatus/index.html')
|
2017-10-24 19:16:36 +05:00
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
def litespeedStatus(request):
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
processList = ProcessUtilities.getLitespeedProcessNumber()
|
|
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
OLS = 0
|
|
|
|
|
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
|
|
|
|
OLS = 1
|
2019-11-02 19:29:02 +05:00
|
|
|
|
|
|
|
|
message = 0
|
|
|
|
|
|
|
|
|
|
if request.META['QUERY_STRING'] == 'bundle':
|
|
|
|
|
message = ''
|
|
|
|
|
message = BUNDLE
|
|
|
|
|
elif request.META['QUERY_STRING'] == 'expire':
|
|
|
|
|
message = 'It looks like your license has expired. Kindly renew your license.'
|
|
|
|
|
message = EXPIRE
|
|
|
|
|
else:
|
|
|
|
|
message = NOTHING
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
|
|
|
|
|
2019-03-21 23:26:42 +05:00
|
|
|
versionInformation = ProcessUtilities.outputExecutioner(["/usr/local/lsws/bin/lshttpd", "-v"]).split("\n")
|
2017-10-24 19:16:36 +05:00
|
|
|
lsversion = versionInformation[0]
|
|
|
|
|
modules = versionInformation[1]
|
|
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
|
loadedModules = []
|
|
|
|
|
|
|
|
|
|
for items in versionInformation:
|
|
|
|
|
if counter == 0 or counter == 1:
|
|
|
|
|
counter = counter + 1
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
loadedModules.append(items)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2017-10-24 19:16:36 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]")
|
2019-01-09 00:07:36 +05:00
|
|
|
return render(request, "serverStatus/litespeedStatus.html", {"processList": processList,
|
|
|
|
|
"liteSpeedVersionStatus": "For some reaons not able to load version details, see CyberCP main log file.",
|
2019-11-02 19:29:02 +05:00
|
|
|
'OLS': OLS , 'message': message})
|
2019-01-09 00:07:36 +05:00
|
|
|
if (processList != 0):
|
2017-10-24 19:16:36 +05:00
|
|
|
dataForHtml = {"processList": processList, "lsversion": lsversion, "modules": modules,
|
2019-11-02 19:29:02 +05:00
|
|
|
"loadedModules": loadedModules, 'OLS': OLS, 'message': message}
|
2019-01-09 00:07:36 +05:00
|
|
|
return render(request, "serverStatus/litespeedStatus.html", dataForHtml)
|
2017-10-24 19:16:36 +05:00
|
|
|
else:
|
|
|
|
|
dataForHtml = {"lsversion": lsversion, "modules": modules,
|
2019-11-02 19:29:02 +05:00
|
|
|
"loadedModules": loadedModules, 'OLS': OLS, 'message': message}
|
2019-01-09 00:07:36 +05:00
|
|
|
return render(request, "serverStatus/litespeedStatus.html", dataForHtml)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2017-10-24 19:16:36 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]")
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
def stopOrRestartLitespeed(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('reboot', 0)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
|
|
|
|
|
reboot = data['reboot']
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
if reboot == 1:
|
2019-04-15 15:54:23 +05:00
|
|
|
if installUtilities.reStartLiteSpeedSocket() == 1:
|
2019-01-09 00:07:36 +05:00
|
|
|
status = {"reboot": 1, "shutdown": 0}
|
2017-10-24 19:16:36 +05:00
|
|
|
else:
|
2019-01-09 00:07:36 +05:00
|
|
|
status = {"reboot": 0, "shutdown": 0, "error_message": "Please see CyberCP main log file."}
|
2017-10-24 19:16:36 +05:00
|
|
|
else:
|
2019-04-15 15:54:23 +05:00
|
|
|
if installUtilities.stopLiteSpeedSocket() == 1:
|
2019-01-09 00:07:36 +05:00
|
|
|
status = {"reboot": 0, "shutdown": 1}
|
2017-10-24 19:16:36 +05:00
|
|
|
else:
|
2019-01-09 00:07:36 +05:00
|
|
|
status = {"reboot": 0, "shutdown": 0, "error_message": "Please see CyberCP main log file."}
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
final_json = json.dumps(status)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2017-10-24 19:16:36 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[stopOrRestartLitespeed]")
|
|
|
|
|
return HttpResponse("Not Logged in as admin")
|
|
|
|
|
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
def cyberCPMainLogFile(request):
|
2017-10-24 19:16:36 +05:00
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
return render(request, 'serverStatus/cybercpmainlogfile.html')
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2017-10-24 19:16:36 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[cyberCPMainLogFile]")
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2017-10-24 19:16:36 +05:00
|
|
|
def getFurtherDataFromLogFile(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
2018-06-30 15:29:56 +05:00
|
|
|
else:
|
2018-08-18 00:39:10 +05:00
|
|
|
return ACLManager.loadErrorJson('logstatus', 0)
|
|
|
|
|
|
|
|
|
|
fewLinesOfLogFile = logging.CyberCPLogFileWriter.readLastNFiles(50, logging.CyberCPLogFileWriter.fileName)
|
2019-03-26 16:19:03 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
fewLinesOfLogFile = str(fewLinesOfLogFile)
|
|
|
|
|
status = {"logstatus": 1, "logsdata": fewLinesOfLogFile}
|
|
|
|
|
final_json = json.dumps(status)
|
|
|
|
|
return HttpResponse(final_json)
|
2017-10-24 19:16:36 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2019-01-09 00:07:36 +05:00
|
|
|
status = {"logstatus": 0,
|
|
|
|
|
"error": "Could not fetch data from log file, please see CyberCP main log file through command line."}
|
2017-10-24 19:16:36 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[getFurtherDataFromLogFile]")
|
2018-01-13 21:41:22 +05:00
|
|
|
return HttpResponse("Not Logged in as admin")
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-01-13 21:41:22 +05:00
|
|
|
def services(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
2018-08-18 00:39:10 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-01-13 21:41:22 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2018-11-09 22:01:28 +05:00
|
|
|
data = {}
|
|
|
|
|
|
|
|
|
|
if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
|
|
|
|
|
data['serverName'] = 'OpenLiteSpeed'
|
|
|
|
|
else:
|
|
|
|
|
data['serverName'] = 'LiteSpeed Ent'
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2019-01-08 18:09:24 +00:00
|
|
|
dockerInstallPath = '/usr/bin/docker'
|
|
|
|
|
if not os.path.exists(dockerInstallPath):
|
|
|
|
|
data['isDocker'] = False
|
|
|
|
|
else:
|
|
|
|
|
data['isDocker'] = True
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
return render(request, 'serverStatus/services.html', data)
|
2018-01-13 21:41:22 +05:00
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-01-13 21:41:22 +05:00
|
|
|
def servicesStatus(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
2019-07-16 23:23:16 +05:00
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('serviceAction', 0)
|
2018-01-13 21:41:22 +05:00
|
|
|
|
|
|
|
|
lsStatus = []
|
|
|
|
|
sqlStatus = []
|
|
|
|
|
dnsStatus = []
|
|
|
|
|
ftpStatus = []
|
|
|
|
|
mailStatus = []
|
2019-01-08 18:09:24 +00:00
|
|
|
dockerStatus = []
|
2018-01-13 21:41:22 +05:00
|
|
|
|
2019-11-22 13:56:31 +05:00
|
|
|
processlist = ProcessUtilities.outputExecutioner('ps -A')
|
2018-01-13 21:41:22 +05:00
|
|
|
|
|
|
|
|
def getServiceStats(service):
|
|
|
|
|
if service in processlist:
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def getMemStats(service):
|
|
|
|
|
memCount = 0
|
|
|
|
|
for proc in psutil.process_iter():
|
|
|
|
|
if service in proc.name():
|
|
|
|
|
process = psutil.Process(proc.pid)
|
|
|
|
|
memCount += process.memory_info().rss
|
|
|
|
|
return memCount
|
|
|
|
|
|
|
|
|
|
### [1] status [2] mem
|
|
|
|
|
lsStatus.append(getServiceStats('litespeed'))
|
|
|
|
|
if getServiceStats('litespeed'):
|
|
|
|
|
lsStatus.append(getMemStats('litespeed'))
|
|
|
|
|
else:
|
|
|
|
|
lsStatus.append(0)
|
|
|
|
|
|
2019-01-08 18:09:24 +00:00
|
|
|
# Docker status
|
|
|
|
|
dockerStatus.append(getServiceStats('docker'))
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-01-13 21:41:22 +05:00
|
|
|
# mysql status
|
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
result = s.connect_ex(('127.0.0.1', 3306))
|
|
|
|
|
|
|
|
|
|
if result == 0:
|
|
|
|
|
sqlStatus.append(1)
|
|
|
|
|
else:
|
|
|
|
|
sqlStatus.append(0)
|
|
|
|
|
s.close()
|
|
|
|
|
|
|
|
|
|
if getServiceStats('mysql'):
|
|
|
|
|
sqlStatus.append(getMemStats('mysql'))
|
|
|
|
|
else:
|
|
|
|
|
sqlStatus.append(0)
|
|
|
|
|
|
|
|
|
|
dnsStatus.append(getServiceStats('pdns'))
|
|
|
|
|
if getServiceStats('pdns'):
|
|
|
|
|
dnsStatus.append(getMemStats('pdns'))
|
|
|
|
|
else:
|
|
|
|
|
dnsStatus.append(0)
|
|
|
|
|
|
|
|
|
|
ftpStatus.append(getServiceStats('pure-ftpd'))
|
|
|
|
|
if getServiceStats('pure-ftpd'):
|
|
|
|
|
ftpStatus.append(getMemStats('pure-ftpd'))
|
|
|
|
|
else:
|
|
|
|
|
ftpStatus.append(0)
|
|
|
|
|
|
|
|
|
|
mailStatus.append(getServiceStats('postfix'))
|
|
|
|
|
if getServiceStats('postfix'):
|
|
|
|
|
mailStatus.append(getMemStats('postfix'))
|
|
|
|
|
else:
|
|
|
|
|
mailStatus.append(0)
|
|
|
|
|
|
|
|
|
|
json_data = {'status':
|
|
|
|
|
{'litespeed': lsStatus[0],
|
|
|
|
|
'mysql': sqlStatus[0],
|
|
|
|
|
'powerdns': dnsStatus[0],
|
|
|
|
|
'pureftp': ftpStatus[0],
|
2019-01-08 18:09:24 +00:00
|
|
|
'postfix': mailStatus[0],
|
|
|
|
|
'docker': dockerStatus[0]},
|
2018-01-13 21:41:22 +05:00
|
|
|
'memUsage':
|
|
|
|
|
{'litespeed': lsStatus[1],
|
|
|
|
|
'mysql': sqlStatus[1],
|
|
|
|
|
'powerdns': dnsStatus[1],
|
|
|
|
|
'pureftp': ftpStatus[1],
|
|
|
|
|
'postfix': mailStatus[1]}}
|
|
|
|
|
|
|
|
|
|
return HttpResponse(json.dumps(json_data))
|
|
|
|
|
except KeyError:
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-01-13 21:41:22 +05:00
|
|
|
def servicesAction(request):
|
|
|
|
|
try:
|
2018-08-18 00:39:10 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
2018-01-13 21:41:22 +05:00
|
|
|
|
2018-08-18 00:39:10 +05:00
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('serviceAction', 0)
|
2018-01-13 21:41:22 +05:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
service = data['service']
|
|
|
|
|
action = data['action']
|
|
|
|
|
|
|
|
|
|
if action not in ["stop", "start", "restart"]:
|
|
|
|
|
|
|
|
|
|
final_dic = {'serviceAction': 0, "error_message": "Invalid Action"}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
else:
|
|
|
|
|
pass
|
|
|
|
|
|
2019-01-08 18:09:24 +00:00
|
|
|
if service not in ["lsws", "mysql", "pdns", "pure-ftpd", "docker"]:
|
2018-01-13 21:41:22 +05:00
|
|
|
final_dic = {'serviceAction': 0, "error_message": "Invalid Service"}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|
|
else:
|
2018-11-08 12:11:42 +05:00
|
|
|
if service == 'pure-ftpd':
|
|
|
|
|
if os.path.exists("/etc/lsb-release"):
|
|
|
|
|
service = 'pure-ftpd-mysql'
|
|
|
|
|
else:
|
|
|
|
|
service = 'pure-ftpd'
|
2018-05-29 20:20:05 +05:00
|
|
|
|
|
|
|
|
command = 'sudo systemctl %s %s' % (action, service)
|
2019-03-26 16:19:03 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2019-03-30 14:21:52 +05:00
|
|
|
final_dic = {'serviceAction': 1, "error_message": 0}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
2018-01-13 21:41:22 +05:00
|
|
|
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-01-13 21:41:22 +05:00
|
|
|
final_dic = {'serviceAction': 0, 'error_message': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2018-01-13 21:41:22 +05:00
|
|
|
final_dic = {'serviceAction': 0, 'error_message': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
def switchTOLSWS(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('status', 0)
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
|
2019-09-19 13:41:46 +05:00
|
|
|
try:
|
|
|
|
|
licenseKey = data['licenseKey']
|
|
|
|
|
except:
|
|
|
|
|
licenseKey = 'trial'
|
|
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
execPath = "sudo /usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/serverStatus/serverStatusUtil.py"
|
2019-09-19 13:41:46 +05:00
|
|
|
execPath = execPath + " switchTOLSWS --licenseKey " + licenseKey
|
2018-11-09 22:01:28 +05:00
|
|
|
|
2019-03-26 16:19:03 +05:00
|
|
|
ProcessUtilities.popenExecutioner(execPath)
|
2018-11-09 22:01:28 +05:00
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
data_ret = {'status': 1, 'error_message': "None", }
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-11-09 22:01:28 +05:00
|
|
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
def switchTOLSWSStatus(request):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
command = 'sudo cat ' + serverStatusUtil.ServerStatusUtil.lswsInstallStatusPath
|
2019-03-26 16:19:03 +05:00
|
|
|
output = ProcessUtilities.outputExecutioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
if output.find('[404]') > -1:
|
2019-03-30 14:21:52 +05:00
|
|
|
command = "sudo rm -f " + serverStatusUtil.ServerStatusUtil.lswsInstallStatusPath
|
|
|
|
|
ProcessUtilities.popenExecutioner(command)
|
2019-06-08 21:41:43 +00:00
|
|
|
data_ret = {'status': 1, 'abort': 1, 'requestStatus': output, 'installed': 0}
|
2018-11-09 22:01:28 +05:00
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
elif output.find('[200]') > -1:
|
2019-03-30 14:21:52 +05:00
|
|
|
command = "sudo rm -f " + serverStatusUtil.ServerStatusUtil.lswsInstallStatusPath
|
|
|
|
|
ProcessUtilities.popenExecutioner(command)
|
2019-06-08 21:41:43 +00:00
|
|
|
data_ret = {'status': 1, 'abort': 1, 'requestStatus': output, 'installed': 1}
|
2018-11-09 22:01:28 +05:00
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
else:
|
2019-06-08 21:41:43 +00:00
|
|
|
data_ret = {'status': 1, 'abort': 0, 'requestStatus': output, 'installed': 0}
|
2018-11-09 22:01:28 +05:00
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2019-03-30 14:21:52 +05:00
|
|
|
command = "sudo rm -f " + serverStatusUtil.ServerStatusUtil.lswsInstallStatusPath
|
|
|
|
|
ProcessUtilities.popenExecutioner(command)
|
2019-06-08 21:41:43 +00:00
|
|
|
data_ret = {'status': 0,'abort': 1, 'requestStatus': str(msg), 'installed': 0}
|
2018-11-09 22:01:28 +05:00
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
|
|
|
|
def licenseStatus(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('status', 0)
|
|
|
|
|
|
|
|
|
|
command = 'sudo cat /usr/local/lsws/conf/serial.no'
|
2019-03-26 16:19:03 +05:00
|
|
|
serial = ProcessUtilities.outputExecutioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
command = 'sudo /usr/local/lsws/bin/lshttpd -V'
|
2019-03-26 16:19:03 +05:00
|
|
|
expiration = ProcessUtilities.outputExecutioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
final_dic = {'status': 1, "erroMessage": 0, 'lsSerial': serial, 'lsexpiration': expiration}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-11-09 22:01:28 +05:00
|
|
|
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2018-11-09 22:01:28 +05:00
|
|
|
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-11-09 22:01:28 +05:00
|
|
|
def changeLicense(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('status', 0)
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
newKey = data['newKey']
|
|
|
|
|
|
|
|
|
|
command = 'sudo chown -R cyberpanel:cyberpanel /usr/local/lsws/conf'
|
2019-03-26 16:19:03 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
serialPath = '/usr/local/lsws/conf/serial.no'
|
|
|
|
|
serialFile = open(serialPath, 'w')
|
|
|
|
|
serialFile.write(newKey)
|
|
|
|
|
serialFile.close()
|
|
|
|
|
|
|
|
|
|
command = 'sudo chown -R lsadm:lsadm /usr/local/lsws/conf'
|
2019-03-26 16:19:03 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
command = 'sudo /usr/local/lsws/bin/lshttpd -r'
|
2019-03-26 16:19:03 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
command = 'sudo /usr/local/lsws/bin/lswsctrl restart'
|
2019-03-26 16:19:03 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2018-11-09 22:01:28 +05:00
|
|
|
|
|
|
|
|
final_dic = {'status': 1, "erroMessage": 'None'}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-12-13 04:23:08 +05:00
|
|
|
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2018-12-13 04:23:08 +05:00
|
|
|
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-12-13 04:23:08 +05:00
|
|
|
def topProcesses(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
|
|
|
|
|
|
|
|
|
templateName = "serverStatus/topProcesses.html"
|
|
|
|
|
proc = httpProc(request, templateName)
|
|
|
|
|
return proc.renderPre()
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2018-12-13 04:23:08 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]")
|
|
|
|
|
return redirect(loadLoginPage)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-12-13 04:23:08 +05:00
|
|
|
def topProcessesStatus(request):
|
|
|
|
|
try:
|
2019-07-16 23:23:16 +05:00
|
|
|
userID = request.session['userID']
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadError()
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
with open("/home/cyberpanel/top", "w") as outfile:
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call("top -n1 -b", shell=True, stdout=outfile)
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
data = open('/home/cyberpanel/top', 'r').readlines()
|
|
|
|
|
|
|
|
|
|
json_data = "["
|
|
|
|
|
checker = 0
|
|
|
|
|
counter = 0
|
|
|
|
|
|
|
|
|
|
loadAVG = data[0].split(' ')
|
2019-12-10 15:09:10 +05:00
|
|
|
loadAVG = [a for a in loadAVG if a != '']
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
loadNow = data[2].split(' ')
|
2019-12-10 15:09:10 +05:00
|
|
|
loadNow = [a for a in loadNow if a != '']
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
memory = data[3].split(' ')
|
2019-12-10 15:09:10 +05:00
|
|
|
memory = [a for a in memory if a != '']
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
swap = data[4].split(' ')
|
2019-12-10 15:09:10 +05:00
|
|
|
swap = [a for a in swap if a != '']
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
processes = data[1].split(' ')
|
2019-12-10 15:09:10 +05:00
|
|
|
processes = [a for a in processes if a != '']
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
for items in data:
|
|
|
|
|
counter = counter + 1
|
|
|
|
|
if counter <= 7:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
points = items.split(' ')
|
2019-12-10 15:09:10 +05:00
|
|
|
points = [a for a in points if a != '']
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
dic = {'PID': points[0], 'User': points[1], 'VIRT': points[4],
|
|
|
|
|
'RES': points[5], 'S': points[7], 'CPU': points[8], 'MEM': points[9],
|
|
|
|
|
'Time': points[10], 'Command': points[11]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if checker == 0:
|
|
|
|
|
json_data = json_data + json.dumps(dic)
|
|
|
|
|
checker = 1
|
|
|
|
|
else:
|
|
|
|
|
json_data = json_data + ',' + json.dumps(dic)
|
|
|
|
|
|
|
|
|
|
json_data = json_data + ']'
|
|
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
|
data['status'] = 1
|
|
|
|
|
data['error_message'] = 'None'
|
|
|
|
|
data['data'] = json_data
|
|
|
|
|
|
|
|
|
|
## CPU
|
|
|
|
|
data['cpuNow'] = loadNow[1]
|
|
|
|
|
data['cpuOne'] = loadAVG[-3].rstrip(',')
|
|
|
|
|
data['cpuFive'] = loadAVG[-2].rstrip(',')
|
|
|
|
|
data['cpuFifteen'] = loadAVG[-1]
|
|
|
|
|
|
|
|
|
|
## CPU Time spent
|
|
|
|
|
|
|
|
|
|
data['ioWait'] = loadNow[9] + '%'
|
|
|
|
|
data['idleTime'] = loadNow[7] + '%'
|
|
|
|
|
data['hwInterrupts'] = loadNow[11] + '%'
|
|
|
|
|
data['Softirqs'] = loadNow[13] + '%'
|
|
|
|
|
|
|
|
|
|
## Memory
|
2019-01-09 00:07:36 +05:00
|
|
|
data['totalMemory'] = str(int(float(memory[3]) / 1024)) + 'MB'
|
|
|
|
|
data['freeMemory'] = str(int(float(memory[5]) / 1024)) + 'MB'
|
|
|
|
|
data['usedMemory'] = str(int(float(memory[7]) / 1024)) + 'MB'
|
|
|
|
|
data['buffCache'] = str(int(float(memory[9]) / 1024)) + 'MB'
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
## Swap
|
|
|
|
|
|
|
|
|
|
data['swapTotalMemory'] = str(int(float(swap[2]) / 1024)) + 'MB'
|
|
|
|
|
data['swapFreeMemory'] = str(int(float(swap[4]) / 1024)) + 'MB'
|
|
|
|
|
data['swapUsedMemory'] = str(int(float(swap[6]) / 1024)) + 'MB'
|
|
|
|
|
data['swapBuffCache'] = str(int(float(swap[8]) / 1024)) + 'MB'
|
|
|
|
|
|
|
|
|
|
## Processes
|
|
|
|
|
|
|
|
|
|
data['totalProcesses'] = processes[1]
|
|
|
|
|
data['runningProcesses'] = processes[3]
|
|
|
|
|
data['sleepingProcesses'] = processes[5]
|
|
|
|
|
data['stoppedProcesses'] = processes[7]
|
|
|
|
|
data['zombieProcesses'] = processes[9]
|
|
|
|
|
|
|
|
|
|
## CPU Details
|
|
|
|
|
|
|
|
|
|
command = 'sudo cat /proc/cpuinfo'
|
2019-03-30 14:21:52 +05:00
|
|
|
output = ProcessUtilities.outputExecutioner(command).splitlines()
|
2018-12-13 04:23:08 +05:00
|
|
|
|
|
|
|
|
import psutil
|
|
|
|
|
|
|
|
|
|
data['cores'] = psutil.cpu_count()
|
|
|
|
|
|
|
|
|
|
for items in output:
|
|
|
|
|
if items.find('model name') > -1:
|
|
|
|
|
modelName = items.split(':')[1].strip(' ')
|
|
|
|
|
index = modelName.find('CPU')
|
|
|
|
|
data['modelName'] = modelName[0:index]
|
|
|
|
|
elif items.find('cpu MHz') > -1:
|
|
|
|
|
data['cpuMHZ'] = items.split(':')[1].strip(' ')
|
|
|
|
|
elif items.find('cache size') > -1:
|
|
|
|
|
data['cacheSize'] = items.split(':')[1].strip(' ')
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
final_json = json.dumps(data)
|
|
|
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-12-13 04:23:08 +05:00
|
|
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
|
|
|
|
json_data = json.dumps(data_ret)
|
|
|
|
|
return HttpResponse(json_data)
|
|
|
|
|
|
2019-01-09 00:07:36 +05:00
|
|
|
|
2018-12-13 04:23:08 +05:00
|
|
|
def killProcess(request):
|
|
|
|
|
try:
|
|
|
|
|
userID = request.session['userID']
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
|
|
|
|
|
|
|
|
if currentACL['admin'] == 1:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
return ACLManager.loadErrorJson('status', 0)
|
|
|
|
|
|
|
|
|
|
data = json.loads(request.body)
|
|
|
|
|
pid = data['pid']
|
|
|
|
|
|
|
|
|
|
ProcessUtilities.executioner('sudo kill ' + pid)
|
|
|
|
|
|
|
|
|
|
proc = httpProc(request, None)
|
|
|
|
|
return proc.ajax(1, None)
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-11-09 22:01:28 +05:00
|
|
|
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|
2019-12-10 15:09:10 +05:00
|
|
|
except KeyError as msg:
|
2018-11-09 22:01:28 +05:00
|
|
|
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
|
|
|
|
final_json = json.dumps(final_dic)
|
|
|
|
|
return HttpResponse(final_json)
|