From 455a1a088f3476fbe9576030fa5ff768f68bb86f Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Tue, 10 Nov 2015 19:29:06 +0300 Subject: [PATCH] Fix. hungup_rx.lua works on Windows 1. Command should use only double quotes. 2. Application should not be quoted (I am not sure may be it is bug in FS `system` command). So I use double quote on Windows and single quote on other system. Also I quote strings only if they contain spaces. To escape quote in string i just double it. `you got "some text"` become to `you got ""some text"""` --- .../app/fax/resources/scripts/hangup_rx.lua | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua index 81ac0ffd13..816c3cb406 100644 --- a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua +++ b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua @@ -41,6 +41,16 @@ --array count require "resources.functions.count"; + local IS_WINDOWS = (package.config:sub(1,1) == '\\') + + local function Q(s) + local q = IS_WINDOWS and '"' or "'" + if s:find('%s') then + s = q .. s:gsub(q, q..q) .. q + end + return s + end + -- set channel variables to lua variables domain_uuid = env:getHeader("domain_uuid"); domain_name = env:getHeader("domain_name"); @@ -181,23 +191,16 @@ end --fax to email - cmd = "'"..php_dir.."/"..php_bin.."' '"..document_root.."/secure/fax_to_email.php' "; - cmd = cmd .. "email='"..fax_email.."' "; - cmd = cmd .. "extension="..fax_extension.." "; - cmd = cmd .. "name='"..fax_file.."' "; - cmd = cmd .. "messages='result:"..fax_result_text.." sender:"..fax_remote_station_id.." pages:"..fax_document_total_pages.."' "; - cmd = cmd .. "domain="..domain_name.." "; - cmd = cmd .. "caller_id_name='"; - if (caller_id_name ~= nil) then - cmd = cmd .. caller_id_name; - end - cmd = cmd .. "' "; - cmd = cmd .. "caller_id_number="; - if (caller_id_number ~= nil) then - cmd = cmd .. caller_id_number; - end - cmd = cmd .. " "; - if (string.len(fax_forward_number) > 0) then + + cmd = Q(php_dir.."/"..php_bin).." "..Q(document_root.."/secure/fax_to_email.php").." "; + cmd = cmd .. "email="..Q(fax_email).." "; + cmd = cmd .. "extension="..Q(fax_extension).." "; + cmd = cmd .. "name="..Q(fax_file).." "; + cmd = cmd .. "messages=" .. Q("result:"..fax_result_text.." sender:"..fax_remote_station_id.." pages:"..fax_document_total_pages).." "; + cmd = cmd .. "domain="..Q(domain_name).." "; + cmd = cmd .. "caller_id_name=" .. Q(caller_id_name or '') .. " "; + cmd = cmd .. "caller_id_number=" .. Q(caller_id_number or '') .. " "; + if #fax_forward_number > 0 then cmd = cmd .. "fax_relay=true "; end freeswitch.consoleLog("notice", "[fax] command: " .. cmd .. "\n");