File size: 1,552 Bytes
456eb99 b0ab72e 43006ee 456eb99 b0ab72e 456eb99 b0ab72e 43006ee cce6b7e b0ab72e cce6b7e b0ab72e cce6b7e b0ab72e cce6b7e 43006ee b0ab72e 43006ee b0ab72e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import os
import subprocess
import gradio as gr
# Fetch the app password from environment variables
APP_PASSWORD = os.getenv("APP_PASSWORD")
# Function to execute shell commands
def execute_command(password, script):
# Check if the password is correct
if password != APP_PASSWORD:
return {"error": "Invalid password!"}
# Validate the script input
if not script:
return {"error": "No script provided!"}
try:
# Execute the command using subprocess
process = subprocess.Popen(
script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, stderr = process.communicate()
# Return the output and errors
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)}"}
# Define Gradio interface
def gradio_interface(password, script):
return execute_command(password, script)
# Create Gradio app
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."
)
# Launch the Gradio interface
if __name__ == "__main__":
interface.launch(share=True, inline=True)
|