forked from steinsag/hosteurope-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
neu.py
executable file
·51 lines (42 loc) · 1.55 KB
/
neu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# coding=utf-8
import json
import os
from shared import domain_list, config_file
# certbot tries to write to /var/log/letsencrypt by default; because of this, running as root is required.
# certbot Error Message:
# Either run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.
is_root = os.geteuid() == 0
home_dir = os.path.expanduser('~/.config/hosteurope-letsencrypt')
certbot_config_dir = home_dir
certbot_work_dir = home_dir
certbot_logs_dir = os.path.expanduser('~/.config/hosteurope-letsencrypt/logs')
if not is_root and not os.path.exists(certbot_logs_dir):
os.makedirs(certbot_logs_dir)
# Einstellungen einlesen
with open(config_file('einstellungen.json')) as cfg_file:
config = json.load(cfg_file)
email = config['email']
staging = config['staging']
challenge = config.get('preferred-challenge', 'http')
# certbot Kommando zusammenbauen
cmd = 'certbot certonly --manual --agree-tos --manual-public-ip-logging-ok'
cmd += ' -m ' + email
cmd += ' --preferred-challenge=' + challenge
if 'http' == challenge:
cmd += ' --manual-auth-hook "python3 validate.py"'
if staging:
cmd += ' --staging'
if not is_root:
cmd += ' --logs-dir ' + certbot_logs_dir
cmd += ' --work-dir ' + certbot_work_dir
cmd += ' --config-dir ' + certbot_config_dir
cmd += domain_list
# Sicherheitsabfrage
print(cmd)
answer = input('Für diese Domains ein neues Zertifikat erstellen? (j/n): ')
if answer != 'j':
print('Abbruch, es wurde kein Zertifikat erstellt.')
exit(0)
# neues Zertifikat erstellen
os.system(cmd)