> to the job's own log with stdin from /dev/null, so a dry run cannot consume the // request's stdin or discard the history of previous runs. // // REQUEST // POST id= [location=/absolute/path] [extra_args=…] // // RESPONSE // {"ok":true} launched — not completed // {"ok":false,"error":"Invalid id"|"Script not found: …"|"Invalid location" // |"Invalid extra_args"} // // DEPENDS ON // include/scheduler.php vv_job_log_path(), vv_job_flags() // run_job.sh the single execution path for every job // ═══════════════════════════════════════════════════════════════════════════════════════════════ header('Content-Type: application/json'); require_once dirname(__DIR__) . '/include/scheduler.php'; $id = trim($_POST['id'] ?? ''); if (!$id || !preg_match('/^[a-zA-Z0-9_.\/\-]+\.sh$/', $id) || str_contains($id, '..')) { echo json_encode(['ok' => false, 'error' => 'Invalid id']); exit; } $script = SCRIPTS_DIR . '/' . $id; if (!file_exists($script)) { echo json_encode(['ok' => false, 'error' => 'Script not found: ' . $id]); exit; } $logFile = vv_job_log_path($id); $logDir = dirname($logFile); if (!is_dir($logDir)) mkdir($logDir, 0755, true); $location = trim($_POST['location'] ?? ''); if ($location && (!str_starts_with($location, '/') || str_contains($location, '..') || preg_match('/[\x00\n\r]/', $location))) { echo json_encode(['ok' => false, 'error' => 'Invalid location']); exit; } // Control characters are rejected outright — a newline would end the command line and start // a second one. Everything that survives is split on whitespace and escaped per token, so // the shell never parses any of it as syntax. $extra_args = trim($_POST['extra_args'] ?? ''); if ($extra_args !== '' && preg_match('/[\x00-\x1f\x7f]/', $extra_args)) { echo json_encode(['ok' => false, 'error' => 'Invalid extra_args']); exit; } $runner = dirname(__DIR__) . '/run_job.sh'; $flags = vv_job_flags($id); $locArg = $location ? ' ' . escapeshellarg('--location=' . $location) : ''; $extraStr = ''; foreach (preg_split('/\s+/', $extra_args, -1, PREG_SPLIT_NO_EMPTY) as $tok) { $extraStr .= ' ' . escapeshellarg($tok); } // setsid for the same reason as api/run.php — a dry run is stoppable too, and Stop resolves the // group from the stat file without caring which endpoint started the job. exec('setsid nohup bash ' . escapeshellarg($runner) . ' ' . escapeshellarg($id) . ' ' . escapeshellarg($script) . ' --dry-run' . ($flags ? " $flags" : '') . ' --manual' . $locArg . $extraStr . ' >> ' . escapeshellarg($logFile) . ' 2>&1 true]);