Example #1
0
 function xml_save_all()
 {
     global $db, $config;
     $domain_uuid = $this->domain_uuid;
     $domain_name = $this->domain_name;
     //get the system settings paths and set them as variables
     $settings_array = v_settings();
     foreach ($settings_array as $name => $value) {
         ${$name} = $value;
     }
     //determine the extensions parent directory
     $extension_parent_dir = realpath($_SESSION['switch']['extensions']['dir'] . "/..");
     // delete all old extensions to prepare for new ones
     if ($dh = opendir($_SESSION['switch']['extensions']['dir'])) {
         $files = array();
         while ($file = readdir($dh)) {
             if ($file != "." && $file != ".." && $file[0] != '.') {
                 if (is_dir($dir . "/" . $file)) {
                     //this is a directory do nothing
                 } else {
                     //check if file is an extension; verify the file numeric and the extension is xml
                     if (substr($file, 0, 2) == 'v_' && substr($file, -4) == '.xml') {
                         unlink($_SESSION['switch']['extensions']['dir'] . "/" . $file);
                     }
                 }
             }
         }
         closedir($dh);
     }
     $sql = "select * from v_extensions ";
     $sql .= "where domain_uuid = '{$domain_uuid}' ";
     $sql .= "order by call_group asc ";
     $prep_statement = $db->prepare(check_sql($sql));
     $prep_statement->execute();
     $i = 0;
     $extension_xml_condensed = false;
     if ($extension_xml_condensed) {
         $fout = fopen($_SESSION['switch']['extensions']['dir'] . "/v_extensions.xml", "w");
         $xml = "<include>\n";
     }
     while ($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) {
         $call_group = $row['call_group'];
         $call_group = str_replace(";", ",", $call_group);
         $tmp_array = explode(",", $call_group);
         foreach ($tmp_array as &$tmp_call_group) {
             if (strlen($tmp_call_group) > 0) {
                 if (strlen($call_group_array[$tmp_call_group]) == 0) {
                     $call_group_array[$tmp_call_group] = $row['extension'];
                 } else {
                     $call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group] . ',' . $row['extension'];
                 }
             }
             $i++;
         }
         if ($row['enabled'] != "false") {
             //$this->import_sql($row);//Do I need to be worried about ghost values? Maybe I should make a new object?
             //if (strlen($switch_account_code)) $this->accountcode=$switch_account_code;
             //$xml.=$this->generate_xml(1);
             $one_row = new fs_directory();
             $one_row->import_sql($row);
             //make a new object to flush ghost rows. And we can call this as static.
             if (strlen($switch_account_code)) {
                 $one_row->accountcode = $switch_account_code;
             }
             $xml .= $one_row->generate_xml(false);
             if (!$extension_xml_condensed) {
                 $xml .= "</include>\n";
                 fwrite($fout, $xml);
                 unset($xml);
                 fclose($fout);
             }
         }
     }
     unset($prep_statement);
     if ($extension_xml_condensed) {
         $xml .= "</include>\n";
         fwrite($fout, $xml);
         unset($xml);
         fclose($fout);
     }
     //define the group members
     $xml = "<!--\n";
     $xml .= "\tNOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
     $xml .= "\n";
     $xml .= "\tFreeSWITCH works off the concept of users and domains just like email.\n";
     $xml .= "\tYou have users that are in domains for example 1000@domain.com.\n";
     $xml .= "\n";
     $xml .= "\tWhen freeswitch gets a register packet it looks for the user in the directory\n";
     $xml .= "\tbased on the from or to domain in the packet depending on how your sofia profile\n";
     $xml .= "\tis configured.  Out of the box the default domain will be the IP address of the\n";
     $xml .= "\tmachine running FreeSWITCH.  This IP can be found by typing \"sofia status\" at the\n";
     $xml .= "\tCLI.  You will register your phones to the IP and not the hostname by default.\n";
     $xml .= "\tIf you wish to register using the domain please open vars.xml in the root conf\n";
     $xml .= "\tdirectory and set the default domain to the hostname you desire.  Then you would\n";
     $xml .= "\tuse the domain name in the client instead of the IP address to register\n";
     $xml .= "\twith FreeSWITCH.\n";
     $xml .= "\n";
     $xml .= "\tNOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
     $xml .= "-->\n";
     $xml .= "\n";
     $xml .= "<include>\n";
     $xml .= "\t<!--the domain or ip (the right hand side of the @ in the addr-->\n";
     if ($extension_dir_name == "default") {
         $xml .= "\t<domain name=\"\$\${domain}\">\n";
     } else {
         $xml .= "\t<domain name=\"" . $extension_dir_name . "\">\n";
     }
     $xml .= "\t\t<params>\n";
     //$xml .= "			<param name=\"dial-string\" value=\"{sip_invite_domain=\${domain_name},presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}\"/>\n";
     $xml .= "\t\t</params>\n";
     $xml .= "\n";
     $xml .= "\t\t<variables>\n";
     $xml .= "\t\t\t<variable name=\"record_stereo\" value=\"true\"/>\n";
     $xml .= "\t\t\t<variable name=\"default_gateway\" value=\"\$\${default_provider}\"/>\n";
     $xml .= "\t\t\t<variable name=\"default_areacode\" value=\"\$\${default_areacode}\"/>\n";
     $xml .= "\t\t\t<variable name=\"transfer_fallback_extension\" value=\"operator\"/>\n";
     $xml .= "\t\t\t<variable name=\"export_vars\" value=\"domain_name\"/>\n";
     $xml .= "\t\t</variables>\n";
     $xml .= "\n";
     $xml .= "\t\t<groups>\n";
     $xml .= "\t\t\t<group name=\"" . $extension_dir_name . "\">\n";
     $xml .= "\t\t\t<users>\n";
     $xml .= "\t\t\t\t<X-PRE-PROCESS cmd=\"include\" data=\"" . $extension_dir_name . "/*.xml\"/>\n";
     $xml .= "\t\t\t</users>\n";
     $xml .= "\t\t\t</group>\n";
     $xml .= "\n";
     $previous_call_group = "";
     foreach ($call_group_array as $key => $value) {
         $call_group = $key;
         $extension_list = $value;
         if (strlen($call_group) > 0) {
             if ($previous_call_group != $call_group) {
                 $xml .= "\t\t\t<group name=\"{$call_group}\">\n";
                 $xml .= "\t\t\t\t<users>\n";
                 $xml .= "\t\t\t\t\t<!--\n";
                 $xml .= "\t\t\t\t\ttype=\"pointer\" is a pointer so you can have the\n";
                 $xml .= "\t\t\t\t\tsame user in multiple groups.  It basically means\n";
                 $xml .= "\t\t\t\t\tto keep searching for the user in the directory.\n";
                 $xml .= "\t\t\t\t\t-->\n";
                 $extension_array = explode(",", $extension_list);
                 foreach ($extension_array as &$tmp_extension) {
                     $xml .= "\t\t\t\t\t<user id=\"{$tmp_extension}\" type=\"pointer\"/>\n";
                 }
                 $xml .= "\t\t\t\t</users>\n";
                 $xml .= "\t\t\t</group>\n";
                 $xml .= "\n";
             }
             $previous_call_group = $call_group;
         }
         unset($call_group);
     }
     $xml .= "\t\t</groups>\n";
     $xml .= "\n";
     $xml .= "\t</domain>\n";
     $xml .= "</include>";
     //remove invalid characters from the file names
     $extension_dir_name = str_replace(" ", "_", $extension_dir_name);
     $extension_dir_name = preg_replace("/[\\*\\:\\/\\<\\>\\|\\'\"\\?]/", "", $extension_dir_name);
     //write the xml file
     $fout = fopen($extension_parent_dir . "/" . $extension_dir_name . ".xml", "w");
     fwrite($fout, $xml);
     unset($xml);
     fclose($fout);
     //syncrhonize the phone directory
     sync_directory();
     //apply settings reminder
     $_SESSION["reload_xml"] = true;
     //call reloadxml direct
     //$cmd = "api reloadxml";
     //event_socket_request_cmd($cmd);
     //unset($cmd);
 }
