📄 Source: command.php
<?php
require_once __DIR__ . '/../auth.php';
require_once __DIR__ . '/../lib/tmux.php';
require_once __DIR__ . '/../lib/servers.php';
require_auth_json();
$CFG = $GLOBALS['__CFG'];
$name = $_POST['server'] ?? '';
$cmd = $_POST['command'] ?? '';
if ($name === '' || strpos($name, '/') !== false || strpos($name, '..') !== false) {
http_response_code(400);
echo json_encode(['ok' => false, 'error' => 'Invalid server name']);
exit;
}
if ($cmd === '') {
http_response_code(400);
echo json_encode(['ok' => false, 'error' => 'Empty command']);
exit;
}
$session = tmux_session_name($CFG['tmux_template'] ?? '%s', $name);
if (!tmux_has_session($session)) {
header('Content-Type: application/json');
echo json_encode(['ok' => false, 'error' => 'Server not running (no tmux session)']);
exit;
}
$ok = tmux_send_command($session, $cmd);
header('Content-Type: application/json');
echo json_encode(['ok' => $ok, 'message' => $ok ? 'Sent' : 'Failed to send']);
← Back