From 854802ea7f926003d8bbae7565b33bad8192cc1d Mon Sep 17 00:00:00 2001 From: fusionate Date: Tue, 14 Feb 2023 01:27:37 +0000 Subject: [PATCH] Recordings - Enable Default/Domain/User setting to control filename prefix and password. --- app/recordings/app_config.php | 18 ++++++- app/recordings/app_languages.php | 40 +++++++------- app/recordings/recordings.php | 53 ++++++++++--------- app/scripts/resources/scripts/recordings.lua | 16 ++++-- .../resources/functions/lazy_settings.lua | 35 +++++++++++- 5 files changed, 111 insertions(+), 51 deletions(-) diff --git a/app/recordings/app_config.php b/app/recordings/app_config.php index 81136db2e7..6556e01a97 100644 --- a/app/recordings/app_config.php +++ b/app/recordings/app_config.php @@ -86,7 +86,7 @@ $apps[$x]['permissions'][$y]['groups'][] = "admin"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; - $apps[$x]['permissions'][$y]['name'] = "recording_pin"; + $apps[$x]['permissions'][$y]['name'] = "recording_password"; $apps[$x]['permissions'][$y]['groups'][] = "admin"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; @@ -123,6 +123,22 @@ $apps[$x]['default_settings'][$y]['default_setting_value'] = "3"; $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; $apps[$x]['default_settings'][$y]['default_setting_description'] = "Seconds of silence to end the recording for the voicemail message."; + $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "e4b509cc-1622-4867-b8b8-c48585c4d796"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "recordings"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "recording_prefix"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "text"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = "recording_"; + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "false"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = "Set the prefix text for the recording name and filename (overrides recordings dialplan)."; + $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "f74ab51f-e7c4-423e-b5b6-6f806ecf96b4"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "recordings"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "recording_password"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "numeric"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = generate_password((is_numeric($_SESSION['voicemail']['password_length']['numeric']) ? $_SESSION['voicemail']['password_length']['numeric'] : 8), 1); + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "false"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = "Set the password required to create a recording (overrides recordings dialplan)."; //schema details $y=0; diff --git a/app/recordings/app_languages.php b/app/recordings/app_languages.php index 828efecf0b..ee1ce1746d 100644 --- a/app/recordings/app_languages.php +++ b/app/recordings/app_languages.php @@ -442,25 +442,25 @@ $text['description']['ru-ru'] = "Наберите *732 для создания $text['description']['sv-se'] = "För att göra en inspelning ring * 732 eller så kan du göra en 16bit 8kHz/16kHz Mono WAV-fil och kopiera den till följande katalog uppdatera sedan sidan för att spela upp den."; $text['description']['uk-ua'] = "Редагування інформації облікового запису"; -$text['description-with_pin']['en-us'] = "Dial *732 and enter the password ||PIN_NUMBER||, followed by a number for the recording to create. Or, for best results, upload a 16bit 8khz/16khz mono WAV file."; -$text['description-with_pin']['en-gb'] = "Dial *732 and enter the password ||PIN_NUMBER||, followed by a number for the recording to create. Or, for best results, upload a 16bit 8khz/16khz mono WAV file."; -$text['description-with_pin']['ar-eg'] = ""; -$text['description-with_pin']['de-at'] = "Wählen Sie *732 um eine Aufnahme direkt vom Telefon zu starten oder laden Sie eine 16bit 8/16kHz mono WAV-Datei hoch."; //copied from de-de -$text['description-with_pin']['de-ch'] = "Wählen Sie *732 um eine Aufnahme direkt vom Telefon zu starten oder laden Sie eine 16bit 8/16kHz mono WAV-Datei hoch."; //copied from de-de -$text['description-with_pin']['de-de'] = "Wählen Sie *732 um eine Aufnahme direkt vom Telefon zu starten oder laden Sie eine 16bit 8/16kHz mono WAV-Datei hoch."; -$text['description-with_pin']['es-cl'] = "Para realizar una grabación marque *732 o puede crear un archivo en formato WAV a 16 bit 8khz/16khz Mono y luego copiarlo en el siguiente directorio y refrezcar la página para reproducirlo."; -$text['description-with_pin']['es-mx'] = "Para realizar una grabación marque *732 o puede crear un archivo en formato WAV a 16 bit 8khz/16khz Mono y luego copiarlo en el siguiente directorio y refrezcar la página para reproducirlo."; //copied from es-cl -$text['description-with_pin']['fr-ca'] = "Pour créer un guide vocal, composer le *732 ou créer un fichier audio WAV 16bit 8khz/16khz Mono et ensuite le copier dans le répertoire qui suit. Rafraîchir ensuite cette page pour le voir apparaitre."; //copied from fr-fr -$text['description-with_pin']['fr-fr'] = "Pour créer un guide vocal, composer le *732 ou créer un fichier audio WAV 16bit 8khz/16khz Mono et ensuite le copier dans le répertoire qui suit. Rafraîchir ensuite cette page pour le voir apparaitre."; -$text['description-with_pin']['he-il'] = "חייג * 732 ליצירת הקלטה, או (לקבלת התוצאות הטובות ביותר) העלה קובץ WAV מונו בגודל 16bit 8khz / 16khz"; -$text['description-with_pin']['it-it'] = "Chiamare *732 per creare una registrazione, o (per un risultato migliore) caricare file WAV a 16bit 8khz/16khz mono."; -$text['description-with_pin']['nl-nl'] = "Kies *732 om een opname te make, of voor betere resultaten, stuur een 16bit 8kHz/16kHz mono WAV bestand. op"; -$text['description-with_pin']['pl-pl'] = "Aby stworzyć własne nagranie wybierz *732 z klawiatury telefonu lub stwórz plik audio w formacie WAV o następujących parametrach: 16bit 8khz/16khz Mono, a następnie skopiuj go do odpowiedniego katalogu i odśwież, aby go odsłuchać."; -$text['description-with_pin']['pt-br'] = "Editar informações da conta."; -$text['description-with_pin']['pt-pt'] = "Para fazer uma gravação marque *732 ou crie um ficheiro WAV de 16bit 8khz/16khz e copie-o para a seguinte directoria e actualize a página para o ouvir."; -$text['description-with_pin']['ro-ro'] = ""; -$text['description-with_pin']['ru-ru'] = "Наберите *732 для создания записи, или (для получения наилучших результатов) загрузите 16bit 8khz/16khz mono WAV файл."; -$text['description-with_pin']['sv-se'] = "För att göra en inspelning ring * 732 eller så kan du göra en 16bit 8kHz/16kHz Mono WAV-fil och kopiera den till följande katalog uppdatera sedan sidan för att spela upp den."; -$text['description-with_pin']['uk-ua'] = "Редагування інформації облікового запису"; +$text['description-with_password']['en-us'] = "Dial *732 and enter the password ||RECORDING_PASSWORD||, followed by a number for the recording to create. Or, for best results, upload a 16bit 8khz/16khz mono WAV file."; +$text['description-with_password']['en-gb'] = "Dial *732 and enter the password ||RECORDING_PASSWORD||, followed by a number for the recording to create. Or, for best results, upload a 16bit 8khz/16khz mono WAV file."; +$text['description-with_password']['ar-eg'] = ""; +$text['description-with_password']['de-at'] = "Wählen Sie *732 um eine Aufnahme direkt vom Telefon zu starten oder laden Sie eine 16bit 8/16kHz mono WAV-Datei hoch."; //copied from de-de +$text['description-with_password']['de-ch'] = "Wählen Sie *732 um eine Aufnahme direkt vom Telefon zu starten oder laden Sie eine 16bit 8/16kHz mono WAV-Datei hoch."; //copied from de-de +$text['description-with_password']['de-de'] = "Wählen Sie *732 um eine Aufnahme direkt vom Telefon zu starten oder laden Sie eine 16bit 8/16kHz mono WAV-Datei hoch."; +$text['description-with_password']['es-cl'] = "Para realizar una grabación marque *732 o puede crear un archivo en formato WAV a 16 bit 8khz/16khz Mono y luego copiarlo en el siguiente directorio y refrezcar la página para reproducirlo."; +$text['description-with_password']['es-mx'] = "Para realizar una grabación marque *732 o puede crear un archivo en formato WAV a 16 bit 8khz/16khz Mono y luego copiarlo en el siguiente directorio y refrezcar la página para reproducirlo."; //copied from es-cl +$text['description-with_password']['fr-ca'] = "Pour créer un guide vocal, composer le *732 ou créer un fichier audio WAV 16bit 8khz/16khz Mono et ensuite le copier dans le répertoire qui suit. Rafraîchir ensuite cette page pour le voir apparaitre."; //copied from fr-fr +$text['description-with_password']['fr-fr'] = "Pour créer un guide vocal, composer le *732 ou créer un fichier audio WAV 16bit 8khz/16khz Mono et ensuite le copier dans le répertoire qui suit. Rafraîchir ensuite cette page pour le voir apparaitre."; +$text['description-with_password']['he-il'] = "חייג * 732 ליצירת הקלטה, או (לקבלת התוצאות הטובות ביותר) העלה קובץ WAV מונו בגודל 16bit 8khz / 16khz"; +$text['description-with_password']['it-it'] = "Chiamare *732 per creare una registrazione, o (per un risultato migliore) caricare file WAV a 16bit 8khz/16khz mono."; +$text['description-with_password']['nl-nl'] = "Kies *732 om een opname te make, of voor betere resultaten, stuur een 16bit 8kHz/16kHz mono WAV bestand. op"; +$text['description-with_password']['pl-pl'] = "Aby stworzyć własne nagranie wybierz *732 z klawiatury telefonu lub stwórz plik audio w formacie WAV o następujących parametrach: 16bit 8khz/16khz Mono, a następnie skopiuj go do odpowiedniego katalogu i odśwież, aby go odsłuchać."; +$text['description-with_password']['pt-br'] = "Editar informações da conta."; +$text['description-with_password']['pt-pt'] = "Para fazer uma gravação marque *732 ou crie um ficheiro WAV de 16bit 8khz/16khz e copie-o para a seguinte directoria e actualize a página para o ouvir."; +$text['description-with_password']['ro-ro'] = ""; +$text['description-with_password']['ru-ru'] = "Наберите *732 для создания записи, или (для получения наилучших результатов) загрузите 16bit 8khz/16khz mono WAV файл."; +$text['description-with_password']['sv-se'] = "För att göra en inspelning ring * 732 eller så kan du göra en 16bit 8kHz/16kHz Mono WAV-fil och kopiera den till följande katalog uppdatera sedan sidan för att spela upp den."; +$text['description-with_password']['uk-ua'] = "Редагування інформації облікового запису"; ?> diff --git a/app/recordings/recordings.php b/app/recordings/recordings.php index 978c26780a..b56e4790d4 100644 --- a/app/recordings/recordings.php +++ b/app/recordings/recordings.php @@ -335,28 +335,33 @@ $recordings = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); -//get current recordings pin number - if (permission_exists('recording_pin')) { - $sql = " - select - split_part(dd.dialplan_detail_data,'=',2) - from - v_dialplans as d, - v_dialplan_details as dd - where - d.dialplan_uuid = dd.dialplan_uuid and - d.domain_uuid = :domain_uuid and - d.app_uuid = '430737df-5385-42d1-b933-22600d3fb79e' and - d.dialplan_name = 'recordings' and - d.dialplan_enabled = 'true' and - dd.dialplan_detail_tag = 'action' and - dd.dialplan_detail_type = 'set' and - dd.dialplan_detail_data like 'pin_number=%' and - dd.dialplan_detail_enabled = 'true' "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; - $pin_number = $database->select($sql, $parameters, 'column'); - unset($sql, $parameters); +//get current recordings password + if (permission_exists('recording_password')) { + if (is_numeric($_SESSION['recordings']['recording_password']['numeric'])) { + $recording_password = $_SESSION['recordings']['recording_password']['numeric']; + } + else { + $sql = " + select + split_part(dd.dialplan_detail_data,'=',2) + from + v_dialplans as d, + v_dialplan_details as dd + where + d.dialplan_uuid = dd.dialplan_uuid and + d.domain_uuid = :domain_uuid and + d.app_uuid = '430737df-5385-42d1-b933-22600d3fb79e' and + d.dialplan_name = 'recordings' and + d.dialplan_enabled = 'true' and + dd.dialplan_detail_tag = 'action' and + dd.dialplan_detail_type = 'set' and + dd.dialplan_detail_data like 'pin_number=%' and + dd.dialplan_detail_enabled = 'true' "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $recording_password = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + } } //create token @@ -422,8 +427,8 @@ echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); } - if (permission_exists('recording_pin') && is_numeric($pin_number)) { - echo str_replace('||PIN_NUMBER||', "".$pin_number."", $text['description-with_pin']."\n"); + if (permission_exists('recording_password') && is_numeric($recording_password)) { + echo str_replace('||RECORDING_PASSWORD||', "".$recording_password."", $text['description-with_password']."\n"); } else { echo $text['description']."\n"; diff --git a/app/scripts/resources/scripts/recordings.lua b/app/scripts/resources/scripts/recordings.lua index 7c9a2fc934..aa4049a2bb 100644 --- a/app/scripts/resources/scripts/recordings.lua +++ b/app/scripts/resources/scripts/recordings.lua @@ -39,6 +39,7 @@ --add functions require "resources.functions.mkdir"; require "resources.functions.explode"; + local cache = require "resources.functions.cache" --setup the database connection local Database = require "resources.functions.database"; @@ -53,22 +54,29 @@ --get the domain_uuid if (session:ready()) then domain_uuid = session:getVariable("domain_uuid"); + user_uuid = session:getVariable("user_uuid"); end --initialize the recordings api = freeswitch.API(); +--clear cached prefix and password, refreshed from database settings + if cache.support() then + cache.del("setting::recordings.recording_prefix.text") + cache.del("setting::recordings.recording_password.numeric") + end + --load lazy settings library local Settings = require "resources.functions.lazy_settings"; --get the recordings settings - local settings = Settings.new(db, domain_name, domain_uuid); + local settings = Settings.new(db, domain_name, domain_uuid, user_uuid); --set the storage type and path storage_type = settings:get('recordings', 'storage_type', 'text') or ''; storage_path = settings:get('recordings', 'storage_path', 'text') or ''; if (storage_path ~= '') then - storage_path = storage_path:gsub("${domain_name}", session:getVariable("domain_name")); + storage_path = storage_path:gsub("${domain_name}", session:getVariable("domain_name")); storage_path = storage_path:gsub("${domain_uuid}", domain_uuid); end @@ -98,7 +106,7 @@ if (not default_dialect) then default_dialect = 'us'; end if (not default_voice) then default_voice = 'callie'; end recording_id = session:getVariable("recording_id"); - recording_prefix = session:getVariable("recording_prefix"); + recording_prefix = settings:get('recordings', 'recording_prefix', 'text') or session:getVariable("recording_prefix"); recording_name = session:getVariable("recording_name"); record_ext = session:getVariable("record_ext"); domain_name = session:getVariable("domain_name"); @@ -294,7 +302,7 @@ if (session:ready()) then session:answer(); --get the dialplan variables and set them as local variables - pin_number = session:getVariable("pin_number"); + pin_number = settings:get('recordings', 'recording_password', 'numeric') or session:getVariable("pin_number"); sounds_dir = session:getVariable("sounds_dir"); domain_name = session:getVariable("domain_name"); domain_uuid = session:getVariable("domain_uuid"); diff --git a/app/scripts/resources/scripts/resources/functions/lazy_settings.lua b/app/scripts/resources/scripts/resources/functions/lazy_settings.lua index 09dca5c645..f9973625f6 100644 --- a/app/scripts/resources/scripts/resources/functions/lazy_settings.lua +++ b/app/scripts/resources/scripts/resources/functions/lazy_settings.lua @@ -49,12 +49,13 @@ local function append_setting(array, category, subcategory, name, value) end end -function Settings.new(db, domain_name, domain_uuid) +function Settings.new(db, domain_name, domain_uuid, user_uuid) local self = setmetatable({}, Settings) self._array = {} self._db = db self._domain_name = domain_name self._domain_uuid = domain_uuid + self._user_uuid = user_uuid self._use_cache = not cache.settings return self @@ -93,6 +94,7 @@ function Settings:get(category, subcategory, name) end function Settings:_load(category, subcategory, name) + local user_uuid = self._user_uuid local domain_uuid = self._domain_uuid local db = self._db if type(self._db) == 'string' then @@ -101,8 +103,37 @@ function Settings:_load(category, subcategory, name) local found = false + --get the user settings + if user_uuid then + local sql = "SELECT user_setting_uuid,user_setting_category,user_setting_subcategory,user_setting_name,user_setting_value " + sql = sql .. "FROM v_user_settings "; + sql = sql .. "WHERE user_uuid = :user_uuid "; + sql = sql .. "AND user_setting_enabled = 'true' "; + sql = sql .. "AND user_setting_category = :category "; + sql = sql .. "AND user_setting_subcategory = :subcategory "; + sql = sql .. "AND user_setting_name = :name "; + sql = sql .. "AND user_setting_value is not null "; + sql = sql .. "ORDER BY user_setting_category, user_setting_subcategory ASC "; + local params = { + user_uuid = user_uuid, + category = category, + subcategory = subcategory, + name = name, + }; + + db:query(sql, params, function(row) + found = true; + self:set( + row.user_setting_category, + row.user_setting_subcategory, + row.user_setting_name, + row.user_setting_value + ) + end) + end + --get the domain settings - if domain_uuid then + if not found and domain_uuid then local sql = "SELECT domain_setting_uuid,domain_setting_category,domain_setting_subcategory,domain_setting_name,domain_setting_value " sql = sql .. "FROM v_domain_settings "; sql = sql .. "WHERE domain_uuid = :domain_uuid ";