Shadow-Here


Server : Apache/2.4.41 (Ubuntu)
System : Linux cls 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : iscuser ( 1001)
PHP Version : 7.4.12
Disable Function : shell_exec,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /home/checkfile/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :
Current File : //home/checkfile/file_watch_discord.py
import time
from datetime import datetime
import requests
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import argparse


class DiscordNotifierHandler(FileSystemEventHandler):
    def __init__(self, webhook_url):
        self.webhook_url = webhook_url

    def notify_discord(self, message):
        data = {"content": message}
        try:
            response = requests.post(self.webhook_url, json=data)
            if response.status_code == 204:
                print("Discord notification sent.")
            else:
                print(f"Failed Discord notification: {response.status_code}")
        except Exception as e:
            print(f"Error sending Discord notification: {e}")

    def on_modified(self, event):
        if not event.is_directory:
            msg = f":warning: File modified: `{event.src_path}` at {datetime.now()}"
            print(msg)
            self.notify_discord(msg)

    def on_created(self, event):
        if not event.is_directory:
            msg = f":new: File created: `{event.src_path}` at {datetime.now()}"
            print(msg)
            self.notify_discord(msg)

    def on_deleted(self, event):
        if not event.is_directory:
            msg = f":x: File deleted: `{event.src_path}` at {datetime.now()}"
            print(msg)
            self.notify_discord(msg)


def watch_directory(path_to_watch, webhook_url):
    event_handler = DiscordNotifierHandler(webhook_url)
    observer = Observer()
    observer.schedule(event_handler, path=path_to_watch, recursive=True)
    observer.start()
    print(f"Started watching directory: {path_to_watch}")

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
        print("Stopped watching directory.")

    observer.join()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Watch a directory and send Discord notifications on file changes.")
    parser.add_argument("--watch", required=True, help="Path to the directory to watch")
    parser.add_argument("--webhook", required=True, help="Discord webhook URL")

    args = parser.parse_args()

    watch_directory(args.watch, args.webhook)

Samx