/
/
home
/
u523034047
/
domains
Server: in-mum-web1112.main-hosting.eu (62.72.28.111)
You: 216.73.216.4
PHP 8.3.16
Dir:
/home/u523034047/domains
Edit:
/home/u523034047/domains/file_monitor.php
<?php /** * File Monitor Script * Path: /home/u523034047/domains/file_monitor.php * Author: Harish (secured by ChatGPT) * * Scans all domains under /domains/ and sends email if files are changed. */ $scanDir = __DIR__; // Will scan /home/u523034047/domains/ $hashFile = __DIR__ . "/.filehashes.json"; // Stores file hashes $email = "harish8313@gmail.com"; // <-- CHANGE THIS TO YOUR EMAIL $changedFiles = []; $deletedFiles = []; $hashes = []; // Scan all files recursively $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($scanDir)); foreach ($files as $file) { if ($file->isFile()) { $path = $file->getRealPath(); // Ignore monitor file & hash storage if (basename($path) == "file_monitor.php" || basename($path) == ".filehashes.json") { continue; } // Allowed file types to monitor $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); $allowed = ['php', 'html', 'htm', 'js', 'css', 'config', 'htaccess']; // Special case: .htaccess (no extension) if (basename($path) === ".htaccess") { $allowed[] = ''; // accept files with no extension if they are .htaccess } if (!in_array($ext, $allowed) && basename($path) !== ".htaccess") { continue; } $hashes[$path] = md5_file($path); } } // If hash file exists, compare changes if (file_exists($hashFile)) { $oldHashes = json_decode(file_get_contents($hashFile), true); // Check for modified or new files foreach ($hashes as $path => $hash) { if (!isset($oldHashes[$path])) { $changedFiles[] = "[NEW] " . $path; } elseif ($oldHashes[$path] !== $hash) { $changedFiles[] = "[MODIFIED] " . $path; } } // Check for deleted files foreach ($oldHashes as $path => $hash) { if (!isset($hashes[$path])) { $deletedFiles[] = "[DELETED] " . $path; } } // Send email if something changed if ($changedFiles || $deletedFiles) { $subject = "⚠️ File Change Alert on Domains Folder"; $message = "The following changes were detected:\n\n"; $message .= implode("\n", $changedFiles); $message .= "\n"; $message .= implode("\n", $deletedFiles); @mail($email, $subject, $message, "From: monitor@" . $_SERVER['SERVER_NAME']); } } // Save current hashes file_put_contents($hashFile, json_encode($hashes, JSON_PRETTY_PRINT)); echo "File monitor check completed.\n"; ?>
Ukuran: 2.6 KB