#!/bin/bash # ============================================================================== # CyberPanel Security Shield & CPU Guard - Otomatik Kurulum Betiği (v1.0.0) # Kaynak: https://tayfuntaskin.com.tr/blog/cyberpanel-security-shield-ve-cpu-guard-modulu-rootkit-tarama-otomatik-koruma # ============================================================================== set -e echo "======================================================================" echo " CyberPanel Security Shield & CPU Guard Kurulumu Başlatılıyor..." echo "======================================================================" if [ "$(id -u)" -ne 0 ]; then echo "[HATA] Bu kurulum betiği root yetkisiyle çalıştırılmalıdır!" exit 1 fi if [ ! -d "/usr/local/CyberCP" ]; then echo "[HATA] Sunucuda CyberPanel (/usr/local/CyberCP) bulunamadı!" exit 1 fi BASE_URL="https://tayfuntaskin.com.tr/assets/downloads/cyberpanel-security-shield" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "[1/5] Modül çekirdek dosyaları kopyalanıyor..." mkdir -p /usr/local/CyberCP/firewall/templates/firewall mkdir -p /usr/local/CyberCP/securityGuardData if [ -f "$SCRIPT_DIR/security_guard.py" ] && [ -f "$SCRIPT_DIR/securityShield.html" ]; then cp "$SCRIPT_DIR/security_guard.py" /usr/local/CyberCP/firewall/security_guard.py cp "$SCRIPT_DIR/securityShield.html" /usr/local/CyberCP/firewall/templates/firewall/securityShield.html else curl -fsSL "$BASE_URL/security_guard.py" -o /usr/local/CyberCP/firewall/security_guard.py curl -fsSL "$BASE_URL/securityShield.html" -o /usr/local/CyberCP/firewall/templates/firewall/securityShield.html fi chmod +x /usr/local/CyberCP/firewall/security_guard.py echo "[2/5] CyberPanel Django URL, View ve Menü entegrasyonları yapılıyor..." python3 - << 'PYCODE' import os urls_path = "/usr/local/CyberCP/firewall/urls.py" with open(urls_path, "r", encoding="utf-8") as f: u_content = f.read() if "securityShield" not in u_content: addition = """ # Security Shield & CPU Guard path('securityShield', views.securityShield, name='securityShield'), path('securityShieldApi', views.securityShieldApi, name='securityShieldApi'), ] """ u_content = u_content.rstrip() if u_content.endswith("]"): u_content = u_content[:-1] + addition with open(urls_path, "w", encoding="utf-8") as f: f.write(u_content) print(" -> firewall/urls.py güncellendi.") views_path = "/usr/local/CyberCP/firewall/views.py" with open(views_path, "r", encoding="utf-8") as f: v_content = f.read() if "def securityShield(" not in v_content: v_addition = """ from django.http import JsonResponse from plogical.httpProc import httpProc from plogical.acl import ACLManager from . import security_guard import os import signal import subprocess def securityShield(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] != 1: return redirect(loadLoginPage) proc = httpProc(request, 'firewall/securityShield.html', None, 'admin') return proc.render() except KeyError: return redirect(loadLoginPage) def securityShieldApi(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] != 1: return JsonResponse({'status': 0, 'error_message': 'Unauthorized'}) data = json.loads(request.body.decode('utf-8')) if request.body else {} action = data.get('action', 'status') if action == 'status': return JsonResponse(security_guard.get_dashboard_status()) elif action == 'scan': res = security_guard.scan_server() return JsonResponse({'status': 1, 'scan': res}) elif action == 'remediate': res = security_guard.remediate_threats() return JsonResponse({'status': 1, 'result': res}) elif action == 'cpuguard': res = security_guard.enforce_cpu_guard() return JsonResponse({'status': 1, 'result': res}) elif action == 'save_config': cfg = security_guard.save_config(data.get('config', {})) return JsonResponse({'status': 1, 'config': cfg}) elif action == 'proc_action': pid = int(data.get('pid', 0)) sub = data.get('sub_action', '') if pid <= 1: return JsonResponse({'status': 0, 'message': 'Geçersiz PID'}) if sub == 'renice': subprocess.run(f"renice -n 19 -p {pid} >/dev/null 2>&1; ionice -c 3 -p {pid} >/dev/null 2>&1", shell=True) security_guard.append_event("MANUAL", "INFO", f"PID {pid} Yavaşlatıldı", f"Kullanıcı müdahalesi ile PID {pid} nice +19 yapıldı.", "Renice +19") return JsonResponse({'status': 1, 'message': f'PID {pid} düşük önceliğe (Nice +19) çekildi.'}) elif sub == 'kill': os.kill(pid, signal.SIGKILL) security_guard.append_event("MANUAL", "WARNING", f"PID {pid} Sonlandırıldı", f"Kullanıcı müdahalesi ile PID {pid} öldürüldü.", "SIGKILL") return JsonResponse({'status': 1, 'message': f'PID {pid} başarıyla sonlandırıldı.'}) return JsonResponse({'status': 0, 'message': 'Unknown action'}) except Exception as e: return JsonResponse({'status': 0, 'message': str(e)}) """ with open(views_path, "w", encoding="utf-8") as f: f.write(v_content + v_addition) print(" -> firewall/views.py güncellendi.") index_path = "/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html" if os.path.exists(index_path): with open(index_path, "r", encoding="utf-8") as f: idx_content = f.read() if "securityShield" not in idx_content: target_menu = """
{% trans "Security" %}
""" replacement_menu = target_menu + """
{% trans "Security Shield & CPU" %}
""" idx_content = idx_content.replace(target_menu, replacement_menu, 1) target_search = "// Security (admin)" replacement_search = target_search + "\n {l:'Security Shield & CPU Guard', h:'{% url \"securityShield\" %}', i:'fa-shield-virus', g:'{% trans \"Security\" %}'}," idx_content = idx_content.replace(target_search, replacement_search, 1) with open(index_path, "w", encoding="utf-8") as f: f.write(idx_content) print(" -> Sol menü ve Ctrl+K arama çubuğu güncellendi.") hub_path = "/usr/local/CyberCP/baseTemplate/templates/baseTemplate/hub.html" if os.path.exists(hub_path): with open(hub_path, "r", encoding="utf-8") as f: hub_content = f.read() if "securityShield" not in hub_content: target_hub = """ {% elif section == 'security' %}

{% trans "SECURITY" %}

""" replacement_hub = target_hub + """
Security Shield & CPU
Rootkit Tarama & CPU Koruma
""" hub_content = hub_content.replace(target_hub, replacement_hub, 1) with open(hub_path, "w", encoding="utf-8") as f: f.write(hub_content) print(" -> Security Hub ekranı güncellendi.") PYCODE echo "[3/5] Rutin Cron Kalkanı (3 dk) ve İlk Güvenlik Taraması başlatılıyor..." python3 /usr/local/CyberCP/firewall/security_guard.py --init echo "[4/5] CyberPanel (lscpd) servisi yeniden başlatılıyor..." pkill -9 -f lswsgi 2>/dev/null || true systemctl restart lscpd echo "[5/5] Kurulum başarıyla tamamlandı!" echo "======================================================================" echo " CyberPanel -> Sol Menü -> 'Security Shield & CPU' üzerinden" echo " veya https://SUNUCU_IP:8090/firewall/securityShield adresinden" echo " modüle hemen erişebilirsiniz." echo "======================================================================"