!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache. PHP/5.6.40 

uname -a: Linux cpanel06wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.80.el6.x86_64 #1 SMP Thu Sep 24
01:42:00 EDT 2020 x86_64
 

uid=851(cp949260) gid=853(cp949260) groups=853(cp949260) 

Safe-mode: OFF (not secure)

/opt/alt/python37/lib/python3.7/site-packages/clwpos/   drwxr-xr-x
Free 234 GB of 981.82 GB (23.83%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     daemon_base.py (5.1 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENCE.TXT
#

# pylint: disable=no-absolute-import

import logging
import os
import signal
import json
from typing import Tuple

from clcommon.utils import get_process_pid
from clwpos.logsetup import setup_logging, init_wpos_sentry_safely


class WposDaemonBase:
    """
    AccelerateWP daemon base class. Signals, signal handlers, setup daemon logger, pid file operations
    """
    _PID_FILENAME = "/var/run/clwpos_monitoring.pid"
    _DAEMON_LOGFILE_PATH = "/var/log/clwpos/daemon.log"
    _DAEMON_CONFIG_PATH = "/etc/clwpos/daemon_conf.json"
    # Default redis monitoring interval 300 seconds = 5 min
    _DEFAULT_MONITORING_INTERVAL = 300

    def __init__(self):
        self._reload_config_need = False
        self._is_terminate = False
        self._monitoring_interval, self._is_reload_interval_enabled, is_full_logging_mode = \
            self._update_monitoring_interval()
        self._logger = setup_logging(
            caller_name=__name__,
            console_level=logging.DEBUG if is_full_logging_mode else logging.INFO,
            file_level=logging.DEBUG if is_full_logging_mode else logging.INFO,
            logfile_path=self._DAEMON_LOGFILE_PATH
        )
        init_wpos_sentry_safely(self._logger)
        self._logger.info("Cloudlinux AccelerateWP daemon uses monitoring interval: %d seconds", self._monitoring_interval)
        if not self._is_reload_interval_enabled:
            self._logger.info("NOTE: Cloudlinux AccelerateWP daemon check reload interval is OFF by config")
        if is_full_logging_mode:
            self._logger.info("NOTE: Cloudlinux AccelerateWP daemon full logging mode is ON by config")

    def _update_monitoring_interval(self) -> Tuple[int, bool, bool]:
        """
        Read daemon parameters from config /etc/clwpos/daemon_conf.json. Use only for debug/testing.
        :return: tuple (monitoring_interval, is_reload_interval_enabled, is_full_logging_mode)
            monitoring_interval: redises monitoring inteval, seconds
            is_reload_interval_enabled: True - daemon will disable 'reload' command via socket from same user
                                                 more often then 1 minute
                                         False - daemon will not check time between 'reload' command,
                                                  all queries will be processed
            is_full_logging_mode: True - debug messages will be written to log
                                  False - debug messages will not be written to log
        """
        try:
            with open(self._DAEMON_CONFIG_PATH, 'r') as f:
                daemon_config = json.load(f)
                monitoring_interval = daemon_config['monitoring_interval_5secs'] * 5
                is_reload_interval_enabled = daemon_config.get('is_reload_interval_enabled', True)
                is_full_logging_mode = daemon_config.get('is_full_logging_mode', False)
        except (OSError, IOError, json.JSONDecodeError, KeyError):
            # Config read error, stay default
            monitoring_interval = self._DEFAULT_MONITORING_INTERVAL
            is_reload_interval_enabled = True
            is_full_logging_mode = False
        return monitoring_interval, is_reload_interval_enabled, is_full_logging_mode

    def _setup_signals(self):
        """
        Setup daemon signal handlers
        """
        # Setup SIGHUP signal handler for config reload
        signal.signal(signal.SIGHUP, self._sighup_handler)
        # Setup Ctrl-C signal handler. Used for console debug
        signal.signal(signal.SIGINT, self._sigint_handler)
        # Setup SIGTERM signal. Called when daemon stops
        signal.signal(signal.SIGTERM, self._sigterm_handler)

    def run(self):
        """
        Main work daemon function (implement in child class)
        """
        raise NotImplementedError()

    def stop(self, *args, **kwargs):
        """
        Stops a working daemon process (implement in child class)
        """
        raise NotImplementedError()

    def reload(self):
        """
        Reload working daemon process by sending SIGHUP signal to it
        """
        try:
            pid = get_process_pid(self._PID_FILENAME)
            if pid:
                os.kill(pid, signal.SIGHUP)
        except:
            pass

    def _sighup_handler(self, signum, frame):
        """
        SIGHUP signal handler
        """
        # Load new user configuration from config file
        self._reload_config_need = True
        self._logger.info("SIGHUP: Cloudlinux AccelerateWP daemon sheduled for reload")

    def _sigint_handler(self, signum, frame):
        """
        SIGINT (Ctrl-C) signal handler. For console debug
        """
        self._logger.info("Ctrl-C received, exit")
        # Terminate main cycle
        self._is_terminate = True

    def _sigterm_handler(self, signum, frame):
        """
        SIGTERM signal handler. Called when daemon stopping
        """
        # Terminate main cycle
        self._is_terminate = True

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0193 ]--