runtime.htm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <%#
  2. Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
  3. This is free software, licensed under the Apache License, Version 2.0
  4. -%>
  5. <%+adblock/adblock_css%>
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. function status_update(json)
  9. {
  10. var btn1 = document.getElementById("btn1");
  11. var btn1_running = document.getElementById("btn1_running");
  12. var btn2 = document.getElementById("btn2");
  13. var btn2_running = document.getElementById("btn2_running");
  14. var input = json.data.adblock_status || "-";
  15. document.getElementById("value_1").innerHTML = input;
  16. if (input === "enabled")
  17. {
  18. btn1.value = "<%:Suspend%>";
  19. btn1.name = "do_suspend";
  20. btn2.value = "<%:Refresh%>";
  21. btn2.name = "do_refresh";
  22. btn1.disabled = false;
  23. running(btn1_running, 0);
  24. btn2.disabled = false;
  25. running(btn2_running, 0);
  26. }
  27. else if (input === "paused")
  28. {
  29. btn1.value = "<%:Resume%>";
  30. btn1.name = "do_resume";
  31. btn2.value = "<%:Refresh%>";
  32. btn2.name = "do_refresh";
  33. btn1.disabled = false;
  34. running(btn1_running, 0);
  35. btn2.disabled = false;
  36. running(btn2_running, 0);
  37. }
  38. else
  39. {
  40. btn1.value = "<%:Suspend%>";
  41. btn1.name = "do_suspend";
  42. btn2.value = "<%:Refresh%>";
  43. btn2.name = "do_refresh";
  44. btn1.disabled = true;
  45. btn2.disabled = true;
  46. }
  47. document.getElementById("value_2").innerHTML = json.data.adblock_version || "-";
  48. document.getElementById("value_3").innerHTML = json.data.fetch_utility || "-";
  49. document.getElementById("value_4").innerHTML = json.data.dns_backend || "-";
  50. document.getElementById("value_5").innerHTML = json.data.overall_domains || "-";
  51. document.getElementById("value_6").innerHTML = json.data.last_rundate || "-";
  52. }
  53. function btn_action(action)
  54. {
  55. var btn1 = document.getElementById("btn1");
  56. var btn1_running = document.getElementById("btn1_running");
  57. var btn2 = document.getElementById("btn2");
  58. var btn2_running = document.getElementById("btn2_running");
  59. btn1.disabled = true;
  60. btn2.disabled = true;
  61. if (action.name === "do_refresh")
  62. {
  63. running(btn2_running, 1);
  64. }
  65. else
  66. {
  67. running(btn1_running, 1);
  68. }
  69. new XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock")%>/action/' + action.name, null,
  70. function(x)
  71. {
  72. if (!x)
  73. {
  74. return;
  75. }
  76. });
  77. }
  78. function running(element, state)
  79. {
  80. if (state === 1)
  81. {
  82. var running_html = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" />';
  83. element.innerHTML = running_html;
  84. }
  85. else
  86. {
  87. element.innerHTML = '';
  88. }
  89. }
  90. function reset_view()
  91. {
  92. document.getElementById("btn1").value = "<%:Suspend%>";
  93. document.getElementById("btn1").name = "do_suspend";
  94. document.getElementById("btn2").value = "<%:Refresh%>";
  95. document.getElementById("btn2").name = "do_refresh";
  96. document.getElementById("btn1").disabled = true;
  97. document.getElementById("btn2").disabled = true;
  98. document.getElementById("value_1").innerHTML = "-";
  99. document.getElementById("value_2").innerHTML = "-";
  100. document.getElementById("value_3").innerHTML = "-";
  101. document.getElementById("value_4").innerHTML = "-";
  102. document.getElementById("value_5").innerHTML = "-";
  103. document.getElementById("value_6").innerHTML = "-";
  104. }
  105. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock", "status")%>', null,
  106. function(x, json_info)
  107. {
  108. if (!x || !json_info || !json_info.data)
  109. {
  110. reset_view();
  111. return;
  112. }
  113. status_update(json_info);
  114. });
  115. XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "adblock", "status")%>', null,
  116. function(x, json_info)
  117. {
  118. if (!x || !json_info || !json_info.data)
  119. {
  120. reset_view();
  121. return;
  122. }
  123. status_update(json_info);
  124. });
  125. //]]>
  126. </script>
  127. <h3><%:Runtime Information%></h3>
  128. <div class="cbi-value" id="status_1">
  129. <label class="cbi-value-title" for="status_1"><%:Adblock Status%></label>
  130. <div class="cbi-value-field">
  131. <span class="runtime" id="value_1">-</span>
  132. </div>
  133. </div>
  134. <div class="cbi-value" id="status_2">
  135. <label class="cbi-value-title" for="status_2"><%:Adblock Version%></label>
  136. <div class="cbi-value-field">
  137. <span class="runtime" id="value_2">-</span>
  138. </div>
  139. </div>
  140. <div class="cbi-value" id="status_3">
  141. <label class="cbi-value-title" for="status_3"><%:Download Utility (SSL Library)%></label>
  142. <div class="cbi-value-field">
  143. <span class="runtime" id="value_3">-</span>
  144. </div>
  145. </div>
  146. <div class="cbi-value" id="status_4">
  147. <label class="cbi-value-title" for="status_4"><%:DNS Backend (DNS Directory)%></label>
  148. <div class="cbi-value-field">
  149. <span class="runtime" id="value_4">-</span>
  150. </div>
  151. </div>
  152. <div class="cbi-value" id="status_5">
  153. <label class="cbi-value-title" for="status_5"><%:Overall Domains%></label>
  154. <div class="cbi-value-field">
  155. <span class="runtime" id="value_5">-</span>
  156. </div>
  157. </div>
  158. <div class="cbi-value" id="status_6">
  159. <label class="cbi-value-title" for="status_6"><%:Last Run%></label>
  160. <div class="cbi-value-field">
  161. <span class="runtime" id="value_6">-</span>
  162. </div>
  163. </div>
  164. <hr />
  165. <div class="cbi-value" id="button_1">
  166. <label class="cbi-value-title" for="button_1"><%:Suspend / Resume Adblock%></label>
  167. <div class="cbi-value-field">
  168. <input class="cbi-button cbi-button-reset" id="btn1" type="button" value="" onclick="btn_action(this)" />
  169. <span id="btn1_running" class="btn_running"></span>
  170. </div>
  171. </div>
  172. <p />
  173. <div class="cbi-value" id="button_2">
  174. <label class="cbi-value-title" for="button_2"><%:Refresh Blocklist Sources%></label>
  175. <div class="cbi-value-field">
  176. <input class="cbi-button cbi-button-apply" id="btn2" type="button" value="" onclick="btn_action(this)" />
  177. <span id="btn2_running" class="btn_running"></span>
  178. </div>
  179. </div>