|
1
|
|
|
<?php |
|
2
|
|
|
class_exists('_IpAddresses', false) or include('_IpAddresses.class.php'); |
|
3
|
|
|
class_exists('_FileCache', false) or include('_FileCache.class.php'); |
|
4
|
|
|
class_exists('Setup', false) or include('Setup.class.php'); |
|
5
|
|
|
class_exists('_MySQL', false) or include('_MySQL.class.php'); |
|
6
|
|
|
|
|
7
|
|
|
class Utilities { |
|
8
|
|
|
|
|
9
|
|
|
public static $domainBlacklists = array(); |
|
10
|
|
|
public static $ipBlacklists = array(); |
|
11
|
|
|
public static $hostNotCheckedMessage = '1ST CHECK SCHEDULED'; |
|
12
|
|
|
public static $frequencyCheckOptions = array('1hour', '2hour', '8hour', 'daily', 'weekly'); |
|
13
|
|
|
public static $mysql = false; |
|
14
|
|
|
|
|
15
|
|
|
public static function setBlockLists(){ |
|
16
|
|
|
$localCache = new _FileCache('blacklistmonitor-Utilities-BlockLists', 60); |
|
17
|
|
|
$cacheKey = 'bl'; |
|
18
|
|
|
$cacheData = $localCache->get($cacheKey); |
|
19
|
|
|
if ($cacheData !== false) { |
|
20
|
|
|
if(isset($cacheData['domains']) && isset($cacheData['ips']) ) { |
|
21
|
|
|
self::$domainBlacklists = $cacheData['domains']; |
|
22
|
|
|
self::$ipBlacklists = $cacheData['ips']; |
|
23
|
|
|
return true; |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
$mysql = new _MySQL(); |
|
27
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
28
|
|
|
$sql = "select host,monitorType from blockLists where isActive = '1';"; |
|
29
|
|
|
$rs = $mysql->runQuery($sql); |
|
30
|
|
|
$cacheData['domains'] = array(); |
|
31
|
|
|
$cacheData['ips'] = array(); |
|
32
|
|
|
while($row = mysqli_fetch_array($rs)){ |
|
33
|
|
|
if($row['monitorType']=='ip'){ |
|
34
|
|
|
$cacheData['ips'][] = $row['host']; |
|
35
|
|
|
}else{ |
|
36
|
|
|
$cacheData['domains'][] = $row['host']; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
$mysql->close(); |
|
40
|
|
|
$localCache->set($cacheKey, $cacheData); |
|
41
|
|
|
self::$domainBlacklists = $cacheData['domains']; |
|
42
|
|
|
self::$ipBlacklists = $cacheData['ips']; |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function randomDNSServer(){ |
|
47
|
|
|
return Setup::$settings['dns_servers'][mt_rand(0,(count(Setup::$settings['dns_servers'])-1))]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public static $isBlocked = 0; |
|
51
|
|
|
|
|
52
|
|
|
public static function checkBlacklists($domainOrIp, $reportClean=false){ |
|
53
|
|
|
self::$isBlocked = 0; |
|
54
|
|
|
$return = array(); |
|
55
|
|
|
if(_IpAddresses::isIPAddress($domainOrIp)){ |
|
56
|
|
View Code Duplication |
foreach(self::$ipBlacklists as $server){ |
|
57
|
|
|
$r = self::ipCheck($domainOrIp, $server); |
|
58
|
|
|
if($r!='') { |
|
59
|
|
|
self::$isBlocked = 1; |
|
60
|
|
|
self::logBlockListStats($server, 'ip', true); |
|
61
|
|
|
}else{ |
|
62
|
|
|
self::logBlockListStats($server, 'ip', false); |
|
63
|
|
|
} |
|
64
|
|
|
if($r!='' || $reportClean==true) { |
|
|
|
|
|
|
65
|
|
|
$return[] = array(trim($server),$r); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
}else{ |
|
69
|
|
View Code Duplication |
foreach(self::$domainBlacklists as $server){ |
|
70
|
|
|
$r = self::domainCheck($domainOrIp, $server); |
|
71
|
|
|
if($r!='') { |
|
72
|
|
|
self::$isBlocked = 1; |
|
73
|
|
|
self::logBlockListStats($server, 'domain', true); |
|
74
|
|
|
}else{ |
|
75
|
|
|
self::logBlockListStats($server, 'domain', false); |
|
76
|
|
|
} |
|
77
|
|
|
if($r!='' || $reportClean==true) { |
|
|
|
|
|
|
78
|
|
|
$return[] = array(trim($server),$r); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
return $return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public static function domainCheck($domain, $server){ |
|
86
|
|
|
$server = trim($server); |
|
87
|
|
|
$host = escapeshellarg("$domain.$server"); |
|
88
|
|
|
$t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host"; |
|
89
|
|
|
// echo("$t</br>"); |
|
90
|
|
|
$text = shell_exec($t); |
|
91
|
|
|
$test = Utilities::parseBetweenText( |
|
92
|
|
|
$text, |
|
93
|
|
|
";; ANSWER SECTION:\n", |
|
94
|
|
|
"\n\n", |
|
95
|
|
|
false, |
|
96
|
|
|
false, |
|
97
|
|
|
true); |
|
98
|
|
|
$testArray = explode("\t", $test); |
|
99
|
|
|
$test = end($testArray); |
|
100
|
|
|
|
|
101
|
|
|
if(trim($test)!=''){ |
|
102
|
|
|
if(Setup::$settings['rbl_txt_extended_status']){ |
|
103
|
|
|
$t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host txt"; |
|
104
|
|
|
// echo("$t</br>"); |
|
105
|
|
|
$text = shell_exec($t); |
|
106
|
|
|
$test = Utilities::parseBetweenText( |
|
107
|
|
|
$text, |
|
108
|
|
|
";; ANSWER SECTION:\n", |
|
109
|
|
|
"\n\n", |
|
110
|
|
|
false, |
|
111
|
|
|
false, |
|
112
|
|
|
true); |
|
113
|
|
|
$testArray = explode("\t", $test); |
|
114
|
|
|
$test = end($testArray); |
|
115
|
|
|
$test = str_replace(array('\'','"'),'',$test); |
|
116
|
|
|
}else{ |
|
117
|
|
|
$test = 'blocked'; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
if(strripos($test,'not found')!==false) return ''; |
|
121
|
|
|
if(strripos($test,'SERVFAIL')!==false) return ''; |
|
122
|
|
|
return trim($test); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public static function ipCheck($ip, $server){ |
|
126
|
|
|
if(_IpAddresses::isIPAddress($ip)===false) return ''; |
|
127
|
|
|
$server = trim($server); |
|
128
|
|
|
|
|
129
|
|
|
$parts = explode('.', $ip); |
|
130
|
|
|
$reverseIp = implode('.', array_reverse($parts)); |
|
131
|
|
|
$text = ""; |
|
|
|
|
|
|
132
|
|
|
$host = escapeshellarg("$reverseIp.$server"); |
|
133
|
|
|
$t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host"; |
|
134
|
|
|
// echo("$t</br>"); |
|
135
|
|
|
$text = shell_exec($t); |
|
136
|
|
|
$test = Utilities::parseBetweenText( |
|
137
|
|
|
$text, |
|
138
|
|
|
";; ANSWER SECTION:\n", |
|
139
|
|
|
"\n\n", |
|
140
|
|
|
false, |
|
141
|
|
|
false, |
|
142
|
|
|
true); |
|
143
|
|
|
$testArray = preg_split("/IN\s+A\s+/i", $test); |
|
144
|
|
|
$test = trim(end($testArray)); |
|
145
|
|
|
// echo "<pre>$test</pre>\n"; |
|
146
|
|
|
if(trim($test)!=''){ |
|
147
|
|
|
if(Setup::$settings['rbl_txt_extended_status']){ |
|
148
|
|
|
$t = "dig @".self::randomDNSServer()." +time=".Setup::$settings['dns_request_timeout']." $host txt"; |
|
149
|
|
|
// echo("$t</br>"); |
|
150
|
|
|
$text = shell_exec($t); |
|
151
|
|
|
$test2 = Utilities::parseBetweenText( |
|
152
|
|
|
$text, |
|
153
|
|
|
";; ANSWER SECTION:\n", |
|
154
|
|
|
"\n\n", |
|
155
|
|
|
false, |
|
156
|
|
|
false, |
|
157
|
|
|
true); |
|
158
|
|
|
$testArray = preg_split("/IN\s+TXT\s+/i", $test2); |
|
159
|
|
|
$test2 = trim(end($testArray)); |
|
160
|
|
|
$test2 = str_replace(array('\'','"'),'',$test2); |
|
161
|
|
|
switch($server){ |
|
162
|
|
|
case 'bl.mailspike.net': |
|
163
|
|
|
$a = explode("|",$test2); |
|
164
|
|
|
$test = (isset($a[1])) ? 'Listed ' . $a[1] : $test2; |
|
165
|
|
|
break; |
|
166
|
|
|
} |
|
167
|
|
|
if($test2!='') $test = $test2; |
|
168
|
|
|
}else{ |
|
169
|
|
|
$test = 'blocked'; |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
if(strripos($test,'not found')!==false) return ''; |
|
173
|
|
|
if(strripos($test,'SERVFAIL')!==false) return ''; |
|
174
|
|
|
return trim($test); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public static function logBlockListStats($server, $monitorType, $isBlocked){ |
|
178
|
|
|
if(Setup::$settings['log_rbl_stats']==0) return true; |
|
179
|
|
|
$mysql = new _MySQL(); |
|
180
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
181
|
|
|
if($isBlocked){ |
|
182
|
|
|
$sql = "update blockLists set blocksToday=(blocksToday+1), lastBlockReport=now() where host = '".$mysql->escape($server)."' and monitorType = '$monitorType';"; |
|
183
|
|
|
}else{ |
|
184
|
|
|
$sql = "update blockLists set cleanToday=(cleanToday+1) where host = '".$mysql->escape($server)."' and monitorType = '$monitorType';"; |
|
185
|
|
|
} |
|
186
|
|
|
$mysql->runQuery($sql); |
|
187
|
|
|
$mysql->close(); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public static function ensureGroupExists($groupName){ |
|
191
|
|
|
$mysql = new _MySQL(); |
|
192
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
193
|
|
|
$id = $mysql->runQueryReturnVar("select id from monitorGroup where groupName = '".$mysql->escape($groupName)."'"); |
|
194
|
|
|
if($id===false){ |
|
195
|
|
|
$mysql->runQuery("insert into monitorGroup set groupName = '".$mysql->escape($groupName)."'"); |
|
196
|
|
|
$id = $mysql->identity; |
|
197
|
|
|
} |
|
198
|
|
|
$mysql->close(); |
|
199
|
|
|
return $id; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public static function updateDomains($domains, $monitorGroupId){ |
|
203
|
|
|
$domains = trim($domains); |
|
204
|
|
|
$monitorGroupId = (int)$monitorGroupId; |
|
205
|
|
|
if($monitorGroupId===0) return false; |
|
206
|
|
|
$mysql = new _MySQL(); |
|
207
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
208
|
|
|
$mysql->runQuery("update monitors set keepOnUpdate = 0 where isDomain = 1 and monitorGroupId = $monitorGroupId"); |
|
209
|
|
|
$mysql->runQuery("update users set lastUpdate = '".$mysql->escape(date('Y-m-d H:i:s'))."'"); |
|
210
|
|
|
$mysql->runQuery("update monitorGroup set domains = '".$mysql->escape($domains)."' where id = $monitorGroupId"); |
|
211
|
|
|
$domainArray = preg_split('/\s+/', $domains); |
|
212
|
|
|
foreach($domainArray as $d){ |
|
213
|
|
|
$d = trim($d); |
|
214
|
|
|
$d = str_ireplace('http://', '', $d); |
|
215
|
|
|
$d = str_ireplace('https://', '', $d); |
|
216
|
|
|
$d = str_ireplace('/', '', $d); |
|
217
|
|
|
$d = preg_replace('/[[:^print:]]/', '', $d); |
|
218
|
|
View Code Duplication |
if($d != ''){ |
|
219
|
|
|
$mysql->runQuery(" |
|
220
|
|
|
update monitors set |
|
221
|
|
|
keepOnUpdate = 1 |
|
222
|
|
|
where |
|
223
|
|
|
monitorGroupId = $monitorGroupId |
|
224
|
|
|
and ipDomain = '".$mysql->escape($d)."' |
|
225
|
|
|
and isDomain = 1 |
|
226
|
|
|
"); |
|
227
|
|
|
if($mysql->affectedRows == 0){ |
|
228
|
|
|
$mysql->runQuery("insert ignore into monitors set |
|
229
|
|
|
monitorGroupId = $monitorGroupId, |
|
230
|
|
|
ipDomain = '".$mysql->escape($d)."', |
|
231
|
|
|
isDomain = 1, |
|
232
|
|
|
keepOnUpdate = 1 |
|
233
|
|
|
"); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
$mysql->runQuery("delete from monitors where keepOnUpdate = 0 and isDomain = 1 and monitorGroupId = $monitorGroupId"); |
|
238
|
|
|
$mysql->close(); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
public static function updateIPs($ips, $monitorGroupId){ |
|
242
|
|
|
$ips = trim($ips); |
|
243
|
|
|
$monitorGroupId = (int)$monitorGroupId; |
|
244
|
|
|
if($monitorGroupId===0) return false; |
|
245
|
|
|
$mysql = new _MySQL(); |
|
246
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
247
|
|
|
$mysql->runQuery("update monitors set keepOnUpdate = 0 where isDomain = 0 and monitorGroupId = $monitorGroupId"); |
|
248
|
|
|
$mysql->runQuery("update users set lastUpdate = '".$mysql->escape(date('Y-m-d H:i:s'))."'"); |
|
249
|
|
|
$mysql->runQuery("update monitorGroup set ips = '".$mysql->escape($ips)."' where id = $monitorGroupId"); |
|
250
|
|
|
$ipsArray = preg_split('/\s+/', $ips); |
|
251
|
|
|
foreach($ipsArray as $i){ |
|
252
|
|
|
// ip checks |
|
253
|
|
|
if(_IpAddresses::isIPAddress($i)){ |
|
254
|
|
|
$mysql->runQuery(" |
|
255
|
|
|
update monitors set |
|
256
|
|
|
keepOnUpdate = 1 |
|
257
|
|
|
where |
|
258
|
|
|
monitorGroupId = $monitorGroupId |
|
259
|
|
|
and ipDomain = '".$mysql->escape($i)."' |
|
260
|
|
|
and isDomain = 0 |
|
261
|
|
|
"); |
|
262
|
|
|
if($mysql->affectedRows == 0){ |
|
263
|
|
|
$mysql->runQuery("insert ignore into monitors set |
|
264
|
|
|
monitorGroupId = $monitorGroupId, |
|
265
|
|
|
ipDomain = '".$mysql->escape($i)."', |
|
266
|
|
|
isDomain = 0, |
|
267
|
|
|
keepOnUpdate = 1 |
|
268
|
|
|
"); |
|
269
|
|
|
} |
|
270
|
|
|
}else{ |
|
271
|
|
|
//cidr /24's max... |
|
272
|
|
|
if(trim($i)!=''){ |
|
273
|
|
|
if(strpos($i, ' ')!==false) continue; |
|
274
|
|
|
if(strpos($i, ':')!==false) continue; |
|
275
|
|
|
$range = _IpAddresses::cidrToRange($i); |
|
276
|
|
|
if($range===false) continue; |
|
277
|
|
|
$start = explode('.', $range[0]); |
|
278
|
|
|
$end = explode('.', $range[1]); |
|
279
|
|
|
if($range[0]==0) continue;// starts with 0 |
|
280
|
|
|
for($i = $start[3]; $i <= $end[3]; $i++){ |
|
281
|
|
|
$host = "{$start[0]}.{$start[1]}.{$start[2]}.$i"; |
|
282
|
|
|
if(_IpAddresses::isIPAddress($host)){ |
|
283
|
|
|
$mysql->runQuery(" |
|
284
|
|
|
update monitors set |
|
285
|
|
|
keepOnUpdate = 1 |
|
286
|
|
|
where |
|
287
|
|
|
monitorGroupId = $monitorGroupId |
|
288
|
|
|
and ipDomain = '".$mysql->escape($host)."' |
|
289
|
|
|
and isDomain = 0 |
|
290
|
|
|
"); |
|
291
|
|
|
if($mysql->affectedRows == 0){ |
|
292
|
|
|
$mysql->runQuery("insert ignore into monitors set |
|
293
|
|
|
monitorGroupId = $monitorGroupId, |
|
294
|
|
|
ipDomain = '".$mysql->escape($host)."', |
|
295
|
|
|
isDomain = 0, |
|
296
|
|
|
keepOnUpdate = 1 |
|
297
|
|
|
"); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
} |
|
304
|
|
|
$mysql->runQuery("delete from monitors where keepOnUpdate = 0 and isDomain = 0 and monitorGroupId = $monitorGroupId"); |
|
305
|
|
|
$mysql->close(); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
public static function isLoggedIn(){ |
|
309
|
|
|
if(isset($_SESSION['id']) && (int)$_SESSION['id'] > 0){ |
|
310
|
|
|
return $_SESSION['id']; |
|
311
|
|
|
}else{ |
|
312
|
|
|
return false; |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
public static function getAccount(){ |
|
317
|
|
|
$mysql = new _MySQL(); |
|
318
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
319
|
|
|
$ret = false; |
|
320
|
|
|
$rs = $mysql->runQuery(" |
|
321
|
|
|
select |
|
322
|
|
|
username, |
|
323
|
|
|
passwd, |
|
324
|
|
|
apiKey, |
|
325
|
|
|
beenChecked, |
|
326
|
|
|
disableEmailNotices, |
|
327
|
|
|
noticeEmailAddresses, |
|
328
|
|
|
textMessageEmails, |
|
329
|
|
|
twitterHandle, |
|
330
|
|
|
apiCallbackURL, |
|
331
|
|
|
checkFrequency |
|
332
|
|
|
from users limit 1"); |
|
333
|
|
|
while($row = mysqli_fetch_array($rs)){ |
|
334
|
|
|
$ret = $row; |
|
335
|
|
|
} |
|
336
|
|
|
$mysql->close(); |
|
337
|
|
|
|
|
338
|
|
|
if(!$ret){ |
|
339
|
|
|
//account |
|
340
|
|
|
_Logging::appLog("no user account"); |
|
341
|
|
|
exit(); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
return $ret; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
public static function validateLogin($userName, $passwd, $api = false, $apiKey = ''){ |
|
|
|
|
|
|
348
|
|
|
$mysql = new _MySQL(); |
|
349
|
|
|
$mysql->connect(Setup::$connectionArray); |
|
350
|
|
|
$sql = " |
|
351
|
|
|
select username |
|
352
|
|
|
from users |
|
353
|
|
|
where "; |
|
354
|
|
|
if(trim($apiKey) != ''){ |
|
355
|
|
|
$sql .= " apiKey = '".$mysql->escape($apiKey)."'"; |
|
356
|
|
|
}else{ |
|
357
|
|
|
$sql .= " passwd = '".$mysql->escape(md5($passwd))."' |
|
358
|
|
|
and username = '".$mysql->escape($userName)."'"; |
|
359
|
|
|
} |
|
360
|
|
|
$rs = $mysql->runQuery($sql); |
|
361
|
|
|
$id = 0; |
|
362
|
|
|
while($row = mysqli_fetch_array($rs)){ |
|
363
|
|
|
$id = 1; |
|
364
|
|
|
} |
|
365
|
|
|
$mysql->close(); |
|
366
|
|
|
return $id; |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
public static function lookupHostDNS($host){ |
|
370
|
|
|
if(_IpAddresses::isIPAddress($host)){ |
|
371
|
|
|
return _IpAddresses::getHostByIp($host); |
|
372
|
|
|
}else{ |
|
373
|
|
|
$host = escapeshellarg($host); |
|
374
|
|
|
exec('host -t a -W 2 '.$host, $output, $return); |
|
375
|
|
|
if ($return !== 0) { |
|
376
|
|
|
return ''; |
|
377
|
|
|
}else{ |
|
378
|
|
|
$output = implode($output); |
|
379
|
|
|
$ips = _IpAddresses::getAllIPsFromString($output, true); |
|
380
|
|
|
$ir = ""; |
|
381
|
|
|
foreach($ips as $ip){ |
|
382
|
|
|
$ir .= "$ip,"; |
|
383
|
|
|
} |
|
384
|
|
|
return trim($ir,','); |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/* |
|
388
|
|
|
if(strripos($host,'not found')!==false) return false; |
|
389
|
|
|
if(strripos($host,'SERVFAIL')!==false) return false; |
|
390
|
|
|
$phost = trim(end(explode(' ', $host))); |
|
391
|
|
|
if(strripos($phost,'reached')!==false) return false; |
|
392
|
|
|
return $phost; |
|
393
|
|
|
*/ |
|
394
|
|
|
} |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
public static function testAPICallback($url){ |
|
398
|
|
|
return self::makeAPICallback($url, |
|
399
|
|
|
'samplehosttest.com', |
|
400
|
|
|
true, |
|
401
|
|
|
'reverse-dns-sample.samplehosttest.com', |
|
402
|
|
|
'a:2:{i:0;a:2:{i:0;s:12:"l2.apews.org";i:1;s:87:"Listed at APEWS-L2 - visit http://www.apews.org/?page=test&C=131&E=1402188&ip=127.0.0.1";}i:1;a:2:{i:0;s:22:"b.barracudacentral.org";i:1;s:9:"127.0.0.2";}}' |
|
403
|
|
|
); |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
public static function makeAPICallback($url, $host, $isBlocked, $rDNS, $status){ |
|
407
|
|
|
if(substr($url,0,4)!='http') return false; |
|
408
|
|
|
|
|
409
|
|
|
$vars = json_encode( |
|
410
|
|
|
array( |
|
411
|
|
|
'host'=>$host, |
|
412
|
|
|
'isBlocked'=>(boolean)$isBlocked, |
|
413
|
|
|
'rDNS'=>$rDNS, |
|
414
|
|
|
'blocks'=>unserialize($status) |
|
415
|
|
|
) |
|
416
|
|
|
); |
|
417
|
|
|
$err = true; |
|
418
|
|
|
try{ |
|
419
|
|
|
$ch = curl_init(); |
|
420
|
|
|
curl_setopt($ch,CURLOPT_URL,$url); |
|
421
|
|
|
curl_setopt($ch,CURLOPT_POST,true); |
|
422
|
|
|
curl_setopt($ch,CURLOPT_FAILONERROR,true); |
|
423
|
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); |
|
424
|
|
|
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); |
|
425
|
|
|
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
|
426
|
|
|
curl_exec($ch); |
|
427
|
|
|
if (curl_errno($ch)) $err = false; |
|
428
|
|
|
} catch (Exception $e) { |
|
429
|
|
|
$err = false; |
|
430
|
|
|
} |
|
431
|
|
|
return $err; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
public static function isValidEmail($emailAddress){ |
|
435
|
|
|
if (filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { |
|
436
|
|
|
return true; |
|
437
|
|
|
} |
|
438
|
|
|
return false; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
public static function parseBetweenText( |
|
442
|
|
|
$text, |
|
443
|
|
|
$beginText, |
|
444
|
|
|
$endText, |
|
445
|
|
|
$removeSpace=true, |
|
446
|
|
|
$removeHtmlTags=true, |
|
447
|
|
|
$firstResultOnlyNoArray=false) { |
|
448
|
|
|
$results = array(); |
|
449
|
|
|
$endPos = 0; |
|
450
|
|
|
while(true) { |
|
451
|
|
|
$beginPos = stripos($text, $beginText, $endPos); |
|
452
|
|
|
if($beginPos===false) break; |
|
453
|
|
|
$beginPos = $beginPos+strlen($beginText); |
|
454
|
|
|
$endPos = stripos($text, $endText, $beginPos); |
|
455
|
|
|
if($endPos===false) break; |
|
456
|
|
|
$result = substr($text, $beginPos, $endPos-$beginPos); |
|
457
|
|
|
if($removeSpace){ |
|
458
|
|
|
$result = str_replace("\t","",$result); |
|
459
|
|
|
$result = str_replace("\n","",$result); |
|
460
|
|
|
$result = preg_replace("/ /"," ",$result); |
|
461
|
|
|
$result = preg_replace("~[\s]{2}?[\t]?~i"," ",$result); |
|
462
|
|
|
$result = str_replace(" "," ",$result); |
|
463
|
|
|
$result = trim($result); |
|
464
|
|
|
} |
|
465
|
|
|
if($removeHtmlTags){ |
|
466
|
|
|
$result = strip_tags($result); |
|
467
|
|
|
} |
|
468
|
|
|
if($firstResultOnlyNoArray) return $result; |
|
469
|
|
|
if($result != '') $results[] = $result; |
|
470
|
|
|
} |
|
471
|
|
|
return ($firstResultOnlyNoArray && empty($results) ? '' : $results); |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
public static function getNextMonitor($mysql){ |
|
475
|
|
|
$ipDomain = $mysql->runQueryReturnVar("select ipDomain from monitors where beenChecked = 0"); |
|
476
|
|
|
$mysql->runQuery("update monitors set beenChecked = 1 where ipDomain = '".$mysql->escape($ipDomain)."'"); |
|
477
|
|
|
return $ipDomain; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
View Code Duplication |
public static function getHostChangeCount($mysql, $monitorGroupId = 0) { |
|
|
|
|
|
|
481
|
|
|
$sql = ''; |
|
482
|
|
|
$monitorGroupId = (int)$monitorGroupId; |
|
483
|
|
|
if($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
484
|
|
|
return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors where lastStatusChanged = 1 $sql"); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
View Code Duplication |
public static function getHostErrorCount($mysql, $monitorGroupId = 0, $onlyNew = false) { |
|
|
|
|
|
|
488
|
|
|
$sql = ''; |
|
489
|
|
|
$monitorGroupId = (int)$monitorGroupId; |
|
490
|
|
|
if($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
491
|
|
|
if($onlyNew) $sql .= " and lastStatusChanged = 1 "; |
|
492
|
|
|
return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors where isBlocked = 1 $sql"); |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
View Code Duplication |
public static function getHostCleanCount($mysql, $monitorGroupId = 0, $onlyNew = false) { |
|
|
|
|
|
|
496
|
|
|
$sql = ''; |
|
497
|
|
|
$monitorGroupId = (int)$monitorGroupId; |
|
498
|
|
|
if($monitorGroupId > 0) $sql = " and monitorGroupId = $monitorGroupId"; |
|
499
|
|
|
if($onlyNew) $sql .= " and lastStatusChanged = 1 "; |
|
500
|
|
|
return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors where isBlocked = 0 $sql"); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
View Code Duplication |
public static function getHostCount($mysql, $monitorGroupId = 0) { |
|
|
|
|
|
|
504
|
|
|
$sql = ''; |
|
505
|
|
|
$monitorGroupId = (int)$monitorGroupId; |
|
506
|
|
|
if($monitorGroupId > 0) $sql = " where monitorGroupId = $monitorGroupId"; |
|
507
|
|
|
return $mysql->runQueryReturnVar("select COALESCE(count(ipDomain),0) as cnt from monitors $sql"); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
//CREDIT: http://braincrafted.com/php-background-processes/ |
|
511
|
|
|
public static function is_process_running($pid){ |
|
512
|
|
|
$pid = (int)$pid; |
|
513
|
|
|
if($pid == 0) return false; |
|
514
|
|
|
if(file_exists('/proc/'.$pid)){ |
|
515
|
|
|
return true; |
|
516
|
|
|
}else{ |
|
517
|
|
|
return false; |
|
518
|
|
|
} |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
public static function run_in_background($command, $priority = 0) { |
|
522
|
|
|
$log = Setup::$settings['log_path']; |
|
523
|
|
|
if($priority !=0){ |
|
524
|
|
|
$pid = shell_exec("nohup nice -n $priority $command >> $log 2>&1 & echo $!"); |
|
525
|
|
|
}else{ |
|
526
|
|
|
$pid = shell_exec("nohup $command >> $log 2>&1 & echo $!"); |
|
527
|
|
|
} |
|
528
|
|
|
return($pid); |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
|
|
534
|
|
|
|
|
535
|
|
|
|
|
536
|
|
|
|
|
537
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.