diff --git a/api/views.py b/api/views.py index d8fed2a67..bef494afe 100644 --- a/api/views.py +++ b/api/views.py @@ -567,8 +567,9 @@ def changeAdminPassword(request): 'error_message': "None"} json_data = json.dumps(data_ret) return HttpResponse(json_data) + os.remove(randomFile) - admin = Administrator.objects.get(pk="admin") + admin = Administrator.objects.get(userName="admin") admin.password = hashPassword.hash_password(adminPass) admin.save() data_ret = {"changed": 1, diff --git a/firewall/firewallManager.py b/firewall/firewallManager.py index aca646aec..d34581a31 100644 --- a/firewall/firewallManager.py +++ b/firewall/firewallManager.py @@ -13,16 +13,15 @@ from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex from plogical.installUtilities import installUtilities -from django.shortcuts import HttpResponse, render, redirect -from loginSystem.models import Administrator +from django.shortcuts import HttpResponse, render from random import randint import time -from loginSystem.views import loadLoginPage from plogical.firewallUtilities import FirewallUtilities from firewall.models import FirewallRules import thread from plogical.modSec import modSec from plogical.csf import CSF +from plogical.processUtilities import ProcessUtilities class FirewallManager: @@ -604,18 +603,24 @@ class FirewallManager: else: return ACLManager.loadError() - confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + OLS = 1 + confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") - command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() - modSecInstalled = 0 + modSecInstalled = 0 - for items in httpdConfig: - if items.find('module mod_security') > -1: - modSecInstalled = 1 - break - return render(request, 'firewall/modSecurity.html', {'modSecInstalled': modSecInstalled}) + for items in httpdConfig: + if items.find('module mod_security') > -1: + modSecInstalled = 1 + break + else: + OLS = 0 + modSecInstalled = 1 + + return render(request, 'firewall/modSecurity.html', {'modSecInstalled': modSecInstalled, 'OLS': OLS}) except BaseException, msg: return HttpResponse(str(msg)) @@ -702,29 +707,89 @@ class FirewallManager: else: return ACLManager.loadErrorJson('fetchStatus', 0) - modsecurity = 0 - SecAuditEngine = 0 - SecRuleEngine = 0 - SecDebugLogLevel = "9" - SecAuditLogRelevantStatus = '^(?:5|4(?!04))' - SecAuditLogParts = 'ABIJDEFHZ' - SecAuditLogType = 'Serial' + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - confPath = os.path.join(virtualHostUtilities.Server_root, 'conf/httpd_config.conf') - modSecPath = os.path.join(virtualHostUtilities.Server_root, 'modules', 'mod_security.so') + modsecurity = 0 + SecAuditEngine = 0 + SecRuleEngine = 0 + SecDebugLogLevel = "9" + SecAuditLogRelevantStatus = '^(?:5|4(?!04))' + SecAuditLogParts = 'ABIJDEFHZ' + SecAuditLogType = 'Serial' - if os.path.exists(modSecPath): + confPath = os.path.join(virtualHostUtilities.Server_root, 'conf/httpd_config.conf') + modSecPath = os.path.join(virtualHostUtilities.Server_root, 'modules', 'mod_security.so') + + if os.path.exists(modSecPath): + command = "sudo cat " + confPath + data = subprocess.check_output(shlex.split(command)).splitlines() + + for items in data: + + if items.find('modsecurity ') > -1: + if items.find('on') > -1 or items.find('On') > -1: + modsecurity = 1 + continue + if items.find('SecAuditEngine ') > -1: + if items.find('on') > -1 or items.find('On') > -1: + SecAuditEngine = 1 + continue + + if items.find('SecRuleEngine ') > -1: + if items.find('on') > -1 or items.find('On') > -1: + SecRuleEngine = 1 + continue + + if items.find('SecDebugLogLevel') > -1: + result = items.split(' ') + if result[0] == 'SecDebugLogLevel': + SecDebugLogLevel = result[1] + continue + if items.find('SecAuditLogRelevantStatus') > -1: + result = items.split(' ') + if result[0] == 'SecAuditLogRelevantStatus': + SecAuditLogRelevantStatus = result[1] + continue + if items.find('SecAuditLogParts') > -1: + result = items.split(' ') + if result[0] == 'SecAuditLogParts': + SecAuditLogParts = result[1] + continue + if items.find('SecAuditLogType') > -1: + result = items.split(' ') + if result[0] == 'SecAuditLogType': + SecAuditLogType = result[1] + continue + + final_dic = {'fetchStatus': 1, + 'installed': 1, + 'SecRuleEngine': SecRuleEngine, + 'modsecurity': modsecurity, + 'SecAuditEngine': SecAuditEngine, + 'SecDebugLogLevel': SecDebugLogLevel, + 'SecAuditLogParts': SecAuditLogParts, + 'SecAuditLogRelevantStatus': SecAuditLogRelevantStatus, + 'SecAuditLogType': SecAuditLogType, + } + + else: + final_dic = {'fetchStatus': 1, + 'installed': 0} + else: + SecAuditEngine = 0 + SecRuleEngine = 0 + SecDebugLogLevel = "9" + SecAuditLogRelevantStatus = '^(?:5|4(?!04))' + SecAuditLogParts = 'ABIJDEFHZ' + SecAuditLogType = 'Serial' + + confPath = os.path.join(virtualHostUtilities.Server_root, 'conf/modsec.conf') command = "sudo cat " + confPath data = subprocess.check_output(shlex.split(command)).splitlines() for items in data: - - if items.find('modsecurity ') > -1: - if items.find('on') > -1 or items.find('On') > -1: - modsecurity = 1 - continue if items.find('SecAuditEngine ') > -1: if items.find('on') > -1 or items.find('On') > -1: SecAuditEngine = 1 @@ -759,7 +824,6 @@ class FirewallManager: final_dic = {'fetchStatus': 1, 'installed': 1, 'SecRuleEngine': SecRuleEngine, - 'modsecurity': modsecurity, 'SecAuditEngine': SecAuditEngine, 'SecDebugLogLevel': SecDebugLogLevel, 'SecAuditLogParts': SecAuditLogParts, @@ -767,10 +831,6 @@ class FirewallManager: 'SecAuditLogType': SecAuditLogType, } - else: - final_dic = {'fetchStatus': 1, - 'installed': 0} - final_json = json.dumps(final_dic) return HttpResponse(final_json) @@ -788,68 +848,126 @@ class FirewallManager: else: return ACLManager.loadErrorJson('saveStatus', 0) - modsecurity = data['modsecurity_status'] - SecAuditEngine = data['SecAuditEngine'] - SecRuleEngine = data['SecRuleEngine'] - SecDebugLogLevel = data['SecDebugLogLevel'] - SecAuditLogParts = data['SecAuditLogParts'] - SecAuditLogRelevantStatus = data['SecAuditLogRelevantStatus'] - SecAuditLogType = data['SecAuditLogType'] + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - if modsecurity == True: - modsecurity = "modsecurity on" + modsecurity = data['modsecurity_status'] + SecAuditEngine = data['SecAuditEngine'] + SecRuleEngine = data['SecRuleEngine'] + SecDebugLogLevel = data['SecDebugLogLevel'] + SecAuditLogParts = data['SecAuditLogParts'] + SecAuditLogRelevantStatus = data['SecAuditLogRelevantStatus'] + SecAuditLogType = data['SecAuditLogType'] + + if modsecurity == True: + modsecurity = "modsecurity on" + else: + modsecurity = "modsecurity off" + + if SecAuditEngine == True: + SecAuditEngine = "SecAuditEngine on" + else: + SecAuditEngine = "SecAuditEngine off" + + if SecRuleEngine == True: + SecRuleEngine = "SecRuleEngine On" + else: + SecRuleEngine = "SecRuleEngine off" + + SecDebugLogLevel = "SecDebugLogLevel " + str(SecDebugLogLevel) + SecAuditLogParts = "SecAuditLogParts " + str(SecAuditLogParts) + SecAuditLogRelevantStatus = "SecAuditLogRelevantStatus " + SecAuditLogRelevantStatus + SecAuditLogType = "SecAuditLogType " + SecAuditLogType + + ## writing data temporary to file + + + tempConfigPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + + confPath = open(tempConfigPath, "w") + + confPath.writelines(modsecurity + "\n") + confPath.writelines(SecAuditEngine + "\n") + confPath.writelines(SecRuleEngine + "\n") + confPath.writelines(SecDebugLogLevel + "\n") + confPath.writelines(SecAuditLogParts + "\n") + confPath.writelines(SecAuditLogRelevantStatus + "\n") + confPath.writelines(SecAuditLogType + "\n") + + confPath.close() + + ## save configuration data + + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" + + execPath = execPath + " saveModSecConfigs --tempConfigPath " + tempConfigPath + + output = subprocess.check_output(shlex.split(execPath)) + + if output.find("1,None") > -1: + installUtilities.reStartLiteSpeed() + data_ret = {'saveStatus': 1, 'error_message': "None"} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'saveStatus': 0, 'error_message': output} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) else: - modsecurity = "modsecurity off" + SecAuditEngine = data['SecAuditEngine'] + SecRuleEngine = data['SecRuleEngine'] + SecDebugLogLevel = data['SecDebugLogLevel'] + SecAuditLogParts = data['SecAuditLogParts'] + SecAuditLogRelevantStatus = data['SecAuditLogRelevantStatus'] + SecAuditLogType = data['SecAuditLogType'] - if SecAuditEngine == True: - SecAuditEngine = "SecAuditEngine on" - else: - SecAuditEngine = "SecAuditEngine off" + if SecAuditEngine == True: + SecAuditEngine = "SecAuditEngine on" + else: + SecAuditEngine = "SecAuditEngine off" - if SecRuleEngine == True: - SecRuleEngine = "SecRuleEngine On" - else: - SecRuleEngine = "SecRuleEngine off" + if SecRuleEngine == True: + SecRuleEngine = "SecRuleEngine On" + else: + SecRuleEngine = "SecRuleEngine off" - SecDebugLogLevel = "SecDebugLogLevel " + str(SecDebugLogLevel) - SecAuditLogParts = "SecAuditLogParts " + str(SecAuditLogParts) - SecAuditLogRelevantStatus = "SecAuditLogRelevantStatus " + SecAuditLogRelevantStatus - SecAuditLogType = "SecAuditLogType " + SecAuditLogType + SecDebugLogLevel = "SecDebugLogLevel " + str(SecDebugLogLevel) + SecAuditLogParts = "SecAuditLogParts " + str(SecAuditLogParts) + SecAuditLogRelevantStatus = "SecAuditLogRelevantStatus " + SecAuditLogRelevantStatus + SecAuditLogType = "SecAuditLogType " + SecAuditLogType - ## writing data temporary to file + ## writing data temporary to file - tempConfigPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + tempConfigPath = "/home/cyberpanel/" + str(randint(1000, 9999)) - confPath = open(tempConfigPath, "w") + confPath = open(tempConfigPath, "w") - confPath.writelines(modsecurity + "\n") - confPath.writelines(SecAuditEngine + "\n") - confPath.writelines(SecRuleEngine + "\n") - confPath.writelines(SecDebugLogLevel + "\n") - confPath.writelines(SecAuditLogParts + "\n") - confPath.writelines(SecAuditLogRelevantStatus + "\n") - confPath.writelines(SecAuditLogType + "\n") + confPath.writelines(SecAuditEngine + "\n") + confPath.writelines(SecRuleEngine + "\n") + confPath.writelines(SecDebugLogLevel + "\n") + confPath.writelines(SecAuditLogParts + "\n") + confPath.writelines(SecAuditLogRelevantStatus + "\n") + confPath.writelines(SecAuditLogType + "\n") - confPath.close() + confPath.close() - ## save configuration data + ## save configuration data - execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" - execPath = execPath + " saveModSecConfigs --tempConfigPath " + tempConfigPath + execPath = execPath + " saveModSecConfigs --tempConfigPath " + tempConfigPath - output = subprocess.check_output(shlex.split(execPath)) + output = subprocess.check_output(shlex.split(execPath)) - if output.find("1,None") > -1: - installUtilities.reStartLiteSpeed() - data_ret = {'saveStatus': 1, 'error_message': "None"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - else: - data_ret = {'saveStatus': 0, 'error_message': output} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + if output.find("1,None") > -1: + installUtilities.reStartLiteSpeed() + data_ret = {'saveStatus': 1, 'error_message': "None"} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'saveStatus': 0, 'error_message': output} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) except BaseException, msg: data_ret = {'saveStatus': 0, 'error_message': str(msg)} @@ -866,17 +984,20 @@ class FirewallManager: else: return ACLManager.loadError() - confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") - command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() - modSecInstalled = 0 + modSecInstalled = 0 - for items in httpdConfig: - if items.find('module mod_security') > -1: - modSecInstalled = 1 - break + for items in httpdConfig: + if items.find('module mod_security') > -1: + modSecInstalled = 1 + break + else: + modSecInstalled = 1 return render(request, 'firewall/modSecurityRules.html', {'modSecInstalled': modSecInstalled}) @@ -892,21 +1013,39 @@ class FirewallManager: else: return ACLManager.loadErrorJson('modSecInstalled', 0) - confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") - modSecInstalled = 0 + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() - for items in httpdConfig: - if items.find('module mod_security') > -1: - modSecInstalled = 1 - break + modSecInstalled = 0 - rulesPath = os.path.join(virtualHostUtilities.Server_root + "/conf/modsec/rules.conf") + for items in httpdConfig: + if items.find('module mod_security') > -1: + modSecInstalled = 1 + break + + rulesPath = os.path.join(virtualHostUtilities.Server_root + "/conf/modsec/rules.conf") + + if modSecInstalled: + command = "sudo cat " + rulesPath + currentModSecRules = subprocess.check_output(shlex.split(command)) + + final_dic = {'modSecInstalled': 1, + 'currentModSecRules': currentModSecRules} + + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + else: + final_dic = {'modSecInstalled': 0} + + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + else: + rulesPath = os.path.join(virtualHostUtilities.Server_root + "/conf/rules.conf") - if modSecInstalled: command = "sudo cat " + rulesPath currentModSecRules = subprocess.check_output(shlex.split(command)) @@ -915,11 +1054,6 @@ class FirewallManager: final_json = json.dumps(final_dic) return HttpResponse(final_json) - else: - final_dic = {'modSecInstalled': 0} - - final_json = json.dumps(final_dic) - return HttpResponse(final_json) except BaseException, msg: final_dic = {'modSecInstalled': 0, @@ -941,17 +1075,13 @@ class FirewallManager: ## writing data temporary to file rulesPath = open(modSec.tempRulesFile, "w") - rulesPath.write(newModSecRules) - rulesPath.close() ## save configuration data execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" - execPath = execPath + " saveModSecRules" - output = subprocess.check_output(shlex.split(execPath)) if output.find("1,None") > -1: @@ -979,17 +1109,21 @@ class FirewallManager: else: return ACLManager.loadError() - confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") - modSecInstalled = 0 + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() - for items in httpdConfig: - if items.find('module mod_security') > -1: - modSecInstalled = 1 - break + modSecInstalled = 0 + + for items in httpdConfig: + if items.find('module mod_security') > -1: + modSecInstalled = 1 + break + else: + modSecInstalled = 1 return render(request, 'firewall/modSecurityRulesPacks.html', {'modSecInstalled': modSecInstalled}) @@ -1006,47 +1140,70 @@ class FirewallManager: else: return ACLManager.loadErrorJson('modSecInstalled', 0) - confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") - command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() - - modSecInstalled = 0 - - for items in httpdConfig: - if items.find('module mod_security') > -1: - modSecInstalled = 1 - break - - comodoInstalled = 0 - owaspInstalled = 0 - - if modSecInstalled: command = "sudo cat " + confPath httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + modSecInstalled = 0 + for items in httpdConfig: - - if items.find('modsec/comodo') > -1: - comodoInstalled = 1 - elif items.find('modsec/owasp') > -1: - owaspInstalled = 1 - - if owaspInstalled == 1 and comodoInstalled == 1: + if items.find('module mod_security') > -1: + modSecInstalled = 1 break + comodoInstalled = 0 + owaspInstalled = 0 + + if modSecInstalled: + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + + for items in httpdConfig: + + if items.find('modsec/comodo') > -1: + comodoInstalled = 1 + elif items.find('modsec/owasp') > -1: + owaspInstalled = 1 + + if owaspInstalled == 1 and comodoInstalled == 1: + break + + final_dic = { + 'modSecInstalled': 1, + 'owaspInstalled': owaspInstalled, + 'comodoInstalled': comodoInstalled + } + + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + else: + final_dic = {'modSecInstalled': 0} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + else: + comodoInstalled = 0 + owaspInstalled = 0 + + try: + command = 'sudo cat /usr/local/lsws/conf/comodo_litespeed/rules.conf.main' + res = subprocess.call(shlex.split(command)) + + if res == 0: + comodoInstalled = 1 + except subprocess.CalledProcessError: + pass + final_dic = { 'modSecInstalled': 1, 'owaspInstalled': owaspInstalled, 'comodoInstalled': comodoInstalled } + final_json = json.dumps(final_dic) + return HttpResponse(final_json) - final_json = json.dumps(final_dic) - return HttpResponse(final_json) - else: - final_dic = {'modSecInstalled': 0} - final_json = json.dumps(final_dic) - return HttpResponse(final_json) except BaseException, msg: final_dic = {'modSecInstalled': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) @@ -1064,21 +1221,40 @@ class FirewallManager: packName = data['packName'] - execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - execPath = execPath + " " + packName + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" + execPath = execPath + " " + packName - output = subprocess.check_output(shlex.split(execPath)) + output = subprocess.check_output(shlex.split(execPath)) - if output.find("1,None") > -1: - installUtilities.reStartLiteSpeed() - data_ret = {'installStatus': 1, 'error_message': "None"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + if output.find("1,None") > -1: + installUtilities.reStartLiteSpeed() + data_ret = {'installStatus': 1, 'error_message': "None"} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'installStatus': 0, 'error_message': output} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) else: - data_ret = {'installStatus': 0, 'error_message': output} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + if packName == 'disableOWASP' or packName == 'installOWASP': + final_json = json.dumps({'installStatus': 0, 'error_message': "OWASP will be available later.", }) + return HttpResponse(final_json) + + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" + execPath = execPath + " " + packName + output = subprocess.check_output(shlex.split(execPath)) + + if output.find("1,None") > -1: + installUtilities.reStartLiteSpeed() + data_ret = {'installStatus': 1, 'error_message': "None"} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'installStatus': 0, 'error_message': output} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) except BaseException, msg: data_ret = {'installStatus': 0, 'error_message': str(msg)} @@ -1096,26 +1272,70 @@ class FirewallManager: packName = data['packName'] - confPath = os.path.join(virtualHostUtilities.Server_root, 'conf/httpd_config.conf') + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + confPath = os.path.join(virtualHostUtilities.Server_root, 'conf/httpd_config.conf') - command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + command = "sudo cat " + confPath + httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() - json_data = "[" - checker = 0 - counter = 0 + json_data = "[" + checker = 0 + counter = 0 - for items in httpdConfig: + for items in httpdConfig: - if items.find('modsec/' + packName) > -1: - counter = counter + 1 - if items[0] == '#': - status = False + if items.find('modsec/' + packName) > -1: + counter = counter + 1 + if items[0] == '#': + status = False + else: + status = True + + fileName = items.lstrip('#') + fileName = fileName.split('/')[-1] + + dic = { + 'id': counter, + 'fileName': fileName, + 'packName': packName, + 'status': status, + + } + + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + + json_data = json_data + ']' + final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data}) + return HttpResponse(final_json) + else: + if packName == 'owasp': + final_json = json.dumps({'fetchStatus': 0, 'error_message': "OWASP will be available later.", }) + return HttpResponse(final_json) + + comodoPath = '/usr/local/lsws/conf/comodo_litespeed' + command = 'sudo chown -R cyberpanel:cyberpanel /usr/local/lsws/conf' + subprocess.call(shlex.split(command)) + + json_data = "[" + + counter = 0 + checker = 0 + for fileName in os.listdir(comodoPath): + + if fileName == 'categories.conf': + continue + + if fileName.endswith('dis'): + status = 0 + fileName = fileName.rstrip('.dis') + elif fileName.endswith('conf'): + status = 1 else: - status = True - - fileName = items.lstrip('#') - fileName = fileName.split('/')[-1] + continue dic = { 'id': counter, @@ -1125,15 +1345,20 @@ class FirewallManager: } + counter = counter + 1 + if checker == 0: json_data = json_data + json.dumps(dic) checker = 1 else: json_data = json_data + ',' + json.dumps(dic) - json_data = json_data + ']' - final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data}) - return HttpResponse(final_json) + command = 'sudo chown -R lsadm:lsadm /usr/local/lsws/conf' + subprocess.call(shlex.split(command)) + + json_data = json_data + ']' + final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data}) + return HttpResponse(final_json) except BaseException, msg: final_dic = {'fetchStatus': 0, 'error_message': str(msg)} diff --git a/firewall/static/firewall/firewall.js b/firewall/static/firewall/firewall.js index ba9df9207..bb0e4a07f 100644 --- a/firewall/static/firewall/firewall.js +++ b/firewall/static/firewall/firewall.js @@ -3,10 +3,6 @@ */ - - - - /* Java script code to ADD Firewall Rules */ app.controller('firewallController', function($scope,$http) { @@ -548,8 +544,6 @@ app.controller('firewallController', function($scope,$http) { /* Java script code to ADD Firewall Rules */ - - /* Java script code to Secure SSH */ app.controller('secureSSHCTRL', function($scope,$http) { diff --git a/firewall/templates/firewall/modSecurity.html b/firewall/templates/firewall/modSecurity.html index e0476e917..768caa26e 100644 --- a/firewall/templates/firewall/modSecurity.html +++ b/firewall/templates/firewall/modSecurity.html @@ -3,189 +3,396 @@ {% block title %}{% trans "ModSecurity - CyberPanel" %}{% endblock %} {% block content %} -{% load static %} -{% get_current_language as LANGUAGE_CODE %} - + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + {% if OLS %} -
-
-

