-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave.php
67 lines (58 loc) · 2.68 KB
/
save.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
<?php
ini_set('display_errors',1);
set_time_limit(0);
require __DIR__ . '/vendor/autoload.php';
use MVar\Apache2LogParser\AccessLogParser;
use MVar\LogParser\LogIterator;
// Access log format from your Apache configuration
// It can be any of predefined `AccessLogParser::FORMAT_*` constants or custom string
$parser = new AccessLogParser('%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"');
$fichiers=array();
if ($handle = opendir(__DIR__."/logs")) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$fichiers[]=$entry;
}
}
closedir($handle);
}
try{
$db = new PDO('mysql:host=localhost;dbname=hack', 'root', '');
}catch(Exception $e){
echo "Erreur : ".$e->getMessage();
}
$query="INSERT INTO `logs` ( `remote_host`, `identity`, `remote_user`, `time`, `method`,`request_line`, `response_code`, `bytes_sent`, `request`, `request_headers`) VALUES (:remote_host, :identity, :remote_user, :time, :method, :request_line, :response_code, :bytes_sent, :request, :request_headers)";
$queryFinal=$db->prepare($query);
foreach($fichiers as $fichier){
echo $fichier."<br>";
foreach (new LogIterator(__DIR__.'/logs/'.$fichier, $parser) as $line => $data) {
//var_dump($data,date('Y-m-d H:i:s',strtotime($data['time'])));
$r=$queryFinal->execute(array(
'remote_host' => $data['remote_host'],
'identity' => $data['identity'],
'remote_user' => $data['remote_user'],
'time' => date('Y-m-d H:i:s',strtotime($data['time'])),
'method' => $data['request']['method'],
'request_line' => $data['request_line'],
'response_code' => $data['response_code'],
'bytes_sent' => $data['bytes_sent'],
'request' => json_encode($data['request']),
'request_headers' => json_encode($data['request_headers'])
));
if($r==false)
var_dump($data,$queryFinal->errorCode()." : ".$queryFinal->errorInfo(),array(
'remote_host' => $data['remote_host'],
'identity' => $data['identity'],
'remote_user' => $data['remote_user'],
'time' => date('Y-m-d H:i:s',strtotime($data['time'])),
'method' => $data['request']['method'],
'request_line' => $data['request_line'],
'response_code' => $data['response_code'],
'bytes_sent' => $data['bytes_sent'],
'request' => json_encode($data['request']),
'request_headers' => json_encode($data['request_headers'])
)
);
}
}
?>