#!/usr/bin/env bash # ============================================================================== # OnlineHızTesti Edge Server - Otomatik Kurulum Scripti (OoklaServer Benzeri) # Kullanım: curl -sSL https://onlinehiztesti.com/install.sh | bash # ============================================================================== set -e RED='\033[0;31m' GREEN='\033[0;32m' CYAN='\033[0;36m' YELLOW='\033[1;33m' BOLD='\033[1m' NC='\033[0m' # No Color clear echo -e "${CYAN}${BOLD}" echo "==================================================================" echo " 🚀 OnlineHızTesti Server - Otomatik Linux Kurulumu" echo " https://onlinehiztesti.com" echo "==================================================================" echo -e "${NC}" # Root kontrolü if [ "$EUID" -ne 0 ]; then echo -e "${RED}[HATA] Bu kurulum root yetkisi gerektirir. Lütfen 'sudo bash' ile çalıştırın.${NC}" exit 1 fi INSTALL_DIR="/opt/onlinehiztesti-server" SERVICE_NAME="onlinehiztesti-server" SERVER_PORT=8080 echo -e "${YELLOW}[*] Sistem paketleri ve Python ortamı kontrol ediliyor...${NC}" # Paket yöneticisi tespiti ve paket kurulumu if command -v apt-get &>/dev/null; then apt-get update -qq apt-get install -y -qq python3 python3-pip curl openssl &>/dev/null elif command -v dnf &>/dev/null; then dnf install -y -q python3 python3-pip curl openssl &>/dev/null elif command -v yum &>/dev/null; then yum install -y -q python3 python3-pip curl openssl &>/dev/null fi # Kurulum klasörü oluştur mkdir -p "$INSTALL_DIR" cd "$INSTALL_DIR" # Gerekli Python bağımlılıklarını kur (FastAPI + Uvicorn) echo -e "${YELLOW}[*] Yüksek hızlı ağ motoru bağımlılıkları kuruluyor (FastAPI/Uvicorn)...${NC}" python3 -m pip install --quiet --upgrade pip &>/dev/null || true python3 -m pip install --quiet fastapi uvicorn &>/dev/null # Dış IP tespiti PUBLIC_IP=$(curl -s -4 https://ifconfig.me || curl -s -4 https://api.ipify.org || echo "127.0.0.1") # Sunucu bilgilerini al (Piped bash uyumlu /dev/tty) echo "" echo -e "${CYAN}${BOLD}--- Sunucu Bilgileri ---${NC}" if [ -t 0 ]; then read -p "Firma / Sponsor Adı (Örn: Netwifi): " SPONSOR_NAME read -p "Şehir (Örn: Konya): " CITY_NAME read -p "Sunucu Adı (Örn: Konya - Netwifi Çumra): " NODE_NAME read -p "Test Portu [Varsayılan: 8080]: " USER_PORT elif [ -e /dev/tty ]; then read -p "Firma / Sponsor Adı (Örn: Netwifi): " SPONSOR_NAME < /dev/tty read -p "Şehir (Örn: Konya): " CITY_NAME < /dev/tty read -p "Sunucu Adı (Örn: Konya - Netwifi Çumra): " NODE_NAME < /dev/tty read -p "Test Portu [Varsayılan: 8080]: " USER_PORT < /dev/tty else SPONSOR_NAME="Netwifi" CITY_NAME="Konya" NODE_NAME="Konya - Netwifi Veri Merkezi" USER_PORT="8080" fi SPONSOR_NAME=${SPONSOR_NAME:-"Netwifi"} CITY_NAME=${CITY_NAME:-"Konya"} NODE_NAME=${NODE_NAME:-"$CITY_NAME - $SPONSOR_NAME"} SERVER_PORT=${USER_PORT:-8080} # Konfigürasyon dosyasını oluştur cat < "$INSTALL_DIR/config.json" { "name": "$NODE_NAME", "city": "$CITY_NAME", "country": "Türkiye", "sponsor": "$SPONSOR_NAME", "ip": "$PUBLIC_IP", "port": $SERVER_PORT } EOF # Ultra-Hafif, Sıfır CPU & Sıfır Bellek Edge Sunucu Kodunu Oluştur cat <<'EOF' > "$INSTALL_DIR/server.py" import os import json from pathlib import Path from fastapi import FastAPI, Request, Response from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse, JSONResponse BASE_DIR = Path(__file__).resolve().parent CONFIG_FILE = BASE_DIR / "config.json" config = { "name": "OnlineHızTesti Node", "city": "İstanbul", "country": "Türkiye", "sponsor": "ISP Partner", "port": 8080 } if CONFIG_FILE.exists(): try: with open(CONFIG_FILE, "r", encoding="utf-8") as f: config.update(json.load(f)) except Exception: pass app = FastAPI(title="OnlineHızTesti Edge Server", version="2.0.0") app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=False, allow_methods=["*"], allow_headers=["*"], expose_headers=["*"], ) # 1 MB'lık sabit RAM tamponu (Zero Memory Allocation) CHUNK_SIZE = 1024 * 1024 ZERO_CHUNK = b"0" * CHUNK_SIZE @app.get("/api/info") def get_info(): return { "status": "online", "name": config.get("name"), "city": config.get("city"), "country": config.get("country"), "sponsor": config.get("sponsor"), "version": "2.0.0" } @app.get("/api/ping") @app.head("/api/ping") def ping(): response = Response(status_code=200) response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" response.headers["Pragma"] = "no-cache" return response async def zero_memory_stream(total_bytes: int): sent = 0 while sent < total_bytes: remaining = total_bytes - sent if remaining >= CHUNK_SIZE: yield ZERO_CHUNK sent += CHUNK_SIZE else: yield ZERO_CHUNK[:remaining] sent += remaining @app.get("/api/download") async def download_stream(bytes: int = 50 * 1024 * 1024): total_bytes = min(max(bytes, 1024 * 1024), 500 * 1024 * 1024) headers = { "Content-Type": "application/octet-stream", "Content-Length": str(total_bytes), "Cache-Control": "no-store, no-cache, must-revalidate, max-age=0" } return StreamingResponse(zero_memory_stream(total_bytes), headers=headers, media_type="application/octet-stream") @app.post("/api/upload") async def upload_sink(request: Request): total_bytes = 0 async for chunk in request.stream(): total_bytes += len(chunk) return JSONResponse(content={"status": "ok", "bytes_received": total_bytes}) if __name__ == "__main__": import uvicorn port = int(config.get("port", 8080)) uvicorn.run(app, host="0.0.0.0", port=port, log_level="warning") EOF # Systemd Servisi Oluştur echo -e "${YELLOW}[*] Systemd arka plan servisi yapılandırılıyor...${NC}" cat < /etc/systemd/system/${SERVICE_NAME}.service [Unit] Description=OnlineHizTesti Edge Speedtest Server After=network.target [Service] Type=simple User=root WorkingDirectory=$INSTALL_DIR ExecStart=/usr/bin/python3 $INSTALL_DIR/server.py Restart=always RestartSec=3 [Install] WantedBy=multi-user.target EOF # Güvenlik Duvarı (Firewall) Ayarı if command -v ufw &>/dev/null && ufw status | grep -q "active"; then ufw allow "$SERVER_PORT/tcp" &>/dev/null || true elif command -v firewall-cmd &>/dev/null && systemctl is-active --quiet firewalld; then firewall-cmd --add-port="$SERVER_PORT/tcp" --permanent &>/dev/null || true firewall-cmd --reload &>/dev/null || true fi # Servisi başlat systemctl daemon-reload systemctl enable --now ${SERVICE_NAME}.service sleep 2 # Test et echo -e "${YELLOW}[*] Yerel servis testi yapılıyor...${NC}" TEST_RESP=$(curl -s "http://127.0.0.1:$SERVER_PORT/api/info" || echo "") if [[ "$TEST_RESP" == *"online"* ]]; then echo -e "${GREEN}${BOLD}" echo "==================================================================" echo " ✅ TEBRİKLER! OnlineHızTesti Server Başarıyla Kuruldu!" echo "==================================================================" echo -e "${NC}" echo -e " 📍 Sunucu Adı : ${BOLD}$NODE_NAME${NC}" echo -e " 🏢 Sponsor : ${BOLD}$SPONSOR_NAME${NC}" echo -e " 🌐 Şehir : ${BOLD}$CITY_NAME${NC}" echo -e " 🔌 Port : ${BOLD}$SERVER_PORT${NC}" echo -e " 🔗 Test URL : ${CYAN}http://$PUBLIC_IP:$SERVER_PORT/api/info${NC}" echo "" echo -e "${YELLOW}Sunucunuzu web sitemize eklemek için şu adrese gidin:${NC}" echo -e "${BOLD}https://onlinehiztesti.com/sunucu-ekle?host=http://$PUBLIC_IP:$SERVER_PORT&name=$(echo "$NODE_NAME" | sed 's/ /%20/g')&city=$(echo "$CITY_NAME" | sed 's/ /%20/g')&sponsor=$(echo "$SPONSOR_NAME" | sed 's/ /%20/g')${NC}" echo "" echo " Servis Komutları:" echo " - Durum Kontrolü : systemctl status $SERVICE_NAME" echo " - Yeniden Başlat : systemctl restart $SERVICE_NAME" echo " - Logları İzle : journalctl -u $SERVICE_NAME -f" echo "==================================================================" else echo -e "${RED}[UYARI] Servis kuruldu ancak yerel porttan yanıt alınamadı. Lütfen 'systemctl status $SERVICE_NAME' komutunu kontrol edin.${NC}" fi