mirror of
https://github.com/openwrt/luci.git
synced 2026-04-15 10:51:51 +00:00
luci-app-acme: Guess the system domain and pre-fill it to domains.
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>
This commit is contained in:
committed by
Toke Høiland-Jørgensen
parent
170c8e5f19
commit
c4e38e2656
@@ -19,6 +19,7 @@ return view.extend({
|
||||
}),
|
||||
L.resolveDefault(fs.exec_direct('/usr/libexec/acmesh-dnsinfo.sh'), ''),
|
||||
L.resolveDefault(fs.stat('/usr/lib/acme/client/dnsapi'), null),
|
||||
L.resolveDefault(fs.lines('/proc/sys/kernel/hostname'), ''),
|
||||
]);
|
||||
},
|
||||
|
||||
@@ -27,6 +28,8 @@ return view.extend({
|
||||
let dnsApiInfoText = data[1];
|
||||
let apiInfos = dnsapi.parseFile(dnsApiInfoText);
|
||||
let hasDnsApi = data[2] != null;
|
||||
let hostname = data[3];
|
||||
let systemDomain = _guessDomain(hostname);
|
||||
let wikiUrl = 'https://github.com/acmesh-official/acme.sh/wiki/';
|
||||
let wikiInstructionUrl = wikiUrl + 'dnsapi';
|
||||
let m, s, o;
|
||||
@@ -97,6 +100,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 (!value) {
|
||||
return true;
|
||||
@@ -271,6 +277,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) && !/[0-9-]\..*$/.test(domain);
|
||||
}
|
||||
|
||||
function _guessDomain(hostname) {
|
||||
return _isFqdn(hostname) ? hostname : (_isFqdn(window.location.hostname) ? window.location.hostname : '');
|
||||
}
|
||||
|
||||
|
||||
function _addDnsProviderField(s, apiId, opt, isOptsAlt) {
|
||||
let desc = '<code>' + opt.Name + '</code> ' + opt.Description;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"read": {
|
||||
"cgi-io": [ "exec" ],
|
||||
"file": {
|
||||
"/proc/sys/kernel/hostname": [ "read" ],
|
||||
"/etc/ssl/acme": [ "list" ],
|
||||
"/usr/libexec/acmesh-dnsinfo.sh": [ "exec" ]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user