HEX
Server: LiteSpeed
System: Linux php-prod-3.spaceapp.ru 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: xnsbl7462 (1008)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/local/CyberCP/tuning/tuning.py
#!/usr/local/CyberCP/bin/python
import os.path
import sys
import django

from plogical.httpProc import httpProc

sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup()
from django.http import HttpResponse
import json
import plogical.CyberCPLogFileWriter as logging
from plogical.tuning import tuning
from loginSystem.views import loadLoginPage
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.acl import ACLManager
from plogical.processUtilities import ProcessUtilities


class tuningManager:
    def loadTuningHome(self, request, userID):
        proc = httpProc(request, 'tuning/index.html',
                        None, 'admin')
        return proc.render()

    def liteSpeedTuning(self, request, userID):
        proc = httpProc(request, 'tuning/liteSpeedTuning.html',
                        None, 'admin')
        return proc.render()

    def phpTuning(self, request, userID):
        currentACL = ACLManager.loadedACL(userID)
        if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
            websitesName = ACLManager.findAllSites(currentACL, userID)
            OLS = 1
            proc = httpProc(request, 'tuning/phpTuning.html',
                            {'websiteList': websitesName, 'OLS': OLS}, 'admin')
            return proc.render()
        else:
            OLS = 0
            proc = httpProc(request, 'tuning/phpTuning.html',
                            {'OLS': OLS}, 'admin')
            return proc.render()

    def tuneLitespeed(self, userID, data):
        try:

            currentACL = ACLManager.loadedACL(userID)

            if currentACL['admin'] == 1:
                pass
            else:
                return ACLManager.loadError()

            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 data.get('maxConn') is None:
                    data_ret = {'fetch_status': 1, 'error_message': "Provide Max Connections", 'tuneStatus': 0}
                    final_json = json.dumps(data_ret)
                    return HttpResponse(final_json)

                if data.get('maxSSLConn') is None:
                    data_ret = {'fetch_status': 1, 'error_message': "Provide Max SSL Connections",
                                'tuneStatus': 0}
                    final_json = json.dumps(data_ret)
                    return HttpResponse(final_json)

                if data.get('keepAlive') is None:
                    data_ret = {'fetch_status': 1, 'error_message': "Provide Keep Alive", 'tuneStatus': 0}
                    final_json = json.dumps(data_ret)
                    return HttpResponse(final_json)

                if data.get('inMemCache') is None:
                    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.get('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 = str(data['maxConn'])
                maxSSLConn = str(data['maxSSLConn'])
                connTime = str(data['connTime'])
                keepAlive = str(data['keepAlive'])
                inMemCache = str(data['inMemCache'])
                gzipCompression = data['gzipCompression']

                execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py"
                execPath = execPath + " saveTuningDetails --maxConn " + maxConn + " --maxSSLConn " + maxSSLConn + " --connTime " + connTime + " --keepAlive " + keepAlive + " --inMemCache '" + inMemCache + "' --gzipCompression " + gzipCompression
                output = ProcessUtilities.outputExecutioner(execPath)

                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)

        except BaseException as msg:
            data_ret = {'fetch_status': 0, 'error_message': str(msg), 'tuneStatus': 0}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)

    def tunePHP(self, userID, data):
        try:

            currentACL = ACLManager.loadedACL(userID)

            if currentACL['admin'] == 1:
                pass
            else:
                return ACLManager.loadError()

            status = data['status']
            domainSelection = data.get('domainSelection')
            
            # Check if domainSelection is None or 'null' string
            if domainSelection is None or domainSelection == 'null' or domainSelection == '':
                data_ret = {'fetch_status': 0, 'error_message': "Please select a domain/PHP version first", 'tuneStatus': 0}
                final_json = json.dumps(data_ret)
                return HttpResponse(final_json)
            
            domainSelection = str(domainSelection)

            if status == "fetch":

                json_data = json.dumps(tuning.fetchPHPDetails(domainSelection))

                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 = str(data['initTimeout'])
                maxConns = str(data['maxConns'])
                memSoftLimit = data['memSoftLimit']
                memHardLimit = data['memHardLimit']
                procSoftLimit = str(data['procSoftLimit'])
                procHardLimit = str(data['procHardLimit'])
                persistConn = data['persistConn']

                execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py"
                execPath = execPath + " tunePHP --virtualHost " + domainSelection + " --initTimeout " + initTimeout + " --maxConns " + maxConns + " --memSoftLimit " + memSoftLimit + " --memHardLimit '" + memHardLimit + "' --procSoftLimit " + procSoftLimit + " --procHardLimit " + procHardLimit + " --persistConn " + persistConn

                output = ProcessUtilities.outputExecutioner(execPath)

                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)

        except BaseException as 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)