Skip to content

Commit

Permalink
luci-app-acme: Guess the system domain and pre-fill it to domains.
Browse files Browse the repository at this point in the history
Check if the hostname is FQDN (e.g. has least one dot).
Check if the domain in the browser is not an IP and FQDN.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
  • Loading branch information
stokito committed Jun 1, 2024
1 parent 9a7e54d commit 9c1bbae
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ return view.extend({
return certs;
}),
L.resolveDefault(fs.stat('/usr/lib/acme/client/dnsapi'), null),
fs.lines('/proc/sys/kernel/hostname'),
]);
},

render: function (data) {
let certs = data[0];
let hasDnsApi = data[1] != null;
let hostname = data[2];
let systemDomain = _guessDomain(hostname);
let wikiUrl = 'https://github.com/acmesh-official/acme.sh/wiki/';
var wikiInstructionUrl = wikiUrl + 'dnsapi';
var m, s, o;
Expand Down Expand Up @@ -96,6 +99,9 @@ return view.extend({
"The first name will be the subject name, subsequent names will be alt names. " +
"Note that all domain names must point at the router in the global DNS."));
o.datatype = "list(string)";
if (systemDomain) {
o.default = [systemDomain];
}
o.validate = function (section_id, value) {
if (!/^[*a-z0-9.-]*$/.test(value)) {
return _('Invalid domain');
Expand Down Expand Up @@ -579,6 +585,15 @@ return view.extend({
}
})

function _isFqdn(domain) {
// Is not an IP i.e. starts from alphanumeric and has least one dot
return /[a-z0-9-]\..*$/.test(domain);
}

function _guessDomain(hostname) {
return _isFqdn(hostname) ? hostname : (_isFqdn(window.location.hostname) ? window.location.hostname : '');
}


function _addDnsProviderField(s, provider, env, title, desc) {
let o = s.taboption('challenge_dns', form.Value, '_' + env, _(title),
Expand Down

0 comments on commit 9c1bbae

Please sign in to comment.