Files
CyberPanel/tuning/views.py

209 lines
8.2 KiB
Python
Raw Normal View History

2017-10-24 19:16:36 +05:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render,redirect
from django.http import HttpResponse
import json
import plogical.CyberCPLogFileWriter as logging
from plogical.tuning import tuning
from loginSystem.views import loadLoginPage
2017-12-09 22:30:10 +05:00
from plogical.virtualHostUtilities import virtualHostUtilities
import subprocess
import shlex
2018-08-23 15:39:28 +05:00
from plogical.acl import ACLManager
2017-10-24 19:16:36 +05:00
# Create your views here.
def loadTuningHome(request):
try:
userID = request.session['userID']
2018-08-23 15:39:28 +05:00
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
2017-10-24 19:16:36 +05:00
return render(request,'tuning/index.html',{})
except KeyError:
return redirect(loadLoginPage)
def liteSpeedTuning(request):
try:
userID = request.session['userID']
2018-08-23 15:39:28 +05:00
currentACL = ACLManager.loadedACL(userID)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
2017-10-24 19:16:36 +05:00
return render(request,'tuning/liteSpeedTuning.html',{})
except KeyError:
return redirect(loadLoginPage)
def phpTuning(request):
try:
userID = request.session['userID']
2018-08-23 15:39:28 +05:00
currentACL = ACLManager.loadedACL(userID)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
2017-12-09 22:30:10 +05:00
2018-08-23 15:39:28 +05:00
websitesName = ACLManager.findAllSites(currentACL, userID)
2017-12-09 22:30:10 +05:00
return render(request,'tuning/phpTuning.html',{'websiteList':websitesName})
2017-10-24 19:16:36 +05:00
except KeyError:
return redirect(loadLoginPage)
def tuneLitespeed(request):
try:
2018-08-23 15:39:28 +05:00
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson('fetch_status', 0)
2017-10-24 19:16:36 +05:00
try:
2018-08-23 15:39:28 +05:00
if request.method == 'POST':
data = json.loads(request.body)
status = data['status']
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if status == "fetch":
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
json_data = json.dumps(tuning.fetchTuningDetails())
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
data_ret = {'fetch_status': 1, 'error_message': "None", "tuning_data": json_data, 'tuneStatus': 0}
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
else:
if not data['maxConn']:
data_ret = {'fetch_status': 1, 'error_message': "Provide Max Connections", 'tuneStatus': 0}
2017-10-24 19:16:36 +05:00
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2018-08-23 15:39:28 +05:00
if not data['maxSSLConn']:
data_ret = {'fetch_status': 1, 'error_message': "Provide Max SSL Connections", 'tuneStatus': 0}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if not data['keepAlive']:
data_ret = {'fetch_status': 1, 'error_message': "Provide Keep Alive", 'tuneStatus': 0}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if not data['inMemCache']:
data_ret = {'fetch_status': 1, 'error_message': "Provide Cache Size in memory", 'tuneStatus': 0}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if not data['gzipCompression']:
data_ret = {'fetch_status': 1, 'error_message': "Provide Enable GZIP Compression",
'tuneStatus': 0}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
maxConn = data['maxConn']
maxSSLConn = data['maxSSLConn']
connTime = data['connTime']
keepAlive = data['keepAlive']
inMemCache = data['inMemCache']
gzipCompression = data['gzipCompression']
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py"
2017-12-09 22:30:10 +05:00
2018-08-23 15:39:28 +05:00
execPath = execPath + " saveTuningDetails --maxConn " + maxConn + " --maxSSLConn " + maxSSLConn + " --connTime " + connTime + " --keepAlive " + keepAlive + " --inMemCache '" + inMemCache + "' --gzipCompression " + gzipCompression
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
output = subprocess.check_output(shlex.split(execPath))
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if output.find("1,None") > -1:
data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 1}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
else:
data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 0}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
except BaseException,msg:
data_ret = {'fetch_status': 0, 'error_message': str(msg), 'tuneStatus': 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError:
2018-06-30 15:29:56 +05:00
data_ret = {'fetch_status': 0, 'error_message': "not logged in as admin",'fetch_status': 0}
2017-10-24 19:16:36 +05:00
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def tunePHP(request):
try:
2018-08-23 15:39:28 +05:00
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson('fetch_status', 0)
try:
if request.method == 'POST':
data = json.loads(request.body)
status = data['status']
domainSelection = str(data['domainSelection'])
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if status == "fetch":
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
json_data = json.dumps(tuning.fetchPHPDetails(domainSelection))
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
data_ret = {'fetch_status': 1, 'error_message': "None", "tuning_data": json_data, 'tuneStatus': 0}
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
final_json = json.dumps(data_ret)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
else:
initTimeout = str(data['initTimeout'])
maxConns = str(data['maxConns'])
memSoftLimit = data['memSoftLimit']
memHardLimit = data['memHardLimit']
procSoftLimit = str(data['procSoftLimit'])
procHardLimit = str(data['procHardLimit'])
persistConn = data['persistConn']
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py"
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
execPath = execPath + " tunePHP --virtualHost " + domainSelection + " --initTimeout " + initTimeout + " --maxConns " + maxConns + " --memSoftLimit " + memSoftLimit + " --memHardLimit '" + memHardLimit + "' --procSoftLimit " + procSoftLimit + " --procHardLimit " + procHardLimit + " --persistConn " + persistConn
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
output = subprocess.check_output(shlex.split(execPath))
2017-10-24 19:16:36 +05:00
2018-08-23 15:39:28 +05:00
if output.find("1,None") > -1:
data_ret = {'tuneStatus': 1, 'fetch_status': 0, 'error_message': "None"}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
else:
data_ret = {'fetch_status': 0, 'error_message': output, 'tuneStatus': 0}
logging.CyberCPLogFileWriter.writeToFile(output + " [tunePHP]]")
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
2017-10-24 19:16:36 +05:00
except BaseException,msg:
data_ret = {'fetch_status': 0, 'error_message': str(msg),'tuneStatus': 0}
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [tunePHP]]")
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError:
data_ret = {'tuneStatus': 0, 'error_message': "not logged in as admin",'fetch_status': 0}
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [tunePHP]]")
json_data = json.dumps(data_ret)
return HttpResponse(json_data)