From bf47bbcc476db5d2f26edd32b3e6f19799621766 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sat, 16 Sep 2023 15:07:41 -0600 Subject: [PATCH] Event Socket settings auto defaults or custom using config.conf --- app/access_controls/app_defaults.php | 2 +- app/phrases/app_defaults.php | 2 +- app/settings/app_config.php | 143 ----- app/settings/app_defaults.php | 91 ---- app/settings/app_languages.php | 507 ------------------ app/settings/app_menu.php | 35 -- app/settings/setting_edit.php | 362 ------------- app/switch/app_config.php | 65 +-- app/switch/app_defaults.php | 101 +--- .../configuration/event_socket.conf.lua | 131 ----- .../scripts/resources/functions/config.lua | 354 ++++++------ .../scripts/resources/functions/esl.lua | 13 +- resources/classes/event_socket.php | 31 +- resources/switch.php | 95 +--- 14 files changed, 221 insertions(+), 1711 deletions(-) delete mode 100644 app/settings/app_config.php delete mode 100644 app/settings/app_defaults.php delete mode 100644 app/settings/app_languages.php delete mode 100644 app/settings/app_menu.php delete mode 100644 app/settings/setting_edit.php delete mode 100644 app/switch/resources/scripts/app/xml_handler/resources/scripts/configuration/event_socket.conf.lua diff --git a/app/access_controls/app_defaults.php b/app/access_controls/app_defaults.php index 3f35ae8a3f..c43a8382d0 100644 --- a/app/access_controls/app_defaults.php +++ b/app/access_controls/app_defaults.php @@ -158,7 +158,7 @@ //create the event socket connection if (!$fp) { - $fp = event_socket_create($setting->get('switch','event_socket_ip_address'), $setting->get('switch','event_socket_port'), $setting->get('switch','event_socket_password')); + $fp = event_socket_create(); } //reload the acl diff --git a/app/phrases/app_defaults.php b/app/phrases/app_defaults.php index 4a211a17fe..0adbfb19a7 100644 --- a/app/phrases/app_defaults.php +++ b/app/phrases/app_defaults.php @@ -142,7 +142,7 @@ if ($domains_processed == 1) { //save_phrases_xml(); //delete the phrase from memcache - $fp = event_socket_create($setting->get('switch','event_socket_ip_address'), $setting->get('switch','event_socket_port'), $setting->get('switch','event_socket_password')); + $fp = event_socket_create(); if ($fp) { //get phrase languages $sql = "select distinct phrase_language from v_phrases order by phrase_language asc "; diff --git a/app/settings/app_config.php b/app/settings/app_config.php deleted file mode 100644 index 61a59bc781..0000000000 --- a/app/settings/app_config.php +++ /dev/null @@ -1,143 +0,0 @@ - diff --git a/app/settings/app_defaults.php b/app/settings/app_defaults.php deleted file mode 100644 index 80d41e6a8a..0000000000 --- a/app/settings/app_defaults.php +++ /dev/null @@ -1,91 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2014 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -if ($domains_processed == 1) { - //get the data from the database - $sql = "select event_socket_ip_address from v_settings "; - $database = new database; - $event_socket_ip_address = $database->select($sql, null, 'column'); - - //check the row count - if (empty($event_socket_ip_address)) { - //add default settings - $event_socket_ip_address = "127.0.0.1"; - $event_socket_port = "8021"; - $event_socket_password = "ClueCon"; - $xml_rpc_http_port = "8080"; - $xml_rpc_auth_realm = "freeswitch"; - $xml_rpc_auth_user = "freeswitch"; - $xml_rpc_auth_pass = "works"; - $mod_shout_decoder = ""; - $mod_shout_volume = "0.3"; - //build array - $array['settings'][0]['setting_uuid'] = uuid(); - $array['settings'][0]['event_socket_ip_address'] = $event_socket_ip_address; - $array['settings'][0]['event_socket_port'] = $event_socket_port; - $array['settings'][0]['event_socket_password'] = $event_socket_password; - $array['settings'][0]['xml_rpc_http_port'] = $xml_rpc_http_port; - $array['settings'][0]['xml_rpc_auth_realm'] = $xml_rpc_auth_realm; - $array['settings'][0]['xml_rpc_auth_user'] = $xml_rpc_auth_user; - $array['settings'][0]['xml_rpc_auth_pass'] = $xml_rpc_auth_pass; - $array['settings'][0]['mod_shout_decoder'] = $mod_shout_decoder; - $array['settings'][0]['mod_shout_volume'] = $mod_shout_volume; - //grant temporary permissions - $p = new permissions; - $p->add('setting_add', 'temp'); - //execute insert - $database = new database; - $database->app_name = 'settings'; - $database->app_uuid = 'b6b1b2e5-4ba5-044c-8a5c-18709a15eb60'; - $database->save($array, false); - unset($array); - //revoke temporary permissions - $p->delete('setting_add', 'temp'); - } - - if (isset($_SESSION['event_socket_ip_address'])) { - $event_socket_ip_address = $_SESSION['event_socket_ip_address']; - if (isset($_SESSION['event_socket_port'])) { $event_socket_port = $_SESSION['event_socket_port']; } - if (isset($_SESSION['event_socket_password'])) { $event_socket_password = $_SESSION['event_socket_password']; } - //build array - $array['settings'][0]['event_socket_ip_address'] = $event_socket_ip_address; - $array['settings'][0]['event_socket_port'] = $event_socket_port; - $array['settings'][0]['event_socket_password'] = $event_socket_password; - //grant temporary permissions - $p = new permissions; - $p->add('setting_edit', 'temp'); - //execute update - $database = new database; - $database->app_name = 'settings'; - $database->app_uuid = 'b6b1b2e5-4ba5-044c-8a5c-18709a15eb60'; - $database->save($array, false); - unset($array); - //revoke temporary permissions - $p->delete('setting_edit', 'temp'); - } -} - -?> diff --git a/app/settings/app_languages.php b/app/settings/app_languages.php deleted file mode 100644 index ab9ae2c641..0000000000 --- a/app/settings/app_languages.php +++ /dev/null @@ -1,507 +0,0 @@ - diff --git a/app/settings/app_menu.php b/app/settings/app_menu.php deleted file mode 100644 index 426f563479..0000000000 --- a/app/settings/app_menu.php +++ /dev/null @@ -1,35 +0,0 @@ - diff --git a/app/settings/setting_edit.php b/app/settings/setting_edit.php deleted file mode 100644 index 8ae3ce0f42..0000000000 --- a/app/settings/setting_edit.php +++ /dev/null @@ -1,362 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2020 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane - James Rose -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('setting_view') || if_group("superadmin")) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//get the number of rows in v_extensions - $sql = " select count(*) from v_settings "; - $database = new database; - $num_rows = $database->select($sql, $parameters ?? null, 'column'); - -//set the action - $action = $num_rows == 0 ? "add" : "update"; - -//get the http values and set them as php variables - if (!empty($_POST)) { - //$numbering_plan = $_POST["numbering_plan"]; - //$default_gateway = $_POST["default_gateway"]; - $setting_uuid = $_POST["setting_uuid"]; - $event_socket_ip_address = $_POST["event_socket_ip_address"]; - if (empty($event_socket_ip_address)) { $event_socket_ip_address = '127.0.0.1'; } - $event_socket_port = $_POST["event_socket_port"]; - $event_socket_password = $_POST["event_socket_password"]; - $event_socket_acl = $_POST["event_socket_acl"]; - $xml_rpc_http_port = $_POST["xml_rpc_http_port"]; - $xml_rpc_auth_realm = $_POST["xml_rpc_auth_realm"]; - $xml_rpc_auth_user = $_POST["xml_rpc_auth_user"]; - $xml_rpc_auth_pass = $_POST["xml_rpc_auth_pass"]; - //$admin_pin = $_POST["admin_pin"]; - $mod_shout_decoder = $_POST["mod_shout_decoder"]; - $mod_shout_volume = $_POST["mod_shout_volume"]; - } - -if (!empty($_POST) && empty($_POST["persistformvar"])) { - - //check for all required data - $msg = ''; - //if (empty($numbering_plan)) { $msg .= "Please provide: Numbering Plan
\n"; } - //if (empty($default_gateway)) { $msg .= "Please provide: Default Gateway
\n"; } - if (empty($event_socket_port)) { $msg .= "Please provide: Event Socket Port
\n"; } - if (empty($event_socket_password)) { $msg .= "Please provide: Event Socket Password
\n"; } - //if (empty($event_socket_acl)) { $msg .= "Please provide: Event Socket ACL
\n"; } - //if (empty($xml_rpc_http_port)) { $msg .= "Please provide: XML RPC HTTP Port
\n"; } - //if (empty($xml_rpc_auth_realm)) { $msg .= "Please provide: XML RPC Auth Realm
\n"; } - //if (empty($xml_rpc_auth_user)) { $msg .= "Please provide: XML RPC Auth User
\n"; } - //if (empty($xml_rpc_auth_pass)) { $msg .= "Please provide: XML RPC Auth Password
\n"; } - //if (empty($admin_pin)) { $msg .= "Please provide: Admin PIN Number
\n"; } - //if (empty($mod_shout_decoder)) { $msg .= "Please provide: Mod Shout Decoder
\n"; } - //if (empty($mod_shout_volume)) { $msg .= "Please provide: Mod Shout Volume
\n"; } - if (!empty($msg) && empty($_POST["persistformvar"])) { - require_once "resources/header.php"; - require_once "resources/persist_form_var.php"; - echo "
\n"; - echo "
\n"; - echo $msg."
"; - echo "
\n"; - persistformvar($_POST); - echo "
\n"; - require_once "resources/footer.php"; - return; - } - - //add or update the database - if (empty($_POST["persistformvar"])) { - if (permission_exists('setting_edit')) { - //build array - $array['settings'][0]['setting_uuid'] = $action == "add" ? uuid() : $setting_uuid; - $array['settings'][0]['event_socket_ip_address'] = $event_socket_ip_address; - $array['settings'][0]['event_socket_port'] = $event_socket_port; - $array['settings'][0]['event_socket_password'] = $event_socket_password; - $array['settings'][0]['event_socket_acl'] = $event_socket_acl; - $array['settings'][0]['xml_rpc_http_port'] = $xml_rpc_http_port; - $array['settings'][0]['xml_rpc_auth_realm'] = $xml_rpc_auth_realm; - $array['settings'][0]['xml_rpc_auth_user'] = $xml_rpc_auth_user; - $array['settings'][0]['xml_rpc_auth_pass'] = $xml_rpc_auth_pass; - $array['settings'][0]['mod_shout_decoder'] = $mod_shout_decoder; - $array['settings'][0]['mod_shout_volume'] = $mod_shout_volume; - //grant temporary permissions - $p = new permissions; - if ($action == 'add') { - $p->add('setting_add', 'temp'); - } - else if ($action == 'update') { - $p->add('setting_edit', 'temp'); - } - //execute insert - $database = new database; - $database->app_name = 'settings'; - $database->app_uuid = 'b6b1b2e5-4ba5-044c-8a5c-18709a15eb60'; - $database->save($array); - unset($array); - //revoke temporary permissions - $p->delete('setting_add', 'temp'); - $p->delete('setting_edit', 'temp'); - //synchronize settings - save_setting_xml(); - //set message - if ($action == 'add') { - message::add($text['message-add']); - } - else if ($action == 'update') { - message::add($text['message-update']); - } - //redirect - header("Location: setting_edit.php"); - exit; - } - } - } - -//pre-populate the form - if (empty($_POST["persistformvar"])) { - $sql = "select * from v_settings "; - $database = new database; - $row = $database->select($sql, null, 'row'); - if (!empty($row)) { - $setting_uuid = $row['setting_uuid']; - $event_socket_ip_address = $row["event_socket_ip_address"]; - $event_socket_port = $row["event_socket_port"]; - $event_socket_password = $row["event_socket_password"]; - $event_socket_acl = $row["event_socket_acl"]; - $xml_rpc_http_port = $row["xml_rpc_http_port"]; - $xml_rpc_auth_realm = $row["xml_rpc_auth_realm"]; - $xml_rpc_auth_user = $row["xml_rpc_auth_user"]; - $xml_rpc_auth_pass = $row["xml_rpc_auth_pass"]; - $mod_shout_decoder = $row["mod_shout_decoder"]; - $mod_shout_volume = $row["mod_shout_volume"]; - } - unset($sql, $row); - } - -//show the header - if ($action == "add") { - $document['title'] = $text['title-settings_add']; - } - else if ($action == "update") { - $document['title'] = $text['title-settings_update']; - } - require_once "resources/header.php"; - -//show the content - echo "
\n"; - - echo "
\n"; - echo "
"; - if ($action == "add") { - echo "".$text['title-settings_add'].""; - } - else if ($action == "update") { - echo "".$text['title-settings_update'].""; - } - echo "
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'never','onclick'=>'submit_form();']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo " ".$text['label-event_socket_ip']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-event_socket_ip']."\n"; - echo "
\n"; - echo " ".$text['label-event_socket_port']."\n"; - echo "\n"; - echo " \n"; - echo " \n"; //help defeat browser auto-fill - echo "
\n"; - echo $text['description-event_socket_port']."\n"; - echo "
\n"; - echo " ".$text['label-event_socket_password']."\n"; - echo "\n"; - echo " \n"; //help defeat browser auto-fill - echo " \n"; - echo "
\n"; - echo $text['description-event_socket_password']."\n"; - echo "
\n"; - echo " ".$text['label-event_socket_acl']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo !empty($text['description-event_socket_acl'])."\n"; - echo "
\n"; - echo " ".$text['label-xml_rpc_http_port']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-xml_rpc_http_port']."\n"; - echo "
\n"; - echo " ".$text['label-xml_rpc_auth_realm']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-xml_rpc_auth_realm']."\n"; - echo "
\n"; - echo " ".$text['label-xml_rpc_auth_user']."\n"; - echo "\n"; - echo " \n"; - echo " \n"; //help defeat browser auto-fill - echo "
\n"; - echo $text['description-xml_rpc_auth_user']."\n"; - echo "
\n"; - echo " ".$text['label-xml_rpc_auth_pass']."\n"; - echo "\n"; - echo " \n"; //help defeat browser auto-fill - echo " \n"; - echo "
\n"; - echo $text['description-xml_rpc_auth_pass']."\n"; - echo "
\n"; - echo " ".$text['label-mod_shout_decoder']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-mod_shout_decoder']."\n"; - echo "
\n"; - echo " ".$text['label-mod_shout_volume']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-mod_shout_volume']."\n"; - echo "
"; - echo "

