2024.8.23
Loading...
Searching...
No Matches
ajax.mariadb.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
11
12/**
13 * This script generates information about the status of the MariaDB service and its versions.
14 * It checks if the MariaDB service is enabled, checks the port, and retrieves the list of versions.
15 * The output is encoded in JSON format and includes the port status and versions information.
16 *
17 * @global object $bearsamppBins Provides access to various binaries including MariaDB.
18 * @global object $bearsamppLang Provides access to language-specific strings.
19 */
20
21// Initialize result array to store port status and versions information
22$result = array(
23 'checkport' => '',
24 'versions' => '',
25);
26
27// Check port
28$port = $bearsamppBins->getMariadb()->getPort();
29
33
34/**
35 * Check if the MariaDB service is enabled and update the port status accordingly.
36 * If the service is enabled, check if the port is open and update the status.
37 * If the service is disabled, set the status to disabled.
38 */
39if ($bearsamppBins->getMariadb()->isEnable()) {
40 if ($bearsamppBins->getMariadb()->checkPort($port)) {
41 $result['checkport'] .= '<span class="float-end badge text-bg-success">' . sprintf($textServiceStarted, $port) . '</span>';
42 } else {
43 $result['checkport'] .= '<span class="float-end badge text-bg-danger">' . $textServiceStopped . '</span>';
44 }
45} else {
46 $result['checkport'] = '<span class="float-end badge text-bg-secondary">' . $textDisabled . '</span>';
47}
48
49/**
50 * Retrieve the list of available MariaDB versions and update the versions information.
51 * Highlight the current version with a primary badge and other versions with a secondary badge.
52 */
53foreach ($bearsamppBins->getMariadb()->getVersionList() as $version) {
54 if ($version != $bearsamppBins->getMariadb()->getVersion()) {
55 $result['versions'] .= '<span class="m-1 badge text-bg-secondary">' . $version . '</span>';
56 } else {
57 $result['versions'] .= '<span class="m-1 badge text-bg-primary">' . $bearsamppBins->getMariadb()->getVersion() . '</span>';
58 }
59}
60
61// Output the result as a JSON-encoded string
62echo json_encode($result);
$result
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
$port
$textServiceStarted
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED
const DISABLED