connlog.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. }
  120. }
  121. });
  122. }
  123. function loadRecordsByTableName(tableName){
  124. $.ajax({
  125. url: "../../system/auth/logger/list",
  126. data: {record: tableName},
  127. success: function(data){
  128. $("#records").html("");
  129. $("#pageIndexs").html("");
  130. if (data.error !== undefined){
  131. $("#records").html(`<tr>
  132. <td data-label="status" colspan="5"><i class="remove icon"></i> ${data.error}</td>
  133. </tr>`);
  134. }else{
  135. if (data.length == 0){
  136. $("#records").html(`<tr>
  137. <td data-label="status" colspan="5"><i class="checkmark icon"></i> No login record in this time period.</td>
  138. </tr>`);
  139. }else{
  140. //console.log(data);
  141. //Reverse the array so the latest login on top
  142. var pageCounter = 1;
  143. var recordCounter = 0;
  144. var pageIndexs = [`<a class="active section pageLabel page1 noselect" onclick="showPage(1);">1</a>`];
  145. data.reverse();
  146. data.forEach(entry => {
  147. var timestamp = getDatetimeFromTimestamp(entry.Timestamp);
  148. var statusIcon = `<i class="green checkmark icon"></i>`;
  149. if (entry.LoginSucceed == false){
  150. statusIcon = `<i class="red remove icon"></i>`;
  151. }
  152. var authType = entry.AuthType;
  153. if (authType == ""){
  154. authType = "N/A"
  155. }else if (authType == "web"){
  156. authType = `<i class="blue globe icon"></i> Web Interface`
  157. }else if (authType == "ftp"){
  158. authType = `<i class="yellow folder icon"></i> FTP`
  159. }else if (authType == "webdav"){
  160. authType = `<i class="blue folder icon"></i> WebDAV`
  161. }
  162. $("#records").append(`<tr class="recordItem page${pageCounter}">
  163. <td data-label="status">${statusIcon}</td>
  164. <td data-label="timestamp">${timestamp}</td>
  165. <td data-label="acc">${entry.TargetUsername}</td>
  166. <td data-label="ip">${entry.IpAddr}</td>
  167. <td data-label="authtype">${authType}</td>
  168. <td data-label="port">${entry.Port}</td>
  169. </tr>`);
  170. recordCounter++;
  171. if (recordCounter % recordPerPage == 0){
  172. //Next page
  173. pageCounter++;
  174. pageIndexs.push(`<a class="section pageLabel page${pageCounter} noselect" onclick="showPage(${pageCounter});">${pageCounter}</a>`);
  175. }
  176. });
  177. $("#pageIndexs").html(pageIndexs.join(`<span class="divider">/</span>`));
  178. maxPage = pageCounter;
  179. updateSummaryText(data);
  180. showPage(1);
  181. }
  182. }
  183. }
  184. });
  185. }
  186. function showPage(pageNumber){
  187. if (pageNumber < 1){
  188. pageNumber = 1;
  189. }
  190. if (pageNumber > maxPage){
  191. pageNumber = maxPage;
  192. }
  193. $(".recordItem").hide();
  194. $(`.recordItem.page${pageNumber}`).show();
  195. $(".pageLabel.active").removeClass("active").removeClass("pageFocus");
  196. $(`.pageLabel.page${pageNumber}`).addClass("active").addClass("pageFocus");
  197. }
  198. function loadRecords(object){
  199. var tableName = object.value;
  200. loadRecordsByTableName(tableName);
  201. }
  202. function updateSummaryText(records){
  203. if (records.length == 0){
  204. $("#normalStatus").parent().attr("class","ui header");
  205. $("#normalStatus").text("No Record");
  206. $("#loginAptCount").text("No ");
  207. return;
  208. }
  209. var succ = 0;
  210. var failed = 0;
  211. //Calculate the risk ratio
  212. records.forEach(entry => {
  213. if (entry.LoginSucceed){
  214. succ++;
  215. }else{
  216. failed++;
  217. }
  218. });
  219. //Do a quick summary
  220. var failRatio = (failed) / (succ + failed) * 100;
  221. if (failRatio > 70){
  222. $("#normalStatus").parent().attr("class","ui red header");
  223. $("#normalStatus").text("HIGH RISK");
  224. }else if (failRatio > 50){
  225. $("#normalStatus").parent().attr("class","ui yellow header");
  226. $("#normalStatus").text("LOW RISK");
  227. }else{
  228. // No problem
  229. $("#normalStatus").parent().attr("class","ui green header");
  230. $("#normalStatus").text("Normal");
  231. }
  232. $("#incorrectRatio").text(failRatio.toFixed(1) + "%");
  233. $("#loginAptCount").text(succ + failed);
  234. }
  235. function getDatetimeFromTimestamp(timestamp){
  236. var s = new Date(timestamp * 1000);
  237. var localOption =Intl.DateTimeFormat().resolvedOptions()
  238. var options = { timeZone: 'UTC' };
  239. if (localOption != undefined && localOption.timeZone != undefined){
  240. options.timeZone = localOption.timeZone;
  241. }
  242. return s.toLocaleDateString(undefined,options) + " " + s.toLocaleTimeString(undefined,options);
  243. }
  244. </script>
  245. </body>
  246. </html>