connlog.html 7.4 KB

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