46 lines
1.2 KiB
Python
Raw Normal View History

2018-11-30 09:14:29 +01:00
#!/usr/bin/env python3
import sys, os, platform, subprocess, re, argparse
re_domain = r'^(?=.{1,253}$)(?!.*\.\..*)(?!\..*)([a-zA-Z0-9-]{,63}\.){,127}[a-zA-Z0-9-]{1,63}$'
def sanity_check_system():
# check apache2
if subprocess.call("apache2 -v", shell=True):
sys.exit("Apache2 not installed on your system. Aborting...")
def cert_add(domains):
dms = []
for d in domains:
if re.match(re_domain, d) is None:
print("Invalid domain name: " + d + " -> pass")
continue
dms.append(d)
2018-12-06 11:00:18 +01:00
certbot_args = ['sudo', 'certbot', '--apache', 'certonly', '-d']
2018-11-30 09:14:29 +01:00
certbot_args.extend(dms)
subprocess.call(certbot_args)
def cert_remove(domain):
pass
if __name__ == "__main__":
2018-12-06 10:56:04 +01:00
p = argparse.ArgumentParser(description='cerbot helper')
p.add_argument('domain', metavar="domain", help="vhost domain(s)", nargs="+")
g = p.add_mutually_exclusive_group()
g.add_argument('-a', '--add', action='store_true', help="adds cert for given domain(s)")
g.add_argument('-r', '--remove', action='store_true', help="removes cert for given domain(s)")
2018-11-30 09:14:29 +01:00
2018-12-06 10:56:04 +01:00
args = p.parse_args()
2018-11-30 09:14:29 +01:00
2018-12-06 10:56:04 +01:00
sanity_check_system()
2018-11-30 09:14:29 +01:00
if args.add:
cert_add(args.domain)
elif args.remove:
cert_remove(args.domain)
print('done.')