|
Server IP : 217.21.85.138 / Your IP : 216.73.216.103 Web Server : LiteSpeed System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64 User : u915722082 ( 915722082) PHP Version : 7.4.33 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF Directory (0755) : /home/u915722082/public_html/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
/**
* File Change Monitor Script (Final Optimized Version)
* Detects Added / Modified / Deleted files inside your /domains folder.
* Fully supports Hostinger symlink structure.
* Correctly excludes cron-log.txt and internal files.
*/
date_default_timezone_set('Asia/Kolkata');
// === SETTINGS ===
$mainFolder = '/home/u915722082/domains'; // Main folder to monitor
$logFile = __DIR__ . '/cron-log.txt'; // Log file
$oldListFile = __DIR__ . '/filelist.json'; // Snapshot file
// Initial Log
file_put_contents($logFile, "\n=== Scan Start: " . date('Y-m-d H:i:s') . " ===\n", FILE_APPEND);
// === FUNCTION: SCAN ALL FILES RECURSIVELY ===
function getAllFiles($dir) {
$allFiles = [];
// IMPORTANT: FOLLOW SYMLINKS (Hostinger required)
$rii = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$dir,
FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS
)
);
// Files to exclude from scanning
$excludeFiles = [
realpath(__FILE__),
realpath(__DIR__ . '/cron-log.txt'),
realpath(__DIR__ . '/filelist.json'),
'/home/u915722082/domains/rrg-iitm.com/public_html/total_views.txt',
'/home/u915722082/domains/rrg-iitm.com/public_html/visitor-ips.txt',
'/home/u915722082/domains/rrg-iitm.com/public_html/unique-visitors.txt',
];
foreach ($rii as $file) {
if ($file->isFile()) {
$path = $file->getPathname();
$relativePath = str_replace('\\', '/', $path);
// Skip cron-log.txt universally (avoid false modification logs)
if (basename($path) === 'cron-log.txt') continue;
// Skip script, snapshot, and manually excluded files
if (in_array(realpath($path), $excludeFiles)) continue;
// Skip session folders
if (preg_match('#/storage/framework/sessions/#', $relativePath)) continue;
// Record file details
$allFiles[$path] = [
'size' => $file->getSize(),
'mtime' => $file->getMTime(),
];
}
}
return $allFiles;
}
// === LOAD PREVIOUS SNAPSHOT ===
$previousData = file_exists($oldListFile)
? json_decode(file_get_contents($oldListFile), true)
: [];
$currentData = getAllFiles($mainFolder);
// === COMPARE FILES ===
$added = array_diff_key($currentData, $previousData);
$deleted = array_diff_key($previousData, $currentData);
$modified = [];
foreach ($currentData as $file => $info) {
if (isset($previousData[$file])) {
if (
$info['size'] !== $previousData[$file]['size'] ||
$info['mtime'] !== $previousData[$file]['mtime']
) {
$modified[$file] = $info;
}
}
}
// === LOG CHANGES ===
if (!empty($added) || !empty($deleted) || !empty($modified)) {
$log = "=== CHANGE DETECTED (" . date('Y-m-d H:i:s') . ") ===\n";
if (!empty($added)) {
$log .= "Added Files:\n";
foreach ($added as $file => $info) {
$log .= " + $file\n";
}
$log .= "\n";
}
if (!empty($modified)) {
$log .= "Modified Files:\n";
foreach ($modified as $file => $info) {
$log .= " * $file\n";
}
$log .= "\n";
}
if (!empty($deleted)) {
$log .= "Deleted Files:\n";
foreach ($deleted as $file => $info) {
$log .= " - $file\n";
}
$log .= "\n";
}
$log .= "--------------------------------------------\n";
file_put_contents($logFile, $log, FILE_APPEND);
}
// === SAVE NEW SNAPSHOT (Pretty JSON) ===
file_put_contents($oldListFile, json_encode($currentData, JSON_PRETTY_PRINT));
// Final Log
file_put_contents($logFile, "Scan Completed: " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
?>