Skip to content

Commit

Permalink
Add migration from NV on 7 and srtp stored on res_devices_phones
Browse files Browse the repository at this point in the history
  • Loading branch information
Stell0 committed Oct 20, 2023
1 parent 360b287 commit 906ef28
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions asterisk/var/lib/asterisk/moh/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
macroform-cold_day.wav filter=lfs diff=lfs merge=lfs -text
macroform-robot_dity.wav filter=lfs diff=lfs merge=lfs -text
macroform-the_simplicity.wav filter=lfs diff=lfs merge=lfs -text
manolo_camp-morning_coffee.wav filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions freepbx/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ while (\$row = \$sth->fetch(\PDO::FETCH_ASSOC)) {
EOF

# migrate database
php /initdb.d/migration.php

if [[ ! -f /etc/asterisk/extensions_additional.conf ]]; then
# First install, set needreload to true
php -r 'include_once "/etc/freepbx_db.conf"; $db->query("UPDATE admin SET value = \"true\" WHERE variable = \"need_reload\"");'
Expand Down
41 changes: 41 additions & 0 deletions freepbx/initdb.d/migration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

include_once '/etc/freepbx_db.conf';

# TODO check if migration is needed. Exit 0 if not

# Add srtp column to rest_devices_phones
$db->query("ALTER TABLE `asterisk`.`rest_devices_phones` ADD COLUMN `srtp` BOOLEAN DEFAULT NULL AFTER `type`");



/* Convert existing srtp extensions to be used with proxy */

# get all NethVoice extensions with srtp enabled
$sql = "SELECT extension
FROM `asterisk`.`rest_devices_phones`
JOIN `asterisk`.`sip`
ON `asterisk`.`rest_devices_phones`.`extension` = `asterisk`.`sip`.`id`
WHERE `type` = 'physical'
AND `srtp` IS NULL
AND `keyword`='media_encryption'
AND `data`='sdes'";

$stmt = $db->prepare($sql);
$stmt->execute();
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$extensions = array_column($res, 'extension');

# set media_encryption to no in freepbx sip table
$sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'media_encryption' AND `id` IN ('".str_repeat('?, ', count($extensions) - 1) . '?'."')";
$stmt = $db->prepare($sql);
$stmt->execute($extensions);

# set srtp to true in rest_devices_phones table
$sql = "UPDATE `asterisk`.`rest_devices_phones` SET `srtp` = 1 WHERE `extension` IN ('".str_repeat('?, ', count($extensions) - 1) . '?'."')";
$stmt = $db->prepare($sql);
$stmt->execute($extensions);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CREATE TABLE `rest_devices_phones` (
`web_user` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`web_password` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`type` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'physical',
`srtp` boolean DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mac` (`mac`,`line`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

0 comments on commit 906ef28

Please sign in to comment.