Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/smshex_r.../opt/sharedra...
File: cms_counter.py
#!/opt/imh-python/bin/python3
[0] Fix | Delete
"""
[1] Fix | Delete
CMS Counter 2.1
[2] Fix | Delete
06/03/2024
[3] Fix | Delete
Corey S
[4] Fix | Delete
-------
[5] Fix | Delete
All Server Version
[6] Fix | Delete
- Should be acceptable for any server environment
[7] Fix | Delete
- Server Type determined by Fabric wrapper ckx.run_cms_counter() and passed to script via '-s'
[8] Fix | Delete
- 3rd Party/Additional Panels added to determine_panel_type()
[9] Fix | Delete
- Refactored NodeJS detection split into its own module
[10] Fix | Delete
- '--new' switch added to only check newly provisioned accounts
[11] Fix | Delete
- Overall code refactored to be more efficient
[12] Fix | Delete
"""
[13] Fix | Delete
import os
[14] Fix | Delete
import subprocess
[15] Fix | Delete
import glob
[16] Fix | Delete
import platform
[17] Fix | Delete
import sys
[18] Fix | Delete
from pathlib import Path
[19] Fix | Delete
import argparse
[20] Fix | Delete
import json
[21] Fix | Delete
import re
[22] Fix | Delete
[23] Fix | Delete
def run(command=None,check_flag=True,error_flag=True):
[24] Fix | Delete
"""
[25] Fix | Delete
check_flag ignores if the command exits w/ anything other than 0 if True
[26] Fix | Delete
error_flag sends errors to /dev/null if set to True
[27] Fix | Delete
"""
[28] Fix | Delete
output = None
[29] Fix | Delete
if command and str(command) and error_flag == True:
[30] Fix | Delete
try:
[31] Fix | Delete
output = subprocess.run(
[32] Fix | Delete
command,
[33] Fix | Delete
shell=True,
[34] Fix | Delete
check = check_flag,
[35] Fix | Delete
stdout=subprocess.PIPE
[36] Fix | Delete
).stdout.decode("utf-8").strip()
[37] Fix | Delete
except Exception as e:
[38] Fix | Delete
print(e)
[39] Fix | Delete
elif command and str(command) and error_flag == False:
[40] Fix | Delete
try:
[41] Fix | Delete
output = subprocess.run(
[42] Fix | Delete
command,
[43] Fix | Delete
shell=True,
[44] Fix | Delete
check = check_flag,
[45] Fix | Delete
stdout=subprocess.PIPE,
[46] Fix | Delete
stderr=subprocess.DEVNULL
[47] Fix | Delete
).stdout.decode("utf-8").strip()
[48] Fix | Delete
except:
[49] Fix | Delete
return
[50] Fix | Delete
return output
[51] Fix | Delete
[52] Fix | Delete
[53] Fix | Delete
[54] Fix | Delete
def determine_panel_type():
[55] Fix | Delete
"""
[56] Fix | Delete
Determines type of Panel in use on server, i.e. CWP, Platform i, Plesk, etc
[57] Fix | Delete
[58] Fix | Delete
Panels Currently Supported:
[59] Fix | Delete
- cPanel
[60] Fix | Delete
- CWP
[61] Fix | Delete
- Platform i
[62] Fix | Delete
- Webmin
[63] Fix | Delete
- Plesk
[64] Fix | Delete
- ISPConfig
[65] Fix | Delete
- DirectAdmin
[66] Fix | Delete
- CloudPanel
[67] Fix | Delete
"""
[68] Fix | Delete
if os.path.exists('/var/cpanel'): # cPanel
[69] Fix | Delete
return 'cPanel'
[70] Fix | Delete
elif os.path.exists('/usr/local/cwp'): # CWP
[71] Fix | Delete
return 'CWP'
[72] Fix | Delete
elif os.path.exists('/etc/profile.d/wp3.sh'): # Platform i
[73] Fix | Delete
return 'Platform_i'
[74] Fix | Delete
elif os.path.exists('/etc/webmin'): # Webmin
[75] Fix | Delete
return 'Webmin'
[76] Fix | Delete
elif os.path.exists('/etc/httpd/conf.d/zz010_psa_httpd.conf') or os.path.exists('/etc/apache2/conf.d/zz010_psa_httpd.conf'): # Plesk
[77] Fix | Delete
return 'Plesk'
[78] Fix | Delete
elif os.path.exists('/usr/local/directadmin'): # DirectAdmin
[79] Fix | Delete
return 'DirectAdmin'
[80] Fix | Delete
elif os.path.exists('/usr/local/bin/dploy'): # CloudPanel
[81] Fix | Delete
return 'CloudPanel'
[82] Fix | Delete
elif os.path.exists('/home/admispconfig/ispconfig/lib/config.inc.php'): # ISPConfig 2
[83] Fix | Delete
return 'ISPConfig-2'
[84] Fix | Delete
elif os.path.exists('/usr/local/ispconfig/interface/lib/config.inc.php'): # ISPConfig 3
[85] Fix | Delete
return 'ISPConfig-3'
[86] Fix | Delete
[87] Fix | Delete
[88] Fix | Delete
return 'cVPS'
[89] Fix | Delete
[90] Fix | Delete
[91] Fix | Delete
def identify_apache_config():
[92] Fix | Delete
"""
[93] Fix | Delete
Function to determine Apache config file to use to check domains as different installs/versions can store the config in different files, starting w/ config for 2.2 and checking different 2.4 config locations to end
[94] Fix | Delete
"""
[95] Fix | Delete
config_file = None
[96] Fix | Delete
if os.path.exists('/usr/local/apache/conf/httpd.conf'):
[97] Fix | Delete
return '/usr/local/apache/conf/httpd.conf'
[98] Fix | Delete
elif os.path.exists('/etc/httpd/conf/httpd.conf'):
[99] Fix | Delete
return '/etc/httpd/conf/httpd.conf'
[100] Fix | Delete
elif os.path.exists('/etc/apache2/httpd.conf'):
[101] Fix | Delete
return '/etc/apache2/httpd.conf'
[102] Fix | Delete
elif os.path.exists('/etc/apache2/conf/httpd.conf'):
[103] Fix | Delete
return '/etc/apache2/conf/httpd.conf'
[104] Fix | Delete
else:
[105] Fix | Delete
sys.exit('Unable to determine Apache config!\nQuitting...')
[106] Fix | Delete
[107] Fix | Delete
def identify_nginx_config():
[108] Fix | Delete
"""
[109] Fix | Delete
Function to find NGINX config file
[110] Fix | Delete
"""
[111] Fix | Delete
if os.path.exists('/etc/nginx/vhosts'):
[112] Fix | Delete
return '/etc/nginx/vhosts'
[113] Fix | Delete
elif os.path.exists('/etc/nginx/conf.d/vhosts'):
[114] Fix | Delete
return '/etc/nginx/conf.d/vhosts'
[115] Fix | Delete
elif os.path.exists('/etc/nginx/nginx.conf'):
[116] Fix | Delete
return '/etc/nginx/nginx.conf'
[117] Fix | Delete
else:
[118] Fix | Delete
sys.exit("Unable to locate NGINX config file! Quitting...")
[119] Fix | Delete
[120] Fix | Delete
[121] Fix | Delete
def find_nodejs(docroot=None, domain=None):
[122] Fix | Delete
"""
[123] Fix | Delete
Find possible Node.JS installs per doc root
[124] Fix | Delete
"""
[125] Fix | Delete
install_list = []
[126] Fix | Delete
if docroot and '\n' not in str(docroot):
[127] Fix | Delete
user = docroot.split('/')[2]
[128] Fix | Delete
if os.path.exists(f"""{docroot}/.htaccess"""):
[129] Fix | Delete
try:
[130] Fix | Delete
with open(f"""{docroot}/.htaccess""", encoding='utf-8') as htaccess:
[131] Fix | Delete
for line in htaccess.readlines():
[132] Fix | Delete
if 'PassengerAppRoot' in line:
[133] Fix | Delete
install_dir = line.split()[1].strip().strip('"')
[134] Fix | Delete
if f"""{domain}:{install_dir}""" not in install_list:
[135] Fix | Delete
install_list.append(f"""{domain}:{install_dir}""") # Dont want a dictionary as a single domain could have multiple subdir installs
[136] Fix | Delete
except:
[137] Fix | Delete
return
[138] Fix | Delete
if len(install_list) == 0: # If not found in htaccess, check via procs instead
[139] Fix | Delete
user_id = run(f"""id -u {user}""", check_flag=False, error_flag=False)
[140] Fix | Delete
if user_id and user_id.isdigit():
[141] Fix | Delete
node_procs = run(f"""pgrep -U {user_id} node""", check_flag=False, error_flag=False).split('\n') #Only return procs whose true owner is the user ID of the currently checked user
[142] Fix | Delete
if len(node_procs) > 0:
[143] Fix | Delete
for pid in node_procs:
[144] Fix | Delete
try:
[145] Fix | Delete
cwd = run(f"""pwdx {pid} | cut -d ':' -f 2""", check_flag=False, error_flag=False)
[146] Fix | Delete
command = run(f"""ps --no-headers -o command {pid} | """ + """awk '{print $2}'""", check_flag=False, error_flag=False).split('.')[1]
[147] Fix | Delete
install_dir = cwd + command
[148] Fix | Delete
except:
[149] Fix | Delete
return
[150] Fix | Delete
if install_dir and os.path.exists(install_dir) and f"""{domain}:{install_dir}""" not in install_list:
[151] Fix | Delete
install_list.append(f"""{domain}:{install_dir}""")
[152] Fix | Delete
return install_list
[153] Fix | Delete
[154] Fix | Delete
[155] Fix | Delete
[156] Fix | Delete
def determine_cms(docroot=None):
[157] Fix | Delete
"""
[158] Fix | Delete
Determine CMS manually with provided document root by matching expected config files for known CMS
[159] Fix | Delete
"""
[160] Fix | Delete
cms = None
[161] Fix | Delete
docroot = str(docroot)
[162] Fix | Delete
cms_dictionary = {
[163] Fix | Delete
f"""{docroot}/concrete.php""": 'Concrete',
[164] Fix | Delete
f"""{docroot}/Mage.php""": 'Magento',
[165] Fix | Delete
f"""{docroot}/clientarea.php""": 'WHMCS',
[166] Fix | Delete
f"""{docroot}/configuration.php""": 'Joomla',
[167] Fix | Delete
f"""{docroot}/ut.php""": 'PHPList',
[168] Fix | Delete
f"""{docroot}/passenger_wsgi.py""": 'Django',
[169] Fix | Delete
f"""{docroot}/wp-content/plugins/boldgrid-inspirations""": 'BoldGrid',
[170] Fix | Delete
f"""{docroot}/wp-config.php""": 'Wordpress',
[171] Fix | Delete
f"""{docroot}/sites/default/settings.php""": 'Drupal',
[172] Fix | Delete
f"""{docroot}/includes/configure.php""": 'ZenCart',
[173] Fix | Delete
f"""{docroot}/config/config.inc.php""": 'Prestashop',
[174] Fix | Delete
f"""{docroot}/config/settings.inc.php""": 'Prestashop',
[175] Fix | Delete
f"""{docroot}/app/etc/env.php""": 'Magento',
[176] Fix | Delete
f"""{docroot}/app/etc/local.xml""": 'Magento',
[177] Fix | Delete
f"""{docroot}/vendor/laravel""": 'Laravel',
[178] Fix | Delete
}
[179] Fix | Delete
for config_file,content in cms_dictionary.items():
[180] Fix | Delete
if os.path.exists(config_file):
[181] Fix | Delete
return content
[182] Fix | Delete
if os.path.exists(f"""{docroot}/index.php"""):
[183] Fix | Delete
try:
[184] Fix | Delete
with open(f"""{docroot}/index.php""", encoding='utf-8') as index:
[185] Fix | Delete
for line in index.readlines():
[186] Fix | Delete
if re.search('CodeIgniter', line, re.IGNORECASE):
[187] Fix | Delete
return 'CodeIgniter'
[188] Fix | Delete
except Exception as e:
[189] Fix | Delete
print(e)
[190] Fix | Delete
if os.path.exists(f"""{docroot}/main.ts"""):
[191] Fix | Delete
return 'Angular'
[192] Fix | Delete
if os.path.exists(f"""{docroot}/main.js"""):
[193] Fix | Delete
if os.path.exists(f"""{docroot}/index.php"""):
[194] Fix | Delete
try:
[195] Fix | Delete
with open(f"""{docroot}/index.php""", encoding='utf-8') as index:
[196] Fix | Delete
for line in index.readlines():
[197] Fix | Delete
if re.search('bootstrap', line, re.IGNORECASE):
[198] Fix | Delete
return 'Bootstrap'
[199] Fix | Delete
return 'Javascript'
[200] Fix | Delete
except Exception as e:
[201] Fix | Delete
print(e)
[202] Fix | Delete
else:
[203] Fix | Delete
return 'Javascript'
[204] Fix | Delete
if os.path.exists(f"""{docroot}/config.php"""):
[205] Fix | Delete
if os.path.exists(f"""{docroot}/admin/config.php"""):
[206] Fix | Delete
return 'OpenCart'
[207] Fix | Delete
else:
[208] Fix | Delete
try:
[209] Fix | Delete
with open(f"""{docroot}/config.php""", encoding='utf-8') as config:
[210] Fix | Delete
for line in config.readlines():
[211] Fix | Delete
if 'Moodle' in line:
[212] Fix | Delete
return 'Moodle'
[213] Fix | Delete
if os.path.exists(f"""{docroot}/cron.php"""):
[214] Fix | Delete
with open(f"""{docroot}/cron.php""", encoding='utf-8') as cron:
[215] Fix | Delete
for line in cron.readlines():
[216] Fix | Delete
if 'phpBB' in line:
[217] Fix | Delete
return 'phpBB'
[218] Fix | Delete
return 'Undetermined'
[219] Fix | Delete
else:
[220] Fix | Delete
return 'Undetermined'
[221] Fix | Delete
except Exception as e:
[222] Fix | Delete
print(e)
[223] Fix | Delete
[224] Fix | Delete
if os.path.exists(f"""{docroot}/index.html"""):
[225] Fix | Delete
return 'HTML'
[226] Fix | Delete
[227] Fix | Delete
return None
[228] Fix | Delete
[229] Fix | Delete
def double_check_wordpress(directory=None):
[230] Fix | Delete
if directory and os.path.exists(directory):
[231] Fix | Delete
if os.path.exists(f"""{directory}/wp-content/plugins/boldgrid-inspirations"""):
[232] Fix | Delete
return 'BoldGrid'
[233] Fix | Delete
return 'Wordpress'
[234] Fix | Delete
[235] Fix | Delete
def manual_find_docroot(domain=None, web_server_config=None, web_server=None):
[236] Fix | Delete
if web_server == 'apache':
[237] Fix | Delete
docroot_cmd = f"""grep 'ServerName {domain}' {web_server_config} -A3 | grep DocumentRoot | """ + r"""awk '{print $2}' | uniq"""
[238] Fix | Delete
domain_name = domain
[239] Fix | Delete
elif web_server == 'nginx':
[240] Fix | Delete
domain_name = domain.removesuffix('.conf')
[241] Fix | Delete
if r'*' in domain_name:
[242] Fix | Delete
return # Skip wildcard subdomain configs
[243] Fix | Delete
if domain_name.count('_') > 0:
[244] Fix | Delete
new_domain = ''
[245] Fix | Delete
if domain_name.split('_')[1] == '': # user__domain_tld.conf
[246] Fix | Delete
domain_name = domain_name.split('_')
[247] Fix | Delete
limit = len(domain_name) - 1
[248] Fix | Delete
start = 2
[249] Fix | Delete
while start <= limit:
[250] Fix | Delete
new_domain += domain_name[start]
[251] Fix | Delete
if start != limit:
[252] Fix | Delete
new_domain += '.'
[253] Fix | Delete
start += 1
[254] Fix | Delete
domain_name = new_domain
[255] Fix | Delete
else: # domain_tld.conf
[256] Fix | Delete
limit = len(domain_name) - 1
[257] Fix | Delete
start = 0
[258] Fix | Delete
while start <= limit:
[259] Fix | Delete
new_domain += domain_name[start]
[260] Fix | Delete
if start != limit:
[261] Fix | Delete
new_domain += '.'
[262] Fix | Delete
start += 1
[263] Fix | Delete
domain_name = new_domain
[264] Fix | Delete
nginx_config = f"""{web_server_config}/{domain}""" # This is the file name, above we extracted the actual domain for use later
[265] Fix | Delete
if os.path.exists(nginx_config):
[266] Fix | Delete
docroot_cmd = f"""grep root {nginx_config} | """ + r"""awk '{print $2}' | uniq | tr -d ';'"""
[267] Fix | Delete
else:
[268] Fix | Delete
docroot_cmd = None
[269] Fix | Delete
if docroot_cmd:
[270] Fix | Delete
docroot = run(docroot_cmd)
[271] Fix | Delete
else:
[272] Fix | Delete
print(f"""Cannot determine docroot for: {domain_name}""")
[273] Fix | Delete
return
[274] Fix | Delete
[275] Fix | Delete
return docroot
[276] Fix | Delete
[277] Fix | Delete
def cms_counter_no_cpanel(verbose=False, new=False, server=None, user_list=[]):
[278] Fix | Delete
"""
[279] Fix | Delete
Function to get counts of CMS from all servers without cPanel
[280] Fix | Delete
"""
[281] Fix | Delete
# Set Variables
[282] Fix | Delete
nginx = 0
[283] Fix | Delete
apache = 0
[284] Fix | Delete
web_server_config = None
[285] Fix | Delete
domains_cmd = None
[286] Fix | Delete
domains_list = None
[287] Fix | Delete
domains = {}
[288] Fix | Delete
docroot_list = []
[289] Fix | Delete
users = []
[290] Fix | Delete
# List of system users not to run counter against - parsed from /etc/passwd
[291] Fix | Delete
sys_users = [
[292] Fix | Delete
'root',
[293] Fix | Delete
'bin',
[294] Fix | Delete
'daemon',
[295] Fix | Delete
'adm',
[296] Fix | Delete
'sync',
[297] Fix | Delete
'shutdown',
[298] Fix | Delete
'halt',
[299] Fix | Delete
'mail',
[300] Fix | Delete
'games',
[301] Fix | Delete
'ftp',
[302] Fix | Delete
'nobody',
[303] Fix | Delete
'systemd-network',
[304] Fix | Delete
'dbus',
[305] Fix | Delete
'polkitd',
[306] Fix | Delete
'rpc',
[307] Fix | Delete
'tss',
[308] Fix | Delete
'ntp',
[309] Fix | Delete
'sshd',
[310] Fix | Delete
'chrony',
[311] Fix | Delete
'nscd',
[312] Fix | Delete
'named',
[313] Fix | Delete
'mailman',
[314] Fix | Delete
'cpanel',
[315] Fix | Delete
'cpanelcabcache',
[316] Fix | Delete
'cpanellogin',
[317] Fix | Delete
'cpaneleximfilter',
[318] Fix | Delete
'cpaneleximscanner',
[319] Fix | Delete
'cpanelroundcube',
[320] Fix | Delete
'cpanelconnecttrack',
[321] Fix | Delete
'cpanelanalytics',
[322] Fix | Delete
'cpses',
[323] Fix | Delete
'mysql',
[324] Fix | Delete
'dovecot',
[325] Fix | Delete
'dovenull',
[326] Fix | Delete
'mailnull',
[327] Fix | Delete
'cpanelphppgadmin',
[328] Fix | Delete
'cpanelphpmyadmin',
[329] Fix | Delete
'rpcuser',
[330] Fix | Delete
'nfsnobody',
[331] Fix | Delete
'_imunify',
[332] Fix | Delete
'wp-toolkit',
[333] Fix | Delete
'redis',
[334] Fix | Delete
'nginx',
[335] Fix | Delete
'telegraf',
[336] Fix | Delete
'sssd',
[337] Fix | Delete
'scops',
[338] Fix | Delete
'clamav',
[339] Fix | Delete
'tier1adv',
[340] Fix | Delete
'inmotion',
[341] Fix | Delete
'hubhost',
[342] Fix | Delete
'tier2s',
[343] Fix | Delete
'lldpd',
[344] Fix | Delete
'patchman',
[345] Fix | Delete
'moveuser',
[346] Fix | Delete
'postgres',
[347] Fix | Delete
'cpanelsolr',
[348] Fix | Delete
'saslauth',
[349] Fix | Delete
'nagios',
[350] Fix | Delete
'wazuh',
[351] Fix | Delete
'systemd-bus-proxy',
[352] Fix | Delete
]
[353] Fix | Delete
nginx_status = run("""systemctl status nginx &>/dev/null;echo $?""")
[354] Fix | Delete
apache_status = run("""systemctl status httpd &>/dev/null;echo $?""")
[355] Fix | Delete
# Determine Domain List
[356] Fix | Delete
if str(apache_status) == '0': # Even if NGiNX server generally Apache is still in use, and is much less convaluted than the NGiNX config
[357] Fix | Delete
apache = 1
[358] Fix | Delete
web_server = 'apache'
[359] Fix | Delete
web_server_config = identify_apache_config()
[360] Fix | Delete
if web_server_config:
[361] Fix | Delete
domains_cmd = f"""grep ServerName '{web_server_config}' | """ + r"""awk '{print $2}' | sort -g | uniq"""
[362] Fix | Delete
elif str(nginx_status) == '0': # If Apache is not in use and NGiNX is, use NGiNX
[363] Fix | Delete
nginx = 1
[364] Fix | Delete
web_server = 'nginx'
[365] Fix | Delete
web_server_config = identify_nginx_config()
[366] Fix | Delete
if web_server_config:
[367] Fix | Delete
# THIS MAY NEED REFINED - is this compatible with all NGiNX configs we're checking for? I think one doesn't end in .conf at least
[368] Fix | Delete
domains_cmd = f"""find '{web_server_config}' -type f -name '*.conf' -print | grep -Ev '\.ssl\.conf' | xargs -d '\n' -l basename"""
[369] Fix | Delete
if domains_cmd:
[370] Fix | Delete
domains_list = run(domains_cmd) # Get list of domains
[371] Fix | Delete
if domains_list:
[372] Fix | Delete
for domain_name in domains_list.split():
[373] Fix | Delete
docroot = manual_find_docroot(domain=domain_name,web_server_config=web_server_config,web_server=web_server)
[374] Fix | Delete
if docroot and os.path.exists(docroot):
[375] Fix | Delete
node_installs = []
[376] Fix | Delete
docroot_list.append(docroot)
[377] Fix | Delete
domains.update({f"""{docroot}""":f"""{domain_name}"""})
[378] Fix | Delete
try:
[379] Fix | Delete
node_installs += find_nodejs(docroot=docroot, domain=domain_name) # Try and find NodeJS installs and add them to list of user_installs
[380] Fix | Delete
except:
[381] Fix | Delete
pass
[382] Fix | Delete
# Check sub-directories
[383] Fix | Delete
bad_dirs = [
[384] Fix | Delete
f"""{docroot}/wp-admin""",
[385] Fix | Delete
f"""{docroot}/wp-includes""",
[386] Fix | Delete
f"""{docroot}/wp-content""",
[387] Fix | Delete
f"""{docroot}/wp-json""",
[388] Fix | Delete
f"""{docroot}/admin""",
[389] Fix | Delete
f"""{docroot}/cache""",
[390] Fix | Delete
f"""{docroot}/temp""",
[391] Fix | Delete
f"""{docroot}/tmp""",
[392] Fix | Delete
f"""{docroot}/__wildcard__""",
[393] Fix | Delete
f"""{docroot}/cgi-bin""",
[394] Fix | Delete
f"""{docroot}/.well-known""",
[395] Fix | Delete
f"""{docroot}/config""",
[396] Fix | Delete
f"""{docroot}/language""",
[397] Fix | Delete
f"""{docroot}/plugins""",
[398] Fix | Delete
f"""{docroot}/media""",
[399] Fix | Delete
f"""{docroot}/libraries""",
[400] Fix | Delete
f"""{docroot}/images""",
[401] Fix | Delete
f"""{docroot}/includes""",
[402] Fix | Delete
f"""{docroot}/include""",
[403] Fix | Delete
f"""{docroot}/modules""",
[404] Fix | Delete
f"""{docroot}/components""",
[405] Fix | Delete
f"""{docroot}/templates""",
[406] Fix | Delete
f"""{docroot}/cli""",
[407] Fix | Delete
f"""{docroot}/layouts""",
[408] Fix | Delete
f"""{docroot}/storage""",
[409] Fix | Delete
f"""{docroot}/logs""",
[410] Fix | Delete
f"""{docroot}/bin""",
[411] Fix | Delete
f"""{docroot}/uploads""",
[412] Fix | Delete
f"""{docroot}/docs""",
[413] Fix | Delete
f"""{docroot}/style""",
[414] Fix | Delete
f"""{docroot}/files""",
[415] Fix | Delete
f"""{docroot}/sounds""",
[416] Fix | Delete
f"""{docroot}/cart""",
[417] Fix | Delete
f"""{docroot}/shop""",
[418] Fix | Delete
f"""{docroot}/assets""",
[419] Fix | Delete
f"""{docroot}/system""",
[420] Fix | Delete
f"""{docroot}/documentation""",
[421] Fix | Delete
f"""{docroot}/application""",
[422] Fix | Delete
f"""{docroot}/script""",
[423] Fix | Delete
f"""{docroot}/scripts""",
[424] Fix | Delete
f"""{docroot}/backups""",
[425] Fix | Delete
f"""{docroot}/backup""",
[426] Fix | Delete
]
[427] Fix | Delete
docroot_dir = Path(docroot)
[428] Fix | Delete
try:
[429] Fix | Delete
for d in docroot_dir.iterdir():
[430] Fix | Delete
if os.path.exists(d) and d.is_dir() and str(d) not in bad_dirs:
[431] Fix | Delete
try:
[432] Fix | Delete
node_installs += find_nodejs(docroot=str(d), domain=domain_name)
[433] Fix | Delete
except:
[434] Fix | Delete
continue
[435] Fix | Delete
dirname = str(os.path.basename(d))
[436] Fix | Delete
d = str(d) # Convert from Path object to String
[437] Fix | Delete
docroot_list.append(d)
[438] Fix | Delete
domains.update({f"""{d}""":f"""{domain_name}/{dirname}"""})
[439] Fix | Delete
bad_dirs.append(d)
[440] Fix | Delete
except NotADirectoryError:
[441] Fix | Delete
continue
[442] Fix | Delete
except Exception as e:
[443] Fix | Delete
print(e)
[444] Fix | Delete
continue
[445] Fix | Delete
[446] Fix | Delete
[447] Fix | Delete
cms_count = {} # Dictionary to hold CMS totals - not requested but will output for good measure anyways
[448] Fix | Delete
# Determine User List
[449] Fix | Delete
if len(user_list) >= 1:
[450] Fix | Delete
users = user_list
[451] Fix | Delete
if os.path.exists('/home') and len(user_list) == 0: # Get users if they weren't passed already - if cPanel was detected but not Softaculous for instance
[452] Fix | Delete
users_dir = Path('/home')
[453] Fix | Delete
try:
[454] Fix | Delete
with open('/etc/passwd', encoding='utf-8') as passwd:
[455] Fix | Delete
passwd_file = passwd.readlines()
[456] Fix | Delete
except:
[457] Fix | Delete
sys.exit('Unable to read /etc/passwd!\nExiting...')
[458] Fix | Delete
for u in users_dir.iterdir():
[459] Fix | Delete
if u.is_dir():
[460] Fix | Delete
limit = len(u.parts) - 1
[461] Fix | Delete
for line in passwd_file:
[462] Fix | Delete
if u.parts[limit] == line.split(':')[0] and u.parts[limit] not in sys_users:
[463] Fix | Delete
users.append(u.parts[limit])
[464] Fix | Delete
if len(users) >= 1 and len(docroot_list) >= 1:
[465] Fix | Delete
for docroot in docroot_list:
[466] Fix | Delete
get_cms = None
[467] Fix | Delete
docroot_user = None
[468] Fix | Delete
for user in users:
[469] Fix | Delete
if user in sys_users:
[470] Fix | Delete
continue # Go to next user if current user is System user
[471] Fix | Delete
if user in docroot.split('/'):
[472] Fix | Delete
docroot_user = user
[473] Fix | Delete
break
[474] Fix | Delete
get_cms = determine_cms(docroot=docroot)
[475] Fix | Delete
[476] Fix | Delete
if verbose:
[477] Fix | Delete
pt = determine_panel_type() # Determine Panel Type if needed
[478] Fix | Delete
if get_cms and docroot_user and docroot_user not in sys_users:
[479] Fix | Delete
domain = domains.get(f"""{docroot}""", None)
[480] Fix | Delete
if verbose:
[481] Fix | Delete
print(f"""{server} {pt} {docroot_user} {domain} {get_cms}""")
[482] Fix | Delete
else:
[483] Fix | Delete
print(f"""{docroot_user} {domain} {get_cms}""")
[484] Fix | Delete
for install in node_installs:
[485] Fix | Delete
if verbose:
[486] Fix | Delete
print(f"""{server} {pt} {docroot_user} {install} NodeJS""")
[487] Fix | Delete
else:
[488] Fix | Delete
print(f"""{docroot_user} {install} NodeJS""")
[489] Fix | Delete
[490] Fix | Delete
return
[491] Fix | Delete
[492] Fix | Delete
def cms_counter_cpanel(verbose=False, new=False, server=None):
[493] Fix | Delete
"""
[494] Fix | Delete
Function to determine CMS counter on servers with cPanel
[495] Fix | Delete
Attempting to use Softaculous first
[496] Fix | Delete
Checking manually if that returns no results
[497] Fix | Delete
Including users list as passed variable so we can run against specific users only as well, future-proofing/anticipating possible request
[498] Fix | Delete
"""
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function