コード例 #1
0
 function send_im($user, $recipient, $message, $opt, &$errors)
 {
     global $config, $lang_set;
     $sip_msg = "MESSAGE\n" . addslashes($recipient) . "\n" . ".\n" . "From: " . $user->get_uri() . "\n" . "To: <" . addslashes($recipient) . ">\n" . "p-version: " . $config->psignature . "\n" . "Contact: <" . $config->web_contact . ">\n" . "Content-Type: text/plain; charset=" . $lang_set['charset'] . "\n.\n" . str_Replace("\n.\n", "\n. \n", $message) . "\n.\n\n";
     if ($config->use_rpc) {
         if (!$this->connect_to_xml_rpc(null, $errors)) {
             return false;
         }
         $params = array(new XML_RPC_Value($sip_msg, 'string'));
         $msg = new XML_RPC_Message('t_uac_dlg', $params);
         $res = $this->rpc->send($msg);
         if ($this->rpc_is_error($res)) {
             log_errors($res, $errors);
             return false;
         }
     } else {
         /* construct FIFO command */
         $fifo_cmd = ":t_uac_dlg:" . $config->reply_fifo_filename . "\n" . $sip_msg;
         if (false === write2fifo($fifo_cmd, $errors, $status)) {
             return false;
         }
         /* we accept any status code beginning with 2 as ok */
         if (substr($status, 0, 1) != "2") {
             $errors[] = $status;
             return false;
         }
     }
     return true;
 }
コード例 #2
0
 /**
  *	set charset for comunication with DB
  */
 function set_db_charset($charset, $opt, &$errors)
 {
     global $config;
     $this->db_charset = $charset;
     /* if connection to db is estabilished run sql query setting the charset */
     if ($this->db) {
         if ($this->db_host['parsed']['phptype'] == 'mysql') {
             $charset_mapping = array('utf-8' => 'utf8', 'iso-8859-1' => 'latin1', 'iso-8859-2' => 'latin2', 'windows-1250' => 'cp1250', 'iso-8859-7' => 'greek', 'iso-8859-8' => 'hebrew', 'iso-8859-9' => 'latin5', 'iso-8859-13' => 'latin7', 'windows-1251' => 'cp1251');
         } else {
             $charset_mapping = array('utf-8' => 'utf8', 'iso-8859-1' => 'latin1', 'iso-8859-2' => 'latin2', 'iso-8859-3' => 'latin3', 'iso-8859-4' => 'latin4', 'iso-8859-5' => 'ISO_8859_5', 'iso-8859-6' => 'ISO_8859_6', 'iso-8859-7' => 'ISO_8859_7', 'iso-8859-8' => 'ISO_8859_8', 'iso-8859-9' => 'latin5', 'iso-8859-10' => 'latin6', 'iso-8859-13' => 'latin7', 'iso-8859-14' => 'latin8', 'iso-8859-15' => 'latin9', 'iso-8859-16' => 'latin10', 'windows-1250' => 'win1250', 'windows-1251' => 'win1251');
         }
         if (strtolower($charset) == 'default') {
             $q = "set NAMES DEFAULT";
         } else {
             $ch = isset($charset_mapping[$this->db_charset]) ? $charset_mapping[$this->db_charset] : $this->db_charset;
             $q = "set NAMES '" . $ch . "'";
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             return false;
         }
     }
     /* otherwise do nothing, charset will be set after connect to DB */
     return true;
 }
コード例 #3
0
 function get_VM($user, $mid, &$errors)
 {
     global $config, $lang_str;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select subject, file from " . $config->data_sql->table_voice_silo . " where mid=" . $mid . " and " . $this->get_indexing_sql_where_phrase_uri($user);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     if (!$res->numRows()) {
         $errors[] = $lang_str['err_voice_msg_not_found'];
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
     $res->free();
     @($fp = fopen($config->voice_silo_dir . $row->file, 'r'));
     if (!$fp) {
         $errors[] = $lang_str['err_can_not_open_message'];
         return false;
     }
     Header("Content-Disposition: attachment;filename=" . RawURLEncode(($row->subject ? $row->subject : "received message") . ".wav"));
     Header("Content-type: audio/wav");
     @fpassthru($fp);
     @fclose($fp);
     return true;
 }
コード例 #4
0
 /**
  *	set password for user
  */
 function set_password_to_user($user, $passwd, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->credentials->table_name;
     /* col names */
     $c =& $config->data_sql->credentials->cols;
     /* flags */
     $f =& $config->data_sql->credentials->flag_values;
     $ha1 = md5($user->get_username() . ":" . $user->get_realm() . ":" . $passwd);
     $ha1b = md5($user->get_username() . "@" . $user->get_realm() . ":" . $user->get_realm() . ":" . $passwd);
     if (!$config->clear_text_pw) {
         $passwd = "";
     }
     $q = "update " . $t_name . " \n\t\t    set " . $c->password . " = " . $this->sql_format($passwd, "s") . ", \n\t\t\t    " . $c->ha1 . "      = " . $this->sql_format($ha1, "s") . ", \n\t\t\t\t" . $c->ha1b . "     = " . $this->sql_format($ha1b, "s") . "\n\t\t\twhere " . $c->uid . "   = " . $this->sql_format($user->get_uid(), "s") . " and\n\t\t\t      " . $c->uname . " = " . $this->sql_format($user->get_username(), "s") . " and\n\t\t\t\t  " . $c->realm . " = " . $this->sql_format($user->get_realm(), "s");
     if ($config->auth['use_did']) {
         $q .= " and " . $c->did . " = " . $this->sql_format($user->get_did(), "s");
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #5
0
 /**
  *  return new id for a domain
  *
  *  Possible options:
  *	 none
  *      
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return int				new id or FALSE on error
  */
 function get_new_domain_id($opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     $ta_name =& $config->data_sql->domain_attrs->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     $ca =& $config->data_sql->domain_attrs->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $fa =& $config->data_sql->domain_attrs->flag_values;
     $q = "select max(" . $this->get_sql_cast_to_int_funct($cd->did) . ")\n\t\t    from " . $td_name . "\n\t\t\twhere " . $this->get_sql_regex_match("^[0-9]+\$", $cd->did, null);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     $row1 = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     $q = "select max(" . $this->get_sql_cast_to_int_funct($ca->did) . ")\n\t\t    from " . $ta_name . "\n\t\t\twhere " . $this->get_sql_regex_match("^[0-9]+\$", $ca->did, null);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     $row2 = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     return max($row1[0], $row2[0]) + 1;
 }
コード例 #6
0
 function del_VM($user, $mid, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select file from " . $config->data_sql->table_voice_silo . " where mid=" . $mid . " and " . $this->get_indexing_sql_where_phrase_uri($user);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     if (!$res->numRows()) {
         $errors[] = "Message not found or you haven't access to message";
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
     $res->free();
     @($unl = unlink($config->voice_silo_dir . $row->file));
     if (!$unl and file_exists($config->voice_silo_dir . $row->file)) {
         $errors[] = "Error when deleting message";
         return false;
     }
     $q = "delete from " . $config->data_sql->table_voice_silo . " where mid=" . $mid . " and " . $this->get_indexing_sql_where_phrase_uri($user);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #7
0
 function get_VMs($user, &$errors)
 {
     global $config, $sess;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select mid, src_addr, inc_time, subject, file from " . $config->data_sql->table_voice_silo . " where " . $this->get_indexing_sql_where_phrase_uri($user);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_OBJECT); $i++) {
         if (date('Y-m-d', $row->inc_time) == date('Y-m-d')) {
             $time = "today " . date('H:i', $row->inc_time);
         } else {
             $time = date('Y-m-d H:i', $row->inc_time);
         }
         $out[$i]['subject'] = $row->subject;
         $out[$i]['src_addr'] = htmlspecialchars($row->src_addr);
         $out[$i]['time'] = $time;
         $out[$i]['url_reply'] = $sess->url("send_im.php?kvrk=" . uniqid("") . "&sip_addr=" . rawURLEncode($row->src_addr));
         $out[$i]['url_get'] = $sess->url("ms_get_v_msg.php?kvrk=" . uniqid("") . "&mid=" . rawURLEncode($row->mid));
         $out[$i]['url_dele'] = $sess->url("message_store.php?kvrk=" . uniqid("") . "&dele_vm=" . rawURLEncode($row->mid));
     }
     $res->free();
     return $out;
 }
コード例 #8
0
 /**
  *  check if admin have permissions to change user's setting
  *
  *  Possible options parameters:
  *	 - none
  *
  *	@param object $admin		admin - instance of class Auth
  *	@param object $user			admin - instance of class SerwebUser
  *	@param array $opt			associative array of options
  *	@return bool				TRUE on permit, FALSE on forbid, -1 on failure
  */
 function check_admin_perms_to_user(&$admin, &$user, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return -1;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     if (false === ($adm_domains = $admin->get_administrated_domains())) {
         return -1;
     }
     $uid = $user->get_uid();
     $q = "select count(*) \n\t\t      from " . $t_name . "\n\t\t\t  where " . $c->uid . " = " . $this->sql_format($uid, "s") . " and \n\t\t\t        " . $this->get_sql_in($c->did, $adm_domains, true) . " and \n\t\t\t\t\t" . $c->flags . " & " . $f['DB_DELETED'] . " = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return -1;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     return $row[0] ? true : false;
 }
コード例 #9
0
 /**
  *	delete contact from USRLOC
  *
  *	@param string $uid		UID of the owner of the contact
  *	@param string $contact	contact which should be removed
  *	@param array $errors	
  *	@return bool			TRUE on success, FALSE on failure
  */
 function del_contact($uid, $contact, &$errors)
 {
     global $config;
     if ($config->use_rpc) {
         if (!$this->connect_to_xml_rpc(null, $errors)) {
             return false;
         }
         $params = array(new XML_RPC_Value($config->ul_table, 'string'), new XML_RPC_Value($uid, 'string'), new XML_RPC_Value($contact, 'string'));
         $msg = new XML_RPC_Message('usrloc.delete_contact', $params);
         $res = $this->rpc->send($msg);
         if ($this->rpc_is_error($res)) {
             log_errors($res, $errors);
             return false;
         }
         return true;
     } else {
         /* construct FIFO command */
         $fifo_cmd = ":usrloc.delete_contact:" . $config->reply_fifo_filename . "\n" . $config->ul_table . "\n" . $uid . "\n" . $contact . "\n\n";
         //contact
         $message = write2fifo($fifo_cmd, $errors, $status);
         if ($errors) {
             return false;
         }
         /* we accept any 2xx as ok */
         if (substr($status, 0, 1) != "2") {
             $errors[] = $status;
             return false;
         }
     }
     return true;
 }
コード例 #10
0
 /**
  *  return array (indexed by customer ID) of customers
  *
  *  Keys of associative arrays:
  *    id	-	id of customer
  *    name	-	name of customer
  *    address  
  *    email
  *    phone
  *
  *  Possible options:
  *
  *    exclude	(string)	default: null
  *      exclude customer with this id from result
  *      
  *    single    (string)    default: null  
  *      return only customer with this id
  *      
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return array			array of customers or FALSE on error
  */
 function get_customers($opt, &$errors)
 {
     global $config, $sess;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $tc_name =& $config->data_sql->customers->table_name;
     /* col names */
     $cc =& $config->data_sql->customers->cols;
     $o_exclude = isset($opt['exclude']) ? $opt['exclude'] : null;
     $o_single = isset($opt['single']) ? $opt['single'] : null;
     $o_order_by = (isset($opt['order_by']) and isset($cc->{$opt}['order_by'])) ? $cc->{$opt}['order_by'] : "";
     $o_order_desc = !empty($opt['order_desc']) ? "desc" : "";
     if (!is_null($o_single)) {
         $qw = " where " . $cc->cid . "  = " . $this->sql_format($o_single, "n") . " ";
     } elseif (!is_null($o_exclude)) {
         $qw = " where " . $cc->cid . " != " . $this->sql_format($o_exclude, "n") . " ";
     } else {
         $qw = "";
     }
     if (is_null($o_single)) {
         /* get num rows */
         $q = "select count(*) from " . $tc_name . $qw;
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             return false;
         }
         $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
         $this->set_num_rows($row[0]);
         $res->free();
     } else {
         $this->set_num_rows(1);
     }
     /* if act_row is bigger then num_rows, correct it */
     $this->correct_act_row();
     $q = "select " . $cc->cid . ", " . $cc->name . ", " . $cc->phone . ", " . $cc->address . ", " . $cc->email . " \n\t\t    from " . $tc_name . $qw;
     if ($o_order_by) {
         $q .= " order by " . $o_order_by . " " . $o_order_desc;
     }
     $q .= $this->get_sql_limit_phrase();
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[$row[$cc->cid]]['cid'] = $row[$cc->cid];
         $out[$row[$cc->cid]]['name'] = $row[$cc->name];
         $out[$row[$cc->cid]]['phone'] = $row[$cc->phone];
         $out[$row[$cc->cid]]['address'] = $row[$cc->address];
         $out[$row[$cc->cid]]['email'] = $row[$cc->email];
         $out[$row[$cc->cid]]['primary_key'] = array('cid' => &$out[$row[$cc->cid]]['cid']);
     }
     $res->free();
     return $out;
 }
コード例 #11
0
 /**
  *  update customer table by $values
  *
  *  Keys of associative array $values:
  *    name
  *    address
  *    email
  *    phone
  *
  *  Possible options:
  *
  *    primary_key	(array) required
  *      contain primary key of record which should be updated
  *      The array contain the same keys as functon get_customers returned in entry 'primary_key'
  *
  *    insert  	(bool) default:true
  *      if true, function insert new record, otherwise update old record
  *
  *	  new_id	(bool)
  *		In this option is returned ID of new created customer. 
  *		Option is created only if 'insert'=true
  *
  *	@param array $values	values
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return bool			TRUE on success, FALSE on failure
  */
 function update_customer($values, &$opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $tc_name =& $config->data_sql->customers->table_name;
     /* col names */
     $cc =& $config->data_sql->customers->cols;
     $opt_insert = isset($opt['insert']) ? (bool) $opt['insert'] : false;
     if (!$opt_insert and (!isset($opt['primary_key']) or !is_array($opt['primary_key']) or empty($opt['primary_key']))) {
         log_errors(PEAR::raiseError('primary key is missing'), $errors);
         return false;
     }
     if ($opt_insert) {
         $sem = new Shm_Semaphore(__FILE__, "s", 1, 0600);
         /* set semaphore to be sure there will not be generated same id for two customers */
         if (!$sem->acquire()) {
             return false;
         }
         $q = "select max(" . $cc->cid . ") from " . $tc_name;
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             $sem->release();
             return false;
         }
         $next_id = 1;
         if ($row = $res->fetchRow(DB_FETCHMODE_ORDERED)) {
             if (!is_null($row[0])) {
                 $next_id = $row[0] + 1;
             }
         }
         $q = "insert into " . $tc_name . " (\n\t\t\t\t\t   " . $cc->cid . ", " . $cc->name . ", " . $cc->address . ", " . $cc->email . ", " . $cc->phone . "\n\t\t\t    ) \n\t\t\t\tvalues (\n\t\t\t\t\t   " . $this->sql_format($next_id, "n") . ", \n\t\t\t\t\t   " . $this->sql_format($values['name'], "s") . ", \n\t\t\t\t\t   " . $this->sql_format($values['address'], "s") . ", \n\t\t\t\t\t   " . $this->sql_format($values['email'], "s") . ", \n\t\t\t\t\t   " . $this->sql_format($values['phone'], "s") . "\n\t\t\t\t )";
         $opt['new_id'] = $next_id;
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             $sem->release();
             return false;
         }
         $sem->release();
     } else {
         $q = "update " . $tc_name . " \n\t\t\t    set " . $cc->name . "   =" . $this->sql_format($values['name'], "s") . ",  \n\t\t\t        " . $cc->address . "=" . $this->sql_format($values['address'], "s") . ", \n\t\t\t        " . $cc->email . "  =" . $this->sql_format($values['email'], "s") . ", \n\t\t\t        " . $cc->phone . "  =" . $this->sql_format($values['phone'], "s") . "\n\t\t\t\twhere " . $cc->cid . "  =" . $this->sql_format($opt['primary_key']['cid'], "n");
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             return false;
         }
     }
     return true;
 }
コード例 #12
0
function logDebugMessages($message, $show = false)
{
    log_errors($message);
    if (!$show) {
        ob_start();
    }
    print '<br>Information log: <hr><pre>';
    debug_print_backtrace();
    print '</pre>';
    if (!$show) {
        log_errors(ob_get_clean());
    }
}
コード例 #13
0
 function del_phonebook_entry($user, $pbid, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "delete from " . $config->data_sql->table_phonebook . " \n\t\t    where " . $this->get_indexing_sql_where_phrase($user) . " and \n\t\t\t      id=" . $this->sql_format($pbid, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #14
0
 function store_greeting($user, $greeting_file, &$errors)
 {
     global $config;
     if ($config->users_indexed_by == 'uuid') {
         if (!copy($greeting_file, $config->greetings_spool_dir . $user->get_uid() . ".wav")) {
             log_errors(PEAR::raiseError("store greeting failed"), $errors);
             return false;
         }
     } else {
         if (!copy($greeting_file, $config->greetings_spool_dir . $user->get_domainname() . "/" . $user->get_username() . ".wav")) {
             log_errors(PEAR::raiseError("store greeting failed"), $errors);
             return false;
         }
     }
     return true;
 }
コード例 #15
0
 /**
  * set collation - for MySQL >= 4.1
  */
 function set_db_collation($collation, $opt, &$errors)
 {
     global $config;
     $this->db_collation = $collation;
     /* if connection to db is estabilished run sql query setting the collation */
     if ($this->db) {
         $q = "set collation_connection='" . $this->db_collation . "'";
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             return false;
         }
     }
     /* otherwise do nothing, collation will be set after connect to DB */
     return true;
 }
コード例 #16
0
 function del_whitelist_entry($user, $opt, &$errors)
 {
     global $config, $lang_str;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     if (!isset($opt['primary_key']) or !is_array($opt['primary_key']) or empty($opt['primary_key'])) {
         log_errors(PEAR::raiseError('primary key is missing'), $errors);
         return false;
     }
     $q = "delete from " . $config->data_sql->table_whitelist . " \n\t\t\twhere uri=" . $this->sql_format($opt['primary_key']['uri'], "s") . " and \n\t\t\t\t  " . $this->get_indexing_sql_where_phrase($user);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #17
0
 /**
  *  Get values of global attributes
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *
  *	@return array
  */
 function get_global_attrs($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->global_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->global_attrs->cols;
     /* flags */
     $f =& $config->data_sql->global_attrs->flag_values;
     $out = array();
     $errors = array();
     /*
      *	get global_attrs
      */
     $flags_val = $f['DB_FOR_SERWEB'];
     $q = "select " . $c->name . " as name,\n\t\t           " . $c->value . " as value \n\t\t    from " . $t_name . "\n\t\t\twhere (" . $c->flags . " & " . $flags_val . ") = " . $flags_val;
     if (isset($c->order)) {
         $q .= " order by " . $c->name . ", " . $c->order;
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         ErrorHandler::add_error($errors);
         return false;
     }
     $ats =& Attr_types::singleton();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         if (false === ($at =& $ats->get_attr_type($row['name']))) {
             return false;
         }
         if (is_object($at) and $at->is_multivalue()) {
             $out[$row['name']][] = $row['value'];
         } else {
             $out[$row['name']] = $row['value'];
         }
     }
     $res->free();
     return $out;
 }
コード例 #18
0
 function add_whitelist_entry($user, $values, $opt, &$errors)
 {
     global $config, $lang_str;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $att = $this->get_indexing_sql_insert_attribs($user);
     $q = "insert into " . $config->data_sql->table_whitelist . " (\n\t\t           " . $att['attributes'] . ", \n\t\t\t\t   uri\n\t\t    ) \n\t\t\tvalues (\n\t\t\t       " . $att['values'] . ", \n\t\t\t\t   " . $this->sql_format($values['uri'], "s") . "\n\t\t\t )";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_ALREADY_EXISTS) {
             $errors[] = $lang_str['err_whitelist_already_exists'];
         } else {
             log_errors($res, $errors);
         }
         return false;
     }
     return true;
 }
