diff --git a/src/AdminCabinet/Controllers/NetworkController.php b/src/AdminCabinet/Controllers/NetworkController.php
index e79c524fc..8760a4d11 100644
--- a/src/AdminCabinet/Controllers/NetworkController.php
+++ b/src/AdminCabinet/Controllers/NetworkController.php
@@ -65,17 +65,17 @@ public function modifyAction(): void
$this->view->setVars(
[
- 'SIP_PORT'=>PbxSettings::getValueByKey(PbxSettingsConstants::SIP_PORT),
- 'EXTERNAL_SIP_PORT'=>PbxSettings::getValueByKey(PbxSettingsConstants::EXTERNAL_SIP_PORT),
- 'TLS_PORT'=>PbxSettings::getValueByKey(PbxSettingsConstants::TLS_PORT),
- 'EXTERNAL_TLS_PORT'=>PbxSettings::getValueByKey(PbxSettingsConstants::EXTERNAL_TLS_PORT),
- 'RTP_PORT_FROM'=>PbxSettings::getValueByKey(PbxSettingsConstants::RTP_PORT_FROM),
- 'RTP_PORT_TO'=>PbxSettings::getValueByKey(PbxSettingsConstants::RTP_PORT_TO),
- 'form'=> $form,
- 'eths'=>$arrEth,
- 'deletableEths'=>$deletableInterfaces,
- 'isDocker'=>Util::isDocker(),
- 'submitMode'=>null,
+ 'SIP_PORT' => PbxSettings::getValueByKey(PbxSettingsConstants::SIP_PORT),
+ 'EXTERNAL_SIP_PORT' => PbxSettings::getValueByKey(PbxSettingsConstants::EXTERNAL_SIP_PORT),
+ 'TLS_PORT' => PbxSettings::getValueByKey(PbxSettingsConstants::TLS_PORT),
+ 'EXTERNAL_TLS_PORT' => PbxSettings::getValueByKey(PbxSettingsConstants::EXTERNAL_TLS_PORT),
+ 'RTP_PORT_FROM' => PbxSettings::getValueByKey(PbxSettingsConstants::RTP_PORT_FROM),
+ 'RTP_PORT_TO' => PbxSettings::getValueByKey(PbxSettingsConstants::RTP_PORT_TO),
+ 'form' => $form,
+ 'eths' => $arrEth,
+ 'deletableEths' => $deletableInterfaces,
+ 'isDocker' => Util::isDocker(),
+ 'submitMode' => null,
]
);
}
@@ -93,7 +93,7 @@ public function saveAction(): void
$this->db->begin();
- list($result, $messages)=$this->saveLanInterfaces($data);
+ list($result, $messages) = $this->saveLanInterfaces($data);
if (!$result) {
$this->flash->warning(implode('
', $messages));
$this->view->success = false;
@@ -101,7 +101,7 @@ public function saveAction(): void
return;
}
- list($result, $messages)=$this->saveNatSettings($data);
+ list($result, $messages) = $this->saveNatSettings($data);
if (!$result) {
$this->flash->warning(implode('
', $messages));
$this->view->success = false;
@@ -115,6 +115,46 @@ public function saveAction(): void
$this->db->commit();
}
+ /**
+ * Saves the LAN interface configurations.
+ *
+ * This method iterates through each existing LAN interface, updates its configuration based on the provided data,
+ * and saves the changes. If a new interface needs to be added (specified by 'interface_0'), it creates and saves this
+ * new interface as well. If any save operation fails, the method returns an array containing `false` and the error messages.
+ *
+ * @param array $data Array containing the interface configurations.
+ * Expected to contain interface settings such as IP, mask, etc., and a special key 'interface_0' for new interfaces.
+ * @return array Returns an array with a boolean success flag and an array of error messages if applicable.
+ */
+ private function saveLanInterfaces(array $data): array
+ {
+ $networkInterfaces = LanInterfaces::find();
+
+ // Update interface settings
+ foreach ($networkInterfaces as $eth) {
+ $this->fillEthStructure($eth, $data);
+ if ($eth->save() === false) {
+ $errors = $eth->getMessages();
+ return [false, $errors];
+ }
+ }
+
+ // Save additional interface settings if it exists
+ if ($data['interface_0'] !== '') {
+ $eth = new LanInterfaces();
+ $eth->id = 0;
+ $this->fillEthStructure($eth, $data);
+ $eth->id = null;
+ $eth->disabled = '0';
+ if ($eth->create() === false) {
+ $errors = $eth->getMessages();
+ return [false, $errors];
+ }
+ }
+
+ return [true, []];
+ }
+
/**
* Fills network interface settings
*
@@ -161,7 +201,7 @@ private function fillEthStructure(LanInterfaces $eth, array $data): void
if (array_key_exists($name . '_' . $eth->id, $data)) {
$eth->$name = ($data['dhcp_' . $eth->id]) === 'on' ? '1' : '0';
}
- if ($isDocker){
+ if ($isDocker) {
$eth->dhcp = '1';
}
break;
@@ -199,46 +239,6 @@ private function fillEthStructure(LanInterfaces $eth, array $data): void
}
}
- /**
- * Saves the LAN interface configurations.
- *
- * This method iterates through each existing LAN interface, updates its configuration based on the provided data,
- * and saves the changes. If a new interface needs to be added (specified by 'interface_0'), it creates and saves this
- * new interface as well. If any save operation fails, the method returns an array containing `false` and the error messages.
- *
- * @param array $data Array containing the interface configurations.
- * Expected to contain interface settings such as IP, mask, etc., and a special key 'interface_0' for new interfaces.
- * @return array Returns an array with a boolean success flag and an array of error messages if applicable.
- */
- private function saveLanInterfaces(array $data): array
- {
- $networkInterfaces = LanInterfaces::find();
-
- // Update interface settings
- foreach ($networkInterfaces as $eth) {
- $this->fillEthStructure($eth, $data);
- if ($eth->save() === false) {
- $errors = $eth->getMessages();
- return [false, $errors];
- }
- }
-
- // Save additional interface settings if it exists
- if ($data['interface_0'] !== '') {
- $eth = new LanInterfaces();
- $eth->id = 0;
- $this->fillEthStructure($eth, $data);
- $eth->id = null;
- $eth->disabled = '0';
- if ($eth->create() === false) {
- $errors = $eth->getMessages();
- return [false, $errors];
- }
- }
-
- return [true, []];
- }
-
/**
* Saves the NAT-related settings for external access.
*
@@ -251,23 +251,29 @@ private function saveLanInterfaces(array $data): array
*/
private function saveNatSettings(array $data): array
{
- foreach ($data as $key=>$value) {
+ $messages['error'] = [];
+ foreach ($data as $key => $value) {
switch ($key) {
case PbxSettingsConstants::AUTO_UPDATE_EXTERNAL_IP:
- if (!PbxSettings::setValue($key, $value === 'on' ? '1' : '0')){
- return [false, ['Error on save '.$key]];
- }
+ PbxSettings::setValue($key, $value === 'on' ? '1' : '0', $messages['error']);
break;
case PbxSettingsConstants::EXTERNAL_SIP_PORT:
+ if (empty($value)) {
+ $value = PbxSettings::getValueByKey(PbxSettingsConstants::SIP_PORT);
+ }
+ PbxSettings::setValue($key, trim($value), $messages['error']);
+ break;
case PbxSettingsConstants::EXTERNAL_TLS_PORT:
- if (!PbxSettings::setValue($key, trim($value))) {
- return [false, ['Error on save '.$key]];
+ if (empty($value)) {
+ $value = PbxSettings::getValueByKey(PbxSettingsConstants::TLS_PORT);
}
- break;
- default:
+ PbxSettings::setValue($key, trim($value), $messages['error']);
+ break;
+ default:
}
}
- return [true, []];
+ $result = count($messages['error']) === 0;
+ return [$result, $messages];
}
/**