connlog.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. </style>
  12. </head>
  13. <body>
  14. <div class="ui container" style="height: 100% !important;">
  15. <div>
  16. <p>Connection Attempts</p>
  17. <h1 class="ui header">
  18. <span id="normalStatus">Analysising</span>
  19. <div class="sub header">
  20. <span id="loginAptCount"></span> login request logged this month with <span id="incorrectRatio"></span> incorrect password attempts.
  21. </div>
  22. </h1>
  23. <div class="ui divider"></div>
  24. <div class="ui fluid selection dropdown">
  25. <input type="hidden" name="tablekey" onchange="loadRecords(this);">
  26. <i class="dropdown icon"></i>
  27. <div class="default text">Date</div>
  28. <div id="recordTables" class="menu">
  29. </div>
  30. </div>
  31. </div>
  32. <div class="ui divider"></div>
  33. <div>
  34. <table class="ui celled table">
  35. <thead>
  36. <tr>
  37. <th>Accepted</th>
  38. <th>Timestamp</th>
  39. <th>Requested Account</th>
  40. <th>IP Address</th>
  41. <th>Access Port</th>
  42. </tr>
  43. </thead>
  44. <tbody id="records">
  45. </tbody>
  46. </table>
  47. </div>
  48. <br><br>
  49. </div>
  50. <script>
  51. var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  52. $(".ui.dropdown").dropdown();
  53. initMonthList();
  54. //Get the table that belongs to today. Put in offset if the current month not found in list
  55. function getCurrentMonthTable(monOffset = 0){
  56. const d = new Date();
  57. return monthNames[d.getMonth() - monOffset] + "-" + d.getFullYear()
  58. }
  59. //Get the month list
  60. function initMonthList(){
  61. $.ajax({
  62. url: "../../system/auth/logger/index",
  63. success: function(data){
  64. var currentMonthTable = getCurrentMonthTable();
  65. var currentMontHTableExists = false;
  66. if (data.error){
  67. alert(data.error);
  68. }else{
  69. $("#recordTables").html("");
  70. data.forEach(tableName => {
  71. if (tableName == currentMonthTable){
  72. currentMontHTableExists = true;
  73. }
  74. $("#recordTables").append(`<div class="item" data-value="${tableName}">${tableName}</div>`);
  75. });
  76. if (data.length == 0){
  77. //No record
  78. $("#normalStatus").parent().attr("class","ui header");
  79. $("#normalStatus").text("No Record");
  80. $("#incorrectRatio").text("0%");
  81. $("#loginAptCount").text("0");
  82. }
  83. }
  84. //Select the current month if it exists
  85. if (currentMontHTableExists){
  86. $("#recordTables").parent().dropdown("set selected", getCurrentMonthTable());
  87. loadRecordsByTableName(getCurrentMonthTable());
  88. }
  89. }
  90. });
  91. }
  92. function loadRecordsByTableName(tableName){
  93. $.ajax({
  94. url: "../../system/auth/logger/list",
  95. data: {record: tableName},
  96. success: function(data){
  97. $("#records").html("");
  98. if (data.error !== undefined){
  99. $("#records").html(`<tr>
  100. <td data-label="status" colspan="5"><i class="remove icon"></i> ${data.error}</td>
  101. </tr>`);
  102. }else{
  103. if (data.length == 0){
  104. $("#records").html(`<tr>
  105. <td data-label="status" colspan="5"><i class="checkmark icon"></i> No login record in this time period.</td>
  106. </tr>`);
  107. }else{
  108. //console.log(data);
  109. //Reverse the array so the latest login on top
  110. data.reverse();
  111. data.forEach(entry => {
  112. var timestamp = getDatetimeFromTimestamp(entry.Timestamp);
  113. var statusIcon = `<i class="green checkmark icon"></i>`;
  114. if (entry.LoginSucceed == false){
  115. statusIcon = `<i class="red remove icon"></i>`;
  116. }
  117. $("#records").append(`<tr>
  118. <td data-label="status">${statusIcon}</td>
  119. <td data-label="timestamp">${timestamp}</td>
  120. <td data-label="acc">${entry.TargetUsername}</td>
  121. <td data-label="ip">${entry.IpAddr}</td>
  122. <td data-label="port">${entry.Port}</td>
  123. </tr>`);
  124. });
  125. updateSummaryText(data);
  126. }
  127. }
  128. }
  129. });
  130. }
  131. function loadRecords(object){
  132. var tableName = object.value;
  133. loadRecordsByTableName(tableName);
  134. }
  135. function updateSummaryText(records){
  136. if (records.length == 0){
  137. $("#normalStatus").parent().attr("class","ui header");
  138. $("#normalStatus").text("No Record");
  139. $("#loginAptCount").text("No ");
  140. return;
  141. }
  142. var succ = 0;
  143. var failed = 0;
  144. //Calculate the risk ratio
  145. records.forEach(entry => {
  146. if (entry.LoginSucceed){
  147. succ++;
  148. }else{
  149. failed++;
  150. }
  151. });
  152. //Do a quick summary
  153. var failRatio = (failed) / (succ + failed) * 100;
  154. if (failRatio > 70){
  155. $("#normalStatus").parent().attr("class","ui red header");
  156. $("#normalStatus").text("HIGH RISK");
  157. }else if (failRatio > 50){
  158. $("#normalStatus").parent().attr("class","ui yellow header");
  159. $("#normalStatus").text("LOW RISK");
  160. }else{
  161. // No problem
  162. $("#normalStatus").parent().attr("class","ui green header");
  163. $("#normalStatus").text("Normal");
  164. }
  165. $("#incorrectRatio").text(failRatio.toFixed(1) + "%");
  166. $("#loginAptCount").text(succ + failed);
  167. }
  168. function getDatetimeFromTimestamp(timestamp){
  169. var s = new Date(timestamp * 1000);
  170. var localOption =Intl.DateTimeFormat().resolvedOptions()
  171. var options = { timeZone: 'UTC' };
  172. if (localOption != undefined && localOption.timeZone != undefined){
  173. options.timeZone = localOption.timeZone;
  174. }
  175. return s.toLocaleDateString(undefined,options) + " " + s.toLocaleTimeString(undefined,options);
  176. }
  177. </script>
  178. </body>
  179. </html>