overview_status.htm 2.8 KB

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