Files
CyberPanel/tuning/views.py

222 lines
9.1 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.models import Administrator
from loginSystem.views import loadLoginPage
2017-12-09 22:30:10 +05:00
from websiteFunctions.models import Websites,ChildDomains
from plogical.virtualHostUtilities import virtualHostUtilities
import subprocess
import shlex
2017-10-24 19:16:36 +05:00
# Create your views here.
def loadTuningHome(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
2018-06-30 15:29:56 +05:00
return HttpResponse("You don't have enough privileges to access this page.")
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']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
2018-06-30 15:29:56 +05:00
return HttpResponse("You don't have enough privileges to access this page.")
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']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
2018-06-30 15:29:56 +05:00
return HttpResponse("You don't have enough privileges to access this page.")
2017-10-24 19:16:36 +05:00
2017-12-09 22:30:10 +05:00
admin = Administrator.objects.get(pk=request.session['userID'])
websites = Websites.objects.all()
websitesName = []
for items in websites:
websitesName.append(items.domain)
childs = ChildDomains.objects.all()
for items in childs:
websitesName.append(items.domain)
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:
val = request.session['userID']
try:
2018-06-30 15:29:56 +05:00
admin = Administrator.objects.get(pk=val)
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
if admin.type == 1:
if request.method == 'POST':
data = json.loads(request.body)
status = data['status']
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
if status=="fetch":
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
json_data = json.dumps(tuning.fetchTuningDetails())
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
data_ret = {'fetch_status': 1, 'error_message': "None","tuning_data":json_data,'tuneStatus': 0}
2017-10-24 19:16:36 +05:00
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2018-06-30 15:29:56 +05:00
else:
if not data['maxConn']:
data_ret = {'fetch_status': 1, 'error_message': "Provide Max Connections", 'tuneStatus': 0}
final_json = json.dumps(data_ret)
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +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-06-30 15:29:56 +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-06-30 15:29:56 +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-06-30 15:29:56 +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-06-30 15:29:56 +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-06-30 15:29:56 +05:00
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py"
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
execPath = execPath + " saveTuningDetails --maxConn " + maxConn + " --maxSSLConn " + maxSSLConn + " --connTime " + connTime + " --keepAlive " + keepAlive + " --inMemCache '" + inMemCache + "' --gzipCompression " + gzipCompression
2017-12-09 22:30:10 +05:00
2018-06-30 15:29:56 +05:00
output = subprocess.check_output(shlex.split(execPath))
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +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
2018-06-30 15:29:56 +05:00
else:
data_ret = {'fetch_status': 0, 'error_message': "You don't have enough privileges.", 'tuneStatus': 0}
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}
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:
val = request.session['userID']
try:
2018-06-30 15:29:56 +05:00
admin = Administrator.objects.get(pk=val)
if admin.type == 1:
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-06-30 15:29:56 +05:00
if status=="fetch":
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
json_data = json.dumps(tuning.fetchPHPDetails(domainSelection))
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +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-06-30 15:29:56 +05:00
final_json = json.dumps(data_ret)
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +05:00
return HttpResponse(final_json)
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +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-06-30 15:29:56 +05:00
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py"
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +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-06-30 15:29:56 +05:00
output = subprocess.check_output(shlex.split(execPath))
2017-10-24 19:16:36 +05:00
2018-06-30 15:29:56 +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)
else:
data_ret = {'fetch_status': 0, 'error_message': "You don't have enough privileges.", 'tuneStatus': 0}
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)