コード例 #19
0
 function get_user_name_from_phonebook($user, $sip_uri, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select fname, lname \n\t\t    from " . $config->data_sql->table_phonebook . " \n\t\t    where sip_uri=" . $this->sql_format($sip_uri, "s") . " and \n\t\t\t      " . $this->get_indexing_sql_where_phrase($user);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     if ($res->numRows() == 0) {
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
     $res->free();
     return implode(' ', array($row->fname, $row->lname));
 }
コード例 #20
0
 function update_phonebook_entry($user, $pbid, $fname, $lname, $sip_uri, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     if ($pbid) {
         $q = "update " . $config->data_sql->table_phonebook . " \n\t\t\t    set fname   = " . $this->sql_format($fname, "s") . ", \n\t\t\t\t    lname   = " . $this->sql_format($lname, "s") . ", \n\t\t\t\t\tsip_uri = " . $this->sql_format($sip_uri, "s") . " \n\t\t\t\twhere id=" . $this->sql_format($pbid, "n") . " and \n\t\t\t       " . $this->get_indexing_sql_where_phrase($user);
     } else {
         $att = $this->get_indexing_sql_insert_attribs($user);
         $q = "insert into " . $config->data_sql->table_phonebook . " \n\t\t\t\t\t(fname, lname, sip_uri, " . $att['attributes'] . ") \n\t\t\t\tvalues (" . $this->sql_format($fname, "s") . ", \n\t\t\t\t        " . $this->sql_format($lname, "s") . ", \n\t\t\t\t\t\t" . $this->sql_format($sip_uri, "s") . ", \n\t\t\t\t\t\t" . $att['values'] . ")";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #21
0
 function remove_greeting($user, &$errors)
 {
     global $config, $lang_str;
     if ($config->users_indexed_by == 'uuid') {
         $filename = $config->greetings_spool_dir . $user->get_uid() . ".wav";
     } else {
         $filename = $config->greetings_spool_dir . $user->get_domainname() . "/" . $user->get_username() . ".wav";
     }
     if (!file_exists($filename)) {
         /* nothing to remove */
         return true;
     }
     if (unlink($filename)) {
         return true;
     } else {
         log_errors(PEAR::raiseError("remove greeting failed"), $errors);
         return false;
     }
 }
コード例 #22
0
 function get_phonebook_entry($user, $pbid, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select fname, lname, sip_uri \n\t\t    from " . $config->data_sql->table_phonebook . " \n\t\t\twhere " . $this->get_indexing_sql_where_phrase($user) . " and \n\t\t\t       id=" . $this->sql_format($pbid, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
     $res->free();
     $out = array();
     $out['fname'] = $row->fname;
     $out['lname'] = $row->lname;
     $out['sip_uri'] = $row->sip_uri;
     return $out;
 }
コード例 #23
0
 function get_whitelist($user, $opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select uri from " . $config->data_sql->table_whitelist . " where " . $this->get_indexing_sql_where_phrase($user) . " order by uri";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i] = $row;
         $out[$i]['primary_key'] = array('uri' => &$out[$i]['uri']);
     }
     $res->free();
     return $out;
 }
コード例 #24
0
 /**
  *  Delete customer 
  *
  *  Possible options parameters:
  *    primary_key	(array) required
  *      contain primary key of record which should be deleted
  *      The array contain the same keys as functon get_customers returned in entry 'primary_key'
  *
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return bool			TRUE on success, FALSE on failure
  */
 function delete_customer($opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $tc_name =& $config->data_sql->customers->table_name;
     /* col names */
     $cc =& $config->data_sql->customers->cols;
     if (!isset($opt['primary_key']) or !is_array($opt['primary_key']) or empty($opt['primary_key'])) {
         log_errors(PEAR::raiseError('primary key is missing'), $errors);
         return false;
     }
     $q = "delete from " . $tc_name . " \n\t\t\twhere " . $cc->cid . "=" . $this->sql_format($opt['primary_key']['cid'], "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #25
0
 function delete_user_vsilo($user, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     if ($config->users_indexed_by == 'uuid') {
         $q = "delete from " . $config->data_sql->table_voice_silo . " where uuid='" . $user->uuid . "'";
     } else {
         $q = "delete from " . $config->data_sql->table_voice_silo . " where r_uri like 'sip:" . $user->uname . "@" . $user->domain . "%'";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             log_errors($res, $errors);
             return false;
         }
     }
     return true;
 }
コード例 #26
0
 function play_greeting($user, &$errors)
 {
     global $config, $lang_str;
     if ($config->users_indexed_by == 'uuid') {
         @($fp = fopen($config->greetings_spool_dir . $user->get_uid() . ".wav", 'rb'));
     } else {
         @($fp = fopen($config->greetings_spool_dir . $user->get_domainname() . "/" . $user->get_username() . ".wav", 'rb'));
     }
     if (!$fp) {
         //try open default greeting
         @($fp = fopen($config->greetings_spool_dir . "default.wav", 'rb'));
         if (!$fp) {
             log_errors(PEAR::raiseError($lang_str['err_can_not_open_greeting']), $errors);
             return false;
         }
     }
     Header("Content-Disposition: attachment;filename=" . RawURLEncode("greeting.wav"));
     Header("Content-type: audio/wav");
     @fpassthru($fp);
     @fclose($fp);
     return true;
 }
コード例 #27
0
 /**
  *  Function mark all acc records of $user as deleted
  *
  *  Possible options parameters:
  *	 - timestamp (int) - if timestamp is set, is deleted only records 
  *	                     older than timestamp (default: none)
  *	 - del_incoming	 (bool) - delete incoming calls (default: true)
  *	 - del_outgoing	 (bool) - delete outgoing calls (default: true)
  *
  */
 function delete_user_acc($uid, $opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $t_acc =& $config->data_sql->acc->table_name;
     /* flags */
     $f_acc =& $config->data_sql->acc->flag_values;
     $opt_timestamp = isset($opt['timestamp']) ? $opt['timestamp'] : null;
     $opt_del_incoming = isset($opt['del_incoming']) ? $opt['del_incoming'] : true;
     $opt_del_outgoing = isset($opt['del_outgoing']) ? $opt['del_outgoing'] : true;
     if ($opt_del_outgoing) {
         $q = "update " . $t_acc . "\n\t\t\t    set flags = ( flags | " . $f_acc['DB_CALLER_DELETED'] . " )\n\t\t\t\twhere from_uid='" . $uid . "'";
         if (!is_null($opt_timestamp)) {
             $q .= " and request_timestamp < '" . gmdate("Y-m-d H:i:s", $opt_timestamp) . "'";
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             return false;
         }
     }
     if ($opt_del_incoming) {
         $q = "update " . $t_acc . "\n\t\t\t    set flags = ( flags | " . $f_acc['DB_CALLEE_DELETED'] . " )\n\t\t\t\twhere to_uid='" . $uid . "'";
         if (!is_null($opt_timestamp)) {
             $q .= " and request_timestamp < '" . gmdate("Y-m-d H:i:s", $opt_timestamp) . "'";
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             log_errors($res, $errors);
             return false;
         }
     }
     return true;
 }
コード例 #28
0
 /**
  *	add new domain alias
  *
  *  Keys of associative array $values:
  *    id
  *    name
  *      
  *  Possible options parameters:
  *	
  *	  set_canon	(bool)	default: false
  *		set domain alias canonical
  *
  *	@param array $values	values
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return bool			TRUE on success, FALSE on failure
  */
 function add_domain_alias($values, $opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $ca =& $config->attr_names;
     $opt['set_canon'] = empty($opt['set_canon']) ? false : true;
     $opt['disabled'] = empty($opt['disabled']) ? false : true;
     $global_attrs =& Global_Attrs::singleton();
     if (false === ($flags = $global_attrs->get_attribute($ca['domain_default_flags']))) {
         return false;
     }
     if (!is_numeric($flags)) {
         ErrorHandler::log_errors(PEAR::raiseError("Attribute '" . $ca['domain_default_flags'] . "' is not defined or is not a number"));
         return false;
     }
     if ($opt['set_canon']) {
         $flags = $flags | $fd['DB_CANON'];
     }
     if ($opt['disabled']) {
         $flags = $flags | $fd['DB_DISABLED'];
     }
     $q = "insert into " . $td_name . " (\n\t\t\t\t   " . $cd->did . ",\n\t\t\t\t   " . $cd->name . ",\n\t\t\t\t   " . $cd->flags . "\n\t\t    ) \n\t\t\tvalues (\n\t\t\t\t   " . $this->sql_format($values['id'], "s") . ", \n\t\t\t\t   " . $this->sql_format($values['name'], "s") . ",\n\t\t\t\t   " . $this->sql_format($flags, "n") . "\n\t\t\t )";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #29
0
 /**
  *  Delete domain
  *
  *  Possible options:
  *
  *    did		(int)   	default: null
  *      id of domain which will be deleted
  *      either id or name is required
  *      
  *    name		(string)	default: null
  *      name of domain which will be deleted
  *      either id or name is required
  *      
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return bool			TRUE on success, FALSE on failure
  */
 function del_domain_alias($opt, &$errors)
 {
     global $config;
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $o_did = isset($opt['did']) ? $opt['did'] : null;
     $o_name = isset($opt['name']) ? $opt['name'] : null;
     if (is_null($o_did) and is_null($o_name)) {
         log_errors(PEAR::raiseError('domain for delete is not specified'), $errors);
         return false;
     }
     $qw = "";
     if ($o_did) {
         $qw .= $cd->did . "= " . $this->sql_format($o_did, "s");
     }
     if ($qw and $o_name) {
         $qw .= " and ";
     }
     if ($o_name) {
         $qw .= $cd->name . "= " . $this->sql_format($o_name, "s");
     }
     $q = "delete from " . $td_name . "\n\t\t\twhere " . $qw;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         log_errors($res, $errors);
         return false;
     }
     return true;
 }
コード例 #30
0
ファイル: super.php プロジェクト: BackupTheBerlios/sipums
  function get_users($domain){
    global $config,$log;
    switch($this->container_type){
    case 'sql':
       /* get num rows */		
       /* get users */
      if ($domain) { 
          $where = " WHERE domain = '$domain' "; 
      } 
      $q="select s.username,s.domain, s.first_name, s.last_name, s.phone, s.email_address, s.perm FROM ".$config->data_sql->table_subscriber." s ". 
         " $where order by s.domain,s.username ";

      $log->log("q -= $q");

	
             $res=$this->db->query($q);
             if (DB::isError($res)) {
               log_errors($res, $errors); 
               return false;
             }
             $out=array();
             while ($row=$res->fetchRow(DB_FETCHMODE_OBJECT)){
                $name=$row->last_name;
                if ($name) $name.=" "; 
                $name.=$row->first_name;
                $row->name=$name;
                $row->permission=$name;
	        $out[]=$row;
              }
              $res->free();
		
              return $out;
       case 'ldap':
         die('NOT IMPLEMENTED: '.__FILE__.":".__LINE__);
     }
  }