summaryrefslogtreecommitdiffhomepage
path: root/docs/jsapi/fs.js.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/jsapi/fs.js.html')
-rw-r--r--docs/jsapi/fs.js.html138
1 files changed, 137 insertions, 1 deletions
diff --git a/docs/jsapi/fs.js.html b/docs/jsapi/fs.js.html
index 467319f89a..769e3edd87 100644
--- a/docs/jsapi/fs.js.html
+++ b/docs/jsapi/fs.js.html
@@ -74,6 +74,8 @@
<li data-name="LuCI#location"><a href="LuCI.html#location">location</a></li>
+ <li data-name="LuCI#media"><a href="LuCI.html#media">media</a></li>
+
<li data-name="LuCI#path"><a href="LuCI.html#path">path</a></li>
<li data-name="LuCI#poll"><a href="LuCI.html#poll">poll</a></li>
@@ -220,12 +222,16 @@
<li data-name="LuCI.fs#exec"><a href="LuCI.fs.html#exec">exec</a></li>
+ <li data-name="LuCI.fs#exec_direct"><a href="LuCI.fs.html#exec_direct">exec_direct</a></li>
+
<li data-name="LuCI.fs#lines"><a href="LuCI.fs.html#lines">lines</a></li>
<li data-name="LuCI.fs#list"><a href="LuCI.fs.html#list">list</a></li>
<li data-name="LuCI.fs#read"><a href="LuCI.fs.html#read">read</a></li>
+ <li data-name="LuCI.fs#read_direct"><a href="LuCI.fs.html#read_direct">read_direct</a></li>
+
<li data-name="LuCI.fs#remove"><a href="LuCI.fs.html#remove">remove</a></li>
<li data-name="LuCI.fs#stat"><a href="LuCI.fs.html#stat">stat</a></li>
@@ -864,6 +870,8 @@
<span class="subtitle">Methods</span>
+ <li data-name="LuCI.Response#blob"><a href="LuCI.Response.html#blob">blob</a></li>
+
<li data-name="LuCI.Response#clone"><a href="LuCI.Response.html#clone">clone</a></li>
<li data-name="LuCI.Response#json"><a href="LuCI.Response.html#json">json</a></li>
@@ -1186,6 +1194,40 @@ function handleRpcReply(expect, rc) {
return rc;
}
+function handleCgiIoReply(res) {
+ if (!res.ok || res.status != 200) {
+ var e = new Error(res.statusText);
+ switch (res.status) {
+ case 400:
+ e.name = 'InvalidArgumentError';
+ break;
+
+ case 403:
+ e.name = 'PermissionError';
+ break;
+
+ case 404:
+ e.name = 'NotFoundError';
+ break;
+
+ default:
+ e.name = 'Error';
+ }
+ throw e;
+ }
+
+ switch (this.type) {
+ case 'blob':
+ return res.blob();
+
+ case 'json':
+ return res.json();
+
+ default:
+ return res.text();
+ }
+}
+
/**
* @class fs
* @memberof LuCI
@@ -1371,6 +1413,100 @@ var FileSystem = L.Class.extend(/** @lends LuCI.fs.prototype */ {
return lines;
});
+ },
+
+ /**
+ * Read the contents of the given file and return them, bypassing ubus.
+ *
+ * This function will read the requested file through the cgi-io
+ * helper applet at `/cgi-bin/cgi-download` which bypasses the ubus rpc
+ * transport. This is useful to fetch large file contents which might
+ * exceed the ubus message size limits or which contain binary data.
+ *
+ * The cgi-io helper will enforce the same access permission rules as
+ * the ubus based read call.
+ *
+ * @param {string} path
+ * The file path to read.
+ *
+ * @param {string} [type=text]
+ * The expected type of read file contents. Valid values are `text` to
+ * interpret the contents as string, `json` to parse the contents as JSON
+ * or `blob` to return the contents as Blob instance.
+ *
+ * @returns {Promise&lt;*>}
+ * Returns a promise resolving with the file contents interpreted according
+ * to the specified type or rejecting with an error stating the failure
+ * reason.
+ */
+ read_direct: function(path, type) {
+ var postdata = 'sessionid=%s&amp;path=%s'
+ .format(encodeURIComponent(L.env.sessionid), encodeURIComponent(path));
+
+ return L.Request.post(L.env.cgi_base + '/cgi-download', postdata, {
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+ responseType: (type == 'blob') ? 'blob' : 'text'
+ }).then(handleCgiIoReply.bind({ type: type }));
+ },
+
+ /**
+ * Execute the specified command, bypassing ubus.
+ *
+ * Note: The `command` must be either the path to an executable,
+ * or a basename without arguments in which case it will be searched
+ * in $PATH. If specified, the values given in `params` will be passed
+ * as arguments to the command.
+ *
+ * This function will invoke the requested commands through the cgi-io
+ * helper applet at `/cgi-bin/cgi-exec` which bypasses the ubus rpc
+ * transport. This is useful to fetch large command outputs which might
+ * exceed the ubus message size limits or which contain binary data.
+ *
+ * The cgi-io helper will enforce the same access permission rules as
+ * the ubus based exec call.
+ *
+ * @param {string} command
+ * The command to invoke.
+ *
+ * @param {string[]} [params]
+ * The arguments to pass to the command.
+ *
+ * @param {string} [type=text]
+ * The expected output type of the invoked program. Valid values are
+ * `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&lt;*>}
+ * 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, latin1) {
+ var cmdstr = String(command)
+ .replace(/\\/g, '\\\\').replace(/(\s)/g, '\\$1');
+
+ if (Array.isArray(params))
+ for (var i = 0; i &lt; params.length; i++)
+ 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&amp;command=%s'
+ .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' },
+ responseType: (type == 'blob') ? 'blob' : 'text'
+ }).then(handleCgiIoReply.bind({ type: type }));
}
});
@@ -1387,7 +1523,7 @@ return FileSystem;
<footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Nov 07 2019 12:36:05 GMT+0100 (Central European Standard Time)
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Feb 12 2020 11:56:59 GMT+0100 (Central European Standard Time)
</footer>
</div>
</div>