/
opt
/
dedrads
/
/opt/dedrads
mkdir
upload
Name
Size
Mode
Actions
account_review/
-
0555
rm
check_software_mods/
-
0555
rm
cms_tools/
-
0555
rm
etc/
-
0555
rm
extras/
-
0555
rm
mailparse/
-
0555
rm
mysql/
-
0555
rm
nlp_scripts/
-
0555
rm
oldrads/
-
0555
rm
perl/
-
0555
rm
provision/
-
0555
rm
python/
-
0555
rm
suspended/
-
0555
rm
__pycache__/
-
0555
rm
account-review
799
0555
edit
dl
rm
allfw
6259
0555
edit
dl
rm
alp.py
16553
0555
edit
dl
rm
autossl_sync
6267
0555
edit
dl
rm
check_apache
9205
0555
edit
dl
rm
check_bandwidth
4546
0555
edit
dl
rm
check_boxtrapper
1684
0555
edit
dl
rm
check_cpu
12212
0555
edit
dl
rm
check_crons
1827
0555
edit
dl
rm
check_dcpumon
1973
0555
edit
dl
rm
check_dns
1827
0555
edit
dl
rm
check_domlogs
61
0555
edit
dl
rm
check_exim
3731
0555
edit
dl
rm
check_hacks
22604
0555
edit
dl
rm
check_imap
5249
0555
edit
dl
rm
check_io
6635
0555
edit
dl
rm
check_max_children
16341
0555
edit
dl
rm
check_mem
1660
0555
edit
dl
rm
check_misc
1510
0555
edit
dl
rm
check_pacct
5201
0555
edit
dl
rm
check_php
4344
0555
edit
dl
rm
check_pop3
2295
0555
edit
dl
rm
check_prov.py
4714
0555
edit
dl
rm
check_server
696
0555
edit
dl
rm
check_size
490
0555
edit
dl
rm
check_software
9849
0555
edit
dl
rm
check_spamd
2426
0555
edit
dl
rm
check_traffic
1933
0555
edit
dl
rm
check_user
1887
0555
edit
dl
rm
clean_exim.py
6390
0555
edit
dl
rm
clusterfix
5343
0555
edit
dl
rm
cmspass.py
3970
0555
edit
dl
rm
cms_check.py
9825
0555
edit
dl
rm
cms_counter.py
36734
0555
edit
dl
rm
cms_creds
713
0555
edit
dl
rm
cms_dumpdb
4485
0555
edit
dl
rm
cms_pw
1416
0555
edit
dl
rm
cpanel-api
7040
0555
edit
dl
rm
cpanel_postgres_manager.py
29004
0555
edit
dl
rm
cpmerge
4631
0555
edit
dl
rm
cpumon
2195
0555
edit
dl
rm
dcpumon.pl
1239
0555
edit
dl
rm
dedcheck
18127
0555
edit
dl
rm
dns-sync
14386
0555
edit
dl
rm
docroot.py
4425
0555
edit
dl
rm
du-tree
7450
0555
edit
dl
rm
envinfo.py
6633
0555
edit
dl
rm
exclude_rbl.py
5249
0555
edit
dl
rm
extract-vhost
2691
0555
edit
dl
rm
filescan
3566
0555
edit
dl
rm
find_warez
1460
0555
edit
dl
rm
first_setup.py
19120
0555
edit
dl
rm
fixwpcron.py
4822
0555
edit
dl
rm
fix_dns_cluster
353
0555
edit
dl
rm
goaccess
1217720
0555
edit
dl
rm
hostsfilemods
4467
0555
edit
dl
rm
imap_io
2323
0555
edit
dl
rm
innodb_converter.py
9343
0555
edit
dl
rm
killall911
530
0555
edit
dl
rm
killdns
941
0555
edit
dl
rm
lastcommcache.sh
1374
0555
edit
dl
rm
legal_lock_down.sh
7450
0555
edit
dl
rm
lil-cpanel
52002
0555
edit
dl
rm
listacct
4575
0555
edit
dl
rm
mailscan
4544
0555
edit
dl
rm
mail_sources.py
7407
0555
edit
dl
rm
megaclisas-status
38664
0555
edit
dl
rm
migrate2central.sh
14418
0555
edit
dl
rm
modify-account
40631
0555
edit
dl
rm
modsec_disable.py
11461
0555
edit
dl
rm
monarxctl
8912
0555
edit
dl
rm
msp.pl
27714
0555
edit
dl
rm
mysql_dstat
474
0555
edit
dl
rm
mysql_selector.py
73102
0555
edit
dl
rm
nlp
4582
0555
edit
dl
rm
procscrape
1863
0555
edit
dl
rm
quarantine
11083
0555
edit
dl
rm
radsfunctions.sh
863
0555
edit
dl
rm
recent-cp
16148
0555
edit
dl
rm
remote_dump
18347
0555
edit
dl
rm
reset_cpanel
3205
0555
edit
dl
rm
server-load
2192
0555
edit
dl
rm
show-conns
20105
0555
edit
dl
rm
show-conns-adv.py
54667
0555
edit
dl
rm
sparta.py
382498
0555
edit
dl
rm
sqltop
27129
0555
edit
dl
rm
telcheck
2411
0555
edit
dl
rm
temprootreset
186
0555
edit
dl
rm
unsuspend_user
1307
0555
edit
dl
rm
unsusprunner.sh
1840
0555
edit
dl
rm
updatednsadmin
526
0555
edit
dl
rm
update_spf
14972
0555
edit
dl
rm
upgrade-check
9216
0555
edit
dl
rm
vhost_data.py
6221
0555
edit
dl
rm
wp-xray.sh
85816
0555
edit
dl
rm
Edit:
/opt/dedrads/check_apache
(9205B)
#!/usr/lib/rads/venv/bin/python3 # vim: set ts=4 sw=4 expandtab syntax=python: """RADS tool to parse and display the output of the Apache server status page""" import sys import re import os import argparse import requests from requests import ConnectionError as ConnError, HTTPError from netaddr import IPAddress, IPNetwork, AddrFormatError def parse_page(itext): """parse HTML from status page and return a list of connections""" # strip out all HTML tags; use <td> as vertical-bar delimiter, # <tr> as newlines itext = ( re.sub(r'<td[^>]*>', '|', itext).replace('\n', '').replace('<tr>', '\n') ) itext = re.sub(r'<\/?[^>]+>', '', itext).replace('&', '&') outbuf = [] for tline in itext.splitlines(): if tline[0] != '|': continue tline = tline[1:] # srv, pid, acc, m, cpu, ss, req, (dur), conn, child, slot, client, # (proto), vhost, method uri proto # proto and dur sections are not present on some machines, so we get # 13 - 15 columns line = tline.strip().split('|') if len(line) < 13: continue if len(line) == 14: del line[11] elif len(line) > 14: del line[7] del line[11] htmatch = re.match(r'^([^ ]+) ?(.*) (HTTP.*)$', line[12], re.I) if htmatch: hmeth, huri, htype = htmatch.groups() else: hmeth, huri, htype = ('', '', '') outbuf.append( { 'srv': line[0], 'pid': line[1], 'acc': line[2], 'm': line[3], 'cpu': line[4], 'ss': line[5], 'req': line[6], 'conn': line[7], 'child': line[8], 'slot': line[9], 'client': line[10], 'vhost': line[11], 'uri': huri, 'htype': htype, 'method': hmeth, } ) return outbuf def get_status_page(url="http://localhost/whm-server-status-imh"): """retrieve server status page from @url""" try: resp = requests.get(url, timeout=10.0) resp.raise_for_status() except ConnError as e: print(f"!! Failed to retrieve status page ({url}): {e}") sys.exit(100) except HTTPError as e: print("!! Received error from server: %s" % (e)) sys.exit(101) return resp.text def parse_status(intext, full=False): """parse and format status from HTML""" # pick scoreboard header if full is True: gtext = intext else: gtext = re.search(r'<body>(.+)<(/p|p /)>', intext, re.S).group(1) # strip out HTML tags otext = re.sub(r'<td[^>]*>', ' ', gtext) otext = re.sub(r'<\/?[^>]+>', '', otext) return otext def enum_domains(indata, ipmask=None): """produce a dict of connections per domain""" # create mask if ipmask is not None: try: netmask = IPNetwork(ipmask) except AddrFormatError as e: print("ERROR: Failed to parse netmask: " + str(e)) netmask = IPNetwork('0.0.0.0/0') else: netmask = IPNetwork('0.0.0.0/0') odata = {} for tline in indata: # parse vhost & port if tline['vhost'].find(':') > 0: vhost, vport = tline['vhost'].split(':', 1) vhost = vhost.lower() else: vhost = tline['vhost'].lower() vport = '80' # parse client IP try: tclient = IPAddress(tline['client']) except AddrFormatError: continue # match against netmask if tclient not in netmask: continue # build entry if vhost in odata: odata[vhost]['count'] += 1 if tclient in odata[vhost]['ips']: odata[vhost]['ips'][tclient] += 1 else: odata[vhost]['ips'][tclient] = 1 else: odata[vhost] = { 'count': 1, 'domain': vhost, 'port': vport, 'ips': {tclient: 1}, } return odata def enum_ips(indata, ipmask=None): """produce a dict of connections per IP""" # create mask if ipmask is not None: try: netmask = IPNetwork(ipmask) except AddrFormatError as e: print("ERROR: Failed to parse netmask: " + str(e)) netmask = IPNetwork('0.0.0.0/0') else: netmask = IPNetwork('0.0.0.0/0') odata = {} for tline in indata: # parse vhost & port if tline['vhost'].find(':') > 0: vhost, vport = tline['vhost'].split(':', 1) vhost = vhost.lower() else: vhost = tline['vhost'].lower() vport = '80' # parse client IP try: tclient = IPAddress(tline['client']) except AddrFormatError: continue # match against netmask if tclient not in netmask: continue # build entry if tclient in odata: odata[tclient]['count'] += 1 odata[tclient]['ip'] = tclient if vhost in odata[tclient]['domains']: odata[tclient]['domains'][vhost] += 1 else: odata[tclient]['domains'][vhost] = 1 else: odata[tclient] = { 'count': 1, 'client': tclient, 'port': vport, 'domains': {vhost: 1}, } return odata def format_output(indata, sortby='count', nototal=False): """perform final processing, then output data""" # sort sortlist = sorted(indata, key=lambda x: indata[x][sortby]) # display tcount = 0 for tkey in sortlist: tval = indata[tkey] if tkey == 'key': continue tcount += tval['count'] print("{:6} {}".format(tval['count'], tkey)) if nototal is False: print(f"{tcount:6} TOTAL") def parse_args(): """parse CLI args; .mode will contain the operation mode, .ip is an optional IP or CIDR range""" aparser = argparse.ArgumentParser( description="Parse the output of the Apache status page and " "process the results" ) aparser.set_defaults(mode=None, ip=None, nototal=False) aparser.add_argument( '--status', action='store_const', dest='mode', const='status', help="Show Apache scoreboard", ) aparser.add_argument( '--statusfull', action='store_const', dest='mode', const='statusfull', help="Show full Apache status output", ) aparser.add_argument( '--countdomain', action='store_const', dest='mode', const='countdomain', help="Count number of connections per domain/VHost", ) aparser.add_argument( '--sortdomain', action='store_const', dest='mode', const='sortdomain', help="Sort domains/VHosts by number of connections", ) aparser.add_argument( '--countip', action='store_const', dest='mode', const='countip', help="Count number of connections by IP", ) aparser.add_argument( '--sortip', action='store_const', dest='mode', const='sortip', help="Sort IPs by number of connections", ) aparser.add_argument( '--ipmask', dest='ip', metavar="IP/CIDR", help="Filter by a specific IP address or CIDR range", ) aparser.add_argument( '--nototal', dest='nototal', action='store_true', default=False, help="Suppress total output", ) args = aparser.parse_args(sys.argv[1:]) if args.mode is None: aparser.print_help() sys.exit(250) else: return args def _main(): """entry point""" args = parse_args() if not 'sharedrads' in os.path.realpath(__file__): url = 'http://localhost/whm-server-status' else: url = 'http://localhost/whm-server-status-imh' spage = get_status_page(url) sdata = parse_page(spage) sortby = None fdata = {} if args.mode.startswith('status'): if args.mode == 'statusfull': sbtext = parse_status(spage, full=True) else: sbtext = parse_status(spage) print(sbtext) elif args.mode == 'countdomain': fdata = enum_domains(sdata, ipmask=args.ip) sortby = 'count' elif args.mode == 'sortdomain': fdata = enum_domains(sdata, ipmask=args.ip) sortby = 'domain' elif args.mode == 'countip': fdata = enum_ips(sdata, ipmask=args.ip) sortby = 'count' elif args.mode == 'sortip': fdata = enum_ips(sdata, ipmask=args.ip) sortby = 'client' else: print("!! No valid action selected.") sys.exit(251) # display sorted output if sortby is not None: format_output(fdata, sortby, nototal=args.nototal) if __name__ == '__main__': _main()
Save
cmd:
run