mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-15 09:46:11 +01:00
Initial Commit
This commit is contained in:
230
tuning/views.py
Normal file
230
tuning/views.py
Normal file
@@ -0,0 +1,230 @@
|
||||
# -*- 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
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def loadTuningHome(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough priviliges to access this page.")
|
||||
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:
|
||||
return HttpResponse("You don't have enough priviliges to access this page.")
|
||||
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:
|
||||
return HttpResponse("You don't have enough priviliges to access this page.")
|
||||
|
||||
return render(request,'tuning/phpTuning.html',{})
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
|
||||
def tuneLitespeed(request):
|
||||
|
||||
try:
|
||||
val = request.session['userID']
|
||||
|
||||
try:
|
||||
|
||||
if request.method == 'POST':
|
||||
data = json.loads(request.body)
|
||||
status = data['status']
|
||||
|
||||
if status=="fetch":
|
||||
|
||||
json_data = json.dumps(tuning.fetchTuningDetails())
|
||||
|
||||
data_ret = {'fetch_status': 1, 'error_message': "None","tuning_data":json_data,'tuneStatus': 0}
|
||||
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
maxConn = data['maxConn']
|
||||
maxSSLConn = data['maxSSLConn']
|
||||
connTime = data['connTime']
|
||||
keepAlive = data['keepAlive']
|
||||
inMemCache = data['inMemCache']
|
||||
gzipCompression = data['gzipCompression']
|
||||
|
||||
|
||||
|
||||
if gzipCompression == "Enable":
|
||||
gzip = 1
|
||||
else:
|
||||
gzip = 0
|
||||
|
||||
|
||||
if tuning.saveTuningDetails(maxConn,maxSSLConn,connTime,keepAlive,inMemCache,gzip)==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)
|
||||
|
||||
|
||||
|
||||
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:
|
||||
data_ret = {'tuneStatus': 0, 'error_message': "not logged in as admin",'fetch_status': 0}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
def tunePHP(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
|
||||
try:
|
||||
|
||||
if request.method == 'POST':
|
||||
data = json.loads(request.body)
|
||||
status = data['status']
|
||||
|
||||
if status=="fetch":
|
||||
|
||||
phpVers = str(data['finalPHP'])
|
||||
finalPHP = 0
|
||||
|
||||
if phpVers == "PHP 5.3":
|
||||
finalPHP = 53
|
||||
|
||||
elif phpVers == "PHP 5.4":
|
||||
finalPHP = 54
|
||||
|
||||
elif phpVers == "PHP 5.5":
|
||||
finalPHP = 55
|
||||
|
||||
elif phpVers == "PHP 5.6":
|
||||
finalPHP = 56
|
||||
|
||||
elif phpVers == "PHP 7.0":
|
||||
finalPHP = 70
|
||||
elif phpVers == "PHP 7.1":
|
||||
finalPHP = 71
|
||||
|
||||
json_data = json.dumps(tuning.fetchPHPDetails(finalPHP))
|
||||
|
||||
data_ret = {'fetch_status': 1, 'error_message': "None","tuning_data":json_data,'tuneStatus': 0}
|
||||
|
||||
final_json = json.dumps(data_ret)
|
||||
|
||||
return HttpResponse(final_json)
|
||||
|
||||
else:
|
||||
initTimeout = data['initTimeout']
|
||||
maxConns = data['maxConns']
|
||||
memSoftLimit = data['memSoftLimit']
|
||||
memHardLimit = data['memHardLimit']
|
||||
procSoftLimit = data['procSoftLimit']
|
||||
procHardLimit = data['procHardLimit']
|
||||
persistConn = data['persistConn']
|
||||
|
||||
phpVers = str(data['finalPHP'])
|
||||
finalPHP = 0
|
||||
|
||||
if phpVers == "PHP 5.3":
|
||||
finalPHP = 53
|
||||
|
||||
elif phpVers == "PHP 5.4":
|
||||
finalPHP = 54
|
||||
|
||||
elif phpVers == "PHP 5.5":
|
||||
finalPHP = 55
|
||||
|
||||
elif phpVers == "PHP 5.6":
|
||||
finalPHP = 56
|
||||
|
||||
elif phpVers == "PHP 7.0":
|
||||
finalPHP = 70
|
||||
|
||||
|
||||
tuning.tunePHP(finalPHP,maxConns,initTimeout,persistConn,memSoftLimit,memHardLimit,procSoftLimit,procHardLimit)
|
||||
|
||||
data_ret = {'fetch_status': 0, 'error_message': "None",'tuneStatus': 1}
|
||||
|
||||
final_json = json.dumps(data_ret)
|
||||
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user