{% trans "ModSecurity Configurations!" %} - {% trans "ModSec Docs" %}

-

{% trans "On this page you can configure ModSecurity settings." %}

-
+
+
+

{% trans "ModSecurity Configurations!" %} - {% trans "ModSec Docs" %} +

+

{% trans "On this page you can configure ModSecurity settings." %}

+
-
-
-

- {% trans "ModSecurity" %} -

+
+
+

+ {% trans "ModSecurity" %} +

-
-
+
+
- {% if modSecInstalled == 0 %} + {% if modSecInstalled == 0 %} -
-

{% trans "ModSecurity is not installed " %} -

-
- - - -
- -
- -
-

{% trans "Failed to start installation, Error message: " %} {$ errorMessage $}

+
+

{% trans "ModSecurity is not installed " %} + +

-
-

{% trans "Could not connect. Please refresh this page." %}

-
+ -
-

{% trans "Installation failed." %} {$ errorMessage $}

-
+
+ +
-
-

{% trans "ModSecurity successfully installed, refreshing page in 3 seconds.." %}

-
-
-
+
+

{% trans "Failed to start installation, Error message: " %} {$ + errorMessage + $}

+
- -
- -
-
-
-

{% trans "Winter is coming, but so is ModSecurity." %}

-
-
- -
-
-
-
- - - - {% else %} - -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
-
{$ SecDebugLogLevel $}
-
-
- -
- -
- -
-
- - -
- -
- -
-
- -
- -
- -
-
- - - -
- -
- - -
-
- - - -
- -
- -
-

{% trans "Failed to save ModSecurity configurations. Error message: " %} {$ errorMessage $}

-
- -
-

{% trans "ModSecurity configurations successfully saved." %}

-
- -
+

{% trans "Could not connect. Please refresh this page." %}

+
+ +
+

{% trans "Installation failed." %} {$ errorMessage $}

+
+ +
+

{% trans "ModSecurity successfully installed, refreshing page in 3 seconds.." %}

+
+
+ + +
+ + +
+
+

{% trans "Winter is coming, but so is ModSecurity." %} +

+
+
+ +
+
+ +
+ + + + {% else %} + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
{$ SecDebugLogLevel $}
+
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+ +
+

{% trans "Failed to save ModSecurity configurations. Error message: " %} + {$ errorMessage $}

+
+ +
+

{% trans "ModSecurity configurations successfully saved." %}

+
+ +
+

{% trans "Could not connect. Please refresh this page." %}

+
+ +
+
+ + +
+
+ + {% endif %} + -
- - - -
- - {% endif %} - - - +
+ +
-
+ + {% else %} + +
+
+

{% trans "ModSecurity Configurations!" %} - {% trans "ModSec Docs" %} +

+

{% trans "On this page you can configure ModSecurity settings." %}

+
+ +
+
+

+ {% trans "ModSecurity" %} +

+ +
+
+ + {% if modSecInstalled == 0 %} + +
+

{% trans "ModSecurity is not installed " %} + +

+
+ + + +
+ +
+ +
+

{% trans "Failed to start installation, Error message: " %} {$ + errorMessage $}

+
+ +
+

{% trans "Could not connect. Please refresh this page." %}

+
+ +
+

{% trans "Installation failed." %} {$ errorMessage $}

+
+ +
+

{% trans "ModSecurity successfully installed, refreshing page in 3 seconds.." %}

+
+
+
-
+
+ +
+
+
+

{% trans "Winter is coming, but so is ModSecurity." %} +

+
+
+ +
+
+
+
+ + + + {% else %} + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
{$ SecDebugLogLevel $}
+
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+ +
+

{% trans "Failed to save ModSecurity configurations. Error message: " %} + {$ errorMessage $}

+
+ +
+

{% trans "ModSecurity configurations successfully saved." %}

+
+ +
+

{% trans "Could not connect. Please refresh this page." %}

