Add missing variable declarations in JavaScript code
[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 (var 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 var auth_port_value;
45 if (auth_port.value == "") {
46 auth_port_value = "6800"
47 } else {
48 auth_port_value = auth_port.value
49 };
50 if (auth_method.value == "token") {
51 var auth_token = document.getElementById("cbid.aria2.main.rpc_secret");
52 newTextNode.value = protocol + "://token:" + auth_token.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
53 } else if (auth_method.value == "user_pass") {
54 var auth_user = document.getElementById("cbid.aria2.main.rpc_user");
55 var auth_passwd = document.getElementById("cbid.aria2.main.rpc_passwd");
56 newTextNode.value = protocol + "://" + auth_user.value + ":" + auth_passwd.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
57 } else {
58 newTextNode.value = protocol + "://" + document.domain + ":" + auth_port_value + "/jsonrpc";
59 }
60 };
61
62 function openWebUI(path) {
63 var curWwwPath = window.document.location.href;
64 var pathName = window.document.location.pathname;
65 var pos = curWwwPath.indexOf(pathName);
66 var localhostPath = curWwwPath.substring(0, pos);
67 var url = "http:" + localhostPath.substring(window.location.protocol.length) + "/" + path;
68 window.open(url)
69 };
70 //]]>
71 </script>
72 <style>.mar-10 {margin-left: 10px; margin-right: 10px;}</style>
73 <fieldset class="cbi-section">
74 <legend><%:Aria2 Status%></legend>
75 <p id="aria2_status">
76 <em><%:Collecting data...%></em>
77 </p>
78 </fieldset>