2024.8.23
Loading...
Searching...
No Matches
ajax.postgresql.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 retrieves information about the PostgreSQL service status and versions.
14 * It checks if the PostgreSQL service is enabled, checks the port, and displays a corresponding badge.
15 * It also retrieves the list of PostgreSQL versions and displays them as badges.
16 * The final result is encoded in JSON format and returned.
17 *
18 * @global object $bearsamppBins Provides access to various binaries including PostgreSQL.
19 * @global object $bearsamppLang Provides access to language strings for localization.
20 */
21
22// Initialize result array to store the status and version information
23$result = array(
24 'checkport' => '',
25 'versions' => '',
26);
27
28// Check port
29$port = $bearsamppBins->getPostgresql()->getPort();
30
34
35/**
36 * Check if PostgreSQL service is enabled and update the result array with the port status.
37 * If the service is enabled, it checks if the port is open and updates the status accordingly.
38 * If the service is disabled, it sets the status to disabled.
39 */
40if ($bearsamppBins->getPostgresql()->isEnable()) {
41 if ($bearsamppBins->getPostgresql()->checkPort($port)) {
42 $result['checkport'] .= '<span class="float-end badge text-bg-success">' . sprintf($textServiceStarted, $port) . '</span>';
43 } else {
44 $result['checkport'] .= '<span class="float-end badge text-bg-danger">' . $textServiceStopped . '</span>';
45 }
46} else {
47 $result['checkport'] = '<span class="float-end badge text-bg-secondary">' . $textDisabled . '</span>';
48}
49
50/**
51 * Retrieve the list of PostgreSQL versions and update the result array.
52 * The current version is highlighted with a primary badge, while other versions are displayed with a secondary badge.
53 */
54foreach ($bearsamppBins->getPostgresql()->getVersionList() as $version) {
55 if ($version != $bearsamppBins->getPostgresql()->getVersion()) {
56 $result['versions'] .= '<span class="m-1 badge text-bg-secondary">' . $version . '</span>';
57 } else {
58 $result['versions'] .= '<span class="m-1 badge text-bg-primary">' . $bearsamppBins->getPostgresql()->getVersion() . '</span>';
59 }
60}
61
62// Encode the result array in JSON format and output it
63echo json_encode($result);
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
$textServiceStarted
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED
const DISABLED