logs.php
См. документацию.
1 <?php
2 
3 /**
4  * @file
5  * @brief страница админки с логами действий
6  */
7 
8 isset($user) or require $_SERVER['DOCUMENT_ROOT'] . '/page/404.php';
9 
10 ?>
11 
12 <div class="table-responsive p-2">
13  <table id="table-logs" class="table table-hover table-striped table-bordered table-sm small" style="width:100%">
14  <thead class="bg-info text-center">
15  <tr>
16  <th>ID</th>
17  <th>Пользователь</th>
18  <th>Запрос</th>
19  <th style="max-width:50%;">Данные</th>
20  <th>Время</th>
21  <th>IP</th>
22  </tr>
23  </thead>
24  </table>
25 </div>
26 
27 <script>
28  $(function() {
29  window.dataTablesConfigs[0].ajax = '<?= Wrong\Models\Selects::find(8)->request ?>';
30  window.dataTablesConfigs[0].initComplete = function() {
31  $('#table-logs_length label').append('<button class="btn btn-outline-primary btn-sm" data-action="clean-logs" data-confirm="true" data-body="Очистить лог?" data-callback="logsCleaned" style="font-size:12px;margin-left:7px;"><i class="fa fa-trash"></i> Очистить</button> <button id="toggle-show" class="btn btn-outline-primary btn-sm" style="font-size:12px;margin-left:7px;"><i class="fa fa-eye-slash"></i> <span>Показать</span></button><button class="btn btn-outline-primary btn-sm autoupdate" data-toggle="button" title="Автообновление таблицы" style="font-size:12px;margin-left:5px;"><i class="fa fa-play"></i></button><button class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#hide-table-cols" title="Видимость колонок таблицы <b>' + $('title').text() + '</b>" style="font-size:12px;margin-left:5px;"><i class="fa fa-table"></i></button>');
32 
33  window.autoupdate = window.localStorage.autoupdate ? JSON.parse(window.localStorage.autoupdate) : {};
34  if (window.autoupdate[location.pathname]) {
35  $('.autoupdate').trigger('click');
36  }
37  }
38  window.dataTablesConfigs[0].drawCallback = function(e) {
39  $(window).trigger('interaction');
40  }
41  window.dataTablesConfigs[0].order = [
42  [4, 'desc']
43  ];
44  $('#table-logs').DataTable(window.dataTablesConfigs[0]);
45 
46  $(document).on('click', '#toggle-show', function() {
47  $(this).find('i').toggleClass('fa-eye fa-eye-slash');
48  $(window).trigger('interaction');
49  if ($('#toggle-show').find('i').is('.fa-eye')) {
50  $('.log-show').removeClass('show');
51  }
52  });
53  });
54 
55  $(window).on("interaction", function() {
56  $('.log-show').not('.show').removeAttr('style');
57  if ($('#toggle-show').find('i').is('.fa-eye')) {
58  $('#toggle-show').find('span').html('Скрыть');
59  $('.log-show').not('.show').css({
60  margin: '0',
61  maxWidth: '850px'
62  });
63  } else {
64  $('#toggle-show').find('span').html('Показать');
65  $('.log-show').not('.show').css({
66  margin: '0',
67  display: '-webkit-box',
68  WebkitLineClamp: '1',
69  WebkitBoxOrient: 'vertical',
70  overflow: 'hidden',
71  textOverflow: 'ellipsis',
72  whiteSpace: 'normal',
73  maxWidth: '850px'
74  });
75  }
76  $('.log-show').each((i, el) => {
77  if ($(el).text().match(/"error"/) || $(el).text().match(/404 Not Found/)) {
78  $(el).addClass('bg-danger text-white');
79  $(el).parents('tr').addClass('bg-danger text-white');
80  }
81  });
82  });
83 
84  $(document).on('click', '#table-logs tbody tr', function() {
85  $(this).find('.log-show').removeAttr('style');
86  if ($(this).find('.log-show').is('.show')) {
87  $(this).find('.log-show').css({
88  margin: '0',
89  display: '-webkit-box',
90  WebkitLineClamp: '1',
91  WebkitBoxOrient: 'vertical',
92  overflow: 'hidden',
93  textOverflow: 'ellipsis',
94  whiteSpace: 'normal',
95  maxWidth: '850px'
96  });
97  } else {
98  $(this).find('.log-show').css({
99  margin: '0',
100  maxWidth: '850px'
101  });
102  }
103  $(this).find('.log-show').toggleClass('show');
104  });
105 
106  function logsCleaned(response) {
107  if (response.error) {
108  errorToast(response.error);
109  return;
110  }
111  successToast(response.message);
112  $('.dataTable').DataTable().ajax.reload(null, false);
113  }
114 
115  $(document).on('click', '.autoupdate', function() {
116  $(this).find('.fa').toggleClass(['fa-play', 'fa-stop']);
117  window.autoupdate[location.pathname] = $('.autoupdate').is('.active');
118  window.localStorage.autoupdate = JSON.stringify(window.autoupdate);
119  });
120 
121  setInterval(() => {
122  $('.autoupdate').is('.active') && $('.dataTable').DataTable().ajax.reload(null, false);
123  }, 5000);
124 </script>
$user
Definition: from-user.php:38
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
Definition: from-user.php:36