| import gradio as gr |
| import subprocess |
|
|
| |
| USERS = {"admin": "1234", "demo": "demo"} |
|
|
| |
| sessions = {} |
|
|
| |
| def run_command(cmd, session_id): |
| if session_id not in sessions: |
| return "⚠ Giriş yapmalısınız!" |
| history = sessions[session_id].setdefault("history", []) |
| if not cmd.strip(): |
| return "\n".join(history) |
| try: |
| output = subprocess.check_output( |
| cmd, shell=True, stderr=subprocess.STDOUT, text=True |
| ) |
| except subprocess.CalledProcessError as e: |
| output = e.output |
| entry = f"$ {cmd}\n{output}" |
| history.append(entry) |
| if len(history) > 50: |
| history = history[-50:] |
| sessions[session_id]["history"] = history |
| return "\n".join(history) |
|
|
| |
| def clear_terminal(session_id): |
| if session_id in sessions: |
| sessions[session_id]["history"] = [] |
| return "" |
|
|
| |
| def login(username, password): |
| if username in USERS and USERS[username] == password: |
| session_id = username |
| sessions[session_id] = {"history": []} |
| return f"✅ Hoşgeldin {username}", session_id, gr.update(visible=False), gr.update(visible=True) |
| else: |
| return "❌ Hatalı kullanıcı adı veya şifre", "", gr.update(visible=True), gr.update(visible=False) |
| |
| def logout(session_id): |
| if session_id in sessions: |
| del sessions[session_id] |
| return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), "" |
|
|
| with gr.Blocks(css=""" |
| body {background-color: #0d1117; color: #e6edf3; font-family: 'Inter', monospace;} |
| .login-box, .dash-box, .terminal-box {background: #161b22; padding: 20px; border-radius: 12px; box-shadow: 0 0 20px rgba(0,0,0,.3);} |
| .btn-primary {background-color: #238636 !important; color: white !important;} |
| .btn-danger {background-color: #da3633 !important; color: white !important;} |
| .btn-secondary {background-color: #0a58ca !important; color: white !important;} |
| #terminal-output {background: #000; color: #0f0; font-family: monospace; font-size: 14px; overflow-y: scroll;} |
| #terminal-input textarea {background: #000; color: #0f0; font-family: monospace;} |
| """) as demo: |
| gr.Markdown("## ☁️ VDS Panel (Gelişmiş Demo)") |
|
|
| |
| with gr.Row(visible=True) as login_page: |
| with gr.Column(scale=1): |
| with gr.Group(elem_classes="login-box"): |
| gr.Markdown("### 🔑 Giriş Yap") |
| username = gr.Textbox(label="Kullanıcı Adı", placeholder="admin") |
| password = gr.Textbox(label="Şifre", type="password") |
| login_btn = gr.Button("Giriş", elem_classes="btn-primary") |
| login_status = gr.Markdown() |
|
|
| |
| with gr.Row(visible=False) as dashboard_page: |
| with gr.Column(): |
| with gr.Group(elem_classes="dash-box"): |
| gr.Markdown("### 📊 Dashboard") |
| gr.Markdown("Hoşgeldiniz! Buradan terminale geçebilirsiniz.") |
| open_terminal = gr.Button("🖥️ Terminale Git", elem_classes="btn-primary") |
| logout_btn = gr.Button("🚪 Logout", elem_classes="btn-danger") |
|
|
| |
| with gr.Row(visible=False) as terminal_page: |
| with gr.Column(): |
| with gr.Group(elem_classes="terminal-box"): |
| gr.Markdown("### 🖥️ Terminal") |
| cmd_input = gr.Textbox(label="Komut Gir", placeholder="ör: ls -la", lines=1, elem_id="terminal-input") |
| terminal_output = gr.Textbox(label="Çıktı", lines=20, elem_id="terminal-output") |
| with gr.Row(): |
| run_btn = gr.Button("▶ Çalıştır", elem_classes="btn-primary") |
| stop_btn = gr.Button("⏹ Durdur / Reset", elem_classes="btn-secondary") |
| back_btn = gr.Button("← Dashboard’a Dön", elem_classes="btn-danger") |
|
|
| |
| session_id = gr.State("") |
|
|
| |
| login_btn.click( |
| login, |
| inputs=[username, password], |
| outputs=[login_status, session_id, login_page, dashboard_page] |
| ) |
|
|
| |
| logout_btn.click( |
| logout, |
| inputs=[session_id], |
| outputs=[login_page, dashboard_page, terminal_page, terminal_output] |
| ) |
|
|
| |
| open_terminal.click(lambda: (gr.update(visible=False), gr.update(visible=True)), None, [dashboard_page, terminal_page]) |
|
|
| |
| back_btn.click(lambda: (gr.update(visible=True), gr.update(visible=False)), None, [dashboard_page, terminal_page]) |
|
|
| |
| run_btn.click(run_command, inputs=[cmd_input, session_id], outputs=terminal_output) |
|
|
| |
| stop_btn.click(clear_terminal, inputs=[session_id], outputs=terminal_output) |
|
|
| |
| cmd_input.submit(run_command, inputs=[cmd_input, session_id], outputs=terminal_output) |
|
|
| demo.launch() |
|
|