$11 GRAYBYTE WORDPRESS FILE MANAGER $50

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos//wpos_req_scanner.py
#!/opt/cloudlinux/venv/bin/python3 -bb
# -*- coding: utf-8 -*-

# clwposcron Utility to scan domains for Cloudlinux WPOS requirements by cron
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

# pylint: disable=no-absolute-import

import os
import time
import subprocess
import logging
import json

from clwpos.logsetup import setup_logging


class CloudlinuxWposReqScanner(object):
    """
    Class for run clwposcron functionality
    """
    TIMEOUT_24H_SECONDS = 24 * 3600
    _CRON_LOG_FILE = '/var/log/clwpos/req_cron.log'

    def __init__(self):
        self._file_flag_force_check = '/var/lve/clwpos/cl_wpos_scan_req_force'
        self._scan_req_scan_last_ts = '/var/lve/clwpos/cl_wpos_scan_req_last_ts'
        self._logger = setup_logging(
            caller_name='clwpos_req_cron',
            # Uncomment this for console debug
            # console_level=logging.DEBUG,
            file_level=logging.INFO,
            logfile_path=self._CRON_LOG_FILE
        )

    def _get_last_start_time(self) -> float:
        """
        Get last time start time from file
        :return: Last start time as UNIX timestamp
        """
        try:
            with open(self._scan_req_scan_last_ts, 'r') as f:
                s_last_ts = f.read()
            last_ts = float(s_last_ts)
        except (OSError, IOError, ValueError):
            last_ts = 0.0
        return last_ts

    def _save_last_start_time(self, last_time: float):
        """
        Save last time to file
        :param last_time: Last time (UNIX timestamp) to save
        """
        with open(self._scan_req_scan_last_ts, 'w') as f:
            f.write(str(last_time))

    def _is_24h_passed(self, ts_now: float) -> bool:
        """
        Check is 24h interval passed
        :param ts_now: 'now' UNIX timestamp
        :return: True - passed, False - not passed
        """
        last_ts = self._get_last_start_time()
        if last_ts != 0.0 and ts_now - last_ts < self.TIMEOUT_24H_SECONDS:
            # 24h not passed
            return False
        return True

    def run(self):
        """
        Run command action
        """
        self._logger.debug("CL AWP requirements cron script started")
        try:
            if not os.path.exists(self._file_flag_force_check):
                # force start flag file absent, check 24h timeout
                ts_now = time.time()
                is_24h_passed = self._is_24h_passed(ts_now)
                if not is_24h_passed:
                    # 24h not passed from last run this script - do nothing
                    self._logger.debug("24 hours not passed - do nothing")
                    return 0
                # timestamp file old/absent, create it
                self._save_last_start_time(ts_now)
            else:
                self._logger.info("Force start")
                # Force start
                try:
                    os.remove(self._file_flag_force_check)
                except (OSError, IOError):
                    self._logger.exception(f'{self._file_flag_force_check} remove error', exc_info=True)
            # Run file generation
            try:
                # /usr/bin/clwpos-admin generate-report --all
                proc = subprocess.Popen(['/usr/bin/clwpos-admin', 'generate-report', '--all'],
                                        shell=False,
                                        stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
                stdout, stderr = proc.communicate()
                if proc.returncode != 0:
                    self._logger.warning('/usr/bin/clwpos-admin generate-report start error: retcode=%d\n'
                                         'stdout: %s\nstderr: %s', proc.returncode, stdout, stderr)
                result_dict = json.loads(stdout)
                if result_dict['result'] != 'success':
                    self._logger.info(f'/usr/bin/clwpos-admin generate-report result: {stdout}')
                    self._logger.warning('/usr/bin/clwpos-admin generate-report error')
            except (OSError, IOError, json.JSONDecodeError, KeyError):
                self._logger.exception('/usr/bin/clwpos-admin generate-report start exception', exc_info=True)
        except:
            self._logger.exception('CL AWP requirements cron script general error', exc_info=True)
        return 0

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
16 Dec 2025 9.38 PM
root / root
0755
bin
--
16 Dec 2025 9.31 PM
root / root
0755
cli_versions
--
16 Dec 2025 9.31 PM
root / root
0755
feature_suites
--
16 Dec 2025 9.31 PM
root / root
0755
hooks
--
16 Dec 2025 9.31 PM
root / root
0755
migrations
--
16 Dec 2025 9.31 PM
root / root
0755
object_cache
--
16 Dec 2025 9.31 PM
root / root
0755
optimization_features
--
16 Dec 2025 9.31 PM
root / root
0755
php
--
16 Dec 2025 9.31 PM
root / root
0755
user
--
16 Dec 2025 9.31 PM
root / root
0755
__init__.py
0.906 KB
29 Sep 2025 8.34 PM
root / root
0644
billing.py
6.242 KB
29 Sep 2025 8.34 PM
root / root
0644
cl_wpos_exceptions.py
3.591 KB
29 Sep 2025 8.34 PM
root / root
0644
constants.py
5.562 KB
29 Sep 2025 8.34 PM
root / root
0644
create_user_uid_dirs.py
0.736 KB
29 Sep 2025 8.34 PM
root / root
0644
cron.py
2.138 KB
29 Sep 2025 8.34 PM
root / root
0644
daemon.py
37.119 KB
29 Sep 2025 8.34 PM
root / root
0644
daemon_base.py
2.844 KB
29 Sep 2025 8.34 PM
root / root
0644
daemon_config.py
0.606 KB
29 Sep 2025 8.34 PM
root / root
0644
daemon_redis_lib.py
11.932 KB
29 Sep 2025 8.34 PM
root / root
0644
daemon_subscription_handler.py
6.438 KB
29 Sep 2025 8.34 PM
root / root
0644
data_collector_utils.py
9.418 KB
29 Sep 2025 8.34 PM
root / root
0644
logsetup.py
4.045 KB
29 Sep 2025 8.34 PM
root / root
0644
papi.py
9.867 KB
29 Sep 2025 8.34 PM
root / root
0644
parse.py
2.104 KB
29 Sep 2025 8.34 PM
root / root
0644
redis_configuration_pid_file_cleaner.py
1.013 KB
29 Sep 2025 8.34 PM
root / root
0755
report_generator.py
21.176 KB
29 Sep 2025 8.34 PM
root / root
0644
scoped_cache.py
1.34 KB
29 Sep 2025 8.34 PM
root / root
0644
socket_utils.py
4.029 KB
29 Sep 2025 8.34 PM
root / root
0644
stats.py
12.016 KB
29 Sep 2025 8.34 PM
root / root
0644
utils.py
54.336 KB
29 Sep 2025 8.34 PM
root / root
0644
whmcs_utils.py
9.361 KB
29 Sep 2025 8.34 PM
root / root
0644
wp_config.py
0.708 KB
29 Sep 2025 8.34 PM
root / root
0644
wp_utils.py
16.33 KB
29 Sep 2025 8.34 PM
root / root
0644
wpos_admin.py
67.14 KB
29 Sep 2025 8.34 PM
root / root
0644
wpos_hooks.py
4.854 KB
29 Sep 2025 8.34 PM
root / root
0755
wpos_req_scanner.py
4.38 KB
29 Sep 2025 8.34 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF