public function __construct() { //connect to the database if not connected if (!$this->db) { require_once "resources/classes/database.php"; $database = new database(); $database->connect(); $this->db = $database->db; } //add multi-lingual support $language = new text(); $text = $language->get(); //get the ringback types $sql = "select * from v_vars "; $sql .= "where var_cat = 'Defaults' "; $sql .= "and var_name LIKE '%-ring' "; $sql .= "order by var_name asc "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $ringbacks = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($prep_statement, $sql); foreach ($ringbacks as $ringback) { $ringback = $ringback['var_name']; $label = $text['label-' . $ringback]; if ($label == "") { $label = $ringback; } $ringback_list[$ringback] = $label; } $this->ringbacks = $ringback_list; unset($ringback_list); //get the default_ringback label /* $sql = "select * from v_vars where var_name = 'ringback' "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetch(); unset ($prep_statement, $sql); $default_ringback = (string) $result['var_value']; $default_ringback = preg_replace('/\A\$\${/',"",$default_ringback); $default_ringback = preg_replace('/}\z/',"",$default_ringback); #$label = $text['label-'.$default_ringback]; #if($label == "") { $label = $default_ringback; #} $this->default_ringback_label = $label; unset($results, $default_ringback, $label); */ //get music on hold and recordings if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/music_on_hold')) { require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; $music = new switch_music_on_hold(); $this->music_list = $music->get(); } if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/recordings')) { require_once "app/recordings/resources/classes/switch_recordings.php"; $recordings = new switch_recordings(); $this->recordings_list = $recordings->list_recordings(); } }
function login_check($username, $password) { global $con, $DB_SALT; // print $username.$password.$DB_SALT; // $Pwd = strrev($username).'#'. $DB_SALT .'#'.strrev($password); // $Pwd = md5($Pwd); if ($username && $password) { $Pwd = pwd_encode($username, $password); $query = "SELECT * FROM User WHERE NAME='" . $username . "' AND Password='******'"; // print '$query= '. $query . '<br>'; $result = mysql_query($query); if ($row = mysql_fetch_array($result)) { $_SESSION['user'] = $row['Name']; $_SESSION['userID'] = $row['ID']; $_SESSION['isadmin'] = $row['Is_Admin']; return True; } } // check token $token = check_sql(trim($_REQUEST['token'])); if ($token and $token != '') { $query = "SELECT * From User WHERE Token='{$token}'"; // print '$query= '. $query . '<br>'; $result = mysql_query($query); if ($row = mysql_fetch_array($result)) { $_SESSION['user'] = $row['Name']; $_SESSION['userID'] = $row['ID']; $_SESSION['isadmin'] = $row['Is_Admin']; return True; } } return False; }
function addFriend($id) { $sessionid = $_SESSION['SESS_LOGIN_ID']; $sql_newfriend = "INSERT INTO friend (User_ID_1, User_ID_2)\n\tVALUES ('{$sessionid}', '{$id}')"; check_sql($sql_newfriend, $conn); $sql_newfriend = "INSERT INTO friend (User_ID_1, User_ID_2)\n\tVALUES ('{$id}', '{$sessionid}')"; check_sql($sql_newfriend, $conn); }
public function list_recordings() { $sql = "select recording_uuid, recording_filename, recording_base64 from v_recordings "; $sql .= "where domain_uuid = '" . $this->domain_uuid . "' "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $recordings[$_SESSION['switch']['recordings']['dir'] . '/' . $_SESSION['domain_name'] . "/" . $row['recording_filename']] = $row['recording_filename']; } unset($prep_statement); return $recordings; }
function ifgroupmembers($db, $groupid, $username) { $sql = "select * from v_group_members "; $sql .= "where v_id = '{$v_id}' "; $sql .= "and groupid = '{$groupid}' "; $sql .= "and username = '******' "; $prepstatement = $db->prepare(check_sql($sql)); $prepstatement->execute(); if (count($prepstatement->fetchAll()) == 0) { return true; } else { return false; } unset($sql, $prepstatement); }
function is_group_member($group_uuid, $user_uuid) { global $db, $domain_uuid; $sql = "select * from v_group_users "; $sql .= "where user_uuid = '" . $user_uuid . "' "; $sql .= "and group_uuid = '" . $group_uuid . "' "; $sql .= "and domain_uuid = '" . ($domain_uuid != '' ? $domain_uuid : $_SESSION['domain_uuid']) . "' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); if (count($prep_statement->fetchAll(PDO::FETCH_NAMED)) == 0) { return true; } else { return false; } unset($sql, $prep_statement); }
function Add_S($array) { foreach ($array as $key => $value) { if (!is_array($value)) { $filter = "\\<.+javascript:window\\[.{1}\\\\x|<.*=(&#\\d+?;?)+?>|<.*(data|src)=data:text\\/html.*>|\\b(alert\\(|confirm\\(|expression\\(|prompt\\(|benchmark\\s*?\\(.*\\)|sleep\\s*?\\(.*\\)|load_file\\s*?\\()|<[a-z]+?\\b[^>]*?\\bon([a-z]{4,})\\s*?=|^\\+\\/v(8|9)|\\b(and|or)\\b\\s*?([\\(\\)'\"\\d]+?=[\\(\\)'\"\\d]+?|[\\(\\)'\"a-zA-Z]+?=[\\(\\)'\"a-zA-Z]+?|>|<|\\s+?[\\w]+?\\s+?\\bin\\b\\s*?\\(|\\blike\\b\\s+?[\"'])|\\/\\*.*\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT(\\(|@{1,2}\\w+?\\s*|\\s+?.+?|.*(`|'|\").+(`|'|\")\\s*)|UPDATE\\s*(\\(.+\\)\\s*|@{1,2}.+?\\s*|\\s+?.+?|(`|'|\").*?(`|'|\")\\s*)SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM\\s+?|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)|FROM\\s.?|\\(select|\\(\\sselect|\\bunion\\b|select\\s.+?"; //่ฟๆปคๅญๆฅ่ฏขๅ็ง !get_magic_quotes_gpc() && ($value = addslashes($value)); $value = check_sql($value); webscan_StOpAttack($key, $value, $filter, "GET"); $array[$key] = $value; } else { $array[$key] = Add_S($array[$key]); } } return $array; }
function search_config($name) { $name = check_sql($name); $userId = $_SESSION['userID']; $query = "SELECT Config.ID,Config.Name,Config.Time,Config.Config,Config.AutoI,Config.Description,Config.IsDefault FROM Config,User WHERE Config.User_ID=User.ID AND Config.Name LIKE '%{$name}%'"; // echo $query.'<br>'; $ret = array('data' => array()); $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { // foreach ($row as $key => $value){ // $row[$key] = check_xss($value); // } $ret['data'][] = $row; // var_dump($row); } return $ret; }
function search_config($s) { $name = check_sql($name); $userId = $_SESSION['userID']; $query = "SELECT Config.Name,Config.Description FROM Config,User WHERE Config.User_ID=User.ID AND Config.Name like '%{$name}%'"; // echo $query.'<br>'; $ret = array(); $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { foreach ($row as $key => $value) { $row[$key] = check_xss($value); } $ret[] = $row; // var_dump($row); } return $ret; }
function device_by_ext($db, $ext, $domain) { $sql = 'select t1.* '; $sql .= 'from v_devices t1 inner join v_device_lines t2 on t1.device_uuid=t2.device_uuid '; $sql .= 'inner join v_domains t3 on t2.domain_uuid=t3.domain_uuid '; $sql .= 'where t2.user_id=:ext '; $sql .= 'and t3.domain_name=:domain '; $sql .= 'and t3.domain_enabled = \'true\' '; $prep = $db->prepare(check_sql($sql)); if ($prep) { $prep->bindParam(':ext', $ext); $prep->bindParam(':domain', $domain); $prep->execute(); $row = $prep->fetch(); unset($prep); return $row; } return false; }
function add_task($target, $arguments) { $target = check_sql($target); $time = time(); // $argJson = base64_encode(json_encode($arguments)); // $argJson = json_encode($arguments,JSON_FORCE_OBJECT); $argJson = json_encode($arguments); $argJson = mysql_real_escape_string($argJson); $userid = get_userid(); var_dump($argJson); $query = "INSERT INTO Task(Target,Start_Time,Arguments,Status,User_ID) VALUES('{$target}',{$time},'{$argJson}','waiting',{$userid})"; // echo $query . '<br>'; $result = mysql_query($query); if ($result) { return True; } else { echo mysql_error(); return False; } }
function get_code($id = 0, $name = '') { $pID = intval($id); $pName = check_sql($name); $query = "SELECT ID,Name,Type,Author,Time,Version,Web,Description,Code FROM Plugin"; if (is_int($pID) and $pID > 0) { $query .= " WHERE ID={$pID}"; } elseif ($pName != '') { $query .= " WHERE Name={$pName}"; } // print($query.'<br>'); // $ret = array('data' => array(), ); $result = mysql_query($query); if ($row = mysql_fetch_row($result)) { foreach ($row as $key => $value) { // echo $key.' => '.$value; $row[$key] = check_xss($value); } $ret['data'][] = $row; return $ret; } }
function call_block_get_extensions($select_extension) { global $db, $text; //list voicemail $sql = "select extension, user_context, description from v_extensions "; $sql .= "where domain_uuid = '" . $_SESSION['domain_uuid'] . "' "; $sql .= "and enabled = 'true' "; $sql .= "order by extension asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); echo "<optgroup label='" . $text['label-voicemail'] . "'>\n"; foreach ($result as &$row) { $extension = $row["extension"]; $context = $row["user_context"]; $description = $row["description"]; if ($extension == $select_extension) { $selected = "selected='selected'"; } echo "\t\t<option value='Voicemail {$context} {$extension}' {$selected}>" . $extension . " " . $description . "</option>\n"; $selected = ""; } echo "</optgroup>\n"; }
$accountcode = $_SESSION['domain_name']; } echo " <input class='formfld' type='text' name='broadcast_accountcode' maxlength='255' value=\"{$broadcast_accountcode}\">\n"; echo "<br />\n"; echo $text['description-accountcode'] . "\n"; echo "</td>\n"; echo "</tr>\n"; } elseif (if_group("admin") && file_exists($_SERVER["PROJECT_ROOT"] . "/app/billing/app_config.php")) { $sql_accountcode = "SELECT type_value FROM v_billings WHERE domain_uuid = '" . $_SESSION['domain_uuid'] . "'"; echo "<tr>\n"; echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n"; echo " " . $text['label-accountcode'] . "\n"; echo "</td>\n"; echo "<td class='vtable' align='left'>\n"; echo " <select name='broadcast_accountcode' id='broadcast_accountcode' class='formfld'>\n"; $prep_statement_accountcode = $db->prepare(check_sql($sql_accountcode)); $prep_statement_accountcode->execute(); $result_accountcode = $prep_statement_accountcode->fetchAll(PDO::FETCH_NAMED); foreach ($result_accountcode as &$row_accountcode) { $selected = ''; if ($action == "add" && $row_accountcode['type_value'] == $_SESSION['domain_name']) { $selected = 'selected="selected"'; } elseif ($row_accountcode['type_value'] == $accountcode) { $selected = 'selected="selected"'; } echo " <option value=\"" . $row_accountcode['type_value'] . "\" {$selected}>" . $row_accountcode['type_value'] . "</option>\n"; } unset($sql_accountcode, $prep_statement_accountcode, $result_accountcode); echo "</select>"; echo "<br />\n"; echo $text['description-accountcode'] . "\n";
} } $count = $db->exec("BEGIN;"); //returns affected rows //This is the buffer we want to do stuff with, maybe thow to a function? $buf = substr($rbuf, 0, $i + 1); $buf = str_replace("{domain_uuid}", $domain_uuid, $buf); $totalsize = strlen($buf) + $totalsize; $lnarray = explode("\n", $buf); //print_r($lnarray); $columnvaluecount = 0; foreach ($lnarray as $sql) { //--- Begin SQLite ------------------------------------- if (strlen($sql) > 0) { //echo $sql."<br /><br />\n"; $count = $db->exec(check_sql($sql)); //returns affected rows $x++; if ($x > 10000) { $count = $db->exec("COMMIT;"); //returns affected rows $count = $db->exec("BEGIN;"); //returns affected rows } } unset($sql); //---EndSQLite------------------------------------- //if ($columnvaluecount > 10) { break; } $columnvaluecount++; } //Point marker back to last \n point
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)) { mkdir($profile_dir, 0775, true); } //get the global variables global $db, $domain_uuid; //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)) { mkdir($profile_dir . '/' . $sip_profile_name, 0775, true); } } //end foreach unset($sql, $result, $row_count); } //end if results //apply settings $_SESSION["reload_xml"] = true; }
<?php if ($safe != "U,,5Enc!") { die("nepovoleny prรญstup k sรบboru!!"); } $from = check_get($_GET[from]); // ziskanie hodnoty premennej vyber $c = check_get($_GET[c]); // ziskanie hodnoty premennej vyber $id = check_get($_GET[id]); // ziskanie hodnoty premennej vyber $from = check_sql($from); // ziskanie hodnoty premennej vyber $c = check_sql($c); // ziskanie hodnoty premennej vyber $id = check_sql($id); // ziskanie hodnoty premennej vyber $actual_order = get_actual_order($from, $c, $id); $max_order = get_max_order($from, $c, $id); if ($order == "up") { if ($actual_order != 0) { up($from, $c, $id); } } if ($order == "down") { if ($actual_order != $max_order) { down($from, $c, $id); } } function get_actual_order($from, $c, $id) {
function user_add($username, $password, $user_email = '') { global $db, $domain_uuid, $v_salt; $user_uuid = uuid(); if (strlen($username) == 0) { return false; } if (strlen($password) == 0) { return false; } if (!username_exists($username)) { //salt used with the password to create a one way hash $salt = generate_password('20', '4'); //add the user account $user_type = 'Individual'; $user_category = 'user'; $sql = "insert into v_users "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "user_uuid, "; $sql .= "username, "; $sql .= "password, "; $sql .= "salt, "; if (strlen($user_email) > 0) { $sql .= "user_email, "; } $sql .= "add_date, "; $sql .= "add_user "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'{$domain_uuid}', "; $sql .= "'{$user_uuid}', "; $sql .= "'{$username}', "; $sql .= "'" . md5($salt . $password) . "', "; $sql .= "'{$salt}', "; if (strlen($user_email) > 0) { $sql .= "'{$user_email}', "; } $sql .= "now(), "; $sql .= "'" . $_SESSION["username"] . "' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //add the user to the member group $group_name = 'user'; $sql = "insert into v_group_users "; $sql .= "("; $sql .= "group_user_uuid, "; $sql .= "domain_uuid, "; $sql .= "group_name, "; $sql .= "user_uuid "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'{$domain_uuid}', "; $sql .= "'{$group_name}', "; $sql .= "'{$user_uuid}' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //end if !username_exists }
function notifiy_friends($conn2) { $query1 = "SELECT * from profile"; $result1 = mysql_query($query1); while ($row = mysql_fetch_array($result1)) { if ($row['profileID'] == $_SESSION['SESS_LOGIN_ID']) { $Temp_ID = $row['profileID']; } } $query2 = "SELECT * from friends"; $result2 = mysql_query($query2); while ($row = mysql_fetch_array($result2)) { if ($row['User_ID_1'] == $Temp_ID) { $Temp_ID_2 = $row['User_ID_2']; $followsuccess = true; $message = "Your friend has made a post!"; $Friend_Request = false; //create new friend link if ($followsuccess) { $err_post = "Friended!"; $sql_newmessage = "INSERT INTO inbox (From_User_ID, To_User_ID, message, Is_FR)\n\t\t\t\tVALUES ('{$Temp_ID}', '{$Temp_ID_2}', '{$message}', '{$Friend_Request}')"; check_sql($sql_newmessage, $conn2); //header("location: index.php"); } header("Location:index.php"); } } }
$sql_loan = "SELECT * FROM loans, loanstatus WHERE loans.loanstatus_id = loanstatus.loanstatus_id AND cust_id = '{$_SESSION['cust_id']}'"; $query_loan = mysql_query($sql_loan); if (!$query_loan) { die('SELECT failed: ' . mysql_error()); } $color = 0; while ($row_loan = mysql_fetch_assoc($query_loan)) { //Select last unpaid Due Date from LTRANS $sql_ltrans = "SELECT MIN(ltrans_due) FROM ltrans, loans WHERE ltrans.loan_id = loans.loan_id AND loans.loanstatus_id = '2' AND loans.loan_id = '{$row_loan['loan_id']}' AND ltrans_due IS NOT NULL AND ltrans_date IS NULL"; $query_ltrans = mysql_query($sql_ltrans); check_sql($query_ltrans); $next_due = mysql_fetch_assoc($query_ltrans); //Select Loan Balance from LTRANS $sql_balance = "SELECT ltrans_principaldue, ltrans_interestdue, ltrans_principal, ltrans_interest FROM ltrans, loans WHERE ltrans.loan_id = loans.loan_id AND loans.loanstatus_id = '2' AND loans.loan_id = '{$row_loan['loan_id']}'"; $query_balance = mysql_query($sql_balance); check_sql($query_balance); $loan_balance = 0; $loan_paid = 0; while ($row_balance = mysql_fetch_assoc($query_balance)) { $loan_paid = $loan_paid + $row_balance['ltrans_principal'] + $row_balance['ltrans_interest']; $loan_balance = $loan_balance + $row_balance['ltrans_interestdue'] + $row_balance['ltrans_principaldue']; } $loan_balance = $loan_balance - $loan_paid; tr_colored($color); echo ' <td><a href="loan.php?lid=' . $row_loan['loan_id'] . '" class="sacco">' . $row_loan['loan_no'] . '</a></td> <td>' . $row_loan['loanstatus_status'] . '</td> <td>' . number_format($row_loan['loan_repaytotal']) . '</td> <td>' . number_format($loan_balance) . '</td>'; if ($row_loan['loanstatus_id'] == 2 and isset($next_due)) { echo '<td'; if ($next_due['MIN(ltrans_due)'] < time()) {
public function set() { //set the global variable global $db; //determine whether to update the dial string $sql = "select * from v_extensions "; $sql .= "where domain_uuid = '" . $this->domain_uuid . "' "; $sql .= "and extension_uuid = '" . $this->extension_uuid . "' "; $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) { $this->extension = $row["extension"]; $this->accountcode = $row["accountcode"]; $this->outbound_caller_id_name = $row["outbound_caller_id_name"]; $this->outbound_caller_id_number = $row["outbound_caller_id_number"]; } } //determine whether to update the dial string $sql = "select * from v_follow_me "; $sql .= "where domain_uuid = '" . $this->domain_uuid . "' "; $sql .= "and follow_me_uuid = '" . $this->follow_me_uuid . "' "; $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) { $follow_me_uuid = $row["follow_me_uuid"]; $this->cid_name_prefix = $row["cid_name_prefix"]; $this->cid_number_prefix = $row["cid_number_prefix"]; } } unset($prep_statement); //add follow me if (strlen($follow_me_uuid) == 0) { $this->add(); } //is follow me enabled if ($this->follow_me_enabled == "true") { //set the extension dial string $sql = "select * from v_follow_me_destinations "; $sql .= "where follow_me_uuid = '" . $this->follow_me_uuid . "' "; $sql .= "order by follow_me_order asc "; $prep_statement_2 = $db->prepare(check_sql($sql)); $prep_statement_2->execute(); $result = $prep_statement_2->fetchAll(PDO::FETCH_NAMED); $dial_string = "{fail_on_single_reject=USER_BUSY"; $dial_string .= ",instant_ringback=true"; $dial_string .= ",ignore_early_media=true"; $dial_string .= ",domain_uuid=" . $_SESSION['domain_uuid']; $dial_string .= ",sip_invite_domain=" . $_SESSION['domain_name']; $dial_string .= ",domain_name=" . $_SESSION['domain_name']; $dial_string .= ",domain=" . $_SESSION['domain_name']; $dial_string .= ",extension_uuid=" . $this->extension_uuid; $dial_string .= ",group_confirm_key=exec,group_confirm_file=lua confirm.lua"; $dial_string_caller_id_name = "\${caller_id_name}"; $dial_string_caller_id_number = "\${caller_id_number}"; if (strlen($this->follow_me_caller_id_uuid) > 0) { $sql_caller = "select destination_number, destination_description from v_destinations where domain_uuid = '{$this->domain_uuid}' and destination_type = 'inbound' and destination_uuid = '{$this->follow_me_caller_id_uuid}'"; $prep_statement_caller = $db->prepare($sql_caller); if ($prep_statement_caller) { $prep_statement_caller->execute(); $row_caller = $prep_statement_caller->fetch(PDO::FETCH_ASSOC); if (strlen($row_caller['destination_description']) > 0) { $dial_string_caller_id_name = $row_caller['destination_description']; } if (strlen($row_caller['destination_number']) > 0) { $dial_string_caller_id_number = $row_caller['destination_number']; } } } if (strlen($this->cid_name_prefix) > 0) { $dial_string .= ",origination_caller_id_name=" . $this->cid_name_prefix . "#{$dial_string_caller_id_name}"; } else { $dial_string .= ",origination_caller_id_name={$dial_string_caller_id_name}"; } if (strlen($this->cid_number_prefix) > 0) { //$dial_string .= ",origination_caller_id_number=".$this->cid_number_prefix.""; $dial_string .= ",origination_caller_id_number=" . $this->cid_number_prefix . "#dial_string_caller_id_number"; } else { $dial_string .= ",origination_caller_id_number={$dial_string_caller_id_number}"; } if (strlen($this->accountcode) > 0) { $dial_string .= ",sip_h_X-accountcode=" . $this->accountcode; $dial_string .= ",accountcode=" . $this->accountcode; } $dial_string .= "}"; $x = 0; foreach ($result as &$row) { if ($x > 0) { $dial_string .= ","; } if (extension_exists($row["follow_me_destination"])) { //set the dial string if (strlen($_SESSION['domain']['dial_string']['text']) == 0) { $dial_string .= "["; $dial_string .= "outbound_caller_id_number={$dial_string_caller_id_number},"; $dial_string .= "presence_id=" . $row["follow_me_destination"] . "@" . $_SESSION['domain_name'] . ","; if ($row["follow_me_prompt"] == "1") { $dial_string .= "group_confirm_key=exec,group_confirm_file=lua confirm.lua,confirm=true,"; } $dial_string .= "leg_delay_start=" . $row["follow_me_delay"] . ","; $dial_string .= "leg_timeout=" . $row["follow_me_timeout"] . "]"; $dial_string .= "\${sofia_contact(" . $row["follow_me_destination"] . "@" . $_SESSION['domain_name'] . ")}"; } else { $replace_value = $row["follow_me_destination"]; if ($row["follow_me_prompt"] == "1") { $replace_value .= "[group_confirm_key=exec,group_confirm_file=lua confirm.lua,confirm=true]"; } $local_dial_string = $_SESSION['domain']['dial_string']['text']; $local_dial_string = str_replace("\${dialed_user}", $replace_value, $local_dial_string); $local_dial_string = str_replace("\${dialed_domain}", $_SESSION['domain_name'], $local_dial_string); $local_dial_string = str_replace("\${call_timeout}", $row["follow_me_timeout"], $local_dial_string); $local_dial_string = str_replace("\${leg_timeout}", $row["follow_me_timeout"], $local_dial_string); $dial_string .= $local_dial_string; } } else { $dial_string .= "["; if ($_SESSION['cdr']['follow_me_fix']['boolean'] == "true") { $dial_string .= "outbound_caller_id_name=" . $this->outbound_caller_id_name; $dial_string .= ",outbound_caller_id_number=" . $this->outbound_caller_id_number; $dial_string .= ",origination_caller_id_name=" . $this->outbound_caller_id_name; $dial_string .= ",origination_caller_id_number=" . $this->outbound_caller_id_number; } else { $dial_string .= "outbound_caller_id_number={$dial_string_caller_id_number}"; } $dial_string .= ",presence_id=" . $this->extension . "@" . $_SESSION['domain_name']; if ($row["follow_me_prompt"] == "1") { $dial_string .= ",group_confirm_key=exec,group_confirm_file=lua confirm.lua,confirm=true,"; } $dial_string .= ",leg_delay_start=" . $row["follow_me_delay"]; $dial_string .= ",leg_timeout=" . $row["follow_me_timeout"] . "]"; if (is_numeric($row["follow_me_destination"])) { if ($_SESSION['domain']['bridge']['text'] == "outbound" || $_SESSION['domain']['bridge']['text'] == "bridge") { $bridge = outbound_route_to_bridge($_SESSION['domain_uuid'], $row["follow_me_destination"]); $dial_string .= $bridge[0] . ","; } elseif ($_SESSION['domain']['bridge']['text'] == "loopback") { $dial_string .= "loopback/" . $row["follow_me_destination"] . "/" . $_SESSION['domain_name']; } elseif ($_SESSION['domain']['bridge']['text'] == "lcr") { $dial_string .= "lcr/" . $_SESSION['lcr']['profile']['text'] . "/" . $_SESSION['domain_name'] . "/" . $row["follow_me_destination"]; } else { $dial_string .= "loopback/" . $row["follow_me_destination"] . "/" . $_SESSION['domain_name']; } } else { $dial_string .= $row["follow_me_destination"]; } } $x++; } $this->dial_string = $dial_string; } else { $this->dial_string = ''; } $sql = "update v_follow_me set "; $sql .= "dial_string = '" . $this->dial_string . "' "; $sql .= "where domain_uuid = '" . $this->domain_uuid . "' "; $sql .= "and follow_me_uuid = '" . $this->follow_me_uuid . "' "; if ($this->debug) { echo $sql . "<br />"; } $db->exec($sql); unset($sql); $sql = "update v_extensions set "; $sql .= "dial_string = '" . $this->dial_string . "', "; $sql .= "dial_domain = '" . $_SESSION['domain_name'] . "' "; $sql .= "where domain_uuid = '" . $this->domain_uuid . "' "; $sql .= "and follow_me_uuid = '" . $this->follow_me_uuid . "' "; if ($this->debug) { echo $sql . "<br />"; } $db->exec($sql); unset($sql); }
function set_country_vars($db, $x) { require "resources/countries.php"; //$country_iso=$_SESSION['domain']['country']['iso_code']; $sql = "select default_setting_value as value from v_default_settings "; $sql .= "where default_setting_name = 'iso_code' "; $sql .= "and default_setting_category = 'domain' "; $sql .= "and default_setting_subcategory = 'country' "; $sql .= "and default_setting_enabled = 'true';"; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (count($result) > 0) { $country_iso = $result[0]["value"]; } } unset($prep_statement, $sql, $result); if ($country_iso === NULL) { return; } if (isset($countries[$country_iso])) { $country = $countries[$country_iso]; // Set default Country ISO code $sql = "select count(*) as num_rows from v_vars "; $sql .= "where var_name = 'default_country' "; $sql .= "and var_cat = 'Defaults' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] == 0) { $sql = "insert into v_vars "; $sql .= "("; $sql .= "var_uuid, "; $sql .= "var_name, "; $sql .= "var_value, "; $sql .= "var_cat, "; $sql .= "var_enabled, "; $sql .= "var_order, "; $sql .= "var_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'default_country', "; $sql .= "'" . $country["isocode"] . "', "; $sql .= "'Defaults', "; $sql .= "'true', "; $sql .= "'" . $x . "', "; $sql .= "'' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql, $row); $x++; } } unset($prep_statement, $sql); // Set default Country code $sql = "select count(*) as num_rows from v_vars "; $sql .= "where var_name = 'default_countrycode' "; $sql .= "and var_cat = 'Defaults' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] == 0) { $sql = "insert into v_vars "; $sql .= "("; $sql .= "var_uuid, "; $sql .= "var_name, "; $sql .= "var_value, "; $sql .= "var_cat, "; $sql .= "var_enabled, "; $sql .= "var_order, "; $sql .= "var_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'default_countrycode', "; $sql .= "'" . $country["countrycode"] . "', "; $sql .= "'Defaults', "; $sql .= "'true', "; $sql .= "'" . $x . "', "; $sql .= "'' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql, $row); $x++; } } unset($prep_statement, $sql); // Set default International Direct Dialing code $sql = "select count(*) as num_rows from v_vars "; $sql .= "where var_name = 'default_exitcode' "; $sql .= "and var_cat = 'Defaults' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] == 0) { $sql = "insert into v_vars "; $sql .= "("; $sql .= "var_uuid, "; $sql .= "var_name, "; $sql .= "var_value, "; $sql .= "var_cat, "; $sql .= "var_enabled, "; $sql .= "var_order, "; $sql .= "var_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'default_exitcode', "; $sql .= "'" . $country["exitcode"] . "', "; $sql .= "'Defaults', "; $sql .= "'true', "; $sql .= "'" . $x . "', "; $sql .= "'' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql, $row); $x++; } } unset($prep_statement, $sql); unset($countries); } }
/** * save to the database */ public function save() { $this->fields(); $field_count = sizeof($this->fields); $sql = "insert into v_xml_cdr ("; $f = 1; if (isset($this->fields)) { foreach ($this->fields as $field) { if ($field_count == $f) { $sql .= "{$field} "; } else { $sql .= "{$field}, "; } $f++; } } $sql .= ")\n"; $sql .= "values \n"; $row_count = sizeof($this->array); //$field_count = sizeof($this->fields); $i = 0; if (isset($this->array)) { foreach ($this->array as $row) { $sql .= "("; $f = 1; if (isset($this->fields)) { foreach ($this->fields as $field) { if (isset($row[$field]) && strlen($row[$field]) > 0) { $sql .= "'" . $row[$field] . "'"; } else { $sql .= "null"; } if ($field_count != $f) { $sql .= ","; } $f++; } } $sql .= ")"; if ($row_count != $i) { $sql .= ",\n"; } $i++; } } if (substr($sql, -2) == ",\n") { $sql = substr($sql, 0, -2); } $this->db->exec(check_sql($sql)); unset($sql); }
function get_countries($db) { $sql = "select * from v_countries order by country asc"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); return $result_count > 0 ? $result : false; unset($prep_statement, $sql); }
function write() { //set default variables $dir_count = 0; $file_count = 0; $row_count = 0; $tmp_array = ''; $i = 0; //get the devices $sql = "select * from v_devices "; //$sql .= "where domain_uuid = '".$this->domain_uuid."' "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { //get the values from the database and set as variables $domain_uuid = $row["domain_uuid"]; $device_uuid = $row["device_uuid"]; $device_mac_address = $row["device_mac_address"]; $device_label = $row["device_label"]; $device_vendor = strtolower($row["device_vendor"]); $device_model = $row["device_model"]; $device_firmware_version = $row["device_firmware_version"]; $device_provision_enable = $row["device_provision_enable"]; $device_template = $row["device_template"]; $device_username = $row["device_username"]; $device_password = $row["device_password"]; $device_description = $row["device_description"]; //loop through the provision template directory clearstatcache(); $dir_list = ''; $file_list = ''; if (strlen($device_template) > 0) { $dir_list = opendir($this->template_dir . "/" . $device_template); $dir_array = array(); while (false !== ($file = readdir($dir_list))) { if ($file != "." and $file != "..") { $new_path = $dir . '/' . $file; $level = explode('/', $new_path); if (substr($new_path, -4) == ".svn") { //ignore .svn dir and subdir } elseif (substr($new_path, -3) == ".db") { //ignore .db files } else { $dir_array[] = $new_path; } if ($x > 1000) { break; } $x++; } } } //asort($dir_array); foreach ($dir_array as $new_path) { $level = explode('/', $new_path); if (is_dir($new_path)) { $dir_name = end($level); //$file_list .= "$dir_name\n"; //$dir_list .= recur_dir($new_path); } else { $file_name = end($level); //debug information //$file_size = round(filesize($new_path)/1024, 2); //echo $this->template_dir."/".$device_template."/".$file_name." $file_size\n"; //write the configuration to the directory if (strlen($_SESSION['switch']['provision']['dir']) > 0) { $dir_array = explode(";", $_SESSION['switch']['provision']['dir']); foreach ($dir_array as $directory) { if (file_exists($this->template_dir . "/" . $device_template . "/" . $file_name)) { //output template to string for header processing //output template to string for header processing $prov->domain_uuid = $domain_uuid; $this->mac = $device_mac_address; $this->file = $file_name; $file_contents = $this->render(); //replace {$mac} in the file name if ($device_vendor == "aastra" || $device_vendor == "cisco") { //upper case the mac address for aastra phones $file_name = str_replace("{\$mac}", strtoupper($device_mac_address), $file_name); } else { //all other phones $file_name = str_replace("{\$mac}", $device_mac_address, $file_name); } //write the file //echo $directory.'/'.$file_name."\n"; $fh = fopen($directory . '/' . $file_name, "w") or die("Unable to write to {$directory} for provisioning. Make sure the path exists and permissons are set correctly."); fwrite($fh, $file_contents); fclose($fh); } } unset($file_name); } } } //end for each closedir($dir_list); //echo "<hr size='1'>\n"; } unset($prep_statement); }
function restore() { //set the variables $db = $this->db; //delete the group permisisons $this->delete(); //get the $apps array from the installed apps from the core and mod directories $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); $x = 0; foreach ($config_list as &$config_path) { include $config_path; $x++; } //restore default permissions foreach ($apps as $row) { foreach ($row['permissions'] as $permission) { //set the variables if ($permission['groups']) { foreach ($permission['groups'] as $group) { //check group protection $sql = "select * from v_groups "; $sql .= "where group_name = '" . $group . "' "; $sql .= "and group_protected = 'true'"; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); unset($prep_statement); if (count($result) == 0) { //if the item uuid is not currently in the db then add it $sql = "select * from v_group_permissions "; $sql .= "where permission_name = '" . $permission['name'] . "' "; $sql .= "and group_name = '{$group}' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); unset($prep_statement); if (count($result) == 0) { //insert the default permissions into the database $sql = "insert into v_group_permissions "; $sql .= "("; $sql .= "group_permission_uuid, "; $sql .= "permission_name, "; $sql .= "group_name "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'" . $permission['name'] . "', "; $sql .= "'" . $group . "' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql); } // if count } // if prepared statement } // if count } // if prepared statement } // foreach group permission } // if permission } // foreach permission } // foreach app }
$prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $highestmenu_item_order = $row[menu_item_order]; } unset($prep_statement); if ($menu_item_order != $highestmenu_item_order) { //clear the menu session so it will rebuild with the update $_SESSION["menu"] = ""; //move the current item's order number up $sql = "update v_menu_items set "; $sql .= "menu_item_order = (menu_item_order-1) "; //move down $sql .= "where domain_uuid = '" . $domain_uuid . "' "; $sql .= "and menu_item_order = " . ($menu_item_order + 1) . " "; $db->exec(check_sql($sql)); unset($sql); //move the selected item's order number down $sql = "update v_menu_items set "; $sql .= "menu_item_order = (menu_item_order+1) "; //move up $sql .= "where domain_uuid = '" . $domain_uuid . "' "; $sql .= "and menu_item_id = '{$menu_item_id}' "; $db->exec(check_sql($sql)); unset($sql); } //redirect the user $_SESSION["message"] = $text['message-moved_down']; header("Location: menu_list.php?menu_item_id=" . $menu_item_id); return; }
public function create_config_lua() { //define the database connection as global global $db; //send progress $this->write_progress("\tCreating " . $this->config_lua); //set the directories $path = dirname($this->config_lua); $parent_dir = basename($path); if ($parent_dir == 'resources' and !file_exists($path)) { $this->write_progress("\t... creating missing '{$path}'"); if (!mkdir($path, 0755, true)) { throw new Exception("Failed to create the missing resources directory '{$path}'"); } } //get the odbc information $sql = "select count(*) as num_rows from v_databases "; $sql .= "where database_driver = 'odbc' "; if (strlen($order_by) > 0) { $sql .= "order by {$order_by} {$order} "; } $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'; } } //config.lua $fout = fopen($this->config_lua, "w"); if (!$fout) { throw new Exception("Failed to open '" . $this->config_lua . "' for writing"); } $tmp = "\n"; $tmp .= "--set the variables\n"; if (strlen($this->global_settings->switch_sounds_dir()) > 0) { $tmp .= normalize_path_to_os("\tsounds_dir = [[" . $this->global_settings->switch_sounds_dir() . "]];\n"); } if (strlen($this->global_settings->switch_phrases_vdir()) > 0) { $tmp .= normalize_path_to_os("\tphrases_dir = [[" . $this->global_settings->switch_phrases_vdir() . "]];\n"); } if (strlen($this->global_settings->switch_db_dir()) > 0) { $tmp .= normalize_path_to_os("\tdatabase_dir = [[" . $this->global_settings->switch_db_dir() . "]];\n"); } if (strlen($this->global_settings->switch_recordings_dir()) > 0) { $tmp .= normalize_path_to_os("\trecordings_dir = [[" . $this->global_settings->switch_recordings_dir() . "]];\n"); } if (strlen($this->global_settings->switch_storage_dir()) > 0) { $tmp .= normalize_path_to_os("\tstorage_dir = [[" . $this->global_settings->switch_storage_dir() . "]];\n"); } if (strlen($this->global_settings->switch_voicemail_vdir()) > 0) { $tmp .= normalize_path_to_os("\tvoicemail_dir = [[" . $this->global_settings->switch_voicemail_vdir() . "]];\n"); } if (strlen($this->global_settings->switch_script_dir()) > 0) { $tmp .= normalize_path_to_os("\tscripts_dir = [[" . $this->global_settings->switch_script_dir() . "]];\n"); } $tmp .= normalize_path_to_os("\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 .= normalize_path_to_os("\tdocument_root = [[" . $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "]];\n"); $tmp .= "\n"; if (strlen($this->global_settings->db_type()) > 0 || strlen($dsn_name) > 0) { $tmp .= "--database information\n"; $tmp .= "\tdatabase = {}\n"; $tmp .= "\tdatabase[\"type\"] = \"" . $this->global_settings->db_type() . "\";\n"; $tmp .= "\tdatabase[\"name\"] = \"" . $this->global_settings->db_name() . "\";\n"; $tmp .= normalize_path_to_os("\tdatabase[\"path\"] = [[" . $this->global_settings->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 ($this->global_settings->db_type() == "pgsql") { $db_host = $this->global_settings->db_host(); if ($db_host == 'localhost') { $db_host = '127.0.0.1'; } // lua cannot resolve localhost if (filter_var($db_host, FILTER_VALIDATE_IP)) { $host_type = "hostaddr"; } else { $host_type = "host"; } $tmp .= "\tdatabase[\"system\"] = \"pgsql://" . $host_type . "=" . $db_host . " port=" . $this->global_settings->db_port() . " dbname=" . $this->global_settings->db_name() . " user="******" password="******" options='' application_name='" . $this->global_settings->db_name() . "'\";\n"; $tmp .= "\tdatabase[\"switch\"] = \"pgsql://" . $host_type . "=" . $db_host . " port=" . $this->global_settings->db_port() . " dbname=freeswitch user="******" password="******" options='' application_name='freeswitch'\";\n"; } elseif ($this->global_settings->db_type() == "sqlite") { $tmp .= "\tdatabase[\"system\"] = \"sqlite://" . $this->global_settings->db_path() . "/" . $this->global_settings->db_name() . "\";\n"; $tmp .= "\tdatabase[\"switch\"] = \"sqlite://" . $_SESSION['switch']['db']['dir'] . "\";\n"; } elseif ($this->global_settings->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.conf\"] = \"3600\";\n"; $tmp .= "\texpire[\"acl.conf\"] = \"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 = " . $this->global_settings->domain_count() . ";\n"; $tmp .= normalize_path_to_os("\ttemp_dir = [[" . $this->global_settings->switch_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); }
echo "\t\t\t\t<span class='sql_controls' " . ($handler != 'sql' ? "style='display: none;'" : null) . ">"; //echo " ".$text['label-table']."<br />"; echo "\t\t\t\t\t<select name='table_name' id='table_name' class='formfld'>\n"; echo "\t\t\t\t\t\t<option value=''></option>\n"; switch ($db_type) { case 'sqlite': $sql = "select name from sqlite_master where type='table' order by name;"; break; case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and table_type='BASE TABLE' order by table_name"; break; case 'mysql': $sql = "show tables"; break; } $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $row = array_values($row); echo "\t\t\t\t\t<option value='" . $row[0] . "'>" . $row[0] . "</option>\n"; } echo "\t\t\t\t\t</select>\n"; //echo " <br /><br />\n"; //echo " ".$text['label-result_type']."<br />"; echo "\t\t\t\t\t<select name='sql_type' id='sql_type' class='formfld'>\n"; echo "\t\t\t\t\t\t<option value=''>" . $text['option-result_type_view'] . "</option>\n"; echo "\t\t\t\t\t\t<option value='csv'>" . $text['option-result_type_csv'] . "</option>\n"; echo "\t\t\t\t\t\t<option value='inserts'>" . $text['option-result_type_insert'] . "</option>\n"; echo "\t\t\t\t\t</select>\n"; echo "\t\t\t\t</span>";
public function message_download() { //check the message waiting status $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd .= "luarun app.lua voicemail mwi " . $this->voicemail_id . "@" . $_SESSION['domain_name']; $switch_result = event_socket_request($fp, 'api ' . $switch_cmd); } //change the message status $this->message_saved(); //clear the cache session_cache_limiter('public'); //set source folder path $path = $_SESSION['switch']['voicemail']['dir'] . '/default/' . $_SESSION['domain_name'] . '/' . $this->voicemail_id; //prepare base64 content from db, if enabled if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { $sql = "select message_base64 from "; $sql .= "v_voicemail_messages as m, "; $sql .= "v_voicemails as v "; $sql .= "where "; $sql .= "m.voicemail_uuid = v.voicemail_uuid "; $sql .= "and v.voicemail_id = '" . $this->voicemail_id . "' "; $sql .= "and m.voicemail_uuid = '" . $this->voicemail_uuid . "' "; $sql .= "and m.domain_uuid = '" . $this->domain_uuid . "' "; $sql .= "and m.voicemail_message_uuid = '" . $this->voicemail_message_uuid . "' "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (count($result) > 0) { foreach ($result as &$row) { if ($row['message_base64'] != '') { $message_decoded = base64_decode($row['message_base64']); file_put_contents($path . '/msg_' . $this->voicemail_message_uuid . '.ext', $message_decoded); $finfo = finfo_open(FILEINFO_MIME_TYPE); //determine mime type (requires PHP >= 5.3.0, must be manually enabled on Windows) $file_mime = finfo_file($finfo, $path . '/msg_' . $this->voicemail_message_uuid . '.ext'); finfo_close($finfo); switch ($file_mime) { case 'audio/x-wav': case 'audio/wav': $file_ext = 'wav'; break; case 'audio/mpeg': case 'audio/mp3': $file_ext = 'mp3'; break; } rename($path . '/msg_' . $this->voicemail_message_uuid . '.ext', $path . '/msg_' . $this->voicemail_message_uuid . '.' . $file_ext); } break; } } unset($sql, $prep_statement, $result, $message_decoded); } //prepare and stream the file if (file_exists($path . '/msg_' . $this->voicemail_message_uuid . '.wav')) { $file_path = $path . '/msg_' . $this->voicemail_message_uuid . '.wav'; } if (file_exists($path . '/msg_' . $this->voicemail_message_uuid . '.mp3')) { $file_path = $path . '/msg_' . $this->voicemail_message_uuid . '.mp3'; } if ($file_path != '') { $fd = fopen($file_path, "rb"); if ($_GET['t'] == "bin") { header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Description: File Transfer"); $file_ext = substr($file_path, -3); if ($file_ext == "wav") { header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.wav"'); } if ($file_ext == "mp3") { header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.mp3"'); } } else { $file_ext = substr($file_path, -3); if ($file_ext == "wav") { header("Content-Type: audio/wav"); } if ($file_ext == "mp3") { header("Content-Type: audio/mpeg"); } } header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past header("Content-Length: " . filesize($file_path)); ob_end_clean(); fpassthru($fd); } //if base64, remove temp file if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { @unlink($path . '/msg_' . $this->voicemail_message_uuid . '.' . $file_ext); } }