2012-06-05 01:05:41 +02:00
|
|
|
--
|
|
|
|
|
-- 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>
|
2014-04-15 20:54:03 +02:00
|
|
|
-- Copyright (C) 2010 - 2014
|
2012-06-05 01:05:41 +02:00
|
|
|
-- the Initial Developer. All Rights Reserved.
|
|
|
|
|
--
|
|
|
|
|
-- Contributor(s):
|
|
|
|
|
-- Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
|
|
|
|
|
--set default variables
|
|
|
|
|
max_tries = "3";
|
|
|
|
|
digit_timeout = "5000";
|
2013-10-30 16:15:55 +01:00
|
|
|
api = freeswitch.API();
|
2013-12-04 19:06:07 +01:00
|
|
|
|
2012-06-08 20:10:25 +02:00
|
|
|
--set the debug level
|
|
|
|
|
debug["sql"] = false;
|
|
|
|
|
debug["var"] = false;
|
2012-07-10 18:23:08 +02:00
|
|
|
db_dial_string = "";
|
|
|
|
|
db_extension_uuid = "";
|
2012-06-08 20:10:25 +02:00
|
|
|
|
2013-03-31 10:18:41 +02:00
|
|
|
--include config.lua
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.config";
|
2012-06-05 01:05:41 +02:00
|
|
|
|
|
|
|
|
--connect to the database
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.database_handle";
|
2013-04-30 01:29:46 +02:00
|
|
|
dbh = database_handle('system');
|
2012-06-05 01:05:41 +02:00
|
|
|
|
|
|
|
|
if ( session:ready() ) then
|
|
|
|
|
session:answer();
|
2013-04-18 09:30:55 +02:00
|
|
|
domain_uuid = session:getVariable("domain_uuid");
|
2012-06-05 01:05:41 +02:00
|
|
|
pin_number = session:getVariable("pin_number");
|
|
|
|
|
sounds_dir = session:getVariable("sounds_dir");
|
|
|
|
|
sip_from_user = session:getVariable("sip_from_user");
|
2012-07-12 22:24:35 +02:00
|
|
|
sip_from_host = session:getVariable("sip_from_host");
|
2012-06-08 20:10:25 +02:00
|
|
|
direction = session:getVariable("direction"); --in, out, both
|
2012-07-10 18:23:08 +02:00
|
|
|
extension = tostring(session:getVariable("extension")); --true, false
|
2015-02-06 19:51:22 +01:00
|
|
|
user_name = tostring(session:getVariable("user_name"));
|
2013-09-28 22:39:06 +02:00
|
|
|
context = session:getVariable("context");
|
2012-07-10 18:23:08 +02:00
|
|
|
dial_string = tostring(session:getVariable("dial_string"));
|
|
|
|
|
if (dial_string == "nil") then dial_string = ""; end
|
2012-06-05 01:05:41 +02:00
|
|
|
|
|
|
|
|
--set the sounds path for the language, dialect and voice
|
|
|
|
|
default_language = session:getVariable("default_language");
|
|
|
|
|
default_dialect = session:getVariable("default_dialect");
|
|
|
|
|
default_voice = session:getVariable("default_voice");
|
|
|
|
|
if (not default_language) then default_language = 'en'; end
|
|
|
|
|
if (not default_dialect) then default_dialect = 'us'; end
|
|
|
|
|
if (not default_voice) then default_voice = 'callie'; end
|
|
|
|
|
|
|
|
|
|
--get the unique_id
|
|
|
|
|
min_digits = 1;
|
|
|
|
|
max_digits = 15;
|
|
|
|
|
unique_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
|
|
|
|
|
|
2012-07-11 12:07:23 +02:00
|
|
|
--add the unique_id value to the dial_string
|
|
|
|
|
if (string.len(dial_string) > 0) then
|
|
|
|
|
dial_string = string.gsub(dial_string, '{v_unique_id}', unique_id);
|
|
|
|
|
end
|
|
|
|
|
|
2012-07-10 18:23:08 +02:00
|
|
|
--authenticate the user
|
|
|
|
|
if (pin_number) then
|
2013-10-30 00:15:20 +01:00
|
|
|
min_digits = string.len(pin_number);
|
|
|
|
|
max_digits = string.len(pin_number)+1;
|
2012-07-10 18:23:08 +02:00
|
|
|
else
|
2013-10-30 00:15:20 +01:00
|
|
|
min_digits = 1;
|
|
|
|
|
max_digits = 12;
|
2012-06-08 20:10:25 +02:00
|
|
|
end
|
2013-10-30 00:15:20 +01:00
|
|
|
caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
2012-06-05 01:05:41 +02:00
|
|
|
|
2012-07-10 18:23:08 +02:00
|
|
|
--get the dial_string, and extension_uuid
|
2014-04-15 20:54:03 +02:00
|
|
|
if (string.len(unique_id) > 0) then
|
|
|
|
|
sql = "SELECT * FROM v_extensions as e, v_domains as d ";
|
|
|
|
|
sql = sql .. "WHERE e.domain_uuid = d.domain_uuid ";
|
|
|
|
|
if (extension == "true") then
|
|
|
|
|
sql = sql .. "AND e.extension = '" .. unique_id .."' ";
|
|
|
|
|
sql = sql .. "AND e.domain_uuid = '" .. domain_uuid .."' ";
|
|
|
|
|
else
|
|
|
|
|
sql = sql .. "AND e.unique_id = '" .. unique_id .."' ";
|
|
|
|
|
end
|
|
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "sql: ".. sql .. "\n");
|
|
|
|
|
end
|
|
|
|
|
dbh:query(sql, function(row)
|
|
|
|
|
db_domain_uuid = row.domain_uuid;
|
|
|
|
|
db_extension_uuid = row.extension_uuid;
|
|
|
|
|
db_extension = row.extension;
|
|
|
|
|
db_number_alias = row.number_alias;
|
|
|
|
|
db_dial_string = row.dial_string;
|
|
|
|
|
db_dial_user = row.dial_user;
|
|
|
|
|
db_dial_domain = row.dial_domain;
|
|
|
|
|
end);
|
2012-06-08 20:10:25 +02:00
|
|
|
end
|
2012-07-10 18:23:08 +02:00
|
|
|
|
2013-09-28 22:39:06 +02:00
|
|
|
--check to see if the pin number is correct
|
2012-07-10 18:23:08 +02:00
|
|
|
if (pin_number) then
|
|
|
|
|
if (pin_number ~= caller_pin_number) then
|
|
|
|
|
--access denied
|
|
|
|
|
db_extension_uuid = "";
|
|
|
|
|
end
|
2013-09-28 22:39:06 +02:00
|
|
|
else
|
2014-04-15 20:54:03 +02:00
|
|
|
if (db_domain_uuid ~= nil) then
|
|
|
|
|
sql = "SELECT * FROM v_voicemails ";
|
|
|
|
|
sql = sql .. "WHERE domain_uuid = '" .. db_domain_uuid .."' ";
|
|
|
|
|
if (tonumber(db_extension) == nil) then
|
|
|
|
|
sql = sql .. "AND voicemail_id = '" .. db_number_alias .."' ";
|
|
|
|
|
else
|
|
|
|
|
sql = sql .. "AND voicemail_id = '" .. db_extension .."' ";
|
|
|
|
|
end
|
|
|
|
|
dbh:query(sql, function(row)
|
|
|
|
|
voicemail_password = row.voicemail_password;
|
|
|
|
|
end);
|
|
|
|
|
if (voicemail_password ~= caller_pin_number) then
|
|
|
|
|
--access denied
|
|
|
|
|
db_extension_uuid = "";
|
|
|
|
|
end
|
2013-09-28 22:39:06 +02:00
|
|
|
end
|
2012-07-10 18:23:08 +02:00
|
|
|
end
|
|
|
|
|
|
2013-09-28 22:39:06 +02:00
|
|
|
--process the request
|
2012-07-10 18:23:08 +02:00
|
|
|
if (string.len(db_extension_uuid) > 0) then
|
2012-06-08 20:10:25 +02:00
|
|
|
--add the dial string
|
|
|
|
|
if (direction == "in") then
|
2012-07-10 18:23:08 +02:00
|
|
|
if (string.len(dial_string) == 0) then
|
2012-07-12 22:24:35 +02:00
|
|
|
dial_string = [[{sip_invite_domain=]] .. sip_from_host .. [[,presence_id=]] .. sip_from_user .. [[@]] .. sip_from_host .. [[}${sofia_contact(]] .. sip_from_user .. [[@]] .. sip_from_host .. [[)}]];
|
2012-07-10 18:23:08 +02:00
|
|
|
end
|
2012-07-12 22:24:35 +02:00
|
|
|
sql = "UPDATE v_extensions SET ";
|
|
|
|
|
sql = sql .. "dial_string = '" .. dial_string .."', ";
|
|
|
|
|
sql = sql .. "dial_user = '" .. sip_from_user .."', ";
|
|
|
|
|
sql = sql .. "dial_domain = '" .. sip_from_host .."' ";
|
|
|
|
|
sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
|
|
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
2012-06-08 20:10:25 +02:00
|
|
|
end
|
2012-07-12 22:24:35 +02:00
|
|
|
dbh:query(sql);
|
|
|
|
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-saved.wav");
|
2012-06-08 20:10:25 +02:00
|
|
|
end
|
|
|
|
|
--remove the dialstring
|
|
|
|
|
if (direction == "out") then
|
|
|
|
|
--if the the dial_string has a value then clear the dial string
|
|
|
|
|
sql = "UPDATE v_extensions SET ";
|
|
|
|
|
sql = sql .. "dial_string = null, ";
|
|
|
|
|
sql = sql .. "dial_user = null, ";
|
|
|
|
|
sql = sql .. "dial_domain = null ";
|
2012-07-10 18:23:08 +02:00
|
|
|
sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
|
2012-06-08 20:10:25 +02:00
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
|
|
|
|
end
|
|
|
|
|
dbh:query(sql);
|
|
|
|
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-deleted.wav");
|
|
|
|
|
end
|
|
|
|
|
--toggle the dial string
|
|
|
|
|
if (direction == "both") then
|
2012-07-10 18:23:08 +02:00
|
|
|
if (string.len(db_dial_string) > 1) then
|
2012-06-08 20:10:25 +02:00
|
|
|
--if the the dial_string has a value then clear the dial string
|
|
|
|
|
sql = "UPDATE v_extensions SET ";
|
|
|
|
|
sql = sql .. "dial_string = null, ";
|
|
|
|
|
sql = sql .. "dial_user = null, ";
|
|
|
|
|
sql = sql .. "dial_domain = null ";
|
2012-07-10 18:23:08 +02:00
|
|
|
sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
|
2012-06-08 20:10:25 +02:00
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
|
|
|
|
end
|
|
|
|
|
dbh:query(sql);
|
|
|
|
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-deleted.wav");
|
|
|
|
|
else
|
|
|
|
|
--if the dial string is empty then set the dial string
|
2012-07-10 18:23:08 +02:00
|
|
|
if (string.len(dial_string) == 0) then
|
2012-07-12 22:24:35 +02:00
|
|
|
dial_string = [[{sip_invite_domain=]] .. sip_from_host .. [[,presence_id=]] .. sip_from_user .. [[@]] .. sip_from_host .. [[}${sofia_contact(]] .. sip_from_user .. [[@]] .. sip_from_host .. [[)}]];
|
2012-07-10 18:23:08 +02:00
|
|
|
end
|
2012-06-08 20:10:25 +02:00
|
|
|
sql = "UPDATE v_extensions SET ";
|
|
|
|
|
sql = sql .. "dial_string = '" .. dial_string .."', ";
|
|
|
|
|
sql = sql .. "dial_user = '" .. sip_from_user .."', ";
|
2012-07-12 22:24:35 +02:00
|
|
|
sql = sql .. "dial_domain = '" .. sip_from_host .."' ";
|
2012-07-10 18:23:08 +02:00
|
|
|
sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
|
2012-06-08 20:10:25 +02:00
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
|
|
|
|
end
|
|
|
|
|
dbh:query(sql);
|
|
|
|
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-saved.wav");
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-06-05 01:05:41 +02:00
|
|
|
else
|
2012-07-10 18:23:08 +02:00
|
|
|
session:streamFile("phrase:voicemail_fail_auth:#");
|
2012-06-05 01:05:41 +02:00
|
|
|
session:hangup("NORMAL_CLEARING");
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-06 19:51:22 +01:00
|
|
|
--clear the cache
|
|
|
|
|
if (user_name ~= nil) then
|
|
|
|
|
cmd = "delete directory:"..user_name.."@"..context;
|
|
|
|
|
result = api:execute("memcache", cmd);
|
|
|
|
|
if (debug["var"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] memcache ".. cmd .. "\n");
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] result: ".. result .. "\n");
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if (db_extension ~= nil) then
|
|
|
|
|
cmd = "delete directory:"..db_extension.."@"..context;
|
|
|
|
|
result = api:execute("memcache", cmd);
|
|
|
|
|
if (debug["var"]) then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] memcache ".. cmd .. "\n");
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "[dial_string] result: ".. result .. "\n");
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-06-05 01:05:41 +02:00
|
|
|
--log to the console
|
2012-06-08 20:10:25 +02:00
|
|
|
if (debug["var"]) then
|
2013-10-30 16:15:55 +01:00
|
|
|
if sip_from_host~=nil then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "sip_from_host: ".. sip_from_host .. "\n");
|
|
|
|
|
else
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "sip_from_host: NIL\n");
|
|
|
|
|
end
|
|
|
|
|
if extension_uuid~=nil then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "extension_uuid: ".. extension_uuid .. "\n");
|
|
|
|
|
else
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "extension_uuid: NIL\n");
|
|
|
|
|
end
|
|
|
|
|
if dial_string~=nil then
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "dial_string: ".. dial_string .. "\n");
|
|
|
|
|
else
|
|
|
|
|
freeswitch.consoleLog("NOTICE", "dial_string: NIL\n");
|
|
|
|
|
end
|
2012-06-08 20:10:25 +02:00
|
|
|
end
|
2012-06-05 01:05:41 +02:00
|
|
|
|
|
|
|
|
--show call variables
|
|
|
|
|
--session:execute("info", "");
|
|
|
|
|
|
2014-04-15 20:54:03 +02:00
|
|
|
end
|