50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
$e5_accessLog = '/var/log/apache2/e5_access.log';
|
||
|
|
$twinpol_accessLog = '/var/log/apache2/twinpol_access.log';
|
||
|
|
|
||
|
|
function extractPathsFromLog($logFile) {
|
||
|
|
$paths = [];
|
||
|
|
if (file_exists($logFile)) {
|
||
|
|
$file = fopen($logFile, 'r');
|
||
|
|
if ($file) {
|
||
|
|
while (($line = fgets($file)) !== false) {
|
||
|
|
if (preg_match('/"GET (\/[^ ]+)/', $line, $matches)) {
|
||
|
|
// Remove part after file extension
|
||
|
|
$path = preg_replace('/(\.[a-zA-Z0-9]+)(\?.*)?$/', '$1', $matches[1]);
|
||
|
|
$paths[] = $path;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
fclose($file);
|
||
|
|
} else {
|
||
|
|
echo "Error opening the log file.";
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
echo "Log file does not exist.";
|
||
|
|
}
|
||
|
|
return $paths;
|
||
|
|
}
|
||
|
|
|
||
|
|
$e5_paths = extractPathsFromLog($e5_accessLog);
|
||
|
|
$twinpol_paths = extractPathsFromLog($twinpol_accessLog);
|
||
|
|
|
||
|
|
$conn = new mysqli('localhost', 'root', '5z#JaL', 'mz_logs');
|
||
|
|
if (!$conn->connect_error) {
|
||
|
|
$stmt = $conn->prepare("INSERT IGNORE INTO php_files_log (system, path) VALUES (?, ?)");
|
||
|
|
$stmt->bind_param("ss", $system, $file);
|
||
|
|
|
||
|
|
$system = 'e5';
|
||
|
|
foreach ($e5_paths as $file) {
|
||
|
|
$stmt->execute();
|
||
|
|
}
|
||
|
|
|
||
|
|
$system = 'twinpol';
|
||
|
|
foreach ($twinpol_paths as $file) {
|
||
|
|
$stmt->execute();
|
||
|
|
}
|
||
|
|
|
||
|
|
$stmt->close();
|
||
|
|
$conn->close();
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|