/opt/dedrads
NameSizeModeActions
account_review/-0555rm
check_software_mods/-0555rm
cms_tools/-0555rm
etc/-0555rm
extras/-0555rm
mailparse/-0555rm
mysql/-0555rm
nlp_scripts/-0555rm
oldrads/-0555rm
perl/-0555rm
provision/-0555rm
python/-0555rm
suspended/-0555rm
__pycache__/-0555rm
account-review7990555editdlrm
allfw62590555editdlrm
alp.py165530555editdlrm
autossl_sync62670555editdlrm
check_apache92050555editdlrm
check_bandwidth45460555editdlrm
check_boxtrapper16840555editdlrm
check_cpu122120555editdlrm
check_crons18270555editdlrm
check_dcpumon19730555editdlrm
check_dns18270555editdlrm
check_domlogs610555editdlrm
check_exim37310555editdlrm
check_hacks226040555editdlrm
check_imap52490555editdlrm
check_io66350555editdlrm
check_max_children163410555editdlrm
check_mem16600555editdlrm
check_misc15100555editdlrm
check_pacct52010555editdlrm
check_php43440555editdlrm
check_pop322950555editdlrm
check_prov.py47140555editdlrm
check_server6960555editdlrm
check_size4900555editdlrm
check_software98490555editdlrm
check_spamd24260555editdlrm
check_traffic19330555editdlrm
check_user18870555editdlrm
clean_exim.py63900555editdlrm
clusterfix53430555editdlrm
cmspass.py39700555editdlrm
cms_check.py98250555editdlrm
cms_counter.py367340555editdlrm
cms_creds7130555editdlrm
cms_dumpdb44850555editdlrm
cms_pw14160555editdlrm
cpanel-api70400555editdlrm
cpanel_postgres_manager.py290040555editdlrm
cpmerge46310555editdlrm
cpumon21950555editdlrm
dcpumon.pl12390555editdlrm
dedcheck181270555editdlrm
dns-sync143860555editdlrm
docroot.py44250555editdlrm
du-tree74500555editdlrm
envinfo.py66330555editdlrm
exclude_rbl.py52490555editdlrm
extract-vhost26910555editdlrm
filescan35660555editdlrm
find_warez14600555editdlrm
first_setup.py191200555editdlrm
fixwpcron.py48220555editdlrm
fix_dns_cluster3530555editdlrm
goaccess12177200555editdlrm
hostsfilemods44670555editdlrm
imap_io23230555editdlrm
innodb_converter.py93430555editdlrm
killall9115300555editdlrm
killdns9410555editdlrm
lastcommcache.sh13740555editdlrm
legal_lock_down.sh74500555editdlrm
lil-cpanel520020555editdlrm
listacct45750555editdlrm
mailscan45440555editdlrm
mail_sources.py74070555editdlrm
megaclisas-status386640555editdlrm
migrate2central.sh144180555editdlrm
modify-account406310555editdlrm
modsec_disable.py114610555editdlrm
monarxctl89120555editdlrm
msp.pl277140555editdlrm
mysql_dstat4740555editdlrm
mysql_selector.py731020555editdlrm
nlp45820555editdlrm
procscrape18630555editdlrm
quarantine110830555editdlrm
radsfunctions.sh8630555editdlrm
recent-cp161480555editdlrm
remote_dump183470555editdlrm
reset_cpanel32050555editdlrm
server-load21920555editdlrm
show-conns201050555editdlrm
show-conns-adv.py546670555editdlrm
sparta.py3824980555editdlrm
sqltop271290555editdlrm
telcheck24110555editdlrm
temprootreset1860555editdlrm
unsuspend_user13070555editdlrm
unsusprunner.sh18400555editdlrm
updatednsadmin5260555editdlrm
update_spf149720555editdlrm
upgrade-check92160555editdlrm
vhost_data.py62210555editdlrm
wp-xray.sh858160555editdlrm
Edit: /opt/dedrads/monarxctl (8912B)
#!/usr/lib/rads/venv/bin/python3 from pathlib import Path from platform import node, freedesktop_os_release from shutil import rmtree from urllib.request import urlretrieve import argparse import subprocess import sys import os import rads hostname = node() monarx_repo = """[monarx] name=Monarx Agent baseurl=https://repository.monarx.com/repository/monarx-yum/linux/yum/el/{}/$basearch gpgkey= gpgcheck=0 """ monarx_apt_repo = """deb [arch=amd64] https://repository.monarx.com/repository/ubuntu-{0}/ {0} main""" apt_signing_key = """https://repository.monarx.com/repository/monarx/publickey/monarxpub.gpg""" packages = [ "monarx-agent", "monarx-protect", "monarx-cpanel-plugin", "monarx-whm-plugin", "monarx-cwp-plugin", ] parser = argparse.ArgumentParser(description='Install or remove monarx') parser.add_argument( 'function', nargs=1, default=None, help='function', choices=['install', 'remove'], ) parser.add_argument('veid', type=int, nargs="?", default=None, help='VPS ID') parser.add_argument( '--client_id', type=str, default='', help='Monarx client_id' ) parser.add_argument( '--client_secret', type=str, default='', help='Monarx client_secret' ) args = parser.parse_args() if args.function is None: print("Please specify if you wish to install or remove monarx") sys.exit() if args.veid is not None and not rads.vz.is_vz(): print("You provided a VPS ID but this isnt a VZ node") sys.exit() if args.function == ['install'] and ( args.client_id == '' or args.client_secret == '' ): print( "Please provide client_id and client_secret from BitWarden for installation" ) sys.exit() monarx_conf = f"""client_id = {args.client_id} client_secret = {args.client_secret} user_base = /home/ tags = upsell host_id = {hostname}""" if rads.vz.is_vz(): if args.veid is None: print("CTID is required (ex: monarxctl install $CTID)") else: ctid = str(args.veid) envid = rads.vz.get_envid(ctid) if not rads.vz.is_ct_running(ctid): print("container not found") sys.exit() grep = ["grep", "--color=never", "-o", "[0-9]", "/etc/redhat-release"] yum_cmd = ["yum", "-y", "-q"] apt_cmd = ["apt-get", "-y"] is_ubuntu = False os_ver = "" def check_install(veid): if is_ubuntu: distro_cmd = ["dpkg-query", "-W", "--showformat='${Status}'"] else: distro_cmd = ["rpm", "-q"] if veid is not None: pkg_cmd = vz_exec + distro_cmd + packages else: pkg_cmd = distro_cmd + packages try: pkg_out = subprocess.run( pkg_cmd, capture_output=True, check=True, text=True ) if is_ubuntu and pkg_out: return True if "not installed" in pkg_out.stdout: return False return True except subprocess.CalledProcessError as e: if e.returncode in (1, 2): print(e.stderr) else: print(f"install check error: {e.cmd} returned {e.returncode}") return None if args.veid: vz_exec = ["/usr/sbin/vzctl", "exec2", ctid] grep = vz_exec + grep yum_cmd = vz_exec + yum_cmd apt_cmd = vz_exec + apt_cmd path_prefix = '/vz/root/' + envid else: ctid = None path_prefix = "" try: print("Checking OS version..") if freedesktop_os_release().get('ID', '') == 'ubuntu': if ctid is not None: lsb_cmd = vz_exec + ["/usr/bin/lsb_release", "-sc"] else: lsb_cmd = ["/usr/bin/lsb_release", "-sc"] is_ubuntu = True check_cmd = "dpkg -l" # ensure apt/apt-get doesnt ask questions os.environ["DEBIAN_FRONTEND"] = "noninteractive" os_ver = subprocess.check_output( lsb_cmd, text=True, stderr=subprocess.DEVNULL ) else: check_cmd = "rpm -q" os_ver = subprocess.check_output( grep, text=True, stderr=subprocess.DEVNULL ) os_ver = int(os_ver.split('\n', maxsplit=1)[0]) print(f"Detected OS version: {os_ver}") except subprocess.CalledProcessError as e: print(e.cmd, e.stderr) if is_ubuntu: # these dont exist on ubuntu packages.remove("monarx-cwp-plugin") repo = Path(f'{path_prefix}/etc/apt/sources.list.d/monarx.list') apt_key_path = Path(f'{path_prefix}/etc/apt/trusted.gpg.d/monarx.asc') os_ver.strip('\n') repotext = monarx_apt_repo.format(os_ver.strip()) else: # dont install cpanel stuff if theres no cpanel if not os.path.exists("/usr/local/cpanel/cpanel"): packages.remove("monarx-whm-plugin") packages.remove("monarx-cpanel-plugin") # dont install cwp stuff if theres no cdwp if not os.path.exists("/usr/local/cwpsrv/bin/cwpsrv"): packages.remove("monarx-cwp-plugin") apt_key_path = None repo = Path(f'{path_prefix}/etc/yum.repos.d/monarx.repo') repotext = monarx_repo.format(os_ver) conf = Path(f'{path_prefix}/etc/monarx-agent.conf') print("repo file:", repo) print("conf file:", conf) if "install" in args.function: if check_install(ctid): print("Monarx packages appear to already be installed") sys.exit() # attempts to download key if its missing if is_ubuntu and not os.path.exists(apt_key_path): print("Fetching signing key...") try: urlretrieve(apt_signing_key, apt_key_path) except Exception as e: print(f"error downloading signing key: {e}") print( """you can download manually with: wget -qO - https://repository.monarx.com/repository/monarx/publickey/monarxpub.gpg | sudo tee /etc/apt/trusted.gpg.d/monarx.asc""" ) sys.exit() print("Beginning monarx install...") repo.write_text(repotext, encoding='ascii') conf.write_text(monarx_conf, encoding='ascii') try: if is_ubuntu: print("Updating package list with apt update...") if ctid is not None: update_cmd = vz_exec + [ "DEBIAN_FRONTEND=noninteractive", "apt-get", "-qq", "update", ] else: update_cmd = ["apt-get", "-qq", "update"] try: subprocess.run(update_cmd, check=True) except subprocess.CalledProcessError as e: print(f"apt update failed: {e}") print("Please resolve any apt source issues and try again") sys.exit() apt_cmd.append("install") apt_inst = subprocess.check_output( apt_cmd + packages, stderr=subprocess.DEVNULL ) else: yum_cmd.append("install") yum_inst = subprocess.check_output( yum_cmd + packages, stderr=subprocess.DEVNULL ) except subprocess.CalledProcessError as e: print(f"install process error: {e.cmd}") if check_install(ctid): print("Monarx install complete.") else: print( f"""There may have been an issue with the installation process!! Please verify with: {check_cmd} {' '.join(packages)}""" ) if "remove" in args.function: if not check_install(ctid): print("Monarx packages not found - are you sure it's installed?") sys.exit() cleanup_files = [repo, conf] # removal will throw errors and leave this behind if the contents changed # the contents have obviously changed, it's a cache dir. print("Removing monarx-agent cache dir...") cache_path = Path(f'{path_prefix}/var/cache/monarx-agent/') if os.path.exists(cache_path): try: rmtree(cache_path) except PermissionError: print(f"permission error: unable to remove {cache_path}") except OSError as e: print(f"removal of {cache_path} failed: {e}") print("Removing monarx packages...") try: if is_ubuntu: apt_cmd.append("purge") apt_purge = subprocess.run(apt_cmd + packages, check=True) cleanup_files.append(apt_key_path) else: yum_cmd.append("remove") yum_inst = subprocess.run(yum_cmd + packages, check=True) except subprocess.CalledProcessError as e: print(f"package removal process error: {e.cmd}") print("Removing monarx repo and conf...") for file in cleanup_files: try: os.remove(file) except FileNotFoundError: pass except OSError as e: print(f"conf/repo removal error: {e.filename} - {e.strerror}.") if not check_install(ctid): print("Monarx removal complete.") else: print( """There may have been an issue with the removal process!!\n""" f"""Please verify with: {check_cmd} {' '.join(packages)}""" )