Bearsampp 2026.9.23
Loading...
Searching...
No Matches
ajax.php File Reference

Go to the source code of this file.

Variables

 $ajaxProcRaw = isset($_POST['proc']) ? $_POST['proc'] : ''
 $ajaxReadOnlyProcs
 $csrfProtectedEndpoints
 $proc = UtilInput::cleanPostVar('proc', 'text')
 $procMap
if(in_array( $proc, $csrfProtectedEndpoints, true)) if(isset($procMap[$proc]) &&file_exists($procMap[$proc])) else
 if (in_array( $ajaxProcRaw, $ajaxReadOnlyProcs, true))

Variable Documentation

◆ $ajaxProcRaw

$ajaxProcRaw = isset($_POST['proc']) ? $_POST['proc'] : ''

AJAX request dispatcher for the Bearsampp homepage.

Receives a 'proc' POST parameter, maps it to a whitelisted handler file and includes the matching AJAX handler. Read-only polling handlers run through a silent logging buffer, while state-changing handlers are restricted to POST requests and protected by CSRF validation. Silent logging gate for read-only homepage polls.

Read-only polls (e.g. summary, service status, latest version) are the main source of homepage log growth because root.php re-initialises every class on each 2s poll. To keep the log useful without the noise, such polls run inside a silent logging transaction:

  1. Log\startSilentBuffer() holds every entry in memory (ERROR still writes immediately so critical failures are never lost).
  2. The handler response body (the exact homepage state rendered) is hashed.
  3. At shutdown (registered BEFORE Log\init(), so it runs before Log\flush) the hash is compared with the one stored for this proc:
    • identical -> nothing changed on the homepage -> rollback (discard)
    • different -> a real state change occurred -> commit (write) + store

No "heartbeat" entries are produced - identical polls write nothing at all. State-changing endpoints (quickpick, toggleenhancedquickpick, applymoduleconfig) are excluded and always log normally.

Definition at line 38 of file ajax.php.

◆ $ajaxReadOnlyProcs

$ajaxReadOnlyProcs
Initial value:
= array(
'summary',
'latestversion',
'apache',
'mailpit',
'memcached',
'mariadb',
'mysql',
'nodejs',
'php',
'postgresql',
'xlight',
'reloadstatus',
)

Definition at line 39 of file ajax.php.

◆ $csrfProtectedEndpoints

$csrfProtectedEndpoints
Initial value:
= [
'quickpick',
'toggleenhancedquickpick',
'applymoduleconfig',
'clearcache'
]

Define which endpoints require CSRF protection. Read-only endpoints (GET-like operations) don't need CSRF protection. Write operations (POST that changes state) require CSRF protection.

Definition at line 137 of file ajax.php.

◆ $proc

◆ $procMap

$procMap
Initial value:
= [
'summary' => __DIR__ . '/ajax/ajax.summary.php',
'latestversion' => __DIR__ . '/ajax/ajax.latestversion.php',
'apache' => __DIR__ . '/ajax/ajax.apache.php',
'mailpit' => __DIR__ . '/ajax/ajax.mailpit.php',
'memcached' => __DIR__ . '/ajax/ajax.memcached.php',
'mariadb' => __DIR__ . '/ajax/ajax.mariadb.php',
'mysql' => __DIR__ . '/ajax/ajax.mysql.php',
'nodejs' => __DIR__ . '/ajax/ajax.nodejs.php',
'php' => __DIR__ . '/ajax/ajax.php.php',
'postgresql' => __DIR__ . '/ajax/ajax.postgresql.php',
'xlight' => __DIR__ . '/ajax/ajax.xlight.php',
'quickpick' => __DIR__ . '/ajax/ajax.quickpick.php',
'toggleenhancedquickpick' => __DIR__ . '/ajax/ajax.toggle.enhancedquickpick.php',
'applymoduleconfig' => __DIR__ . '/ajax/ajax.apply.moduleconfig.php',
'reloadstatus' => __DIR__ . '/ajax/ajax.reload.status.php',
'clearcache' => __DIR__ . '/ajax/ajax.clearcache.php'
]

Definition at line 104 of file ajax.php.

◆ else

if (!empty( $proc)) else
Initial value:
{
$errorMessage = 'Invalid proc parameter'

Validate CSRF token for protected endpoints. Sessions are only started for state-changing endpoints so that read-only polling endpoints (e.g. reload status) never block on a session lock held by a long-running operation such as a module install. Check if the cleaned 'proc' parameter exists in our secure mapping. If valid, include the corresponding AJAX handler file using the pre-defined path. If not valid, return a JSON error message.

Definition at line 188 of file ajax.php.

◆ if

if(in_array($ajaxProcRaw, $ajaxReadOnlyProcs, true)) ( in_array( $ajaxProcRaw, $ajaxReadOnlyProcs, true) )

Include the root configuration file. This file is expected to set up the environment and include necessary configurations.

Definition at line 54 of file ajax.php.