report.htm 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. <%+header%>
  6. <%+adblock/adblock_css%>
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. function report_json(json)
  10. {
  11. document.getElementById("value_1").innerHTML = json.data.start_date + ", " + json.data.start_time || "-";
  12. document.getElementById("value_2").innerHTML = json.data.end_date + ", " + json.data.end_time || "-";
  13. document.getElementById("value_3").innerHTML = json.data.total || "-";
  14. document.getElementById("value_4").innerHTML = json.data.blocked + " (" + json.data.percent + ")" || "-";
  15. var a_cnt;
  16. var b_cnt;
  17. var c_cnt;
  18. var a_val;
  19. var b_val;
  20. var c_val;
  21. var s = '<div class="tr table-titles">';
  22. s += '<div class="th left"><%:Count%></div>';
  23. s += '<div class="th left"><%:Name / IP-Address%></div>';
  24. s += '<div class="th left"><%:Count%></div>';
  25. s += '<div class="th left"><%:Domain%></div>';
  26. s += '<div class="th left"><%:Count%></div>';
  27. s += '<div class="th left"><%:Blocked Domain%></div></div>';
  28. for(var i=0;i<10;i++)
  29. {
  30. if (i < json.top_clients.length)
  31. {
  32. a_cnt = json.top_clients[i].count;
  33. a_val = json.top_clients[i].address;
  34. }
  35. else
  36. {
  37. a_cnt = "-";
  38. a_val = "";
  39. }
  40. if (i < json.top_domains.length)
  41. {
  42. b_cnt = json.top_domains[i].count;
  43. b_val = json.top_domains[i].address;
  44. }
  45. else
  46. {
  47. b_cnt = "-";
  48. b_val = "";
  49. }
  50. if (i < json.top_blocked.length)
  51. {
  52. c_cnt = json.top_blocked[i].count;
  53. c_val = json.top_blocked[i].address;
  54. }
  55. else
  56. {
  57. c_cnt = "-";
  58. c_val = "";
  59. }
  60. s += '<div class="tr left">';
  61. s += '<div class="td left" data-title="<%:Count%>">' + a_cnt + '</div>';
  62. s += '<div class="td left" data-title="<%:Name / IP-Address%>">' + a_val + '</div>';
  63. s += '<div class="td left" data-title="<%:Count%>">' + b_cnt + '</div>';
  64. s += '<div class="td left" data-title="<%:Domain%>">' + b_val + '</div>';
  65. s += '<div class="td left" data-title="<%:Count%>">' + c_cnt + '</div>';
  66. s += '<div class="td left" data-title="<%:Blocked Domain%>">' + c_val + '</div></div>';
  67. }
  68. document.getElementById("value_5").innerHTML = s;
  69. }
  70. function report_text(text)
  71. {
  72. var s = '<div class="tr table-titles">';
  73. s += '<div class="th left"><%:Date%></div>';
  74. s += '<div class="th left"><%:Time%></div>';
  75. s += '<div class="th left"><%:Client%></div>';
  76. s += '<div class="th left"><%:Domain%></div>';
  77. s += '<div class="th left"><%:Answer%></div>';
  78. s += '<div class="th left"><%:Action%></div></div>';
  79. var btn1;
  80. var record;
  81. var title_arr = ["<%:Date%>", "<%:Time%>", "<%:Client%>", "<%:Domain%>", "<%:Answer%>", "<%:Action%>"];
  82. var array = text.split("\n");
  83. for (var i=0;i<array.length;i++)
  84. {
  85. record = array[i].split("\t");
  86. if (record[0] && record[0] != "undefined")
  87. {
  88. s += '<div class="tr left">';
  89. for (var j=0;j<5;j++)
  90. {
  91. s += '<div class="td left" data-title="' + title_arr[j] + '">' + record[j] + '</div>';
  92. if (record[4] === "NX")
  93. {
  94. btn1 = '<div class="td left" data-title="' + title_arr[5] + '"><input type="button" class="cbi-button cbi-button-edit" name="add_whitelist,' + record[3] + '" value="<%:Whitelist%>" onclick="btn_action(this)" /></div>';
  95. }
  96. else if (record[4] === "OK")
  97. {
  98. btn1 = '<div class="td left" data-title="' + title_arr[5] + '"><input type="button" class="cbi-button cbi-button-remove" name="add_blacklist,' + record[3] + '" value="<%:Blacklist%>" onclick="btn_action(this)" /></div>';
  99. }
  100. else
  101. {
  102. btn1 = '-'
  103. }
  104. }
  105. s += btn1 + '</div>'
  106. }
  107. }
  108. document.getElementById("value_6").innerHTML = s;
  109. }
  110. function btn_action(value)
  111. {
  112. var action = value.name.split(",");
  113. if (action[0] === "do_report")
  114. {
  115. var btn1 = document.getElementById("btn1");
  116. var btn1_running = document.getElementById("btn1_running");
  117. btn1.disabled = true;
  118. running(btn1_running, 1);
  119. document.getElementById("filter_search").value = '';
  120. document.getElementById("filter_count").selectedIndex = 1;
  121. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock")%>/action/' + action[0], null,
  122. function(x)
  123. {
  124. if (!x)
  125. {
  126. return;
  127. }
  128. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock", "report_json")%>', null,
  129. function(x, json_info)
  130. {
  131. if (!x || !json_info || !json_info.data)
  132. {
  133. running(btn1_running, 0);
  134. btn1.disabled = false;
  135. return;
  136. }
  137. report_json(json_info);
  138. });
  139. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock", "report_text")%>', null,
  140. function(x)
  141. {
  142. if (!x || !x.responseText)
  143. {
  144. return;
  145. }
  146. report_text(x.responseText);
  147. running(btn1_running, 0);
  148. btn1.disabled = false;
  149. });
  150. });
  151. }
  152. else if (action[0] === "do_filter")
  153. {
  154. var btn2 = document.getElementById("btn2");
  155. var btn2_running = document.getElementById("btn2_running");
  156. var search = document.getElementById("filter_search").value.replace(/[^\x00-\x7F]|[\s!@#$%^&*()+=\[\]{};'"\\|,<>\/?]/g,'') || "\"+\"";
  157. var count = document.getElementById("filter_count").value;
  158. btn2.disabled = true;
  159. running(btn2_running, 1);
  160. if (search != "\"+\"")
  161. {
  162. document.getElementById("filter_search").value = search;
  163. }
  164. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock")%>/action/' + action[0] + "/" + "-" + "/" + search + "/" + count + "/" + "true" + "/" + "false", null,
  165. function(x)
  166. {
  167. if (!x)
  168. {
  169. return;
  170. }
  171. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock", "report_text")%>', null,
  172. function(x)
  173. {
  174. if (!x || !x.responseText)
  175. {
  176. return;
  177. }
  178. report_text(x.responseText);
  179. running(btn2_running, 0);
  180. btn2.disabled = false;
  181. });
  182. });
  183. }
  184. else if (action[0] === "add_blacklist" || action[0] === "add_whitelist")
  185. {
  186. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock")%>/action/' + action[0] + "/" + action[1], null,
  187. function(x)
  188. {
  189. if (!x)
  190. {
  191. return;
  192. }
  193. btn3 = document.getElementsByName(value.name);
  194. for (var i=0; i<btn3.length; i++)
  195. {
  196. btn3[i].disabled = true;
  197. }
  198. });
  199. }
  200. }
  201. function running(element, state)
  202. {
  203. if (state === 1)
  204. {
  205. var running_html = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" />';
  206. element.innerHTML = running_html;
  207. }
  208. else
  209. {
  210. element.innerHTML = '';
  211. }
  212. }
  213. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock", "report_json")%>', null,
  214. function(x, json_info)
  215. {
  216. if (!x || !json_info || !json_info.data)
  217. {
  218. running(btn1_running, 0);
  219. btn1.disabled = false;
  220. return;
  221. }
  222. report_json(json_info);
  223. });
  224. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "adblock", "report_text")%>', null,
  225. function(x)
  226. {
  227. if (!x || !x.responseText)
  228. {
  229. return;
  230. }
  231. report_text(x.responseText);
  232. });
  233. //]]>
  234. </script>
  235. <div class="cbi-section">
  236. <div class="cbi-value" id="status_1">
  237. <label class="cbi-value-title" for="status_1"><%:Start Date%></label>
  238. <div class="cbi-value-field">
  239. <span class="runtime" id="value_1">-</span>
  240. </div>
  241. </div>
  242. <div class="cbi-value" id="status_2">
  243. <label class="cbi-value-title" for="status_2"><%:End Date%></label>
  244. <div class="cbi-value-field">
  245. <span class="runtime" id="value_2">-</span>
  246. </div>
  247. </div>
  248. <div class="cbi-value" id="status_3">
  249. <label class="cbi-value-title" for="status_3"><%:Total DNS Queries%></label>
  250. <div class="cbi-value-field">
  251. <span class="runtime" id="value_3">-</span>
  252. </div>
  253. </div>
  254. <div class="cbi-value" id="status_4">
  255. <label class="cbi-value-title" for="status_4"><%:Blocked DNS Queries%></label>
  256. <div class="cbi-value-field">
  257. <span class="runtime" id="value_4">-</span>
  258. </div>
  259. </div>
  260. <br />
  261. <div id="button">
  262. <input type="button" class="cbi-button cbi-button-action important" id="btn1" name="do_report" value="<%:Refresh Report%>" onclick="btn_action(this)" />
  263. <span id="btn1_running" class="btn1_running"></span>
  264. </div>
  265. </div>
  266. <br />
  267. <div class="cbi-section">
  268. <h3><%:Top 10 Reporting%></h3>
  269. <div class="table" id="value_5"></div>
  270. </div>
  271. <hr />
  272. <div class="cbi-section">
  273. <div class="cbi-section-descr"><%:Filter the DNS Query result set for a particular domain, client or time frame.%></div>
  274. <div style="float:left;">
  275. <input type="text" placeholder="<%:Domain/Client/Date/Time%>" id="filter_search" name="filter_search" />
  276. <select name="filter_count" id="filter_count">
  277. <option value="25">25</option>
  278. <option value="50" selected="selected">50</option>
  279. <option value="100">100</option>
  280. <option value="250">250</option>
  281. <option value="500">500</option>
  282. </select>
  283. <input type="button" class="cbi-button cbi-button-action" id="btn2" name="do_filter" value="<%:Filter%>" onclick="btn_action(this)" />
  284. <span id="btn2_running" class="btn2_running"></span>
  285. </div>
  286. <br />
  287. <br />
  288. <h3><%:Latest DNS Queries%></h3>
  289. <div class="table" id="value_6"></div>
  290. </div>
  291. <%+footer%>