Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/sharedra...
File: software_report.py
#!/opt/imh-python/bin/python3
[0] Fix | Delete
"""Runs check_software on all users and stores the results
[1] Fix | Delete
in /var/log/software_reports"""
[2] Fix | Delete
# Written by JosephM
[3] Fix | Delete
from argparse import ArgumentParser
[4] Fix | Delete
import os
[5] Fix | Delete
import subprocess
[6] Fix | Delete
import sys
[7] Fix | Delete
import multiprocessing
[8] Fix | Delete
import time
[9] Fix | Delete
from pathlib import Path
[10] Fix | Delete
import rads
[11] Fix | Delete
from cpapis import whmapi1, CpAPIError
[12] Fix | Delete
[13] Fix | Delete
LOGDIR = Path("/var/log/software_reports")
[14] Fix | Delete
MAX_LOAD = multiprocessing.cpu_count()
[15] Fix | Delete
[16] Fix | Delete
# users to not run check_software on
[17] Fix | Delete
RESERVED = rads.OUR_RESELLERS + [rads.SECURE_USER]
[18] Fix | Delete
[19] Fix | Delete
[20] Fix | Delete
def main():
[21] Fix | Delete
# blank argparse so -h doesn't surprise anyone by immediately running
[22] Fix | Delete
ArgumentParser(description=__doc__).parse_args()
[23] Fix | Delete
if os.getuid() != 0:
[24] Fix | Delete
print("This tool must be run as root. Exiting...")
[25] Fix | Delete
sys.exit(1)
[26] Fix | Delete
LOGDIR.mkdir(mode=0o755, parents=True, exist_ok=True)
[27] Fix | Delete
check_software_cmd = ['/opt/sharedrads/check_software', '-r']
[28] Fix | Delete
rcode = 0
[29] Fix | Delete
[30] Fix | Delete
try:
[31] Fix | Delete
api = whmapi1('listaccts', check=True)
[32] Fix | Delete
except CpAPIError as exc:
[33] Fix | Delete
sys.exit(f'Unable to retrieve user list! {exc}')
[34] Fix | Delete
users = [x['user'] for x in api['data']['acct'] if x not in RESERVED]
[35] Fix | Delete
[36] Fix | Delete
for user in users:
[37] Fix | Delete
user_log = LOGDIR / f"{user}.txt"
[38] Fix | Delete
cmd = check_software_cmd.copy()
[39] Fix | Delete
cmd.append(user)
[40] Fix | Delete
try:
[41] Fix | Delete
with open(user_log, 'wb') as file:
[42] Fix | Delete
user_log.chmod(0o600)
[43] Fix | Delete
subprocess.run(cmd, stdout=file, stderr=file, check=False)
[44] Fix | Delete
except Exception:
[45] Fix | Delete
print("Error running check_software on", user, file=sys.stderr)
[46] Fix | Delete
rcode = 2
[47] Fix | Delete
if os.getloadavg()[0] > MAX_LOAD:
[48] Fix | Delete
time.sleep(5)
[49] Fix | Delete
print("Sleeping due to high server load...")
[50] Fix | Delete
while os.getloadavg()[0] > MAX_LOAD:
[51] Fix | Delete
time.sleep(5)
[52] Fix | Delete
sys.exit(rcode)
[53] Fix | Delete
[54] Fix | Delete
[55] Fix | Delete
if __name__ == '__main__':
[56] Fix | Delete
main()
[57] Fix | Delete
[58] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function