connlog.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. setTimeout(function(){
  87. $("#recordTables").parent().dropdown("set selected", getCurrentMonthTable());
  88. }, 500);
  89. loadRecordsByTableName(getCurrentMonthTable());
  90. }
  91. }
  92. });
  93. }
  94. function loadRecordsByTableName(tableName){
  95. $.ajax({
  96. url: "../../system/auth/logger/list",
  97. data: {record: tableName},
  98. success: function(data){
  99. $("#records").html("");
  100. if (data.error !== undefined){
  101. $("#records").html(`<tr>
  102. <td data-label="status" colspan="5"><i class="remove icon"></i> ${data.error}</td>
  103. </tr>`);
  104. }else{
  105. if (data.length == 0){
  106. $("#records").html(`<tr>
  107. <td data-label="status" colspan="5"><i class="checkmark icon"></i> No login record in this time period.</td>
  108. </tr>`);
  109. }else{
  110. //console.log(data);
  111. //Reverse the array so the latest login on top
  112. data.reverse();
  113. data.forEach(entry => {
  114. var timestamp = getDatetimeFromTimestamp(entry.Timestamp);
  115. var statusIcon = `<i class="green checkmark icon"></i>`;
  116. if (entry.LoginSucceed == false){
  117. statusIcon = `<i class="red remove icon"></i>`;
  118. }
  119. $("#records").append(`<tr>
  120. <td data-label="status">${statusIcon}</td>
  121. <td data-label="timestamp">${timestamp}</td>
  122. <td data-label="acc">${entry.TargetUsername}</td>
  123. <td data-label="ip">${entry.IpAddr}</td>
  124. <td data-label="port">${entry.Port}</td>
  125. </tr>`);
  126. });
  127. updateSummaryText(data);
  128. }
  129. }
  130. }
  131. });
  132. }
  133. function loadRecords(object){
  134. var tableName = object.value;
  135. loadRecordsByTableName(tableName);
  136. }
  137. function updateSummaryText(records){
  138. if (records.length == 0){
  139. $("#normalStatus").parent().attr("class","ui header");
  140. $("#normalStatus").text("No Record");
  141. $("#loginAptCount").text("No ");
  142. return;
  143. }
  144. var succ = 0;
  145. var failed = 0;
  146. //Calculate the risk ratio
  147. records.forEach(entry => {
  148. if (entry.LoginSucceed){
  149. succ++;
  150. }else{
  151. failed++;
  152. }
  153. });
  154. //Do a quick summary
  155. var failRatio = (failed) / (succ + failed) * 100;
  156. if (failRatio > 70){
  157. $("#normalStatus").parent().attr("class","ui red header");
  158. $("#normalStatus").text("HIGH RISK");
  159. }else if (failRatio > 50){
  160. $("#normalStatus").parent().attr("class","ui yellow header");
  161. $("#normalStatus").text("LOW RISK");
  162. }else{
  163. // No problem
  164. $("#normalStatus").parent().attr("class","ui green header");
  165. $("#normalStatus").text("Normal");
  166. }
  167. $("#incorrectRatio").text(failRatio.toFixed(1) + "%");
  168. $("#loginAptCount").text(succ + failed);
  169. }
  170. function getDatetimeFromTimestamp(timestamp){
  171. var s = new Date(timestamp * 1000);
  172. var localOption =Intl.DateTimeFormat().resolvedOptions()
  173. var options = { timeZone: 'UTC' };
  174. if (localOption != undefined && localOption.timeZone != undefined){
  175. options.timeZone = localOption.timeZone;
  176. }
  177. return s.toLocaleDateString(undefined,options) + " " + s.toLocaleTimeString(undefined,options);
  178. }
  179. </script>
  180. </body>
  181. </html>