Event Socket settings auto defaults or custom using config.conf

This commit is contained in:
FusionPBX
2023-09-16 15:07:41 -06:00
committed by GitHub
parent 0e55637bf6
commit bf47bbcc47
14 changed files with 221 additions and 1711 deletions
+1 -64
View File
@@ -82,68 +82,5 @@
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "7ca40076-b66b-4fe5-90e8-ceb4fe27391c";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "event_socket_ip_address";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "text";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "127.0.0.1";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "IP Address used to connect to event socket.";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "570804f2-65b9-423a-9758-f09c1b4b1482";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "event_socket_port";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "numeric";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "8021";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "Port to connect to event socket.";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "ecd4923b-8396-4d83-b52d-809fe179f93a";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "event_socket_password";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "text";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "ClueCon";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "Password to connect to event socket.";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "2541e9e5-ac09-46f2-8d22-ebc3756b22b7";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "event_socket_acl";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "text";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "false";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "Access control list required to connect to event socket.";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "90c7638c-8ecc-4210-bd7b-c301aef3ae7a";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "xml_rpc_http_port";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "numeric";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "8080";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "d7a91830-6faf-4b26-80e6-c9f9e1898425";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "xml_rpc_auth_realm";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "text";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "freeswitch";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "4a1a4b4c-1a5b-45bb-8393-36c1cb42c875";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "xml_rpc_auth_user";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "text";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "freeswitch";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "";
$y++;
$apps[$x]['default_settings'][$y]['default_setting_uuid'] = "8b51edfe-13f7-4ca3-989a-516072bec0b7";
$apps[$x]['default_settings'][$y]['default_setting_category'] = "switch";
$apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "xml_rpc_auth_pass";
$apps[$x]['default_settings'][$y]['default_setting_name'] = "text";
$apps[$x]['default_settings'][$y]['default_setting_value'] = "works";
$apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true";
$apps[$x]['default_settings'][$y]['default_setting_description'] = "";
$y++;
?>
+1 -100
View File
@@ -27,109 +27,10 @@
//process this only one time
if ($domains_processed == 1) {
//includes files
require 'app/switch/resources/classes/scripts.php';
//copy the switch scripts
$obj = new scripts;
$obj->copy_files();
//move the default settings
$database = new database;
if ($database->table_exists('v_settings')) {
$sql = "select * from v_settings ";
$database = new database;
$row = $database->select($sql, null, 'row');
if (!empty($row)) {
//initialize the setting object
$setting = new settings(["category" => "switch"]);
//save the default settings
if ($setting->get('switch', 'event_socket_ip_address') !== $row["event_socket_ip_address"]) {
$array['setting_uuid'] = "7ca40076-b66b-4fe5-90e8-ceb4fe27391c";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "event_socket_ip_address";
$array['setting_name'] = "text";
$array['setting_value'] = $row["event_socket_ip_address"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'event_socket_port') !== $row["event_socket_port"]) {
$array['setting_uuid'] = "570804f2-65b9-423a-9758-f09c1b4b1482";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "event_socket_port";
$array['setting_name'] = "numeric";
$array['setting_value'] = $row["event_socket_port"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'event_socket_password') !== $row["event_socket_password"]) {
$array['setting_uuid'] = "ecd4923b-8396-4d83-b52d-809fe179f93a";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "event_socket_password";
$array['setting_name'] = "text";
$array['setting_value'] = $row["event_socket_password"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'event_socket_acl') !== $row["event_socket_acl"]) {
$array['setting_uuid'] = "2541e9e5-ac09-46f2-8d22-ebc3756b22b7";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "event_socket_acl";
$array['setting_name'] = "text";
$array['setting_value'] = $row["event_socket_acl"];
$array['setting_enabled'] = (empty($row["event_socket_acl"])) ? "false" : "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'xml_rpc_http_port') !== $row["xml_rpc_http_port"]) {
$array['setting_uuid'] = "90c7638c-8ecc-4210-bd7b-c301aef3ae7a";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "xml_rpc_http_port";
$array['setting_name'] = "numeric";
$array['setting_value'] = $row["xml_rpc_http_port"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'xml_rpc_auth_realm') !== $row["xml_rpc_auth_realm"]) {
$array['setting_uuid'] = "d7a91830-6faf-4b26-80e6-c9f9e1898425";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "xml_rpc_auth_realm";
$array['setting_name'] = "text";
$array['setting_value'] = $row["xml_rpc_auth_realm"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'xml_rpc_auth_user') !== $row["xml_rpc_auth_user"]) {
$array['setting_uuid'] = "4a1a4b4c-1a5b-45bb-8393-36c1cb42c875";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "xml_rpc_auth_user";
$array['setting_name'] = "text";
$array['setting_value'] = $row["xml_rpc_auth_user"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
if ($setting->get('switch', 'xml_rpc_auth_pass') !== $row["xml_rpc_auth_pass"]) {
$array['setting_uuid'] = "8b51edfe-13f7-4ca3-989a-516072bec0b7";
$array['setting_category'] = "switch";
$array['setting_subcategory'] = "xml_rpc_auth_pass";
$array['setting_name'] = "text";
$array['setting_value'] = $row["xml_rpc_auth_pass"];
$array['setting_enabled'] = "true";
$array['setting_description'] = "";
$setting->set($array);
}
}
unset($sql, $row);
}
}
?>
@@ -1,131 +0,0 @@
-- xml_handler.lua
-- Part of FusionPBX
-- Copyright (C) 2023 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--include xml library
local Xml = require "resources.functions.xml";
--get the cache
local cache = require "resources.functions.cache"
local event_socket_cache_key = "configuration:event_socket.conf"
XML_STRING, err = cache.get(event_socket_cache_key)
--set the cache
if not XML_STRING then
--log cache error
if (debug["cache"]) then
freeswitch.consoleLog("warning", "[xml_handler] configuration:event_socket.conf can not get from the cache: " .. tostring(err) .. "\n");
end
--set a default value
if (expire["acl"] == nil) then
expire["acl"]= "3600";
end
--connect to the database
local Database = require "resources.functions.database";
dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--exits the script if we didn't connect properly
assert(dbh:connected());
--start the xml array
local xml = Xml:new();
xml:append([[<configuration name="event_socket.conf" description="Socket Client">]]);
xml:append([[ <settings>]]);
--run the query
sql = "select default_setting_subcategory as name, default_setting_value as value from v_default_settings ";
sql = sql .. "where default_setting_category = 'switch' ";
sql = sql .. "and default_setting_subcategory like 'event_socket_%' ";
sql = sql .. "and default_setting_enabled = 'true' ";
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
end
x = 0;
dbh:query(sql, function(row)
if (row.name == 'event_socket_nat_map') then
xml:append([[ <param name="nat-map" value="]] .. xml.sanitize(row.value) .. [[" />]]);
end
if (row.name == 'event_socket_ip_address') then
xml:append([[ <param name="listen-ip" value="]] .. xml.sanitize(row.value) .. [["/>]]);
end
if (row.name == 'event_socket_port') then
xml:append([[ <param name="listen-port" value="]] .. xml.sanitize(row.value) .. [["/>]]);
end
if (row.name == 'event_socket_password') then
xml:append([[ <param name="password" value="]] .. xml.sanitize(row.value) .. [["/>]]);
end
if (row.name == 'event_socket_acl') then
xml:append([[ <param name="apply-inbound-acl" value="]] .. xml.sanitize(row.value) .. [["/>]]);
end
end)
--close the extension tag if it was left open
xml:append([[ </settings>]]);
xml:append([[</configuration>]]);
XML_STRING = xml:build();
-- if (debug["xml_string"]) then
-- freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n");
-- end
--close the database connection
dbh:release();
--set the cache
local ok, err = cache.set(event_socket_cache_key, XML_STRING, expire["acl"]);
if debug["cache"] then
if ok then
freeswitch.consoleLog("notice", "[xml_handler] " .. event_socket_cache_key .. " stored in the cache\n");
else
freeswitch.consoleLog("warning", "[xml_handler] " .. event_socket_cache_key .. " can not be stored in the cache: " .. tostring(err) .. "\n");
end
end
--send to the console
if (debug["cache"]) then
freeswitch.consoleLog("notice", "[xml_handler] " .. event_socket_cache_key .. " source: database\n");
end
else
--send to the console
if (debug["cache"]) then
freeswitch.consoleLog("notice", "[xml_handler] " .. event_socket_cache_key .. " source: cache\n");
end
end --if XML_STRING
--send the xml to the console
if (debug["xml_string"]) then
local file = assert(io.open(temp_dir .. "/event_socket.conf.xml", "w"));
file:write(XML_STRING);
file:close();
end
@@ -1,191 +1,207 @@
-- add file_exists function
require "resources.functions.file_exists";
require "resources.functions.explode";
require "resources.functions.trim";
require "resources.functions.file_exists";
require "resources.functions.explode";
require "resources.functions.trim";
--find and return path to the config.conf
function config()
if (file_exists("/usr/local/etc/fusionpbx/config.conf")) then
return "/usr/local/etc/fusionpbx/config.conf";
elseif (file_exists("/etc/fusionpbx/config.conf")) then
return "/etc/fusionpbx/config.conf";
else
require "resources.config";
return config_file;
end
function config()
if (file_exists("/usr/local/etc/fusionpbx/config.conf")) then
return "/usr/local/etc/fusionpbx/config.conf";
elseif (file_exists("/etc/fusionpbx/config.conf")) then
return "/etc/fusionpbx/config.conf";
else
require "resources.config";
return config_file;
end
end
--load config
function load_config()
--get the config file
config_file = config();
function load_config()
--get the config file
config_file = config();
--define arrays
database = {}
database.system = {}
database.switch = {}
database.backend = {}
switch = {}
xml_handler = {}
cache = {}
--define arrays
database = {}
database.system = {}
database.switch = {}
database.backend = {}
switch = {}
xml_handler = {}
cache = {}
--read the config file
file = io.open(config_file);
lines = file:lines();
for line in lines do
if (line and string.match(line, "=")) then
--parse the setings
a = explode("=", line);
k = trim(a[1])
v = trim(a[2])
--read the config file
file = io.open(config_file);
lines = file:lines();
for line in lines do
if (line and string.match(line, "=")) then
--parse the setings
a = explode("=", line);
k = trim(a[1])
v = trim(a[2])
--debug information
--freeswitch.consoleLog("notice","line " .. line .. "\n");
--freeswitch.consoleLog("notice","key: " .. k .. ", value: ".. v .. "\n");
--debug information
--freeswitch.consoleLog("notice","line " .. line .. "\n");
--freeswitch.consoleLog("notice","key: " .. k .. ", value: ".. v .. "\n");
--database system settings
if (k == "database.0.type") then database.system.type = v; end
if (k == "database.0.host") then database.system.host = v; end
if (k == "database.0.path") then database.system.path = v; end
if (k == "database.0.hostaddr") then database.system.hostaddr = v; end
if (k == "database.0.port") then database.system.port = v; end
if (k == "database.0.sslmode") then database.system.sslmode = v; end
if (k == "database.0.name") then database.system.name = v; end
if (k == "database.0.username") then database.system.username = v; end
if (k == "database.0.password") then database.system.password = v; end
if (k == "database.0.backend.base64") then database.system.backend.base64 = v; end
--database system settings
if (k == "database.0.type") then database.system.type = v; end
if (k == "database.0.host") then database.system.host = v; end
if (k == "database.0.path") then database.system.path = v; end
if (k == "database.0.hostaddr") then database.system.hostaddr = v; end
if (k == "database.0.port") then database.system.port = v; end
if (k == "database.0.sslmode") then database.system.sslmode = v; end
if (k == "database.0.name") then database.system.name = v; end
if (k == "database.0.username") then database.system.username = v; end
if (k == "database.0.password") then database.system.password = v; end
if (k == "database.0.backend.base64") then database.system.backend.base64 = v; end
--database switch settings
if (k == "database.1.type") then database.switch.type = v; end
if (k == "database.1.path") then database.switch.path = v; end
if (k == "database.1.name") then database.switch.name = v; end
if (k == "database.1.host") then database.switch.host = v; end
if (k == "database.1.hostaddr") then database.switch.hostaddr = v; end
if (k == "database.1.port") then database.switch.port = v; end
if (k == "database.1.sslmode") then database.switch.sslmode = v; end
if (k == "database.1.username") then database.switch.username = v; end
if (k == "database.1.password") then database.switch.password = v; end
if (k == "database.1.backend.base64") then database.backend.base64 = v; end
--database switch settings
if (k == "database.1.type") then database.switch.type = v; end
if (k == "database.1.path") then database.switch.path = v; end
if (k == "database.1.name") then database.switch.name = v; end
if (k == "database.1.host") then database.switch.host = v; end
if (k == "database.1.hostaddr") then database.switch.hostaddr = v; end
if (k == "database.1.port") then database.switch.port = v; end
if (k == "database.1.sslmode") then database.switch.sslmode = v; end
if (k == "database.1.username") then database.switch.username = v; end
if (k == "database.1.password") then database.switch.password = v; end
if (k == "database.1.backend.base64") then database.backend.base64 = v; end
--switch settings
if (k == "switch.conf.dir") then conf_dir = v; end
if (k == "switch.sounds.dir") then sounds_dir = v; end
if (k == "switch.database.dir") then database_dir = v; end
if (k == "switch.database.name") then database_name = v; end
if (k == "switch.recordings.dir") then recordings_dir = v; end
if (k == "switch.storage.dir") then storage_dir = v; end
if (k == "switch.voicemail.dir") then voicemail_dir = v; end
if (k == "switch.scripts.dir") then scripts_dir = v; end
--switch settings
if (k == "switch.conf.dir") then conf_dir = v; end
if (k == "switch.sounds.dir") then sounds_dir = v; end
if (k == "switch.database.dir") then database_dir = v; end
if (k == "switch.database.name") then database_name = v; end
if (k == "switch.recordings.dir") then recordings_dir = v; end
if (k == "switch.storage.dir") then storage_dir = v; end
if (k == "switch.voicemail.dir") then voicemail_dir = v; end
if (k == "switch.scripts.dir") then scripts_dir = v; end
--switch xml handler
if (k == "xml_handler.fs_path") then xml_handler.fs_path = v; end
if (k == "xml_handler.reg_as_number_alias") then xml_handler.reg_as_number_alias = v; end
if (k == "xml_handler.number_as_presence_id") then xml_handler.number_as_presence_id = v; end
--switch event socket settings
if (k == "switch.event_socket.host") then event_socket_host = v; end
if (k == "switch.event_socket.port") then event_socket_port = v; end
if (k == "switch.event_socket.password") then event_socket_password = v; end
--general settings
if (k == "php.dir") then php_dir = v; end
if (k == "php.bin") then php_bin = v; end
if (k == "document.root") then document_root = v; end
if (k == "project.path") then project_path = v; end
if (k == "temp.dir") then temp_dir = v; end
--switch xml handler
if (k == "xml_handler.fs_path") then xml_handler.fs_path = v; end
if (k == "xml_handler.reg_as_number_alias") then xml_handler.reg_as_number_alias = v; end
if (k == "xml_handler.number_as_presence_id") then xml_handler.number_as_presence_id = v; end
--cache settings
if (k == "cache.method") then cache.method = v; end
if (k == "cache.location") then cache.location = v; end
if (k == "cache.settings") then cache.settings = v; end
--general settings
if (k == "php.dir") then php_dir = v; end
if (k == "php.bin") then php_bin = v; end
if (k == "document.root") then document_root = v; end
if (k == "project.path") then project_path = v; end
if (k == "temp.dir") then temp_dir = v; end
--show the array
--for i,v in ipairs(a) do
-- freeswitch.consoleLog("notice","key " .. i .. " value ".. v .. "\n");
--end
end
--cache settings
if (k == "cache.method") then cache.method = v; end
if (k == "cache.location") then cache.location = v; end
if (k == "cache.settings") then cache.settings = v; end
--show the array
--for i,v in ipairs(a) do
-- freeswitch.consoleLog("notice","key " .. i .. " value ".. v .. "\n");
--end
end
io.close(file);
end
io.close(file);
--set the database values
database.type = database.switch.type;
if (database.type == 'sqlite') then
database.path = database.switch.path;
database.name = database.switch.name;
end
--database system dsn
system_dsn = {}
if (database.system.type == 'pgsql') then
--create the system_dsn array
table.insert(system_dsn, [[pgsql://]]);
if (database.system.host) then
table.insert(system_dsn, [[host=]] .. database.system.host .. [[ ]]);
end
if (database.system.hostaddr) then
table.insert(system_dsn, [[hostaddr=]] .. database.system.hostaddr .. [[ ]]);
end
table.insert(system_dsn, [[port=]] .. database.system.port .. [[ ]]);
if (database.switch.sslmode) then
table.insert(system_dsn, [[sslmode=]] .. database.system.sslmode .. [[ ]]);
end
table.insert(system_dsn, [[dbname=]] .. database.system.name .. [[ ]]);
table.insert(system_dsn, [[user=]] .. database.system.username .. [[ ]]);
table.insert(system_dsn, [[password=]] .. database.system.password .. [[ ]]);
elseif (database.system.type == 'sqlite') then
--create the system_dsn array
table.insert(system_dsn, [[sqlite://]] .. database.system.path .. [[/]].. database.system.name ..[[ ]]);
end
database.system = table.concat(system_dsn, '');
--database switch dsn
switch_dsn = {}
if (database.switch.type == 'pgsql') then
--create the switch_dsn array
table.insert(switch_dsn, [[pgsql://]]);
if (database.switch.host) then
table.insert(switch_dsn, [[host=]] .. database.switch.host .. [[ ]]);
end
if (database.switch.hostaddr) then
table.insert(switch_dsn, [[hostaddr=]] .. database.switch.hostaddr .. [[ ]]);
end
table.insert(switch_dsn, [[host=]] .. database.switch.host .. [[ ]]);
table.insert(switch_dsn, [[port=]] .. database.switch.port .. [[ ]]);
if (database.switch.sslmode) then
table.insert(switch_dsn, [[sslmode=]] .. database.switch.sslmode .. [[ ]]);
end
table.insert(switch_dsn, [[dbname=]] .. database.switch.name .. [[ ]]);
table.insert(switch_dsn, [[user=]] .. database.switch.username .. [[ ]]);
table.insert(switch_dsn, [[password=]] .. database.switch.password .. [[ ]]);
database.switch = table.concat(switch_dsn, '');
elseif (database.switch.type == 'sqlite') then
--create the switch_dsn array
table.insert(switch_dsn, [[sqlite://]] .. database.switch.path .. [[/]].. database.switch.name ..[[ ]]);
end
database.switch = table.concat(switch_dsn, '');
--set defaults
expire = {}
expire.default = "3600";
expire.directory = "3600";
expire.dialplan = "3600";
expire.languages = "3600";
expire.sofia = "3600";
expire.acl = "3600";
expire.ivr = "3600";
--set settings
settings = {}
settings.recordings = {}
settings.voicemail = {}
settings.fax = {}
settings.recordings.storage_type = "";
settings.voicemail.storage_type = "";
settings.fax.storage_type = "";
--set the debug options
debug = {}
debug.params = false;
debug.sql = false;
debug.xml_request = false;
debug.xml_string = false;
--set the database values
database.type = database.switch.type;
if (database.type == 'sqlite') then
database.path = database.switch.path;
database.name = database.switch.name;
end
--database system dsn
system_dsn = {}
if (database.system.type == 'pgsql') then
--create the system_dsn array
table.insert(system_dsn, [[pgsql://]]);
if (database.system.host) then
table.insert(system_dsn, [[host=]] .. database.system.host .. [[ ]]);
end
if (database.system.hostaddr) then
table.insert(system_dsn, [[hostaddr=]] .. database.system.hostaddr .. [[ ]]);
end
table.insert(system_dsn, [[port=]] .. database.system.port .. [[ ]]);
if (database.switch.sslmode) then
table.insert(system_dsn, [[sslmode=]] .. database.system.sslmode .. [[ ]]);
end
table.insert(system_dsn, [[dbname=]] .. database.system.name .. [[ ]]);
table.insert(system_dsn, [[user=]] .. database.system.username .. [[ ]]);
table.insert(system_dsn, [[password=]] .. database.system.password .. [[ ]]);
elseif (database.system.type == 'sqlite') then
--create the system_dsn array
table.insert(system_dsn, [[sqlite://]] .. database.system.path .. [[/]].. database.system.name ..[[ ]]);
end
database.system = table.concat(system_dsn, '');
--database switch dsn
switch_dsn = {}
if (database.switch.type == 'pgsql') then
--create the switch_dsn array
table.insert(switch_dsn, [[pgsql://]]);
if (database.switch.host) then
table.insert(switch_dsn, [[host=]] .. database.switch.host .. [[ ]]);
end
if (database.switch.hostaddr) then
table.insert(switch_dsn, [[hostaddr=]] .. database.switch.hostaddr .. [[ ]]);
end
table.insert(switch_dsn, [[host=]] .. database.switch.host .. [[ ]]);
table.insert(switch_dsn, [[port=]] .. database.switch.port .. [[ ]]);
if (database.switch.sslmode) then
table.insert(switch_dsn, [[sslmode=]] .. database.switch.sslmode .. [[ ]]);
end
table.insert(switch_dsn, [[dbname=]] .. database.switch.name .. [[ ]]);
table.insert(switch_dsn, [[user=]] .. database.switch.username .. [[ ]]);
table.insert(switch_dsn, [[password=]] .. database.switch.password .. [[ ]]);
database.switch = table.concat(switch_dsn, '');
elseif (database.switch.type == 'sqlite') then
--create the switch_dsn array
table.insert(switch_dsn, [[sqlite://]] .. database.switch.path .. [[/]].. database.switch.name ..[[ ]]);
end
database.switch = table.concat(switch_dsn, '');
--event socket settings
if (event_socket_host == nil) then
event_socket_host = '127.0.0.1';
end
if (event_socket_port == nil) then
event_socket_port = '8021';
end
if (event_socket_password == nil) then
event_socket_password = 'ClueCon';
end
--set defaults
expire = {}
expire.default = "3600";
expire.directory = "3600";
expire.dialplan = "3600";
expire.languages = "3600";
expire.sofia = "3600";
expire.acl = "3600";
expire.ivr = "3600";
--set settings
settings = {}
settings.recordings = {}
settings.voicemail = {}
settings.fax = {}
settings.recordings.storage_type = "";
settings.voicemail.storage_type = "";
settings.fax.storage_type = "";
--set the debug options
debug = {}
debug.params = false;
debug.sql = false;
debug.xml_request = false;
debug.xml_string = false;
end
--autoload the configuration
load_config();
load_config();
@@ -34,15 +34,10 @@ local host, port, auth
function EventSocket:__init()
if not host then
local db = Database.new('system')
local sql = [[SELECT
MAX(CASE WHEN default_setting_subcategory = 'event_socket_ip_address' THEN default_setting_value END) AS event_socket_address,
MAX(CASE WHEN default_setting_subcategory = 'event_socket_port' THEN default_setting_value END) AS event_socket_port,
MAX(CASE WHEN default_setting_subcategory = 'event_socket_password' THEN default_setting_value END) AS event_socket_password
FROM v_default_settings]];
local settings, err = db:first_row(sql)
if not settings then return nil, err end
host, port, auth = settings.event_socket_ip_address, settings.event_socket_port, settings.event_socket_password
require "resources.functions.config";
host = event_socket_host;
port = event_socket_port;
auth = event_socket_password;
end
return self:_connect(host, port, auth)