|
import os |
|
import subprocess |
|
import gradio as gr |
|
|
|
|
|
APP_PASSWORD = os.getenv("APP_PASSWORD") |
|
|
|
|
|
def execute_command(password, script): |
|
|
|
if password != APP_PASSWORD: |
|
return {"error": "Invalid password!"} |
|
|
|
|
|
if not script: |
|
return {"error": "No script provided!"} |
|
|
|
try: |
|
|
|
process = subprocess.Popen( |
|
script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE |
|
) |
|
stdout, stderr = process.communicate() |
|
|
|
|
|
return { |
|
"stdout": stdout.decode("utf-8"), |
|
"stderr": stderr.decode("utf-8"), |
|
"exit_code": process.returncode |
|
} |
|
except Exception as e: |
|
return {"error": f"Error executing script: {str(e)}"} |
|
|
|
|
|
def gradio_interface(password, script): |
|
return execute_command(password, script) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=gradio_interface, |
|
inputs=[ |
|
gr.Textbox(label="Password", type="password"), |
|
gr.Textbox(label="Script", lines=5, placeholder="Enter your script here...") |
|
], |
|
outputs="json", |
|
title="Command Executor", |
|
description="Provide a password and a shell script to execute commands remotely." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch(share=True, inline=True) |
|
|