From f819eaf65cea6191c6756cf84d694d9f7b18a33a Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 11:23:52 +0000 Subject: [PATCH 01/19] Added check will now throw if the config.lua could not be opened for writing --- core/databases/app_defaults.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/databases/app_defaults.php b/core/databases/app_defaults.php index ea4d04d6c9..71adfaced2 100644 --- a/core/databases/app_defaults.php +++ b/core/databases/app_defaults.php @@ -126,6 +126,9 @@ if ($domains_processed == 1) { $config = $_SESSION['switch']['scripts']['dir']."/resources/config.lua"; } $fout = fopen($config,"w"); + if(!$fout){ + throw new Exception("Failed to open '$config' for writing"); + } $tmp = "\n"; $tmp .= "--set the variables\n"; if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { From 40d5b5a0decbaa06411cb365a5da143d2130a575 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 13:20:04 +0000 Subject: [PATCH 02/19] fixed detection of timezone on debian removed add_new_switch temporarily, currently not supported --- core/install/index.php | 15 --------------- core/install/install_first_time.php | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/core/install/index.php b/core/install/index.php index 9011dd9574..1eb6efc8c9 100644 --- a/core/install/index.php +++ b/core/install/index.php @@ -78,21 +78,6 @@ if (!if_group("superadmin")) { echo "\n"; echo "\n"; - echo "
\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "
\n"; - echo " "; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo "

"; echo "

WiP

"; diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index b4366275fa..1416d39f69 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -63,7 +63,7 @@ if (is_link('/etc/localtime')) { // Ubuntu / Debian. $data = file_get_contents('/etc/timezone'); if ($data) { - $timezone = $data; + $timezone = rtrim($data); } } elseif (file_exists('/etc/sysconfig/clock')) { // RHEL / CentOS From ac44787e36ecdabb0ea0c2a0d8d6c061c2363bdf Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 26 Nov 2015 17:23:33 +0300 Subject: [PATCH 03/19] Fix. problem when same session can release task multiple times. It can be when originate has group dial-string. So it call `api_hangup_hook` for each channel. Now we release task in `retry.lua` only if originate success and this is same channel which execute `exec.lua`. If originate fail we release task `next.lua` --- resources/install/scripts/fax_queue/exec.lua | 6 ++++++ resources/install/scripts/fax_queue/next.lua | 13 ++++++------ resources/install/scripts/fax_queue/retry.lua | 15 ++++++++++---- resources/install/scripts/fax_queue/tasks.lua | 8 ++++++++ .../scripts/resources/functions/esl.lua | 20 ++++++++++++++----- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/resources/install/scripts/fax_queue/exec.lua b/resources/install/scripts/fax_queue/exec.lua index 7fbb58d826..98de09adb7 100644 --- a/resources/install/scripts/fax_queue/exec.lua +++ b/resources/install/scripts/fax_queue/exec.lua @@ -132,6 +132,12 @@ local function check() end local function task() + local session_uuid = session:getVariable('uuid') + + session:setVariable('fax_queue_task_session', session_uuid) + + log.infof("SESSION UUID: %s", session_uuid) + session:waitForAnswer(session) while not session:answered() do diff --git a/resources/install/scripts/fax_queue/next.lua b/resources/install/scripts/fax_queue/next.lua index 0067d0e9b4..9e7ac0081f 100644 --- a/resources/install/scripts/fax_queue/next.lua +++ b/resources/install/scripts/fax_queue/next.lua @@ -28,10 +28,6 @@ local function next_task() local esl local ok, err = pcall(function() - for k, v in pairs(task) do - print(string.format(" `%s` => `%s`", tostring(k), tostring(v))) - end - local mode = (task.retry_counter % #FAX_OPTIONS) + 1 local dial_string = '{' .. task.dial_string .. "api_hangup_hook='lua fax_queue/retry.lua'," .. @@ -42,8 +38,13 @@ local function next_task() log.notice(originate) esl = assert(Esl.new()) - local ok, err = esl:api(originate) - log.notice(ok or err) + local ok, status, info = esl:api(originate) + if not ok then + Tasks.wait_task(task, false, info) + log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info)) + else + log.noticef("originate successfuly: %s", tostring(info)) + end end) if esl then esl:close() end diff --git a/resources/install/scripts/fax_queue/retry.lua b/resources/install/scripts/fax_queue/retry.lua index ef099546b7..d22f6df7ed 100644 --- a/resources/install/scripts/fax_queue/retry.lua +++ b/resources/install/scripts/fax_queue/retry.lua @@ -10,7 +10,7 @@ local Tasks = require "fax_queue.tasks" local fax_task_uuid = env:getHeader('fax_task_uuid') - local task = Tasks.select_task(fax_task_uuid) + local task = Tasks.select_task(fax_task_uuid) if not task then log.warningf("Can not find fax task: %q", tostring(fax_task_uuid)) return @@ -25,6 +25,7 @@ -- Channel/FusionPBX variables local uuid = env:getHeader("uuid") + local fax_queue_task_session = env:getHeader('fax_queue_task_session') local domain_uuid = env:getHeader("domain_uuid") or task.domain_uuid local domain_name = env:getHeader("domain_name") or task.domain_name local origination_caller_id_name = env:getHeader("origination_caller_id_name") or '000000000000000' @@ -338,9 +339,15 @@ end end - Tasks.wait_task(task, answered, hangup_cause_q850) - if task.status ~= 0 then - Tasks.remove_task(task) + -- if task use group call then retry.lua will be called multiple times + -- here we check eathre that channel which execute `exec.lua` + -- Note that if there no one execute `exec.lua` we do not need call this + -- becase it should deal in `next.lua` + if fax_queue_task_session == uuid then + Tasks.wait_task(task, answered, hangup_cause_q850) + if task.status ~= 0 then + Tasks.remove_task(task) + end end end diff --git a/resources/install/scripts/fax_queue/tasks.lua b/resources/install/scripts/fax_queue/tasks.lua index 920f1e9087..96f6d612bf 100644 --- a/resources/install/scripts/fax_queue/tasks.lua +++ b/resources/install/scripts/fax_queue/tasks.lua @@ -103,6 +103,14 @@ local remove_finished_tasks_sql = [[ delete from v_fax_tasks where task_status > 3 ]] +local function serialize(task, header) + local str = header or '' + for k, v in pairs(task) do + str = str .. ('\n %q = %q'):format(tostring(k), tostring(v)) + end + return str +end + local function get_db() if not db then db = assert(Database.new('system')) diff --git a/resources/install/scripts/resources/functions/esl.lua b/resources/install/scripts/resources/functions/esl.lua index fcd4898754..f334be191c 100644 --- a/resources/install/scripts/resources/functions/esl.lua +++ b/resources/install/scripts/resources/functions/esl.lua @@ -117,7 +117,11 @@ function EventSocket:api(cmd) local event, err = self:_request('api ' .. cmd) if not event then return nil, err end local body = event:getBody() - if body then return body end + if body then + local ok, status, msg = split_status(body) + if ok == nil then return body end + return ok, status, msg + end return event:getReply() end @@ -134,6 +138,13 @@ if freeswitch then local api +-- [+-][OK|ERR|USAGE|...][Message] +local function split_status(str) + local ok, status, msg = string.match(str, "^%s*([-+])([^%s]+)%s*(.-)%s*$") + if not ok then return nil, str end + return ok == '+', status, msg +end + function EventSocket:__init() self._api = api or freeswitch.API() api = self._api @@ -142,10 +153,9 @@ end function EventSocket:api(cmd) local result = self._api:executeString(cmd) - if result and result:sub(1, 4) == '-ERR' then - return nil, result:sub(5) - end - return result + local ok, status, msg = split_status(result) + if ok == nil then return result end + return ok, status, msg end function EventSocket:close() From b00229e5fcfb0a941c7a1a8f907b2bcbc8fb5a80 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 26 Nov 2015 17:25:15 +0300 Subject: [PATCH 04/19] Fix. Remove task in next.lua --- resources/install/scripts/fax_queue/next.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/install/scripts/fax_queue/next.lua b/resources/install/scripts/fax_queue/next.lua index 9e7ac0081f..eaa8c0c790 100644 --- a/resources/install/scripts/fax_queue/next.lua +++ b/resources/install/scripts/fax_queue/next.lua @@ -51,6 +51,9 @@ local function next_task() if not ok then Tasks.release_task(task) + if task.status ~= 0 then + Tasks.remove_task(task) + end log.noticef("Error execute task: %s", tostring(err)) end From ed595a37081578dcb865cd8d35fe76ae437cb6c6 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 26 Nov 2015 17:30:56 +0300 Subject: [PATCH 05/19] Fix. Remove task in next.lua (Fix preview commit) --- resources/install/scripts/fax_queue/next.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/install/scripts/fax_queue/next.lua b/resources/install/scripts/fax_queue/next.lua index eaa8c0c790..9d5c0adfff 100644 --- a/resources/install/scripts/fax_queue/next.lua +++ b/resources/install/scripts/fax_queue/next.lua @@ -41,6 +41,9 @@ local function next_task() local ok, status, info = esl:api(originate) if not ok then Tasks.wait_task(task, false, info) + if task.status ~= 0 then + Tasks.remove_task(task) + end log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info)) else log.noticef("originate successfuly: %s", tostring(info)) @@ -51,9 +54,6 @@ local function next_task() if not ok then Tasks.release_task(task) - if task.status ~= 0 then - Tasks.remove_task(task) - end log.noticef("Error execute task: %s", tostring(err)) end From 02b39d9256726f5663bba83b74cf1ba7e3a26f9a Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 14:33:08 +0000 Subject: [PATCH 06/19] Corrected storage of the event_port made a warning render correctly added a warning about choosing a remote host --- core/install/install_first_time.php | 10 ++++++++++ .../resources/page_parts/install_config_database.php | 2 +- .../resources/page_parts/install_config_detail.php | 2 +- .../resources/page_parts/install_event_socket.php | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index 1416d39f69..43311d541e 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -224,6 +224,9 @@ if(!$install_step) { $install_step = 'select_language'; } echo " \n"; echo "\n"; }elseif($install_step == 'detect_config'){ + if(!($event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1')){ + echo "

Warning you have choosen a value other than localhost for event_host, this is unsoported at present

\n"; + } include "resources/page_parts/install_event_socket.php"; if($detect_ok){ echo "
\n"; @@ -238,6 +241,12 @@ if(!$install_step) { $install_step = 'select_language'; } echo " \n"; echo " \n"; echo "
\n"; + }else{ + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; } } elseif($install_step == 'config_detail'){ @@ -257,6 +266,7 @@ if(!$install_step) { $install_step = 'select_language'; } //if($_SERVER['HTTPS']) { $protocol = 'https'; } //echo ""; require_once "core/install/resources/classes/detect_switch.php"; + trigger_error("D:> using $event_host, $event_port, $event_password\n",E_USER_WARNING); $switch_detect = new detect_switch($event_host, $event_port, $event_password); $detect_ok = true; try { diff --git a/core/install/resources/page_parts/install_config_database.php b/core/install/resources/page_parts/install_config_database.php index ad8e632734..371a726b98 100644 --- a/core/install/resources/page_parts/install_config_database.php +++ b/core/install/resources/page_parts/install_config_database.php @@ -31,7 +31,7 @@ echo "\n"; echo "\n"; - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; diff --git a/core/install/resources/page_parts/install_config_detail.php b/core/install/resources/page_parts/install_config_detail.php index 8ee7597ba9..6fd2c8ce05 100644 --- a/core/install/resources/page_parts/install_config_detail.php +++ b/core/install/resources/page_parts/install_config_detail.php @@ -31,7 +31,7 @@ echo "\n"; echo "\n"; - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; diff --git a/core/install/resources/page_parts/install_event_socket.php b/core/install/resources/page_parts/install_event_socket.php index 7122925b4d..8588d13b1e 100644 --- a/core/install/resources/page_parts/install_event_socket.php +++ b/core/install/resources/page_parts/install_event_socket.php @@ -31,10 +31,10 @@ try { $switch_detect->detect(); } catch(Exception $e){ - $messages[] = "Failed to detect confgiuration detect_switch reported: " . $e->getMessage(); + echo "

Failed to detect configuration detect_switch reported: " . $e->getMessage() ."

\n"; $detect_ok = false; } - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "
\n"; From a439e7caa679ba2027c272f6067138a095512bbb Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 26 Nov 2015 17:41:48 +0300 Subject: [PATCH 07/19] Add. log session uuid --- resources/install/scripts/fax_queue/retry.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/install/scripts/fax_queue/retry.lua b/resources/install/scripts/fax_queue/retry.lua index d22f6df7ed..018cec372e 100644 --- a/resources/install/scripts/fax_queue/retry.lua +++ b/resources/install/scripts/fax_queue/retry.lua @@ -77,6 +77,7 @@ log.noticef([[<<< CALL RESULT >>> uuid: = '%s' + task_session_uuid: = '%s' answered: = '%s' fax_file: = '%s' wav_file: = '%s' @@ -91,6 +92,7 @@ fax_options = '%s' ]], tostring(uuid) , + tostring(fax_queue_task_session) , tostring(answered) , tostring(fax_file) , tostring(wav_file) , From e4d02022d6b9ca26ac1b222dd5009223314b0a32 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 14:56:56 +0000 Subject: [PATCH 08/19] moved fusionPBX install after switch install --- core/install/install_first_time.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index 311a36091a..30452fcf8c 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -294,7 +294,6 @@ if(!$install_step) { $install_step = 'select_language'; } require_once "resources/classes/install_fusionpbx.php"; $fusionPBX = new install_fusionpbx($domain_name, null, $switch_detect); $domain_uuid = $fusionPBX->domain_uuid(); - //$fusionPBX->debug = true; $fusionPBX->admin_username = $admin_username; $fusionPBX->admin_password = $admin_password; $fusionPBX->default_country = $install_default_country; @@ -305,12 +304,13 @@ if(!$install_step) { $install_step = 'select_language'; } $fusionPBX->$key = $value; } } - $fusionPBX->install(); require_once "resources/classes/install_switch.php"; $switch = new install_switch($domain_name, $domain_uuid, $switch_detect); //$switch->debug = true; + //$fusionPBX->debug = true; $switch->install(); + $fusionPBX->install(); }catch(Exception $e){ echo "\n"; echo "

Failed to install
" . $e->getMessage() . "

\n"; From b793ccba9de0c2682eb0e1a436f498676c09f177 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 15:57:32 +0000 Subject: [PATCH 09/19] changed install order --- core/install/install_first_time.php | 6 +++--- core/install/resources/classes/install_fusionpbx.php | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index 30452fcf8c..e31be9e062 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -221,7 +221,7 @@ if(!$install_step) { $install_step = 'select_language'; } echo " \n"; echo "\n"; }elseif($install_step == 'detect_config'){ - if(!($event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1')){ + if(!($event_host == '' || $event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1' )){ echo "

Warning you have choosen a value other than localhost for event_host, this is unsoported at present

\n"; } include "resources/page_parts/install_event_socket.php"; @@ -263,7 +263,6 @@ if(!$install_step) { $install_step = 'select_language'; } //if($_SERVER['HTTPS']) { $protocol = 'https'; } //echo ""; require_once "core/install/resources/classes/detect_switch.php"; - trigger_error("D:> using $event_host, $event_port, $event_password\n",E_USER_WARNING); $switch_detect = new detect_switch($event_host, $event_port, $event_password); $detect_ok = true; try { @@ -309,8 +308,9 @@ if(!$install_step) { $install_step = 'select_language'; } $switch = new install_switch($domain_name, $domain_uuid, $switch_detect); //$switch->debug = true; //$fusionPBX->debug = true; - $switch->install(); $fusionPBX->install(); + $switch->install(); + $fusionPBX->app_defaults(); }catch(Exception $e){ echo "\n"; echo "

Failed to install
" . $e->getMessage() . "

\n"; diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index 6d62060939..9c70cb7b2c 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -94,7 +94,6 @@ include "root.php"; $this->create_superuser(); require "resources/require.php"; $this->create_menus(); - $this->app_defaults(); } protected function create_config_php() { From 64e42958b390ea0564529093bba305ee2c3dc379 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 16:57:34 +0000 Subject: [PATCH 10/19] moved restart and unprotected app_defaults --- core/install/install_first_time.php | 1 + core/install/resources/classes/install_fusionpbx.php | 2 +- core/install/resources/classes/install_switch.php | 3 --- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index e31be9e062..99f0ab043a 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -311,6 +311,7 @@ if(!$install_step) { $install_step = 'select_language'; } $fusionPBX->install(); $switch->install(); $fusionPBX->app_defaults(); + $detect_switch->restart_switch(); }catch(Exception $e){ echo "\n"; echo "

Failed to install
" . $e->getMessage() . "

\n"; diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index 9c70cb7b2c..57ee0c6403 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -975,7 +975,7 @@ include "root.php"; } } - protected function app_defaults() { + public function app_defaults() { $this->write_progress("Running app_defaults"); //set needed session settings diff --git a/core/install/resources/classes/install_switch.php b/core/install/resources/classes/install_switch.php index 97b12dd37a..715c2cef5b 100644 --- a/core/install/resources/classes/install_switch.php +++ b/core/install/resources/classes/install_switch.php @@ -176,9 +176,6 @@ include "root.php"; function install() { $this->copy_conf(); $this->copy_scripts(); - //tell freeswitch to restart - $this->write_progress("Restarting switch"); - $this->detect_switch->restart_switch(); } function upgrade() { From ca6bd18b64dc2296d7e06033906a920002701050 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 17:53:02 +0000 Subject: [PATCH 11/19] Corrected incorrect merge --- core/upgrade/app_defaults.php | 6 ++---- core/upgrade/index.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/upgrade/app_defaults.php b/core/upgrade/app_defaults.php index b5625f3e7a..a904361bb8 100644 --- a/core/upgrade/app_defaults.php +++ b/core/upgrade/app_defaults.php @@ -34,10 +34,8 @@ if ($domains_processed == 1) { } //copy the files and directories from resources/install - $install = new install; - $install->domain_uuid = $domain_uuid; - $install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir']; - $install->copy_scripts(); + $obj = new install_switch; + $obj->upgrade(); } //update the software table diff --git a/core/upgrade/index.php b/core/upgrade/index.php index ef686b4b33..6a83f51e10 100644 --- a/core/upgrade/index.php +++ b/core/upgrade/index.php @@ -72,10 +72,8 @@ if (sizeof($_POST) > 0) { //update scripts folder, if allowed (default) if ($_SESSION['switch']['scripts']['dir'] != '') { //copy the files and directories from resources/install - $install = new install; - $install->domain_uuid = $domain_uuid; - $install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir']; - $install->copy_scripts(); + $obj = new install_switch; + $obj->upgrade(); //set the message $response_message = $text['message-upgrade_source_scripts']; } From 55e463b0fffb18503440674eb2f96c30ac773a69 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 18:12:35 +0000 Subject: [PATCH 12/19] populate event_socket_* for core/upgrade/app_defaults --- core/install/resources/classes/install_fusionpbx.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index 57ee0c6403..ebfccc3de1 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -983,7 +983,10 @@ include "root.php"; $_SESSION["domain_uuid"] = $this->_domain_uuid; require $this->config_php; require "resources/require.php"; - + $_SESSION['event_socket_ip_address'] = $this->detect_switch->event_host; + $_SESSION['event_socket_port'] = $this->detect_switch->event_port; + $_SESSION['event_socket_password'] = $this->detect_switch->event_password; + //get the groups assigned to the user and then set the groups in $_SESSION["groups"] $sql = "SELECT * FROM v_group_users "; $sql .= "where domain_uuid=:domain_uuid "; From f45881ec4ba173dc61ebac15bb7e4c0bc79a3611 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 18:24:09 +0000 Subject: [PATCH 13/19] moved upgrade function from app_defaults moved upgrade function out to upgrade.php otherwise during initial install all app_defaults get run twice --- core/install/resources/classes/install_fusionpbx.php | 4 ---- core/upgrade/app_defaults.php | 11 ----------- core/upgrade/upgrade.php | 5 ++++- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index ebfccc3de1..d72a42e4bc 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -1018,10 +1018,6 @@ include "root.php"; $_SESSION['permissions'] = $prep_statementsub->fetchAll(PDO::FETCH_NAMED); unset($sql, $prep_statementsub); - - - - require_once "resources/classes/schema.php"; global $db, $db_type, $db_name, $db_username, $db_password, $db_host, $db_path, $db_port; diff --git a/core/upgrade/app_defaults.php b/core/upgrade/app_defaults.php index a904361bb8..18edf8e23e 100644 --- a/core/upgrade/app_defaults.php +++ b/core/upgrade/app_defaults.php @@ -26,17 +26,6 @@ if ($domains_processed == 1) { - //process if the scripts directory exists - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - //if the resource scripts resource directory does not exist then create it - if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) { - mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true); - } - - //copy the files and directories from resources/install - $obj = new install_switch; - $obj->upgrade(); - } //update the software table $sql = "select count(*) as num_rows from v_software "; diff --git a/core/upgrade/upgrade.php b/core/upgrade/upgrade.php index 0a882c14c1..119d249bab 100644 --- a/core/upgrade/upgrade.php +++ b/core/upgrade/upgrade.php @@ -67,7 +67,10 @@ $obj = new schema; echo $obj->schema("text"); -//run all app_defaults.php files +//request teh switch to perform upgrade functions + $obj = new install_switch; + $obj->upgrade(); + require_once "resources/classes/domains.php"; $domain = new domains; $domain->upgrade(); From 14b873f5dbfa133161b768bade6f16a35e5abf04 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 18:25:46 +0000 Subject: [PATCH 14/19] corrected spelling mistake --- core/upgrade/upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/upgrade/upgrade.php b/core/upgrade/upgrade.php index 119d249bab..3698ef8332 100644 --- a/core/upgrade/upgrade.php +++ b/core/upgrade/upgrade.php @@ -67,7 +67,7 @@ $obj = new schema; echo $obj->schema("text"); -//request teh switch to perform upgrade functions +//request the switch to perform upgrade functions $obj = new install_switch; $obj->upgrade(); From 6cb5fb5f5d123997bffa7c094657058eb6b88d7a Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 18:35:11 +0000 Subject: [PATCH 15/19] incorrect reference to get the switch to restart --- core/install/install_first_time.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index 99f0ab043a..5d4392e586 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -311,7 +311,7 @@ if(!$install_step) { $install_step = 'select_language'; } $fusionPBX->install(); $switch->install(); $fusionPBX->app_defaults(); - $detect_switch->restart_switch(); + $switch->detect_switch->restart_switch(); }catch(Exception $e){ echo "\n"; echo "

Failed to install
" . $e->getMessage() . "

\n"; From 98ba8ea089a44dddeb0e22ab1b80a2250dccb1d2 Mon Sep 17 00:00:00 2001 From: Matthew Vale Date: Thu, 26 Nov 2015 18:45:11 +0000 Subject: [PATCH 16/19] corrected use of detect --- core/install/install_first_time.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php index 5d4392e586..2a4c5ce344 100644 --- a/core/install/install_first_time.php +++ b/core/install/install_first_time.php @@ -311,7 +311,7 @@ if(!$install_step) { $install_step = 'select_language'; } $fusionPBX->install(); $switch->install(); $fusionPBX->app_defaults(); - $switch->detect_switch->restart_switch(); + $switch_detect->restart_switch(); }catch(Exception $e){ echo "\n"; echo "

Failed to install
" . $e->getMessage() . "

\n"; From 2aaba3b440a57773c9cfc129a9f00ed0283b9bde Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 27 Nov 2015 14:50:08 +0300 Subject: [PATCH 17/19] Fix. Use wrapper bat file to v_malito.php on Windows. Tested on WAMP and OpenServer. --- resources/switch.php | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/resources/switch.php b/resources/switch.php index e4eb04c532..9088a49638 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -1267,10 +1267,24 @@ if (!function_exists('switch_conf_xml')) { //prepare the php variables if (stristr(PHP_OS, 'WIN')) { - $bindir = getenv(PHPRC); - $v_mailer_app ='""'. $bindir."/php". '" -f '.$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure/v_mailto.php -- "'; - $v_mailer_app = sprintf("'%s'", $v_mailer_app); + $bindir = find_php_by_extension(); + if(!$bindir) + $bindir = getenv(PHPRC); + + $secure_path = path_join($_SERVER["DOCUMENT_ROOT"], PROJECT_PATH, 'secure'); + + $v_mail_bat = path_join($secure_path, 'v_mailto.bat'); + $v_mail_cmd = '@' . + '"' . str_replace('/', '\\', path_join($bindir, 'php.exe')) . '" ' . + '"' . str_replace('/', '\\', path_join($secure_path, 'v_mailto.php')) . '" '; + + $fout = fopen($v_mail_bat, "w+"); + fwrite($fout, $v_mail_cmd); + fclose($fout); + + $v_mailer_app = '"' . str_replace('/', '\\', $v_mail_bat) . '"'; $v_mailer_app_args = ""; + unset($v_mail_bat, $v_mail_cmd, $secure_path, $bindir, $fout); } else { if (file_exists(PHP_BINDIR.'/php')) { define("PHP_BIN", "php"); } @@ -1453,4 +1467,50 @@ if (!function_exists('save_switch_xml')) { } } +if(!function_exists('path_join')) { + function path_join() { + $args = func_get_args(); + $paths = array(); + foreach ($args as $arg) { + $paths = array_merge($paths, (array)$arg); + } + + $prefix = null; + foreach($paths as &$path) { + if($prefix === null && strlen($path) > 0) { + if(substr($path, 0, 1) == '/') $prefix = '/'; + else $prefix = ''; + } + $path = trim( $path, '/' ); + } + + if($prefix === null){ + return ''; + } + + $paths = array_filter($paths); + + return $prefix . join('/', $paths); + } +} + +if(!function_exists('find_php_by_extension')) { + /*Tesetd on WAMP and OpenServer*/ + function find_php_by_extension(){ + $bin_dir = get_cfg_var('extension_dir'); + + while($bin_dir){ + $bin_dir = dirname($bin_dir); + $php_bin = path_join($bin_dir, 'php.exe'); + if(file_exists($php_bin)) + break; + } + + if(!$bin_dir) + return false; + + return $bin_dir; + } +} + ?> From 406e95ab292c6999f9a64dc107b86aa1f7e9cbfa Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 27 Nov 2015 15:34:58 +0300 Subject: [PATCH 18/19] Add. `send_mail` wrapper function to freeswitch.email and v_mailto.php. Fix. Send voicemail when set unknown language/dialect. --- .../resources/functions/send_email.lua | 45 ++++---- .../scripts/resources/functions/send_mail.lua | 107 ++++++++++++++++++ 2 files changed, 130 insertions(+), 22 deletions(-) create mode 100644 resources/install/scripts/resources/functions/send_mail.lua diff --git a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua index 7009932369..0cb437c19e 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua @@ -23,6 +23,12 @@ -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. + local send_mail = require 'resources.functions.send_mail' + + local function T(str) + return text[str][default_language..'-'..default_dialect] or text[str]['en-us'] + end + --define a function to send email function send_email(id, uuid) --get voicemail message details @@ -103,10 +109,12 @@ end --prepare the headers - headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; - headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; - headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",'; - headers = headers..'"X-FusionPBX-Email-Type":"voicemail"}'; + local headers = { + ["X-FusionPBX-Domain-UUID"] = domain_uuid; + ["X-FusionPBX-Domain-Name"] = domain_name; + ["X-FusionPBX-Call-UUID"] = uuid; + ["X-FusionPBX-Email-Type"] = 'voicemail'; + } --prepare the subject local f = io.open(file_subject, "r"); @@ -134,11 +142,11 @@ body = body:gsub("${sip_to_user}", id); body = body:gsub("${dialed_user}", id); if (voicemail_file == "attach") then - body = body:gsub("${message}", text['label-attached'][default_language.."-"..default_dialect]); + body = body:gsub("${message}", T'label-attached'); elseif (voicemail_file == "link") then - body = body:gsub("${message}", ""..text['label-download'][default_language.."-"..default_dialect]..""); + body = body:gsub("${message}", ""..T'label-download'..""); else - body = body:gsub("${message}", ""..text['label-listen'][default_language.."-"..default_dialect]..""); + body = body:gsub("${message}", ""..T'label-listen'..""); end body = body:gsub(" ", " "); body = body:gsub("%s+", ""); @@ -147,22 +155,15 @@ body = body:gsub("\n", ""); body = trim(body); - --send the email + --prepare file file = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; - if (voicemail_file == "attach") then - freeswitch.email("", - "", - "To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nX-Headers: "..headers.."\nSubject: "..subject, - body, - file - ); - else - freeswitch.email("", - "", - "To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nX-Headers: "..headers.."\nSubject: "..subject, - body - ); - end + + --send the email + send_mail(headers, + voicemail_mail_to, + {subject, body}, + (voicemail_file == "attach") and file + ); end --whether to keep the voicemail message and details local after email diff --git a/resources/install/scripts/resources/functions/send_mail.lua b/resources/install/scripts/resources/functions/send_mail.lua new file mode 100644 index 0000000000..706e6c80b3 --- /dev/null +++ b/resources/install/scripts/resources/functions/send_mail.lua @@ -0,0 +1,107 @@ + +local send_mail + +if not freeswitch then + local Settings = require "resources.functions.lazy_settings" + local Database = require "resources.functions.database" + local log = require "resources.functions.log".sendmail + local sendmail = require "sendmail" + local uuid = require "uuid" + + function send_mail(headers, address, message, file) + local domain_uuid = headers["X-FusionPBX-Domain-UUID"] + local domain_name = headers["X-FusionPBX-Domain-Name"] + local email_type = headers["X-FusionPBX-Email-Type"] or 'info' + local call_uuid = headers["X-FusionPBX-Email-Type"] + local db = dbh or Database.new('system') + local settings = Settings.new(db, domain_name, domain_uuid) + + local ssl = settings:get('email', 'smtp_secure', 'var'); + + local ok, err = sendmail{ + server = { + address = settings:get('email','smtp_host','var'); + user = settings:get('email','smtp_username','var'); + password = settings:get('email','smtp_password','var'); + ssl = (ssl == 'true') and { verify = {"none"} }; + }, + + from = { + title = settings:get('email', 'smtp_from_name', 'var'); + address = settings:get('email', 'smtp_from', 'var'); + }, + + to = { + address = address; + }, + + message = message; + file = file; + } + + if not ok then + log.warningf("Mailer Error: %s", err) + + local email_uuid = uuid.new() + local sql = "insert into v_emails ( " + sql = sql .. "email_uuid, " + if call_uuid then sql = sql .. "call_uuid, " end + sql = sql .. "domain_uuid, " + sql = sql .. "sent_date, " + sql = sql .. "type, " + sql = sql .. "status, " + sql = sql .. "email " + sql = sql .. ") values ( " + sql = sql .. "'" .. email_uuid .. "', " + if call_uuid then sql = sql .. "'" .. call_uuid .. "', " end + sql = sql .. "'" .. domain_uuid .. "', " + sql = sql .. "now()," + sql = sql .. "'" .. email_type .. "', " + sql = sql .. "'failed', " + sql = sql .. "'' " + sql = sql .. ") " + + db:query(sql) + + log.infof("Retained in v_emails as email_uuid = %s", email_uuid) + else + log.infof("Mail to %s sent!", address) + end + end +end + +if freeswitch then + function send_mail(headers, address, message, file) + local xheaders = "{" + for k,v in pairs(headers) do + xheaders = xheaders .. ("'%s':'%s',"):format(k, v) + end + xheaders = xheaders:sub(1,-2) .. '}' + + local subject = message[1] + local body = message[2] or '' + + local mail_headers = + "To: " .. address .. "\n" .. + "From: " .. address .. "\n" .. + "Subject: " .. subject .. "\n" .. + "X-Headers: " .. xheaders + + if file then + freeswitch.email(address, address, mail_headers, body, file) + else + freeswitch.email(address, address, mail_headers, body, file) + end + end +end + +return send_mail + +-- local headers = { +-- ["X-FusionPBX-Domain-UUID"] = '2d171c4c-b237-49ca-9d76-9cffc1618fa7'; +-- ["X-FusionPBX-Domain-Name"] = 'domain.com'; +-- ["X-FusionPBX-Email-Type"] = 'voicemail'; +-- } +-- send_mail(headers, 'alexey@domain.com', {'hello', 'world'}) + + From 83022b60b2f67877e687fc542de45dbd10ed7960 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 27 Nov 2015 16:29:52 +0300 Subject: [PATCH 19/19] Fix. json encode x-headers --- resources/install/scripts/resources/functions/send_mail.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/install/scripts/resources/functions/send_mail.lua b/resources/install/scripts/resources/functions/send_mail.lua index 706e6c80b3..52f8e647e4 100644 --- a/resources/install/scripts/resources/functions/send_mail.lua +++ b/resources/install/scripts/resources/functions/send_mail.lua @@ -74,7 +74,7 @@ if freeswitch then function send_mail(headers, address, message, file) local xheaders = "{" for k,v in pairs(headers) do - xheaders = xheaders .. ("'%s':'%s',"):format(k, v) + xheaders = xheaders .. ('"%s":"%s",'):format(k, v) end xheaders = xheaders:sub(1,-2) .. '}'