|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /opt/alt/python37/lib/python3.7/site-packages/clwpos/ |
Upload File : |
#!/opt/alt/python37/bin/python3
# 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
#
import json
import argparse
import os
import logging
from clwpos.logsetup import setup_logging
from clwpos.optimization_modules import (
get_allowed_modules,
get_admin_config_directory,
get_admin_config_permissions,
)
from clwpos.utils import acquire_lock, user_uid, get_pw, is_wpos_supported
from clwpos.daemon import whmapi1, WposDaemon
_logger = setup_logging(
caller_name='collect_information',
file_level=logging.INFO,
logfile_path='/var/log/clwpos/collect_information.log',
)
def php_get_vhost_versions():
"""
@return: [
{
"account": "rm3",
"account_owner": "root",
"documentroot": "/home/example/public_html",
"homedir": "/home/rm3",
"is_suspended": 0,
"main_domain": 1,
"php_fpm": 1,
"php_fpm_pool_parms": {
"pm_max_children": 5,
"pm_max_requests": 20,
"pm_process_idle_timeout": 10
},
"phpversion_source": [
{
"domain": "example.com",
"system_default": 1
}
],
"version": "ea-php72",
"vhost": "otherchars.rm3.tld"
}
]
"""
return whmapi1(WposDaemon.DAEMON_PHP_GET_VHOST_VERSIONS_COMMAND)["versions"]
def php_get_installed_versions():
"""
@return: [
"ea-php74"
]
"""
return whmapi1(WposDaemon.DAEMON_PHP_GET_INSTALLED_VERSIONS_COMMAND)["versions"]
def listaccts():
"""
@return: [
{
"backup": 0,
"child_nodes": [
{
"alias": "nodealias",
"workload": "Mail"
}
],
"disklimit": "unlimited",
"diskused": "14M",
"domain": "example.com",
"email": "username@example.com",
"has_backup": 1,
"inodeslimit": "unlimited",
"inodesused": 1,
"ip": "192.168.0.128",
"ipv6": [
"0101:ca75:0101:ca75:0101:ca75:0101:ca77"
],
"is_locked": 0,
"legacy_backup": 0,
"mailbox_format": "mdbox",
"max_defer_fail_percentage": "unlimited",
"max_email_per_hour": "unlimited",
"max_emailacct_quota": "unlimited",
"maxaddons": "unlimited",
"maxftp": "unlimited",
"maxlst": "unlimited",
"maxparked": "unlimited",
"maxpop": "unlimited",
"maxsql": "unlimited",
"maxsub": "unlimited",
"min_defer_fail_to_trigger_protection": "unlimited",
"outgoing_mail_hold": 1,
"outgoing_mail_suspended": 0,
"owner": "root",
"partition": "home",
"plan": "packagename",
"shell": "/bin/bash",
"startdate": "13 May 22 16:03",
"suspended": 0,
"suspendreason": "not suspended",
"suspendtime": 1594040856,
"temporary": 0,
"theme": "paper_lantern",
"uid": 1001,
"unix_startdate": 1369256589,
"user": "username"
}
]
"""
return whmapi1("listaccts")["acct"]
if __name__ == '__main__' and is_wpos_supported():
with acquire_lock(os.path.join('/var/run/collect_information.lock',), attempts=None):
parser = argparse.ArgumentParser(description="Utility to collect information about user for AccelerateWP")
parser.add_argument("user", type=str, nargs="?")
args = parser.parse_args()
installed_versions = php_get_installed_versions()
vhost_versions = php_get_vhost_versions()
target_accounts = listaccts()
target_accounts = list(filter(lambda x: get_allowed_modules(int(x["uid"])), target_accounts))
if args.user is not None:
target_accounts = list(filter(lambda x: int(x["uid"]) == user_uid(username=args.user), target_accounts))
for account in target_accounts:
username = account["user"]
filtered_vhost_versions = [version for version in vhost_versions if version["account"] == username]
try:
pw = get_pw(username=username)
admin_config_dir = get_admin_config_directory(pw.pw_uid)
info_json = os.path.join(admin_config_dir, "info.json")
with open(info_json, "w") as f:
json.dump(
{"installed_versions": installed_versions,
"vhost_versions": filtered_vhost_versions},
f,
)
owner, group, mode = get_admin_config_permissions(pw.pw_gid)
os.chown(info_json, owner, group)
os.chmod(info_json, mode)
except Exception as e:
_logger.exception("Error during collecting information for %s: %s", username, e)
continue