+
+ +
+
+ + +
+
+ + {% endif %} + + +
+
+
+
+ + +
+ + {% endif %} {% endblock %} \ No newline at end of file diff --git a/ftp/ftpManager.py b/ftp/ftpManager.py index e7ce81ef5..8dc4b85f4 100644 --- a/ftp/ftpManager.py +++ b/ftp/ftpManager.py @@ -79,12 +79,9 @@ class FTPManager: path = 'None' execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/ftpUtilities.py" - execPath = execPath + " submitFTPCreation --domainName " + domainName + " --userName " + userName \ + " --password " + password + " --path " + path + " --owner " + admin.userName + ' --api ' + api - output = subprocess.check_output(shlex.split(execPath)) - if output.find("1,None") > -1: data_ret = {'status': 1, 'creatFTPStatus': 1, 'error_message': 'None'} json_data = json.dumps(data_ret) diff --git a/install/install.py b/install/install.py index 923701a88..48d37e65a 100644 --- a/install/install.py +++ b/install/install.py @@ -296,24 +296,26 @@ class preFlightsChecks: preFlightsChecks.stdOut("Exception during CyberPanel install") os._exit(os.EX_SOFTWARE) - else: - while(1): - cmd.append("rpm") - cmd.append("-ivh") - cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm") - res = subprocess.call(cmd) + else: + while (1): + cmd.append("rpm") + cmd.append("-ivh") + cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm") + res = subprocess.call(cmd) - if res == 1: - count = count + 1 - preFlightsChecks.stdOut("Unable to add CyberPanel official repository, trying again, try number: " + str(count) + "\n") - if count == 3: - logging.InstallLog.writeToFile("Unable to add CyberPanel official repository, exiting installer! [installCyberPanelRepo]") - preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") - os._exit(0) - else: - logging.InstallLog.writeToFile("CyberPanel Repo added!") - preFlightsChecks.stdOut("CyberPanel Repo added!") - break + if res == 1: + count = count + 1 + preFlightsChecks.stdOut( + "Unable to add CyberPanel official repository, trying again, try number: " + str(count) + "\n") + if count == 3: + logging.InstallLog.writeToFile( + "Unable to add CyberPanel official repository, exiting installer! [installCyberPanelRepo]") + preFlightsChecks.stdOut("Installation failed, consult: /var/log/installLogs.txt") + os._exit(0) + else: + logging.InstallLog.writeToFile("CyberPanel Repo added!") + preFlightsChecks.stdOut("CyberPanel Repo added!") + break def enableEPELRepo(self): try: diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index 4942079ef..d591262cd 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -234,7 +234,6 @@ class InstallCyberPanel: 'lsphp7?-ldap lsphp7?-mysql lsphp7?-opcache lsphp7?-pspell lsphp7?-recode ' \ 'lsphp7?-sqlite3 lsphp7?-tidy' res = os.system(command) - else: command = 'yum -y groupinstall lsphp-all' cmd = shlex.split(command) diff --git a/plogical/CyberCPLogFileWriter.py b/plogical/CyberCPLogFileWriter.py index dc2d11890..2ff68a41d 100644 --- a/plogical/CyberCPLogFileWriter.py +++ b/plogical/CyberCPLogFileWriter.py @@ -41,7 +41,7 @@ class CyberCPLogFileWriter: @staticmethod def statusWriter(tempStatusPath, mesg): try: - statusFile = open(tempStatusPath, 'w') + statusFile = open(tempStatusPath, 'a') statusFile.writelines(mesg) statusFile.close() except BaseException, msg: diff --git a/plogical/filemanager.py b/plogical/filemanager.py index 2c95c8ca8..69faec37a 100644 --- a/plogical/filemanager.py +++ b/plogical/filemanager.py @@ -1,12 +1,7 @@ -import os.path -import shutil import CyberCPLogFileWriter as logging -import subprocess import argparse -import shlex from random import randint - class filemanager: @staticmethod @@ -25,7 +20,7 @@ class filemanager: except BaseException,msg: logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [createEmailAccount]") + str(msg) + " [createTemporaryFile]") print "0," + str(msg) diff --git a/plogical/installUtilities.py b/plogical/installUtilities.py index 7b697e50d..dfbf42fd1 100644 --- a/plogical/installUtilities.py +++ b/plogical/installUtilities.py @@ -4,8 +4,8 @@ import CyberCPLogFileWriter as logging import shutil import pexpect import os -import thread import shlex +from processUtilities import ProcessUtilities class installUtilities: @@ -136,15 +136,15 @@ class installUtilities: @staticmethod def reStartLiteSpeed(): try: - FNULL = open(os.devnull, 'w') - command = "sudo systemctl restart lsws" + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + command = "sudo systemctl restart lsws" + else: + command = "sudo /usr/local/lsws/bin/lswsctrl restart" cmd = shlex.split(command) - - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) - + subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]") @@ -159,12 +159,12 @@ class installUtilities: def reStartOpenLiteSpeed(restart,orestart): try: - FNULL = open(os.devnull, 'w') - - command = "sudo systemctl restart lsws" + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + command = "sudo systemctl restart lsws" + else: + command = "sudo /usr/local/lsws/bin/lswsctrl restart" cmd = shlex.split(command) - res = subprocess.call(cmd) if res == 1: @@ -177,7 +177,6 @@ class installUtilities: print(" Litespeed Re-Started ") print("###############################################") - except OSError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartOpenLiteSpeed]") return 0 @@ -279,8 +278,6 @@ class installUtilities: return 1 - - @staticmethod def installMainWebServer(): if installUtilities.enableEPELRepo() == 1: @@ -370,7 +367,6 @@ class installUtilities: return 1 - @staticmethod def startMariaDB(): @@ -406,7 +402,6 @@ class installUtilities: return 1 - @staticmethod def installMySQL(password): diff --git a/plogical/modSec.py b/plogical/modSec.py index efcfae27b..60ec1f8bf 100644 --- a/plogical/modSec.py +++ b/plogical/modSec.py @@ -7,6 +7,7 @@ import os import tarfile import shutil from mailUtilities import mailUtilities +from processUtilities import ProcessUtilities class modSec: installLogPath = "/home/cyberpanel/modSecInstallLog" @@ -111,42 +112,74 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf data = open(tempConfigPath).readlines() os.remove(tempConfigPath) - confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - confData = open(confFile).readlines() + confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + confData = open(confFile).readlines() + conf = open(confFile, 'w') - conf = open(confFile, 'w') + for items in confData: - for items in confData: + if items.find('modsecurity ') > -1: + conf.writelines(data[0]) + continue + elif items.find('SecAuditEngine ') > -1: + conf.writelines(data[1]) + continue + elif items.find('SecRuleEngine ') > -1: + conf.writelines(data[2]) + continue + elif items.find('SecDebugLogLevel') > -1: + conf.writelines(data[3]) + continue + elif items.find('SecAuditLogRelevantStatus ') > -1: + conf.writelines(data[5]) + continue + elif items.find('SecAuditLogParts ') > -1: + conf.writelines(data[4]) + continue + elif items.find('SecAuditLogType ') > -1: + conf.writelines(data[6]) + continue + else: + conf.writelines(items) - if items.find('modsecurity ') > -1: - conf.writelines(data[0]) - continue - elif items.find('SecAuditEngine ') > -1: - conf.writelines(data[1]) - continue - elif items.find('SecRuleEngine ') > -1: - conf.writelines(data[2]) - continue - elif items.find('SecDebugLogLevel') > -1: - conf.writelines(data[3]) - continue - elif items.find('SecAuditLogRelevantStatus ') > -1: - conf.writelines(data[5]) - continue - elif items.find('SecAuditLogParts ') > -1: - conf.writelines(data[4]) - continue - elif items.find('SecAuditLogType ') > -1: - conf.writelines(data[6]) - continue - else: - conf.writelines(items) + conf.close() - conf.close() + print "1,None" + return + else: + confFile = os.path.join(virtualHostUtilities.Server_root, "conf/modsec.conf") + confData = open(confFile).readlines() + conf = open(confFile, 'w') - print "1,None" - return + for items in confData: + + if items.find('SecAuditEngine ') > -1: + conf.writelines(data[0]) + continue + elif items.find('SecRuleEngine ') > -1: + conf.writelines(data[1]) + continue + elif items.find('SecDebugLogLevel') > -1: + conf.writelines(data[2]) + continue + elif items.find('SecAuditLogRelevantStatus ') > -1: + conf.writelines(data[4]) + continue + elif items.find('SecAuditLogParts ') > -1: + conf.writelines(data[3]) + continue + elif items.find('SecAuditLogType ') > -1: + conf.writelines(data[5]) + continue + else: + conf.writelines(items) + + conf.close() + + print "1,None" + return except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( @@ -160,7 +193,10 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf data = rulesFile.read() rulesFile.close() - rulesFilePath = os.path.join(virtualHostUtilities.Server_root, "conf/modsec/rules.conf") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + rulesFilePath = os.path.join(virtualHostUtilities.Server_root, "conf/modsec/rules.conf") + else: + rulesFilePath = os.path.join(virtualHostUtilities.Server_root, "conf/rules.conf") rulesFile = open(rulesFilePath,'w') rulesFile.write(data) @@ -180,26 +216,47 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf @staticmethod def setupComodoRules(): try: - pathTOOWASPFolder = os.path.join(virtualHostUtilities.Server_root, "conf/modsec/comodo") - extractLocation = os.path.join(virtualHostUtilities.Server_root, "conf/modsec") - if os.path.exists(pathTOOWASPFolder): - shutil.rmtree(pathTOOWASPFolder) + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + pathTOOWASPFolder = os.path.join(virtualHostUtilities.Server_root, "conf/modsec/comodo") + extractLocation = os.path.join(virtualHostUtilities.Server_root, "conf/modsec") - if os.path.exists('comodo.tar.gz'): - os.remove('comodo.tar.gz') + if os.path.exists(pathTOOWASPFolder): + shutil.rmtree(pathTOOWASPFolder) - command = "wget https://" + modSec.mirrorPath + "/modsec/comodo.tar.gz" - result = subprocess.call(shlex.split(command)) + if os.path.exists('comodo.tar.gz'): + os.remove('comodo.tar.gz') - if result == 1: - return 0 + command = "wget https://" + modSec.mirrorPath + "/modsec/comodo.tar.gz" + result = subprocess.call(shlex.split(command)) - tar = tarfile.open('comodo.tar.gz') - tar.extractall(extractLocation) - tar.close() + if result == 1: + return 0 - return 1 + tar = tarfile.open('comodo.tar.gz') + tar.extractall(extractLocation) + tar.close() + + return 1 + else: + if os.path.exists('/usr/local/lsws/conf/comodo_litespeed'): + shutil.rmtree('/usr/local/lsws/conf/comodo_litespeed') + + extractLocation = os.path.join(virtualHostUtilities.Server_root, "conf") + + if os.path.exists('cpanel_litespeed_vendor'): + os.remove('cpanel_litespeed_vendor') + + command = "wget https://waf.comodo.com/api/cpanel_litespeed_vendor" + result = subprocess.call(shlex.split(command)) + + if result == 1: + return 0 + + command = "unzip cpanel_litespeed_vendor -d " + extractLocation + subprocess.call(shlex.split(command)) + + return 1 except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( @@ -209,60 +266,85 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf @staticmethod def installComodo(): try: - if modSec.setupComodoRules() == 0: - print '0, Unable to download Comodo Rules.' + + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + if modSec.setupComodoRules() == 0: + print '0, Unable to download Comodo Rules.' + return + + owaspRulesConf = """modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/modsecurity.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/00_Init_Initialization.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/01_Init_AppsInitialization.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/02_Global_Generic.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/03_Global_Agents.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/04_Global_Domains.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/05_Global_Backdoor.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/06_XSS_XSS.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/07_Global_Other.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/08_Bruteforce_Bruteforce.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/09_HTTP_HTTP.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/10_HTTP_HTTPDoS.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/11_HTTP_Protocol.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/12_HTTP_Request.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/13_Outgoing_FilterGen.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/14_Outgoing_FilterASP.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/15_Outgoing_FilterPHP.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/16_Outgoing_FilterSQL.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/17_Outgoing_FilterOther.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/18_Outgoing_FilterInFrame.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/19_Outgoing_FiltersEnd.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/20_PHP_PHPGen.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/21_SQL_SQLi.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/22_Apps_Joomla.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/23_Apps_JComponent.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/24_Apps_WordPress.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/25_Apps_WPPlugin.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/26_Apps_WHMCS.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/27_Apps_Drupal.conf + modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/28_Apps_OtherApps.conf + """ + + confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + + confData = open(confFile).readlines() + + conf = open(confFile, 'w') + + for items in confData: + if items.find('/usr/local/lsws/conf/modsec/rules.conf') > -1: + conf.writelines(items) + conf.write(owaspRulesConf) + continue + else: + conf.writelines(items) + + conf.close() + + print "1,None" return + else: + if os.path.exists('/usr/local/lsws/conf/comodo_litespeed'): + shutil.rmtree('/usr/local/lsws/conf/comodo_litespeed') - owaspRulesConf = """modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/modsecurity.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/00_Init_Initialization.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/01_Init_AppsInitialization.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/02_Global_Generic.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/03_Global_Agents.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/04_Global_Domains.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/05_Global_Backdoor.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/06_XSS_XSS.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/07_Global_Other.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/08_Bruteforce_Bruteforce.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/09_HTTP_HTTP.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/10_HTTP_HTTPDoS.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/11_HTTP_Protocol.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/12_HTTP_Request.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/13_Outgoing_FilterGen.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/14_Outgoing_FilterASP.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/15_Outgoing_FilterPHP.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/16_Outgoing_FilterSQL.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/17_Outgoing_FilterOther.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/18_Outgoing_FilterInFrame.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/19_Outgoing_FiltersEnd.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/20_PHP_PHPGen.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/21_SQL_SQLi.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/22_Apps_Joomla.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/23_Apps_JComponent.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/24_Apps_WordPress.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/25_Apps_WPPlugin.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/26_Apps_WHMCS.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/27_Apps_Drupal.conf -modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/28_Apps_OtherApps.conf -""" + extractLocation = os.path.join(virtualHostUtilities.Server_root, "conf") - confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + if os.path.exists('cpanel_litespeed_vendor'): + os.remove('cpanel_litespeed_vendor') - confData = open(confFile).readlines() + command = "wget https://waf.comodo.com/api/cpanel_litespeed_vendor" + result = subprocess.call(shlex.split(command)) - conf = open(confFile, 'w') + if result == 1: + return 0 - for items in confData: - if items.find('/usr/local/lsws/conf/modsec/rules.conf') > -1: - conf.writelines(items) - conf.write(owaspRulesConf) - continue - else: - conf.writelines(items) + command = "unzip cpanel_litespeed_vendor -d " + extractLocation + result = subprocess.call(shlex.split(command)) - conf.close() + command = 'sudo chown -R lsadm:lsadm /usr/local/lsws/conf' + subprocess.call(shlex.split(command)) - print "1,None" - return + print "1,None" + return except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( @@ -273,19 +355,28 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/comodo/28_Apps_OtherApps.conf def disableComodo(): try: - confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") - confData = open(confFile).readlines() - conf = open(confFile, 'w') + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + confFile = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") + confData = open(confFile).readlines() + conf = open(confFile, 'w') - for items in confData: - if items.find('modsec/comodo') > -1: - continue - else: - conf.writelines(items) + for items in confData: + if items.find('modsec/comodo') > -1: + continue + else: + conf.writelines(items) - conf.close() + conf.close() + + print "1,None" + + else: + try: + shutil.rmtree('/usr/local/lsws/conf/comodo_litespeed') + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [disableComodo]') + print "1,None" - print "1,None" except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index a87264190..e86a1b081 100644 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -1,11 +1,15 @@ from CyberCPLogFileWriter import CyberCPLogFileWriter as logging import subprocess import shlex - - +import os +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging class ProcessUtilities: litespeedProcess = "litespeed" + ent = 1 + OLS = 0 + centos = 1 + ubuntu = 0 @staticmethod def getLitespeedProcessNumber(): @@ -14,7 +18,7 @@ class ProcessUtilities: try: import psutil for proc in psutil.process_iter(): - if proc.name() == ProcessUtilities.litespeedProcess: + if proc.name().find(ProcessUtilities.litespeedProcess) > -1: finalListOfProcesses.append(proc.pid) except BaseException,msg: @@ -30,7 +34,11 @@ class ProcessUtilities: @staticmethod def restartLitespeed(): try: - command = "sudo systemctl restart lsws" + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + command = "sudo systemctl restart lsws" + else: + command = "sudo /usr/local/lsws/bin/lswsctrl restart" + cmd = shlex.split(command) res = subprocess.call(cmd) @@ -45,7 +53,11 @@ class ProcessUtilities: @staticmethod def stopLitespeed(): try: - command = "sudo systemctl stop lsws" + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + command = "sudo systemctl stop lsws" + else: + command = "sudo /usr/local/lsws/bin/lswsctrl stop" + cmd = shlex.split(command) res = subprocess.call(cmd) @@ -57,4 +69,58 @@ class ProcessUtilities: except subprocess.CalledProcessError, msg: logging.writeToFile(str(msg) + "[stopLitespeed]") + @staticmethod + def executioner(command): + try: + res = subprocess.call(shlex.split(command)) + if res == 1: + raise 0 + else: + return 1 + except BaseException, msg: + return 0 + + @staticmethod + def killLiteSpeed(): + pids = ProcessUtilities.getLitespeedProcessNumber() + if pids !=0: + for items in pids: + try: + command = 'sudo kill -9 ' + str(items) + ProcessUtilities.executioner(command) + except: + pass + + @staticmethod + def decideServer(): + entPath = '/usr/local/lsws/bin/lshttpd' + + if os.readlink(entPath) == '/usr/local/lsws/bin/lshttpd/openlitespeed': + return ProcessUtilities.OLS + else: + return ProcessUtilities.ent + + @staticmethod + def decideDistro(): + distroPath = '/etc/lsb-release' + + if os.path.exists(distroPath): + return ProcessUtilities.ubuntu + else: + return ProcessUtilities.centos + + @staticmethod + def executioner(command, statusFile): + try: + res = subprocess.call(shlex.split(command), stdout=statusFile, stderr=statusFile) + if res == 1: + raise 0 + else: + return 1 + + except BaseException, msg: + logging.writeToFile(str(msg)) + return 0 + + diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index 13b66b51f..687a3432c 100644 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -1,9 +1,10 @@ import CyberCPLogFileWriter as logging -import shutil import os import shlex import subprocess import socket +from plogical.processUtilities import ProcessUtilities +from websiteFunctions.models import ChildDomains, Websites class sslUtilities: @@ -58,109 +59,189 @@ class sslUtilities: return [0, "347 " + str(msg) + " [issueSSLForDomain]"] @staticmethod - def installSSLForDomain(virtualHostName): + def installSSLForDomain(virtualHostName, adminEmail='usman@cyberpersons.com'): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + confPath = sslUtilities.Server_root + "/conf/vhosts/" + virtualHostName + completePathToConfigFile = confPath + "/vhost.conf" - confPath = sslUtilities.Server_root + "/conf/vhosts/" + virtualHostName - completePathToConfigFile = confPath + "/vhost.conf" - - try: - map = " map " + virtualHostName + " " + virtualHostName + "\n" - - if sslUtilities.checkSSLListener() != 1: - - writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'a') - - listener = "listener SSL {" + "\n" - address = " address *:443" + "\n" - secure = " secure 1" + "\n" - keyFile = " keyFile /etc/letsencrypt/live/" + virtualHostName + "/privkey.pem\n" - certFile = " certFile /etc/letsencrypt/live/" + virtualHostName + "/fullchain.pem\n" - certChain = " certChain 1" + "\n" - sslProtocol = " sslProtocol 30" + "\n" + try: map = " map " + virtualHostName + " " + virtualHostName + "\n" - final = "}" + "\n" + "\n" - writeDataToFile.writelines("\n") - writeDataToFile.writelines(listener) - writeDataToFile.writelines(address) - writeDataToFile.writelines(secure) - writeDataToFile.writelines(keyFile) - writeDataToFile.writelines(certFile) - writeDataToFile.writelines(certChain) - writeDataToFile.writelines(sslProtocol) - writeDataToFile.writelines(map) - writeDataToFile.writelines(final) - writeDataToFile.writelines("\n") - writeDataToFile.close() + if sslUtilities.checkSSLListener() != 1: + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'a') - else: - - if sslUtilities.checkIfSSLMap(virtualHostName) == 0: - - data = open("/usr/local/lsws/conf/httpd_config.conf").readlines() - writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w') - sslCheck = 0 - - for items in data: - if items.find("listener") > -1 and items.find("SSL") > -1: - sslCheck = 1 - - if (sslCheck == 1): - writeDataToFile.writelines(items) - writeDataToFile.writelines(map) - sslCheck = 0 - else: - writeDataToFile.writelines(items) - writeDataToFile.close() - - ###################### Write per host Configs for SSL ################### - - data = open(completePathToConfigFile, "r").readlines() - - ## check if vhssl is already in vhconf file - - vhsslPresense = 0 - - for items in data: - if items.find("vhssl") > -1: - vhsslPresense = 1 - - if vhsslPresense == 0: - writeSSLConfig = open(completePathToConfigFile, "a") - - vhssl = "vhssl {" + "\n" - keyFile = " keyFile /etc/letsencrypt/live/" + virtualHostName + "/privkey.pem\n" - certFile = " certFile /etc/letsencrypt/live/" + virtualHostName + "/fullchain.pem\n" + listener = "listener SSL {" + "\n" + address = " address *:443" + "\n" + secure = " secure 1" + "\n" + keyFile = " keyFile /etc/letsencrypt/live/" + virtualHostName + "/privkey.pem\n" + certFile = " certFile /etc/letsencrypt/live/" + virtualHostName + "/fullchain.pem\n" certChain = " certChain 1" + "\n" sslProtocol = " sslProtocol 30" + "\n" - final = "}" + map = " map " + virtualHostName + " " + virtualHostName + "\n" + final = "}" + "\n" + "\n" - writeSSLConfig.writelines("\n") + writeDataToFile.writelines("\n") + writeDataToFile.writelines(listener) + writeDataToFile.writelines(address) + writeDataToFile.writelines(secure) + writeDataToFile.writelines(keyFile) + writeDataToFile.writelines(certFile) + writeDataToFile.writelines(certChain) + writeDataToFile.writelines(sslProtocol) + writeDataToFile.writelines(map) + writeDataToFile.writelines(final) + writeDataToFile.writelines("\n") + writeDataToFile.close() - writeSSLConfig.writelines(vhssl) - writeSSLConfig.writelines(keyFile) - writeSSLConfig.writelines(certFile) - writeSSLConfig.writelines(certChain) - writeSSLConfig.writelines(sslProtocol) - writeSSLConfig.writelines(final) - writeSSLConfig.writelines("\n") + else: - writeSSLConfig.close() + if sslUtilities.checkIfSSLMap(virtualHostName) == 0: - return 1 + data = open("/usr/local/lsws/conf/httpd_config.conf").readlines() + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w') + sslCheck = 0 + + for items in data: + if items.find("listener") > -1 and items.find("SSL") > -1: + sslCheck = 1 + + if (sslCheck == 1): + writeDataToFile.writelines(items) + writeDataToFile.writelines(map) + sslCheck = 0 + else: + writeDataToFile.writelines(items) + writeDataToFile.close() + + ###################### Write per host Configs for SSL ################### + + data = open(completePathToConfigFile, "r").readlines() + + ## check if vhssl is already in vhconf file + + vhsslPresense = 0 + + for items in data: + if items.find("vhssl") > -1: + vhsslPresense = 1 + + if vhsslPresense == 0: + writeSSLConfig = open(completePathToConfigFile, "a") + + vhssl = "vhssl {" + "\n" + keyFile = " keyFile /etc/letsencrypt/live/" + virtualHostName + "/privkey.pem\n" + certFile = " certFile /etc/letsencrypt/live/" + virtualHostName + "/fullchain.pem\n" + certChain = " certChain 1" + "\n" + sslProtocol = " sslProtocol 30" + "\n" + final = "}" + + writeSSLConfig.writelines("\n") + + writeSSLConfig.writelines(vhssl) + writeSSLConfig.writelines(keyFile) + writeSSLConfig.writelines(certFile) + writeSSLConfig.writelines(certChain) + writeSSLConfig.writelines(sslProtocol) + writeSSLConfig.writelines(final) + + writeSSLConfig.writelines("\n") + + writeSSLConfig.close() + + return 1 + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [installSSLForDomain]]") + return 0 + else: + confPath = sslUtilities.Server_root + "/conf/vhosts/" + virtualHostName + completePathToConfigFile = confPath + "/vhost.conf" + + ## Check if SSL VirtualHost already exists + + data = open(completePathToConfigFile, 'r').readlines() + + for items in data: + if items.find('*:443') > -1: + return 1 + + try: + + try: + chilDomain = ChildDomains.objects.get(domain=virtualHostName) + externalApp = chilDomain.master.externalApp + DocumentRoot = ' DocumentRoot ' + chilDomain.path + '\n' + except BaseException, msg: + website = Websites.objects.get(domain=virtualHostName) + externalApp = website.externalApp + DocumentRoot = ' DocumentRoot /home/' + virtualHostName + '/public_html\n' + + data = open(completePathToConfigFile, 'r').readlines() + phpHandler = '' + + for items in data: + if items.find('AddHandler') > -1 and items.find('php') > -1: + phpHandler = items + break + + confFile = open(completePathToConfigFile, 'a') + + doNotModify = '\n\n# Do not modify this file, this is auto-generated file.\n\n' + + VirtualHost = '\n\n' + ServerName = ' ServerName ' + virtualHostName + '\n' + ServerAlias = ' ServerAlias www.' + virtualHostName + '\n' + ScriptAlias = ' Alias /.filemanager/ /usr/local/lsws/FileManager\n' + ServerAdmin = ' ServerAdmin ' + adminEmail + '\n' + SeexecUserGroup = ' SuexecUserGroup ' + externalApp + ' ' + externalApp + '\n' + CustomLogCombined = ' CustomLog /home/' + virtualHostName + '/logs/' + virtualHostName + '.access_log combined\n' + + confFile.writelines(doNotModify) + confFile.writelines(VirtualHost) + confFile.writelines(ServerName) + confFile.writelines(ServerAlias) + confFile.writelines(ScriptAlias) + confFile.writelines(ServerAdmin) + confFile.writelines(SeexecUserGroup) + confFile.writelines(DocumentRoot) + confFile.writelines(CustomLogCombined) + DirectoryFileManager = """\n + AllowOverride All + Options +Includes -Indexes +ExecCGI + php_value display_errors "Off" + php_value upload_max_filesize "200M" + php_value post_max_size "250M" + \n""" + confFile.writelines(DirectoryFileManager) + + SSLEngine = ' SSLEngine on\n' + SSLVerifyClient = ' SSLVerifyClient none\n' + SSLCertificateFile = ' SSLCertificateFile /etc/letsencrypt/live/' + virtualHostName + '/fullchain.pem\n' + SSLCertificateKeyFile = ' SSLCertificateKeyFile /etc/letsencrypt/live/' + virtualHostName + '/privkey.pem\n' + + confFile.writelines(SSLEngine) + confFile.writelines(SSLVerifyClient) + confFile.writelines(SSLCertificateFile) + confFile.writelines(SSLCertificateKeyFile) + confFile.writelines(phpHandler) + + VirtualHostEnd = '\n' + confFile.writelines(VirtualHostEnd) + confFile.close() + return 1 + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [installSSLForDomain]") + return 0 - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [installSSLForDomain]]") - return 0 @staticmethod def obtainSSLForADomain(virtualHostName,adminEmail,sslpath, aliasDomain = None): try: acmePath = '/root/.acme.sh/acme.sh' - if os.path.exists('/etc/lsb-release'): + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: acmePath = '/home/cyberpanel/.acme.sh/acme.sh' if not os.path.exists(acmePath): @@ -239,30 +320,13 @@ class sslUtilities: def issueSSLForDomain(domain, adminEmail, sslpath, aliasDomain = None): try: - if sslUtilities.obtainSSLForADomain(domain, adminEmail, sslpath, aliasDomain) == 1: - - if sslUtilities.installSSLForDomain(domain) == 1: + if sslUtilities.installSSLForDomain(domain, adminEmail) == 1: return [1, "None"] else: return [0, "210 Failed to install SSL for domain. [issueSSLForDomain]"] else: - pathToStoreSSL = "/etc/letsencrypt/live/" + domain - command = 'mkdir -p ' + pathToStoreSSL - subprocess.call(shlex.split(command)) - - pathToStoreSSLPrivKey = "/etc/letsencrypt/live/" + domain + "/privkey.pem" - pathToStoreSSLFullChain = "/etc/letsencrypt/live/" + domain + "/fullchain.pem" - - command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout ' + pathToStoreSSLPrivKey + ' -out ' + pathToStoreSSLFullChain - cmd = shlex.split(command) - subprocess.call(cmd) - - if sslUtilities.installSSLForDomain(domain) == 1: - logging.CyberCPLogFileWriter.writeToFile("Self signed SSL issued for " + domain + ".") - return [1, "None"] - else: - return [0, "220 Failed to install SSL for domain. [issueSSLForDomain]"] + return [0, "283 Failed to obtain SSL for domain. [issueSSLForDomain]"] except BaseException,msg: return [0, "347 "+ str(msg)+ " [issueSSLForDomain]"] \ No newline at end of file diff --git a/plogical/vhost.py b/plogical/vhost.py index a8aa849ce..e9932c80e 100644 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -16,6 +16,7 @@ from databases.models import Databases from mysqlUtilities import mysqlUtilities from dnsUtilities import DNS from random import randint +from processUtilities import ProcessUtilities ## If you want justice, you have come to the wrong place. @@ -87,7 +88,12 @@ class vhost: cmd = shlex.split(command) subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) - command = "chmod -R 666 " + pathLogs + + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + command = "chmod -R 666 " + pathLogs + else: + command = "chmod -R 755 " + pathLogs + cmd = shlex.split(command) subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) @@ -176,215 +182,279 @@ class vhost: @staticmethod def perHostVirtualConf(vhFile, administratorEmail,virtualHostUser, phpVersion, virtualHostName, openBasedir): # General Configurations tab - try: - confFile = open(vhFile, "w+") + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + confFile = open(vhFile, "w+") - docRoot = "docRoot $VH_ROOT/public_html" + "\n" - vhDomain = "vhDomain $VH_NAME" + "\n" - vhAliases = "vhAliases www.$VH_NAME"+ "\n" - adminEmails = "adminEmails " + administratorEmail + "\n" - enableGzip = "enableGzip 1" + "\n" - enableIpGeo = "enableIpGeo 1" + "\n" + "\n" + docRoot = "docRoot $VH_ROOT/public_html" + "\n" + vhDomain = "vhDomain $VH_NAME" + "\n" + vhAliases = "vhAliases www.$VH_NAME"+ "\n" + adminEmails = "adminEmails " + administratorEmail + "\n" + enableGzip = "enableGzip 1" + "\n" + enableIpGeo = "enableIpGeo 1" + "\n" + "\n" - confFile.writelines(docRoot) - confFile.writelines(vhDomain) - confFile.writelines(vhAliases) - confFile.writelines(adminEmails) - confFile.writelines(enableGzip) - confFile.writelines(enableIpGeo) + confFile.writelines(docRoot) + confFile.writelines(vhDomain) + confFile.writelines(vhAliases) + confFile.writelines(adminEmails) + confFile.writelines(enableGzip) + confFile.writelines(enableIpGeo) - # Index file settings + # Index file settings - index = "index {" + "\n" - userServer = " useServer 0" + "\n" - indexFiles = " indexFiles index.php, index.html" + "\n" - index_end = "}" + "\n" + "\n" + index = "index {" + "\n" + userServer = " useServer 0" + "\n" + indexFiles = " indexFiles index.php, index.html" + "\n" + index_end = "}" + "\n" + "\n" - confFile.writelines(index) - confFile.writelines(userServer) - confFile.writelines(indexFiles) - confFile.writelines(index_end) + confFile.writelines(index) + confFile.writelines(userServer) + confFile.writelines(indexFiles) + confFile.writelines(index_end) - # Error Log Settings + # Error Log Settings - error_log = "errorlog $VH_ROOT/logs/$VH_NAME.error_log {" + "\n" - useServer = " useServer 0" + "\n" - logLevel = " logLevel ERROR" + "\n" - rollingSize = " rollingSize 10M" + "\n" - error_log_end = "}" + "\n" + "\n" + error_log = "errorlog $VH_ROOT/logs/$VH_NAME.error_log {" + "\n" + useServer = " useServer 0" + "\n" + logLevel = " logLevel ERROR" + "\n" + rollingSize = " rollingSize 10M" + "\n" + error_log_end = "}" + "\n" + "\n" - confFile.writelines(error_log) - confFile.writelines(useServer) - confFile.writelines(logLevel) - confFile.writelines(rollingSize) - confFile.writelines(error_log_end) + confFile.writelines(error_log) + confFile.writelines(useServer) + confFile.writelines(logLevel) + confFile.writelines(rollingSize) + confFile.writelines(error_log_end) - # Access Log Settings + # Access Log Settings - access_Log = "accesslog $VH_ROOT/logs/$VH_NAME.access_log {" + "\n" - useServer = " useServer 0" + "\n" - logFormat = ' logFormat "%v %h %l %u %t \"%r\" %>s %b"' + "\n" - logHeaders = " logHeaders 5" + "\n" - rollingSize = " rollingSize 10M" + "\n" - keepDays = " keepDays 10" - compressArchive = " compressArchive 1" + "\n" - access_Log_end = "}" + "\n" + "\n" + access_Log = "accesslog $VH_ROOT/logs/$VH_NAME.access_log {" + "\n" + useServer = " useServer 0" + "\n" + logFormat = ' logFormat "%v %h %l %u %t \"%r\" %>s %b"' + "\n" + logHeaders = " logHeaders 5" + "\n" + rollingSize = " rollingSize 10M" + "\n" + keepDays = " keepDays 10" + compressArchive = " compressArchive 1" + "\n" + access_Log_end = "}" + "\n" + "\n" - confFile.writelines(access_Log) - confFile.writelines(useServer) - confFile.writelines(logFormat) - confFile.writelines(logHeaders) - confFile.writelines(rollingSize) - confFile.writelines(keepDays) - confFile.writelines(compressArchive) - confFile.writelines(access_Log_end) + confFile.writelines(access_Log) + confFile.writelines(useServer) + confFile.writelines(logFormat) + confFile.writelines(logHeaders) + confFile.writelines(rollingSize) + confFile.writelines(keepDays) + confFile.writelines(compressArchive) + confFile.writelines(access_Log_end) - # php settings + # php settings - scripthandler = "scripthandler {" + "\n" - add = " add lsapi:"+virtualHostUser+" php" + "\n" - php_end = "}" + "\n" + "\n" + scripthandler = "scripthandler {" + "\n" + add = " add lsapi:"+virtualHostUser+" php" + "\n" + php_end = "}" + "\n" + "\n" - confFile.writelines(scripthandler) - confFile.writelines(add) - confFile.writelines(php_end) + confFile.writelines(scripthandler) + confFile.writelines(add) + confFile.writelines(php_end) - ## external app + ## external app - if phpVersion == "PHP 5.3": - php = "53" - elif phpVersion == "PHP 5.4": - php = "55" - elif phpVersion == "PHP 5.5": - php = "55" - elif phpVersion == "PHP 5.6": - php = "56" - elif phpVersion == "PHP 7.0": - php = "70" - elif phpVersion == "PHP 7.1": - php = "71" - elif phpVersion == "PHP 7.2": - php = "72" + if phpVersion == "PHP 5.3": + php = "53" + elif phpVersion == "PHP 5.4": + php = "55" + elif phpVersion == "PHP 5.5": + php = "55" + elif phpVersion == "PHP 5.6": + php = "56" + elif phpVersion == "PHP 7.0": + php = "70" + elif phpVersion == "PHP 7.1": + php = "71" + elif phpVersion == "PHP 7.2": + php = "72" - extprocessor = "extprocessor "+virtualHostUser+" {\n" - type = " type lsapi\n" - address = " address UDS://tmp/lshttpd/"+virtualHostUser+".sock\n" - maxConns = " maxConns 10\n" - env = " env LSAPI_CHILDREN=10\n" - initTimeout = " initTimeout 600\n" - retryTimeout = " retryTimeout 0\n" - persistConn = " persistConn 1\n" - persistConnTimeout = " pcKeepAliveTimeout 1\n" - respBuffer = " respBuffer 0\n" - autoStart = " autoStart 1\n" - path = " path /usr/local/lsws/lsphp"+php+"/bin/lsphp\n" - extUser = " extUser " + virtualHostUser + "\n" - extGroup = " extGroup " + virtualHostUser + "\n" - memSoftLimit = " memSoftLimit 2047M\n" - memHardLimit = " memHardLimit 2047M\n" - procSoftLimit = " procSoftLimit 400\n" - procHardLimit = " procHardLimit 500\n" - extprocessorEnd = "}\n" + extprocessor = "extprocessor "+virtualHostUser+" {\n" + type = " type lsapi\n" + address = " address UDS://tmp/lshttpd/"+virtualHostUser+".sock\n" + maxConns = " maxConns 10\n" + env = " env LSAPI_CHILDREN=10\n" + initTimeout = " initTimeout 600\n" + retryTimeout = " retryTimeout 0\n" + persistConn = " persistConn 1\n" + persistConnTimeout = " pcKeepAliveTimeout 1\n" + respBuffer = " respBuffer 0\n" + autoStart = " autoStart 1\n" + path = " path /usr/local/lsws/lsphp"+php+"/bin/lsphp\n" + extUser = " extUser " + virtualHostUser + "\n" + extGroup = " extGroup " + virtualHostUser + "\n" + memSoftLimit = " memSoftLimit 2047M\n" + memHardLimit = " memHardLimit 2047M\n" + procSoftLimit = " procSoftLimit 400\n" + procHardLimit = " procHardLimit 500\n" + extprocessorEnd = "}\n" - confFile.writelines(extprocessor) - confFile.writelines(type) - confFile.writelines(address) - confFile.writelines(maxConns) - confFile.writelines(env) - confFile.writelines(initTimeout) - confFile.writelines(retryTimeout) - confFile.writelines(persistConn) - confFile.writelines(persistConnTimeout) - confFile.writelines(respBuffer) - confFile.writelines(autoStart) - confFile.writelines(path) - confFile.writelines(extUser) - confFile.writelines(extGroup) - confFile.writelines(memSoftLimit) - confFile.writelines(memHardLimit) - confFile.writelines(procSoftLimit) - confFile.writelines(procHardLimit) - confFile.writelines(extprocessorEnd) + confFile.writelines(extprocessor) + confFile.writelines(type) + confFile.writelines(address) + confFile.writelines(maxConns) + confFile.writelines(env) + confFile.writelines(initTimeout) + confFile.writelines(retryTimeout) + confFile.writelines(persistConn) + confFile.writelines(persistConnTimeout) + confFile.writelines(respBuffer) + confFile.writelines(autoStart) + confFile.writelines(path) + confFile.writelines(extUser) + confFile.writelines(extGroup) + confFile.writelines(memSoftLimit) + confFile.writelines(memHardLimit) + confFile.writelines(procSoftLimit) + confFile.writelines(procHardLimit) + confFile.writelines(extprocessorEnd) - ## File Manager defination + ## File Manager defination - context = "context /.filemanager {\n" - location = " location /usr/local/lsws/Example/html/FileManager\n" - allowBrowse = " allowBrowse 1\n" - autoIndex = " autoIndex 1\n\n" + context = "context /.filemanager {\n" + location = " location /usr/local/lsws/Example/html/FileManager\n" + allowBrowse = " allowBrowse 1\n" + autoIndex = " autoIndex 1\n\n" - accessControl = " accessControl {\n" - allow = " allow 127.0.0.1, localhost\n" - deny = " deny 0.0.0.0/0\n" - accessControlEnds = " }\n" + accessControl = " accessControl {\n" + allow = " allow 127.0.0.1, localhost\n" + deny = " deny 0.0.0.0/0\n" + accessControlEnds = " }\n" - rewriteInherit = """ rewrite { - inherit 0 + rewriteInherit = """ rewrite { + inherit 0 + + } + """ - } - """ - - phpIniOverride = "phpIniOverride {\n" - php_admin_value = 'php_admin_value open_basedir "/tmp:/usr/local/lsws/Example/html/FileManager:$VH_ROOT"\n' - php_value = 'php_value display_errors "Off"\n' - php_value_upload_max_size = 'php_value upload_max_filesize "200M"\n' - php_value_post_max_size = 'php_value post_max_size "250M"\n' - endPHPIniOverride = "}\n" + phpIniOverride = "phpIniOverride {\n" + php_admin_value = 'php_admin_value open_basedir "/tmp:/usr/local/lsws/Example/html/FileManager:$VH_ROOT"\n' + php_value = 'php_value display_errors "Off"\n' + php_value_upload_max_size = 'php_value upload_max_filesize "200M"\n' + php_value_post_max_size = 'php_value post_max_size "250M"\n' + endPHPIniOverride = "}\n" - defaultCharSet = " addDefaultCharset off\n" - contextEnds = "}\n" + defaultCharSet = " addDefaultCharset off\n" + contextEnds = "}\n" - confFile.writelines(context) - confFile.writelines(location) - confFile.writelines(allowBrowse) - confFile.writelines(autoIndex) - confFile.writelines(accessControl) - confFile.writelines(allow) - confFile.writelines(deny) - confFile.writelines(accessControlEnds) - confFile.write(rewriteInherit) + confFile.writelines(context) + confFile.writelines(location) + confFile.writelines(allowBrowse) + confFile.writelines(autoIndex) + confFile.writelines(accessControl) + confFile.writelines(allow) + confFile.writelines(deny) + confFile.writelines(accessControlEnds) + confFile.write(rewriteInherit) - confFile.writelines(phpIniOverride) - if openBasedir == 1: - confFile.writelines(php_admin_value) - confFile.write(php_value) - confFile.write(php_value_upload_max_size) - confFile.write(php_value_post_max_size) - confFile.writelines(endPHPIniOverride) + confFile.writelines(phpIniOverride) + if openBasedir == 1: + confFile.writelines(php_admin_value) + confFile.write(php_value) + confFile.write(php_value_upload_max_size) + confFile.write(php_value_post_max_size) + confFile.writelines(endPHPIniOverride) - confFile.writelines(defaultCharSet) - confFile.writelines(contextEnds) + confFile.writelines(defaultCharSet) + confFile.writelines(contextEnds) - ## OpenBase Dir Protection + ## OpenBase Dir Protection - phpIniOverride = "phpIniOverride {\n" - php_admin_value = 'php_admin_value open_basedir "/tmp:$VH_ROOT"\n' - endPHPIniOverride = "}\n" + phpIniOverride = "phpIniOverride {\n" + php_admin_value = 'php_admin_value open_basedir "/tmp:$VH_ROOT"\n' + endPHPIniOverride = "}\n" - confFile.writelines(phpIniOverride) - if openBasedir == 1: - confFile.writelines(php_admin_value) - confFile.writelines(endPHPIniOverride) + confFile.writelines(phpIniOverride) + if openBasedir == 1: + confFile.writelines(php_admin_value) + confFile.writelines(endPHPIniOverride) - htaccessAutoLoad = """ -rewrite { - enable 1 - autoLoadHtaccess 1 -} -""" - confFile.write(htaccessAutoLoad) + htaccessAutoLoad = """ + rewrite { + enable 1 + autoLoadHtaccess 1 + } + """ + confFile.write(htaccessAutoLoad) - confFile.close() + confFile.close() + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [IO Error with per host config file [perHostVirtualConf]]") + return 0 + return 1 + else: + try: + confFile = open(vhFile, "w+") + + doNotModify = '# Do not modify this file, this is auto-generated file.\n\n' + + VirtualHost = '\n\n' + ServerName = ' ServerName ' + virtualHostName + '\n' + ServerAlias = ' ServerAlias www.' + virtualHostName + '\n' + ScriptAlias = ' Alias /.filemanager/ /usr/local/lsws/FileManager\n' + ServerAdmin = ' ServerAdmin ' + administratorEmail + '\n' + SeexecUserGroup = ' SuexecUserGroup ' + virtualHostUser + ' ' + virtualHostUser + '\n' + DocumentRoot = ' DocumentRoot /home/' + virtualHostName + '/public_html\n' + CustomLogCombined = ' CustomLog /home/' + virtualHostName + '/logs/' + virtualHostName + '.access_log combined\n' + + confFile.writelines(doNotModify) + confFile.writelines(VirtualHost) + confFile.writelines(ServerName) + confFile.writelines(ServerAlias) + confFile.writelines(ScriptAlias) + confFile.writelines(ServerAdmin) + confFile.writelines(SeexecUserGroup) + confFile.writelines(DocumentRoot) + confFile.writelines(CustomLogCombined) + + DirectoryFileManager = """\n + Options +Includes -Indexes +ExecCGI + php_value display_errors "Off" + php_value upload_max_filesize "200M" + php_value post_max_size "250M" + \n""" + confFile.writelines(DirectoryFileManager) + + ## external app + + if phpVersion == "PHP 5.3": + php = "53" + elif phpVersion == "PHP 5.4": + php = "55" + elif phpVersion == "PHP 5.5": + php = "55" + elif phpVersion == "PHP 5.6": + php = "56" + elif phpVersion == "PHP 7.0": + php = "70" + elif phpVersion == "PHP 7.1": + php = "71" + elif phpVersion == "PHP 7.2": + php = "72" + + AddType = ' AddHandler application/x-httpd-php' + php + ' .php .php7 .phtml\n\n' + VirtualHostEnd = '\n' + + confFile.writelines(AddType) + confFile.writelines(VirtualHostEnd) + + confFile.close() + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [IO Error with per host config file [perHostVirtualConf]]") + return 0 + return 1 - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [IO Error with per host config file [perHostVirtualConf]]") - return 0 - return 1 @staticmethod def createNONSSLMapEntry(virtualHostName): @@ -420,121 +490,203 @@ rewrite { #restrained 1 #} - try: + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: - if vhost.createNONSSLMapEntry(virtualHostName) == 0: - return [0, "Failed to create NON SSL Map Entry [createConfigInMainVirtualHostFile]"] + if vhost.createNONSSLMapEntry(virtualHostName) == 0: + return [0, "Failed to create NON SSL Map Entry [createConfigInMainVirtualHostFile]"] - writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'a') + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'a') - writeDataToFile.writelines("virtualHost " + virtualHostName + " {\n") - writeDataToFile.writelines(" vhRoot /home/$VH_NAME\n") - writeDataToFile.writelines(" configFile $SERVER_ROOT/conf/vhosts/$VH_NAME/vhost.conf\n") - writeDataToFile.writelines(" allowSymbolLink 1\n") - writeDataToFile.writelines(" enableScript 1\n") - writeDataToFile.writelines(" restrained 1\n") - writeDataToFile.writelines("}\n") - writeDataToFile.writelines("\n") + writeDataToFile.writelines("virtualHost " + virtualHostName + " {\n") + writeDataToFile.writelines(" vhRoot /home/$VH_NAME\n") + writeDataToFile.writelines(" configFile $SERVER_ROOT/conf/vhosts/$VH_NAME/vhost.conf\n") + writeDataToFile.writelines(" allowSymbolLink 1\n") + writeDataToFile.writelines(" enableScript 1\n") + writeDataToFile.writelines(" restrained 1\n") + writeDataToFile.writelines("}\n") + writeDataToFile.writelines("\n") - writeDataToFile.close() + writeDataToFile.close() - writeDataToFile.close() - return [1,"None"] + writeDataToFile.close() + return [1,"None"] + except BaseException,msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "223 [IO Error with main config file [createConfigInMainVirtualHostFile]]") + return [0,"223 [IO Error with main config file [createConfigInMainVirtualHostFile]]"] + else: + try: + writeDataToFile = open("/usr/local/lsws/conf/httpd.conf", 'a') + configFile = 'Include /usr/local/lsws/conf/vhosts/' + virtualHostName + '/vhost.conf\n' + writeDataToFile.writelines(configFile) + writeDataToFile.close() - except BaseException,msg: - logging.CyberCPLogFileWriter.writeToFile(str(msg) + "223 [IO Error with main config file [createConfigInMainVirtualHostFile]]") - return [0,"223 [IO Error with main config file [createConfigInMainVirtualHostFile]]"] + writeDataToFile.close() + return [1, "None"] + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + "223 [IO Error with main config file [createConfigInMainVirtualHostFile]]") + return [0, "223 [IO Error with main config file [createConfigInMainVirtualHostFile]]"] @staticmethod def deleteVirtualHostConfigurations(virtualHostName): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: - try: + ## Deleting master conf + numberOfSites = str(Websites.objects.count() + ChildDomains.objects.count()) + vhost.deleteCoreConf(virtualHostName, numberOfSites) - ## Deleting master conf - numberOfSites = str(Websites.objects.count() + ChildDomains.objects.count()) - vhost.deleteCoreConf(virtualHostName, numberOfSites) + delWebsite = Websites.objects.get(domain=virtualHostName) + databases = Databases.objects.filter(website=delWebsite) - delWebsite = Websites.objects.get(domain=virtualHostName) - databases = Databases.objects.filter(website=delWebsite) + childDomains = delWebsite.childdomains_set.all() - childDomains = delWebsite.childdomains_set.all() + ## Deleting child domains - ## Deleting child domains + for items in childDomains: + numberOfSites = Websites.objects.count() + ChildDomains.objects.count() + vhost.deleteCoreConf(items.domain, numberOfSites) - for items in childDomains: - numberOfSites = Websites.objects.count() + ChildDomains.objects.count() - vhost.deleteCoreConf(items.domain, numberOfSites) + for items in databases: + mysqlUtilities.deleteDatabase(items.dbName, items.dbUser) - for items in databases: - mysqlUtilities.deleteDatabase(items.dbName, items.dbUser) + delWebsite.delete() - delWebsite.delete() + ## Deleting DNS Zone if there is any. - ## Deleting DNS Zone if there is any. + DNS.deleteDNSZone(virtualHostName) - DNS.deleteDNSZone(virtualHostName) + installUtilities.installUtilities.reStartLiteSpeed() - installUtilities.installUtilities.reStartLiteSpeed() + ## Delete mail accounts - ## Delete mail accounts + command = "sudo rm -rf /home/vmail/" + virtualHostName + subprocess.call(shlex.split(command)) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") + return 0 + return 1 + else: + try: + ## Deleting master conf + numberOfSites = str(Websites.objects.count() + ChildDomains.objects.count()) + vhost.deleteCoreConf(virtualHostName, numberOfSites) - command = "sudo rm -rf /home/vmail/" + virtualHostName - subprocess.call(shlex.split(command)) + delWebsite = Websites.objects.get(domain=virtualHostName) + databases = Databases.objects.filter(website=delWebsite) - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") - return 0 + childDomains = delWebsite.childdomains_set.all() + + ## Deleting child domains + + for items in childDomains: + numberOfSites = Websites.objects.count() + ChildDomains.objects.count() + vhost.deleteCoreConf(items.domain, numberOfSites) + + for items in databases: + mysqlUtilities.deleteDatabase(items.dbName, items.dbUser) + + delWebsite.delete() + + ## Deleting DNS Zone if there is any. + + DNS.deleteDNSZone(virtualHostName) + + installUtilities.installUtilities.reStartLiteSpeed() + + ## Delete mail accounts + + command = "sudo rm -rf /home/vmail/" + virtualHostName + subprocess.call(shlex.split(command)) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") + return 0 + return 1 - return 1 @staticmethod def deleteCoreConf(virtualHostName, numberOfSites): - try: + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + virtualHostPath = "/home/" + virtualHostName + if os.path.exists(virtualHostPath): + shutil.rmtree(virtualHostPath) + + confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName + if os.path.exists(confPath): + shutil.rmtree(confPath) + + data = open("/usr/local/lsws/conf/httpd_config.conf").readlines() + + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w') + + check = 1 + sslCheck = 1 + + for items in data: + if numberOfSites == 1: + if (items.find(' ' + virtualHostName) > -1 and items.find(" map " + virtualHostName) > -1): + continue + if (items.find(' ' + virtualHostName) > -1 and (items.find("virtualHost") > -1 or items.find("virtualhost") > -1)): + check = 0 + if items.find("listener") > -1 and items.find("SSL") > -1: + sslCheck = 0 + if (check == 1 and sslCheck == 1): + writeDataToFile.writelines(items) + if (items.find("}") > -1 and (check == 0 or sslCheck == 0)): + check = 1 + sslCheck = 1 + else: + if (items.find(' ' + virtualHostName) > -1 and items.find(" map " + virtualHostName) > -1): + continue + if (items.find(' ' + virtualHostName) > -1 and (items.find("virtualHost") > -1 or items.find("virtualhost") > -1)): + check = 0 + if (check == 1): + writeDataToFile.writelines(items) + if (items.find("}") > -1 and check == 0): + check = 1 + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") + return 0 + return 1 + else: virtualHostPath = "/home/" + virtualHostName - if os.path.exists(virtualHostPath): + try: shutil.rmtree(virtualHostPath) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [Not able to remove virtual host directory from /home continuing..]") - confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName - if os.path.exists(confPath): + try: + confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName shutil.rmtree(confPath) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [Not able to remove virtual host configuration directory from /conf ]") - data = open("/usr/local/lsws/conf/httpd_config.conf").readlines() + try: + data = open("/usr/local/lsws/conf/httpd.conf").readlines() - writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w') + writeDataToFile = open("/usr/local/lsws/conf/httpd.conf", 'w') - check = 1 - sslCheck = 1 - - for items in data: - if numberOfSites == 1: - if (items.find(' ' + virtualHostName) > -1 and items.find(" map " + virtualHostName) > -1): - continue - if (items.find(' ' + virtualHostName) > -1 and (items.find("virtualHost") > -1 or items.find("virtualhost") > -1)): - check = 0 - if items.find("listener") > -1 and items.find("SSL") > -1: - sslCheck = 0 - if (check == 1 and sslCheck == 1): + for items in data: + if items.find('/' + virtualHostName + '/') > -1: + pass + else: writeDataToFile.writelines(items) - if (items.find("}") > -1 and (check == 0 or sslCheck == 0)): - check = 1 - sslCheck = 1 - else: - if (items.find(' ' + virtualHostName) > -1 and items.find(" map " + virtualHostName) > -1): - continue - if (items.find(' ' + virtualHostName) > -1 and (items.find("virtualHost") > -1 or items.find("virtualhost") > -1)): - check = 0 - if (check == 1): - writeDataToFile.writelines(items) - if (items.find("}") > -1 and check == 0): - check = 1 - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") - return 0 - return 1 + writeDataToFile.close() + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") + return 0 + return 1 @staticmethod def checkIfVirtualHostExists(virtualHostName): @@ -544,51 +696,88 @@ rewrite { @staticmethod def changePHP(vhFile, phpVersion): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + finalphp = 0 + try: + data = open(vhFile, "r").readlines() - # General Configurations tab + if phpVersion == "PHP 5.3": + finalphp = 53 + elif phpVersion == "PHP 5.4": + finalphp = 54 + elif phpVersion == "PHP 5.5": + finalphp = 55 + elif phpVersion == "PHP 5.6": + finalphp = 56 + elif phpVersion == "PHP 7.0": + finalphp = 70 + elif phpVersion == "PHP 7.1": + finalphp = 71 + elif phpVersion == "PHP 7.2": + finalphp = 72 - finalphp = 0 + writeDataToFile = open(vhFile, "w") - try: - data = open(vhFile, "r").readlines() + path = " path /usr/local/lsws/lsphp" + str(finalphp) + "/bin/lsphp\n" - if phpVersion == "PHP 5.3": - finalphp = 53 - elif phpVersion == "PHP 5.4": - finalphp = 54 - elif phpVersion == "PHP 5.5": - finalphp = 55 - elif phpVersion == "PHP 5.6": - finalphp = 56 - elif phpVersion == "PHP 7.0": - finalphp = 70 - elif phpVersion == "PHP 7.1": - finalphp = 71 - elif phpVersion == "PHP 7.2": - finalphp = 72 + for items in data: + if items.find("/usr/local/lsws/lsphp") > -1 and items.find("path") > -1: + writeDataToFile.writelines(path) + else: + writeDataToFile.writelines(items) - writeDataToFile = open(vhFile, "w") + writeDataToFile.close() - path = " path /usr/local/lsws/lsphp" + str(finalphp) + "/bin/lsphp\n" + installUtilities.installUtilities.reStartLiteSpeed() - for items in data: - if items.find("/usr/local/lsws/lsphp") > -1 and items.find("path") > -1: - writeDataToFile.writelines(path) - else: - writeDataToFile.writelines(items) + print "1,None" + return 1,'None' + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [IO Error with per host config file [changePHP]]") + print 0,str(msg) + return [0, str(msg) + " [IO Error with per host config file [changePHP]]"] + else: + try: + data = open(vhFile, "r").readlines() + if phpVersion == "PHP 5.3": + finalphp = 53 - writeDataToFile.close() + elif phpVersion == "PHP 5.4": + finalphp = 54 + elif phpVersion == "PHP 5.5": + finalphp = 55 + elif phpVersion == "PHP 5.6": + finalphp = 56 + elif phpVersion == "PHP 7.0": + finalphp = 70 + elif phpVersion == "PHP 7.1": + finalphp = 71 + elif phpVersion == "PHP 7.2": + finalphp = 72 - installUtilities.installUtilities.reStartLiteSpeed() + writeDataToFile = open(vhFile, "w") - print "1,None" - return 1,'None' + finalString = ' AddHandler application/x-httpd-php' + str(finalphp) + ' .php\n' + + for items in data: + if items.find("AddHandler application/x-httpd") > -1: + writeDataToFile.writelines(finalString) + else: + writeDataToFile.writelines(items) + + writeDataToFile.close() + + installUtilities.installUtilities.reStartLiteSpeed() + + print "1,None" + return 1, 'None' + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [IO Error with per host config file [changePHP]]") + print 0, str(msg) + return [0, str(msg) + " [IO Error with per host config file [changePHP]]"] - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [IO Error with per host config file [changePHP]]") - print 0,str(msg) - return [0, str(msg) + " [IO Error with per host config file [changePHP]]"] @staticmethod def addRewriteRules(virtualHostName, fileName=None): @@ -648,8 +837,6 @@ rewrite { print str(inMB) + "," + str(percentage) else: print "0,0" - - except OSError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [findDomainBW]") print "0,0" @@ -782,176 +969,227 @@ rewrite { logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDirectoryForDomain]]") return [0, "[351 Not able to directories for virtual host [createDirectoryForDomain]]"] - if vhost.perHostDomainConf(path, masterDomain, completePathToConfigFile, - administratorEmail, phpVersion, virtualHostUser, openBasedir) == 1: + if vhost.perHostDomainConf(path, masterDomain, domain, completePathToConfigFile, + administratorEmail, phpVersion, virtualHostUser, openBasedir) == 1: return [1, "None"] else: return [0, "[359 Not able to create per host virtual configurations [perHostVirtualConf]"] @staticmethod - def perHostDomainConf(path, masterDomain, vhFile, administratorEmail, phpVersion, virtualHostUser, openBasedir): + def perHostDomainConf(path, masterDomain, domain, vhFile, administratorEmail, phpVersion, virtualHostUser, openBasedir): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + confFile = open(vhFile, "w+") - # General Configurations tab + docRoot = "docRoot " + path + "\n" + vhDomain = "vhDomain $VH_NAME" + "\n" + vhAliases = "vhAliases www.$VH_NAME" + "\n" + adminEmails = "adminEmails " + administratorEmail + "\n" + enableGzip = "enableGzip 1" + "\n" + enableIpGeo = "enableIpGeo 1" + "\n" + "\n" - try: - confFile = open(vhFile, "w+") + confFile.writelines(docRoot) + confFile.writelines(vhDomain) + confFile.writelines(vhAliases) + confFile.writelines(adminEmails) + confFile.writelines(enableGzip) + confFile.writelines(enableIpGeo) - docRoot = "docRoot " + path + "\n" - vhDomain = "vhDomain $VH_NAME" + "\n" - vhAliases = "vhAliases www.$VH_NAME" + "\n" - adminEmails = "adminEmails " + administratorEmail + "\n" - enableGzip = "enableGzip 1" + "\n" - enableIpGeo = "enableIpGeo 1" + "\n" + "\n" + # Index file settings - confFile.writelines(docRoot) - confFile.writelines(vhDomain) - confFile.writelines(vhAliases) - confFile.writelines(adminEmails) - confFile.writelines(enableGzip) - confFile.writelines(enableIpGeo) + index = "index {" + "\n" + userServer = " useServer 0" + "\n" + indexFiles = " indexFiles index.php, index.html" + "\n" + index_end = "}" + "\n" + "\n" - # Index file settings + confFile.writelines(index) + confFile.writelines(userServer) + confFile.writelines(indexFiles) + confFile.writelines(index_end) - index = "index {" + "\n" - userServer = " useServer 0" + "\n" - indexFiles = " indexFiles index.php, index.html" + "\n" - index_end = "}" + "\n" + "\n" - - confFile.writelines(index) - confFile.writelines(userServer) - confFile.writelines(indexFiles) - confFile.writelines(index_end) - - # Error Log Settings + # Error Log Settings - error_log = "errorlog $VH_ROOT/logs/" + masterDomain + ".error_log {" + "\n" - useServer = " useServer 0" + "\n" - logLevel = " logLevel ERROR" + "\n" - rollingSize = " rollingSize 10M" + "\n" - error_log_end = "}" + "\n" + "\n" + error_log = "errorlog $VH_ROOT/logs/" + masterDomain + ".error_log {" + "\n" + useServer = " useServer 0" + "\n" + logLevel = " logLevel ERROR" + "\n" + rollingSize = " rollingSize 10M" + "\n" + error_log_end = "}" + "\n" + "\n" - confFile.writelines(error_log) - confFile.writelines(useServer) - confFile.writelines(logLevel) - confFile.writelines(rollingSize) - confFile.writelines(error_log_end) + confFile.writelines(error_log) + confFile.writelines(useServer) + confFile.writelines(logLevel) + confFile.writelines(rollingSize) + confFile.writelines(error_log_end) - # Access Log Settings + # Access Log Settings - access_Log = "accesslog $VH_ROOT/logs/" + masterDomain + ".access_log {" + "\n" - useServer = " useServer 0" + "\n" - logFormat = ' logFormat "%v %h %l %u %t \"%r\" %>s %b"' + "\n" - logHeaders = " logHeaders 5" + "\n" - rollingSize = " rollingSize 10M" + "\n" - keepDays = " keepDays 10" - compressArchive = " compressArchive 1" + "\n" - access_Log_end = "}" + "\n" + "\n" + access_Log = "accesslog $VH_ROOT/logs/" + masterDomain + ".access_log {" + "\n" + useServer = " useServer 0" + "\n" + logFormat = ' logFormat "%v %h %l %u %t \"%r\" %>s %b"' + "\n" + logHeaders = " logHeaders 5" + "\n" + rollingSize = " rollingSize 10M" + "\n" + keepDays = " keepDays 10" + compressArchive = " compressArchive 1" + "\n" + access_Log_end = "}" + "\n" + "\n" - confFile.writelines(access_Log) - confFile.writelines(useServer) - confFile.writelines(logFormat) - confFile.writelines(logHeaders) - confFile.writelines(rollingSize) - confFile.writelines(keepDays) - confFile.writelines(compressArchive) - confFile.writelines(access_Log_end) + confFile.writelines(access_Log) + confFile.writelines(useServer) + confFile.writelines(logFormat) + confFile.writelines(logHeaders) + confFile.writelines(rollingSize) + confFile.writelines(keepDays) + confFile.writelines(compressArchive) + confFile.writelines(access_Log_end) - ## OpenBase Dir Protection + ## OpenBase Dir Protection - phpIniOverride = "phpIniOverride {\n" - php_admin_value = 'php_admin_value open_basedir "/tmp:/usr/local/lsws/Example/html/FileManager:$VH_ROOT"\n' - endPHPIniOverride = "}\n" + phpIniOverride = "phpIniOverride {\n" + php_admin_value = 'php_admin_value open_basedir "/tmp:/usr/local/lsws/Example/html/FileManager:$VH_ROOT"\n' + endPHPIniOverride = "}\n" - confFile.writelines(phpIniOverride) - if openBasedir == 1: - confFile.writelines(php_admin_value) - confFile.writelines(endPHPIniOverride) + confFile.writelines(phpIniOverride) + if openBasedir == 1: + confFile.writelines(php_admin_value) + confFile.writelines(endPHPIniOverride) - # php settings + # php settings - sockRandomPath = str(randint(1000, 9999)) + sockRandomPath = str(randint(1000, 9999)) - scripthandler = "scripthandler {" + "\n" - add = " add lsapi:" + virtualHostUser + sockRandomPath + " php" + "\n" - php_end = "}" + "\n" + "\n" + scripthandler = "scripthandler {" + "\n" + add = " add lsapi:" + virtualHostUser + sockRandomPath + " php" + "\n" + php_end = "}" + "\n" + "\n" - confFile.writelines(scripthandler) - confFile.writelines(add) - confFile.writelines(php_end) + confFile.writelines(scripthandler) + confFile.writelines(add) + confFile.writelines(php_end) - ## external app + ## external app - if phpVersion == "PHP 5.3": - php = "53" - elif phpVersion == "PHP 5.4": - php = "55" - elif phpVersion == "PHP 5.5": - php = "55" - elif phpVersion == "PHP 5.6": - php = "56" - elif phpVersion == "PHP 7.0": - php = "70" - elif phpVersion == "PHP 7.1": - php = "71" - elif phpVersion == "PHP 7.2": - php = "72" + if phpVersion == "PHP 5.3": + php = "53" + elif phpVersion == "PHP 5.4": + php = "55" + elif phpVersion == "PHP 5.5": + php = "55" + elif phpVersion == "PHP 5.6": + php = "56" + elif phpVersion == "PHP 7.0": + php = "70" + elif phpVersion == "PHP 7.1": + php = "71" + elif phpVersion == "PHP 7.2": + php = "72" - extprocessor = "extprocessor " + virtualHostUser + sockRandomPath + " {\n" - type = " type lsapi\n" - address = " address UDS://tmp/lshttpd/" + virtualHostUser + sockRandomPath + ".sock\n" - maxConns = " maxConns 10\n" - env = " env LSAPI_CHILDREN=10\n" - initTimeout = " initTimeout 60\n" - retryTimeout = " retryTimeout 0\n" - persistConn = " persistConn 1\n" - persistConnTimeout = " pcKeepAliveTimeout 1\n" - respBuffer = " respBuffer 0\n" - autoStart = " autoStart 1\n" - path = " path /usr/local/lsws/lsphp" + php + "/bin/lsphp\n" - extUser = " extUser " + virtualHostUser + "\n" - extGroup = " extGroup " + virtualHostUser + "\n" - memSoftLimit = " memSoftLimit 2047M\n" - memHardLimit = " memHardLimit 2047M\n" - procSoftLimit = " procSoftLimit 400\n" - procHardLimit = " procHardLimit 500\n" - extprocessorEnd = "}\n" + extprocessor = "extprocessor " + virtualHostUser + sockRandomPath + " {\n" + type = " type lsapi\n" + address = " address UDS://tmp/lshttpd/" + virtualHostUser + sockRandomPath + ".sock\n" + maxConns = " maxConns 10\n" + env = " env LSAPI_CHILDREN=10\n" + initTimeout = " initTimeout 60\n" + retryTimeout = " retryTimeout 0\n" + persistConn = " persistConn 1\n" + persistConnTimeout = " pcKeepAliveTimeout 1\n" + respBuffer = " respBuffer 0\n" + autoStart = " autoStart 1\n" + path = " path /usr/local/lsws/lsphp" + php + "/bin/lsphp\n" + extUser = " extUser " + virtualHostUser + "\n" + extGroup = " extGroup " + virtualHostUser + "\n" + memSoftLimit = " memSoftLimit 2047M\n" + memHardLimit = " memHardLimit 2047M\n" + procSoftLimit = " procSoftLimit 400\n" + procHardLimit = " procHardLimit 500\n" + extprocessorEnd = "}\n" - confFile.writelines(extprocessor) - confFile.writelines(type) - confFile.writelines(address) - confFile.writelines(maxConns) - confFile.writelines(env) - confFile.writelines(initTimeout) - confFile.writelines(retryTimeout) - confFile.writelines(persistConn) - confFile.writelines(persistConnTimeout) - confFile.writelines(respBuffer) - confFile.writelines(autoStart) - confFile.writelines(path) - confFile.writelines(extUser) - confFile.writelines(extGroup) - confFile.writelines(memSoftLimit) - confFile.writelines(memHardLimit) - confFile.writelines(procSoftLimit) - confFile.writelines(procHardLimit) - confFile.writelines(extprocessorEnd) + confFile.writelines(extprocessor) + confFile.writelines(type) + confFile.writelines(address) + confFile.writelines(maxConns) + confFile.writelines(env) + confFile.writelines(initTimeout) + confFile.writelines(retryTimeout) + confFile.writelines(persistConn) + confFile.writelines(persistConnTimeout) + confFile.writelines(respBuffer) + confFile.writelines(autoStart) + confFile.writelines(path) + confFile.writelines(extUser) + confFile.writelines(extGroup) + confFile.writelines(memSoftLimit) + confFile.writelines(memHardLimit) + confFile.writelines(procSoftLimit) + confFile.writelines(procHardLimit) + confFile.writelines(extprocessorEnd) - htaccessAutoLoad = """ -rewrite { - enable 1 - autoLoadHtaccess 1 -} -""" - confFile.write(htaccessAutoLoad) + htaccessAutoLoad = """ + rewrite { + enable 1 + autoLoadHtaccess 1 + } + """ + confFile.write(htaccessAutoLoad) - confFile.close() + confFile.close() + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [IO Error with per host config file [perHostDomainConf]]") + return 0 + return 1 + else: + try: + + confFile = open(vhFile, "w+") + + doNotModify = '# Do not modify this file, this is auto-generated file.\n\n' + + VirtualHost = '\n\n' + ServerName = ' ServerName ' + domain + '\n' + ServerAlias = ' ServerAlias www.' + domain + '\n' + ServerAdmin = ' ServerAdmin ' + administratorEmail + '\n' + SeexecUserGroup = ' SuexecUserGroup ' + virtualHostUser + ' ' + virtualHostUser + '\n' + DocumentRoot = ' DocumentRoot ' + path + '\n' + CustomLogCombined = ' CustomLog /home/' + masterDomain + '/logs/' + masterDomain + '.access_log combined\n' + + confFile.writelines(doNotModify) + confFile.writelines(VirtualHost) + confFile.writelines(ServerName) + confFile.writelines(ServerAlias) + confFile.writelines(ServerAdmin) + confFile.writelines(SeexecUserGroup) + confFile.writelines(DocumentRoot) + confFile.writelines(CustomLogCombined) + + ## external app + + if phpVersion == "PHP 5.3": + php = "53" + elif phpVersion == "PHP 5.4": + php = "55" + elif phpVersion == "PHP 5.5": + php = "55" + elif phpVersion == "PHP 5.6": + php = "56" + elif phpVersion == "PHP 7.0": + php = "70" + elif phpVersion == "PHP 7.1": + php = "71" + elif phpVersion == "PHP 7.2": + php = "72" + + AddType = ' AddHandler application/x-httpd-php' + php + ' .php .php7 .phtml\n\n' + VirtualHostEnd = '\n' + + confFile.writelines(AddType) + confFile.writelines(VirtualHostEnd) + + confFile.close() + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [IO Error with per host config file [perHostDomainConf]]") + return 0 + return 1 - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [IO Error with per host config file [perHostDomainConf]]") - return 0 - return 1 @staticmethod def createConfigInMainDomainHostFile(domain, masterDomain): @@ -963,28 +1201,40 @@ rewrite { # restrained 1 # } - try: + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: - if vhost.createNONSSLMapEntry(domain) == 0: - return [0, "Failed to create NON SSL Map Entry [createConfigInMainVirtualHostFile]"] + if vhost.createNONSSLMapEntry(domain) == 0: + return [0, "Failed to create NON SSL Map Entry [createConfigInMainVirtualHostFile]"] - writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'a') + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'a') - writeDataToFile.writelines("\n") - writeDataToFile.writelines("virtualHost " + domain + " {\n") - writeDataToFile.writelines(" vhRoot /home/" + masterDomain + "\n") - writeDataToFile.writelines(" configFile $SERVER_ROOT/conf/vhosts/$VH_NAME/vhost.conf\n") - writeDataToFile.writelines(" allowSymbolLink 1\n") - writeDataToFile.writelines(" enableScript 1\n") - writeDataToFile.writelines(" restrained 1\n") - writeDataToFile.writelines("}\n") - writeDataToFile.writelines("\n") + writeDataToFile.writelines("\n") + writeDataToFile.writelines("virtualHost " + domain + " {\n") + writeDataToFile.writelines(" vhRoot /home/" + masterDomain + "\n") + writeDataToFile.writelines(" configFile $SERVER_ROOT/conf/vhosts/$VH_NAME/vhost.conf\n") + writeDataToFile.writelines(" allowSymbolLink 1\n") + writeDataToFile.writelines(" enableScript 1\n") + writeDataToFile.writelines(" restrained 1\n") + writeDataToFile.writelines("}\n") + writeDataToFile.writelines("\n") - writeDataToFile.close() + writeDataToFile.close() - return [1, "None"] + return [1, "None"] - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + "223 [IO Error with main config file [createConfigInMainDomainHostFile]]") - return [0, "223 [IO Error with main config file [createConfigInMainDomainHostFile]]"] + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + "223 [IO Error with main config file [createConfigInMainDomainHostFile]]") + return [0, "223 [IO Error with main config file [createConfigInMainDomainHostFile]]"] + else: + try: + writeDataToFile = open("/usr/local/lsws/conf/httpd.conf", 'a') + configFile = 'Include /usr/local/lsws/conf/vhosts/' + domain + '/vhost.conf\n' + writeDataToFile.writelines(configFile) + writeDataToFile.close() + return [1, "None"] + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + "223 [IO Error with main config file [createConfigInMainDomainHostFile]]") + return [0, "223 [IO Error with main config file [createConfigInMainDomainHostFile]]"] diff --git a/plogical/website.py b/plogical/website.py index eca026cf5..e35f3c6d3 100644 --- a/plogical/website.py +++ b/plogical/website.py @@ -150,7 +150,6 @@ class WebsiteManager: ## Create Configurations execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" - execPath = execPath + " createVirtualHost --virtualHostName " + domain + \ " --administratorEmail " + adminEmail + " --phpVersion '" + phpSelection + \ "' --virtualHostUser " + externalApp + " --ssl " + str(data['ssl']) + " --dkimCheck " \ diff --git a/serverStatus/litespeed/FileManager/.idea/FIleManager.iml b/serverStatus/litespeed/FileManager/.idea/FIleManager.iml new file mode 100644 index 000000000..c956989b2 --- /dev/null +++ b/serverStatus/litespeed/FileManager/.idea/FIleManager.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/serverStatus/litespeed/FileManager/.idea/modules.xml b/serverStatus/litespeed/FileManager/.idea/modules.xml new file mode 100644 index 000000000..34abd3fc4 --- /dev/null +++ b/serverStatus/litespeed/FileManager/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/serverStatus/litespeed/FileManager/.idea/workspace.xml b/serverStatus/litespeed/FileManager/.idea/workspace.xml new file mode 100644 index 000000000..026ca8720 --- /dev/null +++ b/serverStatus/litespeed/FileManager/.idea/workspace.xml @@ -0,0 +1,600 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ../../assets + ajax/libs/angularjs/1.2.12/angular.js + AbnTestController + AbnTest + listAction + $commandToExecute + + + assets + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+
+ + +
+ + + +
+ +
+
+
+

