diff --git a/src/Core/System/Notifications.php b/src/Core/System/Notifications.php
index 34e79112c..866b5f203 100644
--- a/src/Core/System/Notifications.php
+++ b/src/Core/System/Notifications.php
@@ -106,7 +106,7 @@ public static function sendAdminNotification(string $subject, array $messages, b
foreach ($messages as $message) {
$text .= '
' . Util::translate($message, false);
}
- $text = $text . '
' . Network::getInfoMessage();
+ $text = $text . '
' . SystemMessages::getInfoMessage();
// Get the admin email address from PbxSettings.
$adminMail = PbxSettings::getValueByKey(PbxSettingsConstants::SYSTEM_NOTIFICATIONS_EMAIL);
diff --git a/src/Core/System/SystemLoader.php b/src/Core/System/SystemLoader.php
index f4d47d9bc..16aea6ac4 100644
--- a/src/Core/System/SystemLoader.php
+++ b/src/Core/System/SystemLoader.php
@@ -348,108 +348,12 @@ public function startMikoPBX(): bool
$this->echoResultMsg();
// Display network information
- $this->echoStartMsg(self::getInfoMessage());
+ $this->echoStartMsg(SystemMessages::getInfoMessage(true));
$this->di->getShared(RegistryProvider::SERVICE_NAME)->booting = false;
return true;
}
- /**
- * Retrieves the information message containing available web interface addresses.
- *
- * @return string The information message.
- */
- public static function getInfoMessage(): string
- {
- // Assuming a total width of 53 characters for each line
- $lineWidth = 53;
-
- $info = PHP_EOL . "┌────────────────────────────────────────────────┐";
- $info .= PHP_EOL . "│ │";
- $headerSpace = $lineWidth - 3 - 5; // 3 for "│ 🌟 MikoPBX - All services are fully loaded 🌟 " and 5 for " │" at the end
- $headerLine = sprintf("│ %-{$headerSpace}s │", "🌟 MikoPBX - All services are fully loaded 🌟");
- $info .= PHP_EOL . $headerLine;
- $info .= PHP_EOL . "│ │";
- $info .= PHP_EOL . "├────────────────────────────────────────────────┤";
-
- $addresses = [
- 'local' => [],
- 'external' => []
- ];
- /** @var LanInterfaces $interface */
- $interfaces = LanInterfaces::find("disabled='0'");
- foreach ($interfaces as $interface) {
- if (!empty($interface->ipaddr)) {
- $addresses['local'][] = $interface->ipaddr;
- }
- if (!empty($interface->exthostname) && !in_array($interface->exthostname, $addresses['local'], true)) {
- $addresses['external'][] = explode(':', $interface->exthostname)[0] ?? '';
- }
- if (!empty($interface->extipaddr) && !in_array($interface->extipaddr, $addresses['local'], true)) {
- $addresses['external'][] = explode(':', $interface->extipaddr)[0] ?? '';
- }
- }
- unset($interfaces);
-
-
- // Local network
- $port = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_HTTPS_PORT);
- $info .= PHP_EOL . "│ │";
- $headerSpace = $lineWidth - 13 - 1; // 13 for "│ 🌐 Web Interface Access 🌐 " and 1 for " │"
- $headerLine = sprintf("│ %-{$headerSpace}s │", "🌐 Web Interface Access 🌐");
- $info .= PHP_EOL . $headerLine;
- $info .= PHP_EOL . "│ │";
- $info .= PHP_EOL . "│ Local Network Address: │";
-
- $addressSpace = $lineWidth - 7 - 5; // 7 for "│ ➜ " and 5 for " │" at the end
- foreach ($addresses['local'] as $address) {
- if (empty($address)) {
- continue;
- }
- $formattedAddress = $port === '443' ? "https://$address" : "https://$address:$port";
- // Use sprintf to format the string with padding to ensure constant length
- $info .= PHP_EOL . sprintf("│ ➜ %-{$addressSpace}s │", $formattedAddress);
- }
- $info .= PHP_EOL . "│ │";
-
- // External web address info
- if (!empty($addresses['external'])) {
- $info .= PHP_EOL . "│ External Network Address: │";
- foreach ($addresses['external'] as $address) {
- if (empty($address)) {
- continue;
- }
- $formattedAddress = $port === '443' ? "https://$address" : "https://$address:$port";
- // Use sprintf to format the string with padding to ensure constant length
- $info .= PHP_EOL . sprintf("│ ➜ %-{$addressSpace}s │", $formattedAddress);
-
- }
- $info .= PHP_EOL . "│ │";
- }
-
- // Default web user info
- $cloudInstanceId = PbxSettings::getValueByKey(PbxSettingsConstants::CLOUD_INSTANCE_ID);
- $webAdminPassword = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_ADMIN_PASSWORD);
- $defaultPassword = PbxSettings::getDefaultArrayValues()[PbxSettingsConstants::WEB_ADMIN_PASSWORD];
- if ($cloudInstanceId === $webAdminPassword || $webAdminPassword === $defaultPassword) {
- $adminUser = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_ADMIN_LOGIN);
-
- $credentialSpace = $lineWidth - 5 - 3; // 5 for "│ 🔑 Default Credentials: " and 3 for " │"
- $credentialLine = sprintf("│ %-{$credentialSpace}s │", "🔑 Default web credentials:");
- $info .= PHP_EOL . $credentialLine;
- // Login
- $loginSpace = $lineWidth - 12 - 5; // 12 for "│ Login: " and 5 for " │" at the end
- $loginLine = sprintf("│ Login: %-{$loginSpace}s │", $adminUser); // Format the login line
- $info .= PHP_EOL . $loginLine;
-
- // Password
- $passwordSpace = $lineWidth - 15 - 5; // 15 for "│ Password: " and 5 for " │" at the end
- $passwordLine = sprintf("│ Password: %-{$passwordSpace}s │", $cloudInstanceId); // Format the password line
- $info .= PHP_EOL . $passwordLine;
- }
- $info .= PHP_EOL . "└────────────────────────────────────────────────┘" . PHP_EOL . PHP_EOL;
- return $info;
- }
}
\ No newline at end of file
diff --git a/src/Core/System/SystemMessages.php b/src/Core/System/SystemMessages.php
index dbeaf41b9..b578b4a70 100644
--- a/src/Core/System/SystemMessages.php
+++ b/src/Core/System/SystemMessages.php
@@ -19,6 +19,9 @@
namespace MikoPBX\Core\System;
+use MikoPBX\Common\Models\LanInterfaces;
+use MikoPBX\Common\Models\PbxSettings;
+use MikoPBX\Common\Models\PbxSettingsConstants;
use MikoPBX\Common\Providers\LoggerProvider;
use Phalcon\Di;
@@ -198,4 +201,104 @@ public static function echoResultMsg(string $message, string $result = SystemMes
SystemMessages::teletypeEchoResult($message, $result);
SystemMessages::echoResult($message, $result);
}
+
+ /**
+ * Retrieves the information message containing available web interface addresses.
+ * @param bool $showCredentials Optional, if true the message will have the login information
+ * @return string The information message.
+ */
+ public static function getInfoMessage(bool $showCredentials=false): string
+ {
+ // Assuming a total width of 53 characters for each line
+ $lineWidth = 53;
+
+ $info = PHP_EOL . "┌────────────────────────────────────────────────┐";
+ $info .= PHP_EOL . "│ │";
+ $headerSpace = $lineWidth - 3 - 5; // 3 for "│ 🌟 MikoPBX - All services are fully loaded 🌟 " and 5 for " │" at the end
+ $headerLine = sprintf("│ %-{$headerSpace}s │", "🌟 MikoPBX - All services are fully loaded 🌟");
+ $info .= PHP_EOL . $headerLine;
+ $info .= PHP_EOL . "│ │";
+ $info .= PHP_EOL . "├────────────────────────────────────────────────┤";
+
+ $addresses = [
+ 'local' => [],
+ 'external' => []
+ ];
+ /** @var LanInterfaces $interface */
+ $interfaces = LanInterfaces::find("disabled='0'");
+ foreach ($interfaces as $interface) {
+ if (!empty($interface->ipaddr)) {
+ $addresses['local'][] = $interface->ipaddr;
+ }
+ if (!empty($interface->exthostname) && !in_array($interface->exthostname, $addresses['local'], true)) {
+ $addresses['external'][] = explode(':', $interface->exthostname)[0] ?? '';
+ }
+ if (!empty($interface->extipaddr) && !in_array($interface->extipaddr, $addresses['local'], true)) {
+ $addresses['external'][] = explode(':', $interface->extipaddr)[0] ?? '';
+ }
+ }
+ unset($interfaces);
+
+
+ // Local network
+ $port = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_HTTPS_PORT);
+ $info .= PHP_EOL . "│ │";
+ $headerSpace = $lineWidth - 13 - 1; // 13 for "│ 🌐 Web Interface Access 🌐 " and 1 for " │"
+ $headerLine = sprintf("│ %-{$headerSpace}s │", "🌐 Web Interface Access 🌐");
+ $info .= PHP_EOL . $headerLine;
+ $info .= PHP_EOL . "│ │";
+ $info .= PHP_EOL . "│ Local Network Address: │";
+
+ $addressSpace = $lineWidth - 7 - 5; // 7 for "│ ➜ " and 5 for " │" at the end
+ foreach ($addresses['local'] as $address) {
+ if (empty($address)) {
+ continue;
+ }
+ $formattedAddress = $port === '443' ? "https://$address" : "https://$address:$port";
+ // Use sprintf to format the string with padding to ensure constant length
+ $info .= PHP_EOL . sprintf("│ ➜ %-{$addressSpace}s │", $formattedAddress);
+
+ }
+ $info .= PHP_EOL . "│ │";
+
+ // External web address info
+ if (!empty($addresses['external'])) {
+ $info .= PHP_EOL . "│ External Network Address: │";
+ foreach ($addresses['external'] as $address) {
+ if (empty($address)) {
+ continue;
+ }
+ $formattedAddress = $port === '443' ? "https://$address" : "https://$address:$port";
+ // Use sprintf to format the string with padding to ensure constant length
+ $info .= PHP_EOL . sprintf("│ ➜ %-{$addressSpace}s │", $formattedAddress);
+
+ }
+ $info .= PHP_EOL . "│ │";
+ }
+
+ if ($showCredentials) {
+ // Default web user info
+ $cloudInstanceId = PbxSettings::getValueByKey(PbxSettingsConstants::CLOUD_INSTANCE_ID);
+ $webAdminPassword = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_ADMIN_PASSWORD);
+ $defaultPassword = PbxSettings::getDefaultArrayValues()[PbxSettingsConstants::WEB_ADMIN_PASSWORD];
+ if ($cloudInstanceId === $webAdminPassword || $webAdminPassword === $defaultPassword) {
+ $adminUser = PbxSettings::getValueByKey(PbxSettingsConstants::WEB_ADMIN_LOGIN);
+
+ $credentialSpace = $lineWidth - 5 - 3; // 5 for "│ 🔑 Default Credentials: " and 3 for " │"
+ $credentialLine = sprintf("│ %-{$credentialSpace}s │", "🔑 Default web credentials:");
+ $info .= PHP_EOL . $credentialLine;
+ // Login
+ $loginSpace = $lineWidth - 12 - 5; // 12 for "│ Login: " and 5 for " │" at the end
+ $loginLine = sprintf("│ Login: %-{$loginSpace}s │", $adminUser); // Format the login line
+ $info .= PHP_EOL . $loginLine;
+
+ // Password
+ $passwordSpace = $lineWidth - 15 - 5; // 15 for "│ Password: " and 5 for " │" at the end
+ $passwordLine = sprintf("│ Password: %-{$passwordSpace}s │", $cloudInstanceId); // Format the password line
+ $info .= PHP_EOL . $passwordLine;
+ }
+ }
+ $info .= PHP_EOL . "└────────────────────────────────────────────────┘" . PHP_EOL . PHP_EOL;
+ return $info;
+ }
}
\ No newline at end of file
diff --git a/tests/Core/System/NetworkTest.php b/tests/Core/System/NetworkTest.php
index 6aa0430f7..3ddbe72f0 100644
--- a/tests/Core/System/NetworkTest.php
+++ b/tests/Core/System/NetworkTest.php
@@ -19,15 +19,14 @@
namespace MikoPBX\Tests\Core\System;
-use MikoPBX\Core\System\Network;
-use MikoPBX\Core\System\SystemLoader;
+use MikoPBX\Core\System\SystemMessages;
use MikoPBX\Tests\Unit\AbstractUnitTest;
class NetworkTest extends \MikoPBX\Tests\Unit\AbstractUnitTest
{
public function testGetInfoMessage()
{
- $networkInfo = SystemLoader::getInfoMessage();
+ $networkInfo = SystemMessages::getInfoMessage();
$this->assertTrue(true);
}
}