summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-aria2/luasrc/view/aria2
diff options
context:
space:
mode:
authorHsing-Wang Liao <kuoruan@gmail.com>2016-05-30 14:30:47 +0800
committerHsing-Wang Liao <kuoruan@gmail.com>2016-05-30 21:27:22 +0800
commitc88aea6277ce7242217eda6115a44f6fedb49e56 (patch)
tree1a26880f21f79573ed9f96f44e00b69ad9adc6b4 /applications/luci-app-aria2/luasrc/view/aria2
parentc46963613f7f1312dac62e507346777ba6f8d8a6 (diff)
luci-app-aria2: Add package
LuCI Support for Aria2 Signed-off-by: Hsing-Wang Liao <kuoruan@gmail.com>
Diffstat (limited to 'applications/luci-app-aria2/luasrc/view/aria2')
-rw-r--r--applications/luci-app-aria2/luasrc/view/aria2/web_script.htm77
1 files changed, 77 insertions, 0 deletions
diff --git a/applications/luci-app-aria2/luasrc/view/aria2/web_script.htm b/applications/luci-app-aria2/luasrc/view/aria2/web_script.htm
new file mode 100644
index 0000000000..933c6af702
--- /dev/null
+++ b/applications/luci-app-aria2/luasrc/view/aria2/web_script.htm
@@ -0,0 +1,77 @@
+<script type="text/javascript">//<![CDATA[
+XHR.poll(5, '<%=url([[admin]], [[services]], [[aria2]], [[status]])%>', null,
+ function(x, data) {
+ var tb = document.getElementById('aria2_status');
+ if (data && tb) {
+ if (data.running) {
+ var links = '<em><%:The Aria2 service is running.%></em>';
+ if (data.yaaw) {
+ links += '<input class="cbi-button mar-10" type="button" value="<%:Open YAAW%>" onclick="openWebUI(\'yaaw\');" />';
+ }
+ if (data.webui) {
+ links += '<input class="cbi-button mar-10" type="button" value="<%:Open WebUI-Aria2%>" onclick="openWebUI(\'webui-aria2\');" />';
+ }
+ tb.innerHTML = links;
+ } else {
+ tb.innerHTML = '<em><%:The Aria2 service is not running.%></em>';
+ }
+ }
+ }
+);
+
+function randomString(len) {
+ len = len || 32;
+ var $chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
+ var maxPos = $chars.length;
+ var pwd = '';
+ for (i = 0; i < len; i++) {
+ pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
+ }
+ return pwd;
+};
+
+function randomSecret() {
+ var Token = document.getElementById("cbid.aria2.main.rpc_secret");
+ Token.value = randomString(32);
+};
+
+function showRPCURL() {
+ var websocket = document.getElementById("use_websocket");
+ var protocol = (websocket.checked) ? "ws" : "http";
+ var newTextNode = document.getElementById("aria2rpcpath");
+ var auth_method = document.getElementById("cbid.aria2.main.rpc_auth_method");
+ var auth_port = document.getElementById("cbid.aria2.main.rpc_listen_port");
+ if (auth_port.value == "") {
+ auth_port_value = "6800"
+ } else {
+ auth_port_value = auth_port.value
+ };
+ if (auth_method.value == "token") {
+ var auth_token = document.getElementById("cbid.aria2.main.rpc_secret");
+ newTextNode.value = protocol + "://token:" + auth_token.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
+ } else if (auth_method.value == "user_pass") {
+ var auth_user = document.getElementById("cbid.aria2.main.rpc_user");
+ var auth_passwd = document.getElementById("cbid.aria2.main.rpc_passwd");
+ newTextNode.value = protocol + "://" + auth_user.value + ":" + auth_passwd.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
+ } else {
+ newTextNode.value = protocol + "://" + document.domain + ":" + auth_port_value + "/jsonrpc";
+ }
+};
+
+function openWebUI(path) {
+ var curWwwPath = window.document.location.href;
+ var pathName = window.document.location.pathname;
+ var pos = curWwwPath.indexOf(pathName);
+ var localhostPath = curWwwPath.substring(0, pos);
+ var url = "http:" + localhostPath.substring(window.location.protocol.length) + "/" + path;
+ window.open(url)
+};
+//]]>
+</script>
+<style>.mar-10 {margin-left: 10px; margin-right: 10px;}</style>
+<fieldset class="cbi-section">
+ <legend><%:Aria2 Status%></legend>
+ <p id="aria2_status">
+ <em><%:Collecting data...%></em>
+ </p>
+</fieldset>