| import gradio as gr |
| import requests |
| import os |
| from requests.auth import HTTPBasicAuth |
|
|
| def execute_wp_cli(command, args): |
| """ |
| Função para executar comandos WP-CLI via API REST. |
| """ |
| try: |
| |
| wp_app_password = os.getenv("WP_APP_PASSWORD") |
| wp_user = os.getenv("WP_USER") |
| wp_url = os.getenv("WP_PATH") |
|
|
| |
| if not wp_app_password: |
| return "Erro: Variável de ambiente WP_APP_PASSWORD não definida." |
| if not wp_user: |
| return "Erro: Variável de ambiente WP_USER não definida." |
| if not wp_url: |
| return "Erro: Variável de ambiente WP_PATH não definida." |
|
|
| |
| api_url = f"{wp_url}/wp-json/wp/v2" |
|
|
| |
| auth = HTTPBasicAuth(wp_user, wp_app_password) |
|
|
| |
| command_url = f"{api_url}/{command.replace(' ', '/')}" |
|
|
| |
| args = "test" |
|
|
| |
| response = requests.post(command_url, auth=auth, json={"args": args}) |
|
|
| if response.status_code != 200: |
| return f"Erro ao executar o comando: {response.text}" |
| |
| return response.json() |
| except Exception as e: |
| return f"Erro: {str(e)}" |
|
|
| |
| commands = [ |
| "plugin list", |
| "plugin activate", |
| "plugin deactivate", |
| "theme list", |
| "theme activate", |
| "post list", |
| "post create", |
| "post update", |
| "post delete", |
| ] |
|
|
| |
| iface = gr.Interface( |
| fn=execute_wp_cli, |
| inputs=[ |
| gr.Dropdown(choices=commands, label="Comando WP-CLI"), |
| gr.Textbox(lines=1, placeholder="Digite os argumentos (se necessário)", label="Argumentos") |
| ], |
| outputs="text", |
| title="Painel de Controle WP-CLI", |
| description="Selecione um comando WP-CLI e insira os argumentos necessários." |
| ) |
|
|
| |
| iface.launch() |
|
|