diff --git a/includes/install/scripts/xml_handler.lua b/includes/install/scripts/xml_handler.lua
index fc86adea78..36ec9866c2 100644
--- a/includes/install/scripts/xml_handler.lua
+++ b/includes/install/scripts/xml_handler.lua
@@ -57,6 +57,17 @@
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
+--add the explode function
+ function explode ( seperator, str )
+ local pos, arr = 0, {}
+ for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
+ table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
+ pos = sp + 1 -- jump past current divider
+ end
+ table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
+ return arr
+ end
+
--if the params class and methods do not exist then add them to prevent errors
if (not params) then
params = {}
@@ -445,274 +456,357 @@
end --section configuration
--handle the directory
- if (XML_REQUEST["section"] == "directory" and key and user and domain_name) then
+ if (XML_REQUEST["section"] == "directory") then
--set the default
continue = true;
- --get the cache
- if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
- XML_STRING = trim(api:execute("memcache", "get " .. user .. "@" .. domain_name));
- if (XML_STRING == "-ERR NOT FOUND") then
- continue = true;
- else
- --replace the ' back to a single quote
- XML_STRING = XML_STRING:gsub("'", "'");
- continue = false;
- end
- else
- XML_STRING = "";
- continue = true;
- end
+ --get the action
+ action = params:getHeader("action");
+ --sip_auth - registration
+ --group_call - call group has been called
+ --user_call - user has been called
- --prevent processing for invalid user
- if (user == "*97") then
- continue = false;
- end
+ --determine the correction action to perform
+ if (action == "group_call") then
+ --handles action
+ --group_call
- --get the extension from the database
- if (continue) then
- sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and extension = '" .. user .. "' and enabled = 'true' ";
- if (debug["sql"]) then
- freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
- end
- dbh:query(sql, function(row)
- --general
- domain_uuid = row.domain_uuid;
- extension = row.extension;
- cidr = "";
- if (string.len(row.cidr) > 0) then
- cidr = [[ cidr="]] .. row.cidr .. [["]];
+ --build the call group array
+ sql = [[
+ select * from v_extensions
+ where domain_uuid = ']]..domain_uuid..[['
+ order by call_group asc
+ ]];
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ call_group_array = {};
+ status = dbh:query(sql, function(row)
+ call_group = row['call_group'];
+ --call_group = str_replace(";", ",", call_group);
+ tmp_array = explode(",", call_group);
+ for key,value in pairs(tmp_array) do
+ value = trim(value);
+ --freeswitch.consoleLog("notice", "[directory] Key: " .. key .. " Value: " .. value .. " " ..row['extension'] .."\n");
+ if (string.len(value) == 0) then
+
+ else
+ if (call_group_array[value] == nil) then
+ call_group_array[value] = row['extension'];
+ else
+ call_group_array[value] = call_group_array[value]..','..row['extension'];
+ end
+ end
end
- number_alias = "";
- if (string.len(row.number_alias) > 0) then
- number_alias = [[ number-alias="]] .. row.number_alias .. [["]];
- end
- --params
- password = row.password;
- vm_enabled = "true";
- if (string.len(row.vm_enabled) > 0) then
- vm_enabled = row.vm_enabled;
- end
- vm_password = row.vm_password;
- vm_attach_file = "true";
- if (string.len(row.vm_attach_file) > 0) then
- vm_attach_file = row.vm_attach_file;
- end
- vm_keep_local_after_email = "true";
- if (string.len(row.vm_keep_local_after_email) > 0) then
- vm_keep_local_after_email = row.vm_keep_local_after_email;
- end
- if (string.len(row.vm_mailto) > 0) then
- vm_mailto = row.vm_mailto;
- else
- vm_mailto = "";
- end
- mwi_account = row.mwi_account;
- auth_acl = row.auth_acl;
- --variables
- sip_from_user = row.extension;
- call_group = row.call_group;
- hold_music = row.hold_music;
- toll_allow = row.toll_allow;
- accountcode = row.accountcode;
- user_context = row.user_context;
- effective_caller_id_name = row.effective_caller_id_name;
- effective_caller_id_number = row.effective_caller_id_number;
- outbound_caller_id_name = row.outbound_caller_id_name;
- outbound_caller_id_number = row.outbound_caller_id_number;
- emergency_caller_id_number = row.emergency_caller_id_number;
- directory_full_name = row.directory_full_name;
- directory_visible = row.directory_visible;
- directory_exten_visible = row.directory_exten_visible;
- limit_max = row.limit_max;
- limit_destination = row.limit_destination;
- sip_force_contact = row.sip_force_contact;
- sip_force_expires = row.sip_force_expires;
- nibble_account = row.nibble_account;
- sip_bypass_media = row.sip_bypass_media;
+ end);
+ --for key,value in pairs(call_group_array) do
+ -- freeswitch.consoleLog("notice", "[directory] Key: " .. key .. " Value: " .. value .. "\n");
+ --end
- --set the dial_string
- if (string.len(row.dial_string) > 0) then
- dial_string = row.dial_string;
- else
- dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. user .. "@" .. domain_name .. ")}";
- end
- end);
- end
-
- --outbound hot desking - get the extension variables
- if (continue) then
- sql = "SELECT * FROM v_extensions WHERE dial_domain = '" .. domain_name .. "' and dial_user = '" .. user .. "' and enabled = 'true' ";
- if (debug["sql"]) then
- freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
- end
- dbh:query(sql, function(row)
- --variables
- extension_uuid = row.extension_uuid;
- domain_uuid = row.domain_uuid;
- sip_from_user = row.extension;
- call_group = row.call_group;
- hold_music = row.hold_music;
- toll_allow = row.toll_allow;
- accountcode = row.accountcode;
- user_context = row.user_context;
- effective_caller_id_name = row.effective_caller_id_name;
- effective_caller_id_number = row.effective_caller_id_number;
- outbound_caller_id_name = row.outbound_caller_id_name;
- outbound_caller_id_number = row.outbound_caller_id_number;
- emergency_caller_id_number = row.emergency_caller_id_number;
- directory_full_name = row.directory_full_name;
- directory_visible = row.directory_visible;
- directory_exten_visible = row.directory_exten_visible;
- limit_max = row.limit_max;
- limit_destination = row.limit_destination;
- sip_force_contact = row.sip_force_contact;
- sip_force_expires = row.sip_force_expires;
- nibble_account = row.nibble_account;
- sip_bypass_media = row.sip_bypass_media;
- end);
- end
-
- --set the xml array and then concatenate the array to a string
- if (continue and password) then
- --build the xml
+ --build the xml array
local xml = {}
table.insert(xml, [[]]);
table.insert(xml, [[]]);
table.insert(xml, [[ ]]);
table.insert(xml, [[ ]]);
- if (number_alias) then
- if (cidr) then
- table.insert(xml, [[ ]]);
- else
- table.insert(xml, [[ ]]);
- end
- else
- if (cidr) then
- table.insert(xml, [[ ]]);
- else
- table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ previous_call_group = "";
+ for key, value in pairs(call_group_array) do
+ call_group = trim(key);
+ extension_list = trim(value);
+ if (string.len(call_group) > 0) then
+ freeswitch.consoleLog("notice", "[directory] call_group: " .. call_group .. "\n");
+ freeswitch.consoleLog("notice", "[directory] extension_list: " .. extension_list .. "\n");
+ if (previous_call_group ~= call_group) then
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ extension_array = explode(",", extension_list);
+ for index,tmp_extension in pairs(extension_array) do
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ end
+ previous_call_group = call_group;
end
end
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- if (string.len(vm_mailto) > 0) then
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- end
- if (string.len(mwi_account) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(auth_acl) > 0) then
- table.insert(xml, [[ ]]);
- end
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- if (string.len(call_group) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(hold_music) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(toll_allow) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(accountcode) > 0) then
- table.insert(xml, [[ ]]);
- end
- table.insert(xml, [[ ]]);
- if (string.len(effective_caller_id_name) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(effective_caller_id_number) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(outbound_caller_id_name) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(outbound_caller_id_number) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(emergency_caller_id_number) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(directory_full_name) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(directory_visible) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(directory_exten_visible) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(limit_max) > 0) then
- table.insert(xml, [[ ]]);
- else
- table.insert(xml, [[ ]]);
- end
- if (string.len(limit_destination) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(sip_force_contact) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(sip_force_expires) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (string.len(nibble_account) > 0) then
- table.insert(xml, [[ ]]);
- end
- if (sip_bypass_media == "bypass-media") then
- table.insert(xml, [[ ]]);
- end
- if (sip_bypass_media == "bypass-media-after-bridge") then
- table.insert(xml, [[ ]]);
- end
- if (sip_bypass_media == "proxy-media") then
- table.insert(xml, [[ ]]);
- end
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
- table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
table.insert(xml, [[ ]]);
table.insert(xml, [[ ]]);
table.insert(xml, [[]]);
XML_STRING = table.concat(xml, "\n");
+ freeswitch.consoleLog("notice", "[directory] XML_STRING: \n" .. XML_STRING .. "\n");
- --set the cache
- result = trim(api:execute("memcache", "set " .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
+ else
+ --handle action
+ --all directory actions: sip_auth, user_call
+ --except for the action: group_call
- --send the xml to the console
- if (debug["xml_string"]) then
- local file = assert(io.open("/tmp/" .. user .. "@" .. domain_name .. ".xml", "w"));
- file:write(XML_STRING);
- file:close();
- end
-
- --send to the console
- if (debug["cache"]) then
- freeswitch.consoleLog("notice", "[xml_handler] directory: " .. user .. "@" .. domain_name .. " source: database\n");
- end
- else
- --send to the console
- if (debug["cache"]) then
- if (XML_STRING) then
- freeswitch.consoleLog("notice", "[xml_handler] directory: " .. user .. "@" .. domain_name .. " source: memcache \n");
+ --get the cache
+ if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
+ XML_STRING = trim(api:execute("memcache", "get " .. user .. "@" .. domain_name));
+ if (XML_STRING == "-ERR NOT FOUND") then
+ continue = true;
+ else
+ --replace the ' back to a single quote
+ XML_STRING = XML_STRING:gsub("'", "'");
+ continue = false;
end
+ else
+ XML_STRING = "";
+ continue = true;
end
- end
+
+ --prevent processing for invalid user
+ if (user == "*97") then
+ continue = false;
+ end
+
+ --get the extension from the database
+ if (continue) then
+ sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and extension = '" .. user .. "' and enabled = 'true' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ dbh:query(sql, function(row)
+ --general
+ domain_uuid = row.domain_uuid;
+ extension = row.extension;
+ cidr = "";
+ if (string.len(row.cidr) > 0) then
+ cidr = [[ cidr="]] .. row.cidr .. [["]];
+ end
+ number_alias = "";
+ if (string.len(row.number_alias) > 0) then
+ number_alias = [[ number-alias="]] .. row.number_alias .. [["]];
+ end
+ --params
+ password = row.password;
+ vm_enabled = "true";
+ if (string.len(row.vm_enabled) > 0) then
+ vm_enabled = row.vm_enabled;
+ end
+ vm_password = row.vm_password;
+ vm_attach_file = "true";
+ if (string.len(row.vm_attach_file) > 0) then
+ vm_attach_file = row.vm_attach_file;
+ end
+ vm_keep_local_after_email = "true";
+ if (string.len(row.vm_keep_local_after_email) > 0) then
+ vm_keep_local_after_email = row.vm_keep_local_after_email;
+ end
+ if (string.len(row.vm_mailto) > 0) then
+ vm_mailto = row.vm_mailto;
+ else
+ vm_mailto = "";
+ end
+ mwi_account = row.mwi_account;
+ auth_acl = row.auth_acl;
+ --variables
+ sip_from_user = row.extension;
+ call_group = row.call_group;
+ hold_music = row.hold_music;
+ toll_allow = row.toll_allow;
+ accountcode = row.accountcode;
+ user_context = row.user_context;
+ effective_caller_id_name = row.effective_caller_id_name;
+ effective_caller_id_number = row.effective_caller_id_number;
+ outbound_caller_id_name = row.outbound_caller_id_name;
+ outbound_caller_id_number = row.outbound_caller_id_number;
+ emergency_caller_id_number = row.emergency_caller_id_number;
+ directory_full_name = row.directory_full_name;
+ directory_visible = row.directory_visible;
+ directory_exten_visible = row.directory_exten_visible;
+ limit_max = row.limit_max;
+ limit_destination = row.limit_destination;
+ sip_force_contact = row.sip_force_contact;
+ sip_force_expires = row.sip_force_expires;
+ nibble_account = row.nibble_account;
+ sip_bypass_media = row.sip_bypass_media;
+
+ --set the dial_string
+ if (string.len(row.dial_string) > 0) then
+ dial_string = row.dial_string;
+ else
+ dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. user .. "@" .. domain_name .. ")}";
+ end
+ end);
+ end
+
+ --outbound hot desking - get the extension variables
+ if (continue) then
+ sql = "SELECT * FROM v_extensions WHERE dial_domain = '" .. domain_name .. "' and dial_user = '" .. user .. "' and enabled = 'true' ";
+ if (debug["sql"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
+ end
+ dbh:query(sql, function(row)
+ --variables
+ extension_uuid = row.extension_uuid;
+ domain_uuid = row.domain_uuid;
+ sip_from_user = row.extension;
+ call_group = row.call_group;
+ hold_music = row.hold_music;
+ toll_allow = row.toll_allow;
+ accountcode = row.accountcode;
+ user_context = row.user_context;
+ effective_caller_id_name = row.effective_caller_id_name;
+ effective_caller_id_number = row.effective_caller_id_number;
+ outbound_caller_id_name = row.outbound_caller_id_name;
+ outbound_caller_id_number = row.outbound_caller_id_number;
+ emergency_caller_id_number = row.emergency_caller_id_number;
+ directory_full_name = row.directory_full_name;
+ directory_visible = row.directory_visible;
+ directory_exten_visible = row.directory_exten_visible;
+ limit_max = row.limit_max;
+ limit_destination = row.limit_destination;
+ sip_force_contact = row.sip_force_contact;
+ sip_force_expires = row.sip_force_expires;
+ nibble_account = row.nibble_account;
+ sip_bypass_media = row.sip_bypass_media;
+ end);
+ end
+
+ --set the xml array and then concatenate the array to a string
+ if (continue and password) then
+ --build the xml
+ local xml = {}
+ table.insert(xml, [[]]);
+ table.insert(xml, [[]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ if (number_alias) then
+ if (cidr) then
+ table.insert(xml, [[ ]]);
+ else
+ table.insert(xml, [[ ]]);
+ end
+ else
+ if (cidr) then
+ table.insert(xml, [[ ]]);
+ else
+ table.insert(xml, [[ ]]);
+ end
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ if (string.len(vm_mailto) > 0) then
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(mwi_account) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(auth_acl) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ if (string.len(call_group) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(hold_music) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(toll_allow) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(accountcode) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ if (string.len(effective_caller_id_name) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(effective_caller_id_number) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(outbound_caller_id_name) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(outbound_caller_id_number) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(emergency_caller_id_number) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(directory_full_name) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(directory_visible) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(directory_exten_visible) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(limit_max) > 0) then
+ table.insert(xml, [[ ]]);
+ else
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(limit_destination) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(sip_force_contact) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(sip_force_expires) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (string.len(nibble_account) > 0) then
+ table.insert(xml, [[ ]]);
+ end
+ if (sip_bypass_media == "bypass-media") then
+ table.insert(xml, [[ ]]);
+ end
+ if (sip_bypass_media == "bypass-media-after-bridge") then
+ table.insert(xml, [[ ]]);
+ end
+ if (sip_bypass_media == "proxy-media") then
+ table.insert(xml, [[ ]]);
+ end
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[ ]]);
+ table.insert(xml, [[]]);
+ XML_STRING = table.concat(xml, "\n");
+
+ --set the cache
+ result = trim(api:execute("memcache", "set " .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
+
+ --send the xml to the console
+ if (debug["xml_string"]) then
+ local file = assert(io.open("/tmp/" .. user .. "@" .. domain_name .. ".xml", "w"));
+ file:write(XML_STRING);
+ file:close();
+ end
+
+ --send to the console
+ if (debug["cache"]) then
+ freeswitch.consoleLog("notice", "[xml_handler] directory: " .. user .. "@" .. domain_name .. " source: database\n");
+ end
+ else
+ --send to the console
+ if (debug["cache"]) then
+ if (XML_STRING) then
+ freeswitch.consoleLog("notice", "[xml_handler] directory: " .. user .. "@" .. domain_name .. " source: memcache \n");
+ end
+ end
+ end
+ end --if action
--send the xml to the console
if (debug["xml_string"]) then