91 Commits
Author SHA1 Message Date
FusionPBX 7e47bb6446 Update ivr.conf.lua
Fix the memcache expire on the ivr menu.
2016-12-14 08:45:16 -07:00
FusionPBX 154bf5ba83 Update scripts.php
Add expire.default and expire.ivr.
2016-12-14 08:43:10 -07:00
FusionPBX 615743970f Update vars.xml 2016-12-12 18:37:28 -07:00
DigiDaz 48e745e6d6 Fix recording setting in extension (#2246)
* Fix recording setting in extension

If as a superadmin you add recording to an extension, then the admin for the domain (ie member of group: admin) goes in and edits the extension, the recording property will be set to false.

* Update extension_edit.php
2016-12-09 16:26:38 -07:00
FusionPBX 2a8b1ff602 Update functions.php
Updating the version number to 4.2.1 which includes bug fixes and security updates.
2016-12-08 19:37:43 -07:00
FusionPBX 79d149b688 Update dialplan.lua
Use the database params.
2016-12-08 19:24:12 -07:00
markjcrane 9b1b38fab6 Improve security on the lua scripts, add lua json library, add *77 dnd toggle feature code, speed dial *0[ext], and improve blf support for extension number alias. 2016-12-08 18:36:15 -07:00
FusionPBX 30acee4dff Delete provision_write.php 2016-12-06 10:57:45 -07:00
FusionPBX d85528b195 Update device_edit.php 2016-12-06 10:47:31 -07:00
FusionPBX 0a90bd9472 Update device_profile_edit.php 2016-12-06 10:44:09 -07:00
FusionPBX 5e7e2e0778 Update device_dashboard.php 2016-12-06 10:43:16 -07:00
FusionPBX e7879e8b2f Update device_profile_delete.php 2016-12-06 10:42:05 -07:00
FusionPBX 249f0f4b45 Update device_delete.php 2016-12-06 10:39:45 -07:00
FusionPBX d45f89d5fe Update extension_edit.php
Fixes a permission issue for extension edit.
2016-12-06 10:31:44 -07:00
FusionPBX 9fb41cb357 Update 2016-12-03 13:33:47 -07:00
FusionPBX 99e0dfac48 Update voicemail.php
Increase security on the voicemail php class.
2016-12-03 12:03:09 -07:00
FusionPBX b6d49aed5e Update
Fix the bug where voicemail id is null.
2016-12-03 11:56:43 -07:00
FusionPBX 0d913c2b47 Update voicemail_messages.php 2016-12-03 11:53:16 -07:00
FusionPBX 4d03f5f356 Update fax_send.php
Use fax variables from default settings fax category.
2016-12-02 21:28:33 -07:00
FusionPBX d5c7f53be3 Update fax_to_email.php
Remove the hard coded fax_enable_t38=true,fax_enable_t38_request=true in favor of default settings -> fax -> variables.
2016-12-02 21:18:35 -07:00
FusionPBX b96f15fe4e Update fax_to_email.php 2016-12-02 17:17:14 -07:00
FusionPBX 0e5cd1d932 Create json_cdr.conf.xml 2016-12-02 12:23:09 -07:00
FusionPBX 6980ba6a4a Update {$mac}.xml
Add the SPA dialplan to Dial_Plan_2_
2016-12-02 01:59:26 -07:00
FusionPBX d3acbd3289 Update fax_to_email.php
Should fix fax relay and fax forward.
2016-12-02 00:44:38 -07:00
FusionPBX 2348767ab9 Update extension_copy.php
Change the color to red on the duplicate message.
2016-11-29 12:07:26 -07:00
FusionPBX 472069555c Update extension_copy.php 2016-11-29 11:57:54 -07:00
FusionPBX a25dad50bf Update extension.php 2016-11-29 11:50:52 -07:00
FusionPBX 54a83d5725 Update extension.php
I'm prove the extension exists method.
2016-11-29 11:39:14 -07:00
FusionPBX 9c04d93b56 Update extension.php 2016-11-29 11:05:42 -07:00
jebsolutions 04196328ef typo fix (#2200)
Ooh Noo.
2016-11-26 16:08:35 -07:00
FusionPBX 66978fae79 Update gateways.php 2016-11-25 20:39:18 -07:00
FusionPBX b2827775dc Update app_defaults.php
Make sure the temp directory exist in default settings.
2016-11-25 14:29:55 -07:00
FusionPBX b445fd24a8 Update voicemails.php
Uppercase the SQL, cast voicemail id as text, and add sterilize user data.
2016-11-24 13:02:40 -07:00
FusionPBX 50d6e4e2ff Update extension_edit.php
Prevent a minor SQL error.
2016-11-24 12:23:49 -07:00
FusionPBX b0429f15b5 Update extension.php 2016-11-24 11:35:10 -07:00
FusionPBX b9ee3c816f Update {$mac}.cfg 2016-11-24 01:44:26 -07:00
FusionPBX 9dcfbb5234 Update {$mac}.cfg 2016-11-24 01:43:56 -07:00
jebsolutions 8547f2ac32 fixes for #1821 4.2 branch (#2034)
* fixes for #1822 4.2 branch

app/extensions/app_languages.php
+ add duplicate extension error prompt

app/extensions/extension_copy.php
+ add check to see if duplicate extension exists

app/extensions/resources/classes/extension.php
+ add function to check if extension exists
+ all cherry picks "AND AND" fix from master

* fix typo

* Update app_languages.php

* Update extension_copy.php

* Update extension.php
2016-11-24 01:12:21 -07:00
FusionPBX 42aa667a26 Update app_languages.php 2016-11-24 00:56:11 -07:00
FusionPBX 14e1b6c668 Update y000000000044.cfg
Fix the reference to the yealink_t23g_firmware_url variable.
2016-11-23 23:25:36 -07:00
FusionPBX 7809b63e72 Update provision.php
Add ability to use provision settings with type boolean and numeric.
2016-11-23 22:44:38 -07:00
FusionPBX 3dd0f69b03 Create recording_play.php
Add the missing recording play file.
2016-11-23 22:07:07 -07:00
FusionPBX 72ead8b3b1 Update xml_cdr_details.php
Fix the recording links in the xml cdr details for the 4.2 branch.
2016-11-23 22:03:03 -07:00
FusionPBX 209cfbc524 Update {$mac}.cfg
Prevent ghost calls for polycom.
2016-11-23 15:48:02 -07:00
FusionPBX 4b37db4fba Update {$mac}.cfg
Prevent ghost calls for polycom.
2016-11-23 15:46:54 -07:00
FusionPBX fd17546365 Update xml_cdr.php
Fix missed calls on the extension summary.
2016-11-23 05:25:27 -07:00
FusionPBX 17e0ab3181 Update index.lua
Get the sip_from_user and sip_number_alias session variables.
2016-11-23 01:21:25 -07:00
jebsolutions f60b25175d [4.2] fix orphan v_ring_group_users after deleting ring group (#2111)
Same as pr #2110 except for 4.2 branch

steps to test:
create a ring group with one extension and one user. This will add one user to v_ring_group_users table. Delete the ring group.

expected result:
ring group and all it's components are deleted

actual result
v_ring_group_user entry for this ring group is not deleted.

This fix: deletes v_ring_group_user when ring group is deleted.
2016-11-21 13:59:51 -07:00
FusionPBX 130e415bc9 Update app_defaults.php 2016-11-20 16:50:03 -07:00
jebsolutions aa12c13056 include stderr in git pull results and check for error (#2104)
Old result (seems correct but actually failed)
Updating d190f6a..d958bea

Corrected result (includes failure message):
Updating d190f6a..d958bea
error: Your local changes to the following files would be overwritten by merge:
        app/fax/fax_log_view.php
Please, commit your changes or stash them before you can merge.
2016-11-20 13:55:12 -07:00
FusionPBX 59659ddb7a Update {$mac}.cfg 2016-11-14 23:27:35 -07:00
FusionPBX f47509143a Update ivr.conf.lua
Use ${default_language}/${default_dialect}/${default_voice} instead as it will work better when the IVR Menu is cached.
2016-11-14 12:07:04 -07:00
FusionPBX 8a3d4a2488 Update ivr.conf.lua
Fixed multi-lingual support for IVR Menu direct dial your call is being transferred and invalid entry.
2016-11-14 11:47:23 -07:00
FusionPBX 0ffb43d2a9 Update css.php
CSS fix the overwrap problem on the pre html tags.
2016-11-06 01:45:50 -07:00
FusionPBX f43c639ecc Update index.lua
Add additional security when using voicemail_authorized = true.
2016-11-06 01:07:08 -06:00
jebsolutions 251b808558 #1987 combined fix for 4.2 (#2030)
app/fax/app_defaults.php:
+ fix: duplicate check only within same default_setting_category.  This fixes the bug where "keep_local" for fax wasn't being created because there was a "keep_local" for voicemail.  Without this fix you will get a lua error due to the field not being set and nothing shows up in the sent faxes log.

fax/fax_log_view.php:
+ fix: back button text is missing.  Copied correct localized text code from another fax page that worked.

app/fax/app_config.php
+ fix: date field is now timestamp for postgres+mysql.  This fixes the listing only showing the date, not the time as well.

Note: app->defaults doesn't change field types.  Existing installs will have to manually update the field type e.g. for postgres:

sudo -sHu postgres
\d fusionpbx
alter table v_fax_logs alter column fax_date type timestamp without time zone;
\q
2016-11-03 16:25:02 -06:00
FusionPBX 3d52bba57d Update ldap.php
If the password is not provided then set user authorized to false.
2016-11-02 00:34:18 -06:00
FusionPBX 1633a2730d Update install_switch.php 2016-10-31 23:47:10 -06:00
jebsolutions 0ed5657ec6 email/fax fixes for 4.2 branch (#2022)
I updated this to latest 4.2.
2016-10-31 14:21:26 -06:00
FusionPBX b887eb4c82 Update message_waiting.lua 2016-10-30 12:16:49 -06:00
FusionPBX 29b08aa753 Update vars.xml 2016-10-27 12:44:20 -06:00
FusionPBX 213de55ccc Update xml_cdr.php 2016-10-25 18:05:55 -06:00
FusionPBX b75f73f28a Update ivr.conf.lua
Move direct dial after the options.
2016-10-25 10:07:19 -06:00
FusionPBX 8147223696 Update {$mac}.xml 2016-10-24 15:10:06 -06:00
FusionPBX cdd04a39ee Update extension.php 2016-10-18 00:19:10 -06:00
FusionPBX e0b10228e0 Update database.php
Remove the changes to the 4.2 database class they were meant for the master branch.
2016-10-16 10:47:11 -06:00
FusionPBX 6162768599 Update database.php
Moving orm method into to the database class goal is to remove orm class in the near future.
2016-10-16 10:40:03 -06:00
FusionPBX a10ce2d162 Update ivr.conf.lua
Fix IVR Menu greet short.
2016-10-16 01:07:56 -06:00
hargut 687e02569d [4.2] allow page-break on fax_message & fax_footer (#1978)
* enable page-breaks on fax messages

* fix footer & allow page break

* update footer placement to work properly on single page
2016-10-11 22:52:14 -07:00
FusionPBX f52649f2fd Update macro.lua 2016-10-08 09:53:29 -06:00
FusionPBX 65ba2caa57 Update permissions.php 2016-10-01 12:10:07 -06:00
FusionPBX 7887489078 Update xml_cdr_inc.php 2016-09-30 01:02:15 -06:00
Luis Daniel Lucio Quiroz aa21a1c4a5 Look further for domain_name (#1954)
Same rationale as 4.0
2016-09-28 17:57:29 -06:00
FusionPBX 3266c14409 Update fax_to_email.php
Fix fax to email when using method and smtp_port.
2016-09-28 13:32:09 -06:00
FusionPBX 500e42c2ac Update play_greeting.lua 2016-09-25 01:45:05 -06:00
FusionPBX 95a12e2fcd Update recordings.php
When uploading a recording ensure that the domain name directory exists so the file can be uploaded to it.
2016-09-22 19:26:40 -06:00
hargut 760c44b7b0 [4.2] Fix e-mail attachment handling / conversion & allow local emails to be valid (#1921) (#1933)
* Enable local email addresses to be valid. E.g required for local Fax submission.
* Fix filenames & allow spaces in filenames.
* Fix attachment file names.
* Revert "Fix filenames & allow spaces in filenames."
2016-09-20 21:11:13 -06:00
FusionPBX 5d9720c983 Update index.php 2016-09-20 16:51:38 -06:00
Luis Daniel Lucio Quiroz cb3b0e6f06 Fix load balancing (#1919) 2016-09-18 22:09:25 -06:00
FusionPBX 5343cfd641 Update macro.lua 2016-09-18 14:05:52 -06:00
FusionPBX 5a1f8feeec Update macro.lua 2016-09-17 18:21:36 -06:00
FusionPBX c0fdf6d9ad Update check_auth.php 2016-09-16 18:07:47 -06:00
FusionPBX 7f559315a2 Update switch.conf.xml
Update mailer-app and mailer-app-args.
2016-09-15 14:11:10 -06:00
FusionPBX 53b701c398 Update time_condition_edit.php
Time condition time-of-day use 1 minute increments this solves multiple problems and more flexible for minutes 0 - 59.
2016-09-13 19:43:02 -06:00
FusionPBX 89a5f06bb7 Update ivr_menu.php 2016-09-12 15:51:29 -06:00
FusionPBX 639516828b Update permissions.php
Use the new array structure.
2016-09-12 15:42:05 -06:00
FusionPBX 26c4168cab Update authentication.php 2016-09-11 12:52:15 -06:00
FusionPBX cd34ed0527 Update database.php 2016-09-11 12:45:39 -06:00
FusionPBX 69e258e8ae Update check_auth.php
Set the domain_uuid session variables.
2016-09-11 12:28:12 -06:00
FusionPBX 928dd3ecfa Update authentication.php
Make the database the default authentication plugin if the default setting -> authentication is not set.
2016-09-11 09:52:29 -06:00
FusionPBX b61e746b1e Fix a spelling mistake in ldap.php. 2016-09-11 09:09:16 -06:00
138 changed files with 5081 additions and 1917 deletions
+4
View File
@@ -445,6 +445,10 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the extension.";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_speed_dial";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the speed dial.";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_description";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the description.";
+22
View File
@@ -879,6 +879,17 @@ $text['label-phone_tools']['sv-se'] = "Verktyg";
$text['label-phone_tools']['de-at'] = "Funktionen";
$text['label-phone_tools']['he'] = "כלים";
$text['label-phone_speed_dial']['en-us'] = "Speed Dial";
$text['label-phone_speed_dial']['es-cl'] = "";
$text['label-phone_speed_dial']['pt-pt'] = "";
$text['label-phone_speed_dial']['fr-fr'] = "";
$text['label-phone_speed_dial']['pt-br'] = "";
$text['label-phone_speed_dial']['pl'] = "";
$text['label-phone_speed_dial']['uk'] = "";
$text['label-phone_speed_dial']['sv-se'] = "";
$text['label-phone_speed_dial']['de-at'] = "";
$text['label-phone_speed_dial']['he'] = "";
$text['label-phone_numbers']['en-us'] = "Numbers";
$text['label-phone_numbers']['es-cl'] = "Números";
$text['label-phone_numbers']['pt-pt'] = "Números";
@@ -2019,6 +2030,17 @@ $text['description-phone_primary']['sv-se'] = "Sätt som primärt Nummer för de
$text['description-phone_primary']['de-at'] = "Als primäre Nummer für diesen Kontakt setzen.";
$text['description-phone_primary']['he'] = "";
$text['description-phone_speed_dial']['en-us'] = "Enter the speed dial number.";
$text['description-phone_speed_dial']['es-cl'] = "";
$text['description-phone_speed_dial']['pt-pt'] = "";
$text['description-phone_speed_dial']['fr-fr'] = "";
$text['description-phone_speed_dial']['pt-br'] = "";
$text['description-phone_speed_dial']['pl'] = "";
$text['description-phone_speed_dial']['uk'] = "";
$text['description-phone_speed_dial']['sv-se'] = "";
$text['description-phone_speed_dial']['de-at'] = "";
$text['description-phone_speed_dial']['he'] = "";
$text['description-phone_number']['en-us'] = "Enter the phone number.";
$text['description-phone_number']['es-cl'] = "Ingrese el número de teléfono.";
$text['description-phone_number']['pt-pt'] = "Introduza o número de telefone";
+36 -14
View File
@@ -17,23 +17,27 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('contact_phone_edit') || permission_exists('contact_phone_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('contact_phone_edit') || permission_exists('contact_phone_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
@@ -48,9 +52,10 @@ else {
$action = "add";
}
if (strlen($_GET["contact_uuid"]) > 0) {
$contact_uuid = check_str($_GET["contact_uuid"]);
}
//get the uuid
if (strlen($_GET["contact_uuid"]) > 0) {
$contact_uuid = check_str($_GET["contact_uuid"]);
}
//get http post variables and set them to php variables
if (count($_POST)>0) {
@@ -60,6 +65,7 @@ if (strlen($_GET["contact_uuid"]) > 0) {
$phone_type_text = check_str($_POST["phone_type_text"]);
$phone_label = check_str($_POST["phone_label"]);
$phone_label_custom = check_str($_POST["phone_label_custom"]);
$phone_speed_dial = check_str($_POST["phone_speed_dial"]);
$phone_number = check_str($_POST["phone_number"]);
$phone_extension = check_str($_POST["phone_extension"]);
$phone_primary = check_str($_POST["phone_primary"]);
@@ -128,6 +134,7 @@ if (strlen($_GET["contact_uuid"]) > 0) {
$sql .= "phone_type_video, ";
$sql .= "phone_type_text, ";
$sql .= "phone_label, ";
$sql .= "phone_speed_dial, ";
$sql .= "phone_number, ";
$sql .= "phone_extension, ";
$sql .= "phone_primary, ";
@@ -143,6 +150,7 @@ if (strlen($_GET["contact_uuid"]) > 0) {
$sql .= (($phone_type_video) ? 1 : 'null').", ";
$sql .= (($phone_type_text) ? 1 : 'null').", ";
$sql .= "'".$phone_label."', ";
$sql .= "'".$phone_speed_dial."', ";
$sql .= "'".$phone_number."', ";
$sql .= "'".$phone_extension."', ";
$sql .= (($phone_primary) ? 1 : 0).", ";
@@ -164,6 +172,7 @@ if (strlen($_GET["contact_uuid"]) > 0) {
$sql .= "phone_type_video = ".(($phone_type_video) ? 1 : 'null').", ";
$sql .= "phone_type_text = ".(($phone_type_text) ? 1 : 'null').", ";
$sql .= "phone_label = '".$phone_label."', ";
$sql .= "phone_speed_dial = '".$phone_speed_dial."', ";
$sql .= "phone_number = '".$phone_number."', ";
$sql .= "phone_extension = '".$phone_extension."', ";
$sql .= "phone_primary = ".(($phone_primary) ? 1 : 0).", ";
@@ -195,6 +204,7 @@ if (strlen($_GET["contact_uuid"]) > 0) {
$phone_type_video = $row["phone_type_video"];
$phone_type_text = $row["phone_type_text"];
$phone_label = $row["phone_label"];
$phone_speed_dial = $row["phone_speed_dial"];
$phone_number = $row["phone_number"];
$phone_extension = $row["phone_extension"];
$phone_primary = $row["phone_primary"];
@@ -297,6 +307,17 @@ if (strlen($_GET["contact_uuid"]) > 0) {
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-phone_speed_dial']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='phone_speed_dial' maxlength='255' min='0' step='1' value=\"$phone_speed_dial\">\n";
echo "<br />\n";
echo $text['description-phone_speed_dial']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-phone_number']."\n";
@@ -360,4 +381,5 @@ if (strlen($_GET["contact_uuid"]) > 0) {
//include the footer
require_once "resources/footer.php";
?>
+7 -3
View File
@@ -272,9 +272,13 @@
}
//write the provision files
//if (strlen($_SESSION['provision']['path']['text']) > 0) {
//require_once "app/provision/provision_write.php";
//}
if (strlen($_SESSION['provision']['path']['text']) > 0) {
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
}
}
//set the message
if (!isset($_SESSION['message'])) {
+8 -2
View File
@@ -71,11 +71,17 @@ else {
}
//write the provision files
require_once "app/provision/provision_write.php";
if (strlen($_SESSION['provision']['path']['text']) > 0) {
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
}
}
//set the message and redirect the user
$_SESSION["message"] = $text['message-delete'];
header("Location: devices.php");
return;
?>
?>
+5 -1
View File
@@ -312,7 +312,11 @@
//write the provision files
if (strlen($_SESSION['provision']['path']['text']) > 0) {
require_once "app/provision/provision_write.php";
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
}
}
//set the message
+8 -2
View File
@@ -66,11 +66,17 @@ else {
}
//write the provision files
require_once "app/provision/provision_write.php";
if (strlen($_SESSION['provision']['path']['text']) > 0) {
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
}
}
//set the message and redirect the user
$_SESSION["message"] = $text['message-delete'];
header("Location: device_profiles.php");
return;
?>
?>
+5 -1
View File
@@ -141,7 +141,11 @@
//write the provision files
if (strlen($_SESSION['provision']['path']['text']) > 0) {
require_once "app/provision/provision_write.php";
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
}
}
//set the message
@@ -0,0 +1,7 @@
<context name="{v_context}">
<extension name="speed_dial" number="*0[ext]" continue="false" app_uuid="1a4a2611-01e3-4582-982b-4ada4d314ea3" enabled="true">
<condition field="destination_number" expression="^\*0(.*)$">
<action application="lua" data="app.lua speed_dial $1"/>
</condition>
</extension>
</context>
@@ -1,5 +1,9 @@
<context name="{v_context}">
<extension name="do-not-disturb" number="*78,*79" continue="false" app_uuid="df32d982-e39e-4ae5-a46d-aed1893873f2" enabled="true">
<extension name="do-not-disturb" number="*77,*78,*79" continue="false" app_uuid="df32d982-e39e-4ae5-a46d-aed1893873f2" enabled="true">
<condition field="destination_number" expression="^\*77$" break="on-true">
<action application="set" data="enabled=toggle"/>
<action application="lua" data="do_not_disturb.lua"/>
</condition>
<condition field="destination_number" expression="^\*78$|\*363$" break="on-true">
<action application="set" data="enabled=true"/>
<action application="lua" data="do_not_disturb.lua"/>
@@ -33,6 +33,7 @@
<!--<action application="export" data="nolocal:sip_secure_media=${user_data(${dialed_extension}@${domain_name} var sip_secure_media)}"/>-->
<action application="hash" data="insert/${domain_name}-last_dial/${called_party_call_group}/${uuid}"/>
<action application="set" data="api_hangup_hook=lua app.lua hangup"/>
<action application="export" data="domain_name=${context}"/>
<!-- standard method -->
<action application="bridge" data="user/${destination_number}@${domain_name}"/>
<!-- sofia contact -->
+1 -1
View File
@@ -72,7 +72,7 @@
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "number_alias";
//$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
//$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "extension_toll";
+1 -1
View File
@@ -1598,4 +1598,4 @@ $text['button-call_routing']['ro'] = "rutare de apel";
$text['button-call_routing']['ar-eg'] = "توجيه الدعوة";
$text['button-call_routing']['he'] = "ניתוב שיחות";
?>
?>
+27 -14
View File
@@ -17,23 +17,27 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
if (permission_exists('extension_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('extension_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
@@ -47,7 +51,16 @@ else {
$number_alias_new = check_str($_REQUEST["alias"]);
}
}
// skip the copy if the domain extension already exists
$extension = new extension;
if ($extension->exists($_SESSION['domain_uuid'], $extension_new)) {
$_SESSION['message_mood'] = 'negative';
$_SESSION["message"] = $text['message-duplicate'];
header("Location: extensions.php");
return;
}
//get the v_extensions data
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = '$domain_uuid' ";
@@ -228,4 +241,4 @@ else {
header("Location: extensions.php");
return;
?>
?>
+23 -16
View File
@@ -675,7 +675,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
}
$sql .= "call_group = '$call_group', ";
$sql .= "call_screen_enabled = '$call_screen_enabled', ";
$sql .= "user_record = '$user_record', ";
if (permission_exists('extension_user_record')) {
$sql .= "user_record = '$user_record', ";
}
$sql .= "hold_music = '$hold_music', ";
$sql .= "auth_acl = '$auth_acl', ";
$sql .= "cidr = '$cidr', ";
@@ -771,9 +773,12 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
}
//write the provision files
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
require_once "app/provision/provision_write.php";
$ext = new extension;
if (strlen($_SESSION['provision']['path']['text']) > 0) {
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
}
}
//clear the cache
@@ -936,19 +941,21 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
unset($sql, $prep_statement);
//get assigned users
$sql = "SELECT u.username, e.user_uuid FROM v_extension_users as e, v_users as u ";
$sql .= "where e.user_uuid = u.user_uuid ";
$sql .= "and u.user_enabled = 'true' ";
$sql .= "and e.domain_uuid = '".$domain_uuid."' ";
$sql .= "and e.extension_uuid = '".$extension_uuid."' ";
$sql .= "order by u.username asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$assigned_users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach($assigned_users as $field) {
$assigned_user_uuids[] = $field['user_uuid'];
if (is_uuid($extension_uuid)) {
$sql = "SELECT u.username, e.user_uuid FROM v_extension_users as e, v_users as u ";
$sql .= "where e.user_uuid = u.user_uuid ";
$sql .= "and u.user_enabled = 'true' ";
$sql .= "and e.domain_uuid = '".$domain_uuid."' ";
$sql .= "and e.extension_uuid = '".$extension_uuid."' ";
$sql .= "order by u.username asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$assigned_users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach($assigned_users as $field) {
$assigned_user_uuids[] = $field['user_uuid'];
}
unset($sql, $prep_statement);
}
unset($sql, $prep_statement);
//get the users
$sql = "SELECT * FROM v_users ";
+30 -4
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2010 - 2014
Copyright (C) 2010 - 2016
All Rights Reserved.
Contributor(s):
@@ -72,8 +72,16 @@ if (!class_exists('extension')) {
public $description;
public function __construct() {
require_once "resources/classes/database.php";
$this->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
//connect to the database if not connected
if (!$this->db) {
require_once "resources/classes/database.php";
$database = new database;
$database->connect();
$this->db = $database->db;
}
//set the application id
$this->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
}
public function __destruct() {
@@ -82,6 +90,24 @@ if (!class_exists('extension')) {
}
}
public function exists($domain_uuid, $extension) {
$sql = "select extension_uuid from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and (extension = :extension or number_alias = :extension) ";
$sql .= "and enabled = 'true' ";
$prep_statement = $this->db->prepare($sql);
$prep_statement->bindParam(':domain_uuid', $domain_uuid);
$prep_statement->bindParam(':extension', $extension);
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if ($result && count($result) > 0) {
return true;
}
else {
return false;
}
}
public function get_domain_uuid() {
return $this->domain_uuid;
}
@@ -174,7 +200,7 @@ if (!class_exists('extension')) {
//write the xml files
$sql = "SELECT * FROM v_extensions AS e, v_voicemails AS v ";
$sql .= "WHERE e.domain_uuid = '$domain_uuid' ";
$sql .= "AND AND COALESCE(NULLIF(e.number_alias,''),e.extension) = CAST(v.voicemail_id as VARCHAR) ";
$sql .= "AND COALESCE(NULLIF(e.number_alias,''),e.extension) = CAST(v.voicemail_id as VARCHAR) ";
$sql .= "ORDER BY e.call_group ASC ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
+3 -1
View File
@@ -507,7 +507,9 @@
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_date";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "date";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "timestamp";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "date";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "timestamp";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_epoch";
+1 -1
View File
@@ -139,7 +139,7 @@ if ($domains_processed == 1) {
$x++;
//get an array of the default settings
$sql = "select * from v_default_settings ";
$sql = "select * from v_default_settings where default_setting_category = 'fax'";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+2 -4
View File
@@ -11,10 +11,8 @@ else {
}
//add multi-lingual support
require_once "app_languages.php";
foreach($text as $key => $value) {
$text[$key] = $value[$_SESSION['domain']['language']['code']];
}
$language = new text;
$text = $language->get();
//pre-populate the form
if (isset($_REQUEST["id"]) && isset($_REQUEST["fax_uuid"])) {
+55 -16
View File
@@ -346,6 +346,11 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){
$fax_name = str_replace("+", "_", $fax_name);
$fax_name = str_replace("=", "_", $fax_name);
$attachment_file_name = $_files['name'][$index];
rename($dir_fax_temp.'/'.$attachment_file_name, $dir_fax_temp.'/'.$fax_name.'.'.$fax_file_extension);
unset($attachment_file_name);
if (!$included) {
//move uploaded file
move_uploaded_file($_files['tmp_name'][$index], $dir_fax_temp.'/'.$fax_name.'.'.$fax_file_extension);
@@ -530,19 +535,51 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){
}
//message
$pdf -> Rect($x + 0.5, $y + 3.4, 7.5, 6.25, 'D');
if ($fax_message != '') {
$pdf -> SetAutoPageBreak(true, 0.6);
$pdf -> SetTopMargin(0.6);
$pdf -> SetFont($pdf_font, "", 12);
$pdf -> SetXY($x + 0.75, $y + 3.65);
$pdf -> MultiCell(7, 5.75, $fax_message, 0, 'L', false);
}
$pages = $pdf -> getNumPages();
if($pages > 1) {
# save ynew for last page
$yn = $pdf -> GetY();
# First page
$pdf -> setPage(1, 0);
$pdf -> Rect($x + 0.5, $y + 3.4, 7.5, $page_height - 3.9, 'D');
# 2nd to N-th page
for ($n = 2; $n < $pages; $n++) {
$pdf -> setPage($n, 0);
$pdf -> Rect($x + 0.5, $y + 0.5, 7.5, $page_height - 1, 'D');
}
#Last page
$pdf -> setPage($pages, 0);
$pdf -> Rect($x + 0.5, 0.5, 7.5, $yn, 'D');
$y = $yn;
unset($yn);
}
else {
$pdf -> Rect($x + 0.5, $y + 3.4, 7.5, 6.25, 'D');
$y = $pdf -> GetY();
}
//footer
if ($fax_footer != '') {
$pdf -> SetAutoPageBreak(true, 0.6);
$pdf -> SetTopMargin(0.6);
$pdf -> SetFont("helvetica", "", 8);
$pdf -> SetXY($x + 0.5, $y + 9.9);
$pdf -> SetXY($x + 0.5, $y + 0.6);
$pdf -> MultiCell(7.5, 0.75, $fax_footer, 0, 'C', false);
}
$pdf -> SetAutoPageBreak(false);
$pdf -> SetTopMargin(0);
// save cover pdf
$pdf -> Output($dir_fax_temp.'/'.$fax_instance_uuid.'_cover.pdf', "F"); // Display [I]nline, Save to [F]ile, [D]ownload
@@ -686,19 +723,18 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){
//send the fax
$fax_file = $dir_fax_temp."/".$fax_instance_uuid.".tif";
$common_dial_string = "for_fax=1,";
$common_dial_string .= "accountcode='" . $fax_accountcode . "',";
$common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',";
$common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ",";
$common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ",";
$common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',";
$common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',";
$common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',";
$common_dial_string .= "fax_header='" . $fax_caller_id_name . "',";
$common_dial_string .= "fax_file='" . $fax_file . "',";
$dial_string = "for_fax=1,";
$dial_string .= "accountcode='" . $fax_accountcode . "',";
$dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',";
$dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ",";
$dial_string .= "domain_name=" . $_SESSION["domain_name"] . ",";
$dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',";
$dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',";
$dial_string .= "fax_ident='" . $fax_caller_id_number . "',";
$dial_string .= "fax_header='" . $fax_caller_id_name . "',";
$dial_string .= "fax_file='" . $fax_file . "',";
foreach ($fax_numbers as $fax_number) {
$dial_string = $common_dial_string;
fax_split_dtmf($fax_number, $fax_dtmf);
@@ -708,16 +744,19 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){
if (count($route_array) == 0) {
//send the internal call to the registered extension
$fax_uri = "user/".$fax_number."@".$_SESSION['domain_name'];
$t38 = "";
$fax_variables = "";
}
else {
//send the external call
$fax_uri = $route_array[0];
$t38 = "fax_enable_t38=true,fax_enable_t38_request=true,";
$fax_variables = "";
foreach($_SESSION['fax']['variable'] as $variable) {
$fax_variables .= $variable.",";
}
}
if ($fax_send_mode != 'queue') {
$dial_string .= $t38;
$dial_string .= $fax_variables;
$dial_string .= "mailto_address='" . $mailto_address . "',";
$dial_string .= "mailfrom_address='" . $mailfrom_address . "',";
$dial_string .= "fax_uri=" . $fax_uri . ",";
+14 -10
View File
@@ -23,16 +23,20 @@
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('gateway_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('gateway_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
@@ -450,6 +450,13 @@ include "root.php";
//echo "</pre>\n";
//exit;
//add the dialplan permission
$p = new permissions;
$p->add("dialplan_add", 'temp');
$p->add("dialplan_detail_add", 'temp');
$p->add("dialplan_edit", 'temp');
$p->add("dialplan_detail_edit", 'temp');
//save the dialplan
$orm = new orm;
$orm->name('dialplans');
@@ -465,6 +472,12 @@ include "root.php";
//echo "</pre>\n";
//exit;
//remove the temporary permission
$p->delete("dialplan_add", 'temp');
$p->delete("dialplan_detail_add", 'temp');
$p->delete("dialplan_edit", 'temp');
$p->delete("dialplan_detail_edit", 'temp');
//synchronize the xml config
save_dialplan_xml();
+3 -5
View File
@@ -54,10 +54,8 @@ openlog("fusion-provisioning", LOG_PID | LOG_PERROR, LOG_LOCAL0);
}
// Escence make request based on UserID for Memory keys
/*
The file name is fixed to `Account1_Extern.xml`.
(Account1 is the first account you register)
*/
// The file name is fixed to `Account1_Extern.xml`.
// (Account1 is the first account you register)
if(empty($mac) && !empty($ext)){
$domain_array = explode(":", $_SERVER["HTTP_HOST"]);
$domain_name = $domain_array[0];
@@ -84,7 +82,7 @@ The file name is fixed to `Account1_Extern.xml`.
}
//prepare the mac address
if (isset($_REQUEST['mac'])) {
if (isset($mac)) {
//normalize the mac address to lower case
$mac = strtolower($mac);
//replace all non hexadecimal values and validate the mac address
-42
View File
@@ -1,42 +0,0 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2008-2014 All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
include "resources/classes/template.php";
if (if_group("admin") || if_group("superadmin")) {
//access granted
}
else {
echo "access denied";
exit;
}
//output template to string for header processing
$prov = new provision;
$prov->domain_uuid = $domain_uuid;
$response = $prov->write();
?>
@@ -281,6 +281,8 @@ include "root.php";
foreach($_SESSION['provision'] as $key=>$val) {
if (strlen($val['var']) > 0) { $value = $val['var']; }
if (strlen($val['text']) > 0) { $value = $val['text']; }
if (strlen($val['boolean']) > 0) { $value = $val['boolean']; }
if (strlen($val['numeric']) > 0) { $value = $val['numeric']; }
if (strlen($value) > 0) { $provision[$key] = $value; }
unset($value);
}
+88
View File
@@ -0,0 +1,88 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('recording_play')) {
//access granted
}
else {
echo "access denied";
exit;
}
$filename = base64_decode($_GET['filename']);
$type = $_GET['type']; //moh //rec
//show the content
?>
<html>
<head>
</head>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align='center'>
<b>file: <?php echo $filename ?></b>
</td>
</tr>
<tr>
<td align='center'>
<?php
// detect browser
$user_agent = http_user_agent();
$browser_name = $user_agent['name'];
$file_ext = substr($filename, -3);
if ($file_ext == "wav") {
//HTML5 method
if ($browser_name == "Google Chrome" || $browser_name == "Mozilla Firefox") {
echo "<audio src=\"recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" autoplay=\"true\" ></audio>";
}
else {
echo "<audio src=\"http://localhost:8000/mod/recordings/recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" autoplay=\"autoplay\"></audio>";
echo "<embed src=\"recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" autostart=\"true\" width=\"300\" height=\"90\" name=\"sound_".$filename."\" enablejavascript=\"true\">\n";
}
}
if ($file_ext == "mp3") {
echo "<object type=\"application/x-shockwave-flash\" width=\"400\" height=\"17\" data=\"slim.swf?autoplay=true&song_title=".urlencode($filename)."&song_url=recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\">\n";
echo "<param name=\"movie\" value=\"slim.swf?autoplay=true&song_url=recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" />\n";
echo "<param name=\"quality\" value=\"high\"/>\n";
echo "<param name=\"bgcolor\" value=\"#E6E6E6\"/>\n";
echo "</object>\n";
}
?>
</td>
</tr>
</table>
</body>
</html>
+23 -10
View File
@@ -17,16 +17,18 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
James Rose <james.o.rose@gmail.com>
*/
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//add multi-lingual support
$language = new text;
@@ -49,7 +51,8 @@ require_once "resources/check_auth.php";
if ($_GET['a'] == "download" && (permission_exists('recording_play') || permission_exists('recording_download'))) {
session_cache_limiter('public');
if ($_GET['type'] = "rec") {
$path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'];
//set the path for the directory
$path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'];
//if from recordings, get recording details from db
$recording_uuid = check_str($_GET['id']); //recordings
@@ -125,11 +128,21 @@ require_once "resources/check_auth.php";
//upload the recording
if (permission_exists('recording_upload')) {
if ($_POST['submit'] == $text['button-upload'] && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
$recording_filename = str_replace(" ", "_", $_FILES['ulfile']['name']);
$recording_filename = str_replace("'", "", $recording_filename);
move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename);
$_SESSION['message'] = $text['message-uploaded'].": ".htmlentities($recording_filename);
//remove special characters
$recording_filename = str_replace(" ", "_", $_FILES['ulfile']['name']);
$recording_filename = str_replace("'", "", $recording_filename);
//make sure the destination directory exists
if (!is_dir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'])) {
event_socket_mkdir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name']);
}
//move the uploaded files
move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename);
//set the message
$_SESSION['message'] = $text['message-uploaded'].": ".htmlentities($recording_filename);
//set the file name to be inserted as the recording description
$recording_description = base64_encode($_FILES['ulfile']['name']);
@@ -479,4 +492,4 @@ function range_download($file) {
fclose($fp);
}
?>
?>
+7
View File
@@ -72,6 +72,13 @@ else {
$sql .= "and ring_group_uuid = '".$id."' ";
$db->exec(check_sql($sql));
unset($sql);
//delete the ring group users
$sql = "delete from v_ring_group_users ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and ring_group_uuid = '".$id."' ";
$db->exec(check_sql($sql));
unset($sql);
//delete the dialplan details
$sql = "delete from v_dialplan_details ";
@@ -252,11 +252,13 @@ if (!class_exists('scripts')) {
}
$tmp .= "--set defaults\n";
$tmp .= " expire = {}\n";
$tmp .= " expire.default = \"3600\";\n";
$tmp .= " expire.directory = \"3600\";\n";
$tmp .= " expire.dialplan = \"3600\";\n";
$tmp .= " expire.languages = \"3600\";\n";
$tmp .= " expire.sofia = \"3600\";\n";
$tmp .= " expire.acl = \"3600\";\n";
$tmp .= " expire.ivr = \"3600\";\n";
$tmp .= "\n";
$tmp .= "--set xml_handler\n";
$tmp .= " xml_handler = {}\n";
+3 -5
View File
@@ -296,10 +296,10 @@
if ($cond_var == 'time-of-day') {
$cond_var = 'minute-of-day';
$array_cond_start = explode(':', $cond_start);
$cond_start = ($array_cond_start[0] * 60) + $array_cond_start[1] + 1;
$cond_start = ($array_cond_start[0] * 60) + $array_cond_start[1];
if ($cond_stop != '') {
$array_cond_stop = explode(':', $cond_stop);
$cond_stop = ($array_cond_stop[0] * 60) + $array_cond_stop[1] + 1;
$cond_stop = ($array_cond_stop[0] * 60) + $array_cond_stop[1];
}
}
@@ -758,7 +758,7 @@
case 'time-of-day': //time of day
for (h = 0; h <= 23; h++) {
for (m = 0; m <= 55; m += 5) {
for (m = 0; m <= 59; m += 1) {
sel_start.options[sel_start.options.length] = new Option(((h != 0) ? ((h >= 12) ? ((h == 12) ? h : (h - 12)) + ':' + pad(m, 2) + ' PM' : h + ':' + pad(m, 2) + ' AM') : '12:' + pad(m, 2) + ' AM'), pad(h, 2) + ':' + pad(m, 2));
sel_stop.options[sel_stop.options.length] = new Option(((h != 0) ? ((h >= 12) ? ((h == 12) ? h : (h - 12)) + ':' + pad(m, 2) + ' PM' : h + ':' + pad(m, 2) + ' AM') : '12:' + pad(m, 2) + ' AM'), pad(h, 2) + ':' + pad(m, 2));
}
@@ -960,8 +960,6 @@ if ($action == 'update') {
//convert minute-of-day to time-of-day values
if ($cond_var == 'minute-of-day') {
$cond_var = 'time-of-day';
--$cond_val_start;
--$cond_val_stop;
$cond_val_start = number_pad(floor($cond_val_start / 60),2).":".number_pad(fmod($cond_val_start, 60),2);
if ($cond_val_stop != '') {
$cond_val_stop = number_pad(floor($cond_val_stop / 60),2).":".number_pad(fmod($cond_val_stop, 60),2);
+195 -90
View File
@@ -52,8 +52,25 @@
if (strlen($this->domain_uuid) == 0) {
$this->domain_uuid = $_SESSION['domain_uuid'];
}
}
//get the voicemail_id
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
public function get_voicemail_id() {
//check if for valid input
if (is_uuid($this->voicemail_uuid) && is_uuid($this->domain_uuid) ) {
//input is valid
}
else {
return false;
}
//get the voicemail id if it isn't set already
if (!isset($this->voicemail_id)) {
$sql = "select voicemail_id from v_voicemails ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
@@ -68,14 +85,16 @@
}
}
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
public function voicemails() {
//check if for valid input
if (is_uuid($this->domain_uuid)) {
//input is valid
}
else {
return false;
}
//set the voicemail id and voicemail uuid arrays
if (isset($_SESSION['user']['extension'])) foreach ($_SESSION['user']['extension'] as $index => $row) {
if (strlen($row['number_alias']) > 0) {
@@ -102,12 +121,14 @@
else {
//ensure that the requested voicemail box is assigned to this user
$found = false;
if (is_array($voicemail_uuids)) foreach($voicemail_uuids as $row) {
if ($voicemail_uuid == $row['voicemail_uuid']) {
$sql .= "and voicemail_uuid = '".$row['voicemail_uuid']."' ";
$found = true;
if (is_array($voicemail_uuids)) {
foreach($voicemail_uuids as $row) {
if ($voicemail_uuid == $row['voicemail_uuid']) {
$sql .= "and voicemail_uuid = '".$row['voicemail_uuid']."' ";
$found = true;
}
$x++;
}
$x++;
}
//id requested is not owned by the user return no results
if (!$found) {
@@ -163,74 +184,100 @@
}
public function voicemail_messages() {
$sql = "select * from v_voicemail_messages as m, v_voicemails as v ";
$sql .= "where m.domain_uuid = '$this->domain_uuid' ";
$sql .= "and m.voicemail_uuid = v.voicemail_uuid ";
if (is_array($this->voicemail_id)) {
$sql .= "and (";
$x = 0;
if (is_array($this->voicemail_id)) foreach($this->voicemail_id as $row) {
if ($x > 0) {
$sql .= "or ";
}
$sql .= "v.voicemail_id = '".$row['voicemail_id']."' ";
$x++;
}
$sql .= ") ";
}
else {
$sql .= "and v.voicemail_id = '$this->voicemail_id' ";
}
if (strlen($this->order_by) == 0) {
$sql .= "order by v.voicemail_id, m.created_epoch desc ";
}
else {
$sql .= "order by v.voicemail_id, m.$this->order_by $this->order ";
}
//$sql .= "limit $this->rows_per_page offset $this->offset ";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
$result_count = count($result);
unset ($prep_statement, $sql);
if ($result_count > 0) {
if (is_array($result)) foreach($result as &$row) {
//set the greeting directory
$path = $_SESSION['switch']['voicemail']['dir'].'/default/'.$_SESSION['domain_name'].'/'.$row['voicemail_id'];
if (file_exists($path.'/msg_'.$row['voicemail_message_uuid'].'.wav')) {
$row['file_path'] = $path.'/msg_'.$row['voicemail_message_uuid'].'.wav';
}
if (file_exists($path.'/msg_'.$row['voicemail_message_uuid'].'.mp3')) {
$row['file_path'] = $path.'/msg_'.$row['voicemail_message_uuid'].'.mp3';
}
$row['file_size'] = filesize($row['file_path']);
$row['file_size_label'] = byte_convert($row['file_size']);
$row['file_ext'] = substr($row['file_path'], -3);
$message_length = $row['message_length'];
if ($message_length < 60 ) {
$message_length = $message_length. " sec";
}
else {
$message_length = round(($message_length/60), 2). " min";
}
$row['message_length_label'] = $message_length;
$row['created_date'] = date("j M Y g:i a",$row['created_epoch']);
//check if for valid input
if (is_numeric($this->voicemail_id) && is_uuid($this->domain_uuid)) {
//input is valid
}
}
return $result;
else {
return false;
}
//get the message from the database
$sql = "select * from v_voicemail_messages as m, v_voicemails as v ";
$sql .= "where m.domain_uuid = '$this->domain_uuid' ";
$sql .= "and m.voicemail_uuid = v.voicemail_uuid ";
if (is_array($this->voicemail_id)) {
$sql .= "and (";
$x = 0;
if (is_array($this->voicemail_id)) foreach($this->voicemail_id as $row) {
if ($x > 0) {
$sql .= "or ";
}
$sql .= "v.voicemail_id = '".$row['voicemail_id']."' ";
$x++;
}
$sql .= ") ";
}
else {
$sql .= "and v.voicemail_id = '$this->voicemail_id' ";
}
if (strlen($this->order_by) == 0) {
$sql .= "order by v.voicemail_id, m.created_epoch desc ";
}
else {
$sql .= "order by v.voicemail_id, m.$this->order_by $this->order ";
}
//$sql .= "limit $this->rows_per_page offset $this->offset ";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($prep_statement, $sql);
//update the array with additional information
if (is_array($result)) {
foreach($result as &$row) {
//set the greeting directory
$path = $_SESSION['switch']['voicemail']['dir'].'/default/'.$_SESSION['domain_name'].'/'.$row['voicemail_id'];
if (file_exists($path.'/msg_'.$row['voicemail_message_uuid'].'.wav')) {
$row['file_path'] = $path.'/msg_'.$row['voicemail_message_uuid'].'.wav';
}
if (file_exists($path.'/msg_'.$row['voicemail_message_uuid'].'.mp3')) {
$row['file_path'] = $path.'/msg_'.$row['voicemail_message_uuid'].'.mp3';
}
$row['file_size'] = filesize($row['file_path']);
$row['file_size_label'] = byte_convert($row['file_size']);
$row['file_ext'] = substr($row['file_path'], -3);
$message_length = $row['message_length'];
if ($message_length < 60 ) {
$message_length = $message_length. " sec";
}
else {
$message_length = round(($message_length/60), 2). " min";
}
$row['message_length_label'] = $message_length;
$row['created_date'] = date("j M Y g:i a",$row['created_epoch']);
}
}
return $result;
}
public function voicemail_delete() {
//get the voicemail id
$this->get_voicemail_id();
//check if for valid input
if (is_uuid($this->voicemail_uuid)
&& is_uuid($this->domain_uuid)) {
//input is valid
}
else {
return false;
}
//delete voicemail messages
$this->message_delete();
//delete voicemail recordings folder (includes greetings)
$file_path = $_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$this->voicemail_id;
foreach (glob($file_path."/*.*") as $file_name) {
unlink($file_name);
if (is_numeric($this->voicemail_id)) {
$file_path = $_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$this->voicemail_id;
foreach (glob($file_path."/*.*") as $file_name) {
unlink($file_name);
}
@rmdir($file_path);
}
@rmdir($file_path);
//delete voicemail destinations
$sql = "delete from v_voicemail_destinations ";
@@ -241,12 +288,14 @@
unset($sql, $prep_statement);
//delete voicemail greetings
$sql = "delete from v_voicemail_greetings ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql, $prep_statement);
if (is_numeric($this->voicemail_id)) {
$sql = "delete from v_voicemail_greetings ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql, $prep_statement);
}
//delete voicemail options
$sql = "delete from v_voicemail_options ";
@@ -267,21 +316,32 @@
public function message_count() {
$sql = "select count(*) as num_rows from v_voicemail_messages ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
$prep_statement = $this->db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$num_rows = $row['num_rows'];
//check if for valid input
if (is_uuid($this->voicemail_uuid) && is_uuid($this->domain_uuid)) {
//input is valid
}
else {
$num_rows = '0';
return false;
}
}
return $num_rows;
//get the message count
$sql = "select count(*) as num_rows from v_voicemail_messages ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
$prep_statement = $this->db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$num_rows = $row['num_rows'];
}
else {
$num_rows = '0';
}
}
//return the message count
return $num_rows;
}
public function message_waiting() {
@@ -294,6 +354,20 @@
}
public function message_delete() {
//get the voicemail id
$this->get_voicemail_id();
//check if for valid input
if (is_numeric($this->voicemail_id)
&& is_uuid($this->voicemail_uuid)
&& is_uuid($this->domain_uuid)
&& is_uuid($this->voicemail_message_uuid)) {
//input is valid
}
else {
return false;
}
//delete the recording
$file_path = $_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$this->voicemail_id;
@@ -328,6 +402,16 @@
public function message_toggle() {
//check if for valid input
if (is_uuid($this->voicemail_uuid)
&& is_uuid($this->domain_uuid)
&& is_uuid($this->voicemail_message_uuid)) {
//input is valid
}
else {
return false;
}
//get message status
$sql = "select message_status from v_voicemail_messages ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
@@ -356,6 +440,16 @@
public function message_saved() {
//check if for valid input
if (is_uuid($this->voicemail_uuid)
&& is_uuid($this->domain_uuid)
&& is_uuid($this->voicemail_message_uuid)) {
//input is valid
}
else {
return false;
}
//set the voicemail status to saved
$sql = "update v_voicemail_messages set ";
$sql .= "message_status = 'saved' ";
@@ -372,6 +466,17 @@
public function message_download() {
//check if for valid input
if (is_numeric($this->voicemail_id)
&& is_uuid($this->voicemail_uuid)
&& is_uuid($this->domain_uuid)
&& is_uuid($this->voicemail_message_uuid)) {
//input is valid
}
else {
return false;
}
//change the message status
$this->message_saved();
@@ -395,8 +500,8 @@
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0) {
if (is_array($result)) foreach($result as &$row) {
if (is_array($result)) {
foreach($result as &$row) {
if ($row['message_base64'] != '') {
$message_decoded = base64_decode($row['message_base64']);
file_put_contents($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $message_decoded);
+23 -11
View File
@@ -23,18 +23,22 @@
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
require_once "root.php";
require_once "resources/require.php";
if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"]) == "email")) {
require_once "resources/check_auth.php";
if (permission_exists('voicemail_message_view')) {
//access granted
//check permissions
if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"]) == "email")) {
require_once "resources/check_auth.php";
if (permission_exists('voicemail_message_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
}
else {
echo "access denied";
exit;
}
}
//add multi-lingual support
$language = new text;
@@ -137,6 +141,9 @@ if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"]
if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') {
echo "<th style='text-align: right;'>".$text['label-message_size']."</th>\n";
}
if ($_SESSION['voicemail']['transcribe_enabled']['boolean'] == 'true') {
echo "<th>".$text['label-transcription']."</th>\n";
}
if (permission_exists('voicemail_message_delete')) {
echo "<td class='list_control_icons' style='width: 25px;'>";
echo "<a href='javascript:void(0);' onclick=\"if (confirm('".$text['confirm-delete']."')) { $('#frm').attr('action', 'voicemail_message_delete.php').submit(); }\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
@@ -177,10 +184,14 @@ if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"]
echo "<a id='recording_button_".$row['voicemail_message_uuid']."' onclick=\"recording_play('".$row['voicemail_message_uuid']."');\" title='".$text['label-play']." / ".$text['label-pause']."'>".$v_link_label_play."</a>";
echo "<a href=\"voicemail_messages.php?action=download&t=bin&id=".$row['voicemail_id']."&voicemail_uuid=".$row['voicemail_uuid']."&uuid=".$row['voicemail_message_uuid']."\" title='".$text['label-download']."'>".$v_link_label_download."</a>";
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=\"".$style." text-align: right;\">".$row['message_length_label']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=\"".$style." text-align: right;\" nowrap='nowrap'>".$row['message_length_label']."&nbsp;</td>\n";
if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') {
echo " <td valign='top' class='".$row_style[$c]."' style=\"".$style." text-align: right;\" nowrap='nowrap'>".$row['file_size_label']."</td>\n";
}
if ($_SESSION['voicemail']['transcribe_enabled']['boolean'] == 'true') {
echo " <td valign='top' class='".$row_style[$c]."' style=\"".$style."\">".$row['message_transcription']."</td>\n";
}
if (permission_exists('voicemail_message_delete')) {
echo " <td class='list_control_icon' style='width: 25px;'>";
echo "<a href='voicemail_message_delete.php?voicemail_messages[".$row['voicemail_uuid']."][]=".$row['voicemail_message_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>";
@@ -246,4 +257,5 @@ if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"]
//include the footer
require_once "resources/footer.php";
?>
?>
+35 -25
View File
@@ -23,24 +23,34 @@
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('voicemail_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('voicemail_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//retrieve order by
//set the variables
$order_by = check_str($_GET["order_by"]);
$order = check_str($_GET["order"]);
$search = check_str($_GET["search"]);
//sterilize the user data
$order_by = preg_replace('/\s+/', '', $order_by);
if (!(strtolower($order) == "asc" or strtolower($order) == "desc")) { $order = ''; }
if (strlen($search) > 15) { $search = substr($search, 0, 15); }
//set the voicemail id and voicemail uuid arrays
if (isset($_SESSION['user']['extension'])) foreach ($_SESSION['user']['extension'] as $index => $row) {
@@ -62,15 +72,15 @@ else {
require_once "resources/paging.php";
//prepare to page the results
$sql = "select count(*) as num_rows from v_voicemails ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql = "SELECT count(*) AS num_rows FROM v_voicemails ";
$sql .= "WHERE domain_uuid = '$domain_uuid' ";
if (strlen($search) > 0) {
$sql .= "and (";
$sql .= " voicemail_id like '%".$search."%' ";
$sql .= " or voicemail_mail_to like '%".$search."%' ";
$sql .= " or voicemail_local_after_email like '%".$search."%' ";
$sql .= " or voicemail_enabled like '%".$search."%' ";
$sql .= " or voicemail_description like '%".$search."%' ";
$sql .= " CAST(voicemail_id AS TEXT) LIKE '%".$search."%' ";
$sql .= " OR voicemail_mail_to LIKE '%".$search."%' ";
$sql .= " OR voicemail_local_after_email LIKE '%".$search."%' ";
$sql .= " OR voicemail_enabled LIKE '%".$search."%' ";
$sql .= " OR voicemail_description LIKE '%".$search."%' ";
$sql .= ") ";
}
if (!permission_exists('voicemail_delete')) {
@@ -82,14 +92,14 @@ else {
$sql .= "voicemail_uuid = '".$row['voicemail_uuid']."' ";
}
else {
$sql .= " or voicemail_uuid = '".$row['voicemail_uuid']."'";
$sql .= " OR voicemail_uuid = '".$row['voicemail_uuid']."'";
}
$x++;
}
$sql .= ")";
}
else {
$sql .= "and voicemail_uuid is null ";
$sql .= "AND voicemail_uuid IS NULL ";
}
}
$prep_statement = $db->prepare($sql);
@@ -114,14 +124,14 @@ else {
$offset = $rows_per_page * $page;
//get the list
$sql = str_replace('count(*) as num_rows', '*', $sql);
$sql = str_replace('count(*) AS num_rows', '*', $sql);
if (strlen($order_by) > 0) {
$sql .= ($order_by == 'voicemail_id') ? "order by voicemail_id ".$order." " : "order by ".$order_by." ".$order." ";
$sql .= ($order_by == 'voicemail_id') ? "ORDER BY voicemail_id ".$order." " : "ORDER BY ".$order_by." ".$order." ";
}
else {
$sql .= "order by voicemail_id asc ";
$sql .= "ORDER BY voicemail_id ASC ";
}
$sql .= "limit ".$rows_per_page." offset ".$offset." ";
$sql .= "LIMIT ".$rows_per_page." OFFSET ".$offset." ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$voicemails = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@@ -266,4 +276,4 @@ else {
//include the footer
require_once "resources/footer.php";
?>
?>
+9 -2
View File
@@ -330,10 +330,17 @@ if (!class_exists('xml_cdr')) {
$domain_name = check_str(urldecode($xml->variables->domain_name));
$domain_uuid = check_str(urldecode($xml->variables->domain_uuid));
//get the domain name from sip_req_host
//get the domain name
if (strlen($domain_name) == 0) {
$domain_name = check_str(urldecode($xml->variables->sip_req_host));
}
if (strlen($domain_name) == 0) {
$presence_id = check_str(urldecode($xml->variables->presence_id));
if (strlen($presence_id) > 0) {
$presence_array = explode($presence_id);
$domain_name = $presence_array[1];
}
}
//send the domain name to the cdr log
//$this->log("\ndomain_name is `$domain_name`; domain_uuid is '$domain_uuid'\n");
@@ -669,7 +676,7 @@ if (!class_exists('xml_cdr')) {
$sql .= " or \n";
$sql .= " (e.number_alias is not null and (caller_id_number = e.number_alias or destination_number = e.number_alias))\n";
$sql .= ")\n";
$sql .= "and (answer_stamp is not null and bridge_uuid is null) \n";
$sql .= "and (answer_stamp is null and bridge_uuid is null) \n";
$sql .= "and direction = 'inbound' \n";
if (!$this->include_internal) {
$sql .= " and (direction = 'inbound' or direction = 'outbound') \n";
+20 -17
View File
@@ -17,23 +17,26 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('xml_cdr_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//ehceck permissions
if (permission_exists('xml_cdr_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
@@ -194,10 +197,10 @@ else {
//echo " <td valign='top' class='".$row_style[$c]."'>".$context."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>";
if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')) {
//echo " <a href=\"../recordings/v_recordings.php?a=download&type=rec&t=bin&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')."\">\n";
//echo " <a href=\"../recordings/recordings.php?a=download&type=rec&t=bin&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')."\">\n";
//echo " </a>";
echo " <a href=\"javascript:void(0);\" onclick=\"window.open('../recordings/v_recording_play.php?a=download&type=moh&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')."', 'play',' width=420,height=40,menubar=no,status=no,toolbar=no')\">\n";
echo " <a href=\"javascript:void(0);\" onclick=\"window.open('../recordings/recording_play.php?a=download&type=moh&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')."', 'play',' width=420,height=40,menubar=no,status=no,toolbar=no')\">\n";
//$tmp_file_array = explode("\.",$file);
echo $caller_id_name.' ';
echo " </a>";
@@ -208,7 +211,7 @@ else {
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>";
if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')) {
echo " <a href=\"../recordings/v_recordings.php?a=download&type=rec&t=bin&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')."\">\n";
echo " <a href=\"../recordings/recordings.php?a=download&type=rec&t=bin&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')."\">\n";
echo $caller_id_number.' ';
echo " </a>";
}
@@ -291,12 +294,12 @@ else {
$tmp_name = $value."_1.mp3";
}
if (strlen($tmp_name) > 0 && file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)) {
echo " <a href=\"javascript:void(0);\" onclick=\"window.open('../recordings/v_recording_play.php?a=download&type=moh&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)."', 'play',' width=420,height=150,menubar=no,status=no,toolbar=no')\">\n";
echo " <a href=\"javascript:void(0);\" onclick=\"window.open('../recordings/recording_play.php?a=download&type=moh&filename=".base64_encode('archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)."', 'play',' width=420,height=150,menubar=no,status=no,toolbar=no')\">\n";
echo " play";
echo " </a>&nbsp;";
}
if (strlen($tmp_name) > 0 && file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)) {
echo " <a href=\"../recordings/v_recordings.php?a=download&type=rec&t=bin&filename=".base64_encode("archive/".$tmp_year."/".$tmp_month."/".$tmp_day."/".$tmp_name)."\">\n";
echo " <a href=\"../recordings/recordings.php?a=download&type=rec&t=bin&filename=".base64_encode("archive/".$tmp_year."/".$tmp_month."/".$tmp_day."/".$tmp_name)."\">\n";
echo " download";
echo " </a>";
}
@@ -515,4 +518,4 @@ else {
//get the footer
require_once "resources/footer.php";
?>
?>
+1 -1
View File
@@ -283,7 +283,7 @@
if ($rows_per_page > 0) {
if ($_SESSION['cdr']['count']['boolean'] == "true") {
//get the number of rows in the v_xml_cdr
$sql = "select count(*) as num_rows from v_xml_cdr ";
$sql = "select count(uuid) as num_rows from v_xml_cdr ";
$sql .= "where domain_uuid = '".$domain_uuid."' ".$sql_where;
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
@@ -53,6 +53,11 @@ class authentication {
$this->get_domain();
}
//set the database as the default plugin
if (!isset($_SESSION['authentication']['methods'])) {
$_SESSION['authentication']['methods'][] = 'database';
}
//use the authentication plugins
foreach ($_SESSION['authentication']['methods'] as $name) {
$class_name = "plugin_".$name;
@@ -108,20 +113,37 @@ class authentication {
if ($_SESSION["user"]["unique"]["text"] != "global") {
$username_array = explode("@", check_str($_REQUEST["username"]));
if (count($username_array) > 1) {
$this->domain_name = $username_array[count($username_array) -1];
$_REQUEST["username"] = substr(check_str($_REQUEST["username"]), 0, -(strlen($this->domain_name)+1));
//get the domain name
$domain_name = $username_array[count($username_array) -1];
//check if the domain from the username exists then set the domain_uuid
$domain_exists = false;
foreach ($_SESSION['domains'] as $row) {
if (lower_case($row['domain_name']) == lower_case($domain_name)) {
$this->domain_uuid = $row['domain_uuid'];
$domain_exists = true;
break;
}
}
//if the domain exists then set domain_name and update the username
if ($domain_exists) {
$this->domain_name = $domain_name;
$this->username = substr(check_str($_REQUEST["username"]), 0, -(strlen($domain_name)+1));
$_SESSION['domain_uuid'] = $this->domain_uuid;
}
//unset the domain name variable
unset($domain_name);
}
}
//get the domain name from the http value
if (strlen(check_str($_REQUEST["domain_name"])) > 0) {
$this->domain_name = check_str($_REQUEST["domain_name"]);
}
//set
//set the domain name
$_SESSION['domain_name'] = $this->domain_name;
}
//get the domain uuid and domain settings
if (isset($this->domain_name)) {
if (isset($this->domain_name) && !isset($this->domain_uuid)) {
foreach ($_SESSION['domains'] as $row) {
if (lower_case($row['domain_name']) == lower_case($this->domain_name)) {
$this->domain_uuid = $row['domain_uuid'];
@@ -1,7 +1,7 @@
<?php
/**
* plugin_database
* plugin_database
*
* @method validate uses authentication plugins to check if a user is authorized to login
* @method get_domain used to get the domain name from the URL or username and then sets both domain_name and domain_uuid
@@ -52,6 +52,8 @@ class plugin_database {
//$sql .= "and domain_uuid='".$this->domain_uuid."' ";
}
$sql .= "and (user_enabled = 'true' or user_enabled is null) ";
//echo $sql."<br />\n";
//echo "domain name: ".$this->domain_name;
$prep_statement = $db->prepare(check_sql($sql));
if ($_SESSION["user"]["unique"]["text"] != "global") {
$prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
@@ -67,7 +69,8 @@ class plugin_database {
$user_authorized = false;
if (is_array($result)) {
foreach ($result as &$row) {
//get the domain uuid
//get the domain uuid when users are unique globally
if ($_SESSION["user"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
//set the domain_uuid
$this->domain_uuid = $row["domain_uuid"];
@@ -3,7 +3,7 @@
/**
* plugin_ldap
*
* @method dap checks a local or remove ldap database to authenticate the user
* @method ldap checks a local or remote ldap database to authenticate the user
*/
class plugin_ldap {
@@ -18,7 +18,7 @@ class plugin_ldap {
public $contact_uuid;
/**
* ldap checks a local or remove ldap database to authenticate the user
* ldap checks a local or remote ldap database to authenticate the user
* @return array [authorized] => true or false
*/
function ldap() {
@@ -51,11 +51,20 @@ class plugin_ldap {
//Note: As of 4/16, the call below will fail randomly. PHP debug reports ldap_bind
//called below with all arguments '*uninitialized*'. However, the debugger
//single-stepping just before the failing call correctly displays all the values.
$bind = ldap_bind($connect, $bind_dn, $bind_pw);
if ($bind) {
$user_authorized = true;
if (strlen($bind_pw) > 0) {
$bind = ldap_bind($connect, $bind_dn, $bind_pw);
if ($bind) {
//connected and authorized
$user_authorized = true;
break;
}
else {
//connection failed
$user_authorized = false;
}
}
else {
//password not provided
$user_authorized = false;
}
+15 -1
View File
@@ -29,6 +29,13 @@ if ($domains_processed == 1) {
//define array of settings
$x = 0;
$array[$x]['default_setting_category'] = 'server';
$array[$x]['default_setting_subcategory'] = 'temp';
$array[$x]['default_setting_name'] = 'dir';
$array[$x]['default_setting_value'] = sys_get_temp_dir();
$array[$x]['default_setting_enabled'] = 'true';
$array[$x]['default_setting_description'] = '';
$x++;
$array[$x]['default_setting_category'] = 'domain';
$array[$x]['default_setting_subcategory'] = 'time_zone';
$array[$x]['default_setting_name'] = 'name';
@@ -54,7 +61,7 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_subcategory'] = 'paging';
$array[$x]['default_setting_name'] = 'numeric';
$array[$x]['default_setting_value'] = '100';
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_enabled'] = 'true';
$array[$x]['default_setting_description'] = 'Set the maximum number of records displayed per page. (Default: 50)';
$x++;
$array[$x]['default_setting_category'] = 'security';
@@ -169,6 +176,13 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_enabled'] = 'true';
$array[$x]['default_setting_description'] = '';
$x++;
$array[$x]['default_setting_category'] = 'email';
$array[$x]['default_setting_subcategory'] = 'smtp_validate_certificate';
$array[$x]['default_setting_name'] = 'boolean';
$array[$x]['default_setting_value'] = 'true';
$array[$x]['default_setting_enabled'] = 'true';
$array[$x]['default_setting_description'] = 'set to false to ignore SSL certificate warnings e.g. for self-signed certificates';
$x++;
$array[$x]['default_setting_category'] = 'login';
$array[$x]['default_setting_subcategory'] = 'password_reset_key';
$array[$x]['default_setting_name'] = 'text';
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2010-2015
Copyright (C) 2010-2016
All Rights Reserved.
Contributor(s):
@@ -52,7 +52,7 @@ include "root.php";
}
function write_progress($message) {
if($this->echo_progress){
if ($this->echo_progress){
echo "$message\n";
}
}
@@ -68,7 +68,8 @@ include "root.php";
$this->write_debug("backing up to $dst_tar");
if (file_exists('/bin/tar')) {
exec('tar -cvf ' .$dst_tar. ' -C '.$dir .' .');
}else{
}
else {
$this->write_debug('WARN: old config could not be compressed');
$dst_dir = join( DIRECTORY_SEPARATOR, array(sys_get_temp_dir(), "$backup_name"));
recursive_copy($dir, $dst_dir);
@@ -100,7 +101,7 @@ include "root.php";
//make sure the conf directory exists
if (!is_dir($this->global_settings->switch_conf_dir())) {
if (!mkdir($this->global_settings->switch_conf_dir(), 02770, true)) {
throw new Exception("Failed to create the switch conf directory '".$this->global_settings->switch_conf_dir()."'. ");
$this->write_progress("Switch conf directory does not exist");
}
}
@@ -135,12 +136,12 @@ include "root.php";
protected function restart_switch() {
$esl = new event_socket;
if(!$esl->connect($this->global_settings->switch_event_host(), $this->global_settings->switch_event_port(), $this->global_settings->switch_event_password())) {
throw new Exception("Failed to connect to switch");
$this->write_progress("Failed to connect to switch");
}
if (!$esl->request('api fsctl shutdown restart elegant')){
throw new Exception("Failed to send switch restart");
$this->write_progress("Failed to send switch restart");
}
$esl->reset_fp();
}
}
?>
?>
+6 -1
View File
@@ -56,7 +56,7 @@
// run source update
if ($do["source"] && permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx")) {
chdir($_SERVER["PROJECT_ROOT"]);
exec("git pull", $response_source_update);
exec("git pull 2>&1", $response_source_update);
$update_failed = true;
if (sizeof($response_source_update) > 0) {
$_SESSION["response_source_update"] = $response_source_update;
@@ -64,6 +64,11 @@
if (substr_count($response_line, "Updating ") > 0 || substr_count($response_line, "Already up-to-date.") > 0) {
$update_failed = false;
}
if (substr_count($response_line, "error") > 0) {
$update_failed = true;
break;
}
}
}
if ($update_failed) {
+13
View File
@@ -102,6 +102,19 @@ $text['message-failed']['uk'] = "";
$text['message-failed']['sv-se'] = "Uppdatering Misslyckades - Kontakta Support";
$text['message-failed']['de-at'] = "Aktualisierung fehlgeschlagen - Kontaktieren Sie den Support";
$text['message-duplicate']['en-us'] = "Duplicate Detected";
$text['message-duplicate']['es-cl'] = "duplicar detectado";
$text['message-duplicate']['pt-pt'] = "Detectado um duplicado";
$text['message-duplicate']['fr-fr'] = "Donblons détectés";
$text['message-duplicate']['pt-br'] = "Detectado uma dubplicidade";
$text['message-duplicate']['pl'] = "Wykryto duplikat";
$text['message-duplicate']['uk'] = "Знайдено дублікат";
$text['message-duplicate']['sv-se'] = "Dubblett Upptäckt";
$text['message-duplicate']['ro'] = "";
$text['message-duplicate']['de-at'] = "bereits vorhanden";
$text['message-duplicate']['ar-eg'] = "";
$text['message-duplicate']['he'] = "זוהותה כפילות";
$text['message-copy']['en-us'] = "Copy Completed";
$text['message-copy']['es-cl'] = "Copia Completado";
$text['message-copy']['pt-pt'] = "Cópia Preenchida";
+22 -7
View File
@@ -49,7 +49,7 @@
}
//if the username is not provided then send to login.php
if (strlen(check_str($_REQUEST["username"])) == 0 && strlen(check_str($_REQUEST["key"])) == 0) {
if (strlen($_REQUEST["username"]) == 0 && strlen($_REQUEST["key"]) == 0) {
$target_path = ($_REQUEST["path"] != '') ? $_REQUEST["path"] : $_SERVER["REQUEST_URI"];
$_SESSION["message_mood"] = "negative";
$_SESSION["message"] = "Invalid Username and/or Password";
@@ -59,19 +59,34 @@
//validate the username and password
$auth = new authentication;
$auth->username = $_REQUEST["username"];
$auth->password = $_REQUEST["password"];
if (strlen($_REQUEST["username"]) > 0) {
$auth->username = $_REQUEST["username"];
$auth->password = $_REQUEST["password"];
}
if (strlen($_REQUEST["key"]) > 0) {
$auth->key = $_REQUEST["key"];
}
$auth->debug = false;
$result = $auth->validate();
if ($result["authorized"] == "true") {
// add the user settings
// set the session variables
$_SESSION["domain_uuid"] = $result["domain_uuid"];
$_SESSION["user_uuid"] = $result["user_uuid"];
// user session array
$_SESSION["user"]["username"] = $result["username"];
$_SESSION["user"]["user_uuid"] = $result["user_uuid"];
$_SESSION["user"]["contact_uuid"] = $result["contact_uuid"];
}
else {
//debug
if ($debug) {
echo "<pre>";
print_r($result);
echo "</pre>";
exit;
}
//log the failed auth attempt to the system, to be available for fail2ban.
openlog('FusionPBX', LOG_NDELAY, LOG_AUTH);
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] authentication failed for ".$result["username"]);
@@ -91,7 +106,7 @@
$sql .= "where domain_uuid=:domain_uuid ";
$sql .= "and user_uuid=:user_uuid ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->bindParam(':domain_uuid', $domain_uuid);
$prep_statement->bindParam(':domain_uuid', $_SESSION["domain_uuid"] );
$prep_statement->bindParam(':user_uuid', $_SESSION["user_uuid"]);
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@@ -105,10 +120,10 @@
foreach($_SESSION["groups"] as $field) {
if (strlen($field['group_name']) > 0) {
if ($x == 0) {
$sql .= "where (domain_uuid = '".$domain_uuid."' and domain_uuid = null) ";
$sql .= "where (domain_uuid = '".$_SESSION["domain_uuid"]."' and domain_uuid = null) ";
}
else {
$sql .= "or (domain_uuid = '".$domain_uuid."' and domain_uuid = null) ";
$sql .= "or (domain_uuid = '".$_SESSION["domain_uuid"]."' and domain_uuid = null) ";
}
$sql .= "or group_name = '".$field['group_name']."' ";
$x++;
+1 -1
View File
@@ -584,4 +584,4 @@ if (!function_exists('php_right')) {
$database->add();
print_r($database->result);
*/
?>
?>
+52 -64
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2015 All Rights Reserved.
Copyright (C) 2016 All Rights Reserved.
*/
@@ -28,78 +28,66 @@
* @method string delete
* @method string exists
*/
if (!class_exists('permissions')) {
class permissions {
if (!class_exists('permissions')) {
class permissions {
/**
* Add a permission
* @var string $permission
*/
public function add($permission, $type = '') {
if (!$this->exists($permission)) {
//set the ordinal number
$i = count($_SESSION["permissions"])+1;
/**
* Add the permission
* @var string $permission
*/
public function add($permission, $type) {
//add the permission if it is not in array
if (!$this->exists($permission)) {
$_SESSION["permissions"][$permission] = $type;
}
}
//set the permission
$_SESSION["permissions"][$i]["permission_name"] = $permission;
$_SESSION["permissions"][$i]["permission_type"] = "temp";
/**
* Remove the permission
* @var string $permission
*/
public function delete($permission, $type) {
if ($this->exists($permission)) {
if ($type === "temp") {
if ($_SESSION["permissions"][$permission] === "temp") {
echo "delete ".__line__." $type\n";
unset($_SESSION["permissions"][$permission]);
}
}
/**
* Remove the permission
* @var string $permission
*/
public function delete($permission, $type = '') {
if ($this->exists($permission)) {
foreach($_SESSION["permissions"] as $key => $row) {
if ($row['permission_name'] == $permission) {
if ($row['permission_name'] == $permission) {
if ($type == 'temp') {
if ($row['permission_type'] == "temp") {
unset($_SESSION["permissions"][$key]);
}
}
else {
unset($_SESSION["permissions"][$key]);
}
}
break;
}
}
else {
if ($_SESSION["permissions"][$permission] !== "temp") {
echo "delete ".__line__." $type\n";
unset($_SESSION["permissions"][$permission]);
}
}
}
}
/**
* Check to see if the permission exists
* @var string $permission
*/
function exists($permission) {
//set default false
$result = false;
//search for the permission
if (count($_SESSION["permissions"]) > 0) {
foreach($_SESSION["permissions"] as $row) {
if ($row['permission_name'] == $permission) {
$result = true;
break;
}
}
}
//return the result
return $result;
/**
* Check to see if the permission exists
* @var string $permission
*/
function exists($permission) {
//set default false
$result = false;
//search for the permission
if (is_array($_SESSION["permissions"]) && isset($_SESSION["permissions"][$permission])) {
$result = true;
}
//return the result
return $result;
}
}
}
//examples
/*
//add the permission
$p = new permissions;
$p->add($permission);
//delete the permission
$p = new permissions;
$p->delete($permission);
*/
//examples
/*
//add the permission
$p = new permissions;
$p->add($permission);
//delete the permission
$p = new permissions;
$p->delete($permission);
*/
?>
?>
+2 -2
View File
@@ -27,7 +27,7 @@
if (!function_exists('software_version')) {
function software_version() {
return '4.2.0';
return '4.2.1';
}
}
@@ -1101,7 +1101,7 @@ function number_pad($number,$n) {
// validate email address syntax
if(!function_exists('valid_email')) {
function valid_email($email) {
$regex = '/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/';
$regex = '/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+(\.[A-z0-9]{2,6})?$/';
if ($email != "" && preg_match($regex, $email) == 1) {
return true; // email address has valid syntax
}
@@ -6,8 +6,14 @@
debug["sql"] = true;
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--set the api
api = freeswitch.API();
@@ -66,14 +72,19 @@
end
--get the agent password
sql = "SELECT * FROM v_call_center_agents ";
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
sql = sql .. "AND agent_id = '" .. agent_id .."' ";
local params = {domain_uuid = domain_uuid, agent_id = agent_id}
local sql = "SELECT * FROM v_call_center_agents ";
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
sql = sql .. "AND agent_id = :agent_id ";
if (agent_authorized ~= 'true') then
sql = sql .. "AND agent_password = '" .. agent_password .."' ";
sql = sql .. "AND agent_password = :agent_password ";
params.agent_password = agent_password;
end
freeswitch.consoleLog("notice", "[user status] sql: " .. sql .. "\n");
dbh:query(sql, function(row)
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[user status] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
--set the variables
agent_name = row.agent_name;
agent_id = row.agent_id;
@@ -91,13 +102,14 @@
--get the user_uuid
if (agent_authorized == 'true') then
sql = "SELECT user_uuid, user_status FROM v_users ";
sql = sql .. "WHERE username = '".. agent_name .."' ";
sql = sql .. "AND domain_uuid = '" .. domain_uuid .."' ";
local sql = "SELECT user_uuid, user_status FROM v_users ";
sql = sql .. "WHERE username = :agent_name ";
sql = sql .. "AND domain_uuid = :domain_uuid ";
local params = {agent_name = agent_name, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[call_center] sql: ".. sql .. "\n");
freeswitch.consoleLog("notice", "[call_center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get the user info
user_uuid = row.user_uuid;
user_status = row.user_status;
@@ -113,13 +125,14 @@
freeswitch.consoleLog("NOTICE", "[call_center] user_status: ".. status .. "\n");
--set the user_status in the users table
sql = "UPDATE v_users SET ";
sql = sql .. "user_status = '"..status.."' ";
sql = sql .. "WHERE user_uuid = '" .. user_uuid .."' ";
local sql = "UPDATE v_users SET ";
sql = sql .. "user_status = :status ";
sql = sql .. "WHERE user_uuid = :user_uuid ";
local params = {status = status, user_uuid = user_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[call_center] sql: ".. sql .. "\n");
freeswitch.consoleLog("notice", "[call_center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
--send a login or logout to mod_callcenter
cmd = "callcenter_config agent set status "..agent_name.."@"..domain_name.." '"..status.."'";
@@ -166,6 +179,16 @@
status = "Invalid ID or Password";
end
--set the status and presence
if (session:ready()) then
if (action == "login") then
session:execute("playback", sounds_dir.."/ivr/ivr-you_are_now_logged_in.wav");
end
if (action == "logout") then
session:execute("playback", sounds_dir.."/ivr/ivr-you_are_now_logged_out.wav");
end
end
--send the status to the display
if (status ~= nil) then
reply = api:executeString("uuid_display "..uuid.." '"..status.."'");
@@ -175,15 +198,3 @@
if (session:ready()) then
session:execute("sleep", "2000");
end
--set the status and presence
if (session:ready()) then
if (action == "login") then
session:execute("playback", sounds_dir.."/ivr/ivr-you_are_now_logged_in.wav");
--session:execute("playback", "tone_stream://%(500,0,300,200,100,50,25)");
end
if (action == "logout") then
session:execute("playback", sounds_dir.."/ivr/ivr-you_are_now_logged_out.wav");
--session:execute("playback", "tone_stream://%(200,0,500,600,700)");
end
end
@@ -46,12 +46,17 @@ This method causes the script to get its manadatory arguments directly from the
-- Command line parameters
local params = {
cid_num = string.match(tostring(session:getVariable("caller_id_number")), "%d+"),
cid_name = session:getVariable("caller_id_name"),
domain_name = session:getVariable("domain_name"),
userid = "", -- session:getVariable("id")
loglevel = "W" -- Warning, Debug, Info
}
cid_num = string.match(tostring(session:getVariable("caller_id_number")), "%d+"),
cid_name = session:getVariable("caller_id_name"),
domain_name = session:getVariable("domain_name"),
userid = "", -- session:getVariable("id")
loglevel = "W" -- Warning, Debug, Info
}
--check if cid_num is numeric
if (tonumber(params["cid_num"]) == nil) then
return
end
-- local storage
local sql = nil
@@ -88,8 +93,8 @@ This method causes the script to get its manadatory arguments directly from the
--if not cached then get the information from the database
if (cache == "-ERR NOT FOUND") then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
Database = require "resources.functions.database";
dbh = Database.new('system');
--log if not connect
if dbh:connected() == false then
@@ -99,14 +104,14 @@ This method causes the script to get its manadatory arguments directly from the
--check if the the call block is blocked
sql = "SELECT * FROM v_call_block as c "
sql = sql .. "JOIN v_domains as d ON c.domain_uuid=d.domain_uuid "
sql = sql .. "WHERE c.call_block_number = '" .. params["cid_num"] .. "' AND d.domain_name = '" .. params["domain_name"] .."'"
status = dbh:query(sql, function(rows)
sql = sql .. "WHERE c.call_block_number = :cid_num AND d.domain_name = :domain_name "
dbh:query(sql, params, function(rows)
found_cid_num = rows["call_block_number"];
found_uuid = rows["call_block_uuid"];
found_enabled = rows["call_block_enabled"];
found_action = rows["call_block_action"];
found_count = rows["call_block_count"];
end)
end)
-- dbh:affected_rows() doesn't do anything if using core:db so this is the workaround:
--set the cache
@@ -171,7 +176,9 @@ This method causes the script to get its manadatory arguments directly from the
k = k + 1
end
if (source == "database") then
dbh:query("UPDATE v_call_block SET call_block_count = " .. found_count + 1 .. " WHERE call_block_uuid = '" .. found_uuid .. "'")
dbh:query("UPDATE v_call_block SET call_block_count = :call_block_count WHERE call_block_uuid = :call_block_uuid",{
call_block_count = found_count + 1, call_block_uuid = found_uuid
})
end
session:execute("set", "call_blocked=true");
logger("W", "NOTICE", "number " .. params["cid_num"] .. " blocked with " .. found_count .. " previous hits, domain_name: " .. params["domain_name"])
@@ -37,8 +37,14 @@
debug["sql"] = false;
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--prepare the api object
api = freeswitch.API();
@@ -80,11 +86,11 @@
end
--get the moderator_pin
sql = [[SELECT moderator_pin FROM v_meetings
WHERE meeting_uuid = ']] .. meeting_uuid ..[[']];
freeswitch.consoleLog("notice", "[voicemail] sql: " .. sql .. "\n");
status = dbh:query(sql, function(row)
moderator_pin = string.lower(row["moderator_pin"]);
local sql = "SELECT moderator_pin FROM v_meetings WHERE meeting_uuid = :meeting_uuid";
local params = {meeting_uuid = meeting_uuid}
freeswitch.consoleLog("notice", "[voicemail] sql: " .. sql .. "; params:" .. json.encode(params) .. "\n");
dbh:query(sql, params, function(row)
moderator_pin = string.lower(row["moderator_pin"]);
end);
--get the link_address
@@ -159,19 +165,19 @@
end_epoch = os.time();
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
dbh = Database.new('system');
--get the conference sessions
if (conference_session_uuid) then
sql = [[SELECT count(*) as num_rows
local sql = [[SELECT count(*) as num_rows
FROM v_conference_sessions
WHERE conference_session_uuid = ']] .. conference_session_uuid ..[[']];
status = dbh:query(sql, function(row)
num_rows = string.lower(row["num_rows"]);
WHERE conference_session_uuid = :conference_session_uuid]];
local params = {conference_session_uuid = conference_session_uuid};
dbh:query(sql, params, function(row)
num_rows = string.lower(row["num_rows"]);
end);
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. " Rows: "..num_rows.."\n");
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "; Rows: "..num_rows.."\n");
end
if (tonumber(num_rows) == 0) then
local sql = {}
@@ -191,22 +197,35 @@
table.insert(sql, ") ");
table.insert(sql, "VALUES ");
table.insert(sql, "( ");
table.insert(sql, "'".. conference_session_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. meeting_uuid .."', ");
table.insert(sql, ":conference_session_uuid, ");
table.insert(sql, ":domain_uuid, ");
table.insert(sql, ":meeting_uuid, ");
--if (conference_recording) then
-- table.insert(sql, "'".. conference_recording .."', ");
-- table.insert(sql, ":conference_recording, ");
--end
--if (wait_mod) then
-- table.insert(sql, "'".. wait_mod .."', ");
-- table.insert(sql, ":wait_mod, ");
--end
--table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. profile .."' ");
--table.insert(sql, ":start_epoch, ");
table.insert(sql, ":profile ");
table.insert(sql, ") ");
SQL_STRING = table.concat(sql, "\n");
dbh:query(SQL_STRING);
sql = table.concat(sql, "\n");
local params = {
conference_session_uuid = conference_session_uuid;
domain_uuid = domain_uuid;
meeting_uuid = meeting_uuid;
-- conference_recording = conference_recording;
-- wait_mod = wait_mod;
-- start_epoch = start_epoch;
profile = profile;
};
dbh:query(sql, params);
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. SQL_STRING .. "\n");
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
end
end
@@ -233,23 +252,37 @@
table.insert(sql, ") ");
table.insert(sql, "VALUES ");
table.insert(sql, "( ");
table.insert(sql, "'".. conference_session_detail_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. conference_session_uuid .."', ");
table.insert(sql, "'".. meeting_uuid .."', ");
table.insert(sql, "'".. username .."', ");
table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. caller_id_number .."', ");
table.insert(sql, "'".. network_addr .."', ");
table.insert(sql, "'".. uuid .."', ");
table.insert(sql, ":conference_session_detail_uuid, ");
table.insert(sql, ":domain_uuid, ");
table.insert(sql, ":conference_session_uuid, ");
table.insert(sql, ":meeting_uuid, ");
table.insert(sql, ":username, ");
table.insert(sql, ":caller_id_name, ");
table.insert(sql, ":caller_id_number, ");
table.insert(sql, ":network_addr, ");
table.insert(sql, ":uuid, ");
if (conference_moderator) then
table.insert(sql, "'".. conference_moderator .."', ");
table.insert(sql, ":conference_moderator, ");
end
table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. end_epoch .."' ");
table.insert(sql, ":start_epoch, ");
table.insert(sql, ":end_epoch ");
table.insert(sql, ") ");
SQL_STRING = table.concat(sql, "\n");
dbh:query(SQL_STRING);
sql = table.concat(sql, "\n");
local params = {
conference_session_detail_uuid = conference_session_detail_uuid;
domain_uuid = domain_uuid;
conference_session_uuid = conference_session_uuid;
meeting_uuid = meeting_uuid;
username = username;
caller_id_name = caller_id_name;
caller_id_number = caller_id_number;
network_addr = network_addr;
uuid = uuid;
conference_moderator = conference_moderator;
start_epoch = start_epoch;
end_epoch = end_epoch;
};
dbh:query(sql, params);
end
--if the conference is empty
@@ -258,15 +291,16 @@
result = trim(api:executeString(cmd));
if (string.sub(result, -9) == "not found") then
--get the conference start_epoch
sql = [[SELECT start_epoch
local sql = [[SELECT start_epoch
FROM v_conference_session_details
WHERE conference_session_uuid = ']] .. conference_session_uuid ..[['
WHERE conference_session_uuid = :conference_session_uuid
ORDER BY start_epoch ASC
LIMIT 1]];
status = dbh:query(sql, function(row)
start_epoch = string.lower(row["start_epoch"]);
local params = {conference_session_uuid = conference_session_uuid};
dbh:query(sql, params, function(row)
start_epoch = string.lower(row["start_epoch"]);
end);
--freeswitch.consoleLog("notice", "[conference center] <conference_start_epoch> sql: " .. sql .. "\n");
--freeswitch.consoleLog("notice", "[conference center] <conference_start_epoch> sql: " .. sql .. "; params:" .. json.encode(params) .. "\n");
--set the conference_recording
conference_recording = recordings_dir.."/archive/"..os.date("%Y", start_epoch).."/"..os.date("%b", start_epoch).."/"..os.date("%d", start_epoch) .."/"..conference_session_uuid;
@@ -274,15 +308,21 @@
--conference has ended set the end_epoch
local sql = {}
table.insert(sql, "update v_conference_sessions set ");
table.insert(sql, "recording = '".. conference_recording .."', ");
table.insert(sql, "start_epoch = '".. start_epoch .."', ");
table.insert(sql, "end_epoch = '".. end_epoch .."' ");
table.insert(sql, "where conference_session_uuid = '"..conference_session_uuid.."' ");
SQL_STRING = table.concat(sql, "\n");
table.insert(sql, "recording = :conference_recording, ");
table.insert(sql, "start_epoch = :start_epoch, ");
table.insert(sql, "end_epoch = :end_epoch ");
table.insert(sql, "where conference_session_uuid = :conference_session_uuid ");
sql = table.concat(sql, "\n");
local params = {
conference_recording = conference_recording;
start_epoch = start_epoch;
end_epoch = end_epoch;
conference_session_uuid = conference_session_uuid;
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. SQL_STRING .. "\n");
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(SQL_STRING);
dbh:query(sql, params);
--convert the wav to an mp3
if (record == "true") then
--cmd = "sox "..conference_recording..".wav -r 16000 -c 1 "..conference_recording..".mp3";
@@ -358,21 +398,23 @@
--get the domain_uuid
if (domain_name ~= nil and domain_uuid == nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
local sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = :domain_name ";
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(rows)
dbh:query(sql, params, function(rows)
domain_uuid = string.lower(rows["domain_uuid"]);
end);
end
--conference center details
sql = [[SELECT * FROM v_conference_centers
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND conference_center_extension = ']] .. destination_number .. [[']];
status = dbh:query(sql, function(row)
local sql = [[SELECT * FROM v_conference_centers
WHERE domain_uuid = :domain_uuid
AND conference_center_extension = :destination_number]];
local params = {domain_uuid = domain_uuid, destination_number = destination_number};
dbh:query(sql, params, function(row)
conference_center_uuid = string.lower(row["conference_center_uuid"]);
conference_center_greeting = row["conference_center_greeting"];
end);
@@ -381,29 +423,24 @@
end
--connect to the switch database
if (file_exists(database_dir.."/core.db")) then
dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] dbh_switch sqlite\n");
end
else
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] dbh_switch pgsql/mysql\n");
end
dbh_switch = database_handle('switch');
end
local dbh_switch = Database.new('switch')
--check if someone has already joined the conference
local_hostname = trim(api:execute("switchname", ""));
freeswitch.consoleLog("notice", "[conference center] local_hostname is " .. local_hostname .. "\n");
sql = "SELECT hostname FROM channels WHERE application = 'conference' AND dest = '" .. destination_number .. "' AND cid_num <> '".. caller_id_number .."' LIMIT 1";
sql = "SELECT hostname FROM channels WHERE application = 'conference' "
.. "AND dest = :destination_number AND cid_num <> :caller_id_number LIMIT 1";
params = {destination_number = destination_number, caller_id_number = caller_id_number};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh_switch:query(sql, function(rows)
dbh_switch:query(sql, params, function(rows)
conference_hostname = rows["hostname"];
end);
--close the database connection
dbh_switch:release();
--if conference hosntame exist, then we bridge there
if (conference_hostname ~= nil) then
freeswitch.consoleLog("notice", "[conference center] conference_hostname is " .. conference_hostname .. "\n");
@@ -447,42 +484,46 @@
digit_timeout = 5000;
pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", prompt_audio_file, "", "\\d+");
end
if (pin_number ~= "") then
sql = [[SELECT * FROM v_conference_rooms as r, v_meetings as m
WHERE r.domain_uuid = ']] .. domain_uuid ..[['
AND r.meeting_uuid = m.meeting_uuid
AND m.domain_uuid = ']] .. domain_uuid ..[['
AND (m.moderator_pin = ']] .. pin_number ..[[' or m.participant_pin = ']] .. pin_number ..[[')
AND r.enabled = 'true'
AND m.enabled = 'true'
AND (
( r.start_datetime <> '' AND r.start_datetime is not null AND r.start_datetime <= ']] .. os.date("%Y-%m-%d %X") .. [[' ) OR
( r.start_datetime = '' OR r.start_datetime is null )
)
AND (
( r.stop_datetime <> '' AND r.stop_datetime is not null AND r.stop_datetime > ']] .. os.date("%Y-%m-%d %X") .. [[' ) OR
( r.stop_datetime = '' OR r.stop_datetime is null )
) ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "\n");
--use the pin_number to find the conference room
if (pin_number ~= "") then
local sql = [[SELECT * FROM v_conference_rooms as r, v_meetings as m
WHERE r.domain_uuid = :domain_uuid
AND r.meeting_uuid = m.meeting_uuid
AND m.domain_uuid = :domain_uuid
AND (m.moderator_pin = :pin_number or m.participant_pin = :pin_number)
AND r.enabled = 'true'
AND m.enabled = 'true'
AND (
( r.start_datetime <> '' AND r.start_datetime is not null AND r.start_datetime <= :timestam ) OR
( r.start_datetime = '' OR r.start_datetime is null )
)
AND (
( r.stop_datetime <> '' AND r.stop_datetime is not null AND r.stop_datetime > :timestam ) OR
( r.stop_datetime = '' OR r.stop_datetime is null )
) ]];
local params = {
domain_uuid = domain_uuid;
pin_number = pin_number;
timestam = os.date("%Y-%m-%d %X");
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
conference_room_uuid = string.lower(row["conference_room_uuid"]);
end);
end
--if the conference room was not found then return nil
if (conference_room_uuid == nil) then
return nil;
else
return pin_number;
end
status = dbh:query(sql, function(row)
conference_room_uuid = string.lower(row["conference_room_uuid"]);
end);
end
if (conference_room_uuid == nil) then
return nil;
else
return pin_number;
end
end
--get the pin
pin_number = session:getVariable("pin_number");
if (not pin_number) then
pin_number = nil;
pin_number = get_pin_number(domain_uuid, conference_center_greeting);
end
pin_number = get_pin_number(domain_uuid, conference_center_greeting);
if (pin_number == nil) then
pin_number = get_pin_number(domain_uuid, conference_center_greeting);
end
@@ -495,19 +536,24 @@
pin_number = get_pin_number(domain_uuid, conference_center_greeting);
end
if (pin_number ~= nil) then
sql = [[SELECT * FROM v_conference_rooms as r, v_meetings as m
WHERE r.domain_uuid = ']] .. domain_uuid ..[['
local sql = [[SELECT * FROM v_conference_rooms as r, v_meetings as m
WHERE r.domain_uuid = :domain_uuid
AND r.meeting_uuid = m.meeting_uuid
AND r.conference_center_uuid = ']] .. conference_center_uuid ..[['
AND m.domain_uuid = ']] .. domain_uuid ..[['
AND (m.moderator_pin = ']] .. pin_number ..[[' or m.participant_pin = ']] .. pin_number ..[[')
AND r.conference_center_uuid = :conference_center_uuid
AND m.domain_uuid = :domain_uuid
AND (m.moderator_pin = :pin_number or m.participant_pin = :pin_number)
AND r.enabled = 'true'
AND m.enabled = 'true'
]];
]];
local params = {
domain_uuid = domain_uuid;
conference_center_uuid = conference_center_uuid;
pin_number = pin_number;
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[conference center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
conference_room_uuid = string.lower(row["conference_room_uuid"]);
meeting_uuid = string.lower(row["meeting_uuid"]);
record = string.lower(row["record"]);
@@ -32,8 +32,14 @@
require "resources.functions.config";
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--define the explode function
require "resources.functions.explode";
@@ -58,8 +64,8 @@
--get the domain_uuid using the domain name required for multi-tenant
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' ";
status = dbh:query(sql, function(rows)
sql = sql .. "WHERE domain_name = :domain_name ";
dbh:query(sql, {domain_name = domain_name}, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
@@ -154,13 +160,14 @@
end
--get the fax settings from the database
sql = [[SELECT * FROM v_fax
WHERE fax_uuid = ']] .. fax_uuid ..[['
AND domain_uuid = ']] .. domain_uuid ..[[']];
local sql = [[SELECT * FROM v_fax
WHERE fax_uuid = :fax_uuid
AND domain_uuid = :domain_uuid]];
local params = {fax_uuid = fax_uuid, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
dialplan_uuid = row["dialplan_uuid"];
fax_extension = row["fax_extension"];
fax_accountcode = row["accountcode"];
@@ -247,57 +254,72 @@
sql = sql .. ") ";
sql = sql .. "values ";
sql = sql .. "(";
sql = sql .. "'"..uuid.."', ";
sql = sql .. "'"..domain_uuid.."', ";
sql = sql .. ":uuid, ";
sql = sql .. ":domain_uuid, ";
if (fax_uuid ~= nil) then
sql = sql .. "'"..fax_uuid.."', ";
sql = sql .. ":fax_uuid, ";
end
sql = sql .. "'"..fax_success.."', ";
sql = sql .. "'"..fax_result_code .."', ";
sql = sql .. "'"..fax_result_text.."', ";
sql = sql .. "'"..fax_file.."', ";
sql = sql .. ":fax_success, ";
sql = sql .. ":fax_result_code, ";
sql = sql .. ":fax_result_text, ";
sql = sql .. ":fax_file, ";
if (fax_ecm_used ~= nil) then
sql = sql .. "'"..fax_ecm_used.."', ";
sql = sql .. ":fax_ecm_used, ";
end
if (fax_local_station_id ~= nil) then
sql = sql .. "'"..fax_local_station_id.."', ";
end
if (fax_document_transferred_pages == nil) then
sql = sql .. "'0', ";
else
sql = sql .. "'"..fax_document_transferred_pages.."', ";
end
if (fax_document_total_pages == nil) then
sql = sql .. "'0', ";
else
sql = sql .. "'"..fax_document_total_pages.."', ";
sql = sql .. ":fax_local_station_id, ";
end
sql = sql .. ":fax_document_transferred_pages, ";
sql = sql .. ":fax_document_total_pages, ";
if (fax_image_resolution ~= nil) then
sql = sql .. "'"..fax_image_resolution.."', ";
sql = sql .. ":fax_image_resolution, ";
end
if (fax_image_size ~= nil) then
sql = sql .. "'"..fax_image_size.."', ";
sql = sql .. ":fax_image_size, ";
end
if (fax_bad_rows ~= nil) then
sql = sql .. "'"..fax_bad_rows.."', ";
sql = sql .. ":fax_bad_rows, ";
end
if (fax_transfer_rate ~= nil) then
sql = sql .. "'"..fax_transfer_rate.."', ";
sql = sql .. ":fax_transfer_rate, ";
end
if (fax_uri ~= nil) then
sql = sql .. "'"..fax_uri.."', ";
sql = sql .. ":fax_uri, ";
end
if (database["type"] == "sqlite") then
sql = sql .. "'"..os.date("%Y-%m-%d %X").."', ";
sql = sql .. ":fax_date, ";
else
sql = sql .. "now(), ";
end
sql = sql .. "'"..os.time().."' ";
sql = sql .. ":fax_time ";
sql = sql .. ")";
local params = {
uuid = uuid;
domain_uuid = domain_uuid;
fax_uuid = fax_uuid;
fax_success = fax_success;
fax_result_code = fax_result_code;
fax_result_text = fax_result_text;
fax_file = fax_file;
fax_ecm_used = fax_ecm_used;
fax_local_station_id = fax_local_station_id;
fax_document_transferred_pages = fax_document_transferred_pages or '0';
fax_document_total_pages = fax_document_total_pages or '0';
fax_image_resolution = fax_image_resolution;
fax_image_size = fax_image_size;
fax_bad_rows = fax_bad_rows;
fax_transfer_rate = fax_transfer_rate;
fax_uri = fax_uri;
fax_date = os.date("%Y-%m-%d %X");
fax_time = os.time();
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] "..sql.."\n");
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
--add the fax files
if (fax_success ~= nil) then
@@ -333,39 +355,49 @@
table.insert(sql, ") ");
table.insert(sql, "values ");
table.insert(sql, "(");
table.insert(sql, "'" .. uuid .. "', ");
table.insert(sql, "'" .. fax_uuid .. "', ");
table.insert(sql, ":uuid, ");
table.insert(sql, ":fax_uuid, ");
table.insert(sql, "'rx', ");
table.insert(sql, "'tif', ");
table.insert(sql, "'" .. fax_file .. "', ");
table.insert(sql, ":fax_file, ");
if (caller_id_name ~= nil) then
table.insert(sql, "'" .. caller_id_name .. "', ");
table.insert(sql, ":caller_id_name, ");
end
if (caller_id_number ~= nil) then
table.insert(sql, "'" .. caller_id_number .. "', ");
table.insert(sql, ":caller_id_number, ");
end
if (database["type"] == "sqlite") then
table.insert(sql, "'"..os.date("%Y-%m-%d %X").."', ");
table.insert(sql, ":fax_date, ");
else
table.insert(sql, "now(), ");
end
table.insert(sql, "'" .. os.time() .. "', ");
table.insert(sql, ":fax_time, ");
if (storage_type == "base64") then
table.insert(sql, "'" .. fax_base64 .. "', ");
table.insert(sql, ":fax_base64, ");
end
table.insert(sql, "'" .. domain_uuid .. "'");
table.insert(sql, ":domain_uuid");
table.insert(sql, ")");
sql = table.concat(sql, "\n");
local params = {
uuid = uuid;
domain_uuid = domain_uuid;
fax_uuid = fax_uuid;
fax_file = fax_file;
caller_id_name = caller_id_name;
caller_id_number = caller_id_number;
fax_base64 = fax_base64;
fax_date = os.date("%Y-%m-%d %X");
fax_time = os.time();
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
if (storage_type == "base64") then
local Database = require "resources.functions.database"
local dbh = Database.new('system', 'base64');
dbh:query(sql);
dbh:query(sql, params);
dbh:release();
else
result = dbh:query(sql);
result = dbh:query(sql, params);
end
end
end
@@ -9,6 +9,12 @@
local Tasks = require "app.fax.resources.scripts.queue.tasks"
local send_mail = require "resources.functions.send_mail"
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
local fax_task_uuid = env:getHeader('fax_task_uuid')
if not fax_task_uuid then
log.warning("No [fax_task_uuid] channel variable")
@@ -204,42 +210,49 @@
"fax_retry_limit";
"fax_retry_sleep";
"fax_uri";
"fax_date";
"fax_epoch";
}
local values = {
"'"..uuid .. "'";
"'"..domain_uuid .. "'";
opt(fax_uuid);
opt(fax_success);
opt(fax_result_code);
opt(fax_result_text);
opt(fax_file);
opt(fax_ecm_used);
opt(fax_local_station_id);
opt(fax_document_transferred_pages, "'0'");
opt(fax_document_total_pages, "'0'");
opt(fax_image_resolution);
opt(fax_image_size);
opt(fax_bad_rows);
opt(fax_transfer_rate);
opt(fax_retry_attempts);
opt(fax_retry_limit);
opt(fax_retry_sleep);
opt(fax_uri);
now_sql();
"'"..os.time().."' ";
local params = {
fax_log_uuid = uuid;
domain_uuid = domain_uuid;
fax_uuid = fax_uuid or dbh.NULL;
fax_success = fax_success or dbh.NULL;
fax_result_code = fax_result_code or dbh.NULL;
fax_result_text = fax_result_text or dbh.NULL;
fax_file = fax_file or dbh.NULL;
fax_ecm_used = fax_ecm_used or dbh.NULL;
fax_local_station_id = fax_local_station_id or dbh.NULL;
fax_document_transferred_pages = fax_document_transferred_pages or "'0'";
fax_document_total_pages = fax_document_total_pages or "'0'";
fax_image_resolution = fax_image_resolution or dbh.NULL;
fax_image_size = fax_image_size or dbh.NULL;
fax_bad_rows = fax_bad_rows or dbh.NULL;
fax_transfer_rate = fax_transfer_rate or dbh.NULL;
fax_retry_attempts = fax_retry_attempts or dbh.NULL;
fax_retry_limit = fax_retry_limit or dbh.NULL;
fax_retry_sleep = fax_retry_sleep or dbh.NULL;
fax_uri = fax_uri or dbh.NULL;
fax_epoch = os.time();
}
local sql = "insert into v_fax_logs(" .. table.concat(fields, ",") .. ")" ..
"values(" .. table.concat(values, ",") .. ")"
local values = ":" .. table.concat(fields, ",:")
fields = table.concat(fields, ",") .. ",fax_date"
if (debug["sql"]) then
log.noticef("SQL: %s", sql);
if database["type"] == "sqlite" then
params.fax_date = os.date("%Y-%m-%d %X");
values = values .. ",:fax_date"
else
values = values .. ",now()"
end
dbh:query(sql);
local sql = "insert into v_fax_logs(" .. fields .. ")values(" .. values .. ")"
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params, dbh.NULL));
end
dbh:query(sql, params);
end
-- add the fax files
@@ -259,49 +272,58 @@
-- build SQL
local sql do
sql = {
"insert into v_fax_files(";
"fax_file_uuid"; ",";
"fax_uuid"; ",";
"fax_mode"; ",";
"fax_destination"; ",";
"fax_file_type"; ",";
"fax_file_path"; ",";
"fax_caller_id_name"; ",";
"fax_caller_id_number"; ",";
"fax_date"; ",";
"fax_epoch"; ",";
"fax_base64"; ",";
"domain_uuid"; " ";
") values (";
opt(uuid); ",";
opt(fax_uuid); ",";
"'tx'"; ",";
opt(sip_to_user); ",";
"'tif'"; ",";
opt(fax_file); ",";
opt(origination_caller_id_name); ",";
opt(origination_caller_id_number); ",";
now_sql(); ",";
"'" .. os.time() .. "'"; ",";
opt(fax_base64); ",";
opt(domain_uuid); " ";
")"
local fields = {
"fax_file_uuid";
"fax_uuid";
"fax_mode";
"fax_destination";
"fax_file_type";
"fax_file_path";
"fax_caller_id_name";
"fax_caller_id_number";
"fax_epoch";
"fax_base64";
"domain_uuid";
}
sql = table.concat(sql, "\n");
if (debug["sql"]) then
log.noticef("SQL: %s", sql);
end
end
local params = {
fax_file_uuid = uuid;
fax_uuid = fax_uuid or dbh.NULL;
fax_mode = "tx";
fax_destination = sip_to_user or dbh.NULL;
fax_file_type = "tif";
fax_file_path = fax_file or dbh.NULL;
fax_caller_id_name = origination_caller_id_name or dbh.NULL;
fax_caller_id_number = origination_caller_id_number or dbh.NULL;
fax_epoch = os.time();
fax_base64 = fax_base64 or dbh.NULL;
domain_uuid = domain_uuid or dbh.NULL;
}
if storage_type == "base64" then
local Database = require "resources.functions.database"
local dbh = Database.new('system', 'base64');
dbh:query(sql);
dbh:release();
else
result = dbh:query(sql)
local values = ":" .. table.concat(fields, ",:")
fields = table.concat(fields, ",") .. ",fax_date"
if database["type"] == "sqlite" then
params.fax_date = os.date("%Y-%m-%d %X");
values = values .. ",:fax_date"
else
values = values .. ",now()"
end
local sql = "insert into v_fax_files(" .. fields .. ")values(" .. values .. ")"
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params, dbh.NULL));
end
if storage_type == "base64" then
local dbh = Database.new('system', 'base64');
dbh:query(sql, params);
dbh:release();
else
dbh:query(sql, params)
end
end
end
@@ -390,7 +412,7 @@
os.remove(fax_file);
end
end
end
end
end
@@ -29,8 +29,13 @@
outbound_caller_id_number = session:getVariable("outbound_caller_id_number");
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--prepare the api object
api = freeswitch.API();
@@ -43,13 +48,18 @@
--get the destination number
if (cache == "-ERR NOT FOUND") then
sql = "SELECT destination_number, destination_context "
local dbh = Database.new('system');
local sql = "SELECT destination_number, destination_context "
sql = sql .. "FROM v_destinations "
sql = sql .. "WHERE destination_number = '"..destination_number.."' "
sql = sql .. "WHERE destination_number = :destination_number "
sql = sql .. "AND destination_type = 'inbound' "
sql = sql .. "AND destination_enabled = 'true' "
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
assert(dbh:query(sql, function(row)
local params = {destination_number = destination_number};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "SQL:" .. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
--set the outbound caller id
if (outbound_caller_id_name ~= nil) then
@@ -77,7 +87,8 @@
--transfer the call
session:transfer(row.destination_number, "XML", row.destination_context);
end));
end);
else
--add the function
require "resources.functions.explode";
@@ -37,8 +37,14 @@
profile = "internal";
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--answer
session:answer();
@@ -92,14 +98,15 @@
--get the device uuid for the phone that will have its configuration overridden
if (user ~= nil and domain ~= nil and domain_uuid ~= nil) then
sql = [[SELECT * FROM v_device_lines ]];
sql = sql .. [[WHERE user_id = ']] .. user .. [[' ]];
sql = sql .. [[AND server_address = ']]..domain..[[' ]];
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[SELECT device_uuid FROM v_device_lines ]];
sql = sql .. [[WHERE user_id = :user ]];
sql = sql .. [[AND server_address = :domain ]];
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {user = user, domain = domain, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] SQL: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get device uuid
device_uuid = row.device_uuid;
freeswitch.consoleLog("NOTICE", "[provision] device_uuid: ".. device_uuid .. "\n");
@@ -109,14 +116,15 @@
--get the alternate device uuid using the device username and password
authorized = 'false';
if (user_id ~= nil and password ~= nil and domain_uuid ~= nil) then
sql = [[SELECT * FROM v_devices ]];
sql = sql .. [[WHERE device_username = ']]..user_id..[[' ]];
sql = sql .. [[AND device_password = ']]..password..[[' ]]
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[SELECT device_uuid FROM v_devices ]];
sql = sql .. [[WHERE device_username = :user_id ]];
sql = sql .. [[AND device_password = :password ]]
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {user_id = user_id, password = password, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] SQL: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get the alternate device_uuid
device_uuid_alternate = row.device_uuid;
freeswitch.consoleLog("NOTICE", "[provision] alternate device_uuid: ".. device_uuid_alternate .. "\n");
@@ -132,13 +140,14 @@
--this device already has an alternate find the correct device_uuid and then override current one
if (authorized == 'true' and action == "login" and device_uuid_alternate ~= nil and device_uuid ~= nil and domain_uuid ~= nil) then
sql = [[SELECT * FROM v_devices ]];
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]];
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[SELECT * FROM v_devices ]];
sql = sql .. [[WHERE device_uuid_alternate = :device_uuid ]];
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {device_uuid = device_uuid, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] SQL: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
if (row.device_uuid_alternate ~= nil) then
device_uuid = row.device_uuid;
end
@@ -147,21 +156,23 @@
--remove the alternate device from another device so that it can be added to this device
if (authorized == 'true' and action == "login" and device_uuid_alternate ~= nil and domain_uuid ~= nil) then
sql = [[SELECT * FROM v_device_lines ]];
sql = sql .. [[WHERE device_uuid = ']]..device_uuid_alternate..[[' ]];
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[SELECT * FROM v_device_lines ]];
sql = sql .. [[WHERE device_uuid = :device_uuid ]];
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {device_uuid = device_uuid_alternate, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] SQL: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--remove the previous alternate device uuid
sql = [[UPDATE v_devices SET device_uuid_alternate = null ]];
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid_alternate..[[' ]];
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[UPDATE v_devices SET device_uuid_alternate = null ]];
sql = sql .. [[WHERE device_uuid_alternate = :device_uuid_alternate ]];
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {device_uuid_alternate = device_uuid_alternate, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] SQL: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
--send a sync command to the previous device
--create the event notify object
local event = freeswitch.Event('NOTIFY');
@@ -183,26 +194,29 @@
--send a hangup
session:hangup();
--add the new alternate
sql = [[UPDATE v_devices SET device_uuid_alternate = ']]..device_uuid_alternate..[[']];
sql = sql .. [[WHERE device_uuid = ']]..device_uuid..[[' ]];
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[UPDATE v_devices SET device_uuid_alternate = :device_uuid_alternate ]];
sql = sql .. [[WHERE device_uuid = :device_uuid ]];
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {device_uuid_alternate = device_uuid_alternate,
device_uuid = device_uuid, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] SQL: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
end
end
--remove the override to the device uuid (logout)
if (authorized == 'true' and action == "logout") then
if (device_uuid_alternate ~= nil and device_uuid ~= nil and domain_uuid ~= nil) then
sql = [[UPDATE v_devices SET device_uuid_alternate = null ]];
sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]];
sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]];
local sql = [[UPDATE v_devices SET device_uuid_alternate = null ]];
sql = sql .. [[WHERE device_uuid_alternate = :device_uuid ]];
sql = sql .. [[AND domain_uuid = :domain_uuid ]];
local params = {device_uuid = device_uuid, domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n");
freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
end
end
@@ -30,8 +30,14 @@
local log = require "resources.functions.log".ring_group
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--include functions
require "resources.functions.trim";
@@ -104,8 +110,9 @@ local log = require "resources.functions.log".ring_group
ring_group_forward_enabled = "";
ring_group_forward_destination = "";
sql = "SELECT * FROM v_ring_groups ";
sql = sql .. "where ring_group_uuid = '"..ring_group_uuid.."' ";
status = dbh:query(sql, function(row)
sql = sql .. "where ring_group_uuid = :ring_group_uuid ";
local params = {ring_group_uuid = ring_group_uuid};
status = dbh:query(sql, params, function(row)
domain_uuid = row["domain_uuid"];
ring_group_name = row["ring_group_name"];
ring_group_extension = row["ring_group_extension"];
@@ -202,19 +209,20 @@ local log = require "resources.functions.log".ring_group
session:execute("transfer", ring_group_forward_destination.." XML "..context);
else
--get the strategy of the ring group, if random, we use random() to order the destinations
sql = [[
SELECT
r.ring_group_strategy
FROM
v_ring_groups as r
WHERE
ring_group_uuid = ']]..ring_group_uuid..[['
AND r.domain_uuid = ']]..domain_uuid..[['
AND r.ring_group_enabled = 'true'
]];
local sql = [[
SELECT
r.ring_group_strategy
FROM
v_ring_groups as r
WHERE
ring_group_uuid = :ring_group_uuid
AND r.domain_uuid = :domain_uuid
AND r.ring_group_enabled = 'true'
]];
local params = {ring_group_uuid = ring_group_uuid, domain_uuid = domain_uuid};
assert(dbh:query(sql, function(row)
assert(dbh:query(sql, params, function(row)
if (row.ring_group_strategy == "random") then
if (database["type"] == "mysql") then
sql_order = 'rand()'
@@ -236,16 +244,18 @@ local log = require "resources.functions.log".ring_group
v_ring_groups as r, v_ring_group_destinations as d
WHERE
d.ring_group_uuid = r.ring_group_uuid
AND d.ring_group_uuid = ']]..ring_group_uuid..[['
AND r.domain_uuid = ']]..domain_uuid..[['
AND d.ring_group_uuid = :ring_group_uuid
AND r.domain_uuid = :domain_uuid
AND r.ring_group_enabled = 'true'
ORDER BY
]]..sql_order..[[
]];
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
]];
if debug["sql"] then
freeswitch.consoleLog("notice", "[ring group] SQL:" .. sql .. "; params:" .. json.encode(params) .. "\n");
end
destinations = {};
x = 1;
assert(dbh:query(sql, function(row)
assert(dbh:query(sql, params, function(row)
if (row.destination_prompt == "1" or row.destination_prompt == "2") then
prompt = "true";
end
@@ -283,25 +293,29 @@ local log = require "resources.functions.log".ring_group
--get the dialplan data and save it to a table
if (external) then
sql = [[select * from v_dialplans as d, v_dialplan_details as s
where (d.domain_uuid = ']] .. domain_uuid .. [[' or d.domain_uuid is null)
and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3'
and d.dialplan_enabled = 'true'
and d.dialplan_uuid = s.dialplan_uuid
order by
d.dialplan_order asc,
d.dialplan_name asc,
d.dialplan_uuid asc,
s.dialplan_detail_group asc,
CASE s.dialplan_detail_tag
WHEN 'condition' THEN 1
WHEN 'action' THEN 2
WHEN 'anti-action' THEN 3
ELSE 100 END,
s.dialplan_detail_order asc ]]
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
where (d.domain_uuid = :domain_uuid or d.domain_uuid is null)
and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3'
and d.dialplan_enabled = 'true'
and d.dialplan_uuid = s.dialplan_uuid
order by
d.dialplan_order asc,
d.dialplan_name asc,
d.dialplan_uuid asc,
s.dialplan_detail_group asc,
CASE s.dialplan_detail_tag
WHEN 'condition' THEN 1
WHEN 'action' THEN 2
WHEN 'anti-action' THEN 3
ELSE 100 END,
s.dialplan_detail_order asc
]];
params = {domain_uuid = domain_uuid};
if debug["sql"] then
freeswitch.consoleLog("notice", "[ring group] SQL:" .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dialplans = {};
x = 1;
assert(dbh:query(sql, function(row)
assert(dbh:query(sql, params, function(row)
dialplans[x] = row;
x = x + 1;
end));
@@ -628,10 +642,13 @@ local log = require "resources.functions.log".ring_group
--execute the time out action
session:execute(ring_group_timeout_app, ring_group_timeout_data);
else
sql = "SELECT ring_group_timeout_app, ring_group_timeout_data FROM v_ring_groups ";
sql = sql .. "where ring_group_uuid = '"..ring_group_uuid.."' ";
--freeswitch.consoleLog("notice", "[ring group] SQL:" .. sql .. "\n");
dbh:query(sql, function(row)
local sql = "SELECT ring_group_timeout_app, ring_group_timeout_data FROM v_ring_groups ";
sql = sql .. "where ring_group_uuid = :ring_group_uuid";
local params = {ring_group_uuid = ring_group_uuid};
if debug["sql"] then
freeswitch.consoleLog("notice", "[ring group] SQL:" .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
--send missed call notification
missed();
--execute the time out action
@@ -27,8 +27,14 @@
require "resources.functions.config";
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--set default variables
sounds_dir = "";
@@ -105,17 +111,19 @@
freeswitch.consoleLog("NOTICE", "[ring_group] menu_selection: "..menu_selection.."\n");
if (menu_selection == "1") then
--first, check to see if the destination is already in this ring group
sql = [[
local sql = [[
SELECT COUNT(*) AS in_group FROM
v_ring_group_destinations
WHERE
domain_uuid = ']]..domain_uuid..[['
AND ring_group_uuid = ']]..ring_group_uuid..[['
AND destination_number = ']]..destination..[['
domain_uuid = :domain_uuid
AND ring_group_uuid = :ring_group_uuid
AND destination_number = :destination
]];
--freeswitch.consoleLog("NOTICE", "[ring_group] SQL "..sql.."\n");
local params = {domain_uuid = domain_uuid, ring_group_uuid = ring_group_uuid,
destination = destination};
--freeswitch.consoleLog("NOTICE", "[ring_group] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
assert(dbh:query(sql, function(row)
assert(dbh:query(sql, params, function(row)
if (row.in_group == "0") then
sql = [[
INSERT INTO
@@ -128,15 +136,26 @@
destination_timeout
)
VALUES
( ']]..ring_group_destination_uuid..[[',
']]..domain_uuid..[[',
']]..ring_group_uuid..[[',
']]..destination..[[',
]]..destination_delay..[[,
]]..destination_timeout..[[
( :ring_group_destination_uuid,
:domain_uuid,
:ring_group_uuid,
:destination,
:destination_delay,
:destination_timeout
)]];
freeswitch.consoleLog("NOTICE", "[ring_group][destination] SQL "..sql.."\n");
dbh:query(sql);
params = {
ring_group_destination_uuid = ring_group_destination_uuid;
domain_uuid = domain_uuid;
ring_group_uuid = ring_group_uuid;
destination = destination;
destination_delay = destination_delay;
destination_timeout = destination_timeout;
};
freeswitch.consoleLog("NOTICE", "[ring_group][destination] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
dbh:query(sql, params);
freeswitch.consoleLog("NOTICE", "[ring_group][destination] LOG IN\n");
session:streamFile("ivr/ivr-you_are_now_logged_in.wav");
@@ -147,16 +166,18 @@
end));
end
if (menu_selection == "2") then
sql = [[
local sql = [[
DELETE FROM
v_ring_group_destinations
WHERE
domain_uuid =']]..domain_uuid..[['
AND ring_group_uuid=']]..ring_group_uuid..[['
AND destination_number=']]..destination..[['
domain_uuid =:domain_uuid
AND ring_group_uuid=:ring_group_uuid
AND destination_number=:destination
]];
freeswitch.consoleLog("NOTICE", "[ring_group][destination] SQL "..sql.."\n");
dbh:query(sql);
local params = {domain_uuid = domain_uuid, ring_group_uuid = ring_group_uuid,
destination = destination};
freeswitch.consoleLog("NOTICE", "[ring_group][destination] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
dbh:query(sql, params);
freeswitch.consoleLog("NOTICE", "[ring_group][destination] LOG OUT\n");
session:streamFile("ivr/ivr-you_are_now_logged_out.wav");
@@ -0,0 +1,98 @@
-- FusionPBX
-- Version: MPL 1.1
-- The contents of this file are subject to the Mozilla Public License Version
-- 1.1 (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
-- http://www.mozilla.org/MPL/
-- Software distributed under the License is distributed on an "AS IS" basis,
-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-- for the specific language governing rights and limitations under the
-- License.
-- The Original Code is FusionPBX
-- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com>
-- Portions created by the Initial Developer are Copyright (C) 2016
-- the Initial Developer. All Rights Reserved.
-- load config
require "resources.functions.config";
--set debug
debug["sql"] = true;
--load libraries
local log = require "resources.functions.log"["app:dialplan:outbound:speed_dial"]
local Database = require "resources.functions.database";
local cache = require "resources.functions.cache";
local json = require "resources.functions.lunajson";
--get the variables
domain_name = session:getVariable("domain_name");
domain_uuid = session:getVariable("domain_uuid");
context = session:getVariable("context");
--get the argv values
destination = argv[2];
-- search in memcache first
local key = "app:dialplan:outbound:speed_dial:" .. destination .. "@" .. domain_name
local source = "memcache"
local value = cache.get(key)
-- decode value from memcache
if value then
local t = json.decode(value)
if not (t and t.phone_number and t.context) then
log.warning("can not decode value from memcache: %s", value)
value = nil
else
value = t
end
end
-- search in database
if not value then
-- set source flag
source = "database"
-- connect to database
local dbh = Database.new('system');
-- search for the phone number in database using the speed dial
local sql = "SELECT phone_number "
sql = sql .. "FROM v_contact_phones "
sql = sql .. "WHERE phone_speed_dial = :phone_speed_dial "
sql = sql .. "AND domain_uuid = :domain_uuid "
local params = {phone_speed_dial = destination, domain_uuid = domain_uuid};
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
local phone_number = dbh:first_value(sql, params)
-- release database connection
dbh:release()
-- set the cache
if phone_number then
value = {context = context, phone_number = phone_number}
cache.set(key, json.encode(value), expire["speed_dial"])
end
end
-- transfer
if value then
--log the result
log.noticef("%s XML %s source: %s", destination, context, source)
--transfer the call
session:transfer(value.phone_number, "XML", context);
else
log.warningf('can not find number: %s in domain: %s', destination, domain_name)
end
+115 -58
View File
@@ -1,5 +1,5 @@
-- Part of FusionPBX
-- Copyright (C) 2013-2015 Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2013-2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -50,8 +50,13 @@
password_tries = 0;
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library (as global object)
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--set the api
api = freeswitch.API();
@@ -69,6 +74,9 @@
destination_number = session:getVariable("destination_number");
caller_id_name = session:getVariable("caller_id_name");
caller_id_number = session:getVariable("caller_id_number");
if (string.sub(caller_id_number, 1, 1) == "/") then
caller_id_number = string.sub(caller_id_number, 2, -1);
end
voicemail_greeting_number = session:getVariable("voicemail_greeting_number");
skip_instructions = session:getVariable("skip_instructions");
skip_greeting = session:getVariable("skip_greeting");
@@ -83,6 +91,8 @@
record_silence_threshold = 300;
end
voicemail_authorized = session:getVariable("voicemail_authorized");
sip_from_user = session:getVariable("sip_from_user");
sip_number_alias = session:getVariable("sip_number_alias");
if (not vm_message_ext) then vm_message_ext = 'wav'; end
--set the sounds path for the language, dialect and voice
@@ -99,12 +109,13 @@
if (domain_uuid == nil) then
--get the domain_uuid using the domain name required for multi-tenant
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' ";
local sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = :domain_name ";
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(rows)
dbh:query(sql, params, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
@@ -147,6 +158,17 @@
end
end
end
if settings['voicemail'] then
if settings['voicemail']['voicemail_to_sms'] then
voicemail_to_sms = (settings['voicemail']['voicemail_to_sms']['boolean'] == 'true');
end
if settings['voicemail']['voicemail_to_sms_did'] then
voicemail_to_sms_did = settings['voicemail']['voicemail_to_sms_did']['text'];
end
voicemail_to_sms_did = voicemail_to_sms_did or '';
end
if (not temp_dir) or (#temp_dir == 0) then
if (settings['server'] ~= nil) then
if (settings['server']['temp'] ~= nil) then
@@ -161,17 +183,19 @@
if (voicemail_id ~= nil) then
if (session:ready()) then
--get the information from the database
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. voicemail_id ..[['
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
voicemail_uuid = string.lower(row["voicemail_uuid"]);
voicemail_password = row["voicemail_password"];
greeting_id = row["greeting_id"];
voicemail_alternate_greet_id = row["voicemail_alternate_greet_id"];
voicemail_mail_to = row["voicemail_mail_to"];
voicemail_attach_file = row["voicemail_attach_file"];
voicemail_local_after_email = row["voicemail_local_after_email"];
@@ -228,6 +252,7 @@
require "app.voicemail.resources.functions.listen_to_recording";
require "app.voicemail.resources.functions.message_waiting";
require "app.voicemail.resources.functions.send_email";
require "app.voicemail.resources.functions.send_sms";
require "app.voicemail.resources.functions.delete_recording";
require "app.voicemail.resources.functions.message_saved";
require "app.voicemail.resources.functions.return_call";
@@ -251,11 +276,12 @@
debug["info"] = "true";
--get voicemail message details
sql = [[SELECT * FROM v_domains WHERE domain_name = ']] .. domain_name ..[[']]
local sql = [[SELECT * FROM v_domains WHERE domain_name = :domain_name]];
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
domain_uuid = string.lower(row["domain_uuid"]);
end);
@@ -270,7 +296,11 @@
if (voicemail_id) then
if (voicemail_authorized) then
if (voicemail_authorized == "true") then
--skip the password check
if (voicemail_id == sip_from_user or voicemail_id == sip_number_alias) then
--skip the password check
else
check_password(voicemail_id, password_tries);
end
else
check_password(voicemail_id, password_tries);
end
@@ -293,13 +323,14 @@
--check the voicemail quota
if (vm_disk_quota) then
--get voicemail message seconds
sql = [[SELECT coalesce(sum(message_length), 0) as message_sum FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. voicemail_uuid ..[[']]
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
local sql = [[SELECT coalesce(sum(message_length), 0) as message_sum FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid]]
local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
message_sum = row["message_sum"];
end);
if (tonumber(vm_disk_quota) <= tonumber(message_sum)) then
@@ -343,13 +374,14 @@
--get the voicemail destinations
sql = [[select * from v_voicemail_destinations
where voicemail_uuid = ']]..voicemail_uuid..[[']]
--freeswitch.consoleLog("notice", "[voicemail][destinations] SQL:" .. sql .. "\n");
where voicemail_uuid = :voicemail_uuid]]
params = {voicemail_uuid=voicemail_uuid};
--freeswitch.consoleLog("notice", "[voicemail][destinations] SQL:" .. sql .. "; params:" .. json.encode(params) .. "\n");
destinations = {};
x = 1;
table.insert(destinations, {domain_uuid=domain_uuid,voicemail_destination_uuid=voicemail_uuid,voicemail_uuid=voicemail_uuid,voicemail_uuid_copy=voicemail_uuid});
x = x + 1;
assert(dbh:query(sql, function(row)
assert(dbh:query(sql, params, function(row)
destinations[x] = row;
x = x + 1;
end));
@@ -382,68 +414,90 @@
if (storage_type == "base64") then
table.insert(sql, "message_base64, ");
end
if (transcribe_enabled == "true") then
table.insert(sql, "message_transcription, ");
end
table.insert(sql, "message_length ");
--table.insert(sql, "message_status, ");
--table.insert(sql, "message_priority, ");
table.insert(sql, ") ");
table.insert(sql, "VALUES ");
table.insert(sql, "( ");
table.insert(sql, "'"..voicemail_message_uuid.."', ");
table.insert(sql, "'"..domain_uuid.."', ");
table.insert(sql, "'"..row.voicemail_uuid_copy.."', ");
table.insert(sql, "'"..start_epoch.."', ");
table.insert(sql, "'"..caller_id_name.."', ");
table.insert(sql, "'"..caller_id_number.."', ");
table.insert(sql, ":voicemail_message_uuid, ");
table.insert(sql, ":domain_uuid, ");
table.insert(sql, ":voicemail_uuid, ");
table.insert(sql, ":start_epoch, ");
table.insert(sql, ":caller_id_name, ");
table.insert(sql, ":caller_id_number, ");
if (storage_type == "base64") then
table.insert(sql, "'"..message_base64.."', ");
table.insert(sql, ":message_base64, ");
end
table.insert(sql, "'"..message_length.."' ");
--table.insert(sql, "'"..message_status.."', ");
--table.insert(sql, "'"..message_priority.."' ");
if (transcribe_enabled == "true") then
table.insert(sql, ":transcription, ");
end
table.insert(sql, ":message_length ");
--table.insert(sql, ":message_status, ");
--table.insert(sql, ":message_priority ");
table.insert(sql, ") ");
sql = table.concat(sql, "\n");
local params = {
voicemail_message_uuid = voicemail_message_uuid;
domain_uuid = domain_uuid;
voicemail_uuid = row.voicemail_uuid_copy;
start_epoch = start_epoch;
caller_id_name = caller_id_name;
caller_id_number = caller_id_number;
message_base64 = message_base64;
transcription = transcription;
message_length = message_length;
--message_status = message_status;
--message_priority = message_priority;
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
if (storage_type == "base64") then
local Database = require "resources.functions.database"
local dbh = Database.new('system', 'base64');
dbh:query(sql);
dbh:query(sql, params);
dbh:release();
else
dbh:query(sql);
dbh:query(sql, params);
end
end
--get saved and new message counts
local params = {domain_uuid = domain_uuid, voicemail_uuid = row.voicemail_uuid_copy};
--get new message count
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. row.voicemail_uuid_copy ..[['
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND (message_status is null or message_status = '') ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(result)
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(result)
new_messages = result["new_messages"];
end);
--get saved message count
sql = [[SELECT count(*) as saved_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. row.voicemail_uuid_copy ..[['
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND message_status = 'saved' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(result)
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(result)
saved_messages = result["saved_messages"];
end);
--get the voicemail_id
sql = [[SELECT voicemail_id FROM v_voicemails
WHERE voicemail_uuid = ']] .. row.voicemail_uuid_copy ..[[']];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(result)
sql = [[SELECT voicemail_id FROM v_voicemails WHERE voicemail_uuid = :voicemail_uuid]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(result)
voicemail_id_copy = result["voicemail_id"];
end);
@@ -467,6 +521,9 @@
--send the email with the voicemail recording attached
if (tonumber(message_length) > 2) then
send_email(voicemail_id_copy, voicemail_message_uuid);
if (voicemail_to_sms) then
send_sms(voicemail_id_copy, voicemail_message_uuid);
end
end
end --for
@@ -32,15 +32,17 @@
dtmf_digits = '';
password = macro(session, "password_new", 20, 5000, '');
--update the voicemail password
sql = [[UPDATE v_voicemails
set voicemail_password = ']] .. password ..[['
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. voicemail_id ..[['
local sql = [[UPDATE v_voicemails
set voicemail_password = :password
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {password = password, domain_uuid = domain_uuid,
voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
--has been changed to
dtmf_digits = '';
macro(session, "password_changed", 20, 3000, password);
@@ -44,14 +44,15 @@
--get the voicemail settings from the database
if (voicemail_id) then
if (session:ready()) then
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. voicemail_id ..[['
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
voicemail_uuid = string.lower(row["voicemail_uuid"]);
voicemail_password = row["voicemail_password"];
greeting_id = row["greeting_id"];
@@ -40,11 +40,13 @@
--check to see if the greeting file exists
if (storage_type == "base64" or storage_type == "http_cache") then
greeting_invalid = true;
sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']].. voicemail_id.. [['
AND greeting_id = ']].. greeting_id.. [[' ]];
status = dbh:query(sql, function(row)
local sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND greeting_id = :greeting_id]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id,
greeting_id = greeting_id};
dbh:query(sql, params, function(row)
--greeting found
greeting_invalid = false;
end);
@@ -74,31 +76,39 @@
--valid greeting_id update the database
if (session:ready()) then
local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid};
local sql = "UPDATE v_voicemails SET "
if (greeting_id == "0") then
sql = [[UPDATE v_voicemails SET greeting_id = null ]];
sql = sql .. "greeting_id = null ";
else
sql = [[UPDATE v_voicemails SET greeting_id = ']]..greeting_id..[[' ]];
sql = sql .. "greeting_id = :greeting_id ";
params.greeting_id = greeting_id;
end
sql = sql ..[[WHERE domain_uuid = ']] .. domain_uuid ..[[' ]]
sql = sql ..[[AND voicemail_uuid = ']] .. voicemail_uuid ..[[' ]];
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
sql = sql .. "AND voicemail_uuid = :voicemail_uuid ";
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
end
--get the greeting from the database
if (storage_type == "base64") then
local dbh = Database.new('system', 'base64/read')
sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']].. voicemail_id.. [['
AND greeting_id = ']].. greeting_id.. [[' ]];
local sql = [[SELECT greeting_base64
FROM v_voicemail_greetings
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND greeting_id = :greeting_id]];
local params = {
domain_uuid = domain_uuid;
voicemail_id = voicemail_id;
greeting_id = greeting_id;
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--set the voicemail message path
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
@@ -32,11 +32,13 @@
macro(session, "message_deleted", 1, 100, '');
end
end
--get the voicemail_uuid
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. voicemail_id ..[[']];
status = dbh:query(sql, function(row)
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
dbh:query(sql, params, function(row)
db_voicemail_uuid = row["voicemail_uuid"];
end);
--flush dtmf digits from the input buffer
@@ -46,13 +48,14 @@
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext);
--delete from the database
sql = [[DELETE FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. db_voicemail_uuid ..[['
AND voicemail_message_uuid = ']] .. uuid ..[[']];
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND voicemail_message_uuid = :uuid]];
params = {domain_uuid = domain_uuid, voicemail_uuid = db_voicemail_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
--log to console
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail][deleted] message: " .. uuid .. "\n");
@@ -95,21 +95,25 @@
--save the merged file into the database as base64
if (storage_type == "base64") then
local file = require "resources.functions.file"
--get the content of the file
local f = io.open(message_intro_location, "rb");
local file_content = f:read("*all");
f:close();
local file_content = assert(file.read_base64(message_intro_location));
--save the merged file as base64
local sql = {}
sql = [[UPDATE SET v_voicemail_messages
SET message_intro_base64 = ']].. base64.encode(file_content) ..[['
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
sql = table.concat(sql, "\n");
local sql = [[UPDATE SET v_voicemail_messages
SET message_intro_base64 = :file_content
WHERE domain_uuid = :domain_uuid
AND voicemail_message_uuid = :uuid]];
local params = {file_content = file_content, domain_uuid = domain_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
end
local dbh = Database.new('system', 'base64')
dbh:query(sql, params)
dbh:release()
end
end
@@ -52,14 +52,15 @@
--get voicemail message details
if (session:ready()) then
sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
AND voicemail_message_uuid = ']] .. uuid ..[[']]
local sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND voicemail_message_uuid = :uuid]]
local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get the values from the database
created_epoch = row["created_epoch"];
caller_id_name = row["caller_id_name"];
@@ -72,14 +73,15 @@
end
--get the voicemail settings
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. forward_voicemail_id ..[['
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid, voicemail_id = forward_voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
forward_voicemail_uuid = string.lower(row["voicemail_uuid"]);
forward_voicemail_mail_to = row["voicemail_mail_to"];
forward_voicemail_attach_file = row["voicemail_attach_file"];
@@ -108,33 +110,41 @@
table.insert(sql, ") ");
table.insert(sql, "VALUES ");
table.insert(sql, "( ");
table.insert(sql, "'".. voicemail_message_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. forward_voicemail_uuid .."', ");
table.insert(sql, ":voicemail_message_uuid, ");
table.insert(sql, ":domain_uuid, ");
table.insert(sql, ":forward_voicemail_uuid, ");
if (storage_type == "base64") then
table.insert(sql, "'".. message_base64 .."', ");
table.insert(sql, ":message_base64, ");
end
table.insert(sql, "'".. created_epoch .."', ");
table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. caller_id_number .."', ");
table.insert(sql, "'".. message_length .."' ");
--table.insert(sql, "'".. message_status .."', ");
--table.insert(sql, "'".. message_priority .."' ");
table.insert(sql, ":created_epoch, ");
table.insert(sql, ":caller_id_name, ");
table.insert(sql, ":caller_id_number, ");
table.insert(sql, ":message_length ");
--table.insert(sql, ":message_status, ");
--table.insert(sql, ":message_priority ");
table.insert(sql, ") ");
sql = table.concat(sql, "\n");
local params = {
voicemail_message_uuid = voicemail_message_uuid;
domain_uuid = domain_uuid;
forward_voicemail_uuid = forward_voicemail_uuid;
message_base64 = message_base64;
created_epoch = created_epoch;
caller_id_name = caller_id_name;
caller_id_number = caller_id_number;
message_length = message_length;
-- message_status = message_status;
-- message_priority = message_priority;
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
if (storage_type == "base64") then
array = explode("://", database["system"]);
local luasql = require "luasql.postgres";
local env = assert (luasql.postgres());
local dbh = env:connect(array[2]);
res, serr = dbh:execute(sql);
dbh:close();
env:close();
local dbh = Database.new('system', 'base64')
dbh:query(sql, params);
dbh:release();
else
dbh:query(sql);
dbh:query(sql, params);
end
--offer to add an intro to the forwarded message
@@ -23,8 +23,6 @@
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
local Database = require "resources.functions.database"
--define function to listen to the recording
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
@@ -76,13 +74,14 @@
if (storage_type == "base64") then
local dbh = Database.new('system', 'base64/read')
sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
local sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_message_uuid = :uuid]];
local params = {domain_uuid = domain_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--set the voicemail message path
mkdir(voicemail_dir.."/"..voicemail_id);
message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext;
@@ -1,5 +1,5 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2013 - 2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -12,7 +12,7 @@
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
@@ -41,7 +41,13 @@
if (name == "person_not_available_record_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-person.wav"});
--pronounce the voicemail_id
table.insert(actions, {app="say.number.iterated",data=voicemail_id});
if (voicemail_alternate_greet_id and string.len(voicemail_alternate_greet_id) > 0) then
table.insert(actions, {app="say.number.iterated",data=voicemail_alternate_greet_id});
elseif (voicemail_greet_id and string.len(voicemail_greet_id) > 0) then
table.insert(actions, {app="say.number.iterated",data=voicemail_greet_id});
else
table.insert(actions, {app="say.number.iterated",data=voicemail_id});
end
table.insert(actions, {app="streamFile",data="voicemail/vm-not_available.wav"});
end
--record your message at the tone press any key or stop talking to end the recording
@@ -32,14 +32,15 @@
session:flushDigits();
--new voicemail count
if (session:ready()) then
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
local sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND (message_status is null or message_status = '') ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
new_messages = row["new_messages"];
end);
dtmf_digits = macro(session, "new_messages", 1, 100, new_messages);
@@ -48,32 +49,34 @@
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
sql = [[SELECT count(*) as saved_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND message_status = 'saved' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
saved_messages = row["saved_messages"];
end);
dtmf_digits = macro(session, "saved_messages", 1, 100, saved_messages);
end
end
--get domain timezone
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
sql = [[SELECT domain_setting_value as current_time_zone FROM v_domain_settings
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND domain_setting_subcategory='time_zone' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
current_time_zone = row["current_time_zone"];
end);
end
end
--get domain timezone
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
local sql = [[SELECT domain_setting_value as current_time_zone FROM v_domain_settings
WHERE domain_uuid = :domain_uuid
AND domain_setting_subcategory='time_zone' ]];
local params = {domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
current_time_zone = row["current_time_zone"];
end);
end
end
--to listen to new message
if (session:ready() and new_messages ~= '0') then
if (string.len(dtmf_digits) == 0) then
@@ -41,19 +41,21 @@
--message_status new,saved
if (session:ready()) then
if (voicemail_id ~= nil) then
sql = [[SELECT voicemail_message_uuid, created_epoch, caller_id_name, caller_id_number FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. voicemail_uuid ..[[']]
local sql = [[SELECT voicemail_message_uuid, created_epoch, caller_id_name, caller_id_number
FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid ]]
if (message_status == "new") then
sql = sql .. [[AND (message_status is null or message_status = '') ]];
elseif (message_status == "saved") then
sql = sql .. [[AND message_status = 'saved' ]];
end
sql = sql .. [[ORDER BY created_epoch desc;]];
local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get the values from the database
--row["voicemail_message_uuid"];
--row["created_epoch"];
@@ -5,13 +5,13 @@ local log = require "resources.functions.log"["voicemail-count"]
local message_count_by_uuid_sql = [[SELECT
( SELECT count(*)
FROM v_voicemail_messages
WHERE voicemail_uuid = '%s'
WHERE voicemail_uuid = :voicemail_uuid
AND (message_status is null or message_status = '')
) as new_messages,
( SELECT count(*)
FROM v_voicemail_messages
WHERE voicemail_uuid = '%s'
WHERE voicemail_uuid = :voicemail_uuid
AND message_status = 'saved'
) as saved_messages
]]
@@ -19,15 +19,13 @@ local message_count_by_uuid_sql = [[SELECT
function message_count_by_uuid(voicemail_uuid)
local new_messages, saved_messages = "0", "0"
local sql = string.format(message_count_by_uuid_sql,
voicemail_uuid, voicemail_uuid
)
local params = {voicemail_uuid = voicemail_uuid};
if debug["sql"] then
log.noticef("SQL: %s", sql)
log.noticef("SQL: %s; params: %s", message_count_by_uuid_sql, json.encode(params))
end
dbh:query(sql, function(row)
dbh:query(message_count_by_uuid_sql, params, function(row)
new_messages, saved_messages = row.new_messages, row.saved_messages
end)
@@ -42,14 +40,14 @@ local message_count_by_id_sql = [[SELECT
( SELECT count(*)
FROM v_voicemail_messages as m inner join v_voicemails as v
on v.voicemail_uuid = m.voicemail_uuid
WHERE v.voicemail_id = '%s' AND v.domain_uuid = '%s'
WHERE v.voicemail_id = :voicemail_id AND v.domain_uuid = :domain_uuid
AND (m.message_status is null or m.message_status = '')
) as new_messages,
( SELECT count(*)
FROM v_voicemail_messages as m inner join v_voicemails as v
on v.voicemail_uuid = m.voicemail_uuid
WHERE v.voicemail_id = '%s' AND v.domain_uuid = '%s'
WHERE v.voicemail_id = :voicemail_id AND v.domain_uuid = :domain_uuid
AND m.message_status = 'saved'
) as saved_messages
]]
@@ -57,15 +55,13 @@ local message_count_by_id_sql = [[SELECT
function message_count_by_id(voicemail_id, domain_uuid)
local new_messages, saved_messages = "0", "0"
local sql = string.format(message_count_by_id_sql,
voicemail_id, domain_uuid, voicemail_id, domain_uuid
)
local params = {voicemail_id = voicemail_id, domain_uuid = domain_uuid};
if debug["sql"] then
log.noticef("SQL: %s", sql)
log.noticef("SQL: %s; params: %s", message_count_by_id_sql, json.encode(params))
end
dbh:query(sql, function(row)
dbh:query(message_count_by_id_sql, params, function(row)
new_messages, saved_messages = row.new_messages, row.saved_messages
end)
@@ -30,21 +30,23 @@
--flush dtmf digits from the input buffer
session:flushDigits();
--get the voicemail_uuid
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. voicemail_id ..[[']];
status = dbh:query(sql, function(row)
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
dbh:query(sql, params, function(row)
db_voicemail_uuid = row["voicemail_uuid"];
end);
--delete from the database
sql = [[UPDATE v_voicemail_messages SET message_status = 'saved'
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. db_voicemail_uuid ..[['
AND voicemail_message_uuid = ']] .. uuid ..[[']];
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND voicemail_message_uuid = :uuid]];
params = {domain_uuid = domain_uuid, voicemail_uuid = db_voicemail_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql);
dbh:query(sql, params);
--log to console
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail][saved] id: " .. voicemail_id .. " message: "..uuid.."\n");
@@ -1,5 +1,5 @@
-- Part of FusionPBX
-- Copyright (C) 2013-2015 Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2013-2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -12,7 +12,7 @@
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
@@ -25,39 +25,46 @@
--voicemail count if zero new messages set the mwi to no
function message_waiting(voicemail_id, domain_uuid)
--initialize the array and add the voicemail_id
local accounts = {}
--add the current voicemail id to the accounts array
table.insert(accounts, voicemail_id);
--get the voicemail id and all related mwi accounts
local sql = [[SELECT extension, number_alias from v_extensions
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND (mwi_account = ']]..voicemail_id..[[' or mwi_account = ']]..voicemail_id..[[@]]..domain_name..[[')]];
WHERE domain_uuid = :domain_uuid
AND (
mwi_account = :voicemail_id
or mwi_account = :mwi_account
or number_alias = :voicemail_id
)]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id,
mwi_account = voicemail_id .. "@" .. domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
if (string.len(row["number_alias"]) > 0) then
table.insert(accounts, row["number_alias"]);
else
table.insert(accounts, row["extension"]);
end
dbh:query(sql, params, function(row)
table.insert(accounts, row["extension"]);
end);
--get new and saved message counts
local new_messages, saved_messages = message_count_by_id(
voicemail_id, domain_uuid
)
local new_messages, saved_messages = message_count_by_id(voicemail_id, domain_uuid);
--send the message waiting event
for _,value in ipairs(accounts) do
local account = value.."@"..domain_name
mwi_notify(account, new_messages, saved_messages)
if (debug["info"]) then
if new_messages == "0" then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: no new messages\n");
else
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: " .. new_messages .. " new message(s)\n");
--add the domain to voicemail id
local account = value.."@"..domain_name;
--send the message waiting notifications
mwi_notify(account, new_messages, saved_messages);
--send information to the console
if (debug["info"]) then
if new_messages == "0" then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: no new messages\n");
else
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: " .. new_messages .. " new message(s)\n");
end
end
end
end
end
@@ -27,6 +27,10 @@
--play the greeting
function play_greeting()
timeout = 100;
tries = 1;
max_timeout = 200;
--voicemail prompt
if (skip_greeting == "true") then
--skip the greeting
@@ -47,15 +51,17 @@
if (storage_type == "base64") then
local dbh = Database.new('system', 'base64/read')
sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']].. voicemail_id.. [['
AND greeting_id = ']].. greeting_id.. [[' ]];
local sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND greeting_id = :greeting_id ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id,
greeting_id = greeting_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
local saved
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--set the voicemail message path
mkdir(voicemail_dir.."/"..voicemail_id);
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
@@ -76,15 +82,19 @@
if saved then
--play the greeting
session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "", "\\d+", max_timeout);
--session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
--delete the greeting (retain local for better responsiveness)
--os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
end
elseif (storage_type == "http_cache") then
session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "", "\\d+", max_timeout);
--session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
else
session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "","\\d+", max_timeout);
--session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
end
--sleep
@@ -90,12 +90,14 @@
end
--delete the previous recording
sql = "delete from v_voicemail_greetings ";
sql = sql .. "where domain_uuid = '".. domain_uuid .. "' ";
sql = sql .. "and voicemail_id = '".. voicemail_id .."' ";
sql = sql .. "and greeting_id = '".. greeting_id .."' ";
local sql = "delete from v_voicemail_greetings ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and voicemail_id = :voicemail_id ";
sql = sql .. "and greeting_id = :greeting_id ";
local params = {domain_uuid = domain_uuid,
voicemail_id = voicemail_id, greeting_id = greeting_id};
--freeswitch.consoleLog("notice", "[SQL] DELETING: " .. greeting_id .. "\n");
dbh:query(sql);
dbh:query(sql, params);
--get a new uuid
voicemail_greeting_uuid = api:execute("create_uuid");
@@ -116,38 +118,48 @@
table.insert(array, ") ");
table.insert(array, "VALUES ");
table.insert(array, "( ");
table.insert(array, "'"..voicemail_greeting_uuid.."', ");
table.insert(array, "'"..domain_uuid.."', ");
table.insert(array, "'"..voicemail_id.."', ");
table.insert(array, "'"..greeting_id.."', ");
table.insert(array, ":greeting_uuid, ");
table.insert(array, ":domain_uuid, ");
table.insert(array, ":voicemail_id, ");
table.insert(array, ":greeting_id, ");
if (storage_type == "base64") then
table.insert(array, "'"..greeting_base64.."', ");
table.insert(array, ":greeting_base64, ");
end
table.insert(array, "'Greeting "..greeting_id.."', ");
table.insert(array, "'greeting_"..greeting_id..".wav' ");
table.insert(array, ":greeting_name, ");
table.insert(array, ":greeting_filename ");
table.insert(array, ") ");
sql = table.concat(array, "\n");
params = {
greeting_uuid = voicemail_greeting_uuid;
domain_uuid = domain_uuid;
voicemail_id = voicemail_id;
greeting_id = greeting_id;
greeting_base64 = greeting_base64;
greeting_name = "Greeting "..greeting_id;
greeting_filename = "greeting_"..greeting_id..".wav"
};
--freeswitch.consoleLog("notice", "[SQL] INSERTING: " .. greeting_id .. "\n");
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
if (storage_type == "base64") then
local Database = require "resources.functions.database"
local dbh = Database.new('system', 'base64');
dbh:query(sql);
dbh:query(sql, params);
dbh:release();
else
dbh:query(sql);
dbh:query(sql, params);
end
--use the new greeting
local array = {}
table.insert(array, "update v_voicemails ");
table.insert(array, "set greeting_id = '".. greeting_id .."' ");
table.insert(array, "where domain_uuid = '".. domain_uuid .."' ");
table.insert(array, "and voicemail_id = '".. voicemail_id .."' ");
sql = table.concat(array, "\n");
dbh:query(sql);
sql = {}
table.insert(sql, "update v_voicemails ");
table.insert(sql, "set greeting_id = :greeting_id ");
table.insert(sql, "where domain_uuid = :domain_uuid ");
table.insert(sql, "and voicemail_id = :voicemail_id ");
sql = table.concat(sql, "\n");
params = {domain_uuid = domain_uuid, greeting_id = greeting_id,
voicemail_id = voicemail_id};
dbh:query(sql, params);
advanced();
end
@@ -26,6 +26,62 @@
--load libraries
local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings"
local JSON = require "resources.functions.lunajson"
--define uuid function
local random = math.random;
local function gen_uuid()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and random(0, 0xf) or random(8, 0xb);
return string.format('%x', v);
end)
end
local function transcribe(file_path,settings)
--transcription variables
local transcribe_provider = settings:get('voicemail', 'transcribe_provider', 'text') or '';
transcribe_language = settings:get('voicemail', 'transcribe_language', 'text') or 'en-US';
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] transcribe_provider: " .. transcribe_provider .. "\n");
freeswitch.consoleLog("notice", "[voicemail] transcribe_language: " .. transcribe_language .. "\n");
end
if (transcribe_provider == "microsoft") then
local api_key1 = settings:get('voicemail', 'microsoft_key1', 'text') or '';
local api_key2 = settings:get('voicemail', 'microsoft_key2', 'text') or '';
if (api_key1 ~= '' and api_key2 ~= '') then
access_token_cmd = "curl -X POST \"https://api.cognitive.microsoft.com/sts/v1.0/issueToken\" -H \"Content-type: application/x-www-form-urlencoded\" -H \"Content-Length: 0\" -H \"Ocp-Apim-Subscription-Key: "..api_key1.."\""
local handle = io.popen(access_token_cmd);
local access_token_result = handle:read("*a");
handle:close();
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. access_token_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. access_token_result .. "\n");
end
transcribe_cmd = "curl -X POST \"https://speech.platform.bing.com/recognize?scenarios=smd&appid=D4D52672-91D7-4C74-8AD8-42B1D98141A5&locale=en-US&device.os=Freeswitch&version=3.0&format=json&instanceid=" .. gen_uuid() .. "&requestid=" .. gen_uuid() .. "\" -H 'Authorization: Bearer " .. access_token_result .. "' -H 'Content-type: audio/wav; codec=\"audio/pcm\"; samplerate=8000; trustsourcerate=false' --data-binary @"..file_path
local handle = io.popen(transcribe_cmd);
local transcribe_result = handle:read("*a");
handle:close();
local transcribe_json = JSON.decode(transcribe_result);
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. transcribe_cmd .. "\n");
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. transcribe_result .. "\n");
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_json["results"][1]["name"] .. "\n");
freeswitch.consoleLog("notice", "[voicemail] CONFIDENCE: " .. transcribe_json["results"][1]["confidence"] .. "\n");
end
transcription = transcribe_json["results"][1]["name"];
transcription = transcription:gsub("<profanity>.*<%/profanity>","...");
confidence = transcribe_json["results"][1]["confidence"];
end
return transcription;
end
return '';
end
--save the recording
function record_message()
@@ -33,7 +89,12 @@
local settings = Settings.new(db, domain_name, domain_uuid)
local max_len_seconds = settings:get('voicemail', 'message_max_length', 'numeric') or 300;
transcribe_enabled = settings:get('voicemail', 'transcribe_enabled', 'boolean') or "false";
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] transcribe_enabled: " .. transcribe_enabled .. "\n");
end
--record your message at the tone press any key or stop talking to end the recording
if (skip_instructions == "true") then
--skip the instructions
@@ -73,12 +134,13 @@
session:hangup();
else
--get the voicemail options
sql = [[SELECT * FROM v_voicemail_options WHERE voicemail_uuid = ']] .. voicemail_uuid ..[[' ORDER BY voicemail_option_order asc ]];
local sql = [[SELECT * FROM v_voicemail_options WHERE voicemail_uuid = :voicemail_uuid ORDER BY voicemail_option_order asc ]];
local params = {voicemail_uuid = voicemail_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
count = 0;
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--check for matching options
if (tonumber(row.voicemail_option_digits) ~= nil) then
row.voicemail_option_digits = "^"..row.voicemail_option_digits.."$";
@@ -157,13 +219,16 @@
mkdir(voicemail_dir.."/"..voicemail_id);
if (vm_message_ext == "mp3") then
shout_exists = trim(api:execute("module_exists", "mod_shout"));
if (shout_exists == "true") then
if (shout_exists == "true" and transcribe_enabled == "false") then
freeswitch.consoleLog("notice", "using mod_shout for mp3 encoding\n");
--record in mp3 directly
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".mp3", max_len_seconds, record_silence_threshold, silence_seconds);
else
--create initial wav recording
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, record_silence_threshold, silence_seconds);
if (transcribe_enabled == "true") then
transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav",settings);
end
--use lame to encode, if available
if (file_exists("/usr/bin/lame")) then
freeswitch.consoleLog("notice", "using lame for mp3 encoding\n");
@@ -183,6 +248,9 @@
end
else
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds);
if (transcribe_enabled == "true") then
transcription = transcribe(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext,settings);
end
end
end
@@ -62,20 +62,21 @@
voicemail_name_base64 = assert(file.read_base64(voicemail_name_location));
--update the voicemail name
sql = "UPDATE v_voicemails ";
sql = sql .. "set voicemail_name_base64 = '".. voicemail_name_base64 .. "' ";
sql = sql .. "where domain_uuid = '".. domain_uuid .. "' ";
sql = sql .. "and voicemail_id = '".. voicemail_id .."'";
local sql = "UPDATE v_voicemails ";
sql = sql .. "set voicemail_name_base64 = :voicemail_name_base64 ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and voicemail_id = :voicemail_id";
local params = {voicemail_name_base64 = voicemail_name_base64,
domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
if (storage_type == "base64") then
local Database = require "resources.functions.database"
local dbh = Database.new('system', 'base64');
dbh:query(sql);
dbh:query(sql, params);
dbh:release();
else
dbh:query(sql);
dbh:query(sql, params);
end
elseif (storage_type == "http_cache") then
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. " ".. storage_path .."\n");
@@ -34,13 +34,14 @@
local settings = Settings.new(db, domain_name, domain_uuid)
--get voicemail message details
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. id ..[[']]
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id]]
local params = {domain_uuid = domain_uuid, voicemail_id = id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
db_voicemail_uuid = string.lower(row["voicemail_uuid"]);
--voicemail_password = row["voicemail_password"];
--greeting_id = row["greeting_id"];
@@ -71,13 +72,14 @@
end
--get voicemail message details
sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_message_uuid = ']] .. uuid ..[[']]
local sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_message_uuid = :uuid]]
local params = {domain_uuid = domain_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get the values from the database
--uuid = row["voicemail_message_uuid"];
created_epoch = row["created_epoch"];
@@ -115,8 +117,13 @@
local message_date = os.date("%A, %d %b %Y %I:%M %p", created_epoch)
--prepare the files
file_subject = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
file_body = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_body.tpl";
if (transcription ~= nil) then
file_subject = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
file_body = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_body_transcription.tpl";
else
file_subject = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
file_body = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_body.tpl";
end
if (not file_exists(file_subject)) then
file_subject = scripts_dir.."/app/voicemail/resources/templates/en/us/email_subject.tpl";
file_body = scripts_dir.."/app/voicemail/resources/templates/en/us/email_body.tpl";
@@ -166,6 +173,9 @@
body = body:gsub("${caller_id_name}", caller_id_name);
body = body:gsub("${caller_id_number}", caller_id_number);
body = body:gsub("${message_date}", message_date);
if (transcription ~= nil) then
body = body:gsub("${message_text}", transcription);
end
body = body:gsub("${message_duration}", message_length_formatted);
body = body:gsub("${account}", voicemail_name_formatted);
body = body:gsub("${voicemail_id}", id);
@@ -203,14 +213,16 @@
if (string.len(voicemail_mail_to) > 2) then
if (voicemail_local_after_email == "false") then
--delete the voicemail message details
sql = [[DELETE FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. db_voicemail_uuid ..[['
AND voicemail_message_uuid = ']] .. uuid ..[[']]
local sql = [[DELETE FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_uuid = :voicemail_uuid
AND voicemail_message_uuid = :uuid]]
local params = {domain_uuid = domain_uuid,
voicemail_uuid = db_voicemail_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql);
dbh:query(sql, params);
--delete voicemail recording file
if (file_exists(file)) then
os.remove(file);
@@ -0,0 +1,99 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define a function to send sms
function send_sms(id, uuid)
debug["info"] = true;
api = freeswitch.API();
--get voicemail message details
sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']] .. id ..[[']]
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
db_voicemail_uuid = string.lower(row["voicemail_uuid"]);
voicemail_sms_to = row["voicemail_sms_to"];
voicemail_file = row["voicemail_file"];
end);
--get the sms_body template
if (settings['voicemail']['voicemail_sms_body'] ~= nil) then
if (settings['voicemail']['voicemail_sms_body']['text'] ~= nil) then
sms_body = settings['voicemail']['voicemail_sms_body']['text'];
end
else
sms_body = 'You have a new voicemail from: ${caller_id_name} - ${caller_id_number} length ${message_length_formatted}';
end
--require the sms address to send to
if (string.len(voicemail_sms_to) > 2) then
--include languages file
local Text = require "resources.functions.text"
local text = Text.new("app.voicemail.app_languages")
--get voicemail message details
sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_message_uuid = ']] .. uuid ..[[']]
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
--get the values from the database
--uuid = row["voicemail_message_uuid"];
created_epoch = row["created_epoch"];
caller_id_name = row["caller_id_name"];
caller_id_number = row["caller_id_number"];
message_length = row["message_length"];
end);
--format the message length and date
message_length_formatted = format_seconds(message_length);
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
freeswitch.consoleLog("notice", "[voicemail] domain_name: " .. domain_name .. "\n");
end
local message_date = os.date("%A, %d %b %Y %I:%M %p", created_epoch)
sms_body = sms_body:gsub("${caller_id_name}", caller_id_name);
sms_body = sms_body:gsub("${caller_id_number}", caller_id_number);
sms_body = sms_body:gsub("${message_date}", message_date);
sms_body = sms_body:gsub("${message_duration}", message_length_formatted);
sms_body = sms_body:gsub("${account}", id);
sms_body = sms_body:gsub("${domain_name}", domain_name);
sms_body = sms_body:gsub("${sip_to_user}", id);
sms_body = sms_body:gsub("${dialed_user}", id);
-- sms_body = "hello";
cmd = "luarun app.lua sms outbound " .. voicemail_sms_to .. "@" .. domain_name .. " " .. voicemail_to_sms_did .. " '" .. sms_body .. "'";
api:executeString(cmd);
end
end
@@ -40,8 +40,8 @@
runonce = false;
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--used to stop the lua service
local file = assert(io.open(run_file, "w"));
@@ -14,7 +14,7 @@ local vm_message_count do
local vm_to_uuid_sql = [[SELECT v.voicemail_uuid
FROM v_voicemails as v inner join v_domains as d on v.domain_uuid = d.domain_uuid
WHERE v.voicemail_id = '%s' and d.domain_name = '%s']]
WHERE v.voicemail_id = :voicemail_id and d.domain_name = :domain_name]]
local vm_messages_sql = [[SELECT
( SELECT count(*)
@@ -50,7 +50,9 @@ function vm_message_count(account, use_cache)
local sql = string.format(vm_to_uuid_sql,
dbh:escape(id), dbh:escape(domain_name)
)
uuid = dbh:first_value(sql)
uuid = dbh:first_value(vm_to_uuid_sql, {
voicemail_id = id, domain_name = domain_name
})
if uuid and #uuid > 0 then
cache.set('voicemail_uuid:' .. account, uuid, 3600)
@@ -58,22 +60,21 @@ function vm_message_count(account, use_cache)
end
end
local sql
local row
if uuid and #uuid > 0 then
sql = string.format(vm_messages_sql,
dbh:quoted(uuid), dbh:quoted(uuid)
)
local sql = string.format(vm_messages_sql, ":voicemail_uuid", ":voicemail_uuid")
row = dbh:first_row(sql, {voicemail_uuid = uuid})
else
local uuid_sql = '(' .. string.format(vm_to_uuid_sql,
dbh:escape(id), dbh:escape(domain_name)
) .. ')'
local uuid_sql = '(' .. vm_to_uuid_sql .. ')'
sql = string.format(vm_messages_sql,
local sql = string.format(vm_messages_sql,
uuid_sql, uuid_sql
)
end
local row = sql and dbh:first_row(sql)
row = dbh:first_row(sql, {
voicemail_id = id, domain_name = domain_name
})
end
dbh:release()
@@ -0,0 +1,69 @@
<html>
<table width="400" border="0" cellspacing="0" cellpadding="0" align="center"
style="border: 1px solid #cbcfd5;-moz-border-radius: 4px;
-webkit-border-radius: 4px; border-radius: 4px;">
<tr>
<td valign="middle" align="center" bgcolor="#e5e9f0" style="background-color: #e5e9f0;
color: #000; font-family: Arial; font-size: 14px; padding: 7px;-moz-border-radius: 4px;
-webkit-border-radius: 4px; border-radius: 4px;">
<strong>New Voicemail</strong>
</td>
</tr>
<tr>
<td valign="top" style="padding: 15px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
<strong>To</strong>
</td>
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
${voicemail_name_formatted}
</td>
</tr>
<tr>
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;" width="20%">
<strong>From</strong>
</td>
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;" width="80%">
${caller_id_number}
</td>
</tr>
<!--
<tr>
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
<strong>Received</strong>
</td>
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
${message_date}
</td>
</tr>
-->
<tr>
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
<strong>Message</strong>
</td>
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
${message}
</td>
</tr>
<tr>
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
<strong>Message Text</strong>
</td>
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
${message_text}
</td>
</tr>
<tr>
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
<strong>Length</strong>
</td>
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
${message_duration}
</td>
</tr>
</table>
</td>
</tr>
</table>
</html>
@@ -66,6 +66,9 @@
if (domain_name == nil) then
domain_name = params:getHeader("variable_domain_name");
end
if (domain_name == nil) then
domain_name = params:getHeader("variable_sip_from_host");
end
purpose = params:getHeader("purpose");
profile = params:getHeader("profile");
key = params:getHeader("key");
@@ -100,4 +103,4 @@
end
if (XML_REQUEST["section"] == "languages") then
dofile(scripts_dir.."/app/xml_handler/resources/scripts/languages/languages.lua");
end
end
@@ -48,8 +48,14 @@
end
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -76,12 +82,13 @@
--get the nodes
sql = "select * from v_access_control_nodes ";
sql = sql .. "where access_control_uuid = '"..row.access_control_uuid.."' ";
sql = sql .. "where access_control_uuid = :access_control_uuid";
local params = {access_control_uuid = row.access_control_uuid}
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
x = 0;
dbh:query(sql, function(field)
dbh:query(sql, params, function(field)
if (string.len(field.node_domain) > 0) then
table.insert(xml, [[ <node type="]] .. field.node_type .. [[" domain="]] .. field.node_domain .. [[" description="]] .. field.node_description .. [["/>]]);
else
@@ -39,8 +39,8 @@
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -25,8 +25,14 @@
-- POSSIBILITY OF SUCH DAMAGE.
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -45,19 +51,20 @@
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference_control] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(field)
dbh:query(sql, function(field)
conference_control_uuid = field["conference_control_uuid"];
table.insert(xml, [[ <group name="]]..field["control_name"]..[[">]]);
--get the conference control details from the database
sql = [[SELECT * FROM v_conference_control_details
WHERE conference_control_uuid = ']] .. conference_control_uuid ..[['
WHERE conference_control_uuid = :conference_control_uuid
AND control_enabled = 'true' ]];
local params = {conference_control_uuid = conference_control_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference_control] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[conference_control] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--conference_control_uuid = row["conference_control_uuid"];
--conference_control_detail_uuid = row["conference_control_detail_uuid"];
table.insert(xml, [[ <control digits="]]..row["control_digits"]..[[" action="]]..row["control_action"]..[[" data="]]..row["control_data"]..[["/>]]);
@@ -74,19 +81,20 @@
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference_profiles] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(field)
dbh:query(sql, function(field)
conference_profile_uuid = field["conference_profile_uuid"];
table.insert(xml, [[ <profile name="]]..field["profile_name"]..[[">]]);
--get the conference profile parameters from the database
sql = [[SELECT * FROM v_conference_profile_params
WHERE conference_profile_uuid = ']] .. conference_profile_uuid ..[['
WHERE conference_profile_uuid = :conference_profile_uuid
AND profile_param_enabled = 'true' ]];
local params = {conference_profile_uuid = conference_profile_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference_profiles] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[conference_profiles] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--conference_profile_uuid = row["conference_profile_uuid"];
--conference_profile_param_uuid = row["conference_profile_param_uuid"];
--profile_param_description = row["profile_param_description"];
@@ -38,8 +38,16 @@
--set the cache
if (XML_STRING == "-ERR NOT FOUND" or XML_STRING == "-ERR CONNECTION FAILURE") then
--required includes
local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings"
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--set the sound prefix
sound_prefix = sounds_dir.."/${default_language}/${default_dialect}/${default_voice}/";
--connect to the database
local dbh = Database.new('system');
@@ -48,14 +56,15 @@
assert(dbh:connected());
--get the ivr menu from the database
sql = [[SELECT * FROM v_ivr_menus
WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[['
local sql = [[SELECT * FROM v_ivr_menus
WHERE ivr_menu_uuid = :ivr_menu_uuid
AND ivr_menu_enabled = 'true' ]];
local params = {ivr_menu_uuid = ivr_menu_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
domain_uuid = row["domain_uuid"];
ivr_menu_name = row["ivr_menu_name"];
ivr_menu_extension = row["ivr_menu_extension"];
@@ -105,13 +114,14 @@
if not file_exists(path) then
local sql = "SELECT recording_base64 FROM v_recordings " ..
"WHERE domain_uuid = '" .. domain_uuid .. "' " ..
"AND recording_filename = '" .. name .. "' "
"WHERE domain_uuid = :domain_uuid " ..
"AND recording_filename = :name "
local params = {domain_uuid = domain_uuid, name = name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--get full path to recording
is_base64, name = true, path
@@ -167,10 +177,10 @@
--greet short
if (string.len(ivr_menu_greet_short) > 1) then
if (not ivr_menu_greet_short_is_base64 and not file_exists(ivr_menu_greet_short)) then
if (file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_long)) then
ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_long;
elseif (file_exists(sounds_dir.."/en/us/callie/8000/"..ivr_menu_greet_long)) then
ivr_menu_greet_short = sounds_dir.."/${default_language}/${default_dialect}/${default_voice}/"..ivr_menu_greet_long;
if (file_exists(recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_short)) then
ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..ivr_menu_greet_short;
elseif (file_exists(sounds_dir.."/en/us/callie/8000/"..ivr_menu_greet_short)) then
ivr_menu_greet_short = sounds_dir.."/${default_language}/${default_dialect}/${default_voice}/"..ivr_menu_greet_short;
end
end
else
@@ -221,19 +231,13 @@
table.insert(xml, [[ digit-len="]]..ivr_menu_digit_len..[[" ]]);
table.insert(xml, [[ >]]);
--direct dial
if (ivr_menu_direct_dial == "true") then
table.insert(xml, [[<entry action="menu-exec-app" digits="/^(\d{2,11})$/" param="set ${cond(${user_exists id $1 ]]..domain_name..[[} == true ? user_exists=true : user_exists=false)}" description="direct dial"/>\n]]);
table.insert(xml, [[<entry action="menu-exec-app" digits="/^(\d{2,11})$/" param="playback ${cond(${user_exists} == true ? ivr/ivr-call_being_transferred.wav : ivr/ivr-that_was_an_invalid_entry.wav)}" description="direct dial"/>\n]]);
table.insert(xml, [[<entry action="menu-exec-app" digits="/^(\d{2,11})$/" param="transfer ${cond(${user_exists} == true ? $1 XML ]]..domain_name..[[ : ]]..ivr_menu_extension..[[ XML ]]..domain_name..[[)}" description="direct dial"/>\n]]);
end
--get the ivr menu options
sql = [[SELECT * FROM v_ivr_menu_options WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' ORDER BY ivr_menu_option_order asc ]];
local sql = [[SELECT * FROM v_ivr_menu_options WHERE ivr_menu_uuid = :ivr_menu_uuid ORDER BY ivr_menu_option_order asc ]];
local params = {ivr_menu_uuid = ivr_menu_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(r)
dbh:query(sql, params, function(r)
ivr_menu_option_digits = r.ivr_menu_option_digits
ivr_menu_option_action = r.ivr_menu_option_action
ivr_menu_option_param = r.ivr_menu_option_param
@@ -241,6 +245,13 @@
table.insert(xml, [[ <entry action="]]..ivr_menu_option_action..[[" digits="]]..ivr_menu_option_digits..[[" param="]]..ivr_menu_option_param..[[" description="]]..ivr_menu_option_description..[["/>]]);
end);
--direct dial
if (ivr_menu_direct_dial == "true") then
table.insert(xml, [[ <entry action="menu-exec-app" digits="/^(\d{2,11})$/" param="set ${cond(${user_exists id $1 ]]..domain_name..[[} == true ? user_exists=true : user_exists=false)}" description="direct dial"/>\n]]);
table.insert(xml, [[ <entry action="menu-exec-app" digits="/^(\d{2,11})$/" param="playback ${cond(${user_exists} == true ? ]]..sound_prefix..[[ivr/ivr-call_being_transferred.wav : ]]..sound_prefix..[[ivr/ivr-that_was_an_invalid_entry.wav)}" description="direct dial"/>\n]]);
table.insert(xml, [[ <entry action="menu-exec-app" digits="/^(\d{2,11})$/" param="transfer ${cond(${user_exists} == true ? $1 XML ]]..domain_name..[[ : ]]..ivr_menu_extension..[[ XML ]]..domain_name..[[)}" description="direct dial"/>\n]]);
end
--close the extension tag if it was left open
table.insert(xml, [[ </menu>]]);
table.insert(xml, [[ </menus>]]);
@@ -257,7 +268,7 @@
--freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}"));
--set the cache
result = trim(api:execute("memcache", "set configuration:ivr.conf:".. ivr_menu_uuid .." '"..XML_STRING:gsub("'", "&#39;").."' ".."expire['ivr.conf']"));
result = trim(api:execute("memcache", "set configuration:ivr.conf:".. ivr_menu_uuid .." '"..XML_STRING:gsub("'", "&#39;").."' "..expire['ivr']));
--send the xml to the console
if (debug["xml_string"]) then
@@ -1,7 +1,7 @@
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -41,8 +41,14 @@
end
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -52,11 +58,12 @@
--get the domain_uuid
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
sql = sql .. "WHERE domain_name = :domain_name";
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(rows)
dbh:query(sql, params, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
@@ -88,14 +95,15 @@
sql = sql .. "from v_sip_profiles as p, v_sip_profile_settings as s ";
sql = sql .. "where s.sip_profile_setting_enabled = 'true' ";
sql = sql .. "and p.sip_profile_enabled = 'true' ";
sql = sql .. "and (p.sip_profile_hostname = '" .. hostname.. "' or p.sip_profile_hostname is null or p.sip_profile_hostname = '') ";
sql = sql .. "and (p.sip_profile_hostname = :hostname or p.sip_profile_hostname is null or p.sip_profile_hostname = '') ";
sql = sql .. "and p.sip_profile_uuid = s.sip_profile_uuid ";
sql = sql .. "order by p.sip_profile_name asc ";
local params = {hostname = hostname};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
end
x = 0;
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--set as variables
sip_profile_name = row.sip_profile_name;
--sip_profile_description = row.sip_profile_description;
@@ -117,19 +125,20 @@
--get the gateways
if (domain_count > 1) then
sql = "select * from v_gateways as g, v_domains as d ";
sql = sql .. "where g.profile = '"..sip_profile_name.."' ";
sql = sql .. "where g.profile = :profile ";
sql = sql .. "and g.enabled = 'true' ";
sql = sql .. "and (g.domain_uuid = d.domain_uuid or g.domain_uuid is null) ";
else
sql = "select * from v_gateways as g ";
sql = sql .. "where g.enabled = 'true' and g.profile = '"..sip_profile_name.."' ";
sql = sql .. "where g.enabled = 'true' and g.profile = :profile ";
end
sql = sql .. "and (g.hostname = '" .. hostname.. "' or g.hostname is null or g.hostname = '') ";
sql = sql .. "and (g.hostname = :hostname or g.hostname is null or g.hostname = '') ";
local params = {profile = sip_profile_name, hostname = hostname};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
x = 0;
dbh:query(sql, function(field)
dbh:query(sql, params, function(field)
table.insert(xml, [[ <gateway name="]] .. string.lower(field.gateway_uuid) .. [[">]]);
if (string.len(field.username) > 0) then
@@ -24,6 +24,7 @@
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--includes
local cache = require"resources.functions.cache"
local log = require"resources.functions.log"["xml_handler"]
@@ -47,8 +48,14 @@
if not XML_STRING then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -89,9 +96,9 @@
--get the dialplan and related details
sql = "select * from v_dialplans as p, v_dialplan_details as s ";
if (call_context == "public" or string.sub(call_context, 0, 7) == "public@" or string.sub(call_context, -7) == ".public") then
sql = sql .. "where p.dialplan_context = '" .. call_context .. "' ";
sql = sql .. "where p.dialplan_context = :call_context ";
else
sql = sql .. "where (p.dialplan_context = '" .. call_context .. "' or p.dialplan_context = '${domain_name}') ";
sql = sql .. "where (p.dialplan_context = :call_context or p.dialplan_context = '${domain_name}') ";
end
sql = sql .. "and p.dialplan_enabled = 'true' ";
sql = sql .. "and p.dialplan_uuid = s.dialplan_uuid ";
@@ -106,14 +113,15 @@
sql = sql .. "WHEN 'anti-action' THEN 3 ";
sql = sql .. "ELSE 100 END, ";
sql = sql .. "s.dialplan_detail_order asc ";
if (debug["sql"]) then
log.notice("SQL: " .. sql);
end
local x = 0;
local pass
dbh:query(sql, function(row)
local pass;
local params = {call_context = call_context};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[dialplan] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
--clear flag pass
pass = false
pass = false;
--get the dialplan
domain_uuid = row.domain_uuid;
@@ -3,6 +3,12 @@
local log = require "resources.functions.log"["directory_acl"]
local dbh = Database.new('system')
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--build the xml
local xml = {}
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]])
@@ -13,18 +19,19 @@
local sql = "SELECT * FROM v_domains as d, v_extensions as e "
sql = sql .. "where d.domain_uuid = e.domain_uuid and e.cidr is not null and e.cidr <> '' "
if domain_name then
sql = sql .. "and d.domain_name = '"..domain_name.."' "
sql = sql .. "and d.domain_name = :domain_name "
else
sql = sql .. "order by d.domain_name"
end
local params = {domain_name = domain_name}
if debug['sql'] then
log.noticef("SQL - %s", sql)
log.noticef("SQL: %s; params: %s", sql, json.encode(params))
end
local prev_domain_name
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
if prev_domain_name ~= row.domain_name then
if prev_domain_name then
table.insert(xml, [[ </users>]])
@@ -1,8 +1,15 @@
--connect to the database
local Database = require "resources.functions.database"
local log = require "resources.functions.log"["directory_dir"]
local dbh = Database.new('system')
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--build the xml
local xml = {}
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]])
@@ -11,16 +18,17 @@
--process when the sip profile is rescanned, sofia is reloaded, or sip redirect
local sql = "SELECT * FROM v_domains as d, v_extensions as e "
sql = sql .. "where d.domain_uuid = e.domain_uuid and "
sql = sql .. "(e.directory_visible = 'true' or e.directory_exten_visible='true') "
sql = sql .. "where d.domain_uuid = e.domain_uuid "
sql = sql .. "and (e.directory_visible = 'true' or e.directory_exten_visible='true') "
if domain_name then
sql = sql .. "and d.domain_name = '"..domain_name.."' "
sql = sql .. "and d.domain_name = :domain_name "
else
sql = sql .. "order by d.domain_name"
sql = sql .. "order by d.domain_name "
end
local sql_params = {domain_name = domain_name}
if debug['sql'] then
log.noticef("SQL - %s", sql)
log.noticef("SQL: %s; params: %s", sql, json.encode(sql_params))
end
-- export this params
@@ -37,7 +45,7 @@
local prev_domain_name
dbh:query(sql, function(row)
dbh:query(sql, sql_params, function(row)
if prev_domain_name ~= row.domain_name then
if prev_domain_name then
table.insert(xml, [[ </users>]])
@@ -25,8 +25,8 @@
-- POSSIBILITY OF SUCH DAMAGE.
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -36,7 +36,7 @@
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
table.insert(xml, [[<document type="freeswitch/xml">]]);
table.insert(xml, [[ <section name="directory">]]);
sql = "SELECT domain_name FROM v_domains ";
local sql = "SELECT domain_name FROM v_domains ";
dbh:query(sql, function(row)
table.insert(xml, [[ <domain name="]]..row.domain_name..[[" />]]);
end);
@@ -34,8 +34,14 @@
--set the cache
if (XML_STRING == "-ERR NOT FOUND") then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
local dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -44,28 +50,35 @@
if (domain_uuid == nil) then
--get the domain_uuid
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
local sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = :domain_name ";
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(rows)
dbh:query(sql, params, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
end
if not domain_uuid then
freeswitch.consoleLog("warning", "[xml_handler] Can not find domain name: " .. tostring(domain_name) .. "\n");
return
end
--build the call group array
sql = [[
local sql = [[
select * from v_extensions
where domain_uuid = ']]..domain_uuid..[['
where domain_uuid = :domain_uuid
order by call_group asc
]];
local params = {domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
end
call_group_array = {};
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
call_group = row['call_group'];
--call_group = str_replace(";", ",", call_group);
tmp_array = explode(",", call_group);
@@ -31,22 +31,32 @@
--group_call - call group has been called
--user_call - user has been called
--get logger
local log = require "resources.functions.log".xml_handler;
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
--get the domain_uuid
if (domain_uuid == nil and domain_name ~= nil) then
if (domain_uuid == nil) then
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
local sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = :domain_name ";
local params = {domain_name = domain_name}
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
log.noticef("SQL: %s; params %s", sql, json.encode(params));
end
status = dbh:query(sql, function(rows)
dbh:query(sql, params, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
@@ -54,11 +64,14 @@
--get the extension information
if (domain_uuid ~= nil) then
sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and (extension = '" .. user .. "' or number_alias = '" .. user .. "') and enabled = 'true' ";
local sql = "SELECT * FROM v_extensions WHERE domain_uuid = :domain_uuid "
.. "and (extension = :user or number_alias = :user) "
.. "and enabled = 'true' ";
local params = {domain_uuid=domain_uuid, user=user};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
log.noticef("SQL: %s; params %s", sql, json.encode(params));
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--general
domain_uuid = row.domain_uuid;
extension_uuid = row.extension_uuid;
@@ -83,7 +96,7 @@
table.insert(xml, [[<document type="freeswitch/xml">]]);
table.insert(xml, [[ <section name="directory">]]);
table.insert(xml, [[ <domain name="]] .. domain_name .. [[" alias="true">]]);
table.insert(xml, [[ <user id="]] .. extension .. [[">]]);
table.insert(xml, [[ <user id="]] .. extension .. [["]] .. number_alias .. [[>]]);
table.insert(xml, [[ <params>]]);
table.insert(xml, [[ <param name="reverse-auth-user" value="]] .. extension .. [["/>]]);
table.insert(xml, [[ <param name="reverse-auth-pass" value="]] .. password .. [["/>]]);
@@ -1,6 +1,6 @@
-- xml_handler.lua
-- Part of FusionPBX
-- Copyright (C) 2013 - 2015 Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2013 - 2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,12 @@
number_alias_string = "";
vm_mailto = "";
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
-- event source
local event_calling_function = params:getHeader("Event-Calling-Function")
local event_calling_file = params:getHeader("Event-Calling-File")
@@ -70,26 +76,63 @@
--all other directory actions: sip_auth, user_call
--except for the action: group_call
-- Do we need use proxy to make call to ext. reged on different FS
-- true - send call to FS where ext reged
-- false - send call directly to ext
local USE_FS_PATH = xml_handler and xml_handler["fs_path"]
-- Make sance only for extensions with number_alias
-- false - you should register with AuthID=UserID=Extension (default)
-- true - you should register with AuthID=Extension and UserID=Number Alias
-- also in this case you need 2 records in memcache for one extension
local DIAL_STRING_BASED_ON_USERID = xml_handler and xml_handler["reg_as_number_alias"]
-- Use number as presence_id
-- When you have e.g. extension like `user-100` with number-alias `100`
-- by default presence_id is `user-100`. This option allow use `100` as presence_id
local NUMBER_AS_PRESENCE_ID = xml_handler and xml_handler["number_as_presence_id"]
local sip_auth_method = params:getHeader("sip_auth_method")
if sip_auth_method then
sip_auth_method = sip_auth_method:upper();
end
-- Get UserID. If used UserID ~= AuthID then we have to disable `inbound-reg-force-matching-username`
-- on sofia profile and check UserID=Number-Alias and AuthID=Extension on register manually.
-- But in load balancing mode in proxy INVITE we have UserID equal to origin UserID but
-- AuthID equal to callee AuthID. (e.g. 105 call to 100 and one FS forward call to other FS
-- then we have UserID=105 but AuthID=100).
-- Because we do not verify source of INVITE (FS or user device) we have to accept any UserID
-- for INVITE in such mode. So we just substitute correct UserID for check.
-- !!! NOTE !!! do not change USE_FS_PATH before this check.
local from_user = params:getHeader("sip_from_user")
if USE_FS_PATH and sip_auth_method == 'INVITE' then
from_user = user
end
-- Check eather we need build dial-string. Before request dial-string FusionPBX set `dialed_extension`
-- variable. So if we have no such variable we do not need build dial-string.
dialed_extension = params:getHeader("dialed_extension");
if (dialed_extension == nil) then
-- freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is null\n");
USE_FS_PATH = false;
else
-- freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is " .. dialed_extension .. "\n");
end
-- verify from_user and number alias for this methods
local METHODS = {
-- _ANY_ = true,
REGISTER = true,
-- INVITE = true,
}
if (user == nil) then
user = "";
end
--get the cache
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
if (domain_name) then
XML_STRING = trim(api:execute("memcache", "get directory:" .. user .. "@" .. domain_name));
end
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
source = "database";
continue = true;
else
source = "cache";
continue = true;
end
else
XML_STRING = "";
source = "database";
continue = true;
if (from_user == "") or (from_user == nil) then
from_user = user
end
--prevent processing for invalid user
@@ -98,27 +141,58 @@
continue = false;
end
-- cleanup
XML_STRING = nil;
-- get the cache. We can use cache only if we do not use `fs_path`
-- or we do not need dial-string. In other way we have to use database.
if (continue) and (not USE_FS_PATH) then
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
if (domain_name) then
local key = "directory:" .. (from_user or user) .. "@" .. domain_name
XML_STRING = trim(api:execute("memcache", "get " .. key));
if debug['cache'] then
if XML_STRING:sub(1, 4) == '-ERR' then
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] get key: " .. key .. " fail: " .. XML_STRING .. "\n")
else
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] get key: " .. key .. " pass!" .. "\n")
end
end
else
XML_STRING = "-ERR NOT FOUND"
end
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
source = "database";
continue = true;
else
source = "cache";
continue = true;
end
else
XML_STRING = "";
source = "database";
continue = true;
end
end
--show the params in the console
--if (params:serialize() ~= nil) then
-- freeswitch.consoleLog("notice", "[xml_handler-directory.lua] Params:\n" .. params:serialize() .. "\n");
--end
--set the variable from the params
dialed_extension = params:getHeader("dialed_extension");
if (dialed_extension == nil) then
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is null\n");
xml_handler["fs_path"] = false;
else
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is " .. dialed_extension .. "\n");
end
local loaded_from_db = false
--build the XML string from the database
if (source == "database") or (xml_handler["fs_path"]) then
if (source == "database") or (USE_FS_PATH) then
loaded_from_db = true
--include Database class
local Database = require "resources.functions.database";
--database connection
if (continue) then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
dbh = Database.new('system');
--exits the script if we didn't connect properly
assert(dbh:connected());
@@ -127,12 +201,13 @@
if (domain_uuid == nil) then
--get the domain_uuid
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
local sql = "SELECT domain_uuid FROM v_domains "
.. "WHERE domain_name = :domain_name ";
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(rows)
dbh:query(sql, params, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
@@ -146,13 +221,17 @@
--if load balancing is set to true then get the hostname
if (continue) then
if (xml_handler["fs_path"]) then
if (USE_FS_PATH) then
--get the domain_name from domains
if (domain_name == nil) then
sql = "SELECT domain_name FROM v_domains ";
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "' ";
status = dbh:query(sql, function(row)
local sql = "SELECT domain_name FROM v_domains "
.. "WHERE domain_uuid = :domain_uuid ";
local params = {domain_uuid = domain_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
domain_name = row["domain_name"];
end);
end
@@ -165,33 +244,37 @@
require "resources.functions.file_exists";
--connect to the switch database
if (file_exists(database_dir.."/core.db")) then
--dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite
dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db");
else
require "resources.functions.database_handle";
dbh_switch = database_handle('switch');
dbh_switch = Database.new('switch');
--get register name
local reg_user = dialed_extension
if not DIAL_STRING_BASED_ON_USERID then
reg_user = trim(api:execute("user_data", dialed_extension .. "@" .. domain_name .. " attr id"));
end
--get the destination hostname from the registration
sql = "SELECT hostname FROM registrations ";
sql = sql .. "WHERE reg_user = '"..dialed_extension.."' ";
sql = sql .. "AND realm = '"..domain_name.."' ";
local params = {reg_user=reg_user, domain_name=domain_name}
local sql = "SELECT hostname FROM registrations "
.. "WHERE reg_user = :reg_user "
.. "AND realm = :domain_name ";
if (database["type"] == "mysql") then
now = os.time();
sql = sql .. "AND expires > "..now;
params.now = os.time();
sql = sql .. "AND expires > :now ";
else
sql = sql .. "AND to_timestamp(expires) > NOW()";
sql = sql .. "AND to_timestamp(expires) > NOW() ";
end
status = dbh_switch:query(sql, function(row)
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh_switch:query(sql, params, function(row)
database_hostname = row["hostname"];
end);
--freeswitch.consoleLog("notice", "[xml_handler] sql: " .. sql .. "\n");
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] database_hostname is " .. database_hostname .. "\n");
--hostname was not found set xml_handler["fs_path"] to false to prevent a database_hostname concatenation error
--hostname was not found set USE_FS_PATH to false to prevent a database_hostname concatenation error
if (database_hostname == nil) then
xml_handler["fs_path"] = false;
USE_FS_PATH = false;
end
--close the database connection
@@ -201,12 +284,15 @@
--get the extension from the database
if (continue) then
sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and (extension = '" .. user .. "' or number_alias = '" .. user .. "') and enabled = 'true' ";
local sql = "SELECT * FROM v_extensions WHERE domain_uuid = :domain_uuid "
.. "and (extension = :user or number_alias = :user) "
.. "and enabled = 'true' ";
local params = {domain_uuid=domain_uuid, user=user};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
continue = false;
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--general
continue = true;
domain_uuid = row.domain_uuid;
@@ -265,30 +351,48 @@
do_not_disturb = row.do_not_disturb;
-- check matching UserID and AuthName
if sip_auth_method then
local check_from_number = METHODS[sip_auth_method] or METHODS._ANY_
if DIAL_STRING_BASED_ON_USERID then
continue = (sip_from_user == user) and ((not check_from_number) or (from_user == sip_from_number))
else
continue = (sip_from_user == user) and ((not check_from_number) or (from_user == user))
end
if not continue then
XML_STRING = nil;
return 1;
end
end
--set the presence_id
presence_id = (NUMBER_AS_PRESENCE_ID and sip_from_number or sip_from_user) .. "@" .. domain_name;
--set the dial_string
if (string.len(row.dial_string) > 0) then
dial_string = row.dial_string;
else
local destination = (DIAL_STRING_BASED_ON_USERID and sip_from_number or sip_from_user) .. "@" .. domain_name;
--set a default dial string
if (dial_string == null) then
dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. extension .. "@" .. domain_name .. ")}";
dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. presence_id .. "}${sofia_contact(" .. destination .. ")}";
end
--set the an alternative dial string if the hostnames don't match
if (xml_handler["fs_path"]) then
if (USE_FS_PATH) then
if (local_hostname == database_hostname) then
freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_host and database_host are the same\n");
else
--sofia/internal/${user_data(${destination_number}@${domain_name} attr id)}@${domain_name};fs_path=sip:server
user_id = trim(api:execute("user_data", user .. "@" .. domain_name .. " attr id"));
dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. user .. "@" .. domain_name .. "}sofia/internal/" .. user_id .. "@" .. domain_name .. ";fs_path=sip:" .. database_hostname;
local profile, proxy = "internal", database_hostname;
dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. presence_id .."}sofia/" .. profile .. "/" .. destination .. ";fs_path=sip:" .. proxy;
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dial_string " .. dial_string .. "\n");
end
else
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] seems balancing is false??" .. tostring(xml_handler["fs_path"]) .. "\n");
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] seems balancing is false??" .. tostring(USE_FS_PATH) .. "\n");
end
--show debug informationa
if (xml_handler["fs_path"]) then
if (USE_FS_PATH) then
freeswitch.consoleLog("notice", "[xml_handler] local_hostname: " .. local_hostname.. " database_hostname: " .. database_hostname .. " dial_string: " .. dial_string .. "\n");
end
end
@@ -298,15 +402,17 @@
--get the voicemail from the database
if (continue) then
vm_enabled = "true";
if tonumber(user) == nil then
sql = "SELECT * FROM v_voicemails WHERE domain_uuid = '" .. domain_uuid .. "' and voicemail_id = '" .. number_alias .. "' ";
local sql = "SELECT * FROM v_voicemails WHERE domain_uuid = :domain_uuid and voicemail_id = :voicemail_id ";
local params = {domain_uuid = domain_uuid};
if number_alias and #number_alias > 0 then
params.voicemail_id = number_alias;
else
sql = "SELECT * FROM v_voicemails WHERE domain_uuid = '" .. domain_uuid .. "' and voicemail_id = '" .. user .. "' ";
params.voicemail_id = user;
end
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
if (string.len(row.voicemail_enabled) > 0) then
vm_enabled = row.voicemail_enabled;
end
@@ -389,6 +495,7 @@
table.insert(xml, [[ <variable name="call_timeout" value="]] .. call_timeout .. [["/>]]);
table.insert(xml, [[ <variable name="caller_id_name" value="]] .. sip_from_user .. [["/>]]);
table.insert(xml, [[ <variable name="caller_id_number" value="]] .. sip_from_number .. [["/>]]);
table.insert(xml, [[ <variable name="presence_id" value="]] .. presence_id .. [["/>]]);
if (string.len(call_group) > 0) then
table.insert(xml, [[ <variable name="call_group" value="]] .. call_group .. [["/>]]);
end
@@ -517,14 +624,26 @@
dbh:release();
--set the cache
if (user and domain_name) then
result = trim(api:execute("memcache", "set directory:" .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "&#39;").."' "..expire["directory"]));
local key = "directory:" .. sip_from_number .. "@" .. domain_name
if debug['cache'] then
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] set key: " .. key .. "\n")
end
result = trim(api:execute("memcache", "set " .. key .. " '"..XML_STRING:gsub("'", "&#39;").."' "..expire["directory"]));
if sip_from_number ~= sip_from_user then
key = "directory:" .. sip_from_user .. "@" .. domain_name
if debug['cache'] then
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] set key: " .. key .. "\n")
end
result = trim(api:execute("memcache", "set " .. key .. " '"..XML_STRING:gsub("'", "&#39;").."' "..expire["directory"]));
end
--save to the conf directory
--local file = assert(io.open(conf_dir .. "/directory/" .. user .. "@" .. domain_name .. ".xml.cache", "w"));
--file:write(XML_STRING);
--file:close();
--send the xml to the console
if (debug["xml_string"]) then
local file = assert(io.open(temp_dir .. "/" .. user .. "@" .. domain_name .. ".xml", "w"));
file:write(XML_STRING);
file:close();
end
--send to the console
if (debug["cache"]) then
@@ -533,10 +652,22 @@
end
end
--disable registration for number-alias
if (params:getHeader("sip_auth_method") == "REGISTER") then
if (api:execute("user_data", user .. "@" .. domain_name .." attr id") ~= user) then
if XML_STRING and (not loaded_from_db) and sip_auth_method then
local user_id = api:execute("user_data", from_user .. "@" .. domain_name .." attr id")
if user_id ~= user then
XML_STRING = nil;
elseif METHODS[sip_auth_method] or METHODS._ANY_ then
local alias
if DIAL_STRING_BASED_ON_USERID then
alias = api:execute("user_data", from_user .. "@" .. domain_name .." attr number-alias")
end
if alias and #alias > 0 then
if from_user ~= alias then
XML_STRING = nil
end
elseif from_user ~= user_id then
XML_STRING = nil;
end
end
end
@@ -67,29 +67,35 @@
--build the XML string from the database
if (source == "database") then
--database connection
--connect to the database
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
--get the domain_uuid
if (continue) then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
--exits the script if we didn't connect properly
assert(dbh:connected());
--get the domain_uuid
if (domain_uuid == nil) then
--get the domain_uuid
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(rows)
domain_uuid = rows["domain_uuid"];
end);
if (domain_uuid == nil) then
--get the domain_uuid
if (domain_name ~= nil) then
local sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = :domain_name ";
local params = {domain_name = domain_name};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
end
dbh:query(sql, params, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
end
end
--prevent processing for invalid domains
@@ -113,20 +119,21 @@
table.insert(xml, [[ <phrases>]]);
table.insert(xml, [[ <macros>]]);
sql = "SELECT * FROM v_phrases as p, v_phrase_details as d ";
sql = sql .. "WHERE d.domain_uuid = '" .. domain_uuid .. "' ";
sql = sql .. "AND p.phrase_uuid = '".. macro_name .."' ";
sql = sql .. "AND p.phrase_language = '".. language .."' ";
local sql = "SELECT * FROM v_phrases as p, v_phrase_details as d ";
sql = sql .. "WHERE d.domain_uuid = :domain_uuid ";
sql = sql .. "AND p.phrase_uuid = :macro_name ";
sql = sql .. "AND p.phrase_language = :language ";
sql = sql .. "AND p.phrase_uuid = d.phrase_uuid ";
sql = sql .. "AND p.phrase_enabled = 'true' ";
sql = sql .. "ORDER BY d.domain_uuid, p.phrase_uuid, d.phrase_detail_order ASC ";
local params = {domain_uuid = domain_uuid, macro_name = macro_name, language = language};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
end
previous_phrase_uuid = "";
match_tag = "open";
x = 0;
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
--phrase_uuid,domain_uuid,phrase_name,phrase_language
--phrase_description,phrase_enabled,phrase_detail_uuid
--phrase_detail_group,phrase_detail_tag,phrase_detail_pattern
+17 -7
View File
@@ -37,6 +37,12 @@
local file = require "resources.functions.file"
local log = require "resources.functions.log".call_flow
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--connect to the database
local dbh = Database.new('system');
@@ -72,14 +78,15 @@ local function find_file(dbh, domain_name, domain_uuid, file_name)
local storage_type = settings:get('recordings', 'storage_type', 'text') or ''
if storage_type == 'base64' then
local sql = "SELECT recording_base64 FROM v_recordings "
.. "WHERE domain_uuid = '" .. domain_uuid .."'"
.. "AND recording_filename = '".. file_name.. "' "
.. "WHERE domain_uuid = :domain_uuid"
.. "AND recording_filename = :file_name "
local params = {domain_uuid = domain_uuid, file_name = file_name};
if (debug["sql"]) then
log.notice("SQL: " .. sql)
log.notice("SQL: " .. sql .. "; params: " .. json.encode(params))
end
local dbh = Database.new('system', 'base64/read')
local recording_base64 = dbh:first_value(sql);
local recording_base64 = dbh:first_value(sql, params);
dbh:release();
if recording_base64 and #recording_base64 > 32 then
@@ -149,11 +156,12 @@ if (session:ready()) then
local default_voice = session:getVariable("default_voice") or 'callie';
--get the extension list
local sql = "SELECT * FROM v_call_flows where call_flow_uuid = '"..call_flow_uuid.."'"
local sql = "SELECT * FROM v_call_flows where call_flow_uuid = :call_flow_uuid"
-- .. "and call_flow_enabled = 'true'"
local params = {call_flow_uuid = call_flow_uuid};
--log.notice("SQL: %s", sql);
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
call_flow_name = row.call_flow_name;
call_flow_extension = row.call_flow_extension;
call_flow_feature_code = row.call_flow_feature_code;
@@ -210,7 +218,9 @@ if (session:ready()) then
log.noticef("label=%s,status=%s,uuid=%s,audio=%s", active_flow_label, toggle, call_flow_uuid, audio_file)
--store in database
dbh:query("UPDATE v_call_flows SET call_flow_status = '"..toggle.."' WHERE call_flow_uuid = '"..call_flow_uuid.."'");
dbh:query("UPDATE v_call_flows SET call_flow_status = :toggle WHERE call_flow_uuid = :call_flow_uuid", {
toggle = toggle, call_flow_uuid = call_flow_uuid
});
--answer
session:answer();
@@ -38,7 +38,7 @@
require "resources.functions.file_exists";
require "resources.functions.mkdir";
require "resources.functions.database_handle";
local Database = require "resources.functions.database";
local log = require "resources.functions.log".call_flow_monitor
@@ -78,7 +78,7 @@
end
--connect to the database
local dbh = database_handle('system');
local dbh = Database.new('system');
--get the extension list
if dbh:connected() then
+88 -80
View File
@@ -37,24 +37,18 @@
--include config.lua
require "resources.functions.config";
--include config.lua
require "resources.functions.settings";
require "resources.functions.channel_utils";
local log = require "resources.functions.log".call_forward
local cache = require "resources.functions.cache"
local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings"
local route_to_bridge = require "resources.functions.route_to_bridge"
local function opt(t, ...)
if select('#', ...) == 0 then
return t
end
if type(t) ~= 'table' then
return nil
end
return opt(t[...], select(2, ...))
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
local function empty(t)
@@ -86,7 +80,7 @@
session:sleep(1000);
--connect to the database
dbh = Database.new('system');
local dbh = Database.new('system');
--request id is true
if (request_id == "true") then
@@ -110,12 +104,13 @@
--check to see if the pin number is correct
if not session:ready() then return end
local sql = "SELECT voicemail_password FROM v_voicemails ";
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
sql = sql .. "AND voicemail_id = '" .. extension .."' ";
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
sql = sql .. "AND voicemail_id = :extension ";
local params = {domain_uuid = domain_uuid, extension = extension};
if (debug["sql"]) then
log.notice(sql);
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
local voicemail_password = dbh:first_value(sql)
local voicemail_password = dbh:first_value(sql, params)
if (voicemail_password ~= caller_pin_number) then
--access denied
session:streamFile("phrase:voicemail_fail_auth:#");
@@ -127,16 +122,19 @@
if not session:ready() then return end
local sql = "select * from v_extensions ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
sql = sql .. "where domain_uuid = :domain_uuid ";
local params = {domain_uuid = domain_uuid};
if (extension_uuid ~= nil) then
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
sql = sql .. "and extension_uuid = :extension_uuid ";
params.extension_uuid = extension_uuid;
else
sql = sql .. "and (extension = '"..extension.."' or number_alias = '"..extension.."') ";
sql = sql .. "and (extension = :extension or number_alias = :extension) ";
params.extension = extension;
end
if (debug["sql"]) then
log.notice(sql);
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
local row = dbh:first_row(sql)
local row = dbh:first_row(sql, params)
if not row then return end
extension_uuid = row.extension_uuid;
@@ -178,9 +176,13 @@
if enabled == "true" and not empty(forward_caller_id_uuid) then
local sql = "select destination_number, destination_description,"..
"destination_caller_id_number, destination_caller_id_name " ..
"from v_destinations where domain_uuid = '" .. domain_uuid .. "' and " ..
"destination_type = 'inbound' and destination_uuid = '" .. forward_caller_id_uuid .. "'";
local row = dbh:first_row(sql)
"from v_destinations where domain_uuid = :domain_uuid and " ..
"destination_type = 'inbound' and destination_uuid = :destination_uuid";
local params = {domain_uuid = domain_uuid; destination_uuid = forward_caller_id_uuid}
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
local row = dbh:first_row(sql, params)
if row then
local caller_id_number = row.destination_caller_id_number
if empty(caller_id_number) then
@@ -212,66 +214,64 @@
--used for number_alias to get the correct user
local sql = "select extension, number_alias from v_extensions ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
sql = sql .. "and number_alias = '"..forward_all_destination.."' ";
dbh:query(sql, function(row)
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and number_alias = :number_alias ";
local params = {domain_uuid = domain_uuid; number_alias = forward_all_destination}
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
dbh:query(sql, params, function(row)
destination_user = row.extension;
destination_extension = row.extension;
destination_number_alias = row.number_alias or '';
end);
local presence_id
if destination_extension then
if (#destination_number_alias > 0) and (opt(settings(domain_uuid), 'provision', 'number_as_presence_id', 'boolean') == 'true') then
presence_id = destination_number_alias
else
presence_id = destination_extension
end
elseif extension then
-- setting here presence_id equal extension not dialed number allows work BLF and intercept.
-- $presence_id = extension_presence_id($this->extension, $this->number_alias);
if (#number_alias > 0) and (opt(settings(domain_uuid), 'provision', 'number_as_presence_id', 'boolean') == 'true') then
presence_id = number_alias
else
presence_id = extension
end
else
presence_id = forward_all_destination
end
--set the dial_string
dial_string = "{presence_id="..presence_id.."@"..domain_name;
dial_string = dial_string .. ",instant_ringback=true";
dial_string = dial_string .. ",domain_uuid="..domain_uuid;
dial_string = dial_string .. ",sip_invite_domain="..domain_name;
dial_string = dial_string .. ",domain_name="..domain_name;
dial_string = dial_string .. ",domain="..domain_name;
dial_string = dial_string .. ",toll_allow='"..toll_allow.."'";
dial_string = dial_string .. ",sip_h_Diversion=<sip:"..extension.."@"..domain_name..">;reason=unconditional";
if (accountcode ~= nil) then
dial_string = dial_string .. ",accountcode="..accountcode;
end
dial_string = dial_string .. forward_caller_id
dial_string = dial_string .. "}";
if (destination_user ~= nil) then
cmd = "user_exists id ".. destination_user .." "..domain_name;
else
cmd = "user_exists id ".. forward_all_destination .." "..domain_name;
end
user_exists = trim(api:executeString(cmd));
if (user_exists == "true") then
if (destination_user ~= nil) then
dial_string = dial_string .. "user/"..destination_user.."@"..domain_name;
else
dial_string = dial_string .. "user/"..forward_all_destination.."@"..domain_name;
end
local user_exists = trim(api:executeString(cmd));
--set the dial_string
dial_string = "{instant_ringback=true";
dial_string = dial_string .. ",domain_uuid="..domain_uuid;
dial_string = dial_string .. ",sip_invite_domain="..domain_name;
dial_string = dial_string .. ",domain_name="..domain_name;
dial_string = dial_string .. ",domain="..domain_name;
dial_string = dial_string .. ",extension_uuid="..extension_uuid;
dial_string = dial_string .. ",toll_allow='"..toll_allow.."'";
dial_string = dial_string .. ",sip_h_Diversion=<sip:"..extension.."@"..domain_name..">;reason=unconditional";
if (not accountcode) or (#accountcode == 0) then
dial_string = dial_string .. ",sip_h_X-accountcode=${accountcode}";
else
local mode = opt(settings(domain_uuid), 'domain', 'bridge', 'text')
dial_string = dial_string .. ",sip_h_X-accountcode="..accountcode;
dial_string = dial_string .. ",accountcode="..accountcode;
end
dial_string = dial_string .. forward_caller_id
if (user_exists == "true") then
-- we do not need here presence_id because user dial-string already has one
dial_string = dial_string .. ",dialed_extension=" .. forward_all_destination
dial_string = dial_string .. "}"
dial_string = dial_string .. "user/"..forward_all_destination.."@"..domain_name;
else
-- setting here presence_id equal extension not dialed number allows work BLF and intercept.
local settings, presence_id = Settings.new(dbh, domain_name, domain_uuid)
if (#number_alias > 0) and (settings:get('provision', 'number_as_presence_id', 'text') == 'true') then
presence_id = number_alias
else
presence_id = extension
end
dial_string = dial_string .. ",presence_id="..presence_id.."@"..domain_name;
dial_string = dial_string .. "}";
local mode = settings:get('domain', 'bridge', 'text')
if mode == "outbound" or mode == "bridge" then
local bridge = route_to_bridge(dbh, domain_uuid, {
destination_number = forward_all_destination;
['${toll_allow}'] = toll_allow;
['${user_exists}'] = 'false';
})
if bridge and bridge.bridge then
dial_string = dial_string .. bridge.bridge
@@ -297,12 +297,13 @@
if enabled == "true" and not empty(follow_me_uuid) then
local sql = "update v_follow_me set ";
sql = sql .. "follow_me_enabled = 'false' ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and follow_me_uuid = :follow_me_uuid ";
local params = {domain_uuid = domain_uuid, follow_me_uuid = follow_me_uuid};
if (debug["sql"]) then
log.notice(sql);
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
dbh:query(sql);
dbh:query(sql, params);
end
--check the destination
@@ -315,20 +316,27 @@
do
local sql = "update v_extensions set ";
if (enabled == "true") then
sql = sql .. "forward_all_destination = '"..forward_all_destination.."', ";
sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', ";
sql = sql .. "forward_all_destination = :forward_all_destination, ";
sql = sql .. "dial_string = :dial_string, ";
sql = sql .. "do_not_disturb = 'false', ";
else
sql = sql .. "forward_all_destination = null, ";
sql = sql .. "dial_string = null, ";
end
sql = sql .. "forward_all_enabled = '"..forward_all_enabled.."' ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
sql = sql .. "forward_all_enabled = :forward_all_enabled ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and extension_uuid = :extension_uuid ";
local params = {
forward_all_destination = forward_all_destination;
dial_string = dial_string;
forward_all_enabled = forward_all_enabled;
domain_uuid = domain_uuid;
extension_uuid = extension_uuid;
}
if (debug["sql"]) then
log.notice(sql);
log.noticef("SQL: %s; params: %s", sql, json.encode(params));
end
dbh:query(sql);
dbh:query(sql, params);
end
--disconnect from database
+45 -36
View File
@@ -16,7 +16,7 @@
--
-- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2010-2014
-- Copyright (C) 2010-2016
-- the Initial Developer. All Rights Reserved.
--
-- Contributor(s):
@@ -26,9 +26,6 @@
-- add this in Inbound Routes before transfer to use it:
-- action set caller_id_name=${luarun cidlookup.lua ${uuid}}
--debug
debug["sql"] = true;
--define the trim function
require "resources.functions.trim"
@@ -71,42 +68,54 @@
--include config.lua
require "resources.functions.config";
--check if the session is ready
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
--connect to the database
local Database = require "resources.functions.database";
dbh = Database.new('system');
if (database["type"] == "mysql") then
sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts ";
elseif (database["type"] == "pgsql") then
sql = "SELECT CASE WHEN contact_name_given = '' THEN v_contacts.contact_organization ELSE v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_label || ')' END AS name FROM v_contacts ";
else
sql = "SELECT v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_type || ')' AS name FROM v_contacts ";
end
sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid ";
sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid ";
sql = sql .. "WHERE v_contact_phones.phone_number = :caller "
local params = {caller = caller}
if (database["type"] == "mysql") then
sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts ";
else
sql = "SELECT v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_type || ')' AS name FROM v_contacts ";
end
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[cidlookup] SQL: "..sql.."; params:" .. json.encode(params) .. "\n");
end
sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid ";
sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid ";
sql = sql .. "WHERE v_contact_phones.phone_number = '"..caller.."' AND v_destinations.destination_number='"..callee.."'";
dbh:query(sql, params, function(row)
name = row.name;
end);
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[cidlookup] "..sql.."\n");
end
status = dbh:query(sql, function(row)
name = row.name;
end);
if (name == nil) then
freeswitch.consoleLog("NOTICE", "[cidlookup] caller name from contacts db is nil\n");
else
freeswitch.consoleLog("NOTICE", "[cidlookup] caller name from contacts db: "..name.."\n");
end
if (name == nil) then
freeswitch.consoleLog("NOTICE", "[cidlookup] caller name from contacts db is nil\n");
else
freeswitch.consoleLog("NOTICE", "[cidlookup] caller name from contacts db: "..name.."\n");
end
--check if there is a record, if it not then use cidlookup
if ((name == nil) or (string.len(name) == 0)) then
cidlookup_exists = api:executeString("module_exists cidlookup");
if (cidlookup_exists == "true") then
name = api:executeString("cidlookup " .. caller);
end
end
--check if there is a record, if it doesnt, then use common cidlookup
if ((name == nil) or (string.len(name) == 0)) then
name = api:executeString("cidlookup " .. caller);
end
--set the caller id name
if ((name ~= nil) and (string.len(name) > 0)) then
freeswitch.consoleLog("NOTICE", "[cidlookup] uuid_setvar " .. uuid .. " caller_id_name " .. name);
api:executeString("uuid_setvar " .. uuid .. " caller_id_name " .. name);
freeswitch.consoleLog("NOTICE", "[cidlookup] uuid_setvar " .. uuid .. " caller_id_name " .. name);
api:executeString("uuid_setvar " .. uuid .. " caller_id_name " .. name);
freeswitch.consoleLog("NOTICE", "[cidlookup] uuid_setvar " .. uuid .. " effective_caller_id_name " .. name);
api:executeString("uuid_setvar " .. uuid .. " effective_caller_id_name " .. name);
freeswitch.consoleLog("NOTICE", "[cidlookup] uuid_setvar " .. uuid .. " effective_caller_id_name " .. name);
api:executeString("uuid_setvar " .. uuid .. " effective_caller_id_name " .. name);
end
@@ -28,8 +28,14 @@
require "resources.functions.config";
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--define the trim function
require "resources.functions.trim"
@@ -45,11 +51,14 @@
--caller_id_number = session:getVariable("caller_id_number");
--get the destination_number
sql = [[ SELECT * FROM v_destinations
where destination_number like '1]].. outbound_area_code ..[[%']]
freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
sql = "SELECT destination_number FROM v_destinations where destination_number like :destination_number";
local params = {destination_number = '1'.. outbound_area_code .. '%'};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
x = 0;
dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
destination_number = row.destination_number;
--destination_caller_id_name = row.destination_caller_id_name;
--destination_caller_id_number = row.destination_caller_id_number;

Some files were not shown because too many files have changed in this diff Show More