コマンドしなくてもレッツ円栗プトで発行できるようにしてみました。
See the Pen Untitled by John Doe (@04) on CodePen.
初期化
sudo apt install -y zip certbot
server.py
from http.server import HTTPServer, SimpleHTTPRequestHandler
import os
import re
import ssl
import subprocess
import threading
from socketserver import ThreadingMixIn
class ThreadingSimpleServer(ThreadingMixIn,HTTPServer):
pass
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):
def do_POST(self):
domain = os.path.basename(self.path)
if not re.match(r'^([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]*\.)+[a-zA-Z]{2,}$', domain):
self.send_response(400)
self.send_header( "Access-Control-Allow-Origin", "*")
self.end_headers()
return
self.send_response(200)
self.send_header('Content-Type', 'text/event-stream')
self.send_header( "Access-Control-Allow-Origin", "*")
self.end_headers()
domain = os.path.basename(self.path)
proc = subprocess.Popen(f'sudo certbot certonly --standalone --register-unsafely-without-email --agree-tos --non-interactive -d "{domain}"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in proc.stdout:
self.wfile.write(line)
zip_command = f'[ -d "/etc/letsencrypt/live/{domain}" ] && sudo zip -jrq "{domain}.zip" "/etc/letsencrypt/live/{domain}" && echo "\nCertificates: https://certbot.cf/{domain}.zip"'
proc = subprocess.Popen(zip_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in proc.stdout:
self.wfile.write(line)
httpd = ThreadingSimpleServer(('0.0.0.0', 443), CustomHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='../privkey.pem', certfile="../fullchain.pem", server_side=True)
print("Server running on https://certbot.cf")
httpd.serve_forever()