2024.8.23
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 */
9/**
10 * Include the root configuration file.
11 * This file is expected to set up the environment and include necessary configurations.
12 */
13include_once __DIR__ . '/../../root.php';
14
15/**
16 * @var array $procs
17 * An array of valid process names that can be included.
18 */
19$procs = array(
20 'summary',
21 'latestversion',
22 'apache',
23 'filezilla',
24 'mailhog',
25 'mailpit',
26 'memcached',
27 'mariadb',
28 'mysql',
29 'nodejs',
30 'php',
31 'postgresql',
32 'xlight',
33 'quickpick'
34);
35
36/**
37 * Clean and retrieve the 'proc' POST variable.
38 *
39 * Util::cleanPostVar is assumed to be a method that sanitizes the input to prevent security issues such as SQL injection or XSS.
40 *
41 * @var string $proc The cleaned 'proc' parameter from the POST request.
42 */
43$proc = Util::cleanPostVar('proc', 'text'); // Ensure 'proc' is cleaned and read correctly
44
45/**
46 * Check if the cleaned 'proc' parameter is in the list of valid processes.
47 * If valid, include the corresponding AJAX handler file.
48 * If not valid, return a JSON error message.
49 */
50if (in_array($proc, $procs)) {
51 /**
52 * Include the corresponding AJAX handler file based on the 'proc' parameter.
53 * The file path is constructed dynamically.
54 *
55 * Example: If $proc is 'latestversion', the file 'ajax/ajax.latestversion.php' will be included.
56 */
57 include 'ajax/ajax.' . $proc . '.php'; // This line should correctly include 'ajax.latestversion.php'
58} else {
59 /**
60 * Handle the case where the 'proc' parameter is not valid.
61 * Return a JSON encoded error message indicating the invalid parameter.
62 */
63 echo json_encode(['error' => 'Invalid proc parameter']);
64}
$proc
Definition ajax.php:43
$procs
Definition ajax.php:19
static cleanPostVar($name, $type='text')