/
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/autossl_sync
(6267B)
#!/usr/lib/rads/venv/bin/python3 """ AutoSSL Sync Created by Jeff Sh. Copy the SSLs files for a given domain to the provided folder so that it can be used by 3rd party applications and update as AutoSSL updates them. TODO: Only run if the ssl is newer than the current one, or otherwise invalid TODO: Check if self-signed, and prevent replacing DCV with self-signed """ # Imports import sys import os import argparse import errno import logging import logging.handlers import cpapis class MyVars: """ Main/Global variables can be defined here. """ VERSION = "1.0.1" LOG_FILENAME = '/var/log/autossl_sync.log' # Make sure the backup directory exists. If not, abort. def check_dir(dir_path, logger): """ Check to make sure the backup directory exists. If not, create it. Abort if there's a file that exists, but it's not a directory. """ if not os.path.isfile(dir_path): if not os.path.exists(dir_path): try: os.makedirs(dir_path) except OSError as error: if error.errno != errno.EEXIST: logger.error( f"Failed to create directory {dir_path}: {error}" ) else: logger.error( f"A failure occured while trying to create the \ directory {dir_path}." ) logger.error(f"Reported error: {error}") sys.exit(1) else: if not os.path.isdir(dir_path): logger.error( f"{dir_path} already exists, but it's not a directory." ) logger.error("ABORTING.") sys.exit(1) def copy_ssls(domain, folder, pem, logger): """ Given a domain name, we need to get the data to a point that we can use it. The Python JSON module imports the data as a dict, then it's a list, which then puts it into a dict again. So, we have to drill down to get to what we need. """ try: ssl_data = cpapis.whmapi1( "fetch_ssl_certificates_for_fqdns", {"domains": f"{domain}"} ) except IndexError as error: logger.error(f"Unable to load domain data for {domain} from whmapi1.") logger.error("Is the domain a valid domain on this server?") logger.error(f"Reported error was: {error}") sys.exit(1) # ssl_data keys are all located at data -> payload -> index 0 and then: # crt = Certificate # key = Private Key # cab = CA Bundle check_dir(folder, logger) with open(f"{folder}/{domain}.crt", "w", encoding='utf-8') as crt_file: crt_file.write(ssl_data['data']['payload'][0]['crt']) with open(f"{folder}/{domain}.key", "w", encoding='utf-8') as key_file: key_file.write(ssl_data['data']['payload'][0]['key']) with open(f"{folder}/{domain}.cab", "w", encoding='utf-8') as cab_file: cab_file.write(ssl_data['data']['payload'][0]['cab']) logger.info("Files written to the following paths:") logger.info(f"Certificate: {folder}/{domain}.crt") logger.info(f"Private Key: {folder}/{domain}.key") logger.info(f"CA Bundle : {folder}/{domain}.cab") if pem: convert_pem(domain, folder, logger) def convert_pem(domain, folder, logger): """ The PEM file is the CRT, KEY and CA Bundle in one file. Nothing more since the files in WHM are already X.509 formatted. """ cmd = f"cat {folder}/{domain}.crt > {folder}/{domain}.pem &&" cmd = f"cat {folder}/{domain}.key >> {folder}/{domain}.pem &&" cmd = f"cat {folder}/{domain}.cab >> {folder}/{domain}.pem " os.system(cmd) logger.info("PEM file format written to the following location:") logger.info(f"Privacy-Enhanced Mail (PEM): {folder}/{domain}.pem") def main(): """ We need to require the domain and the path to save the files to. No need to allow file names, we'll just use <tld_name>.crt, <tld_name>.key and <tld_name>.cab Set up parsing for the CLI arguments that can be passed and help text. """ # Optional Arguments parser = argparse.ArgumentParser( description=f"AutoSSL Sync v{MyVars.VERSION}" ) parser.add_argument( "--cron", action="store_true", dest="cron", default=False, help="Suppress all output, excluding errors, for CRON.", ) parser.add_argument( "-P", "--pem", action="store_true", dest="pem", default=False, help="Convert the files to PEM format after creation.", ) # Required Arguments required_arg = parser.add_argument_group('**REQUIRED arguments') required_arg.add_argument( "-d", "--domain", action='store', dest='domain', required=True, help="The FQDN domain to obtain SSL information on \ and sync. Subdomains can be used.", ) required_arg.add_argument( "-f", "--folder", action='store', dest='folder', required=True, help="The full path to the folder where the AutoSSL \ files should be copied to. Do not include a trailing slash!", ) # If no argument is passed, display help and exit. if len(sys.argv) == 1: parser.print_help(sys.stderr) print(__doc__) sys.exit(1) args = parser.parse_args() # Setup Logging - Rotate logs when 10MB, keep 6 copies and the current one. logging.basicConfig( level=logging.INFO, format="[%(asctime)s] - %(levelname)s - %(message)s", handlers=[ logging.handlers.RotatingFileHandler( MyVars.LOG_FILENAME, "a", 10485760, 6 ) ], ) logger = logging.getLogger(f'AutoSSL Sync v{MyVars.VERSION}') # Don't print to stdout when running with CRON argument, still send to log. cron_handler = logging.StreamHandler(sys.stdout) if not args.cron: logger.addHandler(cron_handler) else: logger.info("Running CRON Process for AutoSSL Sync v%s", MyVars.VERSION) copy_ssls(args.domain, args.folder, args.pem, logger) sys.exit(0) if __name__ == '__main__': main()
Save
cmd:
run