Skip to content

Introduce FR_EXEC_PROBE config constant (WorkerLauncher + controllers)#113

Open
Giermann wants to merge 3 commits intoerror311:masterfrom
Giermann:patch-2
Open

Introduce FR_EXEC_PROBE config constant (WorkerLauncher + controllers)#113
Giermann wants to merge 3 commits intoerror311:masterfrom
Giermann:patch-2

Conversation

@Giermann
Copy link
Copy Markdown

Add a new config constant FR_EXEC_PROBE (default: true). When set to false, FileRise treats exec/shell_exec as completely unavailable, regardless of what isFunctionEnabled() reports.

Changes to WorkerLauncher:

  • resolvePhpCli(): return null immediately when FR_EXEC_PROBE === false, before any filesystem checks
  • canSpawnBackground(): add FR_EXEC_PROBE === false guard; also call resolvePhpCli() to verify a working binary actually exists
  • canRunForeground(): add prefersSync() short-circuit (no exec needed in sync mode); add FR_EXEC_PROBE === false guard; call resolvePhpCli() to verify
  • hasShell(): add @ operator to is_file('/bin/sh') and is_executable('/bin/sh') to suppress open_basedir warnings before they reach the custom error handler

Changes to FileController and FolderController:

  • Add runJobInRequest() private method that executes file/folder move and copy operations synchronously in-request via FileModel directly (for files) and via FolderController::moveFolder() with output buffering (for folders). Sets the job file to "done" or "error" on completion.
  • In enqueueTransferJob(): add an early guard before spawnWorker() - if !canSpawnBackground() && !canRunForeground(), call runJobInRequest() directly instead of spawning a worker.
  • Also call runJobInRequest() as a second fallback after a failed spawn attempt, so that unexpected spawn failures on other restricted hosts are handled gracefully too.
  • In FileController::transferJobStart(): respect FR_WORKER_MODE=sync by setting $payload['async'] = !WorkerLauncher::prefersSync(). When sync mode is active, capture the response via ob_start()/ob_get_clean() and wrap it in a job-compatible envelope (ok, jobId, status: done) so the frontend poll loop receives the expected structure.
  • In FileController::downloadZip(): add an early guard - if no exec is available and format is zip, fall back to synchronous FileModel::createZipArchive() (pure PHP, no exec needed). For 7z format, return a clear 501 error immediately instead of timing out.
  • In FileController::thumbnail(): replace !function_exists('exec') with !WorkerLauncher::canRunForeground() and return HTTP 204 (no content) instead of 501, so the browser silently skips the thumbnail without showing an error to the user.

To use on a restricted shared host, add to config.php:

define('FR_WORKER_MODE', 'sync');
define('FR_EXEC_PROBE', false);

Added checks to suppress warnings for shell execution and refined conditions for determining executable PHP CLI.
Add runJobInRequest method to handle file and folder transfers synchronously when no workers can be spawned. Enhance error handling and job status updates.
Add runJobInRequest method for synchronous folder transfer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant