Issues (1369)

admin/adm_user_analyze.php (5 issues)

1
<?php
2
3
/**
4
 * adm_payment.php
5
 *
6
 * @version 1.0
7
 * @copyright 2013 by Gorlum for http://supernova.ws
8
*/
9
define('INSIDE', true);
10
define('INSTALL', false);
11
define('IN_ADMIN', true);
12
13
require('../common.' . substr(strrchr(__FILE__, '.'), 1));
14
15
global $lang, $user;
16
17
SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
18
19
// define('SESSION_INTERRUPT', 15*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
20
// define('SUSPICIOUS_LONG', 2 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим
21
22
define('SESSION_INTERRUPT', 1 * 60*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
23
define('SUSPICIOUS_LONG', 16 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим
24
25
26
function check_suspicious(&$session, &$session_list_last_id, &$row) {
27
  $session[2] = $session[1] - $session[0];
28
  if($session[2] > SUSPICIOUS_LONG)
29
  {
30
    $session[2] = pretty_time($session[2]);
31
    $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
32
    $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
33
    $session_list_last_id[] = $session;
34
  }
35
  //$row ?
36
  $session = array(
37
//    0 => $row['time'], // start
38
//    1 => $row['time'], // end
39
    0 => $row['visit_time'], // start
40
    1 => $row['visit_time'], // end
41
  )
42
   //: false
43
   ;
44
}
45
46
$session_list = array();
47
$query = doquery("SELECT `visit_time`, user_id FROM {{counter}} where user_id <> 0 and visit_time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY)) order by user_id, visit_time;");
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
$query = /** @scrutinizer ignore-deprecated */ doquery("SELECT `visit_time`, user_id FROM {{counter}} where user_id <> 0 and visit_time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY)) order by user_id, visit_time;");
Loading history...
48
$session = array();
49
if($row = db_fetch($query)) {
0 ignored issues
show
Deprecated Code introduced by
The function db_fetch() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
if($row = /** @scrutinizer ignore-deprecated */ db_fetch($query)) {
Loading history...
50
  $session = array(
51
    0 => strtotime($row['visit_time']), // start
52
    1 => strtotime($row['visit_time']), // end
53
  );
54
  $last_id = $row['user_id'];
55
}
56
while($row = db_fetch($query)) {
0 ignored issues
show
Deprecated Code introduced by
The function db_fetch() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
while($row = /** @scrutinizer ignore-deprecated */ db_fetch($query)) {
Loading history...
57
  $row['visit_time'] = strtotime($row['visit_time']);
58
  if($last_id == $row['user_id']) {
59
    // Тот же юзер
60
    if($row['visit_time'] - $session[1] <= SESSION_INTERRUPT) { // Та же сессия
61
      $session[1] = $row['visit_time'];
62
    } else {
63
      // Новая сессия
64
//      check_suspicious($session, $session_list[$last_id], $row);
65
      $session[2] = $session[1] - $session[0];
66
      if($session[2] > SUSPICIOUS_LONG)
67
      {
68
        $session[2] = pretty_time($session[2]);
69
        $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
70
        $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
71
        $session_list[$last_id][] = $session;
72
      }
73
      $session = array(
74
        0 => $row['visit_time'], // start
75
        1 => $row['visit_time'], // end
76
      );
77
    }
78
  } else {
79
//    check_suspicious($session, $session_list[$last_id], $row);
80
    $session[2] = $session[1] - $session[0];
81
      if($session[2] > SUSPICIOUS_LONG)
82
      {
83
        $session[2] = pretty_time($session[2]);
84
        $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
85
        $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
86
        $session_list[$last_id][] = $session;
87
      }
88
    $session = array(
89
      0 => $row['visit_time'], // start
90
      1 => $row['visit_time'], // end
91
    );
92
    $last_id = $row['user_id'];
93
  }
94
}
95
96
if($last_id) {
97
  // check_suspicious($session, $session_list[$last_id], $row = array('time' => 0));
98
  $session[2] = $session[1] - $session[0];
99
100
  if($session[2] > SUSPICIOUS_LONG)
101
  {
102
    $session[2] = pretty_time($session[2]);
103
    $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
104
    $session[1] = date(FMT_DATE_TIME_SQL, $session[1]);
105
    $session_list[$last_id][] = $session;
106
  }
107
}
108
109
print("<table border='1'>");
110
print("<tr>");
111
print("<td>ID</td><td>Username</td><td>Start</td><td>End</td><td>Length</td>");
112
print("<td>Last online</td>");
113
print("</tr>");
114
foreach($session_list as $user_id => $value) {
115
  $user_record = doquery("SELECT `username`, onlinetime FROM {{users}} WHERE id = {$user_id};", true);
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

115
  $user_record = /** @scrutinizer ignore-deprecated */ doquery("SELECT `username`, onlinetime FROM {{users}} WHERE id = {$user_id};", true);
Loading history...
true of type true is incompatible with the type string expected by parameter $table of doquery(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

115
  $user_record = doquery("SELECT `username`, onlinetime FROM {{users}} WHERE id = {$user_id};", /** @scrutinizer ignore-type */ true);
Loading history...
116
  foreach($value as $interval_data) {
117
    print("<tr>");
118
    print("<td>{$user_id}</td><td>{$user_record['username']}</td><td>{$interval_data[0]}</td><td>{$interval_data[1]}</td><td>{$interval_data[2]}</td>");
119
    print("<td>" . date(FMT_DATE_TIME_SQL, $user_record['onlinetime']) . "</td>");
120
    print("</tr>");
121
  }
122
}
123
print("</table>");
124