Merge pull request #2307 from dibdot/ovpn
[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 if (data.ariang) {
15 links += '<input class="cbi-button mar-10" type="button" value="<%:Open AriaNg%>" onclick="openWebUI(\'ariang\');" />';
16 }
17 tb.innerHTML = links;
18 } else {
19 tb.innerHTML = '<em><%:The Aria2 service is not running.%></em>';
20 }
21 }
22 }
23 );
24
25 function randomString(len) {
26 len = len || 32;
27 var $chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
28 var maxPos = $chars.length;
29 var pwd = '';
30 for (var i = 0; i < len; i++) {
31 pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
32 }
33 return pwd;
34 };
35
36 function randomSecret() {
37 var Token = document.getElementById("cbid.aria2.main.rpc_secret");
38 Token.value = randomString(32);
39 };
40
41 function showRPCURL() {
42 var websocket = document.getElementById("use_websocket");
43 var protocol = (websocket.checked) ? "ws" : "http";
44 var newTextNode = document.getElementById("aria2rpcpath");
45 var auth_method = document.getElementById("cbid.aria2.main.rpc_auth_method");
46 var auth_port = document.getElementById("cbid.aria2.main.rpc_listen_port");
47 var auth_port_value;
48 if (auth_port.value == "") {
49 auth_port_value = "6800"
50 } else {
51 auth_port_value = auth_port.value
52 };
53 if (auth_method.value == "token") {
54 var auth_token = document.getElementById("cbid.aria2.main.rpc_secret");
55 newTextNode.value = protocol + "://token:" + auth_token.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
56 } else if (auth_method.value == "user_pass") {
57 var auth_user = document.getElementById("cbid.aria2.main.rpc_user");
58 var auth_passwd = document.getElementById("cbid.aria2.main.rpc_passwd");
59 newTextNode.value = protocol + "://" + auth_user.value + ":" + auth_passwd.value + "@" + document.domain + ":" + auth_port_value + "/jsonrpc";
60 } else {
61 newTextNode.value = protocol + "://" + document.domain + ":" + auth_port_value + "/jsonrpc";
62 }
63 };
64
65 function openWebUI(path) {
66 var curWwwPath = window.document.location.href;
67 var pathName = window.document.location.pathname;
68 var pos = curWwwPath.indexOf(pathName);
69 var localhostPath = curWwwPath.substring(0, pos);
70 var url = "http:" + localhostPath.substring(window.location.protocol.length) + "/" + path;
71 window.open(url)
72 };
73 //]]>
74 </script>
75 <style>.mar-10 {margin-left: 10px; margin-right: 10px;}</style>
76 <fieldset class="cbi-section">
77 <legend><%:Aria2 Status%></legend>
78 <p id="aria2_status">
79 <em><%:Collecting data...%></em>
80 </p>
81 </fieldset>