[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: configuration_management.py
File is not writable. Editing disabled.
"""Endpoints for configuration management commands. - manage ModSecurity directives, rulesets. """ import logging from collections import namedtuple from defence360agent.rpc_tools import lookup from defence360agent.rpc_tools.validate import ValidationError from defence360agent.utils import Scope from im360.contracts import config from im360.subsys.panels import hosting_panel __all__ = [] logger = logging.getLogger(__name__) ISSUE_ID_MODSEC_DIRECTIVE_WRONG_VALUE = "1000" MODSEC_DIRECTIVES = dict( (attr, getattr(config.ModSecurityDirectives, attr)) for attr in dir(config.ModSecurityDirectives) if attr.startswith("Sec") ) Issue = namedtuple("Issue", "id title fix url ignored") issues_modsec_directives = [ ( directive, expected, Issue( ISSUE_ID_MODSEC_DIRECTIVE_WRONG_VALUE, "Wrong value for {directive} ModSecurity directive." " Expected: {expected!r} Got: {{got!r}}".format(**vars()), "Run `imunify360-agent fix modsec directives` command", "https://docs.imunify360.com/issues/" + ISSUE_ID_MODSEC_DIRECTIVE_WRONG_VALUE, ignored=False, ), ) for directive, expected in MODSEC_DIRECTIVES.items() ] class ModSecEndpoints(lookup.RootEndpoints): SCOPE = Scope.IM360 def __init__(self, sink): super().__init__(sink) self.hosting_panel = hosting_panel.HostingPanel() @lookup.bind("check", "modsec", "directives") async def validate_modsec_directives(self): skip = config.StopManaging.MODSEC_DIRECTIVES issues = [] for directive, expected, issue in issues_modsec_directives: got = await self.hosting_panel.modsec_get_directive(directive) if got != expected: logger.debug( "directive %r got %r expected %r", directive, got, expected, ) issue = issue._replace(ignored=skip) issues.append( dict(issue._asdict(), title=issue.title.format(**vars())) ) if not all(issue["ignored"] for issue in issues): # there are issues that not ignored raise ValidationError(issues) # produce warnings return {"items": issues} # no issues or all issues are ignored @lookup.bind("fix", "modsec", "directives") async def reset_modsec_directives(self): if config.StopManaging.MODSEC_DIRECTIVES: return { "items": [ "Skipped resetting ModSecurity directives." "\nTo reenable the command, run:" """\n imunify360-agent config update '{"STOP_MANAGING": {"modsec_directives": false}}'""" # noqa ] } await self.hosting_panel.reset_modsec_directives() return {"items": []} @lookup.bind("check", "modsec", "rulesets") async def validate_modsec_rulesets(self): raise NotImplementedError @lookup.bind("fix", "modsec", "rulesets") async def reset_modsec_rulesets(self): raise NotImplementedError
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server05.hostinghome.co.in
Server IP: 192.168.74.40
PHP Version: 7.4.33
Server Software: Apache
System: Linux server05.hostinghome.co.in 3.10.0-962.3.2.lve1.5.81.el7.x86_64 #1 SMP Wed May 31 10:36:47 UTC 2023 x86_64
HDD Total: 1.95 TB
HDD Free: 691.07 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Disabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: itsweb
User ID (UID): 1619
Group ID (GID): 1621
Script Owner UID: 1619
Current Dir Owner: N/A