annotate host/https.luan @ 1630:b735ed134662

add nginx and ssl for host
author fffilimonov
date Fri, 10 Dec 2021 17:08:17 +0000
parents
children 0344a535b1db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1630
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
2 local error = Luan.error
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
3 local load_file = Luan.load_file or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
4 local ipairs = Luan.ipairs or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
5 local Boot = require "luan:Boot.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
6 local Io = require "luan:Io.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
7 local ip = Io.ip or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
8 local uri = Io.uri or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
9 local output_of = Io.output_of or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
10 local String = require "luan:String.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
11 local regex_quote = String.regex_quote or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
12 local matches = String.matches or error()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
13 local Http = require "luan:http/Http.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
14 local Hosted = require "luan:host/Hosted.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
15 local Logging = require "luan:logging/Logging.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
16 local logger = Logging.logger "https"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
17
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
18
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
19 local local_cer = [[
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
20 -----BEGIN CERTIFICATE-----
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
21 MIIGGDCCBQCgAwIBAgISA2I3DK1t/znI/s4eJX23gWOPMA0GCSqGSIb3DQEBCwUA
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
22 MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
23 ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xODA2MTEwODQ1MDJaFw0x
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
24 ODA5MDkwODQ1MDJaMCIxIDAeBgNVBAMTF2h0dHBzLnRlc3QubHVhbmhvc3QuY29t
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
25 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvlvCVOGcE/79DJFCh45W
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
26 pmqfwljQMYWDNbyNb6zND4QzG80RPHgWNpoDyVUXG8eLn/rDazi0ldwkFH5usrO+
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
27 m3IC5lT/Y/wIr+wT9dQv0l0IJKdkA+cnpOB0z8BU0nBnw6TKhhEcZrPsMRzjbFTJ
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
28 BLeUEf855Y+t/8TeSykBbV9ufiisLnR2/5gvOBW19LHkcxQYzKbmHPVh3sD2wyK8
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
29 gg8B3jgqHJh+m/amOfaxZnOEtEd/TGd6QxCbVvh1jewneBoM9niVOScGUk9JuVol
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
30 tEgToV7vKYpwNRObbN7pitdwudbB3gieK1/BoxHNudjArur4Vapkx/+GSX1aHIsO
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
31 wQIDAQABo4IDHjCCAxowDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUF
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
32 BwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBQhhVC3p8SHDpRt
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
33 GfyT/dPWQ7aSUDAfBgNVHSMEGDAWgBSoSmpjBH3duubRObemRWXv86jsoTBvBggr
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
34 BgEFBQcBAQRjMGEwLgYIKwYBBQUHMAGGImh0dHA6Ly9vY3NwLmludC14My5sZXRz
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
35 ZW5jcnlwdC5vcmcwLwYIKwYBBQUHMAKGI2h0dHA6Ly9jZXJ0LmludC14My5sZXRz
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
36 ZW5jcnlwdC5vcmcvMCIGA1UdEQQbMBmCF2h0dHBzLnRlc3QubHVhbmhvc3QuY29t
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
37 MIH+BgNVHSAEgfYwgfMwCAYGZ4EMAQIBMIHmBgsrBgEEAYLfEwEBATCB1jAmBggr
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
38 BgEFBQcCARYaaHR0cDovL2Nwcy5sZXRzZW5jcnlwdC5vcmcwgasGCCsGAQUFBwIC
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
39 MIGeDIGbVGhpcyBDZXJ0aWZpY2F0ZSBtYXkgb25seSBiZSByZWxpZWQgdXBvbiBi
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
40 eSBSZWx5aW5nIFBhcnRpZXMgYW5kIG9ubHkgaW4gYWNjb3JkYW5jZSB3aXRoIHRo
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
41 ZSBDZXJ0aWZpY2F0ZSBQb2xpY3kgZm91bmQgYXQgaHR0cHM6Ly9sZXRzZW5jcnlw
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
42 dC5vcmcvcmVwb3NpdG9yeS8wggEDBgorBgEEAdZ5AgQCBIH0BIHxAO8AdQApPFGW
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
43 VMg5ZbqqUPxYB9S3b79Yeily3KTDDPTlRUf0eAAAAWPuPA0tAAAEAwBGMEQCIFV8
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
44 xYbsY+O1vubYs0f6KVNlCMMd/d7R5HP76vnNWuGEAiBxlEyVDR4qPf8502v4cqfs
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
45 bG6UGaSqPT4gO8Xp8qOSCQB2ANt0r+7LKeyx/so+cW0s5bmquzb3hHGDx12dTze2
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
46 H79kAAABY+48DR0AAAQDAEcwRQIhAKdDQAa1EquTQzbZaiE88QccvGidohe/AbMB
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
47 Dd1TwQdwAiBGuXo3vKBKZpc1SONmXOz8Oq99JziXcsyLUvkBo99lejANBgkqhkiG
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
48 9w0BAQsFAAOCAQEASyfiSFAjL7nUuFrzhUPlMtWE6sF5JgIoLagHqcGiBZYW8Qzg
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
49 1Xs+zByFmIVl96T6Hgf/7ZRTD81CIinQCEeTPkx4P/S8xLSmyCmYjjxyvje4BHJW
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
50 AkW2eJtPwxQfKfLqaRFzJNE2I2PS1mQC2DyL76UghesujMx+B2uqb1geZ87XRwOu
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
51 iCwQtnLvdqAA3m2JMzahTWXElmW5YbzvbxWc1WLRn3lc3R9a9SFX++LTRxv44/i6
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
52 XiVFekc+IG6oL5bkcLIT70rLa8/vyqUaAicHvnkFp6CbmUX+Pe6nYAfBlYuQzGLM
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
53 e1qixE3bA1Mv6cpyOFIC+beASN/Xj7jbEa7EBA==
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
54 -----END CERTIFICATE-----
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
55 -----BEGIN CERTIFICATE-----
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
56 MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
57 MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
58 DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
59 SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
60 GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
61 AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
62 q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
63 SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
64 Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
65 a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
66 /PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
67 AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
68 CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
69 bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
70 c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
71 VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
72 ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
73 MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
74 Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
75 AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
76 uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
77 wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
78 X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
79 PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
80 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
81 -----END CERTIFICATE-----
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
82 ]]
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
83
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
84 local local_key = [[
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
85 -----BEGIN RSA PRIVATE KEY-----
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
86 MIIEpAIBAAKCAQEAvlvCVOGcE/79DJFCh45WpmqfwljQMYWDNbyNb6zND4QzG80R
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
87 PHgWNpoDyVUXG8eLn/rDazi0ldwkFH5usrO+m3IC5lT/Y/wIr+wT9dQv0l0IJKdk
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
88 A+cnpOB0z8BU0nBnw6TKhhEcZrPsMRzjbFTJBLeUEf855Y+t/8TeSykBbV9ufiis
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
89 LnR2/5gvOBW19LHkcxQYzKbmHPVh3sD2wyK8gg8B3jgqHJh+m/amOfaxZnOEtEd/
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
90 TGd6QxCbVvh1jewneBoM9niVOScGUk9JuVoltEgToV7vKYpwNRObbN7pitdwudbB
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
91 3gieK1/BoxHNudjArur4Vapkx/+GSX1aHIsOwQIDAQABAoIBAFRgJcYr7luqpY2B
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
92 gYTGYcAH+OJTLY0Vye/ysJp0dLxQ87p57g7oh6gSImWGUuTcURZLN316OAlI97Eh
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
93 zX1mULFkGsbvm/g8ibk4oixPrhbHZ8mfbKSSPC9H0l8XuEFC06uTirVcNkOLssCe
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
94 NmwZNLTjjj1f7NDFG/IH2CRme5x3cRdfVDQ1tYiK8lHxoHRj2uN3P1gsJIlDYR1a
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
95 A3TqbLDFYGsvoMPtgkcK/wRpBQCX0FL2IDrigGF33Eb5BiqFHx7KXO9Qjsyb6Y6z
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
96 B/OusjQ6LA//Oq2aizdoDD/op5GRAG7R5wB/8SrjlkME4q8psLRYalcgPwBStQjL
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
97 9tWVHGUCgYEA7xK3xB29TwYoTRY9RwtTILnYXdKM5tY0npC9jDeL96KZeibd0l/S
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
98 2jDqn32O8WUGYHticWYFuUS8evcGtsaBmZPUFT5ndp4DmfahttyS+CoF/NDPlZGq
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
99 cpl92ZDDCQrY68zSY9UhHY/JaslOVv963UfrL30Wok1Bg0A0sqDVgY8CgYEAy9YS
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
100 KjnspIWgC8Fq2kkMAIdBXQVnaRP5l7gyRmVuVwDXS+iG/0DGZfmv1g9S17lUz3R0
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
101 rpKp4iorboJ2A4Wiv0dgar7CmzLMcMSUREX4L7DoRsEXUuxsCOf0F2Vt3baVdo3N
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
102 PtfV8QzpcRAlN4Fap7s0ErNP21OE/ZXocwQ1oq8CgYEA5+1GrVEUiAc3LaF3jOZl
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
103 nIfuaQaLfp0rqvBLki2I8ZGiRqhR5XbkfJub4WHTPEd/ajYIiG4q+1K9bqUatFHb
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
104 BHwu8PT7Nk2QvNpQg690PJ+38003NKh9rHNPbbNMIgeN7SNkr0jhuWX2RkxIXYm3
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
105 TdgpRoaZYJaGCahN90SkG+0CgYBWM1J9Pv+/V68mKYaJh2im9IwEzZs8ybC8o63H
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
106 LW/rJTTnKg+k9HyydVQR/2r2Ra8DCGmrxeRH+7NgSZWkyafYolO48LEVtvbUHZ3h
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
107 /YEGkha4jUHS1J6faZBFMKS0pVkxyKfqkpYsGVzDbqN+hJqU4ksUOXZk9z3/i5zA
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
108 vx/7iwKBgQCELMiakqU/tw3U+VwTRKoWYgCxg9SyG3UWpyuZSguK5k+4C+BvCaXN
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
109 PT7RjA5Gb8oQKUd9kcn1x/ljyTw3mqn5AT7TqfJkG/sMh+Fkl+JMpWFVfmexWihG
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
110 eW2FbldbFg8IUzTPHAOFmO7+9h5oN0pBWwcml2D1YUqfGOyezisuAA==
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
111 -----END RSA PRIVATE KEY-----
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
112 ]]
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
113
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
114
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
115 function Hosted.set_https(is_https)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
116 local domain = Http.domain
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
117 local dir = uri("site:").parent()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
118 local nginx_file = dir.child("nginx.ssl.conf")
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
119 local key_file = dir.child(domain..".key")
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
120 local local_cer_file = dir.child("fullchain.cer")
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
121 local local_ca_file = dir.child("ca.cer")
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
122 local top_dir = uri("file:.").canonical().to_string()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
123 local changed = false
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
124 if is_https then -- https
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
125 if not key_file.exists() then
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
126 local is_local = ip(domain) == "127.0.0.1"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
127 logger.info("is_local "..is_local)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
128 if is_local then
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
129 key_file.write(local_key)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
130 local_cer_file.write(local_cer)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
131 else
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
132 local cmd = [[
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
133 ./acme.sh --debug --issue -d "]]..domain..[[" --stateless --cert-home "]]..top_dir..[[/sites" --config-home "]]..top_dir..[[/local/letsencrypt/config";
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
134 ]]
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
135 local s = uri("bash:"..cmd).read_text()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
136 logger.info("issue certificate "..s)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
137 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
138 if key_file.exists() and local_cer_file.exists() then
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
139 changed = true
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
140 local conf = load_file "file:startup/nginx.ssl.conf.luan"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
141 local nginx = output_of( function() conf(top_dir,domain) end )
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
142 nginx_file.write(nginx)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
143 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
144 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
145 else -- http
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
146 if key_file.exists() or nginx_file.exists() then
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
147 changed = true
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
148 nginx_file.delete()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
149 local_cer_file.delete()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
150 local_ca_file.delete()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
151 local ptn = [[^]]..regex_quote(domain)..[[\.]]
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
152 for _, file in ipairs(dir.children()) do
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
153 if matches(file.name(),ptn) then
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
154 file.delete()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
155 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
156 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
157 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
158 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
159 if changed then
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
160 local cmd = [[
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
161 sudo $(which nginx) -t -c "]]..top_dir..[[/local/nginx.conf" && sudo $(which nginx) -s reload;
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
162 ]]
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
163 local s = uri("bash:"..cmd).read_text()
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
164 logger.info("reload_nginx "..s)
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
165 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
166 --logger.info "done"
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
167 end
b735ed134662 add nginx and ssl for host
fffilimonov
parents:
diff changeset
168 Hosted.set_https = Boot.no_security(Hosted.set_https)