runtime.htm 6.4 KB

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