2024.8.23
Loading...
Searching...
No Matches
ajax.apache.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/**
11 * Retrieves information about Apache server status, versions, modules, aliases, vhosts, directories, and URLs.
12 * Returns a JSON-encoded array with the collected data.
13 */
14
15// Declare global variables
17
18// Initialize result array
19$result = array(
20 'checkport' => '',
21 'versions' => '',
22 'modulescount' => '',
23 'aliasescount' => '',
24 'vhostscount' => '',
25 'moduleslist' => '',
26 'aliaseslist' => '',
27 'wwwdirectory' => '',
28 'vhostslist' => '',
29);
30
31/**
32 * Check the status of Apache ports and update the result array.
33 */
34$port = $bearsamppBins->getApache()->getPort();
35$sslPort = $bearsamppBins->getApache()->getSslPort();
36
40
41if ($bearsamppBins->getApache()->isEnable()) {
42 if ($bearsamppBins->getApache()->checkPort($sslPort, true)) {
43 $result['checkport'] .= '<span class="m-1 float-end badge text-bg-success">' . sprintf($textServiceStarted, $sslPort) . ' (SSL)</span>';
44 } else {
45 $result['checkport'] .= '<span class="m-1 float-end badge text-bg-danger">' . $textServiceStopped . ' (SSL)</span>';
46 }
47 if ($bearsamppBins->getApache()->checkPort($port)) {
48 $result['checkport'] .= '<span class="m-1 float-end badge text-bg-success">' . sprintf($textServiceStarted, $port) . '</span>';
49 } else {
50 $result['checkport'] .= '<span class="m-1 float-end badge text-bg-danger">' . $textServiceStopped . '</span>';
51 }
52} else {
53 $result['checkport'] = '<span class="m-1 float-end badge text-bg-secondary">' . $textDisabled . '</span>';
54}
55
56/**
57 * Retrieve and format the list of Apache versions.
58 */
59foreach ($bearsamppBins->getApache()->getVersionList() as $version) {
60 if ($version != $bearsamppBins->getApache()->getVersion()) {
61 $result['versions'] .= '<span class="m-1 badge float-end text-bg-secondary">' . $version . '</span>';
62 } else {
63 $result['versions'] .= '<span class="m-1 badge float-end text-bg-primary">' . $bearsamppBins->getApache()->getVersion() . '</span>';
64 }
65}
66
67/**
68 * Count and format the number of Apache modules.
69 */
70$modules = count($bearsamppBins->getApache()->getModules());
71$modulesLoaded = count($bearsamppBins->getApache()->getModulesLoaded());
72$result['modulescount'] .= '<span class="m-1 float-end badge text-bg-primary">' . $modulesLoaded . ' / ' . $modules . '</span>';
73
74/**
75 * Count and format the number of Apache aliases.
76 */
77$result['aliasescount'] .= '<span class="m-1 float-end badge text-bg-primary">' . count($bearsamppBins->getApache()->getAlias()) . '</span>';
78
79/**
80 * Count and format the number of Apache virtual hosts.
81 */
82$result['vhostscount'] .= '<span class="m-1 float-end badge text-bg-primary">' . count($bearsamppBins->getApache()->getVhosts()) . '</span>';
83
84/**
85 * Retrieve and format the list of Apache modules from the configuration.
86 */
87foreach ($bearsamppBins->getApache()->getModulesFromConf() as $moduleName => $moduleStatus) {
88 if ($moduleStatus == ActionSwitchApacheModule::SWITCH_ON) {
89 $result['moduleslist'] .= '<span class="p-1 col col-xs-12"><i class="fa-regular fa-circle-check"></i> <strong>' . $moduleName . '</strong></span>';
90 } else {
91 $result['moduleslist'] .= '<span class="p-1 col col-xs-12"><i class="fa-regular fa-circle"></i> ' . $moduleName . '</span>';
92 }
93}
94
95/**
96 * Retrieve and format the list of Apache aliases.
97 */
98foreach ($bearsamppBins->getApache()->getAlias() as $alias) {
99 $result['aliaseslist'] .= '<div class="float-start p-1"><a class="btn btn-outline-dark" target="_blank" href="' . $bearsamppRoot->getLocalUrl($alias) . '"><i class="fa-solid fa-link"></i> ' . $alias . '</a></div>';
100}
101
102/**
103 * Retrieve and format the list of Apache www directories.
104 */
105foreach ($bearsamppBins->getApache()->getWwwDirectories() as $wwwDirectory) {
106 $result['wwwdirectory'] .= '<div class="float-start p-1"><a class="btn btn-outline-dark" target="_blank" href="' . $bearsamppRoot->getLocalUrl($wwwDirectory) . '"><i class="fa-solid fa-link"></i> ' . $wwwDirectory . '</a></div>';
107}
108
109/**
110 * Retrieve and format the list of Apache virtual hosts.
111 */
112foreach ($bearsamppBins->getApache()->getVhostsUrl() as $vhost => $enabled) {
113 if ($enabled) {
114 $result['vhostslist'] .= '<div class="float-start p-1"><a class="btn btn-outline-dark" target="_blank" href="http://' . $vhost . '"><i class="fa-regular fa-circle-check"></i> ' . $vhost . '</a></div>';
115 } else {
116 $result['vhostslist'] .= '<div class="float-start p-1"><a class="btn btn-outline-dark" target="_blank" href="http://' . $vhost . '"><i class="fa-regular fa-circle"></i> ' . $vhost . '</a></div>';
117 }
118}
119
120/**
121 * Output the result array as a JSON-encoded string.
122 */
123echo json_encode($result);
$result
foreach($bearsamppBins->getApache() ->getVersionList() as $version) $modules
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
$port
$textServiceStarted
$modulesLoaded
$sslPort
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED
const DISABLED