Skip to content

Commit

Permalink
feat(trunks): automate disable_topos management in wizard
Browse files Browse the repository at this point in the history
- Automatically set the `disable_topos` value for trunks created via the wizard.
- Remove the `disable_topos` value when a trunk is deleted via the wizard.
- Added a new MySQL table to store default `disable_topos` values.
- If no default `disable_topos` value is specified, the feature is enabled by default.
  • Loading branch information
Stell0 committed Nov 29, 2024
1 parent e5fdae4 commit 63a6cae
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions freepbx/var/www/html/freepbx/rest/modules/trunks.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
$trunkid = $route->getArgument('trunkid');
try {
FreePBX::Core()->deleteTrunk($trunkid);
// Delete disable_topos configuration for this trunk
FreePBX::Nethcti3()->delConfig('disable_topos', $trunkid);
system('/var/www/html/freepbx/rest/lib/retrieveHelper.sh > /dev/null &');
return $response->withStatus(200);
} catch (Exception $e) {
Expand Down Expand Up @@ -333,6 +335,13 @@
if (!$res) {
return $response->withStatus(500);
}
// Set topos flag if needed
$sql = "SELECT `value` FROM `rest_pjsip_trunks_custom_flags` WHERE `keyword` = 'disable_topos' AND `provider_id` IN (SELECT `id` FROM `rest_pjsip_providers` WHERE `provider` = ?)";
$sth = $dbh->prepare($sql);
$sth->execute([$params['provider']]);
$disable_topos = $sth->fetchColumn()[0];
Freepbx::Nethcti3()->setConfig('disable_topos', $disable_topos, $trunkid);

system('/var/www/html/freepbx/rest/lib/retrieveHelper.sh > /dev/null &');
return $response->withStatus(200);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!40101 SET NAMES binary*/;
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;

/*!40103 SET TIME_ZONE='+00:00' */;
USE `asterisk`;
CREATE TABLE `rest_pjsip_trunks_custom_flags` (
`provider_id` bigint(20) NOT NULL,
`keyword` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`value` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`provider_id`,`keyword`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*!40101 SET NAMES binary*/;
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40103 SET TIME_ZONE='+00:00' */;
USE `asterisk`;
INSERT INTO `rest_pjsip_trunks_custom_flags` (`provider_id`,`keyword`,`value`) VALUES
(1,"disable_topos",0),
(2,"disable_topos",0),
(3,"disable_topos",0),
(4,"disable_topos",0),
(5,"disable_topos",0),
(6,"disable_topos",0),
(7,"disable_topos",0),
(8,"disable_topos",0),
(9,"disable_topos",0),
(10,"disable_topos",0),
(11,"disable_topos",0),
(12,"disable_topos",0),
(13,"disable_topos",0),
(14,"disable_topos",0),
(15,"disable_topos",0),
(16,"disable_topos",0),
(17,"disable_topos",0),
(18,"disable_topos",0),
(19,"disable_topos",0),
(20,"disable_topos",0),
(21,"disable_topos",0),
(22,"disable_topos",0),
(23,"disable_topos",0),
(24,"disable_topos",0);

0 comments on commit 63a6cae

Please sign in to comment.