diff options
Diffstat (limited to 'applications/luci-app-aria2/luasrc/view')
4 files changed, 193 insertions, 84 deletions
diff --git a/applications/luci-app-aria2/luasrc/view/aria2/log_template.htm b/applications/luci-app-aria2/luasrc/view/aria2/log_template.htm new file mode 100644 index 0000000000..ed91168dbc --- /dev/null +++ b/applications/luci-app-aria2/luasrc/view/aria2/log_template.htm @@ -0,0 +1,55 @@ +<%# + Copyright 2017-2019 Xingwang Liao <kuoruan@gmail.com> + Licensed to the public under the MIT License. +-%> + +<% css = [[ + + #log_text { + padding: 10px; + text-align: left; + } + #log_text pre { + word-break: break-all; + margin: 0; + } + .description { + background-color: #33ccff; + } + +]] +-%> + +<%+header%> + +<script type="text/javascript" src="<%=resource%>/cbi.js"></script> +<script type="text/javascript">//<![CDATA[ + XHR.poll(10, '<%=url("admin/services/aria2/log/read")%>', null, + function(x, data) { + var logElm = document.getElementById('log_text'); + if (logElm) { + logElm.innerHTML = data + ? String.format( + '<pre>%s%s%s%s</pre>', + '<span class="description"><%:Last 50 lines of log file:%></span><br/><br/>', + data.log || '<%:No log data.%>', + '<br/><br/><span class="description"><%:Last 50 lines of syslog:%></span><br/><br/>', + data.syslog || '<%:No log data.%>' + ) + : '<strong><%:Failed to load log data.%></strong>'; + } + } + ); +//]]></script> +<div class="cbi-map"> + <h2 name="content"><%:Aria2%> - <%:Log Data%></h2> + <fieldset class="cbi-section"> + <div id="log_text"> + <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> + <%:Collecting data...%> + </div> + <div style="text-align:right"><small><%:Refresh every 10 seconds.%></small></div> + </fieldset> +</div> + +<%+footer%> diff --git a/applications/luci-app-aria2/luasrc/view/aria2/overview_status.htm b/applications/luci-app-aria2/luasrc/view/aria2/overview_status.htm deleted file mode 100644 index 9d9ffeeac6..0000000000 --- a/applications/luci-app-aria2/luasrc/view/aria2/overview_status.htm +++ /dev/null @@ -1,84 +0,0 @@ -<script type="text/javascript">//<![CDATA[ -XHR.poll(-1, '<%=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\');" />'; - } - if (data.ariang) { - links += '<input class="cbi-button mar-10" type="button" value="<%:Open AriaNg%>" onclick="openWebUI(\'ariang\');" />'; - } - 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 (var 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"); - var auth_port_value; - if (window.location.protocol == "https:") { - protocol += "s"; - } - 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 = localhostPath + "/" + 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> diff --git a/applications/luci-app-aria2/luasrc/view/aria2/settings_header.htm b/applications/luci-app-aria2/luasrc/view/aria2/settings_header.htm new file mode 100644 index 0000000000..b71690fb69 --- /dev/null +++ b/applications/luci-app-aria2/luasrc/view/aria2/settings_header.htm @@ -0,0 +1,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> diff --git a/applications/luci-app-aria2/luasrc/view/aria2/value_with_btn.htm b/applications/luci-app-aria2/luasrc/view/aria2/value_with_btn.htm new file mode 100644 index 0000000000..487e107b6d --- /dev/null +++ b/applications/luci-app-aria2/luasrc/view/aria2/value_with_btn.htm @@ -0,0 +1,22 @@ +<%# + Copyright 2017-2019 Xingwang Liao <kuoruan@gmail.com> + Licensed to the public under the MIT License. +-%> + +<%+cbi/valueheader%> + <input data-update="change" type="text" class="cbi-input-text"<%= + attr("id", cbid) .. + attr("name", cbid) .. + attr("value", self:cfgvalue(section) or self.default) .. + ifattr(self.size, "size") .. + ifattr(self.placeholder, "placeholder") .. + ifattr(self.maxlength, "maxlength") .. + ifattr(self.datatype, "data-type", self.datatype) .. + ifattr(self.onmouseover, "onmouseover") + %> /> + <%- if self.btntext then -%> + <div class="cbi-button cbi-button-neutral" title="<%=self.btntext%>" aria-label="<%=self.btntext%>"<%= + ifattr(self.btnclick, "onclick", self.btnclick) + %>><span style="font-weight: normal;"><%=self.btntext%></span></div> + <% end %> +<%+cbi/valuefooter%> |