Bearsampp 2026.7.11
Loading...
Searching...
No Matches
ajax.summary.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 'binapache' => '',
21 'binmailpit' => '',
22 'binmariadb' => '',
23 'binmysql' => '',
24 'binpostgresql' => '',
25 'binmemcached' => '',
26 'binnodejs' => '',
27 'binphp' => '',
28 'binxlight' => '',
29);
30
31// Template for download link
32$dlMoreTpl = '<a href="' . HttpClient::getWebsiteUrl( 'module/%s', '#releases' ) . '" target="_blank" title="' . $downloadTitle . '"><span class="float-end download-icon-wrapper"><i class="fa-solid fa-cloud-arrow-down"></i></span></a>';
33
34try {
40 $apachePort = $bearsamppBins->getApache()->getPort();
41 $apacheSslPort = $bearsamppBins->getApache()->getSslPort();
42 $apacheLabel = 'bg-secondary';
43 if ( $bearsamppBins->getApache()->isEnable() ) {
44 $apacheLabel = 'bg-danger';
45 if ( $bearsamppBins->getApache()->checkPort( $apachePort ) ) {
46 if ( $bearsamppBins->getApache()->checkPort( $apacheSslPort, true ) ) {
47 $apacheLabel = 'bg-success';
48 }
49 else {
50 $apacheLabel = 'bg-warning';
51 }
52 }
53 }
54 $result['binapache'] = sprintf( $dlMoreTpl, 'apache' );
55 $result['binapache'] .= '<span class = " float-end badge ' . $apacheLabel . '">' . $bearsamppBins->getApache()->getVersion() . '</span>';
56}
57catch ( Exception $e ) {
58 Log::error('Error getting summary for Apache: ' . $e->getMessage());
59 $result['binapache'] = '<span class="float-end badge bg-danger">Error</span>';
60}
61
62try {
68 $mailpitPort = $bearsamppBins->getMailpit()->getSmtpPort();
69 $mailpitLabel = 'bg-secondary';
70 if ( $bearsamppBins->getMailpit()->isEnable() ) {
71 $mailpitLabel = 'bg-danger';
72 if ( $bearsamppBins->getMailpit()->checkPort( $mailpitPort ) ) {
73 $mailpitLabel = 'bg-success';
74 }
75 }
76 $result['binmailpit'] = sprintf( $dlMoreTpl, 'mailpit' );
77 $result['binmailpit'] .= '<span class = " float-end badge ' . $mailpitLabel . '">' . $bearsamppBins->getMailpit()->getVersion() . '</span>';
78}
79catch ( Exception $e ) {
80 Log::error('Error getting summary for Mailpit: ' . $e->getMessage());
81 $result['binmailpit'] = '<span class="float-end badge bg-danger">Error</span>';
82}
83
84try {
90 $xlightPort = $bearsamppBins->getXlight()->getPort();
91 $xlightLabel = 'bg-secondary';
92 if ( $bearsamppBins->getXlight()->isEnable() ) {
93 $xlightLabel = 'bg-danger';
94 if ( $bearsamppBins->getXlight()->checkPort( $xlightPort ) ) {
95 $xlightLabel = 'bg-success';
96 }
97 }
98 $result['binxlight'] = sprintf( $dlMoreTpl, 'xlight' );
99 $result['binxlight'] .= '<span class = " float-end badge ' . $xlightLabel . '">' . $bearsamppBins->getXlight()->getVersion() . '</span>';
100}
101catch ( Exception $e ) {
102 Log::error('Error getting summary for Xlight: ' . $e->getMessage());
103 $result['binxlight'] = '<span class="float-end badge bg-danger">Error</span>';
104}
105
106try {
112 $mariadbPort = $bearsamppBins->getMariadb()->getPort();
113 $mariadbLabel = 'bg-secondary';
114 if ( $bearsamppBins->getMariadb()->isEnable() ) {
115 $mariadbLabel = 'bg-danger';
116 if ( $bearsamppBins->getMariadb()->checkPort( $mariadbPort ) ) {
117 $mariadbLabel = 'bg-success';
118 }
119 }
120 $result['binmariadb'] = sprintf( $dlMoreTpl, 'mariadb' );
121 $result['binmariadb'] .= '<span class = " float-end badge ' . $mariadbLabel . '">' . $bearsamppBins->getMariadb()->getVersion() . '</span>';
122}
123catch ( Exception $e ) {
124 Log::error('Error getting summary for MariaDB: ' . $e->getMessage());
125 $result['binmariadb'] = '<span class="float-end badge bg-danger">Error</span>';
126}
127
128try {
134 $mysqlPort = $bearsamppBins->getMysql()->getPort();
135 $mysqlLabel = 'bg-secondary';
136 if ( $bearsamppBins->getMysql()->isEnable() ) {
137 $mysqlLabel = 'bg-danger';
138 if ( $bearsamppBins->getMysql()->checkPort( $mysqlPort ) ) {
139 $mysqlLabel = 'bg-success';
140 }
141 }
142 $result['binmysql'] = sprintf( $dlMoreTpl, 'mysql' );
143 $result['binmysql'] .= '<span class = " float-end badge ' . $mysqlLabel . '">' . $bearsamppBins->getMysql()->getVersion() . '</span>';
144}
145catch ( Exception $e ) {
146 Log::error('Error getting summary for MySQL: ' . $e->getMessage());
147 $result['binmysql'] = '<span class="float-end badge bg-danger">Error</span>';
148}
149
150try {
156 $postgresqlPort = $bearsamppBins->getPostgresql()->getPort();
157 $postgresqlLabel = 'bg-secondary';
158 if ( $bearsamppBins->getPostgresql()->isEnable() ) {
159 $postgresqlLabel = 'bg-danger';
160 if ( $bearsamppBins->getPostgresql()->checkPort( $postgresqlPort ) ) {
161 $postgresqlLabel = 'bg-success';
162 }
163 }
164 $result['binpostgresql'] = sprintf( $dlMoreTpl, 'postgresql' );
165 $result['binpostgresql'] .= '<span class = " float-end badge ' . $postgresqlLabel . '">' . $bearsamppBins->getPostgresql()->getVersion() . '</span>';
166}
167catch ( Exception $e ) {
168 Log::error('Error getting summary for PostgreSQL: ' . $e->getMessage());
169 $result['binpostgresql'] = '<span class="float-end badge bg-danger">Error</span>';
170}
171
172try {
178 $memcachedPort = $bearsamppBins->getMemcached()->getPort();
179 $memcachedLabel = 'bg-secondary';
180 if ( $bearsamppBins->getMemcached()->isEnable() ) {
181 $memcachedLabel = 'bg-danger';
182 if ( $bearsamppBins->getMemcached()->checkPort( $memcachedPort ) ) {
183 $memcachedLabel = 'bg-success';
184 }
185 }
186 $result['binmemcached'] = sprintf( $dlMoreTpl, 'memcached' );
187 $result['binmemcached'] .= '<span class = " float-end badge ' . $memcachedLabel . '">' . $bearsamppBins->getMemcached()->getVersion() . '</span>';
188}
189catch ( Exception $e ) {
190 Log::error('Error getting summary for Memcached: ' . $e->getMessage());
191 $result['binmemcached'] = '<span class="float-end badge bg-danger">Error</span>';
192}
193
194try {
200 $nodejsLabel = 'bg-secondary';
201 if ( $bearsamppBins->getNodejs()->isEnable() ) {
202 $nodejsLabel = 'bg-success';
203 }
204 $result['binnodejs'] = sprintf( $dlMoreTpl, 'nodejs' );
205 $result['binnodejs'] .= '<span class = " float-end badge ' . $nodejsLabel . '">' . $bearsamppBins->getNodejs()->getVersion() . '</span>';
206}
207catch ( Exception $e ) {
208 Log::error('Error getting summary for NodeJS: ' . $e->getMessage());
209 $result['binnodejs'] = '<span class="float-end badge bg-danger">Error</span>';
210}
211
212try {
218 $phpLabel = 'bg-secondary';
219 if ( $bearsamppBins->getPhp()->isEnable() ) {
220 $phpLabel = 'bg-success';
221 }
222 $result['binphp'] = sprintf( $dlMoreTpl, 'php' );
223 $result['binphp'] .= '<span class = " float-end badge ' . $phpLabel . '">' . $bearsamppBins->getPhp()->getVersion() . '</span>';
224}
225catch ( Exception $e ) {
226 Log::error('Error getting summary for PHP: ' . $e->getMessage());
227 $result['binphp'] = '<span class="float-end badge bg-danger">Error</span>';
228}
229
230// Output the result as JSON
231echo json_encode( $result );
$result
global $bearsamppBins
$dlMoreTpl
$mariadbLabel
$memcachedLabel
$mysqlLabel
$mailpitLabel
$postgresqlLabel
$xlightLabel
$apacheLabel
global $downloadTitle
$apacheSslPort
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
static error($data, $file=null)