Skip to content

Commit 21e3ae6

Browse files
authored
Merge pull request #9 from fritz-fritz/master
Optimize Security
2 parents d97b05a + dd9d859 commit 21e3ae6

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

deploy_freenas.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020
import requests
2121
import subprocess
2222
from datetime import datetime
23+
from urllib3.exceptions import InsecureRequestWarning
24+
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
2325

24-
PRIVATEKEY_PATH = "/root/.acme.sh/your_fqdn/your_fqdn.key"
25-
FULLCHAIN_PATH = "/root/.acme.sh/your_fqdn/fullchain.cer"
26-
USER = "root"
27-
PASSWORD = "ReallySecurePassword"
2826
DOMAIN_NAME = "your_fqdn"
27+
PASSWORD = "ReallySecurePassword"
28+
29+
USER = "root"
30+
PRIVATEKEY_PATH = "/root/.acme.sh/" + DOMAIN_NAME + "/" + DOMAIN_NAME + ".key"
31+
FULLCHAIN_PATH = "/root/.acme.sh/" + DOMAIN_NAME + "/fullchain.cer"
2932
PROTOCOL = 'http://'
33+
PORT = '80'
3034
now = datetime.now()
31-
cert = "letsencrypt-%s-%s-%s" %(now.year, now.strftime('%m'), now.strftime('%d'))
35+
cert = "letsencrypt-%s-%s-%s-%s" %(now.year, now.strftime('%m'), now.strftime('%d'), ''.join(c for c in now.strftime('%X') if
36+
c.isdigit()))
3237

3338
# Load cert/key
3439
with open(PRIVATEKEY_PATH, 'r') as file:
@@ -38,7 +43,8 @@
3843

3944
# Update or create certificate
4045
r = requests.post(
41-
PROTOCOL + DOMAIN_NAME + '/api/v1.0/system/certificate/import/',
46+
PROTOCOL + 'localhost:' + PORT + '/api/v1.0/system/certificate/import/',
47+
verify=False,
4248
auth=(USER, PASSWORD),
4349
headers={'Content-Type': 'application/json'},
4450
data=json.dumps({
@@ -58,7 +64,8 @@
5864
# Download certificate list
5965
limit = {'limit': 0} # set limit to 0 to disable paging in the event of many certificates
6066
r = requests.get(
61-
PROTOCOL + DOMAIN_NAME + '/api/v1.0/system/certificate/',
67+
PROTOCOL + 'localhost:' + PORT + '/api/v1.0/system/certificate/',
68+
verify=False,
6269
params=limit,
6370
auth=(USER, PASSWORD))
6471

@@ -80,7 +87,8 @@
8087

8188
# Set our cert as active
8289
r = requests.put(
83-
PROTOCOL + DOMAIN_NAME + '/api/v1.0/system/settings/',
90+
PROTOCOL + 'localhost:' + PORT + '/api/v1.0/system/settings/',
91+
verify=False,
8492
auth=(USER, PASSWORD),
8593
headers={'Content-Type': 'application/json'},
8694
data=json.dumps({
@@ -98,7 +106,8 @@
98106
# Reload nginx with new cert
99107
try:
100108
r = requests.post(
101-
PROTOCOL + DOMAIN_NAME + '/api/v1.0/system/settings/restart-httpd-all/',
109+
PROTOCOL + 'localhost:' + PORT + '/api/v1.0/system/settings/restart-httpd-all/',
110+
verify=False,
102111
auth=(USER, PASSWORD),
103112
)
104113
except requests.exceptions.ConnectionError:

0 commit comments

Comments
 (0)