"; - - echo "\n"; - echo "
"; - - echo "\n"; - -//show the footer - require_once "resources/footer.php"; - -?> diff --git a/app/switch/app_config.php b/app/switch/app_config.php index 595bb4c265..2e59b982df 100644 --- a/app/switch/app_config.php +++ b/app/switch/app_config.php @@ -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++; + ?> diff --git a/app/switch/app_defaults.php b/app/switch/app_defaults.php index 7540abeadf..2bfa135a21 100644 --- a/app/switch/app_defaults.php +++ b/app/switch/app_defaults.php @@ -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); - } - } ?> diff --git a/app/switch/resources/scripts/app/xml_handler/resources/scripts/configuration/event_socket.conf.lua b/app/switch/resources/scripts/app/xml_handler/resources/scripts/configuration/event_socket.conf.lua deleted file mode 100644 index 9f62e4e1d5..0000000000 --- a/app/switch/resources/scripts/app/xml_handler/resources/scripts/configuration/event_socket.conf.lua +++ /dev/null @@ -1,131 +0,0 @@ --- xml_handler.lua --- Part of FusionPBX --- Copyright (C) 2023 Mark J Crane --- 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([[]]); - xml:append([[ ]]); - - --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([[ ]]); - end - if (row.name == 'event_socket_ip_address') then - xml:append([[ ]]); - end - if (row.name == 'event_socket_port') then - xml:append([[ ]]); - end - if (row.name == 'event_socket_password') then - xml:append([[ ]]); - end - if (row.name == 'event_socket_acl') then - xml:append([[ ]]); - end - end) - - --close the extension tag if it was left open - xml:append([[ ]]); - xml:append([[]]); - 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 diff --git a/app/switch/resources/scripts/resources/functions/config.lua b/app/switch/resources/scripts/resources/functions/config.lua index e9e097d49c..4572f8c4e1 100644 --- a/app/switch/resources/scripts/resources/functions/config.lua +++ b/app/switch/resources/scripts/resources/functions/config.lua @@ -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(); diff --git a/app/switch/resources/scripts/resources/functions/esl.lua b/app/switch/resources/scripts/resources/functions/esl.lua index 9c4361bc80..5c54e30a68 100644 --- a/app/switch/resources/scripts/resources/functions/esl.lua +++ b/app/switch/resources/scripts/resources/functions/esl.lua @@ -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) diff --git a/resources/classes/event_socket.php b/resources/classes/event_socket.php index 82d0305247..52c6e42070 100644 --- a/resources/classes/event_socket.php +++ b/resources/classes/event_socket.php @@ -101,12 +101,33 @@ class event_socket { return $content; } - public function connect($host, $port, $password) { - //set defaults - if ($host == '') { $host = '127.0.0.1'; } - if ($port == '') { $port = '8021'; } - if ($password == '') { $password = 'ClueCon'; } + public function connect($host = null, $port = null, $password = null) { + global $conf; + + //get the database connection settings + if (empty($host) && empty($conf['event_socket.ip_address'])) { + $host = '127.0.0.1'; + } + if (empty($port) && empty($conf['event_socket.port'])) { + $port = '8021'; + } + if (empty($password) && empty($conf['switch.event_socket.password'])) { + $password = 'ClueCon'; + } + + //set the event socket variables + if (!empty($conf['switch.event_socket.host'])) { + $host = $conf['switch.event_socket.host']; + } + if (!empty($conf['switch.event_socket.port'])) { + $port = $conf['switch.event_socket.port']; + } + if (!empty($conf['switch.event_socket.password'])) { + $password = $conf['switch.event_socket.password']; + } + + //open the socket connection $fp = @fsockopen($host, $port, $errno, $errdesc, 3); if (!$fp) { diff --git a/resources/switch.php b/resources/switch.php index 50e374e225..56cd7c2f15 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -29,15 +29,7 @@ //includes files require_once __DIR__ . "/require.php"; -//get the event socket information -if (empty($_SESSION['event_socket_ip_address'])) { - $setting = new settings(["category" => "switch"]); - $_SESSION['event_socket_ip_address'] = $setting->get('switch', 'event_socket_ip_address'); - $_SESSION['event_socket_port'] = $setting->get('switch', 'event_socket_port'); - $_SESSION['event_socket_password'] = $setting->get('switch', 'event_socket_password'); -} - -function event_socket_create($host, $port, $password) { +function event_socket_create($host = null, $port = null, $password = null) { $esl = new event_socket; if ($esl->connect($host, $port, $password)) { return $esl->reset_fp(); @@ -53,26 +45,8 @@ function event_socket_request($fp, $cmd) { } function event_socket_request_cmd($cmd) { - //get the database connection - require_once "resources/classes/database.php"; - $database = new database; - $database->connect(); - $db = $database->db; - - if (file_exists($_SERVER["PROJECT_ROOT"]."/app/settings/app_config.php")) { - $sql = "select * from v_settings "; - $database = new database; - $row = $database->select($sql, null, 'row'); - if (!empty($row)) { - $event_socket_ip_address = $row["event_socket_ip_address"]; - $event_socket_port = $row["event_socket_port"]; - $event_socket_password = $row["event_socket_password"]; - } - unset($sql, $row); - } - $esl = new event_socket; - if (!$esl->connect($event_socket_ip_address, $event_socket_port, $event_socket_password)) { + if (!$esl->connect()) { return false; } $response = $esl->request($cmd); @@ -110,71 +84,6 @@ function ListFiles($dir) { } } -function save_setting_xml() { - global $domain_uuid, $host, $config; - - $sql = "select * from v_settings "; - $database = new database; - $row = $database->select($sql, null, 'row'); - if (!empty($row) && !empty($_SESSION['switch']['conf']['dir'])) { - //event_socket.conf.xml - $event_socket_ip_address = $row['event_socket_ip_address']; - if (empty($event_socket_ip_address)) { $event_socket_ip_address = '127.0.0.1'; } - $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/event_socket.conf.xml","w"); - $xml = "\n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - if (!empty($row['event_socket_acl'])) { - $xml .= " \n"; - } - $xml .= " \n"; - $xml .= ""; - fwrite($fout, $xml); - unset($xml, $event_socket_password); - fclose($fout); - - //xml_rpc.conf.xml - $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_rpc.conf.xml","w"); - $xml = "\n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= "\n"; - fwrite($fout, $xml); - unset($xml); - fclose($fout); - - //shout.conf.xml - $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/shout.conf.xml","w"); - $xml = "\n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= " \n"; - $xml .= ""; - fwrite($fout, $xml); - unset($xml); - fclose($fout); - } - unset($sql, $row); - - //apply settings - $_SESSION["reload_xml"] = true; - - //$cmd = "api reloadxml"; - //event_socket_request_cmd($cmd); - //unset($cmd); -} - function filename_safe($filename) { //lower case $filename = strtolower($filename);