[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: invisible_captcha.py
File is not writable. Editing disabled.
import re from functools import wraps from logging import getLogger from defence360agent.contracts import config from defence360agent.utils import atomic_rewrite from im360.contracts.config import Webshield from im360.subsys import webshield from im360.subsys.features.abstract_feature import ( AbstractFeature, FeatureError ) _NGINX_CONFIG = '/etc/imunify360-webshield/invisible-captcha.conf' _NGINX_CONFIG_TPL = """ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # DO NOT EDIT. AUTOMATICALLY GENERATED. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # # Direct modifications to this file WILL be lost upon subsequent # regeneration of this configuration file. # # To have your modifications retained, you should use CLI command # imunify360-agent features <install|remove> <feature> # or activate/deactivate appropriate feature in UI. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # set $invisible_captcha {invisible_captcha_on_off}; """ logger = getLogger(__name__) def require_webshield_enabled(fun): @wraps(fun) async def wrapper(*args, **kwargs): if not Webshield.ENABLE: raise FeatureError("Webshield should be " "enabled to use this feature") return await fun(*args, **kwargs) return wrapper class InvisibleCaptcha(AbstractFeature): """ This feature allows to activate/deactivate both aiohttp and Nginx captcha invisible option. """ NAME = 'invisible-captcha' LOG_DIR = '/var/log/%s' % config.Core.PRODUCT INSTALL_LOG_FILE_MASK = '%s/dummy-install.log.*' % LOG_DIR REMOVE_LOG_FILE_MASK = '%s/dummy-remove.log.*' % LOG_DIR OPTION_REGEXP = re.compile(r"^\s*set\s+\$invisible_captcha\s+(on|off);", flags=re.MULTILINE) def __init__(self, sink=None, conf_path=_NGINX_CONFIG): self._conf_path = conf_path super().__init__(sink) async def _check_installed_impl(self) -> bool: with open(self._conf_path) as f: current_conf = f.read() m = self.OPTION_REGEXP.search(current_conf) if m is None: raise FeatureError("Failed to detect invisible captcha state." "Check {} for errors".format(self._conf_path)) return m.group(1) == 'on' @require_webshield_enabled async def check_installed(self) -> bool: return await self._check_installed_impl() @require_webshield_enabled @AbstractFeature.raise_if_shouldnt_install_now async def install(self): """ :return path: to dummy log just to keep to the same usage convention """ await self._set_invisible_captcha('on') return self.INSTALL_LOG_FILE_MASK @require_webshield_enabled @AbstractFeature.raise_if_shouldnt_remove_now async def remove(self): """ :return path: to dummy log just to keep to the same usage convention """ await self._set_invisible_captcha('off') return self.REMOVE_LOG_FILE_MASK async def _set_invisible_captcha(self, new_state): """ :param string new_state: :raise CalledProcessError: :raise OSError: """ new_conf = _NGINX_CONFIG_TPL.format(invisible_captcha_on_off=new_state) atomic_rewrite(self._conf_path, new_conf, backup=False) logger.info("Reloading Webshield service.") await webshield.service_reload()
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.34 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