diff --git a/firewall/firewallManager.py b/firewall/firewallManager.py index e9cf462de..09d95aab0 100644 --- a/firewall/firewallManager.py +++ b/firewall/firewallManager.py @@ -1020,6 +1020,22 @@ class FirewallManager: if owaspInstalled == 1 and comodoInstalled == 1: break + # Also check rules.conf for manual OWASP installations + if owaspInstalled == 0: + rulesConfPath = os.path.join(virtualHostUtilities.Server_root, "conf/modsec/rules.conf") + if os.path.exists(rulesConfPath): + try: + command = "sudo cat " + rulesConfPath + rulesConfig = ProcessUtilities.outputExecutioner(command).splitlines() + for items in rulesConfig: + # Check for OWASP includes in rules.conf (case-insensitive) + if ('owasp' in items.lower() or 'crs-setup' in items.lower()) and \ + ('include' in items.lower() or 'modsecurity_rules_file' in items.lower()): + owaspInstalled = 1 + break + except: + pass + final_dic = { 'modSecInstalled': 1, 'owaspInstalled': owaspInstalled, diff --git a/firewall/static/firewall/firewall.js b/firewall/static/firewall/firewall.js index 1d666ed78..2b4043b64 100644 --- a/firewall/static/firewall/firewall.js +++ b/firewall/static/firewall/firewall.js @@ -1366,7 +1366,8 @@ app.controller('modSecRulesPack', function ($scope, $http, $timeout, $window) { $scope.installationFailed = true; $scope.installationSuccess = false; - getOWASPAndComodoStatus(false); + // Update toggle state immediately to reflect installation result + getOWASPAndComodoStatus(true); } else { $scope.modsecLoading = true; @@ -1379,6 +1380,9 @@ app.controller('modSecRulesPack', function ($scope, $http, $timeout, $window) { $scope.installationSuccess = true; $scope.errorMessage = response.data.error_message; + + // Update toggle to reflect failed installation (will show OFF) + getOWASPAndComodoStatus(true); } } diff --git a/plogical/modSec.py b/plogical/modSec.py index 90ee4eee3..8b2e708d2 100644 --- a/plogical/modSec.py +++ b/plogical/modSec.py @@ -405,6 +405,7 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf command = 'mkdir -p /usr/local/lsws/conf/modsec' result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to create modsec directory [setupOWASPRules]") return 0 if os.path.exists(pathToOWASFolderNew): @@ -420,30 +421,35 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to download OWASP CRS from GitHub. Check internet connection. [setupOWASPRules]") return 0 command = "unzip -o /usr/local/lsws/conf/modsec/owasp.zip -d /usr/local/lsws/conf/modsec/" result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to extract OWASP CRS zip file. Ensure unzip is installed. [setupOWASPRules]") return 0 command = 'mv /usr/local/lsws/conf/modsec/coreruleset-3.3.2 /usr/local/lsws/conf/modsec/owasp-modsecurity-crs-3.0-master' result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to rename OWASP CRS directory. File may already exist. [setupOWASPRules]") return 0 command = 'mv %s/crs-setup.conf.example %s/crs-setup.conf' % (pathToOWASFolderNew, pathToOWASFolderNew) result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to setup crs-setup.conf configuration file. [setupOWASPRules]") return 0 command = 'mv %s/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example %s/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf' % (pathToOWASFolderNew, pathToOWASFolderNew) result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to setup REQUEST-900 exclusion rules. [setupOWASPRules]") return 0 command = 'mv %s/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example %s/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf' % ( @@ -451,6 +457,7 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf result = subprocess.call(shlex.split(command)) if result != 0: + logging.CyberCPLogFileWriter.writeToFile("Failed to setup RESPONSE-999 exclusion rules. [setupOWASPRules]") return 0 content = """include {pathToOWASFolderNew}/crs-setup.conf