connlog.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Connection Log</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  10. <style>
  11. a.pageFocus {
  12. background: #222222;
  13. color: white !important;
  14. border-radius: 50%;
  15. -moz-border-radius: 50%;
  16. -webkit-border-radius: 50%;
  17. display: inline-block;
  18. font-weight: bold;
  19. line-height: 30px;
  20. margin-right: 2px;
  21. text-align: center;
  22. width: 30px;
  23. }
  24. .noselect {
  25. -webkit-touch-callout: none; /* iOS Safari */
  26. -webkit-user-select: none; /* Safari */
  27. -khtml-user-select: none; /* Konqueror HTML */
  28. -moz-user-select: none; /* Old versions of Firefox */
  29. -ms-user-select: none; /* Internet Explorer/Edge */
  30. user-select: none; /* Non-prefixed version, currently
  31. supported by Chrome, Edge, Opera and Firefox */
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="ui container" style="height: 100% !important;">
  37. <div>
  38. <p>Connection Attempts</p>
  39. <h1 class="ui header">
  40. <span id="normalStatus">Analysing</span>
  41. <div class="sub header">
  42. <span id="loginAptCount"></span> login request logged this month with <span id="incorrectRatio"></span> incorrect password attempts.
  43. </div>
  44. </h1>
  45. <div class="ui divider"></div>
  46. <div class="ui fluid selection dropdown">
  47. <input type="hidden" name="tablekey" onchange="loadRecords(this);">
  48. <i class="dropdown icon"></i>
  49. <div class="default text">Date</div>
  50. <div id="recordTables" class="menu">
  51. </div>
  52. </div>
  53. </div>
  54. <div class="ui divider"></div>
  55. <div>
  56. <table class="ui celled table">
  57. <thead>
  58. <tr>
  59. <th>Accepted</th>
  60. <th>Timestamp</th>
  61. <th>Requested Account</th>
  62. <th>IP Address</th>
  63. <th>Connection Type</th>
  64. <th>Access Port</th>
  65. </tr>
  66. </thead>
  67. <tbody id="records">
  68. </tbody>
  69. </table>
  70. <div style="width: 100%" align="center">
  71. <div class="ui breadcrumb" id="pageIndexs">
  72. </div>
  73. </div>
  74. </div>
  75. <br><br>
  76. </div>
  77. <script>
  78. var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  79. var maxPage = 0;
  80. var recordPerPage = 20;
  81. $(".ui.dropdown").dropdown();
  82. initMonthList();
  83. //Get the table that belongs to today. Put in offset if the current month not found in list
  84. function getCurrentMonthTable(monOffset = 0){
  85. const d = new Date();
  86. return monthNames[d.getMonth() - monOffset] + "-" + d.getFullYear()
  87. }
  88. //Get the month list
  89. function initMonthList(){
  90. $.ajax({
  91. url: "../../system/auth/logger/index",
  92. success: function(data){
  93. var currentMonthTable = getCurrentMonthTable();
  94. var currentMontHTableExists = false;
  95. if (data.error){
  96. alert(data.error);
  97. }else{
  98. $("#recordTables").html("");
  99. data.forEach(tableName => {
  100. if (tableName == currentMonthTable){
  101. currentMontHTableExists = true;
  102. }
  103. $("#recordTables").append(`<div class="item" data-value="${tableName}">${tableName}</div>`);
  104. });
  105. if (data.length == 0){
  106. //No record
  107. $("#normalStatus").parent().attr("class","ui header");
  108. $("#normalStatus").text("No Record");
  109. $("#incorrectRatio").text("0%");
  110. $("#loginAptCount").text("0");
  111. }
  112. }
  113. //Select the current month if it exists
  114. if (currentMontHTableExists){
  115. setTimeout(function(){
  116. $("#recordTables").parent().dropdown("set selected", getCurrentMonthTable());
  117. }, 500);
  118. loadRecordsByTableName(getCurrentMonthTable());
  119. }else{
  120. $("#normalStatus").text("No Record");
  121. }
  122. }
  123. });
  124. }
  125. function loadRecordsByTableName(tableName){
  126. $.ajax({
  127. url: "../../system/auth/logger/list",
  128. data: {record: tableName},
  129. success: function(data){
  130. $("#records").html("");
  131. $("#pageIndexs").html("");
  132. if (data.error !== undefined){
  133. $("#records").html(`<tr>
  134. <td data-label="status" colspan="5"><i class="remove icon"></i> ${data.error}</td>
  135. </tr>`);
  136. }else{
  137. if (data.length == 0){
  138. $("#records").html(`<tr>
  139. <td data-label="status" colspan="5"><i class="checkmark icon"></i> No login record in this time period.</td>
  140. </tr>`);
  141. }else{
  142. //console.log(data);
  143. //Reverse the array so the latest login on top
  144. var pageCounter = 1;
  145. var recordCounter = 0;
  146. var pageIndexs = [`<a class="active section pageLabel page1 noselect" onclick="showPage(1);">1</a>`];
  147. data.reverse();
  148. data.forEach(entry => {
  149. var timestamp = getDatetimeFromTimestamp(entry.Timestamp);
  150. var statusIcon = `<i class="green checkmark icon"></i>`;
  151. if (entry.LoginSucceed == false){
  152. statusIcon = `<i class="red remove icon"></i>`;
  153. }
  154. var authType = entry.AuthType;
  155. if (authType == ""){
  156. authType = "N/A"
  157. }else if (authType == "web"){
  158. authType = `<i class="blue globe icon"></i> Web Interface`
  159. }else if (authType == "ftp"){
  160. authType = `<i class="yellow folder icon"></i> FTP`
  161. }else if (authType == "webdav"){
  162. authType = `<i class="blue folder icon"></i> WebDAV`
  163. }
  164. $("#records").append(`<tr class="recordItem page${pageCounter}">
  165. <td data-label="status">${statusIcon}</td>
  166. <td data-label="timestamp">${timestamp}</td>
  167. <td data-label="acc">${entry.TargetUsername}</td>
  168. <td data-label="ip">${entry.IpAddr}</td>
  169. <td data-label="authtype">${authType}</td>
  170. <td data-label="port">${entry.Port}</td>
  171. </tr>`);
  172. recordCounter++;
  173. if (recordCounter % recordPerPage == 0){
  174. //Next page
  175. pageCounter++;
  176. pageIndexs.push(`<a class="section pageLabel page${pageCounter} noselect" onclick="showPage(${pageCounter});">${pageCounter}</a>`);
  177. }
  178. });
  179. $("#pageIndexs").html(pageIndexs.join(`<span class="divider">/</span>`));
  180. maxPage = pageCounter;
  181. updateSummaryText(data);
  182. showPage(1);
  183. }
  184. }
  185. }
  186. });
  187. }
  188. function showPage(pageNumber){
  189. if (pageNumber < 1){
  190. pageNumber = 1;
  191. }
  192. if (pageNumber > maxPage){
  193. pageNumber = maxPage;
  194. }
  195. $(".recordItem").hide();
  196. $(`.recordItem.page${pageNumber}`).show();
  197. $(".pageLabel.active").removeClass("active").removeClass("pageFocus");
  198. $(`.pageLabel.page${pageNumber}`).addClass("active").addClass("pageFocus");
  199. }
  200. function loadRecords(object){
  201. var tableName = object.value;
  202. loadRecordsByTableName(tableName);
  203. }
  204. function updateSummaryText(records){
  205. if (records.length == 0){
  206. $("#normalStatus").parent().attr("class","ui header");
  207. $("#normalStatus").text("No Record");
  208. $("#loginAptCount").text("No ");
  209. return;
  210. }
  211. var succ = 0;
  212. var failed = 0;
  213. //Calculate the risk ratio
  214. records.forEach(entry => {
  215. if (entry.LoginSucceed){
  216. succ++;
  217. }else{
  218. failed++;
  219. }
  220. });
  221. //Do a quick summary
  222. var failRatio = (failed) / (succ + failed) * 100;
  223. if (failRatio > 70){
  224. $("#normalStatus").parent().attr("class","ui red header");
  225. $("#normalStatus").text("HIGH RISK");
  226. }else if (failRatio > 50){
  227. $("#normalStatus").parent().attr("class","ui yellow header");
  228. $("#normalStatus").text("LOW RISK");
  229. }else{
  230. // No problem
  231. $("#normalStatus").parent().attr("class","ui green header");
  232. $("#normalStatus").text("Normal");
  233. }
  234. $("#incorrectRatio").text(failRatio.toFixed(1) + "%");
  235. $("#loginAptCount").text(succ + failed);
  236. }
  237. function getDatetimeFromTimestamp(timestamp){
  238. var s = new Date(timestamp * 1000);
  239. var localOption =Intl.DateTimeFormat().resolvedOptions()
  240. var options = { timeZone: 'UTC' };
  241. if (localOption != undefined && localOption.timeZone != undefined){
  242. options.timeZone = localOption.timeZone;
  243. }
  244. return s.toLocaleDateString(undefined,options) + " " + s.toLocaleTimeString(undefined,options);
  245. }
  246. </script>
  247. </body>
  248. </html>