forked from steinsag/hosteurope-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_certificate.py
executable file
·72 lines (57 loc) · 2.32 KB
/
set_certificate.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# coding=utf-8
import json
import os
import asyncio
from pyppeteer import launch
from shared import domain_list, config_file
import time
import sys
cfg_file = open(config_file('einstellungen.json'))
config = json.load(cfg_file)
cert_conf_file = open(config_file('cert-urls.json'))
cert_config = json.load(cert_conf_file)
async def set_certificate_for(browser, url, cert_file, key_file, domain_name):
page = await browser.newPage()
# Open SSL page
await page.goto(url, {'waitUntil': 'networkidle2'})
await page.setViewport({'width': 1366, 'height': 1000})
time.sleep(1)
# Fill in form
certfileUpload = await page.querySelector("input[name=certfile]")
keyfileUpload = await page.querySelector("input[name=keyfile]")
await certfileUpload.uploadFile(cert_file)
await keyfileUpload.uploadFile(key_file)
# Submit form
await page.focus("input[name=keypass]")
await page.keyboard.press("Enter")
time.sleep(1)
await page.waitForNavigation({'waitUntil': 'networkidle2'})
# Log result
await page.screenshot({'path': domain_name+'.log.jpeg'})
async def set_certificate():
# Login
browser = await launch({'headless': False, 'slowMo': 1, 'devtools': True})
page = await browser.newPage()
await page.goto('https://kis.hosteurope.de', {'waitUntil': 'networkidle2'})
await page.focus("input[autocomplete=email]")
await page.keyboard.type(config["kis-username"])
await page.focus("input[type=password]")
await page.keyboard.type(config["kis-password"])
await page.keyboard.press("Enter")
await page.waitForNavigation({'waitUntil': 'networkidle2'})
time.sleep(1)
#2FA
if (config["kis-2fa"]):
await page.focus("input[id=1]")
await page.keyboard.type(input("Enter the 2FA you got via SMS here: "))
await page.keyboard.press("Enter")
await page.waitForNavigation({'waitUntil': 'networkidle2'})
time.sleep(1)
for (domain, url) in cert_config.items():
cert_file = config_file(os.path.join('live', domain, 'fullchain.pem'))
key_file = config_file(os.path.join('live', domain, 'privkey.pem'))
await set_certificate_for(browser, url, cert_file, key_file, domain)
time.sleep(10)
await browser.close()
asyncio.get_event_loop().run_until_complete(set_certificate())