Bearsampp 2025.8.29
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
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
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
59foreach ($bearsamppBins->getApache()->getVersionList() as $version) {
60 $versionBadge = '<span class="m-1 badge text-bg-%s">%s</span>';
61 $isCurrent = $version === $bearsamppBins->getApache()->getVersion();
62
63 $result['versions'] .= sprintf(
64 $versionBadge,
65 $isCurrent ? 'primary' : 'secondary',
66 $version
67 );
68}
69
73$modules = count($bearsamppBins->getApache()->getModules());
74$modulesLoaded = count($bearsamppBins->getApache()->getModulesLoaded());
75$result['modulescount'] .= '<span class="m-1 float-end badge text-bg-primary">' . $modulesLoaded . ' / ' . $modules . '</span>';
76
80$result['aliasescount'] .= '<span class="m-1 float-end badge text-bg-primary">' . count($bearsamppBins->getApache()->getAlias()) . '</span>';
81
85$result['vhostscount'] .= '<span class="m-1 float-end badge text-bg-primary">' . count($bearsamppBins->getApache()->getVhosts()) . '</span>';
86
90foreach ($bearsamppBins->getApache()->getModulesFromConf() as $moduleName => $moduleStatus) {
91 if ($moduleStatus == ActionSwitchApacheModule::SWITCH_ON) {
92 $result['moduleslist'] .= '<span class="p-1 col col-xs-12"><i class="fa-regular fa-circle-check"></i> <strong>' . $moduleName . '</strong></span>';
93 } else {
94 $result['moduleslist'] .= '<span class="p-1 col col-xs-12"><i class="fa-regular fa-circle"></i> ' . $moduleName . '</span>';
95 }
96}
97
101foreach ($bearsamppBins->getApache()->getAlias() as $alias) {
102 $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>';
103}
104
108foreach ($bearsamppBins->getApache()->getWwwDirectories() as $wwwDirectory) {
109 $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>';
110}
111
115foreach ($bearsamppBins->getApache()->getVhostsUrl() as $vhost => $enabled) {
116 if ($enabled) {
117 $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>';
118 } else {
119 $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>';
120 }
121}
122
126echo json_encode($result);
$result
foreach($bearsamppBins->getApache() ->getVersionList() as $version) $modules
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
$port
$textServiceStarted
$modulesLoaded
$sslPort
const DISABLED
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED