Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
ajax.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
13include_once __DIR__ . '/../../root.php';
14
19
27 'summary' => __DIR__ . '/ajax/ajax.summary.php',
28 'latestversion' => __DIR__ . '/ajax/ajax.latestversion.php',
29 'apache' => __DIR__ . '/ajax/ajax.apache.php',
30 'mailpit' => __DIR__ . '/ajax/ajax.mailpit.php',
31 'memcached' => __DIR__ . '/ajax/ajax.memcached.php',
32 'mariadb' => __DIR__ . '/ajax/ajax.mariadb.php',
33 'mysql' => __DIR__ . '/ajax/ajax.mysql.php',
34 'nodejs' => __DIR__ . '/ajax/ajax.nodejs.php',
35 'php' => __DIR__ . '/ajax/ajax.php.php',
36 'postgresql' => __DIR__ . '/ajax/ajax.postgresql.php',
37 'xlight' => __DIR__ . '/ajax/ajax.xlight.php',
38 'quickpick' => __DIR__ . '/ajax/ajax.quickpick.php',
39 'toggleenhancedquickpick' => __DIR__ . '/ajax/ajax.toggle.enhancedquickpick.php',
40 'applymoduleconfig' => __DIR__ . '/ajax/ajax.apply.moduleconfig.php'
41];
42
49 'quickpick', // Installs modules
50 'toggleenhancedquickpick', // Changes configuration
51 'applymoduleconfig' // Applies configuration changes
52];
53
61$proc = Util::cleanPostVar('proc', 'text'); // Ensure 'proc' is cleaned and read correctly
62
66if (in_array($proc, $csrfProtectedEndpoints, true)) {
67 if (!Csrf::validateRequest()) {
68 http_response_code(403);
69 header('Content-Type: application/json');
70 echo json_encode([
71 'error' => 'CSRF validation failed',
72 'message' => 'Invalid or expired security token. Please refresh the page and try again.'
73 ]);
74 exit;
75 }
76}
77
83if (isset($procMap[$proc]) && file_exists($procMap[$proc])) {
87 include $procMap[$proc];
88} else {
94 $errorMessage = 'Invalid proc parameter';
95 if (!empty($proc)) {
96 $errorMessage .= ': "' . htmlspecialchars($proc) . '" is not a valid procedure';
97 } else {
98 $errorMessage .= ': no procedure was specified';
99 }
100 echo json_encode(['error' => $errorMessage]);
101}
$csrfProtectedEndpoints
Definition ajax.php:48
$procMap
Definition ajax.php:26
$proc
Definition ajax.php:61
static validateRequest($removeAfterValidation=false)
static init()
static cleanPostVar($name, $type='text')