From ad82d7fe49e31aee12dc524eb3e100125e1bfce8 Mon Sep 17 00:00:00 2001 From: Digital Daz Date: Wed, 25 Feb 2015 20:35:22 +0000 Subject: [PATCH] Fixed a couple of typos and changed the way the DSN is inserted. --- .../scripts/configuration/callcenter.conf.lua | 503 +++++++++--------- 1 file changed, 252 insertions(+), 251 deletions(-) diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua index 6a9b4f571d..01fce0fecb 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua @@ -1,275 +1,276 @@ --- xml_handler.lua --- Part of FusionPBX --- Copyright (C) 2015 Mark J Crane --- All rights reserved. +-- xml_handler.lua +-- Part of FusionPBX +-- Copyright (C) 2015 Mark J Crane +-- All rights reserved. -- --- Redistribution and use in source and binary forms, with or without --- modification, are permitted provided that the following conditions are met: +-- 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. +-- 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. +-- 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. +-- 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. --get the cache - hostname = trim(api:execute("switchname", "")); - if (trim(api:execute("module_exists", "mod_memcache")) == "true") then - XML_STRING = trim(api:execute("memcache", "get configuration:callcenter.conf:" .. hostname)); - else - XML_STRING = "-ERR NOT FOUND"; - end + hostname = trim(api:execute("switchname", "")); + if (trim(api:execute("module_exists", "mod_memcache")) == "true") then + XML_STRING = trim(api:execute("memcache", "get configuration:callcenter.conf:" .. hostname)); + else + XML_STRING = "-ERR NOT FOUND"; + end --set the cache - if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then + if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then - --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); - dbh = database_handle('system'); + --connect to the database + dofile(scripts_dir.."/resources/functions/database_handle.lua"); + dbh = database_handle('system'); - --exits the script if we didn't connect properly - assert(dbh:connected()); + --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); - end - end + --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); + end + end - --get the variables - dsn = trim(api:execute("global_getvar", "dsn")); + --get the variables + dsn = trim(api:execute("global_getvar", "dsn")); - --start the xml array - local xml = {} - table.insert(xml, [[]]); - table.insert(xml, [[]]); - table.insert(xml, [[
]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - if (string.len(dsn) > 0) then - table.insert(xml, [[ ]]); - end - --table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); + --start the xml array + local xml = {} + table.insert(xml, [[]]); + table.insert(xml, [[]]); + table.insert(xml, [[
]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + if (string.len(dsn) > 0) then + table.insert(xml, [[ ]]); + end + --table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); - --write the queues - table.insert(xml, [[ ]]); - sql = "select * from v_call_center_queues "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); - end - x = 0; - dbh:query(sql, function(row) - --set as variables - queue_name = row.queue_name; - queue_extension = row.queue_extension; - queue_strategy = row.queue_strategy; - queue_moh_sound = row.queue_moh_sound; - queue_record_template = row.queue_record_template; - queue_time_base_score = row.queue_time_base_score; - queue_max_wait_time = row.queue_max_wait_time; - queue_max_wait_time_with_no_agent = row.queue_max_wait_time_with_no_agent; - queue_tier_rules_apply = row.queue_tier_rules_apply; - queue_tier_rule_wait_second = row.queue_tier_rule_wait_second; - queue_tier_rule_wait_multiply_level = row.queue_tier_rule_wait_multiply_level; - queue_tier_rule_no_agent_no_wait = row.queue_tier_rule_no_agent_no_wait; - queue_discard_abandoned_after = row.queue_discard_abandoned_after; - queue_abandoned_resume_allowed = row.queue_abandoned_resume_allowed; - queue_announce_sound = row.queue_announce_sound; - queue_announce_frequency = row.queue_announce_frequency; - queue_description = row.queue_description; + --write the queues + table.insert(xml, [[ ]]); + sql = "select * from v_call_center_queues "; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); + end + x = 0; + dbh:query(sql, function(row) + --set as variables + queue_name = row.queue_name; + queue_extension = row.queue_extension; + queue_strategy = row.queue_strategy; + queue_moh_sound = row.queue_moh_sound; + queue_record_template = row.queue_record_template; + queue_time_base_score = row.queue_time_base_score; + queue_max_wait_time = row.queue_max_wait_time; + queue_max_wait_time_with_no_agent = row.queue_max_wait_time_with_no_agent; + queue_tier_rules_apply = row.queue_tier_rules_apply; + queue_tier_rule_wait_second = row.queue_tier_rule_wait_second; + queue_tier_rule_wait_multiply_level = row.queue_tier_rule_wait_multiply_level; + queue_tier_rule_no_agent_no_wait = row.queue_tier_rule_no_agent_no_wait; + queue_discard_abandoned_after = row.queue_discard_abandoned_after; + queue_abandoned_resume_allowed = row.queue_abandoned_resume_allowed; + queue_announce_sound = row.queue_announce_sound; + queue_announce_frequency = row.queue_announce_frequency; + queue_description = row.queue_description; - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - if (string.len(queue_moh_sound) == 0) then - table.insert(xml, [[ ]]); - else - if (string.sub(queue_moh_sound, 0, 15) == 'local_stream://') then - table.insert(xml, [[ ]]); - elseif (string.sub(queue_moh_sound, 0, 2) == '${' and string.sub(queue_moh_sound, -5) == 'ring}') then - table.insert(xml, [[ ]]); - else - table.insert(xml, [[ ]]); - end - end - if (string.len(queue_record_template) > 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, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + if (string.len(queue_moh_sound) == 0) then + table.insert(xml, [[ ]]); + else + if (string.sub(queue_moh_sound, 0, 15) == 'local_stream://') then + table.insert(xml, [[ ]]); + elseif (string.sub(queue_moh_sound, 0, 2) == '${' and string.sub(queue_moh_sound, -5) == 'ring}') then + table.insert(xml, [[ ]]); + else + table.insert(xml, [[ ]]); + end + end + if (string.len(queue_record_template) > 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, [[ ]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); - --increment the value of x - x = x + 1; - end) - table.insert(xml, [[ ]]); + --increment the value of x + x = x + 1; + end) + table.insert(xml, [[ ]]); - --get the agents - table.insert(xml, [[ ]]); - sql = "select * from v_call_center_agents "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); - end - x = 0; - dbh:query(sql, function(row) - --get the values from the database and set as variables - agent_name = row.agent_name; - agent_type = row.agent_type; - agent_call_timeout = row.agent_call_timeout; - agent_contact = row.agent_contact; - agent_status = row.agent_status; - agent_no_answer_delay_time = row.agent_no_answer_delay_time; - agent_max_no_answer = row.agent_max_no_answer; - agent_wrap_up_time = row.agent_wrap_up_time; - agent_reject_delay_time = row.agent_reject_delay_time; - agent_busy_delay_time = row.agent_busy_delay_time; + --get the agents + table.insert(xml, [[ ]]); + sql = "select * from v_call_center_agents "; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); + end + x = 0; + dbh:query(sql, function(row) + --get the values from the database and set as variables + agent_name = row.agent_name; + agent_type = row.agent_type; + agent_call_timeout = row.agent_call_timeout; + agent_contact = row.agent_contact; + agent_status = row.agent_status; + agent_no_answer_delay_time = row.agent_no_answer_delay_time; + agent_max_no_answer = row.agent_max_no_answer; + agent_wrap_up_time = row.agent_wrap_up_time; + agent_reject_delay_time = row.agent_reject_delay_time; + agent_busy_delay_time = row.agent_busy_delay_time; - --get and then set the complete agent_contact with the call_timeout and when necessary confirm - --confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1"; - --if you change this variable also change app/call_center/call_center_agent_edit.php - confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout="..agent_call_timeout; - if (string.find(agent_contact, '}') == nil) then - --not found - if (string.find(agent_contact, 'sofia/gateway') == nil) then - --add the call_timeout - agent_contact = "{call_timeout="..agent_call_timeout."}"..agent_contact; - else - --add the call_timeout and confirm - tmp_pos = string.find(agent_contact, "}"); - tmp_first = string.sub(agent_contact, 0, tmp_pos); - tmp_last = string.sub(agent_contact, tmp_pos); - agent_contact = tmp_first..',call_timeout='..agent_call_timeout..tmp_last; - agent_contact = "{"..confirm..",call_timeout="..agent_call_timeout.."}"..agent_contact; - end - else - --found - if (string.find(agent_contact, 'sofia/gateway') == nil) then - --not found - if (string.find(agent_contact, 'call_timeout') == nil) then - --add the call_timeout - pos = string.find(agent_contact, "}"); - first = string.sub(agent_contact, 0, pos); - last = string.sub(agent_contact, tmp_pos); - agent_contact = first..[[,call_timeout=]]..agent_call_timeout..last; - else - --the string has the call timeout - agent_contact = agent_contact; - end - else - --found - pos = string.find(agent_contact, "}"); - first = string.sub(agent_contact, 0, pos); - last = string.sub(agent_contact, pos); - if (stristr(agent_contact, 'call_timeout') === FALSE) then - --add the call_timeout and confirm - agent_contact = first.','..confirm.',call_timeout='..agent_call_timeout..last; - else - --add confirm - agent_contact = tmp_first..','..confirm..tmp_last; - end - end - end + --get and then set the complete agent_contact with the call_timeout and when necessary confirm + --confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1"; + --if you change this variable also change app/call_center/call_center_agent_edit.php + confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout="..agent_call_timeout; + if (string.find(agent_contact, '}') == nil) then + --not found + if (string.find(agent_contact, 'sofia/gateway') == nil) then + --add the call_timeout + agent_contact = "{call_timeout="..agent_call_timeout.."}"..agent_contact; + else + --add the call_timeout and confirm + tmp_pos = string.find(agent_contact, "}"); + tmp_first = string.sub(agent_contact, 0, tmp_pos); + tmp_last = string.sub(agent_contact, tmp_pos); + agent_contact = tmp_first..',call_timeout='..agent_call_timeout..tmp_last; + agent_contact = "{"..confirm..",call_timeout="..agent_call_timeout.."}"..agent_contact; + end + else + --found + if (string.find(agent_contact, 'sofia/gateway') == nil) then + --not found + if (string.find(agent_contact, 'call_timeout') == nil) then + --add the call_timeout + pos = string.find(agent_contact, "}"); + first = string.sub(agent_contact, 0, pos); + last = string.sub(agent_contact, tmp_pos); + agent_contact = first..[[,call_timeout=]]..agent_call_timeout..last; + else + --the string has the call timeout + agent_contact = agent_contact; + end + else + --found + pos = string.find(agent_contact, "}"); + first = string.sub(agent_contact, 0, pos); + last = string.sub(agent_contact, pos); + if (stristr(agent_contact, 'call_timeout') == FALSE) then + --add the call_timeout and confirm + agent_contact = first..','..confirm..',call_timeout='..agent_call_timeout..last; + else + --add confirm + agent_contact = tmp_first..','..confirm..tmp_last; + end + end + end - --build the xml string - table.insert(xml, [[ ]]); - end) - table.insert(xml, [[ ]]); + --build the xml string + table.insert(xml, [[ ]]); + end) + table.insert(xml, [[ ]]); - --get the tiers - sql = "select * from v_call_center_tiers "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); - end - table.insert(xml, [[ ]]); - dbh:query(sql, function(row) - --get the values from the database and set as variables - agent_name = row.agent_name; - queue_name = row.queue_name; - tier_level = row.tier_level; - tier_position = row.tier_position; - --build the xml - table.insert(xml, [[ ]]); - end) - table.insert(xml, [[ ]]); + --get the tiers + sql = "select * from v_call_center_tiers "; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); + end + table.insert(xml, [[ ]]); + dbh:query(sql, function(row) + --get the values from the database and set as variables + agent_name = row.agent_name; + queue_name = row.queue_name; + tier_level = row.tier_level; + tier_position = row.tier_position; + --build the xml + table.insert(xml, [[ ]]); + end) + table.insert(xml, [[ ]]); - --close the extension tag if it was left open - table.insert(xml, [[ ]]); - table.insert(xml, [[
]]); - table.insert(xml, [[
]]); - XML_STRING = table.concat(xml, "\n"); - if (debug["xml_string"]) then - freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n"); - end + --close the extension tag if it was left open + table.insert(xml, [[
]]); + table.insert(xml, [[
]]); + table.insert(xml, [[
]]); + XML_STRING = table.concat(xml, "\n"); + if (debug["xml_string"]) then + freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n"); + end - --close the database connection - dbh:release(); + --close the database connection + dbh:release(); + freeswitch.consoleLog("notice", "thing is:"..api:execute("eval ${dsn}")); + --set the cache + result = trim(api:execute("memcache", "set configuration:callcenter.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' ".."expire['callcenter.conf']")); - --set the cache - result = trim(api:execute("memcache", "set configuration:callcenter.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' "..expire["callcenter.conf"])); + --send the xml to the console + if (debug["xml_string"]) then + local file = assert(io.open("/tmp/callcenter.conf.xml", "w")); + file:write(XML_STRING); + file:close(); + end - --send the xml to the console - if (debug["xml_string"]) then - local file = assert(io.open("/tmp/callcenter.conf.xml", "w")); - file:write(XML_STRING); - file:close(); - end - - --send to the console - if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf:" .. hostname .." source: database\n"); - end - else - --replace the ' back to a single quote - XML_STRING = XML_STRING:gsub("'", "'"); - - --send to the console - if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf source: memcache\n"); - end - end --if XML_STRING \ No newline at end of file + --send to the console + if (debug["cache"]) then + freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf:" .. hostname .." source: database\n"); + end + else + --replace the ' back to a single quote + XML_STRING = XML_STRING:gsub("'", "'"); +freeswitch.consoleLog("notice", "XML STRING "..XML_STRING.."\n"); + --send to the console + if (debug["cache"]) then + freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf source: memcache\n"); + end + end --if XML_STRING + \ No newline at end of file