From 4c293b7f9e83325f0592d88c382933edca1286b1 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 7 Jul 2012 21:18:17 +0000 Subject: [PATCH] Do not provide the XMl for registering an disabled extension and other changes to improve the code. --- includes/install/scripts/xml_handler.lua | 231 ++++++++++++----------- 1 file changed, 124 insertions(+), 107 deletions(-) diff --git a/includes/install/scripts/xml_handler.lua b/includes/install/scripts/xml_handler.lua index 0e6a5b8033..4d7a357a2d 100644 --- a/includes/install/scripts/xml_handler.lua +++ b/includes/install/scripts/xml_handler.lua @@ -81,12 +81,13 @@ --handle the directory if (XML_REQUEST["section"] == "directory" and key and user and domain_name) then --get the extension from the database - sql = "SELECT * FROM v_extensions WHERE domain_uuid = '" .. domain_uuid .. "' and extension = '" .. user .. "'"; + 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 @@ -119,6 +120,7 @@ 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; @@ -148,12 +150,14 @@ end); --outbound hot desking - get the extension variables - sql = "SELECT * FROM v_extensions WHERE dial_domain = '" .. domain_name .. "' and dial_user = '" .. user .. "'"; + 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 + 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; @@ -176,119 +180,132 @@ end); --set the xml array and then concatenate the array to a string - local xml = {} - table.insert(xml, [[]]); - table.insert(xml, [[]]); - table.insert(xml, [[
]]); - table.insert(xml, [[ ]]); - if (number_alias) then - if (cidr) then - table.insert(xml, [[ ]]); + if (password) then + 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 - table.insert(xml, [[ ]]); + if (cidr) then + table.insert(xml, [[ ]]); + else + table.insert(xml, [[ ]]); + end end - else - if (cidr) then - table.insert(xml, [[ ]]); - else - table.insert(xml, [[ ]]); + 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 - 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, [[ ]]); - 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 -- - if (extension == "1003") then - table.insert(xml, [[ ]]); - else + 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, [[ ]]); + if (user_context ~= "default" and user_context ~= "public" and user_context ~= "features") then + table.insert(xml, [[ ]]); + end + 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 - 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, [[ ]]); + 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"); else - table.insert(xml, [[ ]]); + XML_STRING = ""; end - if (string.len(limit_destination) > 0) then - table.insert(xml, [[ ]]); + + --send the xml to the console + if (debug["xml_string"]) then + local file = assert(io.open("/tmp/directory.xml", "w")); + file:write(XML_STRING); + file:close(); 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"); --send the xml to the console if (debug["xml_string"]) then