1 | #!/usr/bin/php |
---|
2 | <?php |
---|
3 | //$log = file('/var/log/mail.log'); |
---|
4 | |
---|
5 | #$argv0 = array_shift($argv); |
---|
6 | #print_r($argv0); |
---|
7 | //echo $argv[1]; |
---|
8 | |
---|
9 | #var_dump($argv); |
---|
10 | |
---|
11 | $file = $argv[1]; |
---|
12 | |
---|
13 | if (substr($file,-3)==".gz") { |
---|
14 | $open="gzopen"; |
---|
15 | $gets="gzgets"; |
---|
16 | $close="gzclose"; |
---|
17 | } else { |
---|
18 | $open="fopen"; |
---|
19 | $gets="fgets"; |
---|
20 | $close="fclose"; |
---|
21 | } |
---|
22 | |
---|
23 | if (($f = $open($file, "rb")) === FALSE) { |
---|
24 | die("impossible d'ouvrir le log $file"); |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | $imaploginpatt = '^[[:alpha:]]{3} [ :0-9]{11} [._[:alnum:]-]+ imapd: LOGIN, user=[-_.@[:alnum:]]+, ip=\[[.:[:alnum:]]+\], protocol=IMAP'; |
---|
29 | |
---|
30 | $imaplogout = '^[[:alpha:]]{3} [ :0-9]{11} [._[:alnum:]-]+ imapd: (LOGOUT|TIMEOUT|DISCONNECTED), user=[-_.@[:alnum:]]+, ip=\[[.:[:alnum:]]+\],'; |
---|
31 | |
---|
32 | //foreach($log as $log_data){ |
---|
33 | @define('BUFSIZE', 4096); |
---|
34 | |
---|
35 | //$s=$gets($f,BUFSIZE); |
---|
36 | // $s=trim($s); |
---|
37 | //foreach ($s as $log_data) { |
---|
38 | while ($s=$gets($f,BUFSIZE)) { |
---|
39 | $log_data=trim($s); |
---|
40 | |
---|
41 | |
---|
42 | if(ereg($imaploginpatt,$log_data)){ |
---|
43 | $details = explode(" ",$log_data); |
---|
44 | |
---|
45 | $date = $details[1] ." ".$details[0] ." ".$details[2]; |
---|
46 | $mail = substr($details[6], 5, -1); |
---|
47 | $ip = substr($details[7], 4, -2); |
---|
48 | |
---|
49 | echo $details[5] ." "; |
---|
50 | echo $date ." ".$mail ." ".$ip; |
---|
51 | echo " \n"; |
---|
52 | // print_r($r); |
---|
53 | } |
---|
54 | |
---|
55 | if(ereg($imaplogout,$log_data)){ |
---|
56 | $details = explode(" ",$log_data); |
---|
57 | |
---|
58 | $date = $details[1] ." ".$details[0] ." ".$details[2]; |
---|
59 | $mail = substr($details[6], 5, -1); |
---|
60 | $ip = substr($details[7], 4, -2); |
---|
61 | |
---|
62 | echo $details[5] ." "; |
---|
63 | echo $date ." ".$mail ." ".$ip; |
---|
64 | echo " \n"; |
---|
65 | // print_r($details); |
---|
66 | } |
---|
67 | |
---|
68 | } |
---|
69 | ?> |
---|