diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/acl.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/acl.lua new file mode 100644 index 0000000000..8132861696 --- /dev/null +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/acl.lua @@ -0,0 +1,62 @@ +--connect to the database + local Database = require "resources.functions.database" + local log = require "resources.functions.log"["directory_acl"] + local dbh = Database.new('system') + +--build the xml + local xml = {} + table.insert(xml, [[]]) + table.insert(xml, [[]]) + table.insert(xml, [[
]]) + +--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 e.cidr is not null and e.cidr <> '' " + if domain_name then + sql = sql .. "and d.domain_name = '"..domain_name.."' " + else + sql = sql .. "order by d.domain_name" + end + + if debug['sql'] then + log.noticef("SQL - %s", sql) + end + + local prev_domain_name + + dbh:query(sql, function(row) + if prev_domain_name ~= row.domain_name then + if prev_domain_name then + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end + prev_domain_name = row.domain_name + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end + + local cidr = (#row.cidr > 0) and (' cidr="' .. row.cidr .. '"') or '' + table.insert(xml, [[ ]]) + end) + + if prev_domain_name then + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end + + table.insert(xml, [[
]]) + table.insert(xml, [[
]]) + + XML_STRING = table.concat(xml, "\n") + if (debug["xml_string"]) then + log.notice("XML_STRING "..XML_STRING) + end + +--close the database connection + dbh:release() diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/directory.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/directory.lua new file mode 100644 index 0000000000..7ba1923aa3 --- /dev/null +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/directory.lua @@ -0,0 +1,96 @@ +--connect to the database + local Database = require "resources.functions.database" + local log = require "resources.functions.log"["directory_dir"] + local dbh = Database.new('system') + +--build the xml + local xml = {} + table.insert(xml, [[]]) + table.insert(xml, [[]]) + table.insert(xml, [[
]]) + +--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') " + if domain_name then + sql = sql .. "and d.domain_name = '"..domain_name.."' " + else + sql = sql .. "order by d.domain_name" + end + + if debug['sql'] then + log.noticef("SQL - %s", sql) + end + +-- export this params + local params = { + directory_visible = "directory-visible"; + directory_exten_visible = "directory-exten-visible"; + } + +-- export this variables + local variables = { + effective_caller_id_name = "effective_caller_id_name"; + directory_full_name = "directory_full_name"; + } + + local prev_domain_name + + dbh:query(sql, function(row) + if prev_domain_name ~= row.domain_name then + if prev_domain_name then + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end + prev_domain_name = row.domain_name + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end + + row.sip_from_user = row.extension + row.sip_from_number = (#number_alias > 0) and number_alias or row.extension + local number_alias_string = '' + if #row.number_alias > 0 then + number_alias_string = ' number-alias="' .. row.number_alias .. '"' + end + + table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]) + for name, param in pairs(params) do + if row[name] and #row[name] > 0 then + table.insert(xml, [[ ]]) + end + end + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + for name, param in pairs(variables) do + if row[name] and #row[name] > 0 then + table.insert(xml, [[ ]]) + end + end + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end) + + if prev_domain_name then + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + table.insert(xml, [[ ]]) + end + + table.insert(xml, [[
]]) + table.insert(xml, [[
]]) + + XML_STRING = table.concat(xml, "\n") + if (debug["xml_string"]) then + log.notice("XML_STRING "..XML_STRING) + end + +--close the database connection + dbh:release() \ No newline at end of file diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua index dda1b9617f..cfd42346e3 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/domains.lua @@ -31,212 +31,18 @@ --exits the script if we didn't connect properly assert(dbh:connected()); ---set the variables as a string - number_alias = ""; - number_alias_string = ""; - ---build the xml +--process when the sip profile is rescanned, sofia is reloaded, or sip redirect local 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, [[ ]]); - ---process when the sip profile is rescanned, sofia is reloaded, or sip redirect - sql = "SELECT * FROM v_domains as d, v_extensions as e "; - if (domain_name ~= nil) then - sql = sql .. "where d.domain_name = '"..domain_name.."' "; - sql = sql .. "and d.domain_uuid = e.domain_uuid "; - end - --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] sql "..sql.."\n"); + sql = "SELECT domain_name FROM v_domains "; dbh:query(sql, function(row) - - --variables - cidr = ""; - if (string.len(row.cidr) > 0) then - cidr = [[ cidr="]] .. row.cidr .. [["]]; - end - if (string.len(row.number_alias) > 0) then - number_alias = row.number_alias; - number_alias_string = [[ number-alias="]] .. row.number_alias .. [["]]; - end - row.sip_from_user = row.extension; - row.sip_from_number = (#number_alias > 0) and number_alias or row.extension; - - --continue building the 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(row.mwi_account) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.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, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - if (string.len(row.call_group) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.call_screen_enabled) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.user_record) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.hold_music) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.toll_allow) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.accountcode) > 0) then - table.insert(xml, [[ ]]); - end - table.insert(xml, [[ ]]); - if (string.len(row.effective_caller_id_name) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.effective_caller_id_number) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.outbound_caller_id_name) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.outbound_caller_id_number) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.emergency_caller_id_name) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.emergency_caller_id_number) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.missed_call_app) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.missed_call_data) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.directory_full_name) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.directory_visible) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.directory_exten_visible) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.limit_max) > 0) then - table.insert(xml, [[ ]]); - else - table.insert(xml, [[ ]]); - end - if (string.len(row.limit_destination) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.sip_force_contact) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.sip_force_expires) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.nibble_account) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.absolute_codec_string) > 0) then - table.insert(xml, [[ ]]); - end - if (row.sip_bypass_media == "bypass-media") then - table.insert(xml, [[ ]]); - end - - if (row.sip_bypass_media == "bypass-media-after-bridge") then - table.insert(xml, [[ ]]); - end - if (row.sip_bypass_media == "proxy-media") then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_all_enabled) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_all_destination) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_busy_enabled) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_busy_destination) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_no_answer_enabled) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_no_answer_destination) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_user_not_registered_enabled) > 0) then - table.insert(xml, [[ ]]); - end - if (string.len(row.forward_user_not_registered_destination) > 0) then - table.insert(xml, [[ ]]); - end - - if (string.len(row.do_not_disturb) > 0) then - table.insert(xml, [[ ]]); - end - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); end); - 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", "[xml_handler-directory.lua] XML_STRING "..XML_STRING.."\n"); --close the database connection dbh:release(); diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua index e2a3e5e1db..1d401958a7 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/directory.lua @@ -46,6 +46,10 @@ number_alias_string = ""; vm_mailto = ""; +-- event source + local event_calling_function = params:getHeader("Event-Calling-Function") + local event_calling_file = params:getHeader("Event-Calling-File") + --determine the correction action to perform if (purpose == "gateways") then dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/domains.lua"); @@ -55,10 +59,12 @@ dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/group_call.lua"); elseif (action == "reverse-auth-lookup") then dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua"); - elseif (params:getHeader("Event-Calling-Function") == "switch_xml_locate_domain") then - dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/domains.lua"); - elseif (params:getHeader("Event-Calling-Function") == "switch_load_network_lists") then + elseif (event_calling_function == "switch_xml_locate_domain") then dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/domains.lua"); + elseif (event_calling_function == "switch_load_network_lists") then + dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/acl.lua"); + elseif (event_calling_function == "populate_database") and (event_calling_file == "mod_directory.c") then + dofile(scripts_dir.."/app/xml_handler/resources/scripts/directory/action/directory.lua"); else --handle action --all other directory actions: sip_auth, user_call