forked from poppyred/1.6.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.old.access.logs.php
executable file
·79 lines (56 loc) · 2.68 KB
/
exec.old.access.logs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["debug"]=true;$GLOBALS["VERBOSE"]=true;ini_set('display_errors', 1); ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);}
if($GLOBALS["VERBOSE"]){echo "DEBUG::: ".@implode(" ", $argv)."\n";}
$GLOBALS["AS_ROOT"]=true;
$GLOBALS["NOLOCK"]=true;
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
include_once(dirname(__FILE__)."/ressources/class.user.inc");
include_once(dirname(__FILE__)."/ressources/class.system.network.inc");
include_once(dirname(__FILE__)."/ressources/class.mysql.inc");
include_once(dirname(__FILE__)."/ressources/class.mysql.squid.builder.php");
include_once(dirname(__FILE__)."/ressources/class.squid.tail.inc");
include_once(dirname(__FILE__)."/ressources/class.ccurl.inc");
include_once(dirname(__FILE__)."/ressources/class.os.system.inc");
include_once(dirname(__FILE__)."/framework/class.unix.inc");
include_once(dirname(__FILE__)."/framework/frame.class.inc");
function ParseLogsDir(){
$d=0;$h=0;
$sock=new sockets();
$workingDir=$sock->GET_INFO("SquidOldLogsDefaultDir");
if (!$handle = opendir($workingDir)) {@mkdir($workingDir,0755,true);return;}
$squidtail=new squid_tail();
while (false !== ($filename = readdir($handle))) {
if($filename=="."){continue;}if($filename==".."){continue;}
$targetFile="$workingDir/$filename";
if(!is_file($targetFile)){continue;}
$d++;$h++;$c=0;
if($d>300){
if(systemMaxOverloaded()){$array_load=sys_getloadavg();$internal_load=$array_load[0];events("ParseSquidLogBrutProcess()::$workingDir:: Overloaded: $internal_load system, break loop...",__LINE__);break;}
$d=0;
}
$handle = @fopen($targetFile, "r");
if (!$handle) {events("Failed to open file",__LINE__);continue;}
while (!feof($handle)){
$c++;
$buffer =trim(fgets($handle, 4096));
if(!$squidtail->parse_tail($buffer,null)){continue;}
}
}
}
function events($text,$line=0){
if(function_exists("debug_backtrace")){$trace=debug_backtrace();if(isset($trace[1])){$sourcefile=basename($trace[1]["file"]);$sourcefunction=$trace[1]["function"];$sourceline=$trace[1]["line"];}if($line>0){$sourceline=$line;}$text="$text ($sourcefunction::$sourceline)";}
events_tail($text);
}
function events_tail($text){
if(!isset($GLOBALS["CLASS_UNIX"])){$GLOBALS["CLASS_UNIX"]=new unix();}
//if($GLOBALS["VERBOSE"]){echo "$text\n";}
$pid=@getmypid();
$date=@date("H:i:s");
$logFile="/var/log/artica-postfix/auth-tail.debug";
$size=@filesize($logFile);
if($size>1000000){@unlink($logFile);}
$f = @fopen($logFile, 'a');
$GLOBALS["CLASS_UNIX"]->events(basename(__FILE__)." $date $text");
@fwrite($f, "$pid ".basename(__FILE__)." $date $text\n");
@fclose($f);
}