Example #2
0
        $tmp .= "\t\t//console_log( \"info\", \"last name: \" + result_array[i]['last_name'] + \"\\n\" );\n";
        $tmp .= "\t\t//console_log( \"info\", \"extension: \" + result_array[i]['extension'] + \"\\n\" );\n";
        $tmp .= "\n";
        $tmp .= "\t\t//if 1 is pressed then transfer the call\n";
        $tmp .= "\t\tdtmf.digits = session.getDigits(1, \"#\", 3000);\n";
        $tmp .= "\t\tif (dtmf.digits == \"1\") {\n";
        $tmp .= "\t\t\tconsole_log( \"info\", \"directory: call transfered to: \" + result_array[i]['extension'] + \"\\n\" );\n";
        $tmp .= "\t\t\tsession.execute(\"transfer\", result_array[i]['extension']+\" XML default\");\n";
        $tmp .= "\t\t}\n";
        $tmp .= "\n";
        $tmp .= "\t}\n";
        $tmp .= "}\n";
        $tmp .= "\n";
        $tmp .= "\n";
        $tmp .= "if ( session.ready() ) {\n";
        $tmp .= "\tsession.answer();\n";
        $tmp .= "\tsearch_type = \"last_name\";\n";
        $tmp .= "\tdirectory_search(search_type);\n";
        $tmp .= "\tsession.hangup(\"NORMAL_CLEARING\");\n";
        $tmp .= "}\n";
        $tmp .= "";
        //write the file
        $fout = fopen($v_scripts_dir . "/directory.js", "w");
        fwrite($fout, $tmp);
        fclose($fout);
    }
    //end sync_directory
}
//end if function exists
sync_directory();
Example #3
0
function sync_package_v_extensions()
{
    global $config;
    $v_settings_array = v_settings();
    foreach ($v_settings_array as $name => $value) {
        ${$name} = $value;
    }
    //determine the extensions parent directory
    //$v_extensions_dir = str_replace("\\", "/", $file_contents);
    $v_extensions_dir_array = explode("/", $v_extensions_dir);
    $extension_parent_dir = "";
    $x = 1;
    foreach ($v_extensions_dir_array as $tmp_dir) {
        if (count($v_extensions_dir_array) > $x) {
            $extension_parent_dir .= $tmp_dir . "/";
        } else {
            $extension_dir_name = $tmp_dir;
        }
        $x++;
    }
    $extension_parent_dir = rtrim($extension_parent_dir, "/");
    // delete all old extensions to prepare for new ones
    if ($dh = opendir($v_extensions_dir)) {
        $files = array();
        while ($file = readdir($dh)) {
            if ($file != "." && $file != ".." && $file[0] != '.') {
                if (is_dir($dir . "/" . $file)) {
                    //this is a directory do nothing
                } else {
                    //check if file is an extension; verify the file numeric and the extension is xml
                    $file_array = explode(".", $file);
                    if (is_numeric($file_array[0]) && $file_array[count($file_array) - 1] == "xml") {
                        //echo "name: ".$file_array[0]."<br />\n";
                        //echo "file: ".$file."<br/>\n";
                        unlink($v_extensions_dir . "/" . $file);
                    }
                }
            }
        }
        closedir($dh);
    }
    global $db, $v_id;
    $sql = "";
    $sql .= "select * from v_extensions ";
    $sql .= "where v_id = '{$v_id}' ";
    $sql .= "order by callgroup asc ";
    $prepstatement = $db->prepare(check_sql($sql));
    $prepstatement->execute();
    $i = 0;
    while ($row = $prepstatement->fetch()) {
        $callgroup = $row['callgroup'];
        $callgroup = str_replace(";", ",", $callgroup);
        $tmp_array = explode(",", $callgroup);
        foreach ($tmp_array as &$tmp_callgroup) {
            if (strlen($tmp_callgroup) > 0) {
                if (strlen($callgroups_array[$tmp_callgroup]) == 0) {
                    $callgroups_array[$tmp_callgroup] = $row['extension'];
                } else {
                    $callgroups_array[$tmp_callgroup] = $callgroups_array[$tmp_callgroup] . ',' . $row['extension'];
                }
            }
            $i++;
        }
        $vm_password = $row['vm_password'];
        $vm_password = str_replace("#", "", $vm_password);
        //preserves leading zeros
        //echo "enabled: ".$row['enabled'];
        if ($row['enabled'] != "false") {
            $fout = fopen($v_extensions_dir . "/" . $row['extension'] . ".xml", "w");
            $tmpxml = "<include>\n";
            if (strlen($row['cidr']) == 0) {
                $tmpxml .= "  <user id=\"" . $row['extension'] . "\">\n";
            } else {
                $tmpxml .= "  <user id=\"" . $row['extension'] . "\" cidr=\"" . $row['cidr'] . "\">\n";
            }
            $tmpxml .= "    <params>\n";
            $tmpxml .= "      <param name=\"password\" value=\"" . $row['password'] . "\"/>\n";
            $tmpxml .= "      <param name=\"vm-password\" value=\"" . $vm_password . "\"/>\n";
            if (strlen($row['vm_mailto']) > 0) {
                $tmpxml .= "      <param name=\"vm-email-all-messages\" value=\"true\"/>\n";
                switch ($row['vm_attach_file']) {
                    case "true":
                        $tmpxml .= "      <param name=\"vm-attach-file\" value=\"true\"/>\n";
                        break;
                    case "false":
                        $tmpxml .= "      <param name=\"vm-attach-file\" value=\"false\"/>\n";
                        break;
                    default:
                        $tmpxml .= "      <param name=\"vm-attach-file\" value=\"true\"/>\n";
                }
                switch ($row['vm_keep_local_after_email']) {
                    case "true":
                        $tmpxml .= "      <param name=\"vm-keep-local-after-email\" value=\"true\"/>\n";
                        break;
                    case "false":
                        $tmpxml .= "      <param name=\"vm-keep-local-after-email\" value=\"false\"/>\n";
                        break;
                    default:
                        $tmpxml .= "      <param name=\"vm-keep-local-after-email\" value=\"true\"/>\n";
                }
                $tmpxml .= "      <param name=\"vm-mailto\" value=\"" . $row['vm_mailto'] . "\"/>\n";
            }
            if (strlen($row['auth-acl']) > 0) {
                $tmpxml .= "      <param name=\"auth-acl\" value=\"" . $row['auth_acl'] . "\"/>\n";
            }
            $tmpxml .= "    </params>\n";
            $tmpxml .= "    <variables>\n";
            $tmpxml .= "      <variable name=\"toll_allow\" value=\"domestic,international,local\"/>\n";
            $tmpxml .= "      <variable name=\"accountcode\" value=\"" . $row['accountcode'] . "\"/>\n";
            $tmpxml .= "      <variable name=\"user_context\" value=\"" . $row['user_context'] . "\"/>\n";
            if (strlen($row['effective_caller_id_number']) > 0) {
                $tmpxml .= "      <variable name=\"effective_caller_id_name\" value=\"" . $row['effective_caller_id_name'] . "\"/>\n";
                $tmpxml .= "      <variable name=\"effective_caller_id_number\" value=\"" . $row['effective_caller_id_number'] . "\"/>\n";
            }
            if (strlen($row['outbound_caller_id_number']) > 0) {
                $tmpxml .= "      <variable name=\"outbound_caller_id_name\" value=\"" . $row['outbound_caller_id_name'] . "\"/>\n";
                $tmpxml .= "      <variable name=\"outbound_caller_id_number\" value=\"" . $row['outbound_caller_id_number'] . "\"/>\n";
            }
            if (strlen($row['sip_force_contact']) > 0) {
                $tmpxml .= "      <variable name=\"sip-force-contact\" value=\"" . $row['sip_force_contact'] . "\"/>\n";
            }
            $tmpxml .= "    </variables>\n";
            $tmpxml .= "  </user>\n";
            $tmpxml .= "</include>\n";
            fwrite($fout, $tmpxml);
            unset($tmpxml);
            fclose($fout);
        }
    }
    unset($prepstatement);
    //echo $tmpxml;
    //define the group members
    $tmpxml = "<!--\n";
    $tmpxml .= "\tNOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
    $tmpxml .= "\n";
    $tmpxml .= "\tFreeSWITCH works off the concept of users and domains just like email.\n";
    $tmpxml .= "\tYou have users that are in domains for example 1000@domain.com.\n";
    $tmpxml .= "\n";
    $tmpxml .= "\tWhen freeswitch gets a register packet it looks for the user in the directory\n";
    $tmpxml .= "\tbased on the from or to domain in the packet depending on how your sofia profile\n";
    $tmpxml .= "\tis configured.  Out of the box the default domain will be the IP address of the\n";
    $tmpxml .= "\tmachine running FreeSWITCH.  This IP can be found by typing \"sofia status\" at the\n";
    $tmpxml .= "\tCLI.  You will register your phones to the IP and not the hostname by default.\n";
    $tmpxml .= "\tIf you wish to register using the domain please open vars.xml in the root conf\n";
    $tmpxml .= "\tdirectory and set the default domain to the hostname you desire.  Then you would\n";
    $tmpxml .= "\tuse the domain name in the client instead of the IP address to register\n";
    $tmpxml .= "\twith FreeSWITCH.\n";
    $tmpxml .= "\n";
    $tmpxml .= "\tNOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
    $tmpxml .= "-->\n";
    $tmpxml .= "\n";
    $tmpxml .= "<include>\n";
    $tmpxml .= "\t<!--the domain or ip (the right hand side of the @ in the addr-->\n";
    $tmpxml .= "\t<domain name=\"\$\${domain}\">\n";
    $tmpxml .= "\t\t<params>\n";
    $tmpxml .= "\t\t\t<param name=\"dial-string\" value=\"{presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}\"/>\n";
    $tmpxml .= "\t\t</params>\n";
    $tmpxml .= "\n";
    $tmpxml .= "\t\t<variables>\n";
    $tmpxml .= "\t\t\t<variable name=\"record_stereo\" value=\"true\"/>\n";
    $tmpxml .= "\t\t\t<variable name=\"default_gateway\" value=\"\$\${default_provider}\"/>\n";
    $tmpxml .= "\t\t\t<variable name=\"default_areacode\" value=\"\$\${default_areacode}\"/>\n";
    $tmpxml .= "\t\t\t<variable name=\"transfer_fallback_extension\" value=\"operator\"/>\n";
    $tmpxml .= "\t\t</variables>\n";
    $tmpxml .= "\n";
    $tmpxml .= "\t\t<groups>\n";
    $tmpxml .= "\t\t\t<group name=\"" . $extension_dir_name . "\">\n";
    $tmpxml .= "\t\t\t<users>\n";
    $tmpxml .= "\t\t\t\t<X-PRE-PROCESS cmd=\"include\" data=\"" . $extension_dir_name . "/*.xml\"/>\n";
    $tmpxml .= "\t\t\t</users>\n";
    $tmpxml .= "\t\t\t</group>\n";
    $tmpxml .= "\n";
    $previous_callgroup = "";
    foreach ($callgroups_array as $key => $value) {
        $callgroup = $key;
        $extension_list = $value;
        if (strlen($callgroup) > 0) {
            if ($previous_callgroup != $callgroup) {
                $tmpxml .= "\t\t\t<group name=\"{$callgroup}\">\n";
                $tmpxml .= "\t\t\t\t<users>\n";
                $tmpxml .= "\t\t\t\t\t<!--\n";
                $tmpxml .= "\t\t\t\t\ttype=\"pointer\" is a pointer so you can have the\n";
                $tmpxml .= "\t\t\t\t\tsame user in multiple groups.  It basically means\n";
                $tmpxml .= "\t\t\t\t\tto keep searching for the user in the directory.\n";
                $tmpxml .= "\t\t\t\t\t-->\n";
                $extension_array = explode(",", $extension_list);
                foreach ($extension_array as &$tmp_extension) {
                    $tmpxml .= "\t\t\t\t\t<user id=\"{$tmp_extension}\" type=\"pointer\"/>\n";
                }
                $tmpxml .= "\t\t\t\t</users>\n";
                $tmpxml .= "\t\t\t</group>\n";
                $tmpxml .= "\n";
            }
            $previous_callgroup = $callgroup;
        }
        unset($callgroup);
    }
    $tmpxml .= "\t\t</groups>\n";
    $tmpxml .= "\n";
    $tmpxml .= "\t</domain>\n";
    $tmpxml .= "</include>";
    $fout = fopen($extension_parent_dir . "/" . $extension_dir_name . ".xml", "w");
    fwrite($fout, $tmpxml);
    unset($tmpxml);
    fclose($fout);
    //syncrhonize the phone directory
    sync_directory();
    $cmd = "api reloadxml";
    //event_socket_request_cmd($cmd);
    unset($cmd);
}