summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-aria2/luasrc/view/aria2/overview_status.htm
blob: b14cca228f77a518e0921f5f2f5097305e9ff4b5 (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
<script type="text/javascript">//<![CDATA[
XHR.poll(5, '<%=luci.dispatcher.build_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>