2024.8.23
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
10/**
11 * Generates a JSON output containing information about various bins such as Apache, Filezilla, MailHog, Mailpit, MariaDB, MySQL, PostgreSQL, Memcached, Node.js, and PHP.
12 * The output includes download links, version numbers, and status labels for each bin.
13 */
14
15// Declare global variables
17
18// Initialize result array
19$result = array(
20 'binapache' => '',
21 'binfilezilla' => '',
22 'binmailhog' => '',
23 'binmailpit' => '',
24 'binmariadb' => '',
25 'binmysql' => '',
26 'binpostgresql' => '',
27 'binmemcached' => '',
28 'binnodejs' => '',
29 'binphp' => '',
30 'binxlight' => '',
31);
32
33// Template for download link
34$dlMoreTpl = '<a href="' . Util::getWebsiteUrl( 'module/%s', '#releases' ) . '" target="_blank" title="' . $downloadTitle . '"><span class="float-end" style="margin-left:.5rem;"><i class="fa-solid fa-cloud-arrow-down"></i></span></a>';
35
36try {
37 /**
38 * Apache Bin Information
39 * Retrieves the port and SSL port for Apache, checks if Apache is enabled and the ports are open.
40 * Sets the appropriate label based on the status and appends the version and download link to the result.
41 */
42 $apachePort = $bearsamppBins->getApache()->getPort();
43 $apacheSslPort = $bearsamppBins->getApache()->getSslPort();
44 $apacheLabel = 'bg-secondary';
45 if ( $bearsamppBins->getApache()->isEnable() ) {
46 $apacheLabel = 'bg-danger';
47 if ( $bearsamppBins->getApache()->checkPort( $apachePort ) ) {
48 if ( $bearsamppBins->getApache()->checkPort( $apacheSslPort, true ) ) {
49 $apacheLabel = 'bg-success';
50 }
51 else {
52 $apacheLabel = 'bg-warning';
53 }
54 }
55 }
56 $result['binapache'] = sprintf( $dlMoreTpl, 'apache' );
57 $result['binapache'] .= '<span class = " float-end badge ' . $apacheLabel . '">' . $bearsamppBins->getApache()->getVersion() . '</span>';
58}
59catch ( Exception $e ) {
60 $result['binapache'] = 'An error occurred getting the summary of Apache. ' . $e->getMessage();
61}
62
63try {
64 /**
65 * Filezilla Bin Information
66 * Retrieves the port and SSL port for Filezilla, checks if Filezilla is enabled and the ports are open.
67 * Sets the appropriate label based on the status and appends the version and download link to the result.
68 */
69 $filezillaPort = $bearsamppBins->getFilezilla()->getPort();
70 $filezillaSslPort = $bearsamppBins->getFilezilla()->getSslPort();
71 $filezillaLabel = 'bg-secondary';
72 if ( $bearsamppBins->getFilezilla()->isEnable() ) {
73 $filezillaLabel = 'bg-danger';
74 if ( $bearsamppBins->getFilezilla()->checkPort( $filezillaPort ) ) {
75 if ( $bearsamppBins->getFilezilla()->checkPort( $filezillaSslPort, true ) ) {
76 $filezillaLabel = 'bg-success';
77 }
78 else {
79 $filezillaLabel = 'bg-warning';
80 }
81 }
82 }
83 $result['binfilezilla'] = sprintf( $dlMoreTpl, 'filezilla' );
84 $result['binfilezilla'] .= '<span class = " float-end badge ' . $filezillaLabel . '">' . $bearsamppBins->getFilezilla()->getVersion() . '</span>';
85}
86catch ( Exception $e ) {
87 $result['binfilezilla'] = 'An error occurred getting the summary of Filezilla. ' . $e->getMessage();
88}
89
90try {
91 /**
92 * MailHog Bin Information
93 * Retrieves the SMTP port for MailHog, checks if MailHog is enabled and the port is open.
94 * Sets the appropriate label based on the status and appends the version and download link to the result.
95 */
96 $mailhogPort = $bearsamppBins->getMailhog()->getSmtpPort();
97 $mailhogLabel = 'bg-secondary';
98 if ( $bearsamppBins->getMailhog()->isEnable() ) {
99 $mailhogLabel = 'bg-danger';
100 if ( $bearsamppBins->getMailhog()->checkPort( $mailhogPort ) ) {
101 $mailhogLabel = 'bg-success';
102 }
103 }
104 $result['binmailhog'] = sprintf( $dlMoreTpl, 'mailhog' );
105 $result['binmailhog'] .= '<span class = " float-end badge ' . $mailhogLabel . '">' . $bearsamppBins->getMailhog()->getVersion() . '</span>';
106}
107catch ( Exception $e ) {
108 $result['binmailhog'] = 'An error occurred getting the summary of Mailhog. ' . $e->getMessage();
109}
110
111try {
112 /**
113 * Mailpit Bin Information
114 * Retrieves the SMTP port for Mailpit, checks if Mailpit is enabled and the port is open.
115 * Sets the appropriate label based on the status and appends the version and download link to the result.
116 */
117 $mailpitPort = $bearsamppBins->getMailpit()->getSmtpPort();
118 $mailpitLabel = 'bg-secondary';
119 if ( $bearsamppBins->getMailpit()->isEnable() ) {
120 $mailpitLabel = 'bg-danger';
121 if ( $bearsamppBins->getMailpit()->checkPort( $mailpitPort ) ) {
122 $mailpitLabel = 'bg-success';
123 }
124 }
125 $result['binmailpit'] = sprintf( $dlMoreTpl, 'mailpit' );
126 $result['binmailpit'] .= '<span class = " float-end badge ' . $mailpitLabel . '">' . $bearsamppBins->getMailpit()->getVersion() . '</span>';
127}
128catch ( Exception $e ) {
129 $result['binmailpit'] = 'An error occurred getting the summary of Mailpit. ' . $e->getMessage();
130}
131
132try {
133 /**
134 * Xlight Bin Information
135 * Retrieves the port for Xlight, checks if Xlight is enabled and the port is open.
136 * Sets the appropriate label based on the status and appends the version and download link to the result.
137 */
138 $xlightPort = $bearsamppBins->getXlight()->getPort();
139 $xlightLabel = 'bg-secondary';
140 if ( $bearsamppBins->getXlight()->isEnable() ) {
141 $xlightLabel = 'bg-danger';
142 if ( $bearsamppBins->getXlight()->checkPort( $xlightPort ) ) {
143 $xlightLabel = 'bg-success';
144 }
145 }
146 $result['binxlight'] = sprintf( $dlMoreTpl, 'xlight' );
147 $result['binxlight'] .= '<span class = " float-end badge ' . $xlightLabel . '">' . $bearsamppBins->getXlight()->getVersion() . '</span>';
148}
149catch ( Exception $e ) {
150 $result['binxlight'] = 'An error occurred getting the summary of Xlight. ' . $e->getMessage();
151}
152
153try {
154 /**
155 * MariaDB Bin Information
156 * Retrieves the port for MariaDB, checks if MariaDB is enabled and the port is open.
157 * Sets the appropriate label based on the status and appends the version and download link to the result.
158 */
159 $mariadbPort = $bearsamppBins->getMariadb()->getPort();
160 $mariadbLabel = 'bg-secondary';
161 if ( $bearsamppBins->getMariadb()->isEnable() ) {
162 $mariadbLabel = 'bg-danger';
163 if ( $bearsamppBins->getMariadb()->checkPort( $mariadbPort ) ) {
164 $mariadbLabel = 'bg-success';
165 }
166 }
167 $result['binmariadb'] = sprintf( $dlMoreTpl, 'mariadb' );
168 $result['binmariadb'] .= '<span class = " float-end badge ' . $mariadbLabel . '">' . $bearsamppBins->getMariadb()->getVersion() . '</span>';
169}
170catch ( Exception $e ) {
171 $result['binmariadb'] = 'An error occurred getting the summary of MariaDB. ' . $e->getMessage();
172}
173
174try {
175 /**
176 * MySQL Bin Information
177 * Retrieves the port for MySQL, checks if MySQL is enabled and the port is open.
178 * Sets the appropriate label based on the status and appends the version and download link to the result.
179 */
180 $mysqlPort = $bearsamppBins->getMysql()->getPort();
181 $mysqlLabel = 'bg-secondary';
182 if ( $bearsamppBins->getMysql()->isEnable() ) {
183 $mysqlLabel = 'bg-danger';
184 if ( $bearsamppBins->getMysql()->checkPort( $mysqlPort ) ) {
185 $mysqlLabel = 'bg-success';
186 }
187 }
188 $result['binmysql'] = sprintf( $dlMoreTpl, 'mysql' );
189 $result['binmysql'] .= '<span class = " float-end badge ' . $mysqlLabel . '">' . $bearsamppBins->getMysql()->getVersion() . '</span>';
190}
191catch ( Exception $e ) {
192 $result['binmysql'] = 'An error occurred getting the summary of MySql. ' . $e->getMessage();
193}
194
195try {
196 /**
197 * PostgreSQL Bin Information
198 * Retrieves the port for PostgreSQL, checks if PostgreSQL is enabled and the port is open.
199 * Sets the appropriate label based on the status and appends the version and download link to the result.
200 */
201 $postgresqlPort = $bearsamppBins->getPostgresql()->getPort();
202 $postgresqlLabel = 'bg-secondary';
203 if ( $bearsamppBins->getPostgresql()->isEnable() ) {
204 $postgresqlLabel = 'bg-danger';
205 if ( $bearsamppBins->getPostgresql()->checkPort( $postgresqlPort ) ) {
206 $postgresqlLabel = 'bg-success';
207 }
208 }
209 $result['binpostgresql'] = sprintf( $dlMoreTpl, 'postgresql' );
210 $result['binpostgresql'] .= '<span class = " float-end badge ' . $postgresqlLabel . '">' . $bearsamppBins->getPostgresql()->getVersion() . '</span>';
211}
212catch ( Exception $e ) {
213 $result['binpostgresql'] = 'An error occurred getting the summary of Postgresql. ' . $e->getMessage();
214}
215
216try {
217 /**
218 * Memcached Bin Information
219 * Retrieves the port for Memcached, checks if Memcached is enabled and the port is open.
220 * Sets the appropriate label based on the status and appends the version and download link to the result.
221 */
222 $memcachedPort = $bearsamppBins->getMemcached()->getPort();
223 $memcachedLabel = 'bg-secondary';
224 if ( $bearsamppBins->getMemcached()->isEnable() ) {
225 $memcachedLabel = 'bg-danger';
226 if ( $bearsamppBins->getMemcached()->checkPort( $memcachedPort ) ) {
227 $memcachedLabel = 'bg-success';
228 }
229 }
230 $result['binmemcached'] = sprintf( $dlMoreTpl, 'memcached' );
231 $result['binmemcached'] .= '<span class = " float-end badge ' . $memcachedLabel . '">' . $bearsamppBins->getMemcached()->getVersion() . '</span>';
232}
233catch ( Exception $e ) {
234 $result['binmemcached'] = 'An error occurred getting the summary of Memchached. ' . $e->getMessage();
235}
236
237try {
238 /**
239 * Node.js Bin Information
240 * Checks if Node.js is enabled.
241 * Sets the appropriate label based on the status and appends the version and download link to the result.
242 */
243 $nodejsLabel = 'bg-secondary';
244 if ( $bearsamppBins->getNodejs()->isEnable() ) {
245 $nodejsLabel = 'bg-success';
246 }
247 $result['binnodejs'] = sprintf( $dlMoreTpl, 'nodejs' );
248 $result['binnodejs'] .= '<span class = " float-end badge ' . $nodejsLabel . '">' . $bearsamppBins->getNodejs()->getVersion() . '</span>';
249}
250catch ( Exception $e ) {
251 $result['binnodejs'] = 'An error occurred getting the summary of NodeJS. ' . $e->getMessage();
252}
253
254try {
255 /**
256 * PHP Bin Information
257 * Checks if PHP is enabled.
258 * Sets the appropriate label based on the status and appends the version and download link to the result.
259 */
260 $phpLabel = 'bg-secondary';
261 if ( $bearsamppBins->getPhp()->isEnable() ) {
262 $phpLabel = 'bg-success';
263 }
264 $result['binphp'] = sprintf( $dlMoreTpl, 'php' );
265 $result['binphp'] .= '<span class = " float-end badge ' . $phpLabel . '">' . $bearsamppBins->getPhp()->getVersion() . '</span>';
266}
267catch ( Exception $e ) {
268 $result['binphp'] = 'An error occurred getting the summary of PHP. ' . $e->getMessage();
269}
270
271// Output the result as JSON
272echo json_encode( $result );
$result
$dlMoreTpl
$mariadbLabel
$mailhogLabel
$memcachedLabel
$mysqlLabel
$mailpitLabel
$filezillaSslPort
$filezillaLabel
global $bearsamppBins
$postgresqlLabel
$xlightLabel
$apacheLabel
global $downloadTitle
$apacheSslPort
static getWebsiteUrl($path='', $fragment='', $utmSource=true)