2024.8.23
Loading...
Searching...
No Matches
ajax.mailhog.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 Mailhog service status and versions.
14 * It checks the SMTP port status and retrieves the list of available versions.
15 * The results are returned as a JSON-encoded array.
16 */
17
18// Initialize result array
19$result = array(
20 'checkport' => '',
21 'versions' => '',
22);
23
24// Check SMTP port
25$smtpPort = $bearsamppBins->getMailhog()->getSmtpPort();
26
30
31/**
32 * Check if the Mailhog service is running on the specified SMTP port.
33 * If the port is open, indicate that the service is started.
34 * If the port is closed, indicate that the service is stopped.
35 * If the service is disabled, indicate that it is disabled.
36 */
37if ($bearsamppBins->getMailhog()->isEnable()) {
38 if ($bearsamppBins->getMailhog()->checkPort($smtpPort)) {
39 $result['checkport'] .= '<span class="float-end badge text-bg-success">' . sprintf($textServiceStarted, $smtpPort) . '</span>';
40 } else {
41 $result['checkport'] .= '<span class="float-end badge text-bg-danger">' . $textServiceStopped . '</span>';
42 }
43} else {
44 $result['checkport'] = '<span class="float-end badge text-bg-secondary">' . $textDisabled . '</span>';
45}
46
47/**
48 * Retrieve the list of available Mailhog versions.
49 * Highlight the current version with a primary badge.
50 * Other versions are displayed with a secondary badge.
51 */
52foreach ($bearsamppBins->getMailhog()->getVersionList() as $version) {
53 if ($version != $bearsamppBins->getMailhog()->getVersion()) {
54 $result['versions'] .= '<span class="m-1 badge text-bg-secondary">' . $version . '</span>';
55 } else {
56 $result['versions'] .= '<span class="m-1 badge text-bg-primary">' . $bearsamppBins->getMailhog()->getVersion() . '</span>';
57 }
58}
59
60// Output the result as a JSON-encoded array
61echo json_encode($result);
$result
$textServiceStopped
$textDisabled
global $bearsamppBins
global $bearsamppLang
$textServiceStarted
$smtpPort
const HOMEPAGE_SERVICE_STOPPED
const HOMEPAGE_SERVICE_STARTED
const DISABLED