Merge pull request #656 from nlhintz/pull-request
[project/luci.git] / applications / luci-app-aria2 / luasrc / view / aria2 / overview_status.htm
1 <script type="text/javascript">//<![CDATA[
2 XHR.poll(5, '<%=luci.dispatcher.build_url("admin/services/aria2/status")%>', null,
3 function(x, data) {
4 var tb = document.getElementById('aria2_status');
5 if (data && tb) {
6 if (data.running) {
7 var links = '<em><%:The Aria2 service is running.%></em>';
8 if (data.yaaw) {
9 links += '<input class="cbi-button mar-10" type="button" value="<%:Open YAAW%>" onclick="openWebUI(\'yaaw\');" />';
10 }
11 if (data.webui) {
12 links += '<input class="cbi-button mar-10" type="button" value="<%:Open WebUI-Aria2%>" onclick="openWebUI(\'webui-aria2\');" />';
13 }
14 tb.innerHTML = links;
15 } else {
16 tb.innerHTML = '<em><%:The Aria2 service is not running.%></em>';
17 }
18 }
19 }
20 );
21
22 function randomString(len) {
23 len = len || 32;
24 var $chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
25 var maxPos = $chars.length;
26 var pwd = '';
27 for (i = 0; i < len; i++) {
28 pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
29 }
30 return pwd;
31 };
32
33 function randomSecret() {
34 var Token = document.getElementById("cbid.aria2.main.rpc_secret");
35 Token.value = randomString(32);
36 };
37
38 function showRPCURL() {
39 var websocket = document.getElementById("use_websocket");
40 var protocol = (websocket.checked) ? "ws" : "http";
41 var newTextNode = document.getElementById("aria2rpcpath");
42 var auth_method = document.getElementById("cbid.aria2.main.rpc_auth_method");
43 var auth_port = document.getElementById("cbid.aria2.main.rpc_listen_port");
44 if (auth_port.value == "") {
45 auth_port_value = "6800"
46 } else {
47 auth_port_value = auth_port.value
48 };
49 if (auth_method.value == "token") {
50 var auth_token = document.getElementById("cbid.aria2.main.rpc_secret");
51 newTextNode.value = protocol + "://token:" + auth_token.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
52 } else if (auth_method.value == "user_pass") {
53 var auth_user = document.getElementById("cbid.aria2.main.rpc_user");
54 var auth_passwd = document.getElementById("cbid.aria2.main.rpc_passwd");
55 newTextNode.value = protocol + "://" + auth_user.value + ":" + auth_passwd.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
56 } else {
57 newTextNode.value = protocol + "://" + document.domain + ":" + auth_port_value + "/jsonrpc";
58 }
59 };
60
61 function openWebUI(path) {
62 var curWwwPath = window.document.location.href;
63 var pathName = window.document.location.pathname;
64 var pos = curWwwPath.indexOf(pathName);
65 var localhostPath = curWwwPath.substring(0, pos);
66 var url = "http:" + localhostPath.substring(window.location.protocol.length) + "/" + path;
67 window.open(url)
68 };
69 //]]>
70 </script>
71 <style>.mar-10 {margin-left: 10px; margin-right: 10px;}</style>
72 <fieldset class="cbi-section">
73 <legend><%:Aria2 Status%></legend>
74 <p id="aria2_status">
75 <em><%:Collecting data...%></em>
76 </p>
77 </fieldset>