{% trans "With great wisdom comes great responsibility." %} +

+
+
+ +
+
+
+
+ + + + + +
+
- + + {% else %} +
+ +
+

{% trans "LiteSpeed Status:" %}

+

{% trans "On this page you can get information regarding your LiteSpeed processes." %}

+
+ + +
+
+
+
+
+ + {% if processList %} + +

+ {% trans "LiteSpeed Processes" %} +

+ + + + + + + + + + + {% for items in processList %} + + + + + + {% if forloop.counter == 1 %} + + + {% elif forloop.counter == 2 %} + + + {% else %} + + + {% endif %} + + {% endfor %} + + +
#{% trans "Process ID" %}{% trans "Name" %}
{{ forloop.counter }} {{ items }}{% trans "Main Process" %}{% trans "lscgid Process" %}{% trans "Worker Process" %}
+ {% else %} +
+

{% trans "Could not fetch details, either LiteSpeed is not running or some error occurred, please see CyberPanel Main log file." %}

+
+ {% endif %} + + + + + + + + +
+

{% trans "Action successful." %}

+
+ + +
+

{% trans "Error Occurred. See CyberPanel main log file." %}

+
+ + +
+

{% trans "Could not connect to server." %}

+
+ + +
+
+
+
+
+ + +
+
+

