|
@@ -1,174 +1,190 @@
|
1
|
|
-<?
|
2
|
|
-class Tools {
|
3
|
|
- /**
|
4
|
|
- * Returns true if given IP is banned.
|
5
|
|
- *
|
6
|
|
- * @param string $IP
|
7
|
|
- */
|
8
|
|
- public static function site_ban_ip($IP) {
|
9
|
|
- global $Debug;
|
10
|
|
- $A = substr($IP, 0, strcspn($IP, '.:'));
|
11
|
|
- $IPNum = Tools::ip_to_unsigned($IP);
|
12
|
|
- $IPBans = G::$Cache->get_value('ip_bans_'.$A);
|
13
|
|
- if (!is_array($IPBans)) {
|
14
|
|
- $SQL = sprintf("
|
|
1
|
+<?php
|
|
2
|
+class Tools
|
|
3
|
+{
|
|
4
|
+ /**
|
|
5
|
+ * Returns true if given IP is banned.
|
|
6
|
+ *
|
|
7
|
+ * @param string $IP
|
|
8
|
+ */
|
|
9
|
+ public static function site_ban_ip($IP)
|
|
10
|
+ {
|
|
11
|
+ global $Debug;
|
|
12
|
+ $A = substr($IP, 0, strcspn($IP, '.:'));
|
|
13
|
+ $IPNum = Tools::ip_to_unsigned($IP);
|
|
14
|
+ $IPBans = G::$Cache->get_value('ip_bans_'.$A);
|
|
15
|
+ if (!is_array($IPBans)) {
|
|
16
|
+ $SQL = sprintf("
|
15
|
17
|
SELECT ID, FromIP, ToIP
|
16
|
18
|
FROM ip_bans
|
17
|
19
|
WHERE FromIP BETWEEN %d << 24 AND (%d << 24) - 1", $A, $A + 1);
|
18
|
|
- $QueryID = G::$DB->get_query_id();
|
19
|
|
- G::$DB->query($SQL);
|
20
|
|
- $IPBans = G::$DB->to_array(0, MYSQLI_NUM);
|
21
|
|
- G::$DB->set_query_id($QueryID);
|
22
|
|
- G::$Cache->cache_value('ip_bans_'.$A, $IPBans, 0);
|
23
|
|
- }
|
24
|
|
- $Debug->log_var($IPBans, 'IP bans for class '.$A);
|
25
|
|
- foreach ($IPBans as $Index => $IPBan) {
|
26
|
|
- list ($ID, $FromIP, $ToIP) = $IPBan;
|
27
|
|
- if ($IPNum >= $FromIP && $IPNum <= $ToIP) {
|
28
|
|
- return true;
|
29
|
|
- }
|
30
|
|
- }
|
31
|
|
-
|
32
|
|
- return false;
|
33
|
|
- }
|
|
20
|
+ $QueryID = G::$DB->get_query_id();
|
|
21
|
+ G::$DB->query($SQL);
|
|
22
|
+ $IPBans = G::$DB->to_array(0, MYSQLI_NUM);
|
|
23
|
+ G::$DB->set_query_id($QueryID);
|
|
24
|
+ G::$Cache->cache_value('ip_bans_'.$A, $IPBans, 0);
|
|
25
|
+ }
|
|
26
|
+ $Debug->log_var($IPBans, 'IP bans for class '.$A);
|
|
27
|
+ foreach ($IPBans as $Index => $IPBan) {
|
|
28
|
+ list($ID, $FromIP, $ToIP) = $IPBan;
|
|
29
|
+ if ($IPNum >= $FromIP && $IPNum <= $ToIP) {
|
|
30
|
+ return true;
|
|
31
|
+ }
|
|
32
|
+ }
|
34
|
33
|
|
35
|
|
- /**
|
36
|
|
- * Returns the unsigned form of an IP address.
|
37
|
|
- *
|
38
|
|
- * @param string $IP The IP address x.x.x.x
|
39
|
|
- * @return string the long it represents.
|
40
|
|
- */
|
41
|
|
- public static function ip_to_unsigned($IP) {
|
42
|
|
- $IPnum = sprintf('%u', ip2long($IP));
|
43
|
|
- if (!$IPnum) {
|
44
|
|
- // Try to encode as IPv6 (stolen from stackoverflow)
|
45
|
|
- // Note that this is *wrong* and because of PHP's wankery stops being accurate after the most significant 16 digits or so
|
46
|
|
- // But since this is only used for geolocation and IPv6 blocks are allocated in huge numbers, it's still fine
|
47
|
|
- $IPnum = '';
|
48
|
|
- foreach (unpack('C*', inet_pton($IP)) as $byte) {
|
49
|
|
- $IPnum .= str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
|
50
|
|
- }
|
51
|
|
- $IPnum = base_convert(ltrim($IPnum, '0'), 2, 10);
|
|
34
|
+ return false;
|
52
|
35
|
}
|
53
|
|
- return $IPnum;
|
54
|
|
- }
|
55
|
36
|
|
56
|
|
- /**
|
57
|
|
- * Geolocate an IP address using the database
|
58
|
|
- *
|
59
|
|
- * @param $IP the ip to fetch the country for
|
60
|
|
- * @return the country of origin
|
61
|
|
- */
|
62
|
|
- public static function geoip($IP) {
|
63
|
|
- static $IPs = [];
|
64
|
|
- if (isset($IPs[$IP])) {
|
65
|
|
- return $IPs[$IP];
|
66
|
|
- }
|
67
|
|
- if (is_number($IP)) {
|
68
|
|
- $Long = $IP;
|
69
|
|
- } else {
|
70
|
|
- $Long = Tools::ip_to_unsigned($IP);
|
71
|
|
- }
|
72
|
|
- if (!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
|
73
|
|
- return false;
|
|
37
|
+ /**
|
|
38
|
+ * Returns the unsigned form of an IP address.
|
|
39
|
+ *
|
|
40
|
+ * @param string $IP The IP address x.x.x.x
|
|
41
|
+ * @return string the long it represents.
|
|
42
|
+ */
|
|
43
|
+ public static function ip_to_unsigned($IP)
|
|
44
|
+ {
|
|
45
|
+ $IPnum = sprintf('%u', ip2long($IP));
|
|
46
|
+ if (!$IPnum) {
|
|
47
|
+ // Try to encode as IPv6 (stolen from stackoverflow)
|
|
48
|
+ // Note that this is *wrong* and because of PHP's wankery stops being accurate after the most significant 16 digits or so
|
|
49
|
+ // But since this is only used for geolocation and IPv6 blocks are allocated in huge numbers, it's still fine
|
|
50
|
+ $IPnum = '';
|
|
51
|
+ foreach (unpack('C*', inet_pton($IP)) as $byte) {
|
|
52
|
+ $IPnum .= str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
|
|
53
|
+ }
|
|
54
|
+ $IPnum = base_convert(ltrim($IPnum, '0'), 2, 10);
|
|
55
|
+ }
|
|
56
|
+ return $IPnum;
|
74
|
57
|
}
|
75
|
|
- $QueryID = G::$DB->get_query_id();
|
76
|
|
- G::$DB->query("
|
|
58
|
+
|
|
59
|
+ /**
|
|
60
|
+ * Geolocate an IP address using the database
|
|
61
|
+ *
|
|
62
|
+ * @param $IP the ip to fetch the country for
|
|
63
|
+ * @return the country of origin
|
|
64
|
+ */
|
|
65
|
+ public static function geoip($IP)
|
|
66
|
+ {
|
|
67
|
+ static $IPs = [];
|
|
68
|
+ if (isset($IPs[$IP])) {
|
|
69
|
+ return $IPs[$IP];
|
|
70
|
+ }
|
|
71
|
+ if (is_number($IP)) {
|
|
72
|
+ $Long = $IP;
|
|
73
|
+ } else {
|
|
74
|
+ $Long = Tools::ip_to_unsigned($IP);
|
|
75
|
+ }
|
|
76
|
+ if (!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
|
|
77
|
+ return false;
|
|
78
|
+ }
|
|
79
|
+ $QueryID = G::$DB->get_query_id();
|
|
80
|
+ G::$DB->query("
|
77
|
81
|
SELECT EndIP, Code
|
78
|
82
|
FROM geoip_country
|
79
|
83
|
WHERE $Long >= StartIP
|
80
|
84
|
ORDER BY StartIP DESC
|
81
|
85
|
LIMIT 1");
|
82
|
|
- if ((!list($EndIP, $Country) = G::$DB->next_record()) || $EndIP < $Long) {
|
83
|
|
- $Country = '?';
|
|
86
|
+ if ((!list($EndIP, $Country) = G::$DB->next_record()) || $EndIP < $Long) {
|
|
87
|
+ $Country = '?';
|
|
88
|
+ }
|
|
89
|
+ G::$DB->set_query_id($QueryID);
|
|
90
|
+ $IPs[$IP] = $Country;
|
|
91
|
+ return $Country;
|
84
|
92
|
}
|
85
|
|
- G::$DB->set_query_id($QueryID);
|
86
|
|
- $IPs[$IP] = $Country;
|
87
|
|
- return $Country;
|
88
|
|
- }
|
89
|
93
|
|
90
|
|
- /**
|
91
|
|
- * Gets the hostname for an IP address
|
92
|
|
- *
|
93
|
|
- * @param $IP the IP to get the hostname for
|
94
|
|
- * @return hostname fetched
|
95
|
|
- */
|
96
|
|
- public static function get_host_by_ip($IP) {
|
97
|
|
- $testar = explode('.', $IP);
|
98
|
|
- if (count($testar) != 4) {
|
99
|
|
- return $IP;
|
100
|
|
- }
|
101
|
|
- for ($i = 0; $i < 4; ++$i) {
|
102
|
|
- if (!is_numeric($testar[$i])) {
|
103
|
|
- return $IP;
|
104
|
|
- }
|
105
|
|
- }
|
|
94
|
+ /**
|
|
95
|
+ * Gets the hostname for an IP address
|
|
96
|
+ *
|
|
97
|
+ * @param $IP the IP to get the hostname for
|
|
98
|
+ * @return hostname fetched
|
|
99
|
+ */
|
|
100
|
+ public static function get_host_by_ip($IP)
|
|
101
|
+ {
|
|
102
|
+ $testar = explode('.', $IP);
|
|
103
|
+ if (count($testar) != 4) {
|
|
104
|
+ return $IP;
|
|
105
|
+ }
|
|
106
|
+ for ($i = 0; $i < 4; ++$i) {
|
|
107
|
+ if (!is_numeric($testar[$i])) {
|
|
108
|
+ return $IP;
|
|
109
|
+ }
|
|
110
|
+ }
|
106
|
111
|
|
107
|
|
- $host = `host -W 1 $IP`;
|
108
|
|
- return ($host ? end(explode(' ', $host)) : $IP);
|
109
|
|
- }
|
|
112
|
+ $host = `host -W 1 $IP`;
|
|
113
|
+ return ($host ? end(explode(' ', $host)) : $IP);
|
|
114
|
+ }
|
110
|
115
|
|
111
|
|
- /**
|
112
|
|
- * Gets an hostname using AJAX
|
113
|
|
- *
|
114
|
|
- * @param $IP the IP to fetch
|
115
|
|
- * @return a span with JavaScript code
|
116
|
|
- */
|
117
|
|
- public static function get_host_by_ajax($IP) {
|
118
|
|
- static $ID = 0;
|
119
|
|
- ++$ID;
|
120
|
|
- return '<span id="host_'.$ID.'">Resolving host...<script type="text/javascript">ajax.get(\'tools.php?action=get_host&ip='.$IP.'\',function(host) {$(\'#host_'.$ID.'\').raw().innerHTML=host;});</script></span>';
|
121
|
|
- }
|
|
116
|
+ /**
|
|
117
|
+ * Gets an hostname using AJAX
|
|
118
|
+ *
|
|
119
|
+ * @param $IP the IP to fetch
|
|
120
|
+ * @return a span with JavaScript code
|
|
121
|
+ */
|
|
122
|
+ public static function get_host_by_ajax($IP)
|
|
123
|
+ {
|
|
124
|
+ static $ID = 0;
|
|
125
|
+ ++$ID;
|
|
126
|
+ return '<span id="host_'.$ID.'">Resolving host...<script type="text/javascript">ajax.get(\'tools.php?action=get_host&ip='.$IP.'\',function(host) {$(\'#host_'.$ID.'\').raw().innerHTML=host;});</script></span>';
|
|
127
|
+ }
|
122
|
128
|
|
123
|
129
|
|
124
|
|
- /**
|
125
|
|
- * Looks up the full host of an IP address, by system call.
|
126
|
|
- * Used as the server-side counterpart to get_host_by_ajax.
|
127
|
|
- *
|
128
|
|
- * @param string $IP The IP address to look up.
|
129
|
|
- * @return string the host.
|
130
|
|
- */
|
131
|
|
- public static function lookup_ip($IP) {
|
132
|
|
- //TODO: use the G::$Cache
|
133
|
|
- $Output = explode(' ',shell_exec('host -W 1 '.escapeshellarg($IP)));
|
134
|
|
- if (count($Output) == 1 && empty($Output[0])) { return ''; }
|
135
|
|
- if (count($Output) != 5) { return false; }
|
136
|
|
- if ($Output[2].' '.$Output[3] == 'not found:') { return false; }
|
137
|
|
- return trim($Output[4]);
|
138
|
|
- }
|
|
130
|
+ /**
|
|
131
|
+ * Looks up the full host of an IP address, by system call.
|
|
132
|
+ * Used as the server-side counterpart to get_host_by_ajax.
|
|
133
|
+ *
|
|
134
|
+ * @param string $IP The IP address to look up.
|
|
135
|
+ * @return string the host.
|
|
136
|
+ */
|
|
137
|
+ public static function lookup_ip($IP)
|
|
138
|
+ {
|
|
139
|
+ //TODO: use the G::$Cache
|
|
140
|
+ $Output = explode(' ', shell_exec('host -W 1 '.escapeshellarg($IP)));
|
|
141
|
+ if (count($Output) == 1 && empty($Output[0])) {
|
|
142
|
+ return '';
|
|
143
|
+ }
|
|
144
|
+ if (count($Output) != 5) {
|
|
145
|
+ return false;
|
|
146
|
+ }
|
|
147
|
+ if ($Output[2].' '.$Output[3] == 'not found:') {
|
|
148
|
+ return false;
|
|
149
|
+ }
|
|
150
|
+ return trim($Output[4]);
|
|
151
|
+ }
|
139
|
152
|
|
140
|
|
- /**
|
141
|
|
- * Format an IP address with links to IP history.
|
142
|
|
- *
|
143
|
|
- * @param string IP
|
144
|
|
- * @return string The HTML
|
145
|
|
- */
|
146
|
|
- public static function display_ip($IP) {
|
147
|
|
- $Line = display_str($IP).' ('.Tools::get_country_code_by_ajax($IP).') ';
|
148
|
|
- $Line .= '<a href="user.php?action=search&ip_history=on&ip='.display_str($IP).'&matchtype=strict" title="Search" class="brackets tooltip">S</a>';
|
|
153
|
+ /**
|
|
154
|
+ * Format an IP address with links to IP history.
|
|
155
|
+ *
|
|
156
|
+ * @param string IP
|
|
157
|
+ * @return string The HTML
|
|
158
|
+ */
|
|
159
|
+ public static function display_ip($IP)
|
|
160
|
+ {
|
|
161
|
+ $Line = display_str($IP).' ('.Tools::get_country_code_by_ajax($IP).') ';
|
|
162
|
+ $Line .= '<a href="user.php?action=search&ip_history=on&ip='.display_str($IP).'&matchtype=strict" title="Search" class="brackets tooltip">S</a>';
|
149
|
163
|
|
150
|
|
- return $Line;
|
151
|
|
- }
|
|
164
|
+ return $Line;
|
|
165
|
+ }
|
152
|
166
|
|
153
|
|
- public static function get_country_code_by_ajax($IP) {
|
154
|
|
- static $ID = 0;
|
155
|
|
- ++$ID;
|
156
|
|
- return '<span id="cc_'.$ID.'">Resolving CC...<script type="text/javascript">ajax.get(\'tools.php?action=get_cc&ip='.$IP.'\', function(cc) {$(\'#cc_'.$ID.'\').raw().innerHTML = cc;});</script></span>';
|
157
|
|
- }
|
|
167
|
+ public static function get_country_code_by_ajax($IP)
|
|
168
|
+ {
|
|
169
|
+ static $ID = 0;
|
|
170
|
+ ++$ID;
|
|
171
|
+ return '<span id="cc_'.$ID.'">Resolving CC...<script type="text/javascript">ajax.get(\'tools.php?action=get_cc&ip='.$IP.'\', function(cc) {$(\'#cc_'.$ID.'\').raw().innerHTML = cc;});</script></span>';
|
|
172
|
+ }
|
158
|
173
|
|
159
|
174
|
|
160
|
|
- /**
|
161
|
|
- * Disable an array of users.
|
162
|
|
- *
|
163
|
|
- * @param array $UserIDs (You can also send it one ID as an int, because fuck types)
|
164
|
|
- * @param BanReason 0 - Unknown, 1 - Manual, 2 - Ratio, 3 - Inactive, 4 - Unused.
|
165
|
|
- */
|
166
|
|
- public static function disable_users($UserIDs, $AdminComment, $BanReason = 1) {
|
167
|
|
- $QueryID = G::$DB->get_query_id();
|
168
|
|
- if (!is_array($UserIDs)) {
|
169
|
|
- $UserIDs = array($UserIDs);
|
170
|
|
- }
|
171
|
|
- G::$DB->query("
|
|
175
|
+ /**
|
|
176
|
+ * Disable an array of users.
|
|
177
|
+ *
|
|
178
|
+ * @param array $UserIDs (You can also send it one ID as an int, because fuck types)
|
|
179
|
+ * @param BanReason 0 - Unknown, 1 - Manual, 2 - Ratio, 3 - Inactive, 4 - Unused.
|
|
180
|
+ */
|
|
181
|
+ public static function disable_users($UserIDs, $AdminComment, $BanReason = 1)
|
|
182
|
+ {
|
|
183
|
+ $QueryID = G::$DB->get_query_id();
|
|
184
|
+ if (!is_array($UserIDs)) {
|
|
185
|
+ $UserIDs = array($UserIDs);
|
|
186
|
+ }
|
|
187
|
+ G::$DB->query("
|
172
|
188
|
UPDATE users_info AS i
|
173
|
189
|
JOIN users_main AS m ON m.ID = i.UserID
|
174
|
190
|
SET m.Enabled = '2',
|
|
@@ -178,130 +194,133 @@ class Tools {
|
178
|
194
|
i.BanReason = '$BanReason',
|
179
|
195
|
i.RatioWatchDownload = ".($BanReason == 2 ? 'm.Downloaded' : "'0'")."
|
180
|
196
|
WHERE m.ID IN(".implode(',', $UserIDs).') ');
|
181
|
|
- G::$Cache->decrement('stats_user_count', G::$DB->affected_rows());
|
182
|
|
- foreach ($UserIDs as $UserID) {
|
183
|
|
- G::$Cache->delete_value("enabled_$UserID");
|
184
|
|
- G::$Cache->delete_value("user_info_$UserID");
|
185
|
|
- G::$Cache->delete_value("user_info_heavy_$UserID");
|
186
|
|
- G::$Cache->delete_value("user_stats_$UserID");
|
|
197
|
+ G::$Cache->decrement('stats_user_count', G::$DB->affected_rows());
|
|
198
|
+ foreach ($UserIDs as $UserID) {
|
|
199
|
+ G::$Cache->delete_value("enabled_$UserID");
|
|
200
|
+ G::$Cache->delete_value("user_info_$UserID");
|
|
201
|
+ G::$Cache->delete_value("user_info_heavy_$UserID");
|
|
202
|
+ G::$Cache->delete_value("user_stats_$UserID");
|
187
|
203
|
|
188
|
|
- G::$DB->query("
|
|
204
|
+ G::$DB->query("
|
189
|
205
|
SELECT SessionID
|
190
|
206
|
FROM users_sessions
|
191
|
207
|
WHERE UserID = '$UserID'
|
192
|
208
|
AND Active = 1");
|
193
|
|
- while (list($SessionID) = G::$DB->next_record()) {
|
194
|
|
- G::$Cache->delete_value("session_$UserID"."_$SessionID");
|
195
|
|
- }
|
196
|
|
- G::$Cache->delete_value("users_sessions_$UserID");
|
|
209
|
+ while (list($SessionID) = G::$DB->next_record()) {
|
|
210
|
+ G::$Cache->delete_value("session_$UserID"."_$SessionID");
|
|
211
|
+ }
|
|
212
|
+ G::$Cache->delete_value("users_sessions_$UserID");
|
197
|
213
|
|
198
|
|
- G::$DB->query("
|
|
214
|
+ G::$DB->query("
|
199
|
215
|
DELETE FROM users_sessions
|
200
|
216
|
WHERE UserID = '$UserID'");
|
|
217
|
+ }
|
201
|
218
|
|
202
|
|
- }
|
203
|
|
-
|
204
|
|
- // Remove the users from the tracker.
|
205
|
|
- G::$DB->query('
|
|
219
|
+ // Remove the users from the tracker.
|
|
220
|
+ G::$DB->query('
|
206
|
221
|
SELECT torrent_pass
|
207
|
222
|
FROM users_main
|
208
|
223
|
WHERE ID in ('.implode(', ', $UserIDs).')');
|
209
|
|
- $PassKeys = G::$DB->collect('torrent_pass');
|
210
|
|
- $Concat = '';
|
211
|
|
- foreach ($PassKeys as $PassKey) {
|
212
|
|
- if (strlen($Concat) > 3950) { // Ocelot's read buffer is 4 KiB and anything exceeding it is truncated
|
|
224
|
+ $PassKeys = G::$DB->collect('torrent_pass');
|
|
225
|
+ $Concat = '';
|
|
226
|
+ foreach ($PassKeys as $PassKey) {
|
|
227
|
+ if (strlen($Concat) > 3950) { // Ocelot's read buffer is 4 KiB and anything exceeding it is truncated
|
|
228
|
+ Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
|
|
229
|
+ $Concat = $PassKey;
|
|
230
|
+ } else {
|
|
231
|
+ $Concat .= $PassKey;
|
|
232
|
+ }
|
|
233
|
+ }
|
213
|
234
|
Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
|
214
|
|
- $Concat = $PassKey;
|
215
|
|
- } else {
|
216
|
|
- $Concat .= $PassKey;
|
217
|
|
- }
|
|
235
|
+ G::$DB->set_query_id($QueryID);
|
218
|
236
|
}
|
219
|
|
- Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
|
220
|
|
- G::$DB->set_query_id($QueryID);
|
221
|
|
- }
|
222
|
237
|
|
223
|
|
- /**
|
224
|
|
- * Warn a user.
|
225
|
|
- *
|
226
|
|
- * @param int $UserID
|
227
|
|
- * @param int $Duration length of warning in seconds
|
228
|
|
- * @param string $reason
|
229
|
|
- */
|
230
|
|
- public static function warn_user($UserID, $Duration, $Reason) {
|
231
|
|
- global $Time;
|
|
238
|
+ /**
|
|
239
|
+ * Warn a user.
|
|
240
|
+ *
|
|
241
|
+ * @param int $UserID
|
|
242
|
+ * @param int $Duration length of warning in seconds
|
|
243
|
+ * @param string $reason
|
|
244
|
+ */
|
|
245
|
+ public static function warn_user($UserID, $Duration, $Reason)
|
|
246
|
+ {
|
|
247
|
+ global $Time;
|
232
|
248
|
|
233
|
|
- $QueryID = G::$DB->get_query_id();
|
234
|
|
- G::$DB->query("
|
|
249
|
+ $QueryID = G::$DB->get_query_id();
|
|
250
|
+ G::$DB->query("
|
235
|
251
|
SELECT Warned
|
236
|
252
|
FROM users_info
|
237
|
253
|
WHERE UserID = $UserID
|
238
|
254
|
AND Warned IS NOT NULL");
|
239
|
|
- if (G::$DB->has_results()) {
|
240
|
|
- //User was already warned, appending new warning to old.
|
241
|
|
- list($OldDate) = G::$DB->next_record();
|
242
|
|
- $NewExpDate = date('Y-m-d H:i:s', strtotime($OldDate) + $Duration);
|
|
255
|
+ if (G::$DB->has_results()) {
|
|
256
|
+ //User was already warned, appending new warning to old.
|
|
257
|
+ list($OldDate) = G::$DB->next_record();
|
|
258
|
+ $NewExpDate = date('Y-m-d H:i:s', strtotime($OldDate) + $Duration);
|
243
|
259
|
|
244
|
|
- Misc::send_pm($UserID, 0,
|
245
|
|
- 'You have received multiple warnings.',
|
246
|
|
- "When you received your latest warning (set to expire on ".date('Y-m-d', (time() + $Duration)).'), you already had a different warning (set to expire on '.date('Y-m-d', strtotime($OldDate)).").\n\n Due to this collision, your warning status will now expire at $NewExpDate.");
|
|
260
|
+ Misc::send_pm(
|
|
261
|
+ $UserID,
|
|
262
|
+ 0,
|
|
263
|
+ 'You have received multiple warnings.',
|
|
264
|
+ "When you received your latest warning (set to expire on ".date('Y-m-d', (time() + $Duration)).'), you already had a different warning (set to expire on '.date('Y-m-d', strtotime($OldDate)).").\n\n Due to this collision, your warning status will now expire at $NewExpDate."
|
|
265
|
+ );
|
247
|
266
|
|
248
|
|
- $AdminComment = date('Y-m-d')." - Warning (Clash) extended to expire at $NewExpDate by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
|
|
267
|
+ $AdminComment = date('Y-m-d')." - Warning (Clash) extended to expire at $NewExpDate by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
|
249
|
268
|
|
250
|
|
- G::$DB->query('
|
|
269
|
+ G::$DB->query('
|
251
|
270
|
UPDATE users_info
|
252
|
271
|
SET
|
253
|
272
|
Warned = \''.db_string($NewExpDate).'\',
|
254
|
273
|
WarnedTimes = WarnedTimes + 1,
|
255
|
274
|
AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
|
256
|
275
|
WHERE UserID = \''.db_string($UserID).'\'');
|
257
|
|
- } else {
|
258
|
|
- //Not changing, user was not already warned
|
259
|
|
- $WarnTime = time_plus($Duration);
|
|
276
|
+ } else {
|
|
277
|
+ //Not changing, user was not already warned
|
|
278
|
+ $WarnTime = time_plus($Duration);
|
260
|
279
|
|
261
|
|
- G::$Cache->begin_transaction("user_info_$UserID");
|
262
|
|
- G::$Cache->update_row(false, array('Warned' => $WarnTime));
|
263
|
|
- G::$Cache->commit_transaction(0);
|
|
280
|
+ G::$Cache->begin_transaction("user_info_$UserID");
|
|
281
|
+ G::$Cache->update_row(false, array('Warned' => $WarnTime));
|
|
282
|
+ G::$Cache->commit_transaction(0);
|
264
|
283
|
|
265
|
|
- $AdminComment = date('Y-m-d')." - Warned until $WarnTime by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
|
|
284
|
+ $AdminComment = date('Y-m-d')." - Warned until $WarnTime by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
|
266
|
285
|
|
267
|
|
- G::$DB->query('
|
|
286
|
+ G::$DB->query('
|
268
|
287
|
UPDATE users_info
|
269
|
288
|
SET
|
270
|
289
|
Warned = \''.db_string($WarnTime).'\',
|
271
|
290
|
WarnedTimes = WarnedTimes + 1,
|
272
|
291
|
AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
|
273
|
292
|
WHERE UserID = \''.db_string($UserID).'\'');
|
|
293
|
+ }
|
|
294
|
+ G::$DB->set_query_id($QueryID);
|
274
|
295
|
}
|
275
|
|
- G::$DB->set_query_id($QueryID);
|
276
|
|
- }
|
277
|
296
|
|
278
|
|
- /**
|
279
|
|
- * Update the notes of a user
|
280
|
|
- * @param unknown $UserID ID of user
|
281
|
|
- * @param unknown $AdminComment Comment to update with
|
282
|
|
- */
|
283
|
|
- public static function update_user_notes($UserID, $AdminComment) {
|
284
|
|
- $QueryID = G::$DB->get_query_id();
|
285
|
|
- G::$DB->query('
|
|
297
|
+ /**
|
|
298
|
+ * Update the notes of a user
|
|
299
|
+ * @param unknown $UserID ID of user
|
|
300
|
+ * @param unknown $AdminComment Comment to update with
|
|
301
|
+ */
|
|
302
|
+ public static function update_user_notes($UserID, $AdminComment)
|
|
303
|
+ {
|
|
304
|
+ $QueryID = G::$DB->get_query_id();
|
|
305
|
+ G::$DB->query('
|
286
|
306
|
UPDATE users_info
|
287
|
307
|
SET AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
|
288
|
308
|
WHERE UserID = \''.db_string($UserID).'\'');
|
289
|
|
- G::$DB->set_query_id($QueryID);
|
290
|
|
- }
|
291
|
|
-
|
292
|
|
- /**
|
293
|
|
- * Check if an IP address is part of a given CIDR range.
|
294
|
|
- * @param string $CheckIP the IP address to be looked up
|
295
|
|
- * @param string $Subnet the CIDR subnet to be checked against
|
296
|
|
- */
|
297
|
|
- public static function check_cidr_range($CheckIP, $Subnet) {
|
298
|
|
- $IP = ip2long($CheckIP);
|
299
|
|
- $CIDR = preg_split('/', $Subnet);
|
300
|
|
- $SubnetIP = ip2long($CIDR[0]);
|
301
|
|
- $SubnetMaskBits = 32 - $CIDR[1];
|
|
309
|
+ G::$DB->set_query_id($QueryID);
|
|
310
|
+ }
|
302
|
311
|
|
303
|
|
- return (($IP>>$SubnetMaskBits) == ($SubnetIP>>$SubnetMaskBits));
|
304
|
|
- }
|
|
312
|
+ /**
|
|
313
|
+ * Check if an IP address is part of a given CIDR range.
|
|
314
|
+ * @param string $CheckIP the IP address to be looked up
|
|
315
|
+ * @param string $Subnet the CIDR subnet to be checked against
|
|
316
|
+ */
|
|
317
|
+ public static function check_cidr_range($CheckIP, $Subnet)
|
|
318
|
+ {
|
|
319
|
+ $IP = ip2long($CheckIP);
|
|
320
|
+ $CIDR = preg_split('/', $Subnet);
|
|
321
|
+ $SubnetIP = ip2long($CIDR[0]);
|
|
322
|
+ $SubnetMaskBits = 32 - $CIDR[1];
|
305
|
323
|
|
|
324
|
+ return (($IP>>$SubnetMaskBits) == ($SubnetIP>>$SubnetMaskBits));
|
|
325
|
+ }
|
306
|
326
|
}
|
307
|
|
-?>
|