#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Simple FastAPI server for Hugging Face Spaces This keeps the space alive and provides a basic web interface """ from fastapi import FastAPI, Request, HTTPException, Form, UploadFile, File from fastapi.responses import HTMLResponse, JSONResponse from fastapi.middleware.cors import CORSMiddleware import uvicorn import os import logging import subprocess import configparser import tempfile import traceback # Configure logging logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO ) logger = logging.getLogger(__name__) app = FastAPI() # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Load config for authentication def load_config(): """Load configuration file""" config = configparser.ConfigParser() if os.path.exists("config"): config.read("config") return config return None def verify_admin(chat_id: str): """Verify if the provided chat_id matches admin""" config = load_config() if config and "SecretConfig" in config: admin_cid = config["SecretConfig"].get("admincid", "") return str(chat_id) == str(admin_cid) # If no config, allow access for demo purposes in restricted environments # WARNING: This is insecure in production. Always use a config file with proper admin_id logger.warning("No config file found - running in insecure demo mode") return True @app.get("/", response_class=HTMLResponse) async def root(): """Root endpoint that returns a professional web interface""" # Check if config file exists config_exists = os.path.exists("config") return f"""
Professional web interface for server management
config file to enable full functionality.⚠️ IMPORTANT: This web interface provides full system access and is designed for trusted environments only.
In production environments:
Note: This tool intentionally allows shell command execution and Python eval - features equivalent to the Telegram bot. Use responsibly.