Example #1
0
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 ";
        $prep_statement = $db->prepare(check_sql($sql));
        $prep_statement->execute();
        $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as &$row) {
            $event_socket_ip_address = $row["event_socket_ip_address"];
            $event_socket_port = $row["event_socket_port"];
            $event_socket_password = $row["event_socket_password"];
            break;
            //limit to 1 row
        }
        unset($prep_statement);
    }
    $esl = new event_socket();
    if (!$esl->connect($event_socket_ip_address, $event_socket_port, $event_socket_password)) {
        return false;
    }
    $response = $esl->request($cmd);
    $esl->close();
    return $response;
}
Example #2
0
 protected function event_socket_request($cmd)
 {
     $esl = new event_socket($this->event_socket);
     $result = $esl->request($cmd);
     $esl->reset_fp();
     return $result;
 }
Example #3
0
 /**
  * Writes the config.lua
  */
 public function write_config()
 {
     if (is_dir($_SESSION['switch']['scripts']['dir'])) {
         //define the global variables
         global $db;
         global $db_type;
         global $db_name;
         global $db_host;
         global $db_port;
         global $db_path;
         global $db_username;
         global $db_password;
         //replace the backslash with a forward slash
         $db_path = str_replace("\\", "/", $db_path);
         //get the odbc information
         $sql = "select count(*) as num_rows from v_databases ";
         $sql .= "where database_driver = 'odbc' ";
         $prep_statement = $db->prepare($sql);
         if ($prep_statement) {
             $prep_statement->execute();
             $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
             unset($prep_statement);
             if ($row['num_rows'] > 0) {
                 $odbc_num_rows = $row['num_rows'];
                 $sql = "select * from v_databases ";
                 $sql .= "where database_driver = 'odbc' ";
                 $prep_statement = $db->prepare(check_sql($sql));
                 $prep_statement->execute();
                 $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
                 foreach ($result as &$row) {
                     $dsn_name = $row["database_name"];
                     $dsn_username = $row["database_username"];
                     $dsn_password = $row["database_password"];
                     break;
                     //limit to 1 row
                 }
                 unset($prep_statement);
             } else {
                 $odbc_num_rows = '0';
             }
         }
         //get the recordings directory
         $recordings_dir = $_SESSION['switch']['recordings']['dir'];
         //find the location to write the config.lua
         if (is_dir("/etc/fusionpbx")) {
             $config = "/etc/fusionpbx/config.lua";
         } elseif (is_dir("/usr/local/etc/fusionpbx")) {
             $config = "/usr/local/etc/fusionpbx/config.lua";
         } else {
             //connect to event socket
             $esl = new event_socket();
             $esl->connect($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
             $script_dir = trim($esl->request('api global_getvar script_dir'));
             $config = $script_dir . "/resources/config.lua";
         }
         $fout = fopen($config, "w");
         if (!$fout) {
             return;
         }
         //make the config.lua
         $tmp = "\n";
         $tmp .= "--set the variables\n";
         if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
             $tmp .= $this->correct_path("\tsounds_dir = [[" . $_SESSION['switch']['sounds']['dir'] . "]];\n");
         }
         if (strlen($_SESSION['switch']['phrases']['dir']) > 0) {
             $tmp .= $this->correct_path("\tphrases_dir = [[" . $_SESSION['switch']['phrases']['dir'] . "]];\n");
         }
         if (strlen($_SESSION['switch']['db']['dir']) > 0) {
             $tmp .= $this->correct_path("\tdatabase_dir = [[" . $_SESSION['switch']['db']['dir'] . "]];\n");
         }
         if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
             $tmp .= $this->correct_path("\trecordings_dir = [[" . $recordings_dir . "]];\n");
         }
         if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
             $tmp .= $this->correct_path("\tstorage_dir = [[" . $_SESSION['switch']['storage']['dir'] . "]];\n");
         }
         if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
             $tmp .= $this->correct_path("\tvoicemail_dir = [[" . $_SESSION['switch']['voicemail']['dir'] . "]];\n");
         }
         if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
             $tmp .= $this->correct_path("\tscripts_dir = [[" . $_SESSION['switch']['scripts']['dir'] . "]];\n");
         }
         $tmp .= $this->correct_path("\tphp_dir = [[" . PHP_BINDIR . "]];\n");
         if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
             $tmp .= "\tphp_bin = \"php.exe\";\n";
         } else {
             $tmp .= "\tphp_bin = \"php\";\n";
         }
         $tmp .= $this->correct_path("\tdocument_root = [[" . $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "]];\n");
         $tmp .= "\n";
         if (strlen($db_type) > 0 || strlen($dsn_name) > 0) {
             $tmp .= "--database information\n";
             $tmp .= "\tdatabase = {}\n";
             $tmp .= "\tdatabase.type = \"" . $db_type . "\";\n";
             $tmp .= "\tdatabase.name = \"" . $db_name . "\";\n";
             $tmp .= $this->correct_path("\tdatabase.path = [[" . $db_path . "]];\n");
             if (strlen($dsn_name) > 0) {
                 $tmp .= "\tdatabase.system = \"odbc://" . $dsn_name . ":" . $dsn_username . ":" . $dsn_password . "\";\n";
                 $tmp .= "\tdatabase.switch = \"odbc://freeswitch:" . $dsn_username . ":" . $dsn_password . "\";\n";
             } elseif ($db_type == "pgsql") {
                 if ($db_host == "localhost") {
                     $db_host = "127.0.0.1";
                 }
                 $tmp .= "\tdatabase.system = \"pgsql://hostaddr=" . $db_host . " port=" . $db_port . " dbname=" . $db_name . " user="******" password="******" options='' application_name='" . $db_name . "'\";\n";
                 $tmp .= "\tdatabase.switch = \"pgsql://hostaddr=" . $db_host . " port=" . $db_port . " dbname=freeswitch user="******" password="******" options='' application_name='freeswitch'\";\n";
             } elseif ($db_type == "sqlite") {
                 $tmp .= "\tdatabase.system = \"sqlite://" . $db_path . "/" . $db_name . "\";\n";
                 $tmp .= "\tdatabase.switch = \"sqlite://" . $_SESSION['switch']['db']['dir'] . "\";\n";
             } elseif ($db_type == "mysql") {
                 $tmp .= "\tdatabase.system = \"\";\n";
                 $tmp .= "\tdatabase.switch = \"\";\n";
             }
             $tmp .= "\n";
         }
         $tmp .= "--set defaults\n";
         $tmp .= "\texpire = {}\n";
         $tmp .= "\texpire.directory = \"3600\";\n";
         $tmp .= "\texpire.dialplan = \"3600\";\n";
         $tmp .= "\texpire.languages = \"3600\";\n";
         $tmp .= "\texpire.sofia = \"3600\";\n";
         $tmp .= "\texpire.acl = \"3600\";\n";
         $tmp .= "\n";
         $tmp .= "--set xml_handler\n";
         $tmp .= "\txml_handler = {}\n";
         $tmp .= "\txml_handler.fs_path = false;\n";
         $tmp .= "\n";
         $tmp .= "--set the debug options\n";
         $tmp .= "\tdebug.params = false;\n";
         $tmp .= "\tdebug.sql = false;\n";
         $tmp .= "\tdebug.xml_request = false;\n";
         $tmp .= "\tdebug.xml_string = false;\n";
         $tmp .= "\tdebug.cache = false;\n";
         $tmp .= "\n";
         $tmp .= "--additional info\n";
         $tmp .= "\tdomain_count = " . count($_SESSION["domains"]) . ";\n";
         $tmp .= $this->correct_path("\ttemp_dir = [[" . $_SESSION['server']['temp']['dir'] . "]];\n");
         if (isset($_SESSION['domain']['dial_string']['text'])) {
             $tmp .= "\tdial_string = \"" . $_SESSION['domain']['dial_string']['text'] . "\";\n";
         }
         $tmp .= "\n";
         $tmp .= "--include local.lua\n";
         $tmp .= "\trequire(\"resources.functions.file_exists\");\n";
         $tmp .= "\tif (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
         $tmp .= "\t\tdofile(\"/etc/fusionpbx/local.lua\");\n";
         $tmp .= "\telseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
         $tmp .= "\t\tdofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
         $tmp .= "\telseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
         $tmp .= "\t\trequire(\"resources.local\");\n";
         $tmp .= "\tend\n";
         fwrite($fout, $tmp);
         unset($tmp);
         fclose($fout);
     }
 }
 protected function restart_switch()
 {
     $esl = new event_socket();
     if (!$esl->connect($this->global_settings->switch_event_host(), $this->global_settings->switch_event_port(), $this->global_settings->switch_event_password())) {
         throw new Exception("Failed to connect to switch");
     }
     if (!$esl->request('api fsctl shutdown restart elegant')) {
         throw new Exception("Failed to send switch restart");
     }
     $esl->reset_fp();
 }
Example #5
0
 /**
  * settings Set switch directories in default settings
  */
 public function settings()
 {
     //define the variables
     if (!isset($this->event_socket_ip_address)) {
         if (strlen($_SESSION['event_socket_ip_address']) > 0) {
             $this->event_socket_ip_address = $_SESSION['event_socket_ip_address'];
         } else {
             $this->event_socket_ip_address = '127.0.0.1';
         }
     }
     if (!isset($this->event_socket_port)) {
         if (strlen($_SESSION['event_socket_ip_address']) > 0) {
             $this->event_socket_port = $_SESSION['event_socket_port'];
         } else {
             $this->event_socket_port = '8021';
         }
     }
     if (!isset($this->event_socket_password)) {
         if (strlen($_SESSION['event_socket_ip_address']) > 0) {
             $this->event_socket_password = $_SESSION['event_socket_password'];
         } else {
             $this->event_socket_password = '******';
         }
     }
     //connect to event socket
     $esl = new event_socket();
     $esl->connect($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password);
     //run the api command
     $result = $esl->request('api global_getvar');
     //close event socket
     fclose($fp);
     //set the result as a named array
     $vars = array();
     foreach (explode("\n", $result) as $row) {
         $a = explode("=", $row);
         if (substr($a[0], -4) == "_dir") {
             $vars[$a[0]] = $a[1];
         }
     }
     //set the bin directory
     if ($vars['base_dir'] == "/usr/local/freeswitch") {
         $bin = "/usr/local/freeswitch/bin";
     } else {
         $bin = "";
     }
     //create the default settings array
     $x = 0;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'bin';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $bin;
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'base';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['base_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'call_center';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['conf_dir'] . '/autoload_configs';
     $array[$x]['default_setting_enabled'] = 'false';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'conf';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['conf_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'db';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['db_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'dialplan';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['conf_dir'] . '/dialplan';
     $array[$x]['default_setting_enabled'] = 'false';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'extensions';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['conf_dir'] . '/directory';
     $array[$x]['default_setting_enabled'] = 'false';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'grammar';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['grammar_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'log';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['log_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'mod';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['mod_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'phrases';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['conf_dir'] . '/lang';
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'recordings';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['recordings_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'scripts';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['script_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'sip_profiles';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['conf_dir'] . '/sip_profiles';
     $array[$x]['default_setting_enabled'] = 'false';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'sounds';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['sounds_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'storage';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['storage_dir'];
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     $array[$x]['default_setting_category'] = 'switch';
     $array[$x]['default_setting_subcategory'] = 'voicemail';
     $array[$x]['default_setting_name'] = 'dir';
     $array[$x]['default_setting_value'] = $vars['storage_dir'] . '/voicemail';
     $array[$x]['default_setting_enabled'] = 'true';
     $array[$x]['default_setting_description'] = '';
     $x++;
     //get an array of the default settings
     $sql = "select * from v_default_settings ";
     $sql .= "where default_setting_category = 'switch' ";
     $prep_statement = $this->db->prepare($sql);
     $prep_statement->execute();
     $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     unset($prep_statement, $sql);
     //find the missing default settings
     $x = 0;
     foreach ($array as $setting) {
         $found = false;
         $missing[$x] = $setting;
         foreach ($default_settings as $row) {
             if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) {
                 $found = true;
                 //remove items from the array that were found
                 unset($missing[$x]);
             }
         }
         $x++;
     }
     //add the missing default settings
     if (count($missing) > 0) {
         $sql = "insert into v_default_settings (";
         $sql .= "default_setting_uuid, ";
         $sql .= "default_setting_category, ";
         $sql .= "default_setting_subcategory, ";
         $sql .= "default_setting_name, ";
         $sql .= "default_setting_value, ";
         $sql .= "default_setting_enabled, ";
         $sql .= "default_setting_description ";
         $sql .= ") values \n";
         $i = 1;
         foreach ($missing as $row) {
             $sql .= "(";
             $sql .= "'" . uuid() . "', ";
             $sql .= "'" . check_str($row['default_setting_category']) . "', ";
             $sql .= "'" . check_str($row['default_setting_subcategory']) . "', ";
             $sql .= "'" . check_str($row['default_setting_name']) . "', ";
             $sql .= "'" . check_str($row['default_setting_value']) . "', ";
             $sql .= "'" . check_str($row['default_setting_enabled']) . "', ";
             $sql .= "'" . check_str($row['default_setting_description']) . "' ";
             $sql .= ")";
             if (sizeof($missing) != $i) {
                 $sql .= ",\n";
             }
             $i++;
         }
         $this->db->exec(check_sql($sql));
         unset($missing);
     }
     //set the default settings
     foreach ($array as $row) {
         if (!isset($_SESSION['switch'][$row['default_setting_subcategory']])) {
             if ($row['default_setting_enabled'] != "false") {
                 $_SESSION['switch'][$row['default_setting_subcategory']] = $row['default_setting_value'];
             }
         }
     }
     //unset the array variable
     unset($array);
 }