From 9c51243035b0cd1302c2f6c48898e91854c4cb75 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Wed, 3 Feb 2016 16:53:22 +0300 Subject: [PATCH 01/18] Fix. Can not pick any options after IVR play `streamfile.lua` Rewrite ivr functions to easy read code. --- resources/install/scripts/ivr_menu.lua | 287 ++++++++++++------------- 1 file changed, 139 insertions(+), 148 deletions(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index e1154c8d61..b2c2be7aee 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -40,6 +40,7 @@ --include functions require "resources.functions.format_ringback" + require "resources.functions.split" --get the variables domain_name = session:getVariable("domain_name"); @@ -79,10 +80,8 @@ end end - --set default variable(s) tries = 0; - option_found = "false"; --define the trim function require "resources.functions.trim" @@ -142,12 +141,9 @@ --get the sounds dir, language, dialect and voice sounds_dir = session:getVariable("sounds_dir"); - 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 + default_language = session:getVariable("default_language") or 'en'; + default_dialect = session:getVariable("default_dialect") or 'us'; + default_voice = session:getVariable("default_voice") or 'callie'; --make the path relative if (string.sub(ivr_menu_greet_long,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then @@ -164,16 +160,10 @@ end --parse file names - greet_long_file_name = ivr_menu_greet_long:match("([^/]+)$"); - greet_short_file_name = ivr_menu_greet_short:match("([^/]+)$"); - invalid_sound_file_name = ivr_menu_invalid_sound:match("([^/]+)$"); - exit_sound_file_name = ivr_menu_exit_sound:match("([^/]+)$"); - ---prevent nil concatenation errors - if (greet_long_file_name == nil) then greet_long_file_name = ""; end - if (greet_short_file_name == nil) then greet_short_file_name = ""; end - if (invalid_sound_file_name == nil) then invalid_sound_file_name = ""; end - if (exit_sound_file_name == nil) then exit_sound_file_name = ""; end + greet_long_file_name = ivr_menu_greet_long:match("([^/]+)$") or ""; + greet_short_file_name = ivr_menu_greet_short:match("([^/]+)$") or ""; + invalid_sound_file_name = ivr_menu_invalid_sound:match("([^/]+)$") or ""; + exit_sound_file_name = ivr_menu_exit_sound:match("([^/]+)$") or ""; --get the recordings from the database ivr_menu_greet_long_is_base64 = false; @@ -295,7 +285,7 @@ end end --greet short - if (string.len(ivr_menu_greet_short) > 1) then + if #ivr_menu_greet_short > 1 then if (not file_exists(ivr_menu_greet_short)) then if (file_exists(recordings_dir.."/"..domain_name.."/"..greet_short_file_name)) then ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..greet_short_file_name; @@ -325,44 +315,49 @@ --define the ivr menu function menu() - --increment the tries - tries = tries + 1; - min_digits = 1; - session:setVariable("slept", "false"); - if (tries == 1) then - if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] greet long: " .. ivr_menu_greet_long .. "\n"); + -- increment the tries + tries = tries + 1; + -- set the minimum dtmf lengts + local min_digits = 1; + + -- set sound file and number of attempts + local sound, sound_type, attempts + + if tries == 1 then + sound, sound_type, attempts = ivr_menu_greet_long or "", "long", 1 + else + sound, sound_type, attempts = ivr_menu_greet_short or "", "short", tonumber(ivr_menu_max_timeouts) or 3 end - --check if phrase - pos = string.find(ivr_menu_greet_long, ":", 0, true); - if (pos ~= nil and string.sub(ivr_menu_greet_long, 0, pos-1) == 'phrase') then - freeswitch.consoleLog("notice", "[ivr_menu] phrase detected\n"); - dtmf_digits = session:playAndGetDigits(min_digits, ivr_menu_digit_len, 1, ivr_menu_timeout, ivr_menu_confirm_key, ivr_menu_greet_long, "", ".*"); + + if (debug["tries"]) then + freeswitch.consoleLog("notice", "[ivr_menu] greet " .. sound_type .. ": " .. sound .. "\n"); + end + + -- read dtmf + local dtmf_digits + if attempts > 0 then + dtmf_digits = session:playAndGetDigits(min_digits, ivr_menu_digit_len, attempts, ivr_menu_timeout, ivr_menu_confirm_key, sound, "", ".*"); + -- need pause before stream file session:setVariable("slept", "false"); - else - dtmf_digits = session:playAndGetDigits(min_digits, ivr_menu_digit_len, 1, ivr_menu_timeout, ivr_menu_confirm_key, ivr_menu_greet_long, "", ".*"); end - else - if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] greet long: " .. ivr_menu_greet_short .. "\n"); + + -- proceed dtmf + if dtmf_digits and #dtmf_digits > 0 then + if (debug["tries"]) then + freeswitch.consoleLog("notice", "[ivr_menu] dtmf_digits: " .. dtmf_digits .. "\n"); + end + return menu_options(session, dtmf_digits); end - dtmf_digits = session:playAndGetDigits(min_digits, ivr_menu_digit_len, ivr_menu_max_timeouts, ivr_menu_timeout, ivr_menu_confirm_key, ivr_menu_greet_short, "", ".*"); - end - if (dtmf_digits ~= nil and string.len(dtmf_digits) > 0) then - if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] dtmf_digits: " .. dtmf_digits .. "\n"); + + -- check number of failures + if tries < tonumber(ivr_menu_max_failures) then + --log the dtmf digits + if (debug["tries"]) then + freeswitch.consoleLog("notice", "[ivr_menu] tries: " .. tries .. "\n"); + end + --run the menu again + return menu(); end - menu_options(session, dtmf_digits); - else - if (tries < tonumber(ivr_menu_max_failures)) then - --log the dtmf digits - if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] tries: " .. tries .. "\n"); - end - --run the menu again - menu(); - end - end end function menu_options(session, digits) @@ -377,113 +372,109 @@ if (debug["sql"]) then freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); end - status = dbh:query(sql, function(row) + + local action, script, data + dbh:query(sql, function(row) + -- clear vars + action, script, data = nil + --check for matching options - if (tonumber(row.ivr_menu_option_digits) ~= nil) then + if tonumber(row.ivr_menu_option_digits) then row.ivr_menu_option_digits = "^"..row.ivr_menu_option_digits.."$"; end - if (api:execute("regex", "m:~"..digits.."~"..row.ivr_menu_option_digits) == "true") then - if (row.ivr_menu_option_action == "menu-exec-app") then - --get the action and data - pos = string.find(row.ivr_menu_option_param, " ", 0, true); - if pos then - action = string.sub(row.ivr_menu_option_param, 0, pos-1); - data = string.sub(row.ivr_menu_option_param, pos+1); - else - action, data = row.ivr_menu_option_param, "" - end - --check if the option uses a regex - regex = string.find(row.ivr_menu_option_digits, "(", 0, true); - if (regex) then - --get the regex result - result = trim(api:execute("regex", "m:~"..digits.."~"..row.ivr_menu_option_digits.."~$1")); - if (debug["regex"]) then - freeswitch.consoleLog("notice", "[ivr_menu] regex m:~"..digits.."~"..row.ivr_menu_option_digits.."~$1\n"); - freeswitch.consoleLog("notice", "[ivr_menu] result: "..result.."\n"); - end - - --replace the $1 and the domain name - data = data:gsub("$1", result); - data = data:gsub("${domain_name}", domain_name); - end --if regex - end --if menu-exex-app - if (row.ivr_menu_option_action == "phrase") then - action = 'phrase'; - data = row.ivr_menu_option_param; - end - if (action == "lua") then - pos = string.find(data, " ", 0, true); - if pos then - script = string.sub(data, 0, pos-1); - else - script = data - end - end - end --if regex match - - --execute - if (action) then - if (string.len(action) > 0) then - --option found - option_found = "true"; - - --send to the log - if (debug["action"]) then - freeswitch.consoleLog("notice", "[ivr_menu] action: " .. action .. " data: ".. data .. "\n"); - end - --run the action - if (action == 'phrase' or (script ~= nil and script == 'streamfile.lua')) then - session:execute(action, data); - menu(); - else - if (ivr_menu_exit_sound ~= nil) then - session:streamFile(ivr_menu_exit_sound); - end - session:execute(action, data); - end - end + if api:execute("regex", "m:~"..digits.."~"..row.ivr_menu_option_digits) ~= "true" then + return end - --clear the variables - action = ""; - data = ""; + if row.ivr_menu_option_action == "menu-exec-app" then + --get the action and data + action, data = split_first(row.ivr_menu_option_param, ' ', true) + data = data or "" + + --check if the option uses a regex + local regex = string.find(row.ivr_menu_option_digits, "(", 0, true); + if regex then + --get the regex result + regex = "m:~"..digits.."~"..row.ivr_menu_option_digits.."~$1" + local result = trim(api:execute("regex", regex)); + if (debug["regex"]) then + freeswitch.consoleLog("notice", "[ivr_menu] regex "..regex.."\n"); + freeswitch.consoleLog("notice", "[ivr_menu] result: "..result.."\n"); + end + + --replace the $1 and the domain name + data = data:gsub("$1", result); + data = data:gsub("${domain_name}", domain_name); + end --if regex + end --if menu-exex-app + + if row.ivr_menu_option_action == "phrase" then + action = 'phrase'; + data = row.ivr_menu_option_param; + end + + if action == "lua" then + script = split_first(data, " ", true) + end + + -- break loop + if action and #action > 0 then + return 1 + end + + -- we have unsupported IVR action + freeswitch.consoleLog("warning", "[ivr_menu] invalid action in ivr: " .. row.ivr_menu_option_action .. "\n"); end); --end results - --direct dial - if (ivr_menu_direct_dial == "true") then - if (string.len(digits) < 6 and option_found == "false") then - --replace the $1 and the domain name - digits = digits:gsub("*", ""); - --check to see if the user extension exists - cmd = "user_exists id ".. digits .." "..domain_name; - result = api:executeString(cmd); - freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..cmd.." "..result.."\n"); - if (result == "true") then - --log the action - freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..digits.." XML "..context.."\n"); - --run the action - session:execute("transfer", digits.." XML "..context); - else - --run the menu again - menu(); - end - end + --execute + if action and #action > 0 then + -- send to the log + if (debug["action"]) then + freeswitch.consoleLog("notice", "[ivr_menu] action: " .. action .. " data: ".. data .. "\n"); + end + + -- run the action (with return to menu) + if action == 'phrase' or script == 'streamfile.lua' then + session:execute(action, data); + return menu(); + end + + -- run the action (without return to menu) + if ivr_menu_exit_sound and #ivr_menu_exit_sound > 0 then + session:streamFile(ivr_menu_exit_sound); + end + return session:execute(action, data); end - --execute - if (action) then - if (string.len(action) == 0) then - session:streamFile(ivr_menu_invalid_sound); - menu(); - end - else - if (action ~= 'phrase' and (script == nil or script ~= 'streamfile.lua')) then - session:streamFile(ivr_menu_invalid_sound); - end - menu(); + --direct dial + if ivr_menu_direct_dial == "true" and #digits > 0 and #digits < 6 then + -- remove *# + digits = digits:gsub("[*#]", ""); + + -- check to see if the user extension exists + local cmd = "user_exists id ".. digits .." "..domain_name; + local result = api:executeString(cmd); + freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..cmd.." "..result.."\n"); + if result == "true" then + --log the action + freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..digits.." XML "..context.."\n"); + --run the action + return session:execute("transfer", digits.." XML "..context); + end + + --run the menu again (without play ivr_menu_invalid_sound) + return menu(); end - + + --invalid input try again + if (debug["action"]) then + freeswitch.consoleLog("notice", "[ivr_menu] unrecgnized action \n"); + end + if ivr_menu_invalid_sound and #ivr_menu_invalid_sound then + session:streamFile(ivr_menu_invalid_sound); + end + return menu(); end --end function --answer the session From 883b73f6ac40fcd4880260c308390c4f704e73de Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 4 Feb 2016 13:20:30 +0300 Subject: [PATCH 02/18] Simplify code --- resources/install/scripts/ivr_menu.lua | 204 +++++++++---------------- 1 file changed, 69 insertions(+), 135 deletions(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 146abee182..f06f10df76 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -80,9 +80,6 @@ end end ---set default variable(s) - tries = 0; - --define the trim function require "resources.functions.trim" @@ -146,18 +143,11 @@ default_voice = session:getVariable("default_voice") or 'callie'; --make the path relative - if (string.sub(ivr_menu_greet_long,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then - ivr_menu_greet_long = string.sub(ivr_menu_greet_long,72); - end - if (string.sub(ivr_menu_greet_short,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then - ivr_menu_greet_short = string.sub(ivr_menu_greet_short,72); - end - if (string.sub(ivr_menu_invalid_sound,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then - ivr_menu_invalid_sound = string.sub(ivr_menu_invalid_sound,72); - end - if (string.sub(ivr_menu_exit_sound,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then - ivr_menu_exit_sound = string.sub(ivr_menu_exit_sound,72); - end + local strip_pattern = "^$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/" + ivr_menu_greet_long = string.gsub(ivr_menu_greet_long, strip_pattern, "") + ivr_menu_greet_short = string.gsub(ivr_menu_greet_short, strip_pattern, "") + ivr_menu_invalid_sound = string.gsub(ivr_menu_invalid_sound, strip_pattern, "") + ivr_menu_exit_sound = string.gsub(ivr_menu_exit_sound, strip_pattern, "") --parse file names greet_long_file_name = ivr_menu_greet_long:match("([^/]+)$") or ""; @@ -171,105 +161,65 @@ ivr_menu_invalid_sound_is_base64 = false; ivr_menu_exit_sound_is_base64 = false; if (storage_type == "base64") then + + --add functions + require "resources.functions.base64"; + require "resources.functions.mkdir"; + + --make sure the recordings directory exists + mkdir(recordings_dir.."/"..domain_name); + + --define function to load file from db + local function load_file(recordings_dir, domain_name, file_name) + local full_path = recordings_dir.."/"..domain_name .. "/" .. file_name + if file_exists(full_path) then + return full_path + end + + local sql = [[SELECT * FROM v_recordings WHERE domain_uuid = ']]..domain_uuid.. + [['AND recording_filename = ']]..file_name..[[' ]]; + + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n"); + end + + local is_base64 + dbh:query(sql, function(row) + if #row.recording_base64 > 32 then + local file, err = io.open(full_path, "w"); + if not file then + freeswitch.consoleLog("err", "[ivr_menu] can not create file: "..full_path.."; Error - " .. tostring(err) .. "\n"); + end + file:write(base64.decode(row.recording_base64)); + file:close(); + is_base64 = true; + end + end); + + -- return path in any case + return full_path, is_base64 + end + --greet long - if (string.len(ivr_menu_greet_long) > 1) then - if (not file_exists(recordings_dir.."/"..domain_name.."/"..greet_long_file_name)) then - sql = [[SELECT * FROM v_recordings - WHERE domain_uuid = ']]..domain_uuid..[[' - AND recording_filename = ']]..greet_long_file_name..[[' ]]; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n"); - end - status = dbh:query(sql, function(row) - --add functions - require "resources.functions.base64"; - --make sure the recordings directory exists - require "resources.functions.mkdir"; - mkdir(recordings_dir.."/"..domain_name); - --add the path to filename - ivr_menu_greet_long = recordings_dir.."/"..domain_name.."/"..greet_long_file_name; - ivr_menu_greet_long_is_base64 = true; - --save the recording to the file system - if (string.len(row["recording_base64"]) > 32) then - local file = io.open(ivr_menu_greet_long, "w"); - file:write(base64.decode(row["recording_base64"])); - file:close(); - end - end); - end + if #ivr_menu_greet_long > 1 then + ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_file(recordings_dir, domain_name, greet_long_file_name) end + --greet short - if (string.len(ivr_menu_greet_short) > 1) then - if (not file_exists(recordings_dir.."/"..domain_name.."/"..greet_short_file_name)) then - sql = [[SELECT * FROM v_recordings - WHERE domain_uuid = ']]..domain_uuid..[[' - AND recording_filename = ']]..greet_short_file_name..[[' ]]; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n"); - end - status = dbh:query(sql, function(row) - --add functions - require "resources.functions.base64"; - --add the path to filename - ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..greet_short_file_name; - ivr_menu_greet_short_is_base64 = true; - --save the recording to the file system - if (string.len(row["recording_base64"]) > 32) then - local file = io.open(ivr_menu_greet_short, "w"); - file:write(base64.decode(row["recording_base64"])); - file:close(); - end - end); - end + if #ivr_menu_greet_short > 1 then + ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_file(recordings_dir, domain_name, greet_short_file_name) end + --invalid sound - if (string.len(ivr_menu_invalid_sound) > 1) then - if (not file_exists(recordings_dir.."/"..domain_name.."/"..invalid_sound_file_name)) then - sql = [[SELECT * FROM v_recordings - WHERE domain_uuid = ']]..domain_uuid..[[' - AND recording_filename = ']]..invalid_sound_file_name..[[' ]]; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n"); - end - status = dbh:query(sql, function(row) - --add functions - require "resources.functions.base64"; - --add the path to filename - ivr_menu_invalid_sound = recordings_dir.."/"..domain_name.."/"..invalid_sound_file_name; - ivr_menu_invalid_sound_is_base64 = true; - --save the recording to the file system - if (string.len(row["recording_base64"]) > 32) then - local file = io.open(ivr_menu_invalid_sound, "w"); - file:write(base64.decode(row["recording_base64"])); - file:close(); - end - end); - end + if #ivr_menu_invalid_sound > 1 then + ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_file(recordings_dir, domain_name, invalid_sound_file_name) end + --exit sound - if (string.len(ivr_menu_exit_sound) > 1) then - if (not file_exists(recordings_dir.."/"..domain_name.."/"..exit_sound_file_name)) then - sql = [[SELECT * FROM v_recordings - WHERE domain_uuid = ']]..domain_uuid..[[' - AND recording_filename = ']]..exit_sound_file_name..[[' ]]; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n"); - end - status = dbh:query(sql, function(row) - --add functions - require "resources.functions.base64"; - --add the path to filename - ivr_menu_exit_sound = recordings_dir.."/"..domain_name.."/"..exit_sound_file_name; - ivr_menu_exit_sound_is_base64 = true; - --save the recording to the file system - if (string.len(row["recording_base64"]) > 32) then - local file = io.open(ivr_menu_exit_sound, "w"); - file:write(base64.decode(row["recording_base64"])); - file:close(); - end - end); - end + if #ivr_menu_exit_sound > 1 then + ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(recordings_dir, domain_name, exit_sound_file_name) end + elseif (storage_type == "http_cache") then --add the path to file name ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long; @@ -279,44 +229,28 @@ end --adjust file paths + local function adjust_file_path(full_path, file_name) + return file_exists(full_path) + or file_exists(recordings_dir.."/"..domain_name.."/"..file_name) + or file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name) + or full_path + end --greet long - if (not file_exists(ivr_menu_greet_long)) then - if (file_exists(recordings_dir.."/"..domain_name.."/"..greet_long_file_name)) then - ivr_menu_greet_long = recordings_dir.."/"..domain_name.."/"..greet_long_file_name; - elseif (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_long_file_name)) then - ivr_menu_greet_long = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_long_file_name; - end - end + ivr_menu_greet_long = adjust_file_path(ivr_menu_greet_long, greet_long_file_name) --greet short if #ivr_menu_greet_short > 1 then - if (not file_exists(ivr_menu_greet_short)) then - if (file_exists(recordings_dir.."/"..domain_name.."/"..greet_short_file_name)) then - ivr_menu_greet_short = recordings_dir.."/"..domain_name.."/"..greet_short_file_name; - elseif (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_short_file_name)) then - ivr_menu_greet_short = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_short_file_name; - end - end + ivr_menu_greet_short = adjust_file_path(ivr_menu_greet_short, greet_short_file_name) else - ivr_menu_greet_short = ivr_menu_greet_long; + ivr_menu_greet_short = ivr_menu_greet_long end --invalid sound - if (not file_exists(ivr_menu_invalid_sound)) then - if (file_exists(recordings_dir.."/"..domain_name.."/"..invalid_sound_file_name)) then - ivr_menu_invalid_sound = recordings_dir.."/"..domain_name.."/"..invalid_sound_file_name; - elseif (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..invalid_sound_file_name)) then - ivr_menu_invalid_sound = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..invalid_sound_file_name; - end - end + ivr_menu_invalid_sound = adjust_file_path(ivr_menu_invalid_sound, invalid_sound_file_name) --exit sound - if (not file_exists(ivr_menu_exit_sound)) then - if (file_exists(recordings_dir.."/"..domain_name.."/"..exit_sound_file_name)) then - ivr_menu_exit_sound = recordings_dir.."/"..domain_name.."/"..exit_sound_file_name; - elseif (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..exit_sound_file_name)) then - ivr_menu_exit_sound = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..exit_sound_file_name; - end - end + ivr_menu_exit_sound = adjust_file_path(ivr_menu_exit_sound, exit_sound_file_name) --define the ivr menu + local menu_options, menu + local tries = 0; function menu() -- increment the tries tries = tries + 1; From 3327ecae91b76391fab585bdb10f20316d0fa1f1 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 4 Feb 2016 16:05:35 +0300 Subject: [PATCH 03/18] Use logger class. --- resources/install/scripts/ivr_menu.lua | 64 ++++++++++++++------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index f06f10df76..90af66d61c 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -38,6 +38,9 @@ require "resources.functions.database_handle"; dbh = database_handle('system'); +--get logger + local log = require "resources.functions.log".ivr_menu + --include functions require "resources.functions.format_ringback" require "resources.functions.split" @@ -50,6 +53,8 @@ caller_id_number = session:getVariable("caller_id_number"); domain_uuid = session:getVariable("domain_uuid"); + local recordings_dir = recordings_dir .. "/" .. domain_name + --settings require "resources.functions.settings"; settings = settings(domain_uuid); @@ -94,9 +99,9 @@ WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' AND ivr_menu_enabled = 'true' ]]; if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); + log.notice("SQL: " .. sql); end - status = dbh:query(sql, function(row) + dbh:query(sql, function(row) domain_uuid = row["domain_uuid"]; ivr_menu_name = row["ivr_menu_name"]; --ivr_menu_extension = row["ivr_menu_extension"]; @@ -123,12 +128,10 @@ end); --set the caller id name - if (caller_id_name) then - if (string.len(ivr_menu_cid_prefix) > 0) then - caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name; - session:setVariable("caller_id_name", caller_id_name); - session:setVariable("effective_caller_id_name", caller_id_name); - end + if caller_id_name and #caller_id_name >0 then + caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name; + session:setVariable("caller_id_name", caller_id_name); + session:setVariable("effective_caller_id_name", caller_id_name); end --set ringback @@ -167,11 +170,11 @@ require "resources.functions.mkdir"; --make sure the recordings directory exists - mkdir(recordings_dir.."/"..domain_name); + mkdir(recordings_dir); --define function to load file from db - local function load_file(recordings_dir, domain_name, file_name) - local full_path = recordings_dir.."/"..domain_name .. "/" .. file_name + local function load_file(file_name) + local full_path = recordings_dir .. "/" .. file_name if file_exists(full_path) then return full_path end @@ -180,7 +183,7 @@ [['AND recording_filename = ']]..file_name..[[' ]]; if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n"); + log.notice("SQL: "..sql); end local is_base64 @@ -188,7 +191,8 @@ if #row.recording_base64 > 32 then local file, err = io.open(full_path, "w"); if not file then - freeswitch.consoleLog("err", "[ivr_menu] can not create file: "..full_path.."; Error - " .. tostring(err) .. "\n"); + log.err("can not create file: "..full_path.."; Error - " .. tostring(err)); + return end file:write(base64.decode(row.recording_base64)); file:close(); @@ -202,22 +206,22 @@ --greet long if #ivr_menu_greet_long > 1 then - ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_file(recordings_dir, domain_name, greet_long_file_name) + ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_file(greet_long_file_name) end --greet short if #ivr_menu_greet_short > 1 then - ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_file(recordings_dir, domain_name, greet_short_file_name) + ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_file(greet_short_file_name) end --invalid sound if #ivr_menu_invalid_sound > 1 then - ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_file(recordings_dir, domain_name, invalid_sound_file_name) + ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_file(invalid_sound_file_name) end --exit sound if #ivr_menu_exit_sound > 1 then - ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(recordings_dir, domain_name, exit_sound_file_name) + ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(exit_sound_file_name) end elseif (storage_type == "http_cache") then @@ -231,7 +235,7 @@ --adjust file paths local function adjust_file_path(full_path, file_name) return file_exists(full_path) - or file_exists(recordings_dir.."/"..domain_name.."/"..file_name) + or file_exists(recordings_dir.."/"..file_name) or file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name) or full_path end @@ -267,7 +271,7 @@ end if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] greet " .. sound_type .. ": " .. sound .. "\n"); + log.notice("greet " .. sound_type .. ": " .. sound); end -- read dtmf @@ -281,7 +285,7 @@ -- proceed dtmf if dtmf_digits and #dtmf_digits > 0 then if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] dtmf_digits: " .. dtmf_digits .. "\n"); + log.notice("dtmf_digits: " .. dtmf_digits); end return menu_options(session, dtmf_digits); end @@ -290,7 +294,7 @@ if tries < tonumber(ivr_menu_max_failures) then --log the dtmf digits if (debug["tries"]) then - freeswitch.consoleLog("notice", "[ivr_menu] tries: " .. tries .. "\n"); + log.notice("tries: " .. tries); end --run the menu again return menu(); @@ -301,13 +305,13 @@ --log the dtmf digits if (debug["dtmf"]) then - freeswitch.consoleLog("notice", "[ivr_menu] dtmf: " .. digits .. "\n"); + log.notice("dtmf: " .. digits); end --get the ivr menu options sql = [[SELECT * FROM v_ivr_menu_options WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' ORDER BY ivr_menu_option_order asc ]]; if (debug["sql"]) then - freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); + log.notice("SQL: " .. sql); end local action, script, data @@ -336,8 +340,8 @@ regex = "m:~"..digits.."~"..row.ivr_menu_option_digits.."~$1" local result = trim(api:execute("regex", regex)); if (debug["regex"]) then - freeswitch.consoleLog("notice", "[ivr_menu] regex "..regex.."\n"); - freeswitch.consoleLog("notice", "[ivr_menu] result: "..result.."\n"); + log.notice("regex "..regex); + log.notice("result: "..result); end --replace the $1 and the domain name @@ -361,14 +365,14 @@ end -- we have unsupported IVR action - freeswitch.consoleLog("warning", "[ivr_menu] invalid action in ivr: " .. row.ivr_menu_option_action .. "\n"); + log.warning("invalid action in ivr: " .. row.ivr_menu_option_action); end); --end results --execute if action and #action > 0 then -- send to the log if (debug["action"]) then - freeswitch.consoleLog("notice", "[ivr_menu] action: " .. action .. " data: ".. data .. "\n"); + log.notice("action: " .. action .. " data: ".. data); end -- run the action (with return to menu) @@ -392,10 +396,10 @@ -- check to see if the user extension exists local cmd = "user_exists id ".. digits .." "..domain_name; local result = api:executeString(cmd); - freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..cmd.." "..result.."\n"); + log.notice("[direct dial] "..cmd.." "..result); if result == "true" then --log the action - freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..digits.." XML "..context.."\n"); + log.notice("[direct dial] "..digits.." XML "..context); --run the action return session:execute("transfer", digits.." XML "..context); end @@ -406,7 +410,7 @@ --invalid input try again if (debug["action"]) then - freeswitch.consoleLog("notice", "[ivr_menu] unrecgnized action \n"); + log.notice("unrecgnized action"); end if ivr_menu_invalid_sound and #ivr_menu_invalid_sound then session:streamFile(ivr_menu_invalid_sound); From 551227637013139e0f4e7c33297c8b56651bc3dd Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 4 Feb 2016 19:05:24 +0300 Subject: [PATCH 04/18] Fix. Allow multiple actions in IVR --- resources/install/scripts/ivr_menu.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 90af66d61c..3f98d6d379 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -314,7 +314,7 @@ log.notice("SQL: " .. sql); end - local action, script, data + local actions, script, data = {} dbh:query(sql, function(row) -- clear vars action, script, data = nil @@ -361,7 +361,8 @@ -- break loop if action and #action > 0 then - return 1 + actions[#actions + 1] = {action, script, data} + return end -- we have unsupported IVR action @@ -369,7 +370,9 @@ end); --end results --execute - if action and #action > 0 then + if #actions > 0 then + for _, t in ipairs(actions) do + local action, script, data = t[1],t[2],t[3] -- send to the log if (debug["action"]) then log.notice("action: " .. action .. " data: ".. data); @@ -378,14 +381,15 @@ -- run the action (with return to menu) if action == 'phrase' or script == 'streamfile.lua' then session:execute(action, data); - return menu(); + else + if ivr_menu_exit_sound and #ivr_menu_exit_sound > 0 then + session:streamFile(ivr_menu_exit_sound); + end + -- run the action (without return to menu) + return session:execute(action, data); end - - -- run the action (without return to menu) - if ivr_menu_exit_sound and #ivr_menu_exit_sound > 0 then - session:streamFile(ivr_menu_exit_sound); - end - return session:execute(action, data); + end + return menu(); end --direct dial From 9a70297909ce72d6520a3f4119a00b0446a40138 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 4 Feb 2016 19:42:42 +0300 Subject: [PATCH 05/18] Fix. Infinity loop. IVR ignores `max_failures`. --- resources/install/scripts/ivr_menu.lua | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 3f98d6d379..6349b719a7 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -256,8 +256,19 @@ local menu_options, menu local tries = 0; function menu() + -- check number of failures + if (tries > 0) and (tries >= tonumber(ivr_menu_max_failures)) then + return + end + -- increment the tries tries = tries + 1; + + --log the dtmf digits + if (debug["tries"]) then + log.notice("tries: " .. tries); + end + -- set the minimum dtmf lengts local min_digits = 1; @@ -290,15 +301,7 @@ return menu_options(session, dtmf_digits); end - -- check number of failures - if tries < tonumber(ivr_menu_max_failures) then - --log the dtmf digits - if (debug["tries"]) then - log.notice("tries: " .. tries); - end - --run the menu again - return menu(); - end + return menu(); end function menu_options(session, digits) From 1bafdba1356556f498617001f31b1eb34ce1048b Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 4 Feb 2016 20:00:12 +0300 Subject: [PATCH 06/18] Update log. --- resources/install/scripts/ivr_menu.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 6349b719a7..37d407e9c3 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -266,7 +266,7 @@ --log the dtmf digits if (debug["tries"]) then - log.notice("tries: " .. tries); + log.noticef("tries: %d/%d", tries, tonumber(ivr_menu_max_failures) or '-1'); end -- set the minimum dtmf lengts From c31047470d78d5f02e854cc5acfbe9f2e341b47d Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 5 Feb 2016 10:20:09 +0300 Subject: [PATCH 07/18] Fix. Declare vars in correct scope. --- resources/install/scripts/ivr_menu.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 37d407e9c3..09c83397fc 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -317,10 +317,10 @@ log.notice("SQL: " .. sql); end - local actions, script, data = {} + local actions = {} dbh:query(sql, function(row) - -- clear vars - action, script, data = nil + -- declare vars + local action, script, data --check for matching options if tonumber(row.ivr_menu_option_digits) then From 27dfc364df9c6f1f92be335d1314dffdeaa17730 Mon Sep 17 00:00:00 2001 From: mafoo Date: Mon, 1 Feb 2016 12:18:11 +0000 Subject: [PATCH 08/18] Fix for when a conference room has no admins If a conference room had no admins it would become impossible to see it in the GUI This fix makes it possible for a admin or super admin to view rooms in this state. this uses a new permission "conference_room_view_all" --- app/conference_centers/app_config.php | 4 +++ .../resources/classes/conference_center.php | 31 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/conference_centers/app_config.php b/app/conference_centers/app_config.php index 464bc6fd51..063076cda0 100644 --- a/app/conference_centers/app_config.php +++ b/app/conference_centers/app_config.php @@ -58,6 +58,10 @@ $apps[$x]['permissions'][$y]['groups'][] = "admin"; $apps[$x]['permissions'][$y]['groups'][] = "user"; $y++; + $apps[$x]['permissions'][$y]['name'] = "conference_room_view_all"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $apps[$x]['permissions'][$y]['groups'][] = "admin"; + $y++; $apps[$x]['permissions'][$y]['name'] = "conference_room_add"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $apps[$x]['permissions'][$y]['groups'][] = "admin"; diff --git a/app/conference_centers/resources/classes/conference_center.php b/app/conference_centers/resources/classes/conference_center.php index 9fffc7cc39..92d1c7768b 100644 --- a/app/conference_centers/resources/classes/conference_center.php +++ b/app/conference_centers/resources/classes/conference_center.php @@ -41,11 +41,18 @@ public function room_count() { //get the room count - $sql = "select count(*) as num_rows from v_conference_rooms as r, v_meeting_users as u, v_meetings as p "; + $not_admin = 1; + if (if_permision("conference_room_view_all")) { + $not_admin = 0; + } + $sql = "select count(*) as num_rows from v_conference_rooms as r, v_meetings as p "; + if ($not_admin) { + $sql .= "v_meeting_users as u, "; + } $sql .= "where r.domain_uuid = '".$this->domain_uuid."' "; - $sql .= "and r.meeting_uuid = u.meeting_uuid "; $sql .= "and r.meeting_uuid = p.meeting_uuid "; - if (!if_group("admin") && !if_group("superadmin")) { + if ($not_admin) { + $sql .= "and r.meeting_uuid = u.meeting_uuid "; $sql .= "and u.user_uuid = '".$_SESSION["user_uuid"]."' "; } if (isset($this->search)) { @@ -71,14 +78,24 @@ public function rooms() { //get the list of rooms + $not_admin = 1; + if (if_permision("conference_room_view_all")) { + $not_admin = 0; + } $fields = "r.domain_uuid, r.conference_room_uuid, r.conference_center_uuid, r.meeting_uuid, r.conference_room_name, max_members, "; $fields .= "wait_mod, announce, mute, sounds, created, created_by, r.enabled, r.description, record, "; - $fields .= "profile, meeting_user_uuid, user_uuid, moderator_pin, participant_pin "; - $sql = "select ".$fields." from v_conference_rooms as r, v_meeting_users as u, v_meetings as p "; + $fields .= "profile, moderator_pin, participant_pin"; + if ($not_admin) { + $fields .= ", meeting_user_uuid, user_uuid"; + } + $sql = "select ".$fields." from v_conference_rooms as r, v_meetings as p "; + if ($not_admin) { + $sql .= ", v_meeting_users as u "; + } $sql .= "where r.domain_uuid = '".$this->domain_uuid."' "; - $sql .= "and r.meeting_uuid = u.meeting_uuid "; $sql .= "and r.meeting_uuid = p.meeting_uuid "; - if (!if_group("admin") && !if_group("superadmin")) { + if ($not_admin) { + $sql .= "and r.meeting_uuid = u.meeting_uuid "; $sql .= "and u.user_uuid = '".$_SESSION["user_uuid"]."' "; } //if (is_numeric($this->search)) { From dcc64101be78bb00e0968c7c82f72ac6be5e3d7f Mon Sep 17 00:00:00 2001 From: skyeblueiscool Date: Fri, 5 Feb 2016 16:47:36 -0800 Subject: [PATCH 09/18] Update follow_me.php --- app/calls/resources/classes/follow_me.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/calls/resources/classes/follow_me.php b/app/calls/resources/classes/follow_me.php index 5cdf86d74e..a5bd693380 100644 --- a/app/calls/resources/classes/follow_me.php +++ b/app/calls/resources/classes/follow_me.php @@ -324,7 +324,7 @@ include "root.php"; } if (strlen($this->cid_name_prefix) > 0) { - $dial_string .= ",origination_caller_id_name=".$this->cid_name_prefix."#$dial_string_caller_id_name"; + $dial_string .= ",origination_caller_id_name=".$this->cid_name_prefix."$dial_string_caller_id_name"; } else { $dial_string .= ",origination_caller_id_name=$dial_string_caller_id_name"; @@ -332,7 +332,7 @@ include "root.php"; if (strlen($this->cid_number_prefix) > 0) { //$dial_string .= ",origination_caller_id_number=".$this->cid_number_prefix.""; - $dial_string .= ",origination_caller_id_number=".$this->cid_number_prefix."#dial_string_caller_id_number"; + $dial_string .= ",origination_caller_id_number=".$this->cid_number_prefix."$dial_string_caller_id_number"; } else { $dial_string .= ",origination_caller_id_number=$dial_string_caller_id_number"; From aa9717518fdcc0698f038e7e15b150bf5a77c4c3 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sat, 6 Feb 2016 14:53:31 -0700 Subject: [PATCH 10/18] Change the category to provision for provision ntp_server_primary, and ntp_server_secondary. --- app/provision/app_defaults.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/provision/app_defaults.php b/app/provision/app_defaults.php index da82965d6e..fd879bfa3f 100644 --- a/app/provision/app_defaults.php +++ b/app/provision/app_defaults.php @@ -186,15 +186,15 @@ $array[$x]['default_setting_enabled'] = 'false'; $array[$x]['default_setting_description'] = 'allow extensions to be provisioned as contacts as $extensions in provision templates'; $x++; - $array[$x]['default_setting_category'] = 'ntp_server_primary'; - $array[$x]['default_setting_subcategory'] = 'directory'; + $array[$x]['default_setting_category'] = 'provision'; + $array[$x]['default_setting_subcategory'] = 'ntp_server_primary'; $array[$x]['default_setting_name'] = 'text'; $array[$x]['default_setting_value'] = 'pool.ntp.org'; $array[$x]['default_setting_enabled'] = 'true'; $array[$x]['default_setting_description'] = ''; $x++; - $array[$x]['default_setting_category'] = 'ntp_server_secondary'; - $array[$x]['default_setting_subcategory'] = 'directory'; + $array[$x]['default_setting_category'] = 'provision'; + $array[$x]['default_setting_subcategory'] = 'ntp_server_secondary'; $array[$x]['default_setting_name'] = 'text'; $array[$x]['default_setting_value'] = '2.us.pool.ntp.org'; $array[$x]['default_setting_enabled'] = 'true'; From 17b89a8fc8245c79d18bf60c5a73464d22cd5a40 Mon Sep 17 00:00:00 2001 From: bdstephenson Date: Mon, 8 Feb 2016 08:48:37 -0500 Subject: [PATCH 11/18] Update W52P Provisioning Template account.1.subscribe_mwi should be set to '1' as per Yealink documentation. Not setting this may cause MWI to not work on the W52P. --- resources/templates/provision/yealink/w52p/{$mac}.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/templates/provision/yealink/w52p/{$mac}.cfg b/resources/templates/provision/yealink/w52p/{$mac}.cfg index 2509a41fbf..22515ece62 100644 --- a/resources/templates/provision/yealink/w52p/{$mac}.cfg +++ b/resources/templates/provision/yealink/w52p/{$mac}.cfg @@ -80,7 +80,7 @@ account.1.precondition = account.1.subscribe_register = #Enable or disable the phone to subscribe the message waiting indicator; 0-Disabled (default), 1-Enabled; -account.1.subscribe_mwi = +account.1.subscribe_mwi = 1 #Configure MWI subscribe expiry time (in seconds). It ranges from 0 to 84600, the default value is 3600. account.1.subscribe_mwi_expires = @@ -1219,4 +1219,4 @@ network.internet_port.ip = network.internet_port.mask = network.internet_port.gateway = network.primary_dns= -network.secondary_dns = \ No newline at end of file +network.secondary_dns = From d61c7815f95a6245938e7b55427479bc795204b7 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 10 Feb 2016 13:49:31 -0700 Subject: [PATCH 12/18] Prevent nil from crashing the lua script. --- .../install/scripts/resources/functions/explode.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/install/scripts/resources/functions/explode.lua b/resources/install/scripts/resources/functions/explode.lua index 4355a643e8..f6965f79df 100644 --- a/resources/install/scripts/resources/functions/explode.lua +++ b/resources/install/scripts/resources/functions/explode.lua @@ -2,10 +2,12 @@ --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 + if (seperator ~= nil and str ~= nil) then + 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 end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider return arr end \ No newline at end of file From 2e5e2aa3b3a044c1244c02903f0c73e7968eb890 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 10 Feb 2016 13:54:15 -0700 Subject: [PATCH 13/18] XML CDR - if the domain_uuid is not found then attempt to use sip_req_host to get the domain name. If domain_name and domain_uuid are still empty then add the CDR record with the domain_uuid as null so there is a record of the call. --- app/xml_cdr/v_xml_cdr_import.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index 236940e143..5622e9275a 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -192,6 +192,12 @@ $domain_name = check_str(urldecode($xml->variables->domain_name)); $domain_uuid = check_str(urldecode($xml->variables->domain_uuid)); + //get the domain name from sip_req_host + if (strlen($domain_name) > 0) { + $domain_name = check_str(urldecode($xml->variables->sip_req_host)); + } + + //send the domain name to the cdr log xml_cdr_log("\ndomain_name is `$domain_name`; domain_uuid is '$domain_uuid'\n"); //get the domain_uuid with the domain_name @@ -205,18 +211,16 @@ } $row = $db->query($sql)->fetch(); $domain_uuid = $row['domain_uuid']; - if (strlen($domain_uuid) == 0) { - $sql = "select domain_name, domain_uuid from v_domains "; - $row = $db->query($sql)->fetch(); - $domain_uuid = $row['domain_uuid']; - if (strlen($domain_name) == 0) { $domain_name = $row['domain_name']; } - } } //set values in the database - $database->domain_uuid = $domain_uuid; - $database->fields['domain_uuid'] = $domain_uuid; - $database->fields['domain_name'] = $domain_name; + if (strlen($domain_uuid) > 0) { + $database->domain_uuid = $domain_uuid; + $database->fields['domain_uuid'] = $domain_uuid; + } + if (strlen($domain_name) > 0) { + $database->fields['domain_name'] = $domain_name; + } //check whether a recording exists $recording_relative_path = '/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; From 9b1cb7c43ee737e3a0174fa76383a77d01d35622 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 10 Feb 2016 17:15:31 -0700 Subject: [PATCH 14/18] Fix the check to see if domain_name is not set. --- app/xml_cdr/v_xml_cdr_import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index 5622e9275a..6e0a663c01 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -193,7 +193,7 @@ $domain_uuid = check_str(urldecode($xml->variables->domain_uuid)); //get the domain name from sip_req_host - if (strlen($domain_name) > 0) { + if (strlen($domain_name) == 0) { $domain_name = check_str(urldecode($xml->variables->sip_req_host)); } From b489074e0c14b5b1f80ed69c6d8ec2648cbd8481 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 10 Feb 2016 21:44:03 -0700 Subject: [PATCH 15/18] Fax add a way to change the inbound fax file name. --- app/fax/resources/classes/fax.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/fax/resources/classes/fax.php b/app/fax/resources/classes/fax.php index 0100aeaeaa..534e48fc1d 100644 --- a/app/fax/resources/classes/fax.php +++ b/app/fax/resources/classes/fax.php @@ -160,7 +160,12 @@ $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=\${caller_id_number}-\${strftime(%Y-%m-%d-%H-%M-%S)}"; + if (strlen($_SESSION['fax']['last_fax']['text']) > 0) { + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=".$_SESSION['fax']['last_fax']['text']; + } + else { + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=\${caller_id_number}-\${strftime(%Y-%m-%d-%H-%M-%S)}"; + } $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; $y++; From 13861172a9de6bc066630b2fd4d58990e9caac26 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Thu, 11 Feb 2016 00:19:44 -0700 Subject: [PATCH 16/18] If the user is in the superadmin or admin group and user group it was preventing the fax_forward number from being updated. --- app/fax/fax_edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/fax/fax_edit.php b/app/fax/fax_edit.php index 81eec1b848..fb7004788c 100644 --- a/app/fax/fax_edit.php +++ b/app/fax/fax_edit.php @@ -820,7 +820,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo " \n"; echo "
"; if ($action == "update") { - if (if_group("user")) { + if (!permission_exists('fax_extension_delete')) { echo " \n"; echo " \n"; echo " \n"; From a7084e4b0b3b36f08a9daacf2d2fff16bcdf05b2 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Thu, 11 Feb 2016 13:35:12 -0700 Subject: [PATCH 17/18] Fix a spelling problem in the demo_ivr.xml. --- resources/templates/conf/ivr_menus/demo_ivr.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/templates/conf/ivr_menus/demo_ivr.xml b/resources/templates/conf/ivr_menus/demo_ivr.xml index d9aefaadb5..0e2c074939 100644 --- a/resources/templates/conf/ivr_menus/demo_ivr.xml +++ b/resources/templates/conf/ivr_menus/demo_ivr.xml @@ -57,8 +57,8 @@ max-failures="3"> - - + + --> From fe6a73a3d81b124eb532cb953183aab9ce60a2ac Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sun, 14 Feb 2016 03:09:55 -0700 Subject: [PATCH 18/18] Add ability to the acl.conf.xml to read a description attribute. --- app/access_controls/app_defaults.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/access_controls/app_defaults.php b/app/access_controls/app_defaults.php index 062bf8a558..2d37a7b0c9 100644 --- a/app/access_controls/app_defaults.php +++ b/app/access_controls/app_defaults.php @@ -97,6 +97,7 @@ $node_type = $row['@attributes']['type']; $node_cidr = $row['@attributes']['cidr']; $node_domain = $row['@attributes']['domain']; + $node_description = $row['@attributes']['description']; //replace $${domain} if (strlen($node_domain) > 0) { $node_domain = str_replace("\$\${domain}", $domain_name, $node_domain); @@ -109,7 +110,8 @@ $sql .= "access_control_uuid, "; $sql .= "node_type, "; $sql .= "node_cidr, "; - $sql .= "node_domain "; + $sql .= "node_domain, "; + $sql .= "node_description "; $sql .= ") "; $sql .= "values "; $sql .= "( "; @@ -117,7 +119,8 @@ $sql .= "'".$access_control_uuid."', "; $sql .= "'".$node_type."', "; $sql .= "'".$node_cidr."', "; - $sql .= "'".$node_domain."' "; + $sql .= "'".$node_domain."', "; + $sql .= "'".$node_description."' "; $sql .= ")"; //echo $sql."\n"; $db->exec(check_sql($sql));