+ {% trans "License Manager" %} +

+ +
+
+ + + + + + + +
+ +
+
+
+ +
+
+

{$ lsSerial $}

+

{$ lsexpiration $}

+
+
+
+ +
+ + + +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+
+ + + + +
+
+
+
+ + +
+ {% endif %} {% endblock %} \ No newline at end of file diff --git a/serverStatus/templates/serverStatus/services.html b/serverStatus/templates/serverStatus/services.html index 54ed94e0f..dab445905 100644 --- a/serverStatus/templates/serverStatus/services.html +++ b/serverStatus/templates/serverStatus/services.html @@ -35,7 +35,7 @@
-
OpenLiteSpeed
+
{{ serverName }}
Stopped
diff --git a/serverStatus/urls.py b/serverStatus/urls.py index fa6060e27..39569e1c4 100644 --- a/serverStatus/urls.py +++ b/serverStatus/urls.py @@ -3,13 +3,17 @@ import views urlpatterns = [ url(r'^$', views.serverStatusHome, name='serverStatusHome'), - url(r'^litespeedStatus', views.litespeedStatus, name='litespeedStatus'), - url(r'^startorstopLitespeed', views.stopOrRestartLitespeed, name='startorstopLitespeed'), - url(r'^cyberCPMainLogFile', views.cyberCPMainLogFile, name='cyberCPMainLogFile'), - url(r'^getFurtherDataFromLogFile',views.getFurtherDataFromLogFile,name='getFurtherDataFromLogFile'), + url(r'^litespeedStatus$', views.litespeedStatus, name='litespeedStatus'), + url(r'^startorstopLitespeed$', views.stopOrRestartLitespeed, name='startorstopLitespeed'), + url(r'^cyberCPMainLogFile$', views.cyberCPMainLogFile, name='cyberCPMainLogFile'), + url(r'^getFurtherDataFromLogFile$',views.getFurtherDataFromLogFile,name='getFurtherDataFromLogFile'), - url(r'^servicesStatus', views.servicesStatus, name='servicesStatus'), - url(r'^servicesAction', views.servicesAction, name='servicesAction'), - url(r'^services', views.services, name='services'), + url(r'^servicesStatus$', views.servicesStatus, name='servicesStatus'), + url(r'^servicesAction$', views.servicesAction, name='servicesAction'), + url(r'^services$', views.services, name='services'), + url(r'^switchTOLSWS$', views.switchTOLSWS, name='switchTOLSWS'), + url(r'^switchTOLSWSStatus$', views.switchTOLSWSStatus, name='switchTOLSWSStatus'), + url(r'^licenseStatus$', views.licenseStatus, name='licenseStatus'), + url(r'^changeLicense$', views.changeLicense, name='changeLicense'), ] \ No newline at end of file diff --git a/serverStatus/views.py b/serverStatus/views.py index 623bd8f1f..b269fadd2 100644 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from django.shortcuts import render,redirect from django.http import HttpResponse -from plogical.processUtilities import ProcessUtilities import plogical.CyberCPLogFileWriter as logging from loginSystem.views import loadLoginPage import json @@ -13,6 +12,10 @@ import shlex import socket from plogical.acl import ACLManager import os +from plogical.virtualHostUtilities import virtualHostUtilities +import time +import serverStatusUtil +from plogical.processUtilities import ProcessUtilities # Create your views here. def serverStatusHome(request): @@ -26,7 +29,6 @@ def litespeedStatus(request): try: userID = request.session['userID'] - currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] == 1: @@ -36,6 +38,9 @@ def litespeedStatus(request): processList = ProcessUtilities.getLitespeedProcessNumber() + OLS = 0 + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + OLS = 1 try: versionInformation = subprocess.check_output(["/usr/local/lsws/bin/lshttpd", "-v"]).split("\n") @@ -54,16 +59,16 @@ def litespeedStatus(request): except subprocess.CalledProcessError,msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]") - return render(request,"serverStatus/litespeedStatus.html",{"processList":processList,"liteSpeedVersionStatus":"For some reaons not able to load version details, see CyberCP main log file."}) + return render(request,"serverStatus/litespeedStatus.html",{"processList":processList,"liteSpeedVersionStatus":"For some reaons not able to load version details, see CyberCP main log file.", 'OLS': OLS}) if(processList!=0): dataForHtml = {"processList": processList, "lsversion": lsversion, "modules": modules, - "loadedModules": loadedModules} + "loadedModules": loadedModules, 'OLS':OLS} return render(request,"serverStatus/litespeedStatus.html",dataForHtml) else: dataForHtml = {"lsversion": lsversion, "modules": modules, - "loadedModules": loadedModules} + "loadedModules": loadedModules, 'OLS': OLS} return render(request, "serverStatus/litespeedStatus.html",dataForHtml) except KeyError,msg: @@ -152,8 +157,14 @@ def services(request): pass else: return ACLManager.loadError() + data = {} - return render(request, 'serverStatus/services.html') + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + data['serverName'] = 'OpenLiteSpeed' + else: + data['serverName'] = 'LiteSpeed Ent' + + return render(request, 'serverStatus/services.html', data) except KeyError: return redirect(loadLoginPage) @@ -302,3 +313,134 @@ def servicesAction(request): final_dic = {'serviceAction': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) + +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) + + execPath = "sudo /usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/serverStatus/serverStatusUtil.py" + execPath = execPath + " switchTOLSWS --licenseKey " + data['licenseKey'] + + subprocess.Popen(shlex.split(execPath)) + time.sleep(2) + + data_ret = {'status': 1, 'error_message': "None", } + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException, msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + +def switchTOLSWSStatus(request): + try: + + command = 'sudo cat ' + serverStatusUtil.ServerStatusUtil.lswsInstallStatusPath + output = subprocess.check_output(shlex.split(command)) + + if output.find('[404]') > -1: + data_ret = {'abort': 1, 'requestStatus': output, 'installed': 0} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + elif output.find('[200]') > -1: + data_ret = {'abort': 1, 'requestStatus': output, 'installed': 1} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'abort': 0, 'requestStatus': output, 'installed': 0} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException, msg: + data_ret = {'abort': 1, 'requestStatus': str(msg), 'installed': 0} + 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' + serial = subprocess.check_output(shlex.split(command)) + + + command = 'sudo /usr/local/lsws/bin/lshttpd -V' + expiration = subprocess.check_output(shlex.split(command)) + + final_dic = {'status': 1, "erroMessage": 0, 'lsSerial': serial, 'lsexpiration': expiration} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + except BaseException, msg: + final_dic = {'status': 0, 'erroMessage': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except KeyError, msg: + final_dic = {'status': 0, 'erroMessage': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +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' + subprocess.call(shlex.split(command)) + + 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' + subprocess.call(shlex.split(command)) + + + command = 'sudo /usr/local/lsws/bin/lshttpd -r' + subprocess.call(shlex.split(command)) + + command = 'sudo /usr/local/lsws/bin/lswsctrl restart' + subprocess.call(shlex.split(command)) + + + final_dic = {'status': 1, "erroMessage": 'None'} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + except BaseException, msg: + final_dic = {'status': 0, 'erroMessage': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except KeyError, msg: + final_dic = {'status': 0, 'erroMessage': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) \ No newline at end of file diff --git a/static/firewall/firewall.js b/static/firewall/firewall.js index ba9df9207..bb0e4a07f 100644 --- a/static/firewall/firewall.js +++ b/static/firewall/firewall.js @@ -3,10 +3,6 @@ */ - - - - /* Java script code to ADD Firewall Rules */ app.controller('firewallController', function($scope,$http) { @@ -548,8 +544,6 @@ app.controller('firewallController', function($scope,$http) { /* Java script code to ADD Firewall Rules */ - - /* Java script code to Secure SSH */ app.controller('secureSSHCTRL', function($scope,$http) { diff --git a/static/images/litespeed-logo.png b/static/images/litespeed-logo.png new file mode 100644 index 000000000..5ac9124e5 Binary files /dev/null and b/static/images/litespeed-logo.png differ diff --git a/static/serverStatus/serverStatus.js b/static/serverStatus/serverStatus.js index e52d380fe..99b324364 100644 --- a/static/serverStatus/serverStatus.js +++ b/static/serverStatus/serverStatus.js @@ -5,7 +5,7 @@ /* Java script code to start/stop litespeed */ -app.controller('litespeedStatus', function($scope,$http) { +app.controller('litespeedStatus', function ($scope, $http) { $scope.restartorStopLoading = true; $scope.actionResult = true; @@ -13,424 +13,507 @@ app.controller('litespeedStatus', function($scope,$http) { $scope.serverStatusCouldNotConnect = true; - $scope.restartLitespeed = function(){ + $scope.restartLitespeed = function () { - $scope.disableReboot = true; - $scope.disableStop = true; - $scope.restartorStopLoading = false; + $scope.disableReboot = true; + $scope.disableStop = true; + $scope.restartorStopLoading = false; + var url = "/serverstatus/startorstopLitespeed"; + + var data = { + reboot: 1, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - var url = "/serverstatus/startorstopLitespeed"; + function ListInitialDatas(response) { - var data = { - reboot:1, - }; + $scope.restartorStopLoading = true; + $scope.disableReboot = false; + $scope.disableStop = false; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + if (response.data.reboot == 1) { - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.restartorStopLoading = true; - $scope.disableReboot = false; - $scope.disableStop = false; - - if(response.data.reboot == 1){ - - $scope.restartorStopLoading = true; - $scope.actionResult = false; - $scope.actionResultBad = true; - $scope.serverStatusCouldNotConnect = true; - - } - else{ - - $scope.restartorStopLoading = true; - $scope.actionResult = true; - $scope.actionResultBad = false; - $scope.serverStatusCouldNotConnect = true; - } - - - } - function cantLoadInitialDatas(response) { - $scope.restartorStopLoading = true; - $scope.actionResult = true; - $scope.actionResultBad = true; - $scope.serverStatusCouldNotConnect = false; - $scope.disableReboot = false; - $scope.disableStop = false; - } + $scope.restartorStopLoading = true; + $scope.actionResult = false; + $scope.actionResultBad = true; + $scope.serverStatusCouldNotConnect = true; + + } + else { + + $scope.restartorStopLoading = true; + $scope.actionResult = true; + $scope.actionResultBad = false; + $scope.serverStatusCouldNotConnect = true; + } + } + function cantLoadInitialDatas(response) { + $scope.restartorStopLoading = true; + $scope.actionResult = true; + $scope.actionResultBad = true; + $scope.serverStatusCouldNotConnect = false; + $scope.disableReboot = false; + $scope.disableStop = false; + } }; - $scope.stopLitespeed = function(){ + $scope.stopLitespeed = function () { - $scope.disableReboot = true; - $scope.disableStop = true; - $scope.restartorStopLoading = false; + $scope.disableReboot = true; + $scope.disableStop = true; + $scope.restartorStopLoading = false; + var url = "/serverstatus/startorstopLitespeed"; + + var data = { + reboot: 0, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - var url = "/serverstatus/startorstopLitespeed"; + function ListInitialDatas(response) { - var data = { - reboot:0, - }; + $scope.restartorStopLoading = true; + $scope.disableReboot = false; + $scope.disableStop = false; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + if (response.data.shutdown == 1) { - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.restartorStopLoading = true; - $scope.disableReboot = false; - $scope.disableStop = false; - - if(response.data.shutdown == 1){ - - $scope.restartorStopLoading = true; - $scope.actionResult = false; - $scope.actionResultBad = true; - $scope.serverStatusCouldNotConnect = true; - - } - else{ - - $scope.restartorStopLoading = true; - $scope.actionResult = true; - $scope.actionResultBad = false; - $scope.serverStatusCouldNotConnect = true; - } - - - } - function cantLoadInitialDatas(response) { - $scope.restartorStopLoading = true; - $scope.actionResult = true; - $scope.actionResultBad = true; - $scope.serverStatusCouldNotConnect = false; - $scope.disableReboot = false; - $scope.disableStop = false; - } + $scope.restartorStopLoading = true; + $scope.actionResult = false; + $scope.actionResultBad = true; + $scope.serverStatusCouldNotConnect = true; + + } + else { + + $scope.restartorStopLoading = true; + $scope.actionResult = true; + $scope.actionResultBad = false; + $scope.serverStatusCouldNotConnect = true; + } + } + function cantLoadInitialDatas(response) { + $scope.restartorStopLoading = true; + $scope.actionResult = true; + $scope.actionResultBad = true; + $scope.serverStatusCouldNotConnect = false; + $scope.disableReboot = false; + $scope.disableStop = false; + } }; }); - - /* Java script code to start/stop litespeed */ - - - /* Java script code to read log file */ +app.controller('readCyberCPLogFile', function ($scope, $http) { -app.controller('readCyberCPLogFile', function($scope,$http) { + $scope.logFileLoading = false; + $scope.logsFeteched = true; + $scope.couldNotFetchLogs = true; - $scope.logFileLoading = false; - $scope.logsFeteched = true; + + var url = "/serverstatus/getFurtherDataFromLogFile"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.logstatus == 1) { + + $scope.logFileLoading = true; + $scope.logsFeteched = false; + $scope.couldNotFetchLogs = true; + + $scope.logsData = response.data.logsdata; + + + } + else { + + $scope.logFileLoading = true; + $scope.logsFeteched = true; + $scope.couldNotFetchLogs = false; + + + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.logFileLoading = true; + $scope.logsFeteched = true; + $scope.couldNotFetchLogs = false; + + } + + + $scope.fetchLogs = function () { + + + $scope.logFileLoading = false; + $scope.logsFeteched = true; + $scope.couldNotFetchLogs = true; + + + var url = "/serverstatus/getFurtherDataFromLogFile"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.logstatus == 1) { + + $scope.logFileLoading = true; + $scope.logsFeteched = false; $scope.couldNotFetchLogs = true; - - var url = "/serverstatus/getFurtherDataFromLogFile"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $scope.logsData = response.data.logsdata; - function ListInitialDatas(response) { + } + else { - - - if(response.data.logstatus == 1){ - - $scope.logFileLoading = true; - $scope.logsFeteched = false; - $scope.couldNotFetchLogs = true; - - $scope.logsData = response.data.logsdata; - - - - } - else{ - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = false; - - - } - - - } - function cantLoadInitialDatas(response) { - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = false; - - } - - - - - $scope.fetchLogs = function(){ - - - $scope.logFileLoading = false; + $scope.logFileLoading = true; $scope.logsFeteched = true; - $scope.couldNotFetchLogs = true; + $scope.couldNotFetchLogs = false; - var url = "/serverstatus/getFurtherDataFromLogFile"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + } - function ListInitialDatas(response) { - - - - if(response.data.logstatus == 1){ - - $scope.logFileLoading = true; - $scope.logsFeteched = false; - $scope.couldNotFetchLogs = true; - - $scope.logsData = response.data.logsdata; - - - - } - else{ - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = false; - - - } - - - } - function cantLoadInitialDatas(response) { - - $scope.logFileLoading = true; - $scope.logsFeteched = true; - $scope.couldNotFetchLogs = false; - - } + } + function cantLoadInitialDatas(response) { + $scope.logFileLoading = true; + $scope.logsFeteched = true; + $scope.couldNotFetchLogs = false; + } }; }); - - /* Java script code to read log file ends here */ - /* Java script code to read log file ends here */ /* Services */ -app.controller('servicesManager', function($scope,$http) { +app.controller('servicesManager', function ($scope, $http) { - $scope.services = false; - $scope.btnDisable = false; - $scope.actionLoader = false; + $scope.services = false; + $scope.btnDisable = false; + $scope.actionLoader = false; - function getServiceStatus(){ - $scope.btnDisable = true; + function getServiceStatus() { + $scope.btnDisable = true; - url = "/serverstatus/servicesStatus"; + url = "/serverstatus/servicesStatus"; - $http.post(url).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - if (response.data.status.litespeed) { - $scope.olsStatus = "Running"; - $scope.olsStats = true; - $scope.olsStart = false; - $scope.olsStop = true; - $scope.olsMem = Math.round(parseInt(response.data.memUsage.litespeed) / 1048576) + " MB"; - } - else { - $scope.olsStatus = "Stopped"; - $scope.olsStats = false; - $scope.olsStart = true; - $scope.olsStop = false; - } + if (response.data.status.litespeed) { + $scope.olsStatus = "Running"; + $scope.olsStats = true; + $scope.olsStart = false; + $scope.olsStop = true; + $scope.olsMem = Math.round(parseInt(response.data.memUsage.litespeed) / 1048576) + " MB"; + } + else { + $scope.olsStatus = "Stopped"; + $scope.olsStats = false; + $scope.olsStart = true; + $scope.olsStop = false; + } - // Update SQL stats + // Update SQL stats - if (response.data.status.mysql) { - $scope.sqlStatus = "Running"; - $scope.sqlStats = true; - $scope.sqlStart = false; - $scope.sqlStop = true; - $scope.sqlMem = Math.round(parseInt(response.data.memUsage.mysql) / 1048576) + " MB"; - } - else { - $scope.sqlStatus = "Stopped"; - $scope.sqlStats = false; - $scope.sqlStart = true; - $scope.sqlStop = false; - } + if (response.data.status.mysql) { + $scope.sqlStatus = "Running"; + $scope.sqlStats = true; + $scope.sqlStart = false; + $scope.sqlStop = true; + $scope.sqlMem = Math.round(parseInt(response.data.memUsage.mysql) / 1048576) + " MB"; + } + else { + $scope.sqlStatus = "Stopped"; + $scope.sqlStats = false; + $scope.sqlStart = true; + $scope.sqlStop = false; + } - // Update DNS stats + // Update DNS stats - if (response.data.status.powerdns) { - $scope.dnsStatus = "Running"; - $scope.dnsStats = true; - $scope.dnsStart = false; - $scope.dnsStop = true; - $scope.dnsMem = Math.round(parseInt(response.data.memUsage.powerdns) / 1048576) + " MB"; - } - else { - $scope.dnsStatus = "Stopped"; - $scope.dnsStats = false; - $scope.dnsStart = true; - $scope.dnsStop = false; - } + if (response.data.status.powerdns) { + $scope.dnsStatus = "Running"; + $scope.dnsStats = true; + $scope.dnsStart = false; + $scope.dnsStop = true; + $scope.dnsMem = Math.round(parseInt(response.data.memUsage.powerdns) / 1048576) + " MB"; + } + else { + $scope.dnsStatus = "Stopped"; + $scope.dnsStats = false; + $scope.dnsStart = true; + $scope.dnsStop = false; + } - // Update FTP stats + // Update FTP stats - if (response.data.status.pureftp) { - $scope.ftpStatus = "Running"; - $scope.ftpStats = true; - $scope.ftpStart = false; - $scope.ftpStop = true; - $scope.ftpMem = Math.round(parseInt(response.data.memUsage.pureftp) / 1048576) + " MB"; - } - else { - $scope.ftpStatus = "Stopped"; - $scope.ftpStats = false; - $scope.ftpStart = true; - $scope.ftpStop = false; - } + if (response.data.status.pureftp) { + $scope.ftpStatus = "Running"; + $scope.ftpStats = true; + $scope.ftpStart = false; + $scope.ftpStop = true; + $scope.ftpMem = Math.round(parseInt(response.data.memUsage.pureftp) / 1048576) + " MB"; + } + else { + $scope.ftpStatus = "Stopped"; + $scope.ftpStats = false; + $scope.ftpStart = true; + $scope.ftpStop = false; + } - $scope.services = true; + $scope.services = true; - $scope.btnDisable = false; + $scope.btnDisable = false; - } - function cantLoadInitialDatas(response) { - $scope.couldNotConnect = true; + } - } + function cantLoadInitialDatas(response) { + $scope.couldNotConnect = true; - }; - getServiceStatus(); + } - $scope.serviceAction = function(serviceName, action){ - $scope.ActionProgress = true; - $scope.btnDisable = true; - $scope.ActionSuccessfull = false; - $scope.ActionFailed = false; - $scope.couldNotConnect = false; - $scope.actionLoader = true; + }; + getServiceStatus(); - url = "/serverstatus/servicesAction"; + $scope.serviceAction = function (serviceName, action) { + $scope.ActionProgress = true; + $scope.btnDisable = true; + $scope.ActionSuccessfull = false; + $scope.ActionFailed = false; + $scope.couldNotConnect = false; + $scope.actionLoader = true; - var data = { - service:serviceName, - action:action - }; + url = "/serverstatus/servicesAction"; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var data = { + service: serviceName, + action: action + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - function ListInitialDatas(response) { - console.log(response.data); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - if(response.data.serviceAction == 1){ - setTimeout(function() { - getServiceStatus(); - $scope.ActionSuccessfull = true; - $scope.ActionFailed = false; - $scope.couldNotConnect = false; - $scope.actionLoader = false; - $scope.btnDisable = false; - }, 3000); - } - else{ - setTimeout(function() { - getServiceStatus(); - $scope.ActionSuccessfull = false; - $scope.ActionFailed = true; - $scope.couldNotConnect = false; - $scope.actionLoader = false; - $scope.btnDisable = false; - }, 5000); + function ListInitialDatas(response) { + console.log(response.data); - } - - } - function cantLoadInitialDatas(response) { - $scope.ActionSuccessfull = false; + if (response.data.serviceAction == 1) { + setTimeout(function () { + getServiceStatus(); + $scope.ActionSuccessfull = true; $scope.ActionFailed = false; - $scope.couldNotConnect = true; + $scope.couldNotConnect = false; $scope.actionLoader = false; $scope.btnDisable = false; - } + }, 3000); + } + else { + setTimeout(function () { + getServiceStatus(); + $scope.ActionSuccessfull = false; + $scope.ActionFailed = true; + $scope.couldNotConnect = false; + $scope.actionLoader = false; + $scope.btnDisable = false; + }, 5000); - } + } + + } + + function cantLoadInitialDatas(response) { + $scope.ActionSuccessfull = false; + $scope.ActionFailed = false; + $scope.couldNotConnect = true; + $scope.actionLoader = false; + $scope.btnDisable = false; + } + + } }); + +app.controller('lswsSwitch', function ($scope, $http, $timeout, $window) { + + + $scope.cyberPanelLoading = true; + $scope.installBoxGen = true; + + $scope.switchTOLSWS = function () { + + $scope.cyberPanelLoading = false; + $scope.installBoxGen = true; + + url = "/serverstatus/switchTOLSWS"; + + var data = { + licenseKey: $scope.licenseKey + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + $scope.installBoxGen = false; + getRequestStatus(); + } + else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + }; + + function getRequestStatus() { + $scope.cyberPanelLoading = false; + + url = "/serverstatus/switchTOLSWSStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + if (response.data.abort === 0) { + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } + else { + // Notifications + $scope.cyberPanelLoading = true; + $timeout.cancel(); + $scope.requestData = response.data.requestStatus; + if (response.data.installed === 1) { + $timeout(function () { + $window.location.reload(); + }, 3000); + } + + } + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + + + } + + } + +}); \ No newline at end of file