33import requests
44import sys
55import subprocess
6+
67from subprocess import PIPE
78from os import path , remove
8- from shutil import copyfile
9+ from shutil import copyfile , which
10+
11+ import dns_01
912
1013LE_INFO_URL = 'https://acme-v02.api.letsencrypt.org/directory'
1114
@@ -72,6 +75,10 @@ def invalid_domains(domains):
7275 if len (domain ) > 254 :
7376 return ('Error in {}: Domain names must not exceed 254'
7477 ' characters' .format (domain ))
78+ if domain .count ('.' ) < 1 :
79+ return ('Error in {}: Domain may not have less'
80+ ' than 2 segments'
81+ '' .format (domain ))
7582 for part in domain .split ('.' ):
7683 if not 0 < len (part ) < 64 :
7784 return ('Error in {}: Domain segments may not be larger'
@@ -100,16 +107,6 @@ def run():
100107 console .msgbox ('Error' , msg , autosize = True )
101108 return
102109
103- ret = console .yesno (
104- 'DNS must be configured before obtaining certificates. '
105- 'Incorrectly configured dns and excessive attempts could '
106- 'lead to being temporarily blocked from requesting '
107- 'certificates.\n \n Do you wish to continue?' ,
108- autosize = True
109- )
110- if ret != 'ok' :
111- return
112-
113110 ret = console .yesno (
114111 "Before getting a Let's Encrypt certificate, you must agree"
115112 ' to the current Terms of Service.\n \n '
@@ -132,6 +129,74 @@ def run():
132129 )
133130 return
134131
132+ ret , challenge = console .menu ('Challenge type' ,
133+ 'Select challenge type to use' , [
134+ ('http-01' , 'Requires public web access to this system' ),
135+ ('dns-01' , 'Requires your DNS provider to provide an API' )
136+ ])
137+ if ret != 'ok' :
138+ return
139+
140+ if challenge == 'http-01' :
141+ ret = console .yesno (
142+ 'DNS must be configured before obtaining certificates. '
143+ 'Incorrectly configured DNS and excessive attempts could '
144+ 'lead to being temporarily blocked from requesting '
145+ 'certificates.\n \n Do you wish to continue?' ,
146+ autosize = True
147+ )
148+ if ret != 'ok' :
149+ return
150+
151+ if challenge == 'dns-01' :
152+ config = dns_01 .load_config ()
153+ fields = [
154+ ('' , 1 , 0 , config [0 ], 1 , 10 , field_width , 255 ),
155+ ('' , 2 , 0 , config [1 ], 2 , 10 , field_width , 255 ),
156+ ('' , 3 , 0 , config [2 ], 3 , 10 , field_width , 255 ),
157+ ('' , 4 , 0 , config [3 ], 4 , 10 , field_width , 255 ),
158+ ('' , 5 , 0 , config [4 ], 5 , 10 , field_width , 255 ),
159+ ('' , 6 , 0 , config [5 ], 6 , 10 , field_width , 255 ),
160+ ('' , 7 , 0 , config [6 ], 7 , 10 , field_width , 255 ),
161+ ]
162+ ret , values = console .form ('Lexicon configuration' ,
163+ 'Review and adjust current lexicon '
164+ 'configuration as necessary.\n \n '
165+ 'You can follow configuration reference at:\n '
166+ 'https://dns-lexicon.readthedocs.io/' ,
167+ fields , autosize = True )
168+ if ret != 'ok' :
169+ return
170+
171+ if config != values :
172+ dns_01 .save_config (values )
173+
174+ providers , err = dns_01 .get_providers ()
175+ if err :
176+ console .msgbox ('Error' , err , autosize = True )
177+ return
178+
179+ ret , provider = console .menu ('DNS providers list' ,
180+ 'Select DNS provider you\' d like to use' ,
181+ providers )
182+ if ret != 'ok' :
183+ return
184+ elif provider == 'auto' and not which ('nslookup' ):
185+ ret = console .yesno (
186+ 'nslookup tool is required to use dns-01 challenge with auto provider.\n \n '
187+ 'Do you wish to install it now?' ,
188+ autosize = True
189+ )
190+ if ret != 'ok' :
191+ return
192+
193+ apt = subprocess .run (['apt-get' , '-y' , 'install' , 'dnsutils' ],
194+ encoding = sys .stdin .encoding ,
195+ stderr = PIPE )
196+ if apt .returncode != 0 :
197+ console .msgbox ('Error' , apt .stderr .strip (), autosize = True )
198+ return
199+
135200 domains = load_domains ()
136201 m = invalid_domains (domains )
137202
@@ -179,10 +244,13 @@ def run():
179244
180245 # User has accepted ToS as part of this process, so pass '--register'
181246 # switch to Dehydrated wrapper
182- proc = subprocess .run (
183- ['bash' , path .join (
184- path .dirname (PLUGIN_PATH ), 'dehydrated-wrapper' ),
185- '--register' ],
247+ dehydrated_bin = ['bash' , path .join (
248+ path .dirname (PLUGIN_PATH ), 'dehydrated-wrapper' ),
249+ '--register' , '--challenge' , challenge ]
250+ if challenge == 'dns-01' :
251+ dehydrated_bin .append ('--provider' )
252+ dehydrated_bin .append (provider )
253+ proc = subprocess .run (dehydrated_bin ,
186254 encoding = sys .stdin .encoding ,
187255 stderr = PIPE )
188256 if proc .returncode == 0 :
0 commit comments