Example #1
0
             $sql .= "'soft', ";
             $sql .= "null, ";
             $sql .= "null, ";
             $sql .= "null ";
             $sql .= ") ";
             unset($music_on_hold_name, $music_on_hold_path);
         }
         //execute query
         if (!$stream_path_found) {
             $db->exec(check_sql($sql));
             unset($sql);
         }
     }
     //check target folder, move uploaded file
     if (!is_dir($stream_path)) {
         event_socket_mkdir($stream_path);
     }
     if (is_dir($stream_path)) {
         if (copy($stream_file_name_temp, $stream_path . '/' . $stream_file_name)) {
             @unlink($stream_file_name_temp);
         }
     }
     //set message
     $_SESSION['message'] = $text['message-upload_completed'];
 }
 //require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
 $music = new switch_music_on_hold();
 $music->reload();
 //redirect
 header("Location: music_on_hold.php");
 exit;
Example #2
0
        event_socket_mkdir($_SESSION['switch']['storage']['dir'] . '/fax');
    }
    if (!is_dir($_SESSION['switch']['storage']['dir'] . '/fax/' . $_SESSION['domain_name'])) {
        event_socket_mkdir($_SESSION['switch']['storage']['dir'] . '/fax/' . $_SESSION['domain_name']);
    }
    if (!is_dir($fax_dir . '/' . $fax_extension)) {
        event_socket_mkdir($fax_dir . '/' . $fax_extension);
    }
    if (!is_dir($dir_fax_inbox)) {
        event_socket_mkdir($dir_fax_inbox);
    }
    if (!is_dir($dir_fax_sent)) {
        event_socket_mkdir($dir_fax_sent);
    }
    if (!is_dir($dir_fax_temp)) {
        event_socket_mkdir($dir_fax_temp);
    }
}
//clear file status cache
clearstatcache();
//send the fax
$continue = false;
if (!$included) {
    if ($_POST['action'] == "send") {
        $fax_numbers = $_POST['fax_numbers'];
        $fax_uuid = check_str($_POST["id"]);
        $fax_caller_id_name = check_str($_POST['fax_caller_id_name']);
        $fax_caller_id_number = check_str($_POST['fax_caller_id_number']);
        $fax_header = check_str($_POST['fax_header']);
        $fax_sender = check_str($_POST['fax_sender']);
        $fax_recipient = check_str($_POST['fax_recipient']);
Example #3
0
            }
        }
    }
}
//if the public directory doesn't exist then create it
if ($domains_processed == 1) {
    if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
        if (!is_dir($_SESSION['switch']['dialplan']['dir'] . '/public')) {
            event_socket_mkdir($_SESSION['switch']['dialplan']['dir'] . '/public');
        }
    }
}
//if multiple domains then make sure that the dialplan/public/domain_name.xml file exists
if (count($_SESSION["domains"]) > 1) {
    //make sure the public directory and xml file exist
    if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) {
        if (!is_dir($_SESSION['switch']['dialplan']['dir'] . '/public' . $_SESSION['domains'][$domain_uuid]['domain_name'])) {
            event_socket_mkdir($_SESSION['switch']['dialplan']['dir'] . '/public/' . $_SESSION['domains'][$domain_uuid]['domain_name']);
        }
        $file = $_SESSION['switch']['dialplan']['dir'] . "/public/" . $_SESSION['domains'][$domain_uuid]['domain_name'] . ".xml";
        if (!file_exists($file)) {
            $fout = fopen($file, "w");
            $xml = "<include>\n";
            $xml .= "  <X-PRE-PROCESS cmd=\"include\" data=\"" . $_SESSION['domains'][$domain_uuid]['domain_name'] . "/*.xml\"/>\n";
            $xml .= "</include>\n";
            fwrite($fout, $xml);
            fclose($fout);
            unset($xml, $file);
        }
    }
}
if (permission_exists('voicemail_greeting_upload')) {
    if ($_POST['submit'] == $text['button-upload'] && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['file']['tmp_name'])) {
        //find the next available
        for ($i = 1; $i < 10; $i++) {
            $file_name = 'greeting_' . $i . '.wav';
            //check the database
            $sql = "select voicemail_greeting_uuid from v_voicemail_greetings ";
            $sql .= "where domain_uuid = '" . $domain_uuid . "' ";
            $sql .= "and voicemail_id = '" . $voicemail_id . "' ";
            $sql .= "and greeting_filename = '" . $file_name . "' ";
            $prep_statement = $db->prepare(check_sql($sql));
            $prep_statement->execute();
            $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
            if (count($result) == 0 && !file_exists($v_greeting_dir . '/' . $file_name)) {
                //move the uploaded greeting
                event_socket_mkdir($v_greeting_dir);
                move_uploaded_file($_FILES['file']['tmp_name'], $v_greeting_dir . '/' . $file_name);
                //set newly uploaded greeting as active greeting for voicemail box
                $sql = "update v_voicemails ";
                $sql .= "set greeting_id = '" . $i . "' ";
                $sql .= "where domain_uuid = '" . $domain_uuid . "' ";
                $sql .= "and voicemail_id = '" . $voicemail_id . "' ";
                $prep_statement = $db->prepare(check_sql($sql));
                $prep_statement->execute();
                unset($prep_statement);
                $_SESSION["message"] = $text['message-uploaded'] . ": " . $_FILES['file']['name'];
                break;
            } else {
                continue;
            }
            unset($prep_statement);
Example #5
0
 /**
  * process method converts the xml cdr and adds it to the database
  */
 public function xml_array($key, $leg, $xml_string)
 {
     //fix the xml by escaping the contents of <sip_full_XXX>
     if (defined('STDIN')) {
         $xml_string = preg_replace_callback("/<([^><]+)>(.*?[><].*?)<\\/\\g1>/", function ($matches) {
             return '<' . $matches[1] . '>' . str_replace(">", "&gt;", str_replace("<", "&lt;", $matches[2])) . '</' . $matches[1] . '>';
         }, $xml_string);
     }
     //parse the xml to get the call detail record info
     try {
         //$this->log($xml_string);
         $xml = simplexml_load_string($xml_string);
         //$this->log("\nxml load done\n");
     } catch (Exception $e) {
         echo $e->getMessage();
         //$this->log("\nfail loadxml: " . $e->getMessage() . "\n");
     }
     //get the destination number
     if ($xml->variables->current_application == "bridge") {
         $current_application_data = urldecode($xml->variables->current_application_data);
         $bridge_array = explode("/", $current_application_data);
         $destination_number = end($bridge_array);
         if (strpos($destination_number, '@') !== FALSE) {
             $destination_array = explode("@", $destination_number);
             $destination_number = $destination_array[0];
         }
     } else {
         $destination_number = urldecode($xml->variables->sip_to_user);
     }
     //if last_sent_callee_id_number is set use it for the destination_number
     if (strlen($xml->variables->last_sent_callee_id_number) > 0) {
         $destination_number = urldecode($xml->variables->last_sent_callee_id_number);
     }
     //get the caller id
     $caller_id_name = urldecode($xml->variables->effective_caller_id_name);
     $caller_id_number = urldecode($xml->variables->effective_caller_id_number);
     if (strlen($caller_id_number) == 0) {
         foreach ($xml->callflow as $row) {
             $caller_id_name = urldecode($row->caller_profile->caller_id_name);
             $caller_id_number = urldecode($row->caller_profile->caller_id_number);
         }
     }
     //misc
     $uuid = check_str(urldecode($xml->variables->uuid));
     $this->array[$key]['uuid'] = $uuid;
     $this->array[$key]['destination_number'] = check_str($destination_number);
     $this->array[$key]['source_number'] = check_str(urldecode($xml->variables->effective_caller_id_number));
     $this->array[$key]['user_context'] = check_str(urldecode($xml->variables->user_context));
     $this->array[$key]['network_addr'] = check_str(urldecode($xml->variables->sip_network_ip));
     $this->array[$key]['caller_id_name'] = check_str($caller_id_name);
     $this->array[$key]['caller_id_number'] = check_str($caller_id_number);
     $this->array[$key]['accountcode'] = check_str(urldecode($xml->variables->accountcode));
     $this->array[$key]['default_language'] = check_str(urldecode($xml->variables->default_language));
     $this->array[$key]['bridge_uuid'] = check_str(urldecode($xml->variables->bridge_uuid));
     //$this->array[$key]['digits_dialed'] = check_str(urldecode($xml->variables->digits_dialed));
     $this->array[$key]['sip_hangup_disposition'] = check_str(urldecode($xml->variables->sip_hangup_disposition));
     $this->array[$key]['pin_number'] = check_str(urldecode($xml->variables->pin_number));
     //time
     $this->array[$key]['start_epoch'] = check_str(urldecode($xml->variables->start_epoch));
     $start_stamp = check_str(urldecode($xml->variables->start_stamp));
     $this->array[$key]['start_stamp'] = $start_stamp;
     $this->array[$key]['answer_stamp'] = check_str(urldecode($xml->variables->answer_stamp));
     $this->array[$key]['answer_epoch'] = check_str(urldecode($xml->variables->answer_epoch));
     $this->array[$key]['end_epoch'] = check_str(urldecode($xml->variables->end_epoch));
     $this->array[$key]['end_stamp'] = check_str(urldecode($xml->variables->end_stamp));
     $this->array[$key]['duration'] = check_str(urldecode($xml->variables->duration));
     $this->array[$key]['mduration'] = check_str(urldecode($xml->variables->mduration));
     $this->array[$key]['billsec'] = check_str(urldecode($xml->variables->billsec));
     $this->array[$key]['billmsec'] = check_str(urldecode($xml->variables->billmsec));
     //codecs
     $this->array[$key]['read_codec'] = check_str(urldecode($xml->variables->read_codec));
     $this->array[$key]['read_rate'] = check_str(urldecode($xml->variables->read_rate));
     $this->array[$key]['write_codec'] = check_str(urldecode($xml->variables->write_codec));
     $this->array[$key]['write_rate'] = check_str(urldecode($xml->variables->write_rate));
     $this->array[$key]['remote_media_ip'] = check_str(urldecode($xml->variables->remote_media_ip));
     $this->array[$key]['hangup_cause'] = check_str(urldecode($xml->variables->hangup_cause));
     $this->array[$key]['hangup_cause_q850'] = check_str(urldecode($xml->variables->hangup_cause_q850));
     //call center
     $this->array[$key]['cc_side'] = check_str(urldecode($xml->variables->cc_side));
     $this->array[$key]['cc_member_uuid'] = check_str(urldecode($xml->variables->cc_member_uuid));
     $this->array[$key]['cc_queue_joined_epoch'] = check_str(urldecode($xml->variables->cc_queue_joined_epoch));
     $this->array[$key]['cc_queue'] = check_str(urldecode($xml->variables->cc_queue));
     $this->array[$key]['cc_member_session_uuid'] = check_str(urldecode($xml->variables->cc_member_session_uuid));
     $this->array[$key]['cc_agent'] = check_str(urldecode($xml->variables->cc_agent));
     $this->array[$key]['cc_agent_type'] = check_str(urldecode($xml->variables->cc_agent_type));
     $this->array[$key]['waitsec'] = check_str(urldecode($xml->variables->waitsec));
     //app info
     $this->array[$key]['last_app'] = check_str(urldecode($xml->variables->last_app));
     $this->array[$key]['last_arg'] = check_str(urldecode($xml->variables->last_arg));
     //conference
     $this->array[$key]['conference_name'] = check_str(urldecode($xml->variables->conference_name));
     $this->array[$key]['conference_uuid'] = check_str(urldecode($xml->variables->conference_uuid));
     $this->array[$key]['conference_member_id'] = check_str(urldecode($xml->variables->conference_member_id));
     //call quality
     $rtp_audio_in_mos = check_str(urldecode($xml->variables->rtp_audio_in_mos));
     if (strlen($rtp_audio_in_mos) > 0) {
         $this->array[$key]['rtp_audio_in_mos'] = $rtp_audio_in_mos;
     }
     //store the call leg
     $this->array[$key]['leg'] = $leg;
     //store the call direction
     $this->array[$key]['direction'] = check_str(urldecode($xml->variables->call_direction));
     //store post dial delay, in milliseconds
     $this->array[$key]['pdd_ms'] = check_str(urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec));
     //get break down the date to year, month and day
     $tmp_time = strtotime($start_stamp);
     $tmp_year = date("Y", $tmp_time);
     $tmp_month = date("M", $tmp_time);
     $tmp_day = date("d", $tmp_time);
     //get the domain values from the xml
     $domain_name = check_str(urldecode($xml->variables->domain_name));
     $domain_uuid = check_str(urldecode($xml->variables->domain_uuid));
     //get the domain name from sip_req_host
     if (strlen($domain_name) == 0) {
         $domain_name = check_str(urldecode($xml->variables->sip_req_host));
     }
     //send the domain name to the cdr log
     //$this->log("\ndomain_name is `$domain_name`; domain_uuid is '$domain_uuid'\n");
     //get the domain_uuid with the domain_name
     if (strlen($domain_uuid) == 0) {
         $sql = "select domain_uuid from v_domains ";
         if (strlen($domain_name) == 0 && $context != 'public' && $context != 'default') {
             $sql .= "where domain_name = '" . $context . "' ";
         } else {
             $sql .= "where domain_name = '" . $domain_name . "' ";
         }
         $row = $this->db->query($sql)->fetch();
         $domain_uuid = $row['domain_uuid'];
     }
     //set values in the database
     if (strlen($domain_uuid) > 0) {
         $this->array[$key]['domain_uuid'] = $domain_uuid;
     }
     if (strlen($domain_name) > 0) {
         $this->array[$key]['domain_name'] = $domain_name;
     }
     //check whether a recording exists
     $recording_relative_path = '/' . $_SESSION['domain_name'] . '/archive/' . $tmp_year . '/' . $tmp_month . '/' . $tmp_day;
     if (file_exists($_SESSION['switch']['recordings']['dir'] . $recording_relative_path . '/' . $uuid . '.wav')) {
         $recording_file = $recording_relative_path . '/' . $uuid . '.wav';
     } elseif (file_exists($_SESSION['switch']['recordings']['dir'] . $recording_relative_path . '/' . $uuid . '.mp3')) {
         $recording_file = $recording_relative_path . '/' . $uuid . '.mp3';
     }
     if (isset($recording_file) && !empty($recording_file)) {
         $this->array[$key]['recording_file'] = $recording_file;
     }
     //save to the database in xml format
     if ($_SESSION['cdr']['format']['text'] == "xml" && $_SESSION['cdr']['storage']['text'] == "db") {
         $this->array[$key]['xml'] = check_str($xml_string);
     }
     //save to the database in json format
     if ($_SESSION['cdr']['format']['text'] == "json" && $_SESSION['cdr']['storage']['text'] == "db") {
         $this->array[$key]['json'] = check_str(json_encode($xml));
     }
     //insert the check_str($extension_uuid)
     if (strlen($xml->variables->extension_uuid) > 0) {
         $this->array[$key]['extension_uuid'] = check_str(urldecode($xml->variables->extension_uuid));
     }
     //insert the values
     if (strlen($uuid) > 0) {
         if ($this->debug) {
             //$time5_insert = microtime(true);
             //echo $sql."<br />\n";
         }
         try {
             $error = "false";
             //$this->db->exec(check_sql($sql));
         } catch (PDOException $e) {
             $tmp_dir = $_SESSION['switch']['log']['dir'] . '/xml_cdr/failed/';
             if (!file_exists($tmp_dir)) {
                 event_socket_mkdir($tmp_dir);
             }
             if ($_SESSION['cdr']['format']['text'] == "xml") {
                 $tmp_file = $uuid . '.xml';
                 $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                 fwrite($fh, $xml_string);
             } else {
                 $tmp_file = $uuid . '.json';
                 $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                 fwrite($fh, json_encode($xml));
             }
             fclose($fh);
             if ($this->debug) {
                 echo $e->getMessage();
             }
             $error = "true";
         }
         if ($_SESSION['cdr']['storage']['text'] == "dir" && $error != "true") {
             if (strlen($uuid) > 0) {
                 $tmp_time = strtotime($start_stamp);
                 $tmp_year = date("Y", $tmp_time);
                 $tmp_month = date("M", $tmp_time);
                 $tmp_day = date("d", $tmp_time);
                 $tmp_dir = $_SESSION['switch']['log']['dir'] . '/xml_cdr/archive/' . $tmp_year . '/' . $tmp_month . '/' . $tmp_day;
                 if (!file_exists($tmp_dir)) {
                     event_socket_mkdir($tmp_dir);
                 }
                 if ($_SESSION['cdr']['format']['text'] == "xml") {
                     $tmp_file = $uuid . '.xml';
                     $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                     fwrite($fh, $xml_string);
                 } else {
                     $tmp_file = $uuid . '.json';
                     $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                     fwrite($fh, json_encode($xml));
                 }
                 fclose($fh);
             }
         }
         unset($error);
         //if ($this->debug) {
         //GLOBAL $insert_time,$insert_count;
         //$insert_time+=microtime(true)-$time5_insert; //add this current query.
         //$insert_count++;
         //}
     }
     unset($sql);
 }
Example #6
0
	License.

	The Original Code is FusionPBX

	The Initial Developer of the Original Code is
	Mark J Crane <*****@*****.**>
	Portions created by the Initial Developer are Copyright (C) 2008-2015
	the Initial Developer. All Rights Reserved.

	Contributor(s):
	Mark J Crane <*****@*****.**>
*/
//if the recordings directory doesn't exist then create it
if (strlen($_SESSION['switch']['recordings']['dir'] . "/" . $domain_name) > 0) {
    if (!is_readable($_SESSION['switch']['recordings']['dir'] . "/" . $domain_name)) {
        event_socket_mkdir($_SESSION['switch']['recordings']['dir'] . "/" . $domain_name, 02770, true);
    }
}
if ($domains_processed == 1) {
    //if base64, populate from existing recording files, then remove
    if ($_SESSION['recordings']['storage_type']['text'] == 'base64') {
        //get recordings without base64 in db
        $sql = "select recording_uuid, domain_uuid, recording_filename ";
        $sql .= "from v_recordings where recording_base64 is null or recording_base64 = '' ";
        $prep_statement = $db->prepare(check_sql($sql));
        $prep_statement->execute();
        $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
        if (count($result) > 0) {
            foreach ($result as &$row) {
                $recording_uuid = $row['recording_uuid'];
                $recording_domain_uuid = $row['domain_uuid'];
Example #7
0
function process_xml_cdr($db, $leg, $xml_string)
{
    //set global variable
    global $debug;
    //fix the xml by escaping the contents of <sip_full_XXX>
    $xml_string = preg_replace_callback("/<([^><]+)>(.*?[><].*?)<\\/\\g1>/", function ($matches) {
        return '<' . $matches[1] . '>' . str_replace(">", "&gt;", str_replace("<", "&lt;", $matches[2])) . '</' . $matches[1] . '>';
    }, $xml_string);
    //parse the xml to get the call detail record info
    try {
        xml_cdr_log($xml_string);
        $xml = simplexml_load_string($xml_string);
        xml_cdr_log("\nxml load done\n");
    } catch (Exception $e) {
        echo $e->getMessage();
        xml_cdr_log("\nfail loadxml: " . $e->getMessage() . "\n");
    }
    //prepare the database object
    require_once "resources/classes/database.php";
    $database = new database();
    $database->table = "v_xml_cdr";
    //misc
    $uuid = check_str(urldecode($xml->variables->uuid));
    $database->fields['uuid'] = $uuid;
    $database->fields['accountcode'] = check_str(urldecode($xml->variables->accountcode));
    $database->fields['default_language'] = check_str(urldecode($xml->variables->default_language));
    $database->fields['bridge_uuid'] = check_str(urldecode($xml->variables->bridge_uuid));
    //$database->fields['digits_dialed'] = check_str(urldecode($xml->variables->digits_dialed));
    $database->fields['sip_hangup_disposition'] = check_str(urldecode($xml->variables->sip_hangup_disposition));
    $database->fields['pin_number'] = check_str(urldecode($xml->variables->pin_number));
    //time
    $database->fields['start_epoch'] = check_str(urldecode($xml->variables->start_epoch));
    $start_stamp = check_str(urldecode($xml->variables->start_stamp));
    $database->fields['start_stamp'] = $start_stamp;
    $database->fields['answer_stamp'] = check_str(urldecode($xml->variables->answer_stamp));
    $database->fields['answer_epoch'] = check_str(urldecode($xml->variables->answer_epoch));
    $database->fields['end_epoch'] = check_str(urldecode($xml->variables->end_epoch));
    $database->fields['end_stamp'] = check_str(urldecode($xml->variables->end_stamp));
    $database->fields['duration'] = check_str(urldecode($xml->variables->duration));
    $database->fields['mduration'] = check_str(urldecode($xml->variables->mduration));
    $database->fields['billsec'] = check_str(urldecode($xml->variables->billsec));
    $database->fields['billmsec'] = check_str(urldecode($xml->variables->billmsec));
    //codecs
    $database->fields['read_codec'] = check_str(urldecode($xml->variables->read_codec));
    $database->fields['read_rate'] = check_str(urldecode($xml->variables->read_rate));
    $database->fields['write_codec'] = check_str(urldecode($xml->variables->write_codec));
    $database->fields['write_rate'] = check_str(urldecode($xml->variables->write_rate));
    $database->fields['remote_media_ip'] = check_str(urldecode($xml->variables->remote_media_ip));
    $database->fields['hangup_cause'] = check_str(urldecode($xml->variables->hangup_cause));
    $database->fields['hangup_cause_q850'] = check_str(urldecode($xml->variables->hangup_cause_q850));
    //call center
    $database->fields['cc_side'] = check_str(urldecode($xml->variables->cc_side));
    $database->fields['cc_member_uuid'] = check_str(urldecode($xml->variables->cc_member_uuid));
    $database->fields['cc_queue_joined_epoch'] = check_str(urldecode($xml->variables->cc_queue_joined_epoch));
    $database->fields['cc_queue'] = check_str(urldecode($xml->variables->cc_queue));
    $database->fields['cc_member_session_uuid'] = check_str(urldecode($xml->variables->cc_member_session_uuid));
    $database->fields['cc_agent'] = check_str(urldecode($xml->variables->cc_agent));
    $database->fields['cc_agent_type'] = check_str(urldecode($xml->variables->cc_agent_type));
    $database->fields['waitsec'] = check_str(urldecode($xml->variables->waitsec));
    //app info
    $database->fields['last_app'] = check_str(urldecode($xml->variables->last_app));
    $database->fields['last_arg'] = check_str(urldecode($xml->variables->last_arg));
    //conference
    $database->fields['conference_name'] = check_str(urldecode($xml->variables->conference_name));
    $database->fields['conference_uuid'] = check_str(urldecode($xml->variables->conference_uuid));
    $database->fields['conference_member_id'] = check_str(urldecode($xml->variables->conference_member_id));
    //call quality
    $rtp_audio_in_mos = check_str(urldecode($xml->variables->rtp_audio_in_mos));
    if (strlen($rtp_audio_in_mos) > 0) {
        $database->fields['rtp_audio_in_mos'] = $rtp_audio_in_mos;
    }
    //get the values from the callflow.
    $x = 0;
    foreach ($xml->callflow as $row) {
        if ($x == 0) {
            $context = check_str(urldecode($row->caller_profile->context));
            $database->fields['destination_number'] = check_str(urldecode($row->caller_profile->destination_number));
            $database->fields['context'] = $context;
            $database->fields['network_addr'] = check_str(urldecode($row->caller_profile->network_addr));
        }
        $database->fields['caller_id_name'] = check_str(urldecode($row->caller_profile->caller_id_name));
        $database->fields['caller_id_number'] = check_str(urldecode($row->caller_profile->caller_id_number));
        $x++;
    }
    unset($x);
    //if last_sent_callee_id_number is set use it for the destination_number
    if (strlen($xml->variables->last_sent_callee_id_number) > 0) {
        $database->fields['destination_number'] = urldecode($xml->variables->last_sent_callee_id_number);
    }
    //store the call leg
    $database->fields['leg'] = $leg;
    //store the call direction
    $database->fields['direction'] = check_str(urldecode($xml->variables->call_direction));
    //store post dial delay, in milliseconds
    $database->fields['pdd_ms'] = check_str(urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec));
    //get break down the date to year, month and day
    $tmp_time = strtotime($start_stamp);
    $tmp_year = date("Y", $tmp_time);
    $tmp_month = date("M", $tmp_time);
    $tmp_day = date("d", $tmp_time);
    //get the domain values from the xml
    $domain_name = check_str(urldecode($xml->variables->domain_name));
    $domain_uuid = check_str(urldecode($xml->variables->domain_uuid));
    //get the domain name from sip_req_host
    if (strlen($domain_name) == 0) {
        $domain_name = check_str(urldecode($xml->variables->sip_req_host));
    }
    //send the domain name to the cdr log
    xml_cdr_log("\ndomain_name is `{$domain_name}`; domain_uuid is '{$domain_uuid}'\n");
    //get the domain_uuid with the domain_name
    if (strlen($domain_uuid) == 0) {
        $sql = "select domain_uuid from v_domains ";
        if (strlen($domain_name) == 0 && $context != 'public' && $context != 'default') {
            $sql .= "where domain_name = '" . $context . "' ";
        } else {
            $sql .= "where domain_name = '" . $domain_name . "' ";
        }
        $row = $db->query($sql)->fetch();
        $domain_uuid = $row['domain_uuid'];
    }
    //set values in the database
    if (strlen($domain_uuid) > 0) {
        $database->domain_uuid = $domain_uuid;
        $database->fields['domain_uuid'] = $domain_uuid;
    }
    if (strlen($domain_name) > 0) {
        $database->fields['domain_name'] = $domain_name;
    }
    //check whether a recording exists
    $recording_relative_path = '/' . $_SESSION['domain_name'] . '/archive/' . $tmp_year . '/' . $tmp_month . '/' . $tmp_day;
    if (file_exists($_SESSION['switch']['recordings']['dir'] . $recording_relative_path . '/' . $uuid . '.wav')) {
        $recording_file = $recording_relative_path . '/' . $uuid . '.wav';
    } elseif (file_exists($_SESSION['switch']['recordings']['dir'] . $recording_relative_path . '/' . $uuid . '.mp3')) {
        $recording_file = $recording_relative_path . '/' . $uuid . '.mp3';
    }
    if (isset($recording_file) && !empty($recording_file)) {
        $database->fields['recording_file'] = $recording_file;
    }
    //save to the database in xml format
    if ($_SESSION['cdr']['format']['text'] == "xml" && $_SESSION['cdr']['storage']['text'] == "db") {
        $database->fields['xml'] = check_str($xml_string);
    }
    //save to the database in json format
    if ($_SESSION['cdr']['format']['text'] == "json" && $_SESSION['cdr']['storage']['text'] == "db") {
        $database->fields['json'] = check_str(json_encode($xml));
    }
    //insert the check_str($extension_uuid)
    if (strlen($xml->variables->extension_uuid) > 0) {
        $database->fields['extension_uuid'] = check_str(urldecode($xml->variables->extension_uuid));
    }
    //billing information
    if (file_exists($_SERVER["PROJECT_ROOT"] . "/app/billing/app_config.php")) {
        $db2 = new database();
        $lcr_currency = strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD';
        $accountcode = strlen(urldecode($xml->variables->accountcode)) ? check_str(urldecode($xml->variables->accountcode)) : $domain_name;
        switch (check_str(urldecode($xml->variables->call_direction))) {
            case "outbound":
                $destination_number = check_str(urldecode($xml->variables->lcr_query_digits));
                $destination_number_serie = number_series($destination_number);
                $database->fields['carrier_name'] = check_str(urldecode($xml->variables->lcr_carrier));
                $sql_rate = "SELECT v_lcr.connect_increment, v_lcr.talk_increment, v_lcr.currency FROM v_lcr, v_carriers WHERE v_carriers.carrier_name = '" . $xml->variables->lcr_carrier . "' AND v_lcr.rate=" . $xml->variables->lcr_rate . " AND v_lcr.lcr_direction = '" . check_str(urldecode($xml->variables->call_direction)) . "' AND digits IN ({$destination_number_serie}) AND v_lcr.carrier_uuid = v_carriers.carrier_uuid  ORDER BY digits DESC, rate ASC limit 1";
                $sql_user_rate = "SELECT v_lcr.currency, connect_increment, talk_increment FROM v_lcr JOIN v_billings ON v_billings.type_value='{$accountcode}' WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.lcr_direction = '" . check_str(urldecode($xml->variables->call_direction)) . "' AND v_lcr.lcr_profile=v_billings.lcr_profile AND NOW() >= v_lcr.date_start AND NOW() < v_lcr.date_end AND digits IN ({$destination_number_serie}) ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1";
                if ($debug) {
                    echo "sql_rate: {$sql_rate}\n";
                    echo "sql_user_rate: {$sql_user_rate}\n";
                }
                $db2->sql = $sql_rate;
                $db2->result = $db2->execute();
                //print_r($db2->result);
                $lcr_currency = strlen($db2->result[0]['currency']) ? check_str($db2->result[0]['currency']) : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
                $lcr_rate = strlen($xml->variables->lcr_rate) ? $xml->variables->lcr_rate : 0;
                $lcr_first_increment = strlen($db2->result[0]['connect_increment']) ? check_str($db2->result[0]['connect_increment']) : 60;
                $lcr_second_increment = strlen($db2->result[0]['talk_increment']) ? check_str($db2->result[0]['talk_increment']) : 60;
                unset($db2->sql);
                unset($db2->result);
                $db2->sql = $sql_user_rate;
                $db2->result = $db2->execute();
                $lcr_user_rate = strlen($xml->variables->lcr_user_rate) ? $xml->variables->lcr_user_rate : 0.01;
                $lcr_user_first_increment = strlen($db2->result[0]['connect_increment']) ? check_str($db2->result[0]['connect_increment']) : 60;
                $lcr_user_second_increment = strlen($db2->result[0]['talk_increment']) ? check_str($db2->result[0]['talk_increment']) : 60;
                $lcr_user_currency = strlen($db2->result[0]['currency']) ? check_str($db2->result[0]['currency']) : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
                unset($db2->sql);
                unset($db2->result);
                break;
            case "inbound":
                $callee_number = check_str(urldecode($row->caller_profile->destination_number));
                $callee_number_serie = number_series($callee_number);
                $sql_user_rate = "SELECT v_lcr.currency, v_lcr.rate, v_lcr.connect_increment, v_lcr.talk_increment FROM v_lcr JOIN v_billings ON v_billings.type_value='{$accountcode}' WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.lcr_direction = '" . check_str(urldecode($xml->variables->call_direction)) . "' AND v_lcr.lcr_profile=v_billings.lcr_profile AND NOW() >= v_lcr.date_start AND NOW() < v_lcr.date_end AND digits IN ({$callee_number_serie}) ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1";
                if ($debug) {
                    echo "sql_user_rate: {$sql_user_rate}\n";
                }
                $db2->sql = $sql_user_rate;
                $db2->result = $db2->execute();
                // If selling rate is found, then we fill with data, otherwise rate will be 0
                $lcr_currency = strlen($db2->result[0]['currency']) ? check_str($db2->result[0]['currency']) : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
                $lcr_user_rate = strlen($db2->result[0]['rate']) ? $db2->result[0]['rate'] : 0;
                $lcr_user_first_increment = strlen($db2->result[0]['connect_increment']) ? $db2->result[0]['connect_increment'] : 60;
                $lcr_user_second_increment = strlen($db2->result[0]['talk_increment']) ? $db2->result[0]['talk_increment'] : 60;
                $lcr_user_currency = strlen($db2->result[0]['currency']) ? check_str($db2->result[0]['currency']) : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
                // Actually, there is no way to detect what carrier is the calling comming from using current information
                $lcr_rate = 0;
                $lcr_first_increment = 0;
                $lcr_second_increment = 0;
                unset($db2->sql);
                unset($db2->result);
                break;
            case "local":
                $destination_number = check_str(urldecode($xml->variables->lcr_query_digits));
                $destination_number_serie = number_series($destination_number);
                $sql_user_rate = "SELECT v_lcr.currency, connect_increment, talk_increment FROM v_lcr JOIN v_billings ON v_billings.type_value='{$accountcode}' WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.lcr_direction = '" . check_str(urldecode($xml->variables->call_direction)) . "' AND v_lcr.lcr_profile=v_billings.lcr_profile AND NOW() >= v_lcr.date_start AND NOW() < v_lcr.date_end AND digits IN ({$destination_number_serie}) ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1";
                if ($debug) {
                    echo "sql_user_rate: {$sql_user_rate}\n";
                }
                $db2->sql = $sql_user_rate;
                $db2->result = $db2->execute();
                // If selling rate is found, then we fill with data, otherwise rate will be 0
                $lcr_currency = strlen($db2->result[0]['currency']) ? check_str($db2->result[0]['currency']) : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
                $lcr_user_rate = strlen($db2->result[0]['rate']) ? ${$db2}->result[0]['rate'] : 0;
                $lcr_user_first_increment = strlen($db2->result[0]['connect_increment']) ? $db2->result[0]['connect_increment'] : 60;
                $lcr_user_second_increment = strlen($db2->result[0]['talk_increment']) ? $db2->result[0]['talk_increment'] : 60;
                $lcr_user_currency = strlen($db2->result[0]['currency']) ? check_str($db2->result[0]['currency']) : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
                // Actually, internal calls have 0 cost
                $lcr_rate = 0;
                $lcr_first_increment = 0;
                $lcr_second_increment = 0;
                unset($db2->sql);
                unset($db2->result);
                break;
        }
        // Please note that we save values using LCR currency, but we discount balance in billing currency
        $time = check_str(urldecode($xml->variables->billsec));
        $call_buy = call_cost($lcr_rate, $lcr_first_increment, $lcr_second_increment, $time);
        $call_sell = call_cost($lcr_user_rate, $lcr_user_first_increment, $lcr_user_second_increment, $time);
        // Costs/Sell call are in original LCR currency, they need to be converted
        $database->fields['call_buy'] = check_str($call_buy);
        $database->fields['call_sell'] = check_str($call_sell);
        $db2->table = "v_xml_cdr";
        $db2->sql = "SELECT currency FROM v_billings WHERE type_value='{$accountcode}' LIMIT 1";
        $db2->result = $db2->execute();
        $actual_currency = strlen($lcr_currency) ? $lcr_currency : (strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD');
        $billing_currency = strlen($db2->result[0]['currency']) ? $db2->result[0]['currency'] : $default_currency;
        if ($debug) {
            echo "sql: " . $db2->sql . "\n";
            echo "c " . $database->fields['carrier_name'] . "\n";
            echo "t {$time}\n";
            echo "b r:{$lcr_rate} - {$lcr_first_increment} - {$lcr_first_increment} = {$call_buy}\n";
            echo "s r:{$lcr_user_rate} - {$lcr_user_first_increment} - {$lcr_user_second_increment} = {$call_sell}\n";
            echo "lcr currency {$lcr_currency}\n";
            echo "actual currency {$actual_currency}\n";
            echo "user currency {$lcr_user_currency}\n";
            echo "billing currency {$billing_currency}\n";
        }
        unset($database->sql);
        unset($database->result);
        $sql_balance = "SELECT balance, old_balance FROM v_billings WHERE type_value='" . check_str(urldecode($xml->variables->accountcode)) . "'";
        $db2->sql = $sql_balance;
        $db2->result = $db2->execute();
        $balance = $db2->result[0]['balance'];
        $old_balance = $db2->result[0]['old_balance'];
        if ($debug) {
            echo "sql_balance: {$sql_balance}\n";
            echo "bal: {$balance}\n";
            echo "old bal: {$old_balance}\n";
        }
        // Lets convert rate from lcr_currency to billing_currency
        $billing_call_sell = currency_convert($call_sell, $billing_currency, $lcr_user_currency);
        if ($debug) {
            echo "bcs: {$billing_call_sell} {$billing_currency}\n";
        }
        // Remember that old_balance is using billing_currency
        $updated_balance = (double) $old_balance - (double) $billing_call_sell;
        unset($db2->sql);
        unset($db2->result);
        $sql_update_balance = "UPDATE v_billings SET balance={$updated_balance}, old_balance={$updated_balance} WHERE type_value='" . check_str(urldecode($xml->variables->accountcode)) . "'";
        if ($debug) {
            echo "sql_update_balance: {$sql_update_balance}\n";
        }
        $db2->sql = $sql_update_balance;
        $db2->result = $db2->execute();
        unset($db2->sql);
        unset($db2->result);
    }
    //insert xml_cdr into the db
    if (strlen($start_stamp) > 0) {
        $database->add();
        if ($debug) {
            echo $database->sql . "\n";
        }
    }
    //insert the values
    if (strlen($uuid) > 0) {
        if ($debug) {
            $time5_insert = microtime(true);
            //echo $sql."<br />\n";
        }
        try {
            $error = "false";
            //$db->exec(check_sql($sql));
        } catch (PDOException $e) {
            $tmp_dir = $_SESSION['switch']['log']['dir'] . '/xml_cdr/failed/';
            if (!file_exists($tmp_dir)) {
                event_socket_mkdir($tmp_dir);
            }
            if ($_SESSION['cdr']['format']['text'] == "xml") {
                $tmp_file = $uuid . '.xml';
                $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                fwrite($fh, $xml_string);
            } else {
                $tmp_file = $uuid . '.json';
                $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                fwrite($fh, json_encode($xml));
            }
            fclose($fh);
            if ($debug) {
                echo $e->getMessage();
            }
            $error = "true";
        }
        if ($_SESSION['cdr']['storage']['text'] == "dir" && $error != "true") {
            if (strlen($uuid) > 0) {
                $tmp_time = strtotime($start_stamp);
                $tmp_year = date("Y", $tmp_time);
                $tmp_month = date("M", $tmp_time);
                $tmp_day = date("d", $tmp_time);
                $tmp_dir = $_SESSION['switch']['log']['dir'] . '/xml_cdr/archive/' . $tmp_year . '/' . $tmp_month . '/' . $tmp_day;
                if (!file_exists($tmp_dir)) {
                    event_socket_mkdir($tmp_dir);
                }
                if ($_SESSION['cdr']['format']['text'] == "xml") {
                    $tmp_file = $uuid . '.xml';
                    $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                    fwrite($fh, $xml_string);
                } else {
                    $tmp_file = $uuid . '.json';
                    $fh = fopen($tmp_dir . '/' . $tmp_file, 'w');
                    fwrite($fh, json_encode($xml));
                }
                fclose($fh);
            }
        }
        unset($error);
        if ($debug) {
            global $insert_time, $insert_count;
            $insert_time += microtime(true) - $time5_insert;
            //add this current query.
            $insert_count++;
        }
    }
    unset($sql);
}
Example #8
0
 function save_sip_profile_xml()
 {
     //skip saving the sip profile xml if the directory is not set
     if (strlen($_SESSION['switch']['sip_profiles']['dir']) == 0) {
         return;
     }
     // make profile dir if needed
     $profile_dir = $_SESSION['switch']['conf']['dir'] . "/sip_profiles";
     if (!is_readable($profile_dir)) {
         event_socket_mkdir($profile_dir);
     }
     //get the global variables
     global $domain_uuid;
     //get the database connection
     require_once "resources/classes/database.php";
     $database = new database();
     $database->connect();
     $db = $database->db;
     //get the sip profiles from the database
     $sql = "select * from v_sip_profiles";
     $prep_statement = $db->prepare(check_sql($sql));
     $prep_statement->execute();
     $result = $prep_statement->fetchAll();
     $result_count = count($result);
     unset($prep_statement, $sql);
     if ($result_count > 0) {
         foreach ($result as $row) {
             $sip_profile_uuid = $row['sip_profile_uuid'];
             $sip_profile_name = $row['sip_profile_name'];
             $sip_profile_enabled = $row['sip_profile_enabled'];
             if ($sip_profile_enabled == 'false') {
                 $fout = fopen($profile_dir . '/' . $sip_profile_name . ".xml", "w");
                 if ($fout) {
                     fclose($fout);
                 }
                 continue;
             }
             //get the xml sip profile template
             if ($sip_profile_name == "internal" || $sip_profile_name == "external" || $sip_profile_name == "internal-ipv6") {
                 $file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/sip_profiles/resources/xml/sip_profiles/" . $sip_profile_name . ".xml");
             } else {
                 $file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/sip_profiles/resources/xml/sip_profiles/default.xml");
             }
             //get the sip profile settings
             $sql = "select * from v_sip_profile_settings ";
             $sql .= "where sip_profile_uuid = '{$sip_profile_uuid}' ";
             $sql .= "and sip_profile_setting_enabled = 'true' ";
             $prep_statement = $db->prepare(check_sql($sql));
             $prep_statement->execute();
             $result = $prep_statement->fetchAll();
             $sip_profile_settings = '';
             foreach ($result as &$row) {
                 $sip_profile_settings .= "\t\t<param name=\"" . $row["sip_profile_setting_name"] . "\" value=\"" . $row["sip_profile_setting_value"] . "\"/>\n";
             }
             unset($prep_statement);
             //replace the values in the template
             $file_contents = str_replace("{v_sip_profile_name}", $sip_profile_name, $file_contents);
             $file_contents = str_replace("{v_sip_profile_settings}", $sip_profile_settings, $file_contents);
             //write the XML config file
             if (is_readable($profile_dir . '/')) {
                 $fout = fopen($profile_dir . '/' . $sip_profile_name . ".xml", "w");
                 fwrite($fout, $file_contents);
                 fclose($fout);
             }
             //if the directory does not exist then create it
             if (!is_readable($profile_dir . '/' . $sip_profile_name)) {
                 event_socket_mkdir($profile_dir . '/' . $sip_profile_name);
             }
         }
         //end foreach
         unset($sql, $result, $row_count);
     }
     //end if results
     //apply settings
     $_SESSION["reload_xml"] = true;
 }
Example #9
0
 public function xml()
 {
     if (isset($_SESSION['switch']['extensions']['dir'])) {
         //declare global variables
         global $config, $db, $domain_uuid;
         //get the domain_name
         $domain_name = $_SESSION['domains'][$domain_uuid]['domain_name'];
         $user_context = $domain_name;
         //delete all old extensions to prepare for new ones
         $dialplan_list = glob($_SESSION['switch']['extensions']['dir'] . "/" . $user_context . "/v_*.xml");
         foreach ($dialplan_list as $name => $value) {
             unlink($value);
         }
         //write the xml files
         $sql = "SELECT * FROM v_extensions AS e, v_voicemails AS v ";
         $sql .= "WHERE e.domain_uuid = '{$domain_uuid}' ";
         $sql .= "AND (e.extension = v.voicemail_id or e.number_alias = v.voicemail_id) ";
         $sql .= "ORDER BY e.call_group ASC ";
         $prep_statement = $db->prepare(check_sql($sql));
         $prep_statement->execute();
         $i = 0;
         $extension_xml_condensed = false;
         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) {
                 $tmp_call_group = trim($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++;
             }
             $call_timeout = $row['call_timeout'];
             $user_context = $row['user_context'];
             $password = $row['password'];
             $voicemail_password = $row['voicemail_password'];
             //$voicemail_password = str_replace("#", "", $voicemail_password); //preserves leading zeros
             //echo "enabled: ".$row['enabled'];
             if ($row['enabled'] != "false") {
                 $extension_uuid = $row['extension_uuid'];
                 //remove invalid characters from the file names
                 $extension = $row['extension'];
                 $extension = str_replace(" ", "_", $extension);
                 $extension = preg_replace("/[\\*\\:\\/\\<\\>\\|\\'\"\\?]/", "", $extension);
                 $dial_string = $row['dial_string'];
                 if (strlen($dial_string) == 0) {
                     if (strlen($_SESSION['domain']['dial_string']['text']) > 0) {
                         $dial_string = $_SESSION['domain']['dial_string']['text'];
                     } else {
                         $dial_string = "{sip_invite_domain=\${domain_name},leg_timeout=" . $call_timeout . ",presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}";
                     }
                 }
                 //set the password hashes
                 $a1_hash = md5($extension . ":" . $domain_name . ":" . $password);
                 $vm_a1_hash = md5($extension . ":" . $domain_name . ":" . $voicemail_password);
                 $xml .= "<include>\n";
                 $cidr = '';
                 if (strlen($row['cidr']) > 0) {
                     $cidr = " cidr=\"" . $row['cidr'] . "\"";
                 }
                 $number_alias = '';
                 if (strlen($row['number_alias']) > 0) {
                     $number_alias = " number-alias=\"" . $row['number_alias'] . "\"";
                 }
                 $xml .= "  <user id=\"" . $row['extension'] . "\"" . $cidr . "" . $number_alias . ">\n";
                 $xml .= "    <params>\n";
                 //$xml .= "      <param name=\"a1-hash\" value=\"" . $a1_hash . "\"/>\n";
                 $xml .= "      <param name=\"password\" value=\"" . $row['password'] . "\"/>\n";
                 $xml .= "      <param name=\"reverse-auth-user\" value=\"" . $row['extension'] . "\"/>\n";
                 $xml .= "      <param name=\"reverse-auth-pass\" value=\"" . $row['password'] . "\"/>\n";
                 //voicemail settings
                 //$xml .= "      <param name=\"vm-a1-hash\" value=\"" . $vm_a1_hash. "\"/>\n";
                 $xml .= "      <param name=\"vm-password\" value=\"" . $voicemail_password . "\"/>\n";
                 switch ($row['voicemail_enabled']) {
                     case "true":
                         $xml .= "      <param name=\"vm-enabled\" value=\"true\"/>\n";
                         break;
                     case "false":
                         $xml .= "      <param name=\"vm-enabled\" value=\"false\"/>\n";
                         break;
                     default:
                         $xml .= "      <param name=\"vm-enabled\" value=\"true\"/>\n";
                 }
                 if (strlen($row['voicemail_mail_to']) > 0) {
                     $xml .= "      <param name=\"vm-email-all-messages\" value=\"true\"/>\n";
                     switch ($row['voicemail_file']) {
                         case "attach":
                             $xml .= "      <param name=\"vm-attach-file\" value=\"true\"/>\n";
                             break;
                         default:
                             $xml .= "      <param name=\"vm-attach-file\" value=\"false\"/>\n";
                     }
                     switch ($row['voicemail_local_after_email']) {
                         case "true":
                             $xml .= "      <param name=\"vm-keep-local-after-email\" value=\"true\"/>\n";
                             break;
                         case "false":
                             $xml .= "      <param name=\"vm-keep-local-after-email\" value=\"false\"/>\n";
                             break;
                         default:
                             $xml .= "      <param name=\"vm-keep-local-after-email\" value=\"true\"/>\n";
                     }
                     $xml .= "      <param name=\"vm-mailto\" value=\"" . $row['voicemail_mail_to'] . "\"/>\n";
                 }
                 if (strlen($row['mwi_account']) > 0) {
                     $xml .= "      <param name=\"MWI-Account\" value=\"" . $row['mwi_account'] . "\"/>\n";
                 }
                 if (strlen($row['auth_acl']) > 0) {
                     $xml .= "      <param name=\"auth-acl\" value=\"" . $row['auth_acl'] . "\"/>\n";
                 }
                 if (strlen($row['directory_exten_visible']) > 0) {
                     $xml .= "      <param name=\"directory-exten-visible\" value=\"" . $row['directory_exten_visible'] . "\"/>\n";
                 }
                 $xml .= "      <param name=\"dial-string\" value=\"" . $dial_string . "\"/>\n";
                 $xml .= "    </params>\n";
                 $xml .= "    <variables>\n";
                 $xml .= "      <variable name=\"domain_name\" value=\"" . $_SESSION['domain_name'] . "\"/>\n";
                 $xml .= "      <variable name=\"domain_uuid\" value=\"" . $_SESSION['domain_uuid'] . "\"/>\n";
                 $xml .= "      <variable name=\"extension_uuid\" value=\"" . $extension_uuid . "\"/>\n";
                 if (strlen($row['call_group']) > 0) {
                     $xml .= "      <variable name=\"call_group\" value=\"" . $row['call_group'] . "\"/>\n";
                 }
                 if (strlen($row['user_record']) > 0) {
                     $xml .= "      <variable name=\"user_record\" value=\"" . $row['user_record'] . "\"/>\n";
                 }
                 if (strlen($row['hold_music']) > 0) {
                     $xml .= "      <variable name=\"hold_music\" value=\"" . $row['hold_music'] . "\"/>\n";
                 }
                 $xml .= "      <variable name=\"toll_allow\" value=\"" . $row['toll_allow'] . "\"/>\n";
                 if (strlen($row['call_timeout']) > 0) {
                     $xml .= "      <variable name=\"call_timeout\" value=\"" . $row['call_timeout'] . "\"/>\n";
                 }
                 if (strlen($switch_account_code) > 0) {
                     $xml .= "      <variable name=\"accountcode\" value=\"" . $switch_account_code . "\"/>\n";
                 } else {
                     $xml .= "      <variable name=\"accountcode\" value=\"" . $row['accountcode'] . "\"/>\n";
                 }
                 $xml .= "      <variable name=\"user_context\" value=\"" . $row['user_context'] . "\"/>\n";
                 if (strlen($row['effective_caller_id_name']) > 0) {
                     $xml .= "      <variable name=\"effective_caller_id_name\" value=\"" . $row['effective_caller_id_name'] . "\"/>\n";
                 }
                 if (strlen($row['effective_caller_id_number']) > 0) {
                     $xml .= "      <variable name=\"effective_caller_id_number\" value=\"" . $row['effective_caller_id_number'] . "\"/>\n";
                 }
                 if (strlen($row['outbound_caller_id_name']) > 0) {
                     $xml .= "      <variable name=\"outbound_caller_id_name\" value=\"" . $row['outbound_caller_id_name'] . "\"/>\n";
                 }
                 if (strlen($row['outbound_caller_id_number']) > 0) {
                     $xml .= "      <variable name=\"outbound_caller_id_number\" value=\"" . $row['outbound_caller_id_number'] . "\"/>\n";
                 }
                 if (strlen($row['emergency_caller_id_name']) > 0) {
                     $xml .= "      <variable name=\"emergency_caller_id_name\" value=\"" . $row['emergency_caller_id_name'] . "\"/>\n";
                 }
                 if (strlen($row['emergency_caller_id_number']) > 0) {
                     $xml .= "      <variable name=\"emergency_caller_id_number\" value=\"" . $row['emergency_caller_id_number'] . "\"/>\n";
                 }
                 if (strlen($row['directory_full_name']) > 0) {
                     $xml .= "      <variable name=\"directory_full_name\" value=\"" . $row['directory_full_name'] . "\"/>\n";
                 }
                 if (strlen($row['directory_visible']) > 0) {
                     $xml .= "      <variable name=\"directory-visible\" value=\"" . $row['directory_visible'] . "\"/>\n";
                 }
                 if (strlen($row['limit_max']) > 0) {
                     $xml .= "      <variable name=\"limit_max\" value=\"" . $row['limit_max'] . "\"/>\n";
                 } else {
                     $xml .= "      <variable name=\"limit_max\" value=\"5\"/>\n";
                 }
                 if (strlen($row['limit_destination']) > 0) {
                     $xml .= "      <variable name=\"limit_destination\" value=\"" . $row['limit_destination'] . "\"/>\n";
                 }
                 if (strlen($row['sip_force_contact']) > 0) {
                     $xml .= "      <variable name=\"sip-force-contact\" value=\"" . $row['sip_force_contact'] . "\"/>\n";
                 }
                 if (strlen($row['sip_force_expires']) > 0) {
                     $xml .= "      <variable name=\"sip-force-expires\" value=\"" . $row['sip_force_expires'] . "\"/>\n";
                 }
                 if (strlen($row['nibble_account']) > 0) {
                     $xml .= "      <variable name=\"nibble_account\" value=\"" . $row['nibble_account'] . "\"/>\n";
                 }
                 switch ($row['sip_bypass_media']) {
                     case "bypass-media":
                         $xml .= "      <variable name=\"bypass_media\" value=\"true\"/>\n";
                         break;
                     case "bypass-media-after-bridge":
                         $xml .= "      <variable name=\"bypass_media_after_bridge\" value=\"true\"/>\n";
                         break;
                     case "proxy-media":
                         $xml .= "      <variable name=\"proxy_media\" value=\"true\"/>\n";
                         break;
                 }
                 if (strlen($row['absolute_codec_string']) > 0) {
                     $xml .= "      <variable name=\"absolute_codec_string\" value=\"" . $row['absolute_codec_string'] . "\"/>\n";
                 }
                 if (strlen($row['forward_all_enabled']) > 0) {
                     $xml .= "      <variable name=\"forward_all_enabled\" value=\"" . $row['forward_all_enabled'] . "\"/>\n";
                 }
                 if (strlen($row['forward_all_destination']) > 0) {
                     $xml .= "      <variable name=\"forward_all_destination\" value=\"" . $row['forward_all_destination'] . "\"/>\n";
                 }
                 if (strlen($row['forward_busy_enabled']) > 0) {
                     $xml .= "      <variable name=\"forward_busy_enabled\" value=\"" . $row['forward_busy_enabled'] . "\"/>\n";
                 }
                 if (strlen($row['forward_busy_destination']) > 0) {
                     $xml .= "      <variable name=\"forward_busy_destination\" value=\"" . $row['forward_busy_destination'] . "\"/>\n";
                 }
                 if (strlen($row['forward_no_answer_enabled']) > 0) {
                     $xml .= "      <variable name=\"forward_no_answer_enabled\" value=\"" . $row['forward_no_answer_enabled'] . "\"/>\n";
                 }
                 if (strlen($row['forward_no_answer_destination']) > 0) {
                     $xml .= "      <variable name=\"forward_no_answer_destination\" value=\"" . $row['forward_no_answer_destination'] . "\"/>\n";
                 }
                 if (strlen($row['forward_user_not_registered_enabled']) > 0) {
                     $xml .= "      <variable name=\"forward_user_not_registered_enabled\" value=\"" . $row['forward_user_not_registered_enabled'] . "\"/>\n";
                 }
                 if (strlen($row['forward_user_not_registered_destination']) > 0) {
                     $xml .= "      <variable name=\"forward_user_not_registered_destination\" value=\"" . $row['forward_user_not_registered_destination'] . "\"/>\n";
                 }
                 if (strlen($row['do_not_disturb']) > 0) {
                     $xml .= "      <variable name=\"do_not_disturb\" value=\"" . $row['do_not_disturb'] . "\"/>\n";
                 }
                 $xml .= "    </variables>\n";
                 $xml .= "  </user>\n";
                 if (!is_readable($_SESSION['switch']['extensions']['dir'] . "/" . $row['user_context'])) {
                     event_socket_mkdir($_SESSION['switch']['extensions']['dir'] . "/" . $row['user_context']);
                 }
                 if (strlen($extension) > 0) {
                     $fout = fopen($_SESSION['switch']['extensions']['dir'] . "/" . $row['user_context'] . "/v_" . $extension . ".xml", "w");
                 }
                 $xml .= "</include>\n";
                 fwrite($fout, $xml);
                 unset($xml);
                 fclose($fout);
             }
         }
         unset($prep_statement);
         //prepare extension
         $extension_dir = realpath($_SESSION['switch']['extensions']['dir']);
         $user_context = str_replace(" ", "_", $user_context);
         $user_context = preg_replace("/[\\*\\:\\/\\<\\>\\|\\'\"\\?]/", "", $user_context);
         //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 ($user_context == "default") {
             $xml .= "\t<domain name=\"\$\${domain}\">\n";
         } else {
             $xml .= "\t<domain name=\"" . $user_context . "\">\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=\"" . $user_context . "\">\n";
         $xml .= "\t\t\t<users>\n";
         $xml .= "\t\t\t\t<X-PRE-PROCESS cmd=\"include\" data=\"" . $user_context . "/*.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 = trim($key);
             $extension_list = trim($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>";
         //write the xml file
         if (is_readable($extension_dir) && strlen($extension_dir) > 0) {
             $fout = fopen($extension_dir . "/" . $user_context . ".xml", "w");
             fwrite($fout, $xml);
             unset($xml);
             fclose($fout);
         }
         //apply settings
         $_SESSION["reload_xml"] = true;
     }
 }
Example #10
0
	FusionPBX
	Version: MPL 1.1

	The contents of this file are subject to the Mozilla Public License Version
	1.1 (the "License"); you may not use this file except in compliance with
	the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/

	Software distributed under the License is distributed on an "AS IS" basis,
	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
	for the specific language governing rights and limitations under the
	License.

	The Original Code is FusionPBX

	The Initial Developer of the Original Code is
	Mark J Crane <*****@*****.**>
	Portions created by the Initial Developer are Copyright (C) 2008-2012
	the Initial Developer. All Rights Reserved.

	Contributor(s):
	Mark J Crane <*****@*****.**>
*/
//if the extensions dir doesn't exist then create it
if ($domains_processed == 1) {
    if (strlen($_SESSION['switch']['extensions']['dir']) > 0) {
        if (!is_dir($_SESSION['switch']['extensions']['dir'])) {
            event_socket_mkdir($_SESSION['switch']['extensions']['dir']);
        }
    }
}