diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-02-12 11:38:53 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-02-12 11:59:41 +0100 |
commit | dc60aaeb77575bc261331ba1ea288d18c330f160 (patch) | |
tree | 4ca98ad93420d198a03f90dd272617a3c27521d7 /modules/luci-base/htdocs/luci-static/resources/fs.js | |
parent | 9bb78b5cd842f94cbcaf00cc5b19c1e3b9669d93 (diff) |
luci-base: fs.js: exec_direct(): add ability to encode command as latin1
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources/fs.js')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/fs.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/fs.js b/modules/luci-base/htdocs/luci-static/resources/fs.js index df3a14b756..8d2760dd5e 100644 --- a/modules/luci-base/htdocs/luci-static/resources/fs.js +++ b/modules/luci-base/htdocs/luci-static/resources/fs.js @@ -390,12 +390,17 @@ var FileSystem = L.Class.extend(/** @lends LuCI.fs.prototype */ { * `text` to interpret the output as string, `json` to parse the output * as JSON or `blob` to return the output as Blob instance. * + * @param {boolean} [latin1=false] + * Whether to encode the command line as Latin1 instead of UTF-8. This + * is usually not needed but can be useful for programs that cannot + * handle UTF-8 input. + * * @returns {Promise<*>} * Returns a promise resolving with the command stdout output interpreted * according to the specified type or rejecting with an error stating the * failure reason. */ - exec_direct: function(command, params, type) { + exec_direct: function(command, params, type, latin1) { var cmdstr = String(command) .replace(/\\/g, '\\\\').replace(/(\s)/g, '\\$1'); @@ -404,8 +409,13 @@ var FileSystem = L.Class.extend(/** @lends LuCI.fs.prototype */ { cmdstr += ' ' + String(params[i]) .replace(/\\/g, '\\\\').replace(/(\s)/g, '\\$1'); + if (latin1) + cmdstr = escape(cmdstr).replace(/\+/g, '%2b'); + else + cmdstr = encodeURIComponent(cmdstr); + var postdata = 'sessionid=%s&command=%s' - .format(encodeURIComponent(L.env.sessionid), encodeURIComponent(cmdstr)); + .format(encodeURIComponent(L.env.sessionid), cmdstr); return L.Request.post(L.env.cgi_base + '/cgi-exec', postdata, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, |