blob: 7e71e8e47840ab30614ef76077fd1018d689d3fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<%#
Copyright 2017-2019 Xingwang Liao <kuoruan@gmail.com>
Licensed to the public under the MIT License.
-%>
<%
local ipkg = require "luci.model.ipkg"
local has_ui = false
local uilist = {
supported = {
["ariang"] = "AriaNg",
["webui-aria2"] = "WebUI-Aria2",
["yaaw"] = "YAAW"
},
installed = {}
}
for k in pairs(uilist.supported) do
if ipkg.installed(k) then
uilist.installed[#uilist.installed + 1] = k
has_ui = true
end
end
%>
<fieldset class="cbi-section">
<p id="aria2_status">
<em><%:Collecting data...%></em>
</p>
<% if has_ui then %>
<p>
<%:Installed web interface: %>
<%- for _, v in pairs(uilist.installed) do %>
<input type="button" class="cbi-button" style="margin: 0 5px;" value="<%=uilist.supported[v]%>" onclick="openWebInterface('<%=v%>');" />
<%- end %>
</p>
<% end %>
</fieldset>
<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) {
tb.innerHTML = data.running
? '<%:The Aria2 service is running.%>'
: '<%:The Aria2 service is not running.%>';
}
}
);
function randomString(len) {
var randomStr = '';
var restLen = len;
while ((restLen = len - randomStr.length) > 0) {
randomStr += Math.random().toString(36).substring(2, 2 + restLen);
}
return randomStr;
}
function randomToken() {
var len = 32;
var inputLength = prompt('<%:Please input token length:%>', len);
if (inputLength === null || inputLength === '') {
return;
} else if (/^\d+$/.test(inputLength)) {
len = parseInt(inputLength);
}
var secretInput = document.getElementById('cbid.aria2.main.rpc_secret');
if (secretInput) {
secretInput.value = randomString(len);
}
};
function showRPCURL() {
var portElm = document.getElementById('cbid.aria2.main.rpc_listen_port');
var authMethodElm = document.getElementById('cbid.aria2.main.rpc_auth_method');
var useWSElm = document.getElementById('cbid.aria2.main._use_ws');
var secureElm = document.getElementById('cbid.aria2.main.rpc_secure');
var port = (portElm && /^\d+$/.test(portElm.value)) ? parseInt(portElm.value) : 6800;
var authMethod = (authMethodElm && authMethodElm.value) ? authMethodElm.value : "none";
var useWS = (useWSElm && useWSElm.checked) ? true : false;
var secure = (secureElm && secureElm.checked) ? true : false;
var protocol = useWS
? (secure ? 'wss' : 'ws')
: (secure ? 'https' : 'http');
var url = protocol + "://";
if (authMethod == 'token') {
var authToken = document.getElementById('cbid.aria2.main.rpc_secret').value;
url += 'token:' + authToken + '@';
} else if (authMethod == 'user_pass') {
var authUser = document.getElementById('cbid.aria2.main.rpc_user').value;
var authPasswd = document.getElementById('cbid.aria2.main.rpc_passwd').value;
url += authUser + ':' + authPasswd + '@';
}
url += window.location.hostname + ':' + port + '/jsonrpc';
var rpcUrlElm = document.getElementById('cbid.aria2.main._rpc_url');
if (rpcUrlElm) {
rpcUrlElm.value = url;
} else {
alert(url)
}
};
function openWebInterface(path) {
var host = window.location.host;
var protocol = window.location.protocol;
window.open(protocol + '//' + host + '/' + path);
};
//]]></script>
|