From f843014f2469da1a7844754a9e804783fdb6fe39 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 27 Dec 2024 01:08:48 +0200 Subject: [PATCH] luci-app-acme: DNS API store all params Previously only one DNS API field was stored. Get the current creds list, alter it and save. Fix #7504 Signed-off-by: Sergey Ponomarev --- .../htdocs/luci-static/resources/view/acme.js | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js b/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js index d948762609..2b0e7a78f4 100644 --- a/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js +++ b/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js @@ -529,7 +529,7 @@ return view.extend({ function _addDnsProviderField(s, provider, env, title, desc) { - let o = s.taboption('challenge_dns', form.Value, '_' + env, _(title), + let o = s.taboption('challenge_dns', form.Value, '_credentials_' + env, _(title), _(desc)); o.depends('dns', provider); o.modalonly = true; @@ -537,35 +537,58 @@ function _addDnsProviderField(s, provider, env, title, desc) { var creds = this.map.data.get(this.map.config, section_id, 'credentials'); return _extractParamValue(creds, env); }; - o.write = function (section_id, value) { - this.map.data.set('acme', section_id, 'credentials', [env + '="' + value + '"']); - }; + o.write = function (section_id, value) { }; + o.onchange = _handleEditChange; return o; } +function _handleEditChange(event, section_id, newVal) { + // Add the provider field value directly to the credentials DynList + let credentialsDynList = this.map.lookupOption('credentials', section_id)[0].getUIElement(section_id); + let creds = credentialsDynList.getValue(); + let credsMap = _parseKeyValueListToMap(creds); + let optName = this.option.substring('_credentials_'.length); + if (newVal) { + credsMap.set(optName, newVal); + } else { + credsMap.delete(optName); + } + let newCreds = []; + for (let [key, val] of credsMap) { + newCreds.push(key + '="' + val + '"'); + } + credentialsDynList.setValue(newCreds); +} + /** * @param {string[]} paramsKeyVals * @param {string} paramName * @returns {string} */ function _extractParamValue(paramsKeyVals, paramName) { + let map = _parseKeyValueListToMap(paramsKeyVals) + return map.get(paramName) || ''; +} + +/** + * @param {string[]} paramsKeyVals + * @returns {Map} + */ +function _parseKeyValueListToMap(paramsKeyVals) { + let map = new Map(); if (!paramsKeyVals) { - return ''; + return map; } - for (let i = 0; i < paramsKeyVals.length; i++) { - var paramKeyVal = paramsKeyVals[i]; - var parts = paramKeyVal.split('='); - if (parts.lenght < 2) { + for (let paramKeyVal of paramsKeyVals) { + let pos = paramKeyVal.indexOf("="); + if (pos < 0) { continue; } - var name = parts[0]; - var val = parts[1]; - if (name == paramName) { - // unquote - return val.substring(0, val.length-1).substring(1); - } + let name = paramKeyVal.slice(0, pos); + let unquotedVal = paramKeyVal.slice(pos + 2, paramKeyVal.length - 1); + map.set(name, unquotedVal); } - return ''; + return map; } function _handleCheckService(c, event, curVal, newVal) {