This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcertbun.py
executable file
·46 lines (37 loc) · 1.87 KB
/
certbun.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
import json
import requests
import sys
import os
def getSSL(domain): #grab all the records so we know which ones to delete to make room for our record. Also checks to make sure we've got the right domain
allRecords=json.loads(requests.post(apiConfig["endpoint"] + '/ssl/retrieve/' + domain, data = json.dumps(apiConfig)).text)
if allRecords["status"]=="ERROR":
print('Error retrieving SSL.');
print(allRecords["message"]);
sys.exit();
return(allRecords)
if len(sys.argv)>1: #at least the config and root domain is specified
apiConfig = json.load(open(sys.argv[1])) #load the config file into a variable
rootDomain=apiConfig["domain"]
print("Downloading certs for " + rootDomain + "\n");
certJSON=getSSL(rootDomain)
f = open(apiConfig["domainCertLocation"], "w")
print("Installing " + apiConfig["domainCertLocation"])
f.write(certJSON["certificatechain"])
f.close()
f = open(apiConfig["privateKeyLocation"], "w")
print("Installing " + apiConfig["privateKeyLocation"])
f.write(certJSON["privatekey"])
f.close()
f = open(apiConfig["publicKeyLocation"], "w")
print("Installing " + apiConfig["publicKeyLocation"])
f.write(certJSON["publickey"])
f.close()
f = open(apiConfig["intermediateCertLocation"], "w")
print("Installing " + apiConfig["intermediateCertLocation"])
f.write(certJSON["intermediatecertificate"])
f.close()
print("\nExecuting system command:\n" + apiConfig["commandToReloadWebserver"] + "\n")
commandOutput=os.popen(apiConfig["commandToReloadWebserver"]).read()
print(commandOutput + "\n")
else:
print("certbun, a simpler way to keep your web server's SSL certificates current.\n\nError: not enough arguments. Example:\npython certbun.py /path/to/config.json \n\nThe config file contains your Porkbun API keys as well as the \ndomain in question, the location on your file system to copy\nthe keys, and the command to restart/reload the web server.\n")