From 5059613a404ff79c9bdc8b4538b26a36fab77712 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 2 Jul 2015 13:14:35 +0400 Subject: [PATCH 1/7] Change. Does not use `default` dialplan/directory. I think it more consistent that it allows edit domain in single place. Also on my Windows machine while installing all users/context creates not in `default` directory. And I have problem because remove users did not work, `default.xml` file contain `$${v_domain}` variables. --- app/call_broadcast/call_broadcast_send.php | 9 ++------- app/click_to_call/click_to_call.php | 7 +------ app/dialplan/resources/classes/dialplan.php | 16 ++++------------ app/extensions/resources/classes/extension.php | 9 +-------- app/hot_desking/extension_edit.php | 7 +------ resources/switch.php | 14 ++------------ 6 files changed, 11 insertions(+), 51 deletions(-) diff --git a/app/call_broadcast/call_broadcast_send.php b/app/call_broadcast/call_broadcast_send.php index 4b7df2a84f..1ccf411c42 100644 --- a/app/call_broadcast/call_broadcast_send.php +++ b/app/call_broadcast/call_broadcast_send.php @@ -46,7 +46,7 @@ function cmd_async($cmd) { //windows if (stristr(PHP_OS, 'WIN')) { $descriptorspec = array( - 0 => array("pipe", "r"), // stdin + 0 => array("pipe", "r"), // stdin 1 => array("pipe", "w"), // stdout 2 => array("pipe", "w") // stderr ); @@ -176,12 +176,7 @@ function cmd_async($cmd) { $origination_url = "{".$channel_variables."}".$bridge_array[0]; //get the context - if (count($_SESSION["domains"]) > 1) { - $context = $_SESSION['domain_name']; - } - else { - $context = "default"; - } + $context = $_SESSION['domain_name']; //set the command $cmd = "bgapi sched_api +".$sched_seconds." ".$call_broadcast_uuid." bgapi originate ".$origination_url." ".$broadcast_destination_data." XML $context"; diff --git a/app/click_to_call/click_to_call.php b/app/click_to_call/click_to_call.php index 398586aa8f..cc4fe7323a 100644 --- a/app/click_to_call/click_to_call.php +++ b/app/click_to_call/click_to_call.php @@ -73,12 +73,7 @@ if (is_array($_REQUEST) && !empty($_REQUEST['src']) && !empty($_REQUEST['dest']) $sip_auto_answer = ''; } if (strlen($cid_number) == 0) { $cid_number = $src;} - if (strlen($_SESSION['context']) > 0) { - $context = $_SESSION['context']; - } - else { - $context = 'default'; - } + $context = $_SESSION['context']; //workaround for TBDialout on Thunderbird //seems it can only handle the first %NUM% diff --git a/app/dialplan/resources/classes/dialplan.php b/app/dialplan/resources/classes/dialplan.php index 5e27d2654f..c828cc25b1 100644 --- a/app/dialplan/resources/classes/dialplan.php +++ b/app/dialplan/resources/classes/dialplan.php @@ -192,18 +192,10 @@ include "root.php"; $file_default_path = $src_dir.'/dialplan/default.xml'; $file_default_contents = file_get_contents($file_default_path); //prepare the file contents and the path - if (count($_SESSION['domains']) < 2) { - //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number - $file_default_contents = str_replace("{v_domain}", 'default', $file_default_contents); - //set the file path - $file_path = $switch_dialplan_dir.'/default.xml'; - } - else { - //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number - $file_default_contents = str_replace("{v_domain}", $_SESSION['domain_name'], $file_default_contents); - //set the file path - $file_path = $switch_dialplan_dir.'/'.$_SESSION['domain_name'].'.xml'; - } + //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number + $file_default_contents = str_replace("{v_domain}", $_SESSION['domain_name'], $file_default_contents); + //set the file path + $file_path = $switch_dialplan_dir.'/'.$_SESSION['domain_name'].'.xml'; //write the default dialplan $fh = fopen($file_path,'w') or die('Unable to write to '.$file_path.'. Make sure the path exists and permissons are set correctly.'); fwrite($fh, $file_default_contents); diff --git a/app/extensions/resources/classes/extension.php b/app/extensions/resources/classes/extension.php index a1eb923c5b..e1aef02f50 100644 --- a/app/extensions/resources/classes/extension.php +++ b/app/extensions/resources/classes/extension.php @@ -159,16 +159,9 @@ //declare global variables global $config, $db, $domain_uuid; - //get the context based from the domain_uuid - if (count($_SESSION['domains']) == 1) { - $user_context = "default"; - } - else { - $user_context = $_SESSION['domains'][$domain_uuid]['domain_name']; - } - //get the domain_name $domain_name = $_SESSION['domains'][$domain_uuid]['domain_name']; + $user_context = $domain_name; //delete all old extensions to prepare for new ones $dialplan_list = glob($_SESSION['switch']['extensions']['dir']."/".$user_context."/v_*.xml"); diff --git a/app/hot_desking/extension_edit.php b/app/hot_desking/extension_edit.php index 86cb81dd1b..b511cb4127 100644 --- a/app/hot_desking/extension_edit.php +++ b/app/hot_desking/extension_edit.php @@ -94,12 +94,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { else { //if the user_context was not set then set the default value if (strlen($user_context) == 0) { - if (count($_SESSION["domains"]) > 1) { - $user_context = $_SESSION['domain_name']; - } - else { - $user_context = "default"; - } + $user_context = $_SESSION['domain_name']; } } diff --git a/resources/switch.php b/resources/switch.php index 1919eb77c0..20a2c3dcab 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -211,12 +211,7 @@ function load_extensions() { } //if no extension has been assigned then setting the user_context will still need to be set if (strlen($_SESSION['user_context']) == 0) { - if (count($_SESSION['domains']) == 1) { - $_SESSION['user_context'] = "default"; - } - else { - $_SESSION['user_context'] = $_SESSION['domain_name']; - } + $_SESSION['user_context'] = $_SESSION['domain_name']; } } } @@ -1906,12 +1901,7 @@ function save_dialplan_xml() { global $db, $domain_uuid; //get the context based from the domain_uuid - if (count($_SESSION['domains']) == 1) { - $user_context = "default"; - } - else { - $user_context = $_SESSION['domains'][$domain_uuid]['domain_name']; - } + $user_context = $_SESSION['domains'][$domain_uuid]['domain_name']; //prepare for dialplan .xml files to be written. delete all dialplan files that are prefixed with dialplan_ and have a file extension of .xml $dialplan_list = glob($_SESSION['switch']['dialplan']['dir'] . "/*/*v_dialplan*.xml"); From 3da348fff0c4ec6879d15449dfa575f949fdc762 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Wed, 22 Jul 2015 13:20:51 +0400 Subject: [PATCH 2/7] Change. Use `require "resources.functions.config"` to load config file. Change. Move `script_dir` definition into config file. --- core/databases/app_defaults.php | 41 ++++++++++++++----- resources/install/scripts/app.lua | 4 +- .../resources/scripts/start_recording.lua | 4 +- .../app/fax/resources/scripts/hangup_rx.lua | 4 +- .../install/scripts/app/provision/index.lua | 5 --- .../ring_groups/resources/scripts/confirm.lua | 2 +- .../app/voicemail/resources/scripts/mwi.lua | 4 +- resources/install/scripts/call_flow.lua | 4 +- .../install/scripts/call_flow_monitor.lua | 4 +- resources/install/scripts/call_forward.lua | 4 +- resources/install/scripts/cidlookup.lua | 4 +- .../install/scripts/destination_caller_id.lua | 4 +- resources/install/scripts/dial_string.lua | 4 +- resources/install/scripts/directory.lua | 9 +--- .../scripts/disa.callback.loopback.lua | 4 +- resources/install/scripts/disa.callback.lua | 4 +- resources/install/scripts/disa.plus.lua | 4 +- resources/install/scripts/do_not_disturb.lua | 4 +- resources/install/scripts/eavesdrop.lua | 4 +- resources/install/scripts/extension_queue.lua | 4 +- resources/install/scripts/fax_retry.lua | 4 +- resources/install/scripts/follow_me.lua | 4 +- resources/install/scripts/intercept.lua | 4 +- resources/install/scripts/intercept_group.lua | 4 +- resources/install/scripts/ivr_menu.lua | 4 +- resources/install/scripts/park.lua | 4 +- resources/install/scripts/park_monitor.lua | 4 +- resources/install/scripts/recordings.lua | 4 +- .../scripts/resources/functions/config.lua | 20 +++++++-- resources/install/scripts/streamfile.lua | 4 +- .../conf/autoload_configs/lua.conf.xml | 2 +- 31 files changed, 75 insertions(+), 104 deletions(-) diff --git a/core/databases/app_defaults.php b/core/databases/app_defaults.php index 7c40fae423..dfd247334e 100644 --- a/core/databases/app_defaults.php +++ b/core/databases/app_defaults.php @@ -24,6 +24,22 @@ Mark J Crane */ +global $IS_WINDOWS; + +if ($IS_WINDOWS == null) { + if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } +} + +if (!function_exists('correct_path')) { + function correct_path($p) { + global $IS_WINDOWS; + if ($IS_WINDOWS) { + return str_replace('/', '\\', $p); + } + return $p; + } +} + //proccess this only one time if ($domains_processed == 1) { @@ -113,28 +129,31 @@ if ($domains_processed == 1) { $tmp = "\n"; $tmp .= "--set the variables\n"; if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { - $tmp .= " sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"; + $tmp .= correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"); } if (strlen($_SESSION['switch']['db']['dir']) > 0) { - $tmp .= " database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"; + $tmp .= correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"); } if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - $tmp .= " recordings_dir = [[".$recordings_dir."]];\n"; + $tmp .= correct_path(" recordings_dir = [[".$recordings_dir."]];\n"); } if (strlen($_SESSION['switch']['storage']['dir']) > 0) { - $tmp .= " storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"; + $tmp .= correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"); } if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) { - $tmp .= " voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"; + $tmp .= correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"); } - $tmp .= " php_dir = [[".PHP_BINDIR."]];\n"; + if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { + $tmp .= correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n"); + } + $tmp .= correct_path(" php_dir = [[".PHP_BINDIR."]];\n"); if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { $tmp .= " php_bin = \"php.exe\";\n"; } else { $tmp .= " php_bin = \"php\";\n"; } - $tmp .= " document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"; + $tmp .= correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"); $tmp .= "\n"; if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) { @@ -142,7 +161,7 @@ if ($domains_processed == 1) { $tmp .= " database = {}\n"; $tmp .= " database[\"type\"] = \"".$db_type."\";\n"; $tmp .= " database[\"name\"] = \"".$db_name."\";\n"; - $tmp .= " database[\"path\"] = \"".$db_path."\";\n"; + $tmp .= correct_path(" database[\"path\"] = [[".$db_path."]];\n"); if (strlen($dsn_name) > 0) { $tmp .= " database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n"; @@ -166,19 +185,19 @@ if ($domains_processed == 1) { $tmp .= "--additional info\n"; $tmp .= " domain_count = ".count($_SESSION["domains"]).";\n"; - $tmp .= " temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"; + $tmp .= correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"); if (isset($_SESSION['domain']['dial_string']['text'])) { $tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n"; } $tmp .= "\n"; $tmp .= "--include local.lua\n"; - $tmp .= " dofile(scripts_dir..\"/resources/functions/file_exists.lua\");\n"; + $tmp .= " require(\"resources.functions.file_exists\");\n"; $tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n"; $tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n"; $tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n"; $tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n"; $tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n"; - $tmp .= " dofile(scripts_dir..\"/resources/local.lua\");\n"; + $tmp .= " require(\"resources.local\");\n"; $tmp .= " end\n"; fwrite($fout, $tmp); unset($tmp); diff --git a/resources/install/scripts/app.lua b/resources/install/scripts/app.lua index 4d6f0c4361..6f90a8b836 100644 --- a/resources/install/scripts/app.lua +++ b/resources/install/scripts/app.lua @@ -25,9 +25,7 @@ --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --get the argv values script_name = argv[0]; diff --git a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua index b2a9da42c6..018f60a92f 100644 --- a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua +++ b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua @@ -1,7 +1,5 @@ --get the scripts directory and include the config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --additional includes dofile(scripts_dir.."/resources/functions/file_exists.lua"); 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 e7e623d2d9..1d2e158291 100644 --- a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua +++ b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua @@ -26,9 +26,7 @@ api = freeswitch.API(); --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/app/provision/index.lua b/resources/install/scripts/app/provision/index.lua index f0b910f3b7..7d4b9a6468 100644 --- a/resources/install/scripts/app/provision/index.lua +++ b/resources/install/scripts/app/provision/index.lua @@ -44,11 +44,6 @@ tries = 0; profile = "internal"; ---include config.lua - --scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - --dofile(scripts_dir.."/resources/functions/config.lua"); - --dofile(config()); - --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); diff --git a/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua b/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua index b934862092..9af1d1e470 100644 --- a/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua +++ b/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua @@ -23,7 +23,7 @@ -- Mark J Crane --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + require "resources.functions.config"; --set variables max_tries = "3"; diff --git a/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua b/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua index be241cc5d8..71a5366518 100644 --- a/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua +++ b/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua @@ -24,9 +24,7 @@ -- POSSIBILITY OF SUCH DAMAGE. --include the lua script - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --define general settings sleep = 300; diff --git a/resources/install/scripts/call_flow.lua b/resources/install/scripts/call_flow.lua index ee62ed61a6..08ed304b6d 100644 --- a/resources/install/scripts/call_flow.lua +++ b/resources/install/scripts/call_flow.lua @@ -29,9 +29,7 @@ digit_timeout = "5000"; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/call_flow_monitor.lua b/resources/install/scripts/call_flow_monitor.lua index c6cff6aa04..9203d2fc91 100644 --- a/resources/install/scripts/call_flow_monitor.lua +++ b/resources/install/scripts/call_flow_monitor.lua @@ -32,9 +32,7 @@ debug["sql"] = false; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --general functions dofile(scripts_dir.."/resources/functions/file_exists.lua"); diff --git a/resources/install/scripts/call_forward.lua b/resources/install/scripts/call_forward.lua index 2269b3df85..3340129f61 100644 --- a/resources/install/scripts/call_forward.lua +++ b/resources/install/scripts/call_forward.lua @@ -51,9 +51,7 @@ api = freeswitch.API(); --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --check if the session is ready if (session:ready()) then diff --git a/resources/install/scripts/cidlookup.lua b/resources/install/scripts/cidlookup.lua index 338b12928d..f932d18077 100644 --- a/resources/install/scripts/cidlookup.lua +++ b/resources/install/scripts/cidlookup.lua @@ -79,9 +79,7 @@ end; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --check if the session is ready diff --git a/resources/install/scripts/destination_caller_id.lua b/resources/install/scripts/destination_caller_id.lua index 89742740ad..5a22ac71f7 100644 --- a/resources/install/scripts/destination_caller_id.lua +++ b/resources/install/scripts/destination_caller_id.lua @@ -25,9 +25,7 @@ -- POSSIBILITY OF SUCH DAMAGE. --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/dial_string.lua b/resources/install/scripts/dial_string.lua index b4a7a2f522..6470426af9 100644 --- a/resources/install/scripts/dial_string.lua +++ b/resources/install/scripts/dial_string.lua @@ -34,9 +34,7 @@ db_extension_uuid = ""; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/directory.lua b/resources/install/scripts/directory.lua index c987e13ff9..762dfd6dc5 100644 --- a/resources/install/scripts/directory.lua +++ b/resources/install/scripts/directory.lua @@ -34,14 +34,7 @@ search_count = 0; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); - ---include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/disa.callback.loopback.lua b/resources/install/scripts/disa.callback.loopback.lua index 00b00d46fa..11627d1233 100644 --- a/resources/install/scripts/disa.callback.loopback.lua +++ b/resources/install/scripts/disa.callback.loopback.lua @@ -27,9 +27,7 @@ debug["sql"] = true; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/disa.callback.lua b/resources/install/scripts/disa.callback.lua index 121da756a1..b809d0649a 100644 --- a/resources/install/scripts/disa.callback.lua +++ b/resources/install/scripts/disa.callback.lua @@ -27,9 +27,7 @@ debug["sql"] = false; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/disa.plus.lua b/resources/install/scripts/disa.plus.lua index 5d8e3963d5..266d96854a 100644 --- a/resources/install/scripts/disa.plus.lua +++ b/resources/install/scripts/disa.plus.lua @@ -31,9 +31,7 @@ digit_timeout = "5000"; debug["sql"] = true; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/do_not_disturb.lua b/resources/install/scripts/do_not_disturb.lua index 9b7666b156..2cc2dc486a 100644 --- a/resources/install/scripts/do_not_disturb.lua +++ b/resources/install/scripts/do_not_disturb.lua @@ -51,9 +51,7 @@ api = freeswitch.API(); --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --check if the session is ready if ( session:ready() ) then diff --git a/resources/install/scripts/eavesdrop.lua b/resources/install/scripts/eavesdrop.lua index bebaa6cb34..45e50e930d 100644 --- a/resources/install/scripts/eavesdrop.lua +++ b/resources/install/scripts/eavesdrop.lua @@ -28,9 +28,7 @@ digit_timeout = "5000"; extension = argv[1]; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --add the file_exists function dofile(scripts_dir.."/resources/functions/file_exists.lua"); diff --git a/resources/install/scripts/extension_queue.lua b/resources/install/scripts/extension_queue.lua index db83c14017..4c73818863 100644 --- a/resources/install/scripts/extension_queue.lua +++ b/resources/install/scripts/extension_queue.lua @@ -24,9 +24,7 @@ -- Riccardo Granchi --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/fax_retry.lua b/resources/install/scripts/fax_retry.lua index e4d4d12ef7..6fff79ff2f 100644 --- a/resources/install/scripts/fax_retry.lua +++ b/resources/install/scripts/fax_retry.lua @@ -31,9 +31,7 @@ api = freeswitch.API(); --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/follow_me.lua b/resources/install/scripts/follow_me.lua index 5485093413..b3f59cde20 100644 --- a/resources/install/scripts/follow_me.lua +++ b/resources/install/scripts/follow_me.lua @@ -51,9 +51,7 @@ api = freeswitch.API(); --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --check if the session is ready if ( session:ready() ) then diff --git a/resources/install/scripts/intercept.lua b/resources/install/scripts/intercept.lua index 419813c0cc..aea2741aec 100644 --- a/resources/install/scripts/intercept.lua +++ b/resources/install/scripts/intercept.lua @@ -32,9 +32,7 @@ debug["sql"] = false; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database if (file_exists(database_dir.."/core.db")) then diff --git a/resources/install/scripts/intercept_group.lua b/resources/install/scripts/intercept_group.lua index 13a82e70df..d81234f4ac 100644 --- a/resources/install/scripts/intercept_group.lua +++ b/resources/install/scripts/intercept_group.lua @@ -31,9 +31,7 @@ debug["sql"] = false; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --add the function dofile(scripts_dir.."/resources/functions/explode.lua"); diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 19a3cb04db..583ca3682f 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -32,9 +32,7 @@ debug["tries"] = false; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/park.lua b/resources/install/scripts/park.lua index 42b47ce423..77118a4be2 100644 --- a/resources/install/scripts/park.lua +++ b/resources/install/scripts/park.lua @@ -15,9 +15,7 @@ --action lua park.lua --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database --dbh = freeswitch.Dbh("core:core"); -- when using sqlite diff --git a/resources/install/scripts/park_monitor.lua b/resources/install/scripts/park_monitor.lua index e7b0a7a455..495c4a93ac 100644 --- a/resources/install/scripts/park_monitor.lua +++ b/resources/install/scripts/park_monitor.lua @@ -29,9 +29,7 @@ --then send presence terminate, and delete from the database --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database --dbh = freeswitch.Dbh("core:core"); -- when using sqlite diff --git a/resources/install/scripts/recordings.lua b/resources/install/scripts/recordings.lua index ecc1d4f1a0..ae5aebb751 100644 --- a/resources/install/scripts/recordings.lua +++ b/resources/install/scripts/recordings.lua @@ -34,9 +34,7 @@ recording_prefix = ""; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/install/scripts/resources/functions/config.lua b/resources/install/scripts/resources/functions/config.lua index c43b0c0f00..70dcb0efe7 100644 --- a/resources/install/scripts/resources/functions/config.lua +++ b/resources/install/scripts/resources/functions/config.lua @@ -1,12 +1,26 @@ +-- add file_exists function + require "resources.functions.file_exists"; + --find and return path to the config.lua function config() - dofile(scripts_dir.."/resources/functions/file_exists.lua"); if (file_exists("/etc/fusionpbx/config.lua")) then return "/etc/fusionpbx/config.lua"; elseif (file_exists("/usr/local/etc/fusionpbx/config.lua")) then return "/usr/local/etc/fusionpbx/config.lua"; else - return scripts_dir.."/resources/config.lua"; + return "resources.config"; end - end \ No newline at end of file + end + +-- load config + function load_config() + local cfg = config() + if cfg:sub(1,1) == '//' then + dofile(cfg) + else + require(cfg) + end + end + + load_config() diff --git a/resources/install/scripts/streamfile.lua b/resources/install/scripts/streamfile.lua index 377974dae7..079a64f283 100644 --- a/resources/install/scripts/streamfile.lua +++ b/resources/install/scripts/streamfile.lua @@ -3,9 +3,7 @@ file_name = argv[1]; --include config.lua - scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); - dofile(scripts_dir.."/resources/functions/config.lua"); - dofile(config()); + require "resources.functions.config"; --connect to the database dofile(scripts_dir.."/resources/functions/database_handle.lua"); diff --git a/resources/templates/conf/autoload_configs/lua.conf.xml b/resources/templates/conf/autoload_configs/lua.conf.xml index a608494467..f485269a9c 100644 --- a/resources/templates/conf/autoload_configs/lua.conf.xml +++ b/resources/templates/conf/autoload_configs/lua.conf.xml @@ -13,8 +13,8 @@ These entries will be pre-pended to the LUA_PATH environment variable --> - + From 6f28a7123b5b6712dbc2a7b3d19201b613bc187a Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Fri, 24 Jul 2015 11:26:11 +0400 Subject: [PATCH 3/7] Add. Support windows services. --- app/services/resources/classes/lib_win.php | 227 +++++++++++++++++++++ app/services/service_edit.php | 6 + app/services/services.php | 116 ++++++++--- 3 files changed, 318 insertions(+), 31 deletions(-) create mode 100644 app/services/resources/classes/lib_win.php diff --git a/app/services/resources/classes/lib_win.php b/app/services/resources/classes/lib_win.php new file mode 100644 index 0000000000..6368893376 --- /dev/null +++ b/app/services/resources/classes/lib_win.php @@ -0,0 +1,227 @@ +'CONTINUE_PENDING', + WIN32_SERVICE_PAUSE_PENDING =>'PAUSE_PENDING', + WIN32_SERVICE_PAUSED =>'PAUSED', + WIN32_SERVICE_RUNNING =>'RUNNING', + WIN32_SERVICE_START_PENDING =>'START_PENDING', + WIN32_SERVICE_STOP_PENDING =>'STOP_PENDING', + WIN32_SERVICE_STOPPED =>'STOPPED', + ); + + private static $win_error = array( + WIN32_NO_ERROR => 'NO_ERROR', + WIN32_ERROR_ACCESS_DENIED => 'ACCESS_DENIED', + WIN32_ERROR_CIRCULAR_DEPENDENCY => 'CIRCULAR_DEPENDENCY', + WIN32_ERROR_DATABASE_DOES_NOT_EXIST => 'DATABASE_DOES_NOT_EXIST', + WIN32_ERROR_DEPENDENT_SERVICES_RUNNING => 'DEPENDENT_SERVICES_RUNNING', + WIN32_ERROR_DUPLICATE_SERVICE_NAME => 'DUPLICATE_SERVICE_NAME', + WIN32_ERROR_FAILED_SERVICE_CONTROLLER_CONNECT => 'FAILED_SERVICE_CONTROLLER_CONNECT', + WIN32_ERROR_INSUFFICIENT_BUFFER => 'INSUFFICIENT_BUFFER', + WIN32_ERROR_INVALID_DATA => 'INVALID_DATA', + WIN32_ERROR_INVALID_HANDLE => 'INVALID_HANDLE', + WIN32_ERROR_INVALID_LEVEL => 'INVALID_LEVEL', + WIN32_ERROR_INVALID_NAME => 'INVALID_NAME', + WIN32_ERROR_INVALID_PARAMETER => 'INVALID_PARAMETER', + WIN32_ERROR_INVALID_SERVICE_ACCOUNT => 'INVALID_SERVICE_ACCOUNT', + WIN32_ERROR_INVALID_SERVICE_CONTROL => 'INVALID_SERVICE_CONTROL', + WIN32_ERROR_PATH_NOT_FOUND => 'PATH_NOT_FOUND', + WIN32_ERROR_SERVICE_ALREADY_RUNNING => 'SERVICE_ALREADY_RUNNING', + WIN32_ERROR_SERVICE_CANNOT_ACCEPT_CTRL => 'SERVICE_CANNOT_ACCEPT_CTRL', + WIN32_ERROR_SERVICE_DATABASE_LOCKED => 'SERVICE_DATABASE_LOCKED', + WIN32_ERROR_SERVICE_DEPENDENCY_DELETED => 'SERVICE_DEPENDENCY_DELETED', + WIN32_ERROR_SERVICE_DEPENDENCY_FAIL => 'SERVICE_DEPENDENCY_FAIL', + WIN32_ERROR_SERVICE_DISABLED => 'SERVICE_DISABLED', + WIN32_ERROR_SERVICE_DOES_NOT_EXIST => 'SERVICE_DOES_NOT_EXIST', + WIN32_ERROR_SERVICE_EXISTS => 'SERVICE_EXISTS', + WIN32_ERROR_SERVICE_LOGON_FAILED => 'SERVICE_LOGON_FAILED', + WIN32_ERROR_SERVICE_MARKED_FOR_DELETE => 'SERVICE_MARKED_FOR_DELETE', + WIN32_ERROR_SERVICE_NO_THREAD => 'SERVICE_NO_THREAD', + WIN32_ERROR_SERVICE_NOT_ACTIVE => 'SERVICE_NOT_ACTIVE', + WIN32_ERROR_SERVICE_REQUEST_TIMEOUT => 'SERVICE_REQUEST_TIMEOUT', + WIN32_ERROR_SHUTDOWN_IN_PROGRESS => 'SHUTDOWN_IN_PROGRESS' + ); + + private static function val2val($val,$map,$default){ + if(isset($map[$val])) return $map[$val]; + return $default; + } + + var $status; + var $last_error; + var $name; + var $description; + var $machine; + + function win_service($srvname, $machine=null){ + $this->name = $srvname; + $this->machine = $machine; + $this->status = null; + $this->last_error = WIN32_NO_ERROR; + } + + function refresh_status(){ + $status = win32_query_service_status($this->name,$this->machine); + if(is_array($status)){ + $this->status = (object)$status; + $this->last_error = WIN32_NO_ERROR; + return true; + } + $this->status = null; + $last_error = $status; + return false; + } + + function start(){ + $this->last_error = win32_start_service($this->name, $this->machine); + return ($this->last_error === WIN32_NO_ERROR) or ($this->last_error === WIN32_ERROR_SERVICE_ALREADY_RUNNING); + } + + function stop(){ + $this->last_error = win32_stop_service($this->name, $this->machine); + return $this->last_error === WIN32_NO_ERROR; + } + + function last_error($as_string = true){ + if($as_string){ + return self::val2val( + $this->last_error, self::$win_error, $this->last_error + ); + } + return $this->last_error; + } + + function state($as_string = true){ + if((!$this->status)and(!$this->refresh_status())) return false; + if($as_string){ + return self::val2val( + $this->status->CurrentState, self::$service_state, 'UNKNOWN' + ); + } + return $this->status->CurrentState; + } + + function pid(){ + if((!$this->status)and(!$this->refresh_status())) return false; + return $this->status->ProcessId; + } + + } + +} + +if(function_exists('reg_open_key')){ + + class win_reg_key{ + + private static $HK = array( + HKEY_CLASSES_ROOT => "HKCR", + HKEY_CURRENT_USER => "HKCU", + HKEY_LOCAL_MACHINE => "HKLM", + HKEY_USERS => "HKU", + HKEY_CURRENT_CONFIG => "HKCC", + ); + + function __construct($haiv, $key){ + $this->h = $haiv; + $this->k = $key; + $this->r = reg_open_key($this->h, $this->k); + $this->shell = new COM('WScript.Shell'); + if(!$this->shell){ + throw new Exception("Cannot create shell object."); + } + if(!$this->r){ + throw new Exception("Cannot access registry."); + } + $this->path = self::$HK[$this->h] . '\\' . $this->k; + } + + function __destruct(){ + if($this->r){ + reg_close_key($this->r); + $this->r = false; + } + } + + function keys(){ + return reg_enum_key($this->r); + } + + function values($as_hash = false){ + $values = reg_enum_value($this->r); + if(!$as_hash) return $values; + $result = Array(); + foreach($values as $key){ + $result[$key] = reg_get_value($this->r, $key); + } + return $result; + } + + function value($key){ + return reg_get_value($this->r, $key); + } + + function exists($key){ + $v = $this->value($key); + if($v === NULL) return false; + if($v === false) return false; + return true; + } + + private function write_raw($key, $type, $value){ + return reg_set_value($this->r, $key, $type, $value); + } + + function write_dword($key, $value){ + return $this->write_raw($key, REG_DWORD, $value); + } + + function write_string($key, $value){ + return $this->write_raw($key, REG_SZ, $value); + } + + function remove_value($key){ + if(!$this->exists($key)) return; + $key = $this->path . '\\' . $key; + $this->shell->RegDelete($key); + } + + } + +} diff --git a/app/services/service_edit.php b/app/services/service_edit.php index cb64aaac3a..aaaf09c584 100644 --- a/app/services/service_edit.php +++ b/app/services/service_edit.php @@ -221,6 +221,12 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { else { echo " \n"; } + if ($service_type == "svc") { + echo " \n"; + } + else { + echo " \n"; + } echo " \n"; echo "
\n"; echo $text['description-type']."\n"; diff --git a/app/services/services.php b/app/services/services.php index 9a1799550c..dc970bf43e 100644 --- a/app/services/services.php +++ b/app/services/services.php @@ -34,6 +34,18 @@ else { exit; } +global $IS_WINDOWS; + +if ($IS_WINDOWS == null) { + if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } +} + +$HAS_WIN_SVC = false; +if($IS_WINDOWS){ + require_once "resources/classes/lib_win.php"; + $HAS_WIN_SVC = class_exists('win_service'); +} + //add multi-lingual support $language = new text; $text = $language->get(); @@ -63,13 +75,28 @@ if (strlen($_GET["a"]) > 0) { } unset ($prep_statement); - if ($_GET["a"] == "stop") { - $_SESSION["message"] = $text['message-stopping'].': '.$service_name; - shell_exec($service_cmd_stop); + if($service_type == 'svc'){ + if($HAS_WIN_SVC){ + $svc = new win_service($service_data); + if ($_GET["a"] == "stop") { + $_SESSION["message"] = $text['message-stopping'].': '.$service_name; + $svc->stop(); + } + if ($_GET["a"] == "start") { + $_SESSION["message"] = $text['message-starting'].': '.$service_name; + $svc->start(); + } + } } - if ($_GET["a"] == "start") { - $_SESSION["message"] = $text['message-starting'].': '.$service_name; - shell_exec($service_cmd_start); + else { + if ($_GET["a"] == "stop") { + $_SESSION["message"] = $text['message-stopping'].': '.$service_name; + shell_exec($service_cmd_stop); + } + if ($_GET["a"] == "start") { + $_SESSION["message"] = $text['message-starting'].': '.$service_name; + shell_exec($service_cmd_start); + } } header("Location: services.php"); return; @@ -152,42 +179,69 @@ if (strlen($_GET["a"]) > 0) { } echo " \n"; echo " \n"; - if ($row[service_type] == "pid" || $row[service_type] == "pid_file") { - $pid = file_get_contents($row[service_data]); - if (is_process_running($pid)) { + $service_running = false; + + if ($row[service_type] == "svc") { + if ($HAS_WIN_SVC) { + $service_data = $row[service_data]; + $svc = new win_service($service_data); + $svc_state = $svc->state() or $svc->last_error(); + if(!$svc_state){ + $svc_state = 'NOT_INSTALL'; + } + $service_running = (($svc_state == 'RUNNING') || ($svc_state == 'START_PENDING')); + + echo "$svc_state"; + + echo "\n"; + echo " \n"; + if ($svc_state == 'NOT_INSTALL') { + echo "$svc_state"; + } + else { + if ($service_running) { + echo " ".$text['label-stop'].""; + } + else { + echo " ".$text['label-start'].""; + } + } + } + else{ + echo "UNSUPPORT"; + echo "\n"; + echo " \n"; + echo "UNSUPPORT"; + } + } + else { + if ($row[service_type] == "pid" || $row[service_type] == "pid_file") { + $pid = file_get_contents($row[service_data]); + $service_running = is_process_running($pid); + } + if ($row[service_type] == "file") { + $service_data = $row[service_data]; + $service_running = file_exists($service_data); + } + + if ($service_running) { echo "".$text['label-running'].""; } else { echo "".$text['label-stopped'].""; } - } - if ($row[service_type] == "file") { - $service_data = $row[service_data]; - if (file_exists($service_data)) { - echo "".$text['label-running'].""; - } - else { - echo "".$text['label-stopped'].""; - } - } - echo "\n"; - echo " \n"; - if ($row[service_type] == "pid" || $row[service_type] == "pid_file") { - if (is_process_running($pid)) { - echo " ".$text['label-stop'].""; - } - else { - echo " ".$text['label-start'].""; - } - } - if ($row[service_type] == "file") { - if (file_exists($service_data)) { + + echo "\n"; + echo " \n"; + if ($service_running) { echo " ".$text['label-stop'].""; } else { echo " ".$text['label-start'].""; } } + + echo "\n"; echo " ".$row[service_description]." \n"; echo " "; From 565395c44fc85a499087e70cb8f325f8fa01ba90 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Tue, 28 Jul 2015 15:59:04 +0400 Subject: [PATCH 4/7] Fix. Correct path when user on `group_confirm_file` --- resources/install/scripts/app/ring_groups/index.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index b1135f84c5..11ab042292 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -329,16 +329,16 @@ or ring_group_strategy == "sequence" or ring_group_strategy == "rollover") then session:execute("set", "group_confirm_key=exec"); - session:execute("set", "group_confirm_file=lua ".. scripts_dir .."/confirm.lua"); + session:execute("set", "group_confirm_file=lua ".. scripts_dir:gsub('\\','/') .."/confirm.lua"); end --determine confirm prompt if (destination_prompt == nil) then group_confirm = "confirm=false,"; elseif (destination_prompt == "1") then - group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir .."/confirm.lua,confirm=true,"; + group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir:gsub('\\','/') .."/confirm.lua,confirm=true,"; elseif (destination_prompt == "2") then - group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir .."/confirm.lua,confirm=true,"; + group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir:gsub('\\','/') .."/confirm.lua,confirm=true,"; else group_confirm = "confirm=false,"; end From 703b61636a4f77c758e2596225cf4e96e3eb8f83 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Mon, 10 Aug 2015 12:43:06 +0400 Subject: [PATCH 5/7] Change. Use only `require` to load function. Fix. Remove multiple definition of same function. --- .../scripts/app/agent_status/index.lua | 2 +- .../install/scripts/app/call_block/index.lua | 6 +- .../scripts/app/conference_center/index.lua | 16 ++--- .../resources/scripts/start_recording.lua | 6 +- .../install/scripts/app/dialplan/index.lua | 4 +- .../inbound/010_get_domain.lua.noload | 4 +- .../scripts/app/event_notify/index.lua | 12 +--- .../scripts/app/failure_handler/index.lua | 6 +- .../app/fax/resources/scripts/hangup_rx.lua | 24 ++----- .../install/scripts/app/hangup/index.lua | 8 +-- .../install/scripts/app/is_local/index.lua | 12 ++-- .../install/scripts/app/provision/index.lua | 14 +---- .../install/scripts/app/ring_groups/index.lua | 6 +- .../ring_groups/resources/scripts/confirm.lua | 18 ++---- .../ring_groups/resources/scripts/monitor.lua | 18 ++---- .../install/scripts/app/toll_allow/index.lua | 2 +- .../install/scripts/app/voicemail/index.lua | 62 +++++++++---------- .../resources/functions/check_password.lua | 1 - .../resources/functions/choose_greeting.lua | 2 +- .../functions/listen_to_recording.lua | 2 +- .../resources/functions/play_greeting.lua | 2 +- .../resources/functions/record_menu.lua | 2 +- .../resources/functions/record_name.lua | 2 +- .../resources/functions/send_email.lua | 4 +- .../app/voicemail/resources/scripts/mwi.lua | 13 ++-- .../install/scripts/app/xml_handler/index.lua | 6 +- .../scripts/configuration/callcenter.conf.lua | 2 +- .../scripts/configuration/sofia.conf.lua | 2 +- .../resources/scripts/dialplan/dialplan.lua | 2 +- .../scripts/directory/action/domains.lua | 2 +- .../scripts/directory/action/group_call.lua | 2 +- .../directory/action/reverse-auth-lookup.lua | 2 +- .../resources/scripts/directory/directory.lua | 6 +- .../resources/scripts/languages/languages.lua | 2 +- resources/install/scripts/call_flow.lua | 2 +- .../install/scripts/call_flow_monitor.lua | 6 +- resources/install/scripts/call_forward.lua | 16 +---- resources/install/scripts/cidlookup.lua | 22 ++----- resources/install/scripts/confirm.lua | 5 +- .../install/scripts/destination_caller_id.lua | 8 +-- resources/install/scripts/dial_string.lua | 2 +- resources/install/scripts/directory.lua | 29 +++------ .../scripts/disa.callback.loopback.lua | 2 +- resources/install/scripts/disa.callback.lua | 4 +- resources/install/scripts/disa.lua | 16 ++--- resources/install/scripts/disa.plus.lua | 18 ++---- resources/install/scripts/do_not_disturb.lua | 16 +---- resources/install/scripts/eavesdrop.lua | 4 +- resources/install/scripts/extension_queue.lua | 2 +- resources/install/scripts/fax_retry.lua | 24 ++----- resources/install/scripts/follow_me.lua | 16 +---- resources/install/scripts/intercept.lua | 4 +- resources/install/scripts/intercept_group.lua | 6 +- resources/install/scripts/ivr_menu.lua | 23 +++---- resources/install/scripts/monitor.lua | 11 +--- resources/install/scripts/page.lua | 16 ++--- resources/install/scripts/park.lua | 20 ++---- resources/install/scripts/park_monitor.lua | 8 +-- resources/install/scripts/pin_number.lua | 16 ++--- resources/install/scripts/recordings.lua | 10 +-- .../scripts/resources/functions/base64.lua | 4 +- .../scripts/resources/functions/settings.lua | 6 +- resources/install/scripts/streamfile.lua | 11 ++-- resources/install/scripts/wakeup.lua | 6 +- 64 files changed, 207 insertions(+), 400 deletions(-) diff --git a/resources/install/scripts/app/agent_status/index.lua b/resources/install/scripts/app/agent_status/index.lua index d950f7abe7..abbed2e5a3 100644 --- a/resources/install/scripts/app/agent_status/index.lua +++ b/resources/install/scripts/app/agent_status/index.lua @@ -6,7 +6,7 @@ debug["sql"] = true; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --set the api diff --git a/resources/install/scripts/app/call_block/index.lua b/resources/install/scripts/app/call_block/index.lua index 9ca1d9d8fc..8821a099ef 100644 --- a/resources/install/scripts/app/call_block/index.lua +++ b/resources/install/scripts/app/call_block/index.lua @@ -57,7 +57,7 @@ This method causes the script to get its manadatory arguments directly from the local sql = nil --define the functions - dofile(scripts_dir.."/resources/functions/trim.lua"); + require "resources.functions.trim"; --define the logger function local function logger(level, log, data) @@ -88,7 +88,7 @@ This method causes the script to get its manadatory arguments directly from the --if not cached then get the information from the database if (cache == "-ERR NOT FOUND") then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --log if not connect @@ -123,7 +123,7 @@ This method causes the script to get its manadatory arguments directly from the else --get from memcache --add the function - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.explode"; --parse the cache array = explode("&", cache); diff --git a/resources/install/scripts/app/conference_center/index.lua b/resources/install/scripts/app/conference_center/index.lua index 1f4b724892..89d157c2da 100644 --- a/resources/install/scripts/app/conference_center/index.lua +++ b/resources/install/scripts/app/conference_center/index.lua @@ -37,19 +37,19 @@ debug["sql"] = false; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --prepare the api object api = freeswitch.API(); --general functions - dofile(scripts_dir.."/resources/functions/base64.lua"); - dofile(scripts_dir.."/resources/functions/trim.lua"); - dofile(scripts_dir.."/resources/functions/file_exists.lua"); - dofile(scripts_dir.."/resources/functions/explode.lua"); - dofile(scripts_dir.."/resources/functions/format_seconds.lua"); - dofile(scripts_dir.."/resources/functions/mkdir.lua"); + require "resources.functions.base64"; + require "resources.functions.trim"; + require "resources.functions.file_exists"; + require "resources.functions.explode"; + require "resources.functions.format_seconds"; + require "resources.functions.mkdir"; --get the session variables uuid = session:getVariable("uuid"); @@ -153,7 +153,7 @@ end_epoch = os.time(); --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --get the conference sessions diff --git a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua index 018f60a92f..b30412451d 100644 --- a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua +++ b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua @@ -2,9 +2,9 @@ require "resources.functions.config"; --additional includes - dofile(scripts_dir.."/resources/functions/file_exists.lua"); - dofile(scripts_dir.."/resources/functions/trim.lua"); - dofile(scripts_dir.."/resources/functions/mkdir.lua"); + require "resources.functions.file_exists"; + require "resources.functions.trim"; + require "resources.functions.mkdir"; --get the argv values script_name = argv[0]; diff --git a/resources/install/scripts/app/dialplan/index.lua b/resources/install/scripts/app/dialplan/index.lua index 0679747163..fbd3892031 100644 --- a/resources/install/scripts/app/dialplan/index.lua +++ b/resources/install/scripts/app/dialplan/index.lua @@ -19,8 +19,8 @@ -- the Initial Developer. All Rights Reserved. --add functions - dofile(scripts_dir.."/resources/functions/file_exists.lua"); - dofile(scripts_dir.."/resources/functions/trim.lua"); + require "resources.functions.file_exists"; + require "resources.functions.trim"; --set the api object api = freeswitch.API(); diff --git a/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload b/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload index 3493b46377..cbdeefea70 100644 --- a/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload +++ b/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload @@ -32,7 +32,7 @@ end --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --get the cache @@ -64,7 +64,7 @@ else --add the function - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.explode"; --parse the cache array = explode("&", cache); diff --git a/resources/install/scripts/app/event_notify/index.lua b/resources/install/scripts/app/event_notify/index.lua index 68f7002c8e..827ddfe664 100644 --- a/resources/install/scripts/app/event_notify/index.lua +++ b/resources/install/scripts/app/event_notify/index.lua @@ -23,16 +23,8 @@ -- Mark J Crane -- Errol Samuels ---define explode - 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end +--define the explode function + require "resources.functions.explode"; --usage --luarun app.lua event_notify internal reboot 1003@domain.fusionpbx.com yealink diff --git a/resources/install/scripts/app/failure_handler/index.lua b/resources/install/scripts/app/failure_handler/index.lua index 038b6f6c96..6e174911ce 100644 --- a/resources/install/scripts/app/failure_handler/index.lua +++ b/resources/install/scripts/app/failure_handler/index.lua @@ -28,9 +28,9 @@ debug["sql"] = false; --include config.lua - dofile(scripts_dir .. "/resources/functions/config.lua"); - dofile(scripts_dir .. "/resources/functions/explode.lua"); - dofile(scripts_dir .. "/resources/functions/trim.lua"); + require "resources.functions.config"; + require "resources.functions.explode"; + require "resources.functions.trim"; --check the missed calls function missed() 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 1d2e158291..d70db541e9 100644 --- a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua +++ b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua @@ -29,28 +29,14 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --define 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end + require "resources.functions.explode"; --array count - function count(t) - c = 0; - for k,v in pairs(t) do - c = c+1; - end - return c; - end + require "resources.functions.count"; -- set channel variables to lua variables domain_uuid = env:getHeader("domain_uuid"); @@ -66,7 +52,7 @@ end --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -311,7 +297,7 @@ if (fax_success =="1") then if (storage_type == "base64") then --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --base64 encode the file local f = io.open(fax_file, "rb"); diff --git a/resources/install/scripts/app/hangup/index.lua b/resources/install/scripts/app/hangup/index.lua index 05d4dd1329..9a77d819cc 100644 --- a/resources/install/scripts/app/hangup/index.lua +++ b/resources/install/scripts/app/hangup/index.lua @@ -25,10 +25,10 @@ debug["sql"] = false; --general functions - dofile(scripts_dir .. "/resources/functions/config.lua"); - dofile(scripts_dir .. "/resources/functions/explode.lua"); - dofile(scripts_dir.."/resources/functions/trim.lua"); - --dofile(scripts_dir.."/resources/functions/file_exists.lua"); + require "resources.functions.config"; + require "resources.functions.explode"; + require "resources.functions.trim"; + -- require "resources.functions.file_exists"; --create the api object api = freeswitch.API(); diff --git a/resources/install/scripts/app/is_local/index.lua b/resources/install/scripts/app/is_local/index.lua index 9d9e06fba5..1fcbf9aaa9 100644 --- a/resources/install/scripts/app/is_local/index.lua +++ b/resources/install/scripts/app/is_local/index.lua @@ -29,18 +29,14 @@ outbound_caller_id_number = session:getVariable("outbound_caller_id_number"); --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --prepare the api object api = freeswitch.API(); ---add the trim function - function trim(s) - if (s) then - return s:gsub("^%s+", ""):gsub("%s+$", "") - end - end +--define the trim function + require "resources.functions.trim"; --get the cache cache = trim(api:execute("memcache", "get app:dialplan:outbound:is_local:" .. destination_number .. "@" .. domain_name)); @@ -84,7 +80,7 @@ end)); else --add the function - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.explode"; --define the array/table and variables local var = {} diff --git a/resources/install/scripts/app/provision/index.lua b/resources/install/scripts/app/provision/index.lua index 7d4b9a6468..5eba2c844a 100644 --- a/resources/install/scripts/app/provision/index.lua +++ b/resources/install/scripts/app/provision/index.lua @@ -26,16 +26,8 @@ --set the debug options debug["sql"] = false; ---define explode - 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end +--define the explode function + require "resources.functions.explode"; --set the defaults max_tries = 3; @@ -45,7 +37,7 @@ profile = "internal"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --answer diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index 11ab042292..3f51d86931 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -28,12 +28,12 @@ -- Luis Daniel Lucio Qurioz --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --include functions - dofile(scripts_dir.."/resources/functions/trim.lua"); - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.trim"; + require "resources.functions.explode"; --get the variables domain_name = session:getVariable("domain_name"); diff --git a/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua b/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua index 9af1d1e470..ab77b5d0a9 100644 --- a/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua +++ b/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua @@ -29,21 +29,11 @@ max_tries = "3"; digit_timeout = "5000"; ---add a trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end +--define the trim function + require "resources.functions.trim"; ---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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end +--define the explode function + require "resources.functions.explode"; --get the argv values script_name = argv[0]; diff --git a/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua b/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua index 2b54a4a152..36e373685d 100644 --- a/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua +++ b/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua @@ -33,21 +33,11 @@ uuid = argv[1]; timeout = argv[2]; ---add a trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end +--define the trim function + require "resources.functions.trim"; ---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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end +--define the explode function + require "resources.functions.explode"; --prepare the api api = freeswitch.API(); diff --git a/resources/install/scripts/app/toll_allow/index.lua b/resources/install/scripts/app/toll_allow/index.lua index 869add5847..31844e4e69 100644 --- a/resources/install/scripts/app/toll_allow/index.lua +++ b/resources/install/scripts/app/toll_allow/index.lua @@ -26,7 +26,7 @@ --debug debug["toll_type"] = false - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.explode"; --create the api object and get variables api = freeswitch.API() diff --git a/resources/install/scripts/app/voicemail/index.lua b/resources/install/scripts/app/voicemail/index.lua index 42f1e54751..91ac38f61b 100644 --- a/resources/install/scripts/app/voicemail/index.lua +++ b/resources/install/scripts/app/voicemail/index.lua @@ -50,7 +50,7 @@ password_tries = 0; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --set the api @@ -123,7 +123,7 @@ end --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -199,36 +199,36 @@ end --general functions - dofile(scripts_dir.."/resources/functions/base64.lua"); - dofile(scripts_dir.."/resources/functions/trim.lua"); - dofile(scripts_dir.."/resources/functions/file_exists.lua"); - dofile(scripts_dir.."/resources/functions/explode.lua"); - dofile(scripts_dir.."/resources/functions/format_seconds.lua"); - dofile(scripts_dir.."/resources/functions/mkdir.lua"); - dofile(scripts_dir.."/resources/functions/copy.lua"); + require "resources.functions.base64"; + require "resources.functions.trim"; + require "resources.functions.file_exists"; + require "resources.functions.explode"; + require "resources.functions.format_seconds"; + require "resources.functions.mkdir"; + require "resources.functions.copy"; --voicemail functions - dofile(scripts_dir.."/app/voicemail/resources/functions/on_dtmf.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/get_voicemail_id.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/check_password.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/change_password.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/macro.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/play_greeting.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/record_message.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/record_menu.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/forward_to_extension.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/main_menu.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/listen_to_recording.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/message_waiting.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/send_email.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/delete_recording.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/message_saved.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/return_call.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/menu_messages.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/advanced.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/record_greeting.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/choose_greeting.lua"); - dofile(scripts_dir.."/app/voicemail/resources/functions/record_name.lua"); + require "app.voicemail.resources.functions.on_dtmf"; + require "app.voicemail.resources.functions.get_voicemail_id"; + require "app.voicemail.resources.functions.check_password"; + require "app.voicemail.resources.functions.change_password"; + require "app.voicemail.resources.functions.macro"; + require "app.voicemail.resources.functions.play_greeting"; + require "app.voicemail.resources.functions.record_message"; + require "app.voicemail.resources.functions.record_menu"; + require "app.voicemail.resources.functions.forward_to_extension"; + require "app.voicemail.resources.functions.main_menu"; + require "app.voicemail.resources.functions.listen_to_recording"; + require "app.voicemail.resources.functions.message_waiting"; + require "app.voicemail.resources.functions.send_email"; + require "app.voicemail.resources.functions.delete_recording"; + require "app.voicemail.resources.functions.message_saved"; + require "app.voicemail.resources.functions.return_call"; + require "app.voicemail.resources.functions.menu_messages"; + require "app.voicemail.resources.functions.advanced"; + require "app.voicemail.resources.functions.record_greeting"; + require "app.voicemail.resources.functions.choose_greeting"; + require "app.voicemail.resources.functions.record_name"; --send a message waiting event if (voicemail_action == "mwi") then @@ -317,7 +317,7 @@ freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --base64 encode the file if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then diff --git a/resources/install/scripts/app/voicemail/resources/functions/check_password.lua b/resources/install/scripts/app/voicemail/resources/functions/check_password.lua index 5170fdcab7..b95cf1feae 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/check_password.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/check_password.lua @@ -82,4 +82,3 @@ end end end ---dofile(scripts_dir.."/app/voicemail/resources/functions/check_password.lua"); \ No newline at end of file diff --git a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua index f8611c398a..0e71727c6d 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua @@ -96,7 +96,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --set the voicemail message path greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua b/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua index 89e0925ff5..cf4971e5e2 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua @@ -67,7 +67,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --set the voicemail message path message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua index 484dc24ef0..358059e0a6 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua @@ -52,7 +52,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --set the voicemail message path greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua b/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua index be468907ea..cd0f950f15 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua @@ -83,7 +83,7 @@ --if base64, encode file if (storage_type == "base64") then --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --base64 encode the file local f = io.open(real_file, "rb"); local file_content = f:read("*all"); diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_name.lua b/resources/install/scripts/app/voicemail/resources/functions/record_name.lua index fa4f039902..fb4b3d6587 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_name.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_name.lua @@ -44,7 +44,7 @@ --record and save the file if (storage_type == "base64") then --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --set the location voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav"; 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 b2f0fe5867..f00cb942a5 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua @@ -52,7 +52,7 @@ --require the email address to send the email if (string.len(voicemail_mail_to) > 2) then --include languages file - dofile(scripts_dir.."/app/voicemail/app_languages.lua"); + require "app.voicemail.app_languages"; --get voicemail message details sql = [[SELECT * FROM v_voicemail_messages @@ -73,7 +73,7 @@ --get the recordings from the database if (storage_type == "base64") then --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --set the voicemail message path message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua b/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua index 71a5366518..82d9d17973 100644 --- a/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua +++ b/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua @@ -39,23 +39,18 @@ --only run the script a single time runonce = true --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --used to stop the lua service local file = assert(io.open(run_file, "w")); file:write("remove this file to stop the script"); ---add the trim function - function trim(s) - return s:gsub("^%s+", ""):gsub("%s+$", "") - end +--define the trim function + require "resources.functions.trim"; --check if a file exists - function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end - end + require "resources.functions.file_exists"; --create the api object api = freeswitch.API(); diff --git a/resources/install/scripts/app/xml_handler/index.lua b/resources/install/scripts/app/xml_handler/index.lua index d97f45f408..770c5a4b0c 100644 --- a/resources/install/scripts/app/xml_handler/index.lua +++ b/resources/install/scripts/app/xml_handler/index.lua @@ -39,9 +39,9 @@ debug["cache"] = false; --general functions - dofile(scripts_dir.."/resources/functions/trim.lua"); - dofile(scripts_dir.."/resources/functions/file_exists.lua"); - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.trim"; + require "resources.functions.file_exists"; + require "resources.functions.explode"; --if the params class and methods do not exist then add them to prevent errors if (not params) then diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua index 3e7c29920d..fea1a74184 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua @@ -36,7 +36,7 @@ if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua index e6e8a1ffe1..b0172f5334 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua @@ -36,7 +36,7 @@ if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua index c4eeeb0f63..bac93081ab 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua @@ -35,7 +35,7 @@ if (XML_STRING == "-ERR NOT FOUND") then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly 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 e0ec0d6b5e..10df751dcb 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 @@ -25,7 +25,7 @@ -- POSSIBILITY OF SUCH DAMAGE. --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua index b00c279891..458c6d02c9 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua @@ -34,7 +34,7 @@ --set the cache if (XML_STRING == "-ERR NOT FOUND") then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua index fca7636069..6711bc1f0f 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua @@ -32,7 +32,7 @@ --user_call - user has been called --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly 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 6f98af09d2..836841b471 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 @@ -109,7 +109,7 @@ --database connection if (continue) then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly @@ -154,14 +154,14 @@ --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_hostname is " .. local_hostname .. "\n"); --add the file_exists function - dofile(scripts_dir.."/resources/functions/file_exists.lua"); + require "resources.functions.file_exists"; --connect to the switch database if (file_exists(database_dir.."/core.db")) then --dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); else - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh_switch = database_handle('switch'); end diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua index e9c9ba8a93..da3871df7d 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua @@ -65,7 +65,7 @@ --database connection if (continue) then --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/call_flow.lua b/resources/install/scripts/call_flow.lua index 08ed304b6d..a8298a067c 100644 --- a/resources/install/scripts/call_flow.lua +++ b/resources/install/scripts/call_flow.lua @@ -32,7 +32,7 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); if (session:ready()) then diff --git a/resources/install/scripts/call_flow_monitor.lua b/resources/install/scripts/call_flow_monitor.lua index 9203d2fc91..5be5ccf4bb 100644 --- a/resources/install/scripts/call_flow_monitor.lua +++ b/resources/install/scripts/call_flow_monitor.lua @@ -35,11 +35,11 @@ require "resources.functions.config"; --general functions - dofile(scripts_dir.."/resources/functions/file_exists.lua"); - dofile(scripts_dir.."/resources/functions/mkdir.lua"); + require "resources.functions.file_exists"; + require "resources.functions.mkdir"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --make sure the scripts/run dir exists diff --git a/resources/install/scripts/call_forward.lua b/resources/install/scripts/call_forward.lua index 3340129f61..ceb87a5701 100644 --- a/resources/install/scripts/call_forward.lua +++ b/resources/install/scripts/call_forward.lua @@ -32,20 +32,10 @@ debug["sql"] = false; --define the trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end + require "resources.functions.trim" --define 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end + require "resources.functions.explode" --create the api object api = freeswitch.API(); @@ -81,7 +71,7 @@ session:sleep(1000); --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --request id is true diff --git a/resources/install/scripts/cidlookup.lua b/resources/install/scripts/cidlookup.lua index f932d18077..b45a319d49 100644 --- a/resources/install/scripts/cidlookup.lua +++ b/resources/install/scripts/cidlookup.lua @@ -30,20 +30,10 @@ debug["sql"] = true; --define the trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end + require "resources.functions.trim" --define 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end + require "resources.functions.explode" --create the api object api = freeswitch.API(); @@ -82,17 +72,17 @@ require "resources.functions.config"; --check if the session is ready - + --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); - + if (database["type"] == "mysql") then sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts "; else sql = "SELECT v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_type || ')' AS name FROM v_contacts "; end - + sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid "; sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid "; sql = sql .. "WHERE v_contact_phones.phone_number = '"..caller.."' AND v_destinations.destination_number='"..callee.."'"; diff --git a/resources/install/scripts/confirm.lua b/resources/install/scripts/confirm.lua index 6154979de3..a44f23b14f 100644 --- a/resources/install/scripts/confirm.lua +++ b/resources/install/scripts/confirm.lua @@ -26,10 +26,7 @@ digit_timeout = "5000"; --check if a file exists - function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end - end + require "resources.functions.file_exists" --run if the session is ready if ( session:ready() ) then diff --git a/resources/install/scripts/destination_caller_id.lua b/resources/install/scripts/destination_caller_id.lua index 5a22ac71f7..df105bd919 100644 --- a/resources/install/scripts/destination_caller_id.lua +++ b/resources/install/scripts/destination_caller_id.lua @@ -28,13 +28,11 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); ---add a trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end +--define the trim function + require "resources.functions.trim" --get the variables domain_name = session:getVariable("domain_name"); diff --git a/resources/install/scripts/dial_string.lua b/resources/install/scripts/dial_string.lua index 6470426af9..5616d64778 100644 --- a/resources/install/scripts/dial_string.lua +++ b/resources/install/scripts/dial_string.lua @@ -37,7 +37,7 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); if ( session:ready() ) then diff --git a/resources/install/scripts/directory.lua b/resources/install/scripts/directory.lua index 762dfd6dc5..01b4f85455 100644 --- a/resources/install/scripts/directory.lua +++ b/resources/install/scripts/directory.lua @@ -37,11 +37,11 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -151,16 +151,8 @@ end end ---define explode - 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end +--define the explode function + require "resources.functions.explode" --define a function to convert dialpad letters to numbers function dialpad_to_digit(letter) @@ -193,16 +185,11 @@ return count end ---define trim - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end +--define the trim function + require "resources.functions.trim" --check if a file exists - function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end - end + require "resources.functions.file_exists" --define select_entry function function select_entry() @@ -261,7 +248,7 @@ end status = dbh:query(sql, function(field) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --set the voicemail message path file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav"; diff --git a/resources/install/scripts/disa.callback.loopback.lua b/resources/install/scripts/disa.callback.loopback.lua index 11627d1233..d0fb1b8923 100644 --- a/resources/install/scripts/disa.callback.loopback.lua +++ b/resources/install/scripts/disa.callback.loopback.lua @@ -30,7 +30,7 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); api = freeswitch.API(); diff --git a/resources/install/scripts/disa.callback.lua b/resources/install/scripts/disa.callback.lua index b809d0649a..ab471109bc 100644 --- a/resources/install/scripts/disa.callback.lua +++ b/resources/install/scripts/disa.callback.lua @@ -30,13 +30,13 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); api = freeswitch.API(); --other libs - dofile(scripts_dir.."/resources/functions/trim.lua"); + require "resources.functions.trim"; aleg_number = argv[1]; bleg_number = argv[2]; diff --git a/resources/install/scripts/disa.lua b/resources/install/scripts/disa.lua index 7ce526edc5..893b33b5a6 100644 --- a/resources/install/scripts/disa.lua +++ b/resources/install/scripts/disa.lua @@ -26,19 +26,11 @@ predefined_destination = ""; max_tries = "3"; digit_timeout = "5000"; -function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) -end +--define the trim function + require "resources.functions.trim"; -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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr -end +--define the explode function + require "resources.functions.explode"; if ( session:ready() ) then session:answer( ); diff --git a/resources/install/scripts/disa.plus.lua b/resources/install/scripts/disa.plus.lua index 266d96854a..575fd06385 100644 --- a/resources/install/scripts/disa.plus.lua +++ b/resources/install/scripts/disa.plus.lua @@ -34,24 +34,16 @@ digit_timeout = "5000"; require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); api = freeswitch.API(); -function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) -end +--define the trim function + require "resources.functions.trim"; -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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr -end +--define the explode function + require "resources.functions.explode"; if ( session:ready() ) then session:answer( ); diff --git a/resources/install/scripts/do_not_disturb.lua b/resources/install/scripts/do_not_disturb.lua index 2cc2dc486a..f48c426dee 100644 --- a/resources/install/scripts/do_not_disturb.lua +++ b/resources/install/scripts/do_not_disturb.lua @@ -32,20 +32,10 @@ debug["sql"] = false; --define the trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end + require "resources.functions.trim"; --define 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end + require "resources.functions.explode"; --create the api object api = freeswitch.API(); @@ -80,7 +70,7 @@ session:sleep(1000); --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --determine whether to update the dial string diff --git a/resources/install/scripts/eavesdrop.lua b/resources/install/scripts/eavesdrop.lua index 45e50e930d..f89c557491 100644 --- a/resources/install/scripts/eavesdrop.lua +++ b/resources/install/scripts/eavesdrop.lua @@ -31,7 +31,7 @@ extension = argv[1]; require "resources.functions.config"; --add the file_exists function - dofile(scripts_dir.."/resources/functions/file_exists.lua"); + require "resources.functions.file_exists"; --connect to the database if (file_exists(database_dir.."/core.db")) then @@ -39,7 +39,7 @@ extension = argv[1]; dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); freeswitch.consoleLog("NOTICE", "[eavesdrop] using core.db\n"); else - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('switch'); freeswitch.consoleLog("NOTICE", "[eavesdrop] using freeswitch db\n"); diff --git a/resources/install/scripts/extension_queue.lua b/resources/install/scripts/extension_queue.lua index 4c73818863..2f8ed817ab 100644 --- a/resources/install/scripts/extension_queue.lua +++ b/resources/install/scripts/extension_queue.lua @@ -27,7 +27,7 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); if (session:ready()) then diff --git a/resources/install/scripts/fax_retry.lua b/resources/install/scripts/fax_retry.lua index 6fff79ff2f..4b0d38e3e0 100644 --- a/resources/install/scripts/fax_retry.lua +++ b/resources/install/scripts/fax_retry.lua @@ -34,28 +34,14 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --define 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end + require "resources.functions.explode"; --array count - function count(t) - c = 0; - for k,v in pairs(t) do - c = c+1; - end - return c; - end + require "resources.functions.count"; -- show all channel variables --dat = env:serialize() @@ -137,7 +123,7 @@ end --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -300,7 +286,7 @@ if (fax_success =="1") then if (storage_type == "base64") then --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --base64 encode the file local f = io.open(fax_file, "rb"); diff --git a/resources/install/scripts/follow_me.lua b/resources/install/scripts/follow_me.lua index b3f59cde20..bfacd96359 100644 --- a/resources/install/scripts/follow_me.lua +++ b/resources/install/scripts/follow_me.lua @@ -32,20 +32,10 @@ debug["sql"] = true; --define the trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end + require "resources.functions.trim"; --define 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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end + require "resources.functions.explode"; --create the api object api = freeswitch.API(); @@ -79,7 +69,7 @@ session:sleep(1000); --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --determine whether to update the dial string diff --git a/resources/install/scripts/intercept.lua b/resources/install/scripts/intercept.lua index aea2741aec..b6927c6083 100644 --- a/resources/install/scripts/intercept.lua +++ b/resources/install/scripts/intercept.lua @@ -39,7 +39,7 @@ --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); else - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('switch'); end @@ -47,7 +47,7 @@ api = freeswitch.API(); --add the function - dofile(scripts_dir.."/resources/functions/trim.lua"); + require "resources.functions.trim"; --exits the script if we didn't connect properly assert(dbh:connected()); diff --git a/resources/install/scripts/intercept_group.lua b/resources/install/scripts/intercept_group.lua index d81234f4ac..e6078da4d7 100644 --- a/resources/install/scripts/intercept_group.lua +++ b/resources/install/scripts/intercept_group.lua @@ -34,10 +34,10 @@ require "resources.functions.config"; --add the function - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.explode"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --check if the session is ready @@ -147,7 +147,7 @@ --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); else - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('switch'); end diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 583ca3682f..65f0babf5d 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -35,7 +35,7 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --get the variables @@ -47,7 +47,7 @@ domain_uuid = session:getVariable("domain_uuid"); --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -83,16 +83,11 @@ --set default variable(s) tries = 0; ---add the trim function - function trim(s) - return s:gsub("^%s+", ""):gsub("%s+$", "") - end +--define the trim function + require "resources.functions.trim" --check if a file exists - function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end - end + require "resources.functions.file_exists" --prepare the api object api = freeswitch.API(); @@ -216,7 +211,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --add the path to filename ivr_menu_greet_long = recordings_dir.."/"..greet_long_file_name; ivr_menu_greet_long_is_base64 = true; @@ -240,7 +235,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --add the path to filename ivr_menu_greet_short = recordings_dir.."/"..greet_short_file_name; ivr_menu_greet_short_is_base64 = true; @@ -264,7 +259,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --add the path to filename ivr_menu_invalid_sound = recordings_dir.."/"..invalid_sound_file_name; ivr_menu_invalid_sound_is_base64 = true; @@ -288,7 +283,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --add the path to filename ivr_menu_exit_sound = recordings_dir.."/"..exit_sound_file_name; ivr_menu_exit_sound_is_base64 = true; diff --git a/resources/install/scripts/monitor.lua b/resources/install/scripts/monitor.lua index 0b86958a93..baf3ef55f7 100644 --- a/resources/install/scripts/monitor.lua +++ b/resources/install/scripts/monitor.lua @@ -31,16 +31,11 @@ local file = assert(io.open(tmp_file, "w")); file:write("remove this file to stop the script"); ---add the trim function - function trim(s) - return s:gsub("^%s+", ""):gsub("%s+$", "") - end +--define the trim function + require "resources.functions.trim" --check if a file exists - function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end - end + require "resources.functions.file_exists" --create the api object api = freeswitch.API(); diff --git a/resources/install/scripts/page.lua b/resources/install/scripts/page.lua index 8d23657700..418fcefe3a 100644 --- a/resources/install/scripts/page.lua +++ b/resources/install/scripts/page.lua @@ -28,19 +28,11 @@ pin_number = ""; max_tries = "3"; digit_timeout = "3000"; -function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) -end +--define the trim function + require "resources.functions.trim"; -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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr -end +--define the explode function + require "resources.functions.explode"; if ( session:ready() ) then session:answer(); diff --git a/resources/install/scripts/park.lua b/resources/install/scripts/park.lua index 77118a4be2..829688f82e 100644 --- a/resources/install/scripts/park.lua +++ b/resources/install/scripts/park.lua @@ -20,7 +20,7 @@ --connect to the database --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db"); - --dofile(scripts_dir.."/resources/functions/database_handle.lua"); + --require "resources.functions.database_handle"; --dbh = database_handle('system'); --exits the script if we didn't connect properly @@ -38,21 +38,11 @@ park_timeout_seconds = session:getVariable("park_timeout_seconds"); park_music = session:getVariable("park_music"); ---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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr - end +--define the trim function + require "resources.functions.trim"; ---add the trim function - function trim(s) - return s:gsub("^%s+", ""):gsub("%s+$", "") - end +--define the explode function + require "resources.functions.explode"; --if park_timeout_seconds is not defined set the timeout to 5 minutes if (not park_timeout_seconds) then diff --git a/resources/install/scripts/park_monitor.lua b/resources/install/scripts/park_monitor.lua index 495c4a93ac..3162120c48 100644 --- a/resources/install/scripts/park_monitor.lua +++ b/resources/install/scripts/park_monitor.lua @@ -34,7 +34,7 @@ --connect to the database --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db"); - --dofile(scripts_dir.."/resources/functions/database_handle.lua"); + --require "resources.functions.database_handle"; --get the argv values script_name = argv[0]; @@ -48,10 +48,8 @@ --prepare the api api = freeswitch.API(); ---add a trim function - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end +--define the trim function + require "resources.functions.trim"; --monitor the parking lot if the call has hungup send a terminated event, and delete from the db x = 0 diff --git a/resources/install/scripts/pin_number.lua b/resources/install/scripts/pin_number.lua index a5bd1d4c04..fa2cb4bcbf 100644 --- a/resources/install/scripts/pin_number.lua +++ b/resources/install/scripts/pin_number.lua @@ -27,19 +27,11 @@ digit_timeout = 5000; max_retries = 3; tries = 0; -function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) -end +--define the trim function + require "resources.functions.trim"; -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 - end - table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider - return arr -end +--define the explode function + require "resources.functions.explode"; function check_pin_number() --sleep diff --git a/resources/install/scripts/recordings.lua b/resources/install/scripts/recordings.lua index ae5aebb751..dfce840f06 100644 --- a/resources/install/scripts/recordings.lua +++ b/resources/install/scripts/recordings.lua @@ -37,21 +37,21 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --get the domain_uuid domain_uuid = session:getVariable("domain_uuid"); --add functions - dofile(scripts_dir.."/resources/functions/mkdir.lua"); - dofile(scripts_dir.."/resources/functions/explode.lua"); + require "resources.functions.mkdir"; + require "resources.functions.explode"; --initialize the recordings api = freeswitch.API(); --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -124,7 +124,7 @@ --begin recording if (storage_type == "base64") then --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --make the directory mkdir(recordings_dir); diff --git a/resources/install/scripts/resources/functions/base64.lua b/resources/install/scripts/resources/functions/base64.lua index b83a116bbd..c045d93ceb 100644 --- a/resources/install/scripts/resources/functions/base64.lua +++ b/resources/install/scripts/resources/functions/base64.lua @@ -6,7 +6,7 @@ function base64.encode(s) local mime = require("mime"); return (mime.b64(s)); else - dofile(scripts_dir.."/resources/functions/base64_alex.lua"); + require "resources.functions.base64_alex"; return base64.enc(s); end end @@ -17,7 +17,7 @@ function base64.decode(s) local mime = require("mime"); return (mime.unb64(s)); else - dofile(scripts_dir.."/resources/functions/base64_alex.lua"); + require "resources.functions.base64_alex"; return base64.dec(s); end end \ No newline at end of file diff --git a/resources/install/scripts/resources/functions/settings.lua b/resources/install/scripts/resources/functions/settings.lua index 0bcee003c2..d1d1c5eebe 100644 --- a/resources/install/scripts/resources/functions/settings.lua +++ b/resources/install/scripts/resources/functions/settings.lua @@ -2,10 +2,8 @@ --debug debug["sql"] = false; ---define trim - function trim (s) - return (string.gsub(s, "^%s*(.-)%s*$", "%1")) - end +--define the trim function + require "resources.functions.trim"; --get the domain_uuid if (domain_uuid == nil) then diff --git a/resources/install/scripts/streamfile.lua b/resources/install/scripts/streamfile.lua index 079a64f283..7d07cc1960 100644 --- a/resources/install/scripts/streamfile.lua +++ b/resources/install/scripts/streamfile.lua @@ -6,7 +6,7 @@ require "resources.functions.config"; --connect to the database - dofile(scripts_dir.."/resources/functions/database_handle.lua"); + require "resources.functions.database_handle"; dbh = database_handle('system'); --get the variables @@ -23,7 +23,7 @@ if (not default_voice) then default_voice = 'callie'; end --settings - dofile(scripts_dir.."/resources/functions/settings.lua"); + require "resources.functions.settings"; settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -57,10 +57,7 @@ end --check if a file exists - function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end - end + require "resources.functions.file_exists"; --define the on_dtmf call back function function on_dtmf(s, type, obj, arg) @@ -103,7 +100,7 @@ end status = dbh:query(sql, function(row) --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + require "resources.functions.base64"; --add the path to filename file_name = recordings_dir.."/"..file_name_only; --save the recording to the file system diff --git a/resources/install/scripts/wakeup.lua b/resources/install/scripts/wakeup.lua index 45c7774fdb..fd192f1514 100644 --- a/resources/install/scripts/wakeup.lua +++ b/resources/install/scripts/wakeup.lua @@ -27,10 +27,8 @@ domain_name = argv[1]; wakeup_number = argv[2]; ---add the trim function - function trim(s) - return s:gsub("^%s+", ""):gsub("%s+$", "") - end +--define the trim function + require "resources.functions.trim"; --add is_numeric function is_numeric(text) From d8b2ec5271615d3b4a766c20ceb2e4733bc18131 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Mon, 10 Aug 2015 13:01:49 +0400 Subject: [PATCH 6/7] Fix. add functions/count.lua to preview commit. --- resources/install/scripts/resources/functions/count.lua | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 resources/install/scripts/resources/functions/count.lua diff --git a/resources/install/scripts/resources/functions/count.lua b/resources/install/scripts/resources/functions/count.lua new file mode 100644 index 0000000000..4a98776979 --- /dev/null +++ b/resources/install/scripts/resources/functions/count.lua @@ -0,0 +1,9 @@ + +--array count + function count(t) + local c = 0; + for k in pairs(t) do + c = c + 1; + end + return c; + end \ No newline at end of file From 2a2dd209df7320841417c8c0edfcd71a4b18ec18 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 10 Aug 2015 11:50:29 -0600 Subject: [PATCH 7/7] Revert "Change. Use `require "resources.functions.config"` to load config file." --- core/databases/app_defaults.php | 41 ++++-------- resources/install/scripts/app.lua | 4 +- .../scripts/app/agent_status/index.lua | 2 +- .../install/scripts/app/call_block/index.lua | 6 +- .../scripts/app/conference_center/index.lua | 16 ++--- .../resources/scripts/start_recording.lua | 10 +-- .../install/scripts/app/dialplan/index.lua | 4 +- .../inbound/010_get_domain.lua.noload | 4 +- .../scripts/app/event_notify/index.lua | 12 +++- .../scripts/app/failure_handler/index.lua | 6 +- .../app/fax/resources/scripts/hangup_rx.lua | 28 +++++++-- .../install/scripts/app/hangup/index.lua | 8 +-- .../install/scripts/app/is_local/index.lua | 12 ++-- .../install/scripts/app/provision/index.lua | 19 +++++- .../install/scripts/app/ring_groups/index.lua | 12 ++-- .../ring_groups/resources/scripts/confirm.lua | 20 ++++-- .../ring_groups/resources/scripts/monitor.lua | 18 ++++-- .../install/scripts/app/toll_allow/index.lua | 2 +- .../install/scripts/app/voicemail/index.lua | 62 +++++++++---------- .../resources/functions/check_password.lua | 1 + .../resources/functions/choose_greeting.lua | 2 +- .../functions/listen_to_recording.lua | 2 +- .../resources/functions/play_greeting.lua | 2 +- .../resources/functions/record_menu.lua | 2 +- .../resources/functions/record_name.lua | 2 +- .../resources/functions/send_email.lua | 4 +- .../app/voicemail/resources/scripts/mwi.lua | 17 +++-- .../install/scripts/app/xml_handler/index.lua | 6 +- .../scripts/configuration/callcenter.conf.lua | 2 +- .../scripts/configuration/sofia.conf.lua | 2 +- .../resources/scripts/dialplan/dialplan.lua | 2 +- .../scripts/directory/action/domains.lua | 2 +- .../scripts/directory/action/group_call.lua | 2 +- .../directory/action/reverse-auth-lookup.lua | 2 +- .../resources/scripts/directory/directory.lua | 6 +- .../resources/scripts/languages/languages.lua | 2 +- resources/install/scripts/call_flow.lua | 6 +- .../install/scripts/call_flow_monitor.lua | 10 +-- resources/install/scripts/call_forward.lua | 20 ++++-- resources/install/scripts/cidlookup.lua | 26 +++++--- resources/install/scripts/confirm.lua | 5 +- .../install/scripts/destination_caller_id.lua | 12 ++-- resources/install/scripts/dial_string.lua | 6 +- resources/install/scripts/directory.lua | 38 +++++++++--- .../scripts/disa.callback.loopback.lua | 6 +- resources/install/scripts/disa.callback.lua | 8 ++- resources/install/scripts/disa.lua | 16 +++-- resources/install/scripts/disa.plus.lua | 22 +++++-- resources/install/scripts/do_not_disturb.lua | 20 ++++-- resources/install/scripts/eavesdrop.lua | 8 ++- resources/install/scripts/extension_queue.lua | 6 +- resources/install/scripts/fax_retry.lua | 28 +++++++-- resources/install/scripts/follow_me.lua | 20 ++++-- resources/install/scripts/intercept.lua | 8 ++- resources/install/scripts/intercept_group.lua | 10 +-- resources/install/scripts/ivr_menu.lua | 27 +++++--- resources/install/scripts/monitor.lua | 11 +++- resources/install/scripts/page.lua | 16 +++-- resources/install/scripts/park.lua | 24 +++++-- resources/install/scripts/park_monitor.lua | 12 ++-- resources/install/scripts/pin_number.lua | 16 +++-- resources/install/scripts/recordings.lua | 14 +++-- .../scripts/resources/functions/base64.lua | 4 +- .../scripts/resources/functions/config.lua | 20 +----- .../scripts/resources/functions/count.lua | 9 --- .../scripts/resources/functions/settings.lua | 6 +- resources/install/scripts/streamfile.lua | 15 +++-- resources/install/scripts/wakeup.lua | 6 +- .../conf/autoload_configs/lua.conf.xml | 2 +- 69 files changed, 507 insertions(+), 294 deletions(-) delete mode 100644 resources/install/scripts/resources/functions/count.lua diff --git a/core/databases/app_defaults.php b/core/databases/app_defaults.php index dfd247334e..7c40fae423 100644 --- a/core/databases/app_defaults.php +++ b/core/databases/app_defaults.php @@ -24,22 +24,6 @@ Mark J Crane */ -global $IS_WINDOWS; - -if ($IS_WINDOWS == null) { - if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } -} - -if (!function_exists('correct_path')) { - function correct_path($p) { - global $IS_WINDOWS; - if ($IS_WINDOWS) { - return str_replace('/', '\\', $p); - } - return $p; - } -} - //proccess this only one time if ($domains_processed == 1) { @@ -129,31 +113,28 @@ if ($domains_processed == 1) { $tmp = "\n"; $tmp .= "--set the variables\n"; if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { - $tmp .= correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"); + $tmp .= " sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"; } if (strlen($_SESSION['switch']['db']['dir']) > 0) { - $tmp .= correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"); + $tmp .= " database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"; } if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - $tmp .= correct_path(" recordings_dir = [[".$recordings_dir."]];\n"); + $tmp .= " recordings_dir = [[".$recordings_dir."]];\n"; } if (strlen($_SESSION['switch']['storage']['dir']) > 0) { - $tmp .= correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"); + $tmp .= " storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"; } if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) { - $tmp .= correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"); + $tmp .= " voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"; } - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - $tmp .= correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n"); - } - $tmp .= correct_path(" php_dir = [[".PHP_BINDIR."]];\n"); + $tmp .= " php_dir = [[".PHP_BINDIR."]];\n"; if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { $tmp .= " php_bin = \"php.exe\";\n"; } else { $tmp .= " php_bin = \"php\";\n"; } - $tmp .= correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"); + $tmp .= " document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"; $tmp .= "\n"; if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) { @@ -161,7 +142,7 @@ if ($domains_processed == 1) { $tmp .= " database = {}\n"; $tmp .= " database[\"type\"] = \"".$db_type."\";\n"; $tmp .= " database[\"name\"] = \"".$db_name."\";\n"; - $tmp .= correct_path(" database[\"path\"] = [[".$db_path."]];\n"); + $tmp .= " database[\"path\"] = \"".$db_path."\";\n"; if (strlen($dsn_name) > 0) { $tmp .= " database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n"; @@ -185,19 +166,19 @@ if ($domains_processed == 1) { $tmp .= "--additional info\n"; $tmp .= " domain_count = ".count($_SESSION["domains"]).";\n"; - $tmp .= correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"); + $tmp .= " temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"; if (isset($_SESSION['domain']['dial_string']['text'])) { $tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n"; } $tmp .= "\n"; $tmp .= "--include local.lua\n"; - $tmp .= " require(\"resources.functions.file_exists\");\n"; + $tmp .= " dofile(scripts_dir..\"/resources/functions/file_exists.lua\");\n"; $tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n"; $tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n"; $tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n"; $tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n"; $tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n"; - $tmp .= " require(\"resources.local\");\n"; + $tmp .= " dofile(scripts_dir..\"/resources/local.lua\");\n"; $tmp .= " end\n"; fwrite($fout, $tmp); unset($tmp); diff --git a/resources/install/scripts/app.lua b/resources/install/scripts/app.lua index 6f90a8b836..4d6f0c4361 100644 --- a/resources/install/scripts/app.lua +++ b/resources/install/scripts/app.lua @@ -25,7 +25,9 @@ --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --get the argv values script_name = argv[0]; diff --git a/resources/install/scripts/app/agent_status/index.lua b/resources/install/scripts/app/agent_status/index.lua index abbed2e5a3..d950f7abe7 100644 --- a/resources/install/scripts/app/agent_status/index.lua +++ b/resources/install/scripts/app/agent_status/index.lua @@ -6,7 +6,7 @@ debug["sql"] = true; --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --set the api diff --git a/resources/install/scripts/app/call_block/index.lua b/resources/install/scripts/app/call_block/index.lua index 8821a099ef..9ca1d9d8fc 100644 --- a/resources/install/scripts/app/call_block/index.lua +++ b/resources/install/scripts/app/call_block/index.lua @@ -57,7 +57,7 @@ This method causes the script to get its manadatory arguments directly from the local sql = nil --define the functions - require "resources.functions.trim"; + dofile(scripts_dir.."/resources/functions/trim.lua"); --define the logger function local function logger(level, log, data) @@ -88,7 +88,7 @@ This method causes the script to get its manadatory arguments directly from the --if not cached then get the information from the database if (cache == "-ERR NOT FOUND") then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --log if not connect @@ -123,7 +123,7 @@ This method causes the script to get its manadatory arguments directly from the else --get from memcache --add the function - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/explode.lua"); --parse the cache array = explode("&", cache); diff --git a/resources/install/scripts/app/conference_center/index.lua b/resources/install/scripts/app/conference_center/index.lua index 58d61f10fb..5f2a21a919 100644 --- a/resources/install/scripts/app/conference_center/index.lua +++ b/resources/install/scripts/app/conference_center/index.lua @@ -37,19 +37,19 @@ debug["sql"] = false; --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --prepare the api object api = freeswitch.API(); --general functions - require "resources.functions.base64"; - require "resources.functions.trim"; - require "resources.functions.file_exists"; - require "resources.functions.explode"; - require "resources.functions.format_seconds"; - require "resources.functions.mkdir"; + dofile(scripts_dir.."/resources/functions/base64.lua"); + dofile(scripts_dir.."/resources/functions/trim.lua"); + dofile(scripts_dir.."/resources/functions/file_exists.lua"); + dofile(scripts_dir.."/resources/functions/explode.lua"); + dofile(scripts_dir.."/resources/functions/format_seconds.lua"); + dofile(scripts_dir.."/resources/functions/mkdir.lua"); --get the session variables uuid = session:getVariable("uuid"); @@ -153,7 +153,7 @@ end_epoch = os.time(); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --get the conference sessions diff --git a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua index b30412451d..b2a9da42c6 100644 --- a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua +++ b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua @@ -1,10 +1,12 @@ --get the scripts directory and include the config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --additional includes - require "resources.functions.file_exists"; - require "resources.functions.trim"; - require "resources.functions.mkdir"; + dofile(scripts_dir.."/resources/functions/file_exists.lua"); + dofile(scripts_dir.."/resources/functions/trim.lua"); + dofile(scripts_dir.."/resources/functions/mkdir.lua"); --get the argv values script_name = argv[0]; diff --git a/resources/install/scripts/app/dialplan/index.lua b/resources/install/scripts/app/dialplan/index.lua index fbd3892031..0679747163 100644 --- a/resources/install/scripts/app/dialplan/index.lua +++ b/resources/install/scripts/app/dialplan/index.lua @@ -19,8 +19,8 @@ -- the Initial Developer. All Rights Reserved. --add functions - require "resources.functions.file_exists"; - require "resources.functions.trim"; + dofile(scripts_dir.."/resources/functions/file_exists.lua"); + dofile(scripts_dir.."/resources/functions/trim.lua"); --set the api object api = freeswitch.API(); diff --git a/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload b/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload index cbdeefea70..3493b46377 100644 --- a/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload +++ b/resources/install/scripts/app/dialplan/resources/inbound/010_get_domain.lua.noload @@ -32,7 +32,7 @@ end --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --get the cache @@ -64,7 +64,7 @@ else --add the function - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/explode.lua"); --parse the cache array = explode("&", cache); diff --git a/resources/install/scripts/app/event_notify/index.lua b/resources/install/scripts/app/event_notify/index.lua index 827ddfe664..68f7002c8e 100644 --- a/resources/install/scripts/app/event_notify/index.lua +++ b/resources/install/scripts/app/event_notify/index.lua @@ -23,8 +23,16 @@ -- Mark J Crane -- Errol Samuels ---define the explode function - require "resources.functions.explode"; +--define explode + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --usage --luarun app.lua event_notify internal reboot 1003@domain.fusionpbx.com yealink diff --git a/resources/install/scripts/app/failure_handler/index.lua b/resources/install/scripts/app/failure_handler/index.lua index 6e174911ce..038b6f6c96 100644 --- a/resources/install/scripts/app/failure_handler/index.lua +++ b/resources/install/scripts/app/failure_handler/index.lua @@ -28,9 +28,9 @@ debug["sql"] = false; --include config.lua - require "resources.functions.config"; - require "resources.functions.explode"; - require "resources.functions.trim"; + dofile(scripts_dir .. "/resources/functions/config.lua"); + dofile(scripts_dir .. "/resources/functions/explode.lua"); + dofile(scripts_dir .. "/resources/functions/trim.lua"); --check the missed calls function missed() 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 d70db541e9..e7e623d2d9 100644 --- a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua +++ b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua @@ -26,17 +26,33 @@ api = freeswitch.API(); --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --define the explode function - require "resources.functions.explode"; + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --array count - require "resources.functions.count"; + function count(t) + c = 0; + for k,v in pairs(t) do + c = c+1; + end + return c; + end -- set channel variables to lua variables domain_uuid = env:getHeader("domain_uuid"); @@ -52,7 +68,7 @@ end --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -297,7 +313,7 @@ if (fax_success =="1") then if (storage_type == "base64") then --include the base64 function - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --base64 encode the file local f = io.open(fax_file, "rb"); diff --git a/resources/install/scripts/app/hangup/index.lua b/resources/install/scripts/app/hangup/index.lua index 9a77d819cc..05d4dd1329 100644 --- a/resources/install/scripts/app/hangup/index.lua +++ b/resources/install/scripts/app/hangup/index.lua @@ -25,10 +25,10 @@ debug["sql"] = false; --general functions - require "resources.functions.config"; - require "resources.functions.explode"; - require "resources.functions.trim"; - -- require "resources.functions.file_exists"; + dofile(scripts_dir .. "/resources/functions/config.lua"); + dofile(scripts_dir .. "/resources/functions/explode.lua"); + dofile(scripts_dir.."/resources/functions/trim.lua"); + --dofile(scripts_dir.."/resources/functions/file_exists.lua"); --create the api object api = freeswitch.API(); diff --git a/resources/install/scripts/app/is_local/index.lua b/resources/install/scripts/app/is_local/index.lua index 1fcbf9aaa9..9d9e06fba5 100644 --- a/resources/install/scripts/app/is_local/index.lua +++ b/resources/install/scripts/app/is_local/index.lua @@ -29,14 +29,18 @@ outbound_caller_id_number = session:getVariable("outbound_caller_id_number"); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --prepare the api object api = freeswitch.API(); ---define the trim function - require "resources.functions.trim"; +--add the trim function + function trim(s) + if (s) then + return s:gsub("^%s+", ""):gsub("%s+$", "") + end + end --get the cache cache = trim(api:execute("memcache", "get app:dialplan:outbound:is_local:" .. destination_number .. "@" .. domain_name)); @@ -80,7 +84,7 @@ end)); else --add the function - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/explode.lua"); --define the array/table and variables local var = {} diff --git a/resources/install/scripts/app/provision/index.lua b/resources/install/scripts/app/provision/index.lua index 5eba2c844a..f0b910f3b7 100644 --- a/resources/install/scripts/app/provision/index.lua +++ b/resources/install/scripts/app/provision/index.lua @@ -26,8 +26,16 @@ --set the debug options debug["sql"] = false; ---define the explode function - require "resources.functions.explode"; +--define explode + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --set the defaults max_tries = 3; @@ -36,8 +44,13 @@ tries = 0; profile = "internal"; +--include config.lua + --scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + --dofile(scripts_dir.."/resources/functions/config.lua"); + --dofile(config()); + --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --answer diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index 70e1f72ec8..d375160595 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -28,12 +28,12 @@ -- Luis Daniel Lucio Qurioz --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --include functions - require "resources.functions.trim"; - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/trim.lua"); + dofile(scripts_dir.."/resources/functions/explode.lua"); --get the variables domain_name = session:getVariable("domain_name"); @@ -329,16 +329,16 @@ or ring_group_strategy == "sequence" or ring_group_strategy == "rollover") then session:execute("set", "group_confirm_key=exec"); - session:execute("set", "group_confirm_file=lua ".. scripts_dir:gsub('\\','/') .."/confirm.lua"); + session:execute("set", "group_confirm_file=lua ".. scripts_dir .."/confirm.lua"); end --determine confirm prompt if (destination_prompt == nil) then group_confirm = "confirm=false,"; elseif (destination_prompt == "1") then - group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir:gsub('\\','/') .."/confirm.lua,confirm=true,"; + group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir .."/confirm.lua,confirm=true,"; elseif (destination_prompt == "2") then - group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir:gsub('\\','/') .."/confirm.lua,confirm=true,"; + group_confirm = "group_confirm_key=exec,group_confirm_file=lua ".. scripts_dir .."/confirm.lua,confirm=true,"; else group_confirm = "confirm=false,"; end diff --git a/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua b/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua index ab77b5d0a9..b934862092 100644 --- a/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua +++ b/resources/install/scripts/app/ring_groups/resources/scripts/confirm.lua @@ -23,17 +23,27 @@ -- Mark J Crane --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); --set variables max_tries = "3"; digit_timeout = "5000"; ---define the trim function - require "resources.functions.trim"; +--add a trim function + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end ---define the explode function - require "resources.functions.explode"; +--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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --get the argv values script_name = argv[0]; diff --git a/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua b/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua index 36e373685d..2b54a4a152 100644 --- a/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua +++ b/resources/install/scripts/app/ring_groups/resources/scripts/monitor.lua @@ -33,11 +33,21 @@ uuid = argv[1]; timeout = argv[2]; ---define the trim function - require "resources.functions.trim"; +--add a trim function + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end ---define the explode function - require "resources.functions.explode"; +--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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --prepare the api api = freeswitch.API(); diff --git a/resources/install/scripts/app/toll_allow/index.lua b/resources/install/scripts/app/toll_allow/index.lua index 31844e4e69..869add5847 100644 --- a/resources/install/scripts/app/toll_allow/index.lua +++ b/resources/install/scripts/app/toll_allow/index.lua @@ -26,7 +26,7 @@ --debug debug["toll_type"] = false - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/explode.lua"); --create the api object and get variables api = freeswitch.API() diff --git a/resources/install/scripts/app/voicemail/index.lua b/resources/install/scripts/app/voicemail/index.lua index 056127af3b..e0c2383890 100644 --- a/resources/install/scripts/app/voicemail/index.lua +++ b/resources/install/scripts/app/voicemail/index.lua @@ -50,7 +50,7 @@ password_tries = 0; --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --set the api @@ -123,7 +123,7 @@ end --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -200,36 +200,36 @@ end --general functions - require "resources.functions.base64"; - require "resources.functions.trim"; - require "resources.functions.file_exists"; - require "resources.functions.explode"; - require "resources.functions.format_seconds"; - require "resources.functions.mkdir"; - require "resources.functions.copy"; + dofile(scripts_dir.."/resources/functions/base64.lua"); + dofile(scripts_dir.."/resources/functions/trim.lua"); + dofile(scripts_dir.."/resources/functions/file_exists.lua"); + dofile(scripts_dir.."/resources/functions/explode.lua"); + dofile(scripts_dir.."/resources/functions/format_seconds.lua"); + dofile(scripts_dir.."/resources/functions/mkdir.lua"); + dofile(scripts_dir.."/resources/functions/copy.lua"); --voicemail functions - require "app.voicemail.resources.functions.on_dtmf"; - require "app.voicemail.resources.functions.get_voicemail_id"; - require "app.voicemail.resources.functions.check_password"; - require "app.voicemail.resources.functions.change_password"; - require "app.voicemail.resources.functions.macro"; - require "app.voicemail.resources.functions.play_greeting"; - require "app.voicemail.resources.functions.record_message"; - require "app.voicemail.resources.functions.record_menu"; - require "app.voicemail.resources.functions.forward_to_extension"; - require "app.voicemail.resources.functions.main_menu"; - require "app.voicemail.resources.functions.listen_to_recording"; - require "app.voicemail.resources.functions.message_waiting"; - require "app.voicemail.resources.functions.send_email"; - require "app.voicemail.resources.functions.delete_recording"; - require "app.voicemail.resources.functions.message_saved"; - require "app.voicemail.resources.functions.return_call"; - require "app.voicemail.resources.functions.menu_messages"; - require "app.voicemail.resources.functions.advanced"; - require "app.voicemail.resources.functions.record_greeting"; - require "app.voicemail.resources.functions.choose_greeting"; - require "app.voicemail.resources.functions.record_name"; + dofile(scripts_dir.."/app/voicemail/resources/functions/on_dtmf.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/get_voicemail_id.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/check_password.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/change_password.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/macro.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/play_greeting.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/record_message.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/record_menu.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/forward_to_extension.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/main_menu.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/listen_to_recording.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/message_waiting.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/send_email.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/delete_recording.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/message_saved.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/return_call.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/menu_messages.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/advanced.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/record_greeting.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/choose_greeting.lua"); + dofile(scripts_dir.."/app/voicemail/resources/functions/record_name.lua"); --send a message waiting event if (voicemail_action == "mwi") then @@ -318,7 +318,7 @@ freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); --include the base64 function - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --base64 encode the file if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then diff --git a/resources/install/scripts/app/voicemail/resources/functions/check_password.lua b/resources/install/scripts/app/voicemail/resources/functions/check_password.lua index b95cf1feae..5170fdcab7 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/check_password.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/check_password.lua @@ -82,3 +82,4 @@ end end end +--dofile(scripts_dir.."/app/voicemail/resources/functions/check_password.lua"); \ No newline at end of file diff --git a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua index 0e71727c6d..f8611c398a 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua @@ -96,7 +96,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --set the voicemail message path greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua b/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua index cf4971e5e2..89e0925ff5 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua @@ -67,7 +67,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --set the voicemail message path message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua index 358059e0a6..484dc24ef0 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua @@ -52,7 +52,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --set the voicemail message path greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua b/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua index cd0f950f15..be468907ea 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua @@ -83,7 +83,7 @@ --if base64, encode file if (storage_type == "base64") then --include the base64 function - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --base64 encode the file local f = io.open(real_file, "rb"); local file_content = f:read("*all"); diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_name.lua b/resources/install/scripts/app/voicemail/resources/functions/record_name.lua index fb4b3d6587..fa4f039902 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_name.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_name.lua @@ -44,7 +44,7 @@ --record and save the file if (storage_type == "base64") then --include the base64 function - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --set the location voicemail_name_location = voicemail_dir.."/"..voicemail_id.."/recorded_name.wav"; 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 f00cb942a5..b2f0fe5867 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua @@ -52,7 +52,7 @@ --require the email address to send the email if (string.len(voicemail_mail_to) > 2) then --include languages file - require "app.voicemail.app_languages"; + dofile(scripts_dir.."/app/voicemail/app_languages.lua"); --get voicemail message details sql = [[SELECT * FROM v_voicemail_messages @@ -73,7 +73,7 @@ --get the recordings from the database if (storage_type == "base64") then --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --set the voicemail message path message_location = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; diff --git a/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua b/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua index 82d9d17973..be241cc5d8 100644 --- a/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua +++ b/resources/install/scripts/app/voicemail/resources/scripts/mwi.lua @@ -24,7 +24,9 @@ -- POSSIBILITY OF SUCH DAMAGE. --include the lua script - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --define general settings sleep = 300; @@ -39,18 +41,23 @@ --only run the script a single time runonce = true --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --used to stop the lua service local file = assert(io.open(run_file, "w")); file:write("remove this file to stop the script"); ---define the trim function - require "resources.functions.trim"; +--add the trim function + function trim(s) + return s:gsub("^%s+", ""):gsub("%s+$", "") + end --check if a file exists - require "resources.functions.file_exists"; + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --create the api object api = freeswitch.API(); diff --git a/resources/install/scripts/app/xml_handler/index.lua b/resources/install/scripts/app/xml_handler/index.lua index 770c5a4b0c..d97f45f408 100644 --- a/resources/install/scripts/app/xml_handler/index.lua +++ b/resources/install/scripts/app/xml_handler/index.lua @@ -39,9 +39,9 @@ debug["cache"] = false; --general functions - require "resources.functions.trim"; - require "resources.functions.file_exists"; - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/trim.lua"); + dofile(scripts_dir.."/resources/functions/file_exists.lua"); + dofile(scripts_dir.."/resources/functions/explode.lua"); --if the params class and methods do not exist then add them to prevent errors if (not params) then diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua index a4006530f3..a884a23ed8 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua @@ -36,7 +36,7 @@ if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua index 6656f619f3..41d74a8651 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua @@ -36,7 +36,7 @@ if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua index c838fcf782..077ebf77e0 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua @@ -35,7 +35,7 @@ if (XML_STRING == "-ERR NOT FOUND") then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly 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 10df751dcb..e0ec0d6b5e 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 @@ -25,7 +25,7 @@ -- POSSIBILITY OF SUCH DAMAGE. --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua index 458c6d02c9..b00c279891 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/group_call.lua @@ -34,7 +34,7 @@ --set the cache if (XML_STRING == "-ERR NOT FOUND") then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua index 6711bc1f0f..fca7636069 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/directory/action/reverse-auth-lookup.lua @@ -32,7 +32,7 @@ --user_call - user has been called --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly 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 307594da85..6658dd49a8 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 @@ -109,7 +109,7 @@ --database connection if (continue) then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly @@ -154,14 +154,14 @@ --freeswitch.consoleLog("notice", "[xml_handler-directory.lua] local_hostname is " .. local_hostname .. "\n"); --add the file_exists function - require "resources.functions.file_exists"; + dofile(scripts_dir.."/resources/functions/file_exists.lua"); --connect to the switch database if (file_exists(database_dir.."/core.db")) then --dbh_switch = freeswitch.Dbh("core:core"); -- when using sqlite dbh_switch = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); else - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh_switch = database_handle('switch'); end diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua index 86047db948..ae1b29bfc7 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua @@ -65,7 +65,7 @@ --database connection if (continue) then --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --exits the script if we didn't connect properly diff --git a/resources/install/scripts/call_flow.lua b/resources/install/scripts/call_flow.lua index a8298a067c..ee62ed61a6 100644 --- a/resources/install/scripts/call_flow.lua +++ b/resources/install/scripts/call_flow.lua @@ -29,10 +29,12 @@ digit_timeout = "5000"; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); if (session:ready()) then diff --git a/resources/install/scripts/call_flow_monitor.lua b/resources/install/scripts/call_flow_monitor.lua index 5be5ccf4bb..c6cff6aa04 100644 --- a/resources/install/scripts/call_flow_monitor.lua +++ b/resources/install/scripts/call_flow_monitor.lua @@ -32,14 +32,16 @@ debug["sql"] = false; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --general functions - require "resources.functions.file_exists"; - require "resources.functions.mkdir"; + dofile(scripts_dir.."/resources/functions/file_exists.lua"); + dofile(scripts_dir.."/resources/functions/mkdir.lua"); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --make sure the scripts/run dir exists diff --git a/resources/install/scripts/call_forward.lua b/resources/install/scripts/call_forward.lua index ceb87a5701..2269b3df85 100644 --- a/resources/install/scripts/call_forward.lua +++ b/resources/install/scripts/call_forward.lua @@ -32,16 +32,28 @@ debug["sql"] = false; --define the trim function - require "resources.functions.trim" + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --define the explode function - require "resources.functions.explode" + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --create the api object api = freeswitch.API(); --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --check if the session is ready if (session:ready()) then @@ -71,7 +83,7 @@ session:sleep(1000); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --request id is true diff --git a/resources/install/scripts/cidlookup.lua b/resources/install/scripts/cidlookup.lua index b45a319d49..338b12928d 100644 --- a/resources/install/scripts/cidlookup.lua +++ b/resources/install/scripts/cidlookup.lua @@ -30,10 +30,20 @@ debug["sql"] = true; --define the trim function - require "resources.functions.trim" + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --define the explode function - require "resources.functions.explode" + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --create the api object api = freeswitch.API(); @@ -69,20 +79,22 @@ end; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --check if the session is ready - + --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); - + if (database["type"] == "mysql") then sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts "; else sql = "SELECT v_contacts.contact_name_given || ' ' || v_contacts.contact_name_family || ' (' || v_contact_phones.phone_type || ')' AS name FROM v_contacts "; end - + sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid "; sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid "; sql = sql .. "WHERE v_contact_phones.phone_number = '"..caller.."' AND v_destinations.destination_number='"..callee.."'"; diff --git a/resources/install/scripts/confirm.lua b/resources/install/scripts/confirm.lua index b51d4279c7..7c8f452ce1 100644 --- a/resources/install/scripts/confirm.lua +++ b/resources/install/scripts/confirm.lua @@ -26,7 +26,10 @@ digit_timeout = "5000"; --check if a file exists - require "resources.functions.file_exists" + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --run if the session is ready if ( session:ready() ) then diff --git a/resources/install/scripts/destination_caller_id.lua b/resources/install/scripts/destination_caller_id.lua index df105bd919..89742740ad 100644 --- a/resources/install/scripts/destination_caller_id.lua +++ b/resources/install/scripts/destination_caller_id.lua @@ -25,14 +25,18 @@ -- POSSIBILITY OF SUCH DAMAGE. --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); ---define the trim function - require "resources.functions.trim" +--add a trim function + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --get the variables domain_name = session:getVariable("domain_name"); diff --git a/resources/install/scripts/dial_string.lua b/resources/install/scripts/dial_string.lua index 5616d64778..b4a7a2f522 100644 --- a/resources/install/scripts/dial_string.lua +++ b/resources/install/scripts/dial_string.lua @@ -34,10 +34,12 @@ db_extension_uuid = ""; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); if ( session:ready() ) then diff --git a/resources/install/scripts/directory.lua b/resources/install/scripts/directory.lua index 01b4f85455..c987e13ff9 100644 --- a/resources/install/scripts/directory.lua +++ b/resources/install/scripts/directory.lua @@ -34,14 +34,21 @@ search_count = 0; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); + +--include config.lua + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -151,8 +158,16 @@ end end ---define the explode function - require "resources.functions.explode" +--define explode + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --define a function to convert dialpad letters to numbers function dialpad_to_digit(letter) @@ -185,11 +200,16 @@ return count end ---define the trim function - require "resources.functions.trim" +--define trim + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --check if a file exists - require "resources.functions.file_exists" + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --define select_entry function function select_entry() @@ -248,7 +268,7 @@ end status = dbh:query(sql, function(field) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --set the voicemail message path file_location = voicemail_dir.."/"..row.extension.."/recorded_name.wav"; diff --git a/resources/install/scripts/disa.callback.loopback.lua b/resources/install/scripts/disa.callback.loopback.lua index d0fb1b8923..00b00d46fa 100644 --- a/resources/install/scripts/disa.callback.loopback.lua +++ b/resources/install/scripts/disa.callback.loopback.lua @@ -27,10 +27,12 @@ debug["sql"] = true; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); api = freeswitch.API(); diff --git a/resources/install/scripts/disa.callback.lua b/resources/install/scripts/disa.callback.lua index ab471109bc..121da756a1 100644 --- a/resources/install/scripts/disa.callback.lua +++ b/resources/install/scripts/disa.callback.lua @@ -27,16 +27,18 @@ debug["sql"] = false; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); api = freeswitch.API(); --other libs - require "resources.functions.trim"; + dofile(scripts_dir.."/resources/functions/trim.lua"); aleg_number = argv[1]; bleg_number = argv[2]; diff --git a/resources/install/scripts/disa.lua b/resources/install/scripts/disa.lua index 893b33b5a6..7ce526edc5 100644 --- a/resources/install/scripts/disa.lua +++ b/resources/install/scripts/disa.lua @@ -26,11 +26,19 @@ predefined_destination = ""; max_tries = "3"; digit_timeout = "5000"; ---define the trim function - require "resources.functions.trim"; +function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) +end ---define the explode function - require "resources.functions.explode"; +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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr +end if ( session:ready() ) then session:answer( ); diff --git a/resources/install/scripts/disa.plus.lua b/resources/install/scripts/disa.plus.lua index 575fd06385..5d8e3963d5 100644 --- a/resources/install/scripts/disa.plus.lua +++ b/resources/install/scripts/disa.plus.lua @@ -31,19 +31,29 @@ digit_timeout = "5000"; debug["sql"] = true; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); api = freeswitch.API(); ---define the trim function - require "resources.functions.trim"; +function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) +end ---define the explode function - require "resources.functions.explode"; +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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr +end if ( session:ready() ) then session:answer( ); diff --git a/resources/install/scripts/do_not_disturb.lua b/resources/install/scripts/do_not_disturb.lua index f48c426dee..9b7666b156 100644 --- a/resources/install/scripts/do_not_disturb.lua +++ b/resources/install/scripts/do_not_disturb.lua @@ -32,16 +32,28 @@ debug["sql"] = false; --define the trim function - require "resources.functions.trim"; + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --define the explode function - require "resources.functions.explode"; + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --create the api object api = freeswitch.API(); --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --check if the session is ready if ( session:ready() ) then @@ -70,7 +82,7 @@ session:sleep(1000); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --determine whether to update the dial string diff --git a/resources/install/scripts/eavesdrop.lua b/resources/install/scripts/eavesdrop.lua index f89c557491..bebaa6cb34 100644 --- a/resources/install/scripts/eavesdrop.lua +++ b/resources/install/scripts/eavesdrop.lua @@ -28,10 +28,12 @@ digit_timeout = "5000"; extension = argv[1]; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --add the file_exists function - require "resources.functions.file_exists"; + dofile(scripts_dir.."/resources/functions/file_exists.lua"); --connect to the database if (file_exists(database_dir.."/core.db")) then @@ -39,7 +41,7 @@ extension = argv[1]; dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); freeswitch.consoleLog("NOTICE", "[eavesdrop] using core.db\n"); else - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('switch'); freeswitch.consoleLog("NOTICE", "[eavesdrop] using freeswitch db\n"); diff --git a/resources/install/scripts/extension_queue.lua b/resources/install/scripts/extension_queue.lua index 2f8ed817ab..db83c14017 100644 --- a/resources/install/scripts/extension_queue.lua +++ b/resources/install/scripts/extension_queue.lua @@ -24,10 +24,12 @@ -- Riccardo Granchi --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); if (session:ready()) then diff --git a/resources/install/scripts/fax_retry.lua b/resources/install/scripts/fax_retry.lua index f1fda766b1..64d214cdea 100644 --- a/resources/install/scripts/fax_retry.lua +++ b/resources/install/scripts/fax_retry.lua @@ -31,17 +31,33 @@ api = freeswitch.API(); --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --define the explode function - require "resources.functions.explode"; + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --array count - require "resources.functions.count"; + function count(t) + c = 0; + for k,v in pairs(t) do + c = c+1; + end + return c; + end -- show all channel variables --dat = env:serialize() @@ -125,7 +141,7 @@ end --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -288,7 +304,7 @@ if (fax_success =="1") then if (storage_type == "base64") then --include the base64 function - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --base64 encode the file local f = io.open(fax_file, "rb"); diff --git a/resources/install/scripts/follow_me.lua b/resources/install/scripts/follow_me.lua index bfacd96359..5485093413 100644 --- a/resources/install/scripts/follow_me.lua +++ b/resources/install/scripts/follow_me.lua @@ -32,16 +32,28 @@ debug["sql"] = true; --define the trim function - require "resources.functions.trim"; + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --define the explode function - require "resources.functions.explode"; + 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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end --create the api object api = freeswitch.API(); --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --check if the session is ready if ( session:ready() ) then @@ -69,7 +81,7 @@ session:sleep(1000); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --determine whether to update the dial string diff --git a/resources/install/scripts/intercept.lua b/resources/install/scripts/intercept.lua index b6927c6083..419813c0cc 100644 --- a/resources/install/scripts/intercept.lua +++ b/resources/install/scripts/intercept.lua @@ -32,14 +32,16 @@ debug["sql"] = false; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database if (file_exists(database_dir.."/core.db")) then --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); else - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('switch'); end @@ -47,7 +49,7 @@ api = freeswitch.API(); --add the function - require "resources.functions.trim"; + dofile(scripts_dir.."/resources/functions/trim.lua"); --exits the script if we didn't connect properly assert(dbh:connected()); diff --git a/resources/install/scripts/intercept_group.lua b/resources/install/scripts/intercept_group.lua index e6078da4d7..13a82e70df 100644 --- a/resources/install/scripts/intercept_group.lua +++ b/resources/install/scripts/intercept_group.lua @@ -31,13 +31,15 @@ debug["sql"] = false; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --add the function - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/explode.lua"); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --check if the session is ready @@ -147,7 +149,7 @@ --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); else - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('switch'); end diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 09ab8fe8fb..b4d916de0c 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -32,10 +32,12 @@ debug["tries"] = false; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --get the variables @@ -47,7 +49,7 @@ domain_uuid = session:getVariable("domain_uuid"); --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -84,11 +86,16 @@ --set default variable(s) tries = 0; ---define the trim function - require "resources.functions.trim" +--add the trim function + function trim(s) + return s:gsub("^%s+", ""):gsub("%s+$", "") + end --check if a file exists - require "resources.functions.file_exists" + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --prepare the api object api = freeswitch.API(); @@ -212,7 +219,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --add the path to filename ivr_menu_greet_long = recordings_dir.."/"..greet_long_file_name; ivr_menu_greet_long_is_base64 = true; @@ -236,7 +243,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --add the path to filename ivr_menu_greet_short = recordings_dir.."/"..greet_short_file_name; ivr_menu_greet_short_is_base64 = true; @@ -260,7 +267,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --add the path to filename ivr_menu_invalid_sound = recordings_dir.."/"..invalid_sound_file_name; ivr_menu_invalid_sound_is_base64 = true; @@ -284,7 +291,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --add the path to filename ivr_menu_exit_sound = recordings_dir.."/"..exit_sound_file_name; ivr_menu_exit_sound_is_base64 = true; diff --git a/resources/install/scripts/monitor.lua b/resources/install/scripts/monitor.lua index baf3ef55f7..0b86958a93 100644 --- a/resources/install/scripts/monitor.lua +++ b/resources/install/scripts/monitor.lua @@ -31,11 +31,16 @@ local file = assert(io.open(tmp_file, "w")); file:write("remove this file to stop the script"); ---define the trim function - require "resources.functions.trim" +--add the trim function + function trim(s) + return s:gsub("^%s+", ""):gsub("%s+$", "") + end --check if a file exists - require "resources.functions.file_exists" + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --create the api object api = freeswitch.API(); diff --git a/resources/install/scripts/page.lua b/resources/install/scripts/page.lua index 80bf8c80df..0f3af2af14 100644 --- a/resources/install/scripts/page.lua +++ b/resources/install/scripts/page.lua @@ -28,11 +28,19 @@ pin_number = ""; max_tries = "3"; digit_timeout = "3000"; ---define the trim function - require "resources.functions.trim"; +function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) +end ---define the explode function - require "resources.functions.explode"; +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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr +end if ( session:ready() ) then session:answer(); diff --git a/resources/install/scripts/park.lua b/resources/install/scripts/park.lua index 829688f82e..42b47ce423 100644 --- a/resources/install/scripts/park.lua +++ b/resources/install/scripts/park.lua @@ -15,12 +15,14 @@ --action lua park.lua --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db"); - --require "resources.functions.database_handle"; + --dofile(scripts_dir.."/resources/functions/database_handle.lua"); --dbh = database_handle('system'); --exits the script if we didn't connect properly @@ -38,11 +40,21 @@ park_timeout_seconds = session:getVariable("park_timeout_seconds"); park_music = session:getVariable("park_music"); ---define the trim function - require "resources.functions.trim"; +--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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr + end ---define the explode function - require "resources.functions.explode"; +--add the trim function + function trim(s) + return s:gsub("^%s+", ""):gsub("%s+$", "") + end --if park_timeout_seconds is not defined set the timeout to 5 minutes if (not park_timeout_seconds) then diff --git a/resources/install/scripts/park_monitor.lua b/resources/install/scripts/park_monitor.lua index 3162120c48..e7b0a7a455 100644 --- a/resources/install/scripts/park_monitor.lua +++ b/resources/install/scripts/park_monitor.lua @@ -29,12 +29,14 @@ --then send presence terminate, and delete from the database --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database --dbh = freeswitch.Dbh("core:core"); -- when using sqlite dbh = freeswitch.Dbh("sqlite://"..database_dir.."/park.db"); - --require "resources.functions.database_handle"; + --dofile(scripts_dir.."/resources/functions/database_handle.lua"); --get the argv values script_name = argv[0]; @@ -48,8 +50,10 @@ --prepare the api api = freeswitch.API(); ---define the trim function - require "resources.functions.trim"; +--add a trim function + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --monitor the parking lot if the call has hungup send a terminated event, and delete from the db x = 0 diff --git a/resources/install/scripts/pin_number.lua b/resources/install/scripts/pin_number.lua index fa2cb4bcbf..a5bd1d4c04 100644 --- a/resources/install/scripts/pin_number.lua +++ b/resources/install/scripts/pin_number.lua @@ -27,11 +27,19 @@ digit_timeout = 5000; max_retries = 3; tries = 0; ---define the trim function - require "resources.functions.trim"; +function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) +end ---define the explode function - require "resources.functions.explode"; +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 + end + table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider + return arr +end function check_pin_number() --sleep diff --git a/resources/install/scripts/recordings.lua b/resources/install/scripts/recordings.lua index f03fd0a0d4..40c5624cc1 100644 --- a/resources/install/scripts/recordings.lua +++ b/resources/install/scripts/recordings.lua @@ -34,24 +34,26 @@ recording_prefix = ""; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --get the domain_uuid domain_uuid = session:getVariable("domain_uuid"); --add functions - require "resources.functions.mkdir"; - require "resources.functions.explode"; + dofile(scripts_dir.."/resources/functions/mkdir.lua"); + dofile(scripts_dir.."/resources/functions/explode.lua"); --initialize the recordings api = freeswitch.API(); --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -125,7 +127,7 @@ --begin recording if (storage_type == "base64") then --include the base64 function - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --make the directory mkdir(recordings_dir); diff --git a/resources/install/scripts/resources/functions/base64.lua b/resources/install/scripts/resources/functions/base64.lua index c045d93ceb..b83a116bbd 100644 --- a/resources/install/scripts/resources/functions/base64.lua +++ b/resources/install/scripts/resources/functions/base64.lua @@ -6,7 +6,7 @@ function base64.encode(s) local mime = require("mime"); return (mime.b64(s)); else - require "resources.functions.base64_alex"; + dofile(scripts_dir.."/resources/functions/base64_alex.lua"); return base64.enc(s); end end @@ -17,7 +17,7 @@ function base64.decode(s) local mime = require("mime"); return (mime.unb64(s)); else - require "resources.functions.base64_alex"; + dofile(scripts_dir.."/resources/functions/base64_alex.lua"); return base64.dec(s); end end \ No newline at end of file diff --git a/resources/install/scripts/resources/functions/config.lua b/resources/install/scripts/resources/functions/config.lua index 70dcb0efe7..c43b0c0f00 100644 --- a/resources/install/scripts/resources/functions/config.lua +++ b/resources/install/scripts/resources/functions/config.lua @@ -1,26 +1,12 @@ --- add file_exists function - require "resources.functions.file_exists"; - --find and return path to the config.lua function config() + dofile(scripts_dir.."/resources/functions/file_exists.lua"); if (file_exists("/etc/fusionpbx/config.lua")) then return "/etc/fusionpbx/config.lua"; elseif (file_exists("/usr/local/etc/fusionpbx/config.lua")) then return "/usr/local/etc/fusionpbx/config.lua"; else - return "resources.config"; + return scripts_dir.."/resources/config.lua"; end - end - --- load config - function load_config() - local cfg = config() - if cfg:sub(1,1) == '//' then - dofile(cfg) - else - require(cfg) - end - end - - load_config() + end \ No newline at end of file diff --git a/resources/install/scripts/resources/functions/count.lua b/resources/install/scripts/resources/functions/count.lua deleted file mode 100644 index 4a98776979..0000000000 --- a/resources/install/scripts/resources/functions/count.lua +++ /dev/null @@ -1,9 +0,0 @@ - ---array count - function count(t) - local c = 0; - for k in pairs(t) do - c = c + 1; - end - return c; - end \ No newline at end of file diff --git a/resources/install/scripts/resources/functions/settings.lua b/resources/install/scripts/resources/functions/settings.lua index 8c5952cdd1..1c1971849a 100644 --- a/resources/install/scripts/resources/functions/settings.lua +++ b/resources/install/scripts/resources/functions/settings.lua @@ -2,8 +2,10 @@ --debug debug["sql"] = false; ---define the trim function - require "resources.functions.trim"; +--define trim + function trim (s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) + end --get the domain_uuid if (domain_uuid == nil) then diff --git a/resources/install/scripts/streamfile.lua b/resources/install/scripts/streamfile.lua index 576fd46a29..02b6ca3d47 100644 --- a/resources/install/scripts/streamfile.lua +++ b/resources/install/scripts/streamfile.lua @@ -3,10 +3,12 @@ file_name = argv[1]; --include config.lua - require "resources.functions.config"; + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); --connect to the database - require "resources.functions.database_handle"; + dofile(scripts_dir.."/resources/functions/database_handle.lua"); dbh = database_handle('system'); --get the variables @@ -23,7 +25,7 @@ if (not default_voice) then default_voice = 'callie'; end --settings - require "resources.functions.settings"; + dofile(scripts_dir.."/resources/functions/settings.lua"); settings = settings(domain_uuid); storage_type = ""; storage_path = ""; @@ -59,7 +61,10 @@ end --check if a file exists - require "resources.functions.file_exists"; + function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --define the on_dtmf call back function function on_dtmf(s, type, obj, arg) @@ -102,7 +107,7 @@ end status = dbh:query(sql, function(row) --add functions - require "resources.functions.base64"; + dofile(scripts_dir.."/resources/functions/base64.lua"); --add the path to filename file_name = recordings_dir.."/"..file_name_only; --save the recording to the file system diff --git a/resources/install/scripts/wakeup.lua b/resources/install/scripts/wakeup.lua index fd192f1514..45c7774fdb 100644 --- a/resources/install/scripts/wakeup.lua +++ b/resources/install/scripts/wakeup.lua @@ -27,8 +27,10 @@ domain_name = argv[1]; wakeup_number = argv[2]; ---define the trim function - require "resources.functions.trim"; +--add the trim function + function trim(s) + return s:gsub("^%s+", ""):gsub("%s+$", "") + end --add is_numeric function is_numeric(text) diff --git a/resources/templates/conf/autoload_configs/lua.conf.xml b/resources/templates/conf/autoload_configs/lua.conf.xml index f485269a9c..a608494467 100644 --- a/resources/templates/conf/autoload_configs/lua.conf.xml +++ b/resources/templates/conf/autoload_configs/lua.conf.xml @@ -13,8 +13,8 @@ These entries will be pre-pended to the LUA_PATH environment variable --> + -