コード例 #1
0
 /**
  *	get all versions of file specific for domain
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param string $file		filename (with path)
  *	@param array $opt		associative array of options
  *	@return array			array of versions of file or FALSE on failure
  */
 function get_file_versions($did, $file, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     /* flags */
     $fd =& $config->data_sql->domain_settings->flag_values;
     $q = "select " . $cd->version . ", " . $cd->timestamp . ", " . $cd->flags . " \n\t\t      from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t        " . $cd->filename . " = " . $this->sql_format($file, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[$row[$cd->version]]['timestamp'] = $row[$cd->timestamp];
         $out[$row[$cd->version]]['deleted'] = (bool) ($row[$cd->flags] & $fd["DB_DELETED"]);
         $out[$row[$cd->version]]['dir'] = (bool) ($row[$cd->flags] & $fd["DB_DIR"]);
     }
     $res->free();
     return $out;
 }
コード例 #2
0
 /**
  * return list of all attributes without atribute named as $att_edit
  * $att_edit may be null
  */
 function get_attr_type_groups($opt = null)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_at =& $config->data_sql->attr_types->table_name;
     /* col names */
     $c =& $config->data_sql->attr_types->cols;
     $q = "select " . $c->group . "\n\t\t    from " . $t_at . " \n\t\t\tgroup by " . $c->group;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[] = $row[$c->group];
     }
     $res->free();
     return $out;
 }
コード例 #3
0
 /**
  *	get content of file specific for a domain from db
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param string $file		filename (with path)
  *	@param string $version	version of file
  *	@param array $opt		associative array of options
  *	@return string			content of file or FALSE on failure
  */
 function get_file_content($did, $file, $version, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     $q = "select " . $cd->content . " \n\t\t      from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t        " . $cd->filename . " = " . $this->sql_format($file, "s") . " and\n\t\t\t        " . $cd->version . " = " . $this->sql_format($version, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = null;
     if ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out = $this->sql_unescape_binary($row[$cd->content]);
     }
     $res->free();
     return $out;
 }
コード例 #4
0
 function check_credentials($uname, $did, $realm, $passw, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_ldap($errors)) {
         ErrorHandler::add_error($errors);
         return 0;
     }
     $a =& $config->auth_ldap['attrib'];
     $q = array("(" . $a['user'] . "=" . addslashes($user . '@' . $domain) . ") ", 'base_dn' => $config->auth_ldap['dn'], 'attributes' => array($a['uuid'], $a['pass']), 'action' => 'list');
     $res = $this->ldap->query($q);
     if (DB::isError($res)) {
         //if user is not found
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return -1;
         } else {
             ErrorHandler::log_errors($res);
             return 0;
         }
     }
     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
     $res->free();
     // check password
     if ($row[$a['pass']] != $passw) {
         return -1;
     }
     return $row[$a['uuid']];
 }
コード例 #5
0
 /**
  * delete all missed calls of user
  * if $timestamp is not null delete only calls older than $timestamp
  */
 function delete_user_missed_calls($uid, $timestamp)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_mc =& $config->data_sql->missed_calls->table_name;
     /* flags */
     $f_mc =& $config->data_sql->missed_calls->flag_values;
     $q = "delete from " . $t_mc . " \n\t\t\twhere to_uid='" . $uid . "'";
     if (!is_null($timestamp)) {
         $q .= " and request_timestamp < '" . gmdate("Y-m-d H:i:s", $timestamp) . "'";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
コード例 #6
0
 /**
  *  Delete credentials from DB
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *	
  *
  *	@return bool
  */
 function del_credentials($uid, $did, $uname, $realm, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($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;
     $q = "delete from " . $t_name . "\n\t\t      where " . $c->uid . "   = " . $this->sql_format($uid, "s") . " and\n\t\t            " . $c->uname . " = " . $this->sql_format($uname, "s") . " and\n\t\t            " . $c->realm . " = " . $this->sql_format($realm, "s");
     if ($config->auth['use_did']) {
         $q .= " and " . $c->did . " = " . $this->sql_format($did, "s");
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #7
0
 /**
  *  Purge old acc records
  *
  *  Possible options parameters:
  *		none
  *
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function delete_acc($opt)
 {
     global $config;
     if (!$config->keep_acc_interval) {
         return true;
     }
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return 0;
     }
     /* table's name */
     $t_name =& $config->data_sql->acc->table_name;
     /* col names */
     $c =& $config->data_sql->acc->cols;
     /* flags */
     $f =& $config->data_sql->acc->flag_values;
     if ($this->db_host['parsed']['phptype'] == 'mysql') {
         $q = "delete from " . $t_name . " \n\t\t\t\twhere DATE_ADD(" . $c->request_timestamp . ", INTERVAL " . $config->keep_acc_interval . " DAY) < now()";
     } else {
         $q = "delete from " . $t_name . " \n\t\t\t\twhere (" . $c->request_timestamp . " + INTERVAL '" . $config->keep_acc_interval . " DAY') < now()";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         //expect that table mayn't exist in installed version
         if ($res->getCode() != DB_ERROR_NOSUCHTABLE) {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
コード例 #8
0
 /**
  *	delete all user's records from user_attrs
  */
 function delete_user_attrs($uid)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->user_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->user_attrs->cols;
     /* flags */
     $f =& $config->data_sql->user_attrs->flag_values;
     $q = "delete from " . $t_name . " \n\t\t      where " . $c->uid . "  = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     return true;
 }
コード例 #9
0
 /**
  *	delete alias of user
  *
  *	@param string	$uid		owner of the contact 
  *	@param string	$username	username part from URI
  *	@param string	$did		domain part from URI
  *	@param string	$flags		flags of the URI
  *	@param array	$opt		various options
  *	@return bool				TRUE on success, FALSE on failure
  */
 function delete_uri($uid, $scheme, $username, $did, $flags, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* 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;
     $q = "delete from " . $t_name . "\n\t\t      where " . $c->uid . "      = " . $this->sql_format($uid, "s") . " and \n\t\t            " . $c->scheme . "   = " . $this->sql_format($scheme, "s") . " and \n\t\t            " . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t            " . $c->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t            " . $c->flags . "    = " . $this->sql_format($flags, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     if (isModuleLoaded('xxl')) {
         // get domain: $alias_d = domainname of $did
         $alias_uri = "sip:" . $username . "@" . $alias_d;
         if (false === $this->clear_proxy_xxl($alias_uri, null, $errors)) {
             ErrorHandler::add_error($errors);
             return false;
         }
     }
     return true;
 }
コード例 #10
0
 function get_missed_calls_of_yesterday($uid, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     if ($this->db_host['parsed']['phptype'] == 'mysql') {
         $q_date = " date_format(request_timestamp, '%Y-%m-%d')=date_format(DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d') ";
     } else {
         $q_date = " date_trunc('day', request_timestamp)=date_trunc('day', (CURRENT_DATE - INTERVAL '1 DAY')) ";
     }
     $q = "SELECT from_uri, sip_from, request_timestamp, sip_status  " . "FROM " . $config->data_sql->table_missed_calls . " " . "WHERE to_uid='" . $uid . "' and " . $q_date . "ORDER BY request_timestamp DESC ";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $out[] = $row;
     }
     $res->free();
     return $out;
 }
コード例 #11
0
 /**
  *  Get array of aliases of user with given sip-uri
  *
  *  Possible options:
  *		none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	array				FALSE on error
  */
 function get_aliases_by_uri($sip_uri, $opt)
 {
     global $config;
     $errors = array();
     /* create connection to proxy where are stored data of user */
     if (isModuleLoaded('xxl') and $this->name != "get_aliases_tmp") {
         $tmp_data = CData_Layer::singleton("get_aliases_tmp", $errors);
         $tmp_data->set_xxl_user_id($sip_uri);
         $tmp_data->expect_user_id_may_not_exists();
         return $tmp_data->get_aliases_by_uri($sip_uri, $errors);
     }
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tu_name =& $config->data_sql->uri->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     //parse username and domain from sip uri
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return array();
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return array();
         }
     } else {
         $did = $config->default_did;
     }
     $flags_val = $fu['DB_DISABLED'] | $fu['DB_DELETED'];
     $q = "select " . $cu->uid . " as uid\n\t\t    from " . $tu_name . "\n\t\t\twhere  " . $cu->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t\t       " . $cu->username . " = " . $this->sql_format($uname, "s") . " and \n\t\t\t\t  (" . $cu->flags . " & " . $flags_val . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
     if (!$row) {
         unset($res);
         return array();
     }
     $uid = $row['uid'];
     if (is_null($uid)) {
         return array();
     }
     $uri_handler =& URIs::singleton($uid);
     if (false === ($out = $uri_handler->get_URIs())) {
         return false;
     }
     return $out;
 }
コード例 #12
0
 /**
  *  return array of credentials of user
  *
  *  Possible options:
  *	 - none
  *    	
  *	@param	string	$uid	uid of user
  *	@param	array	$opt	array of options
  *	@return array			array of credentials
  */
 function get_credentials($uid, $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->credentials->table_name;
     /* col names */
     $c =& $config->data_sql->credentials->cols;
     /* flags */
     $f =& $config->data_sql->credentials->flag_values;
     $q = "select " . $c->did . ", \n\t\t           " . $c->uname . ",\n\t\t           " . $c->realm . ",\n\t\t           " . $c->password . ",\n\t\t           " . $c->ha1 . ",\n\t\t           " . $c->ha1b . ",\n\t\t           " . $c->flags . "\n\t\t    from " . $t_name . " \n\t\t\twhere " . $c->uid . " = " . $this->sql_format($uid, "s") . " and\n\t\t\t      " . $c->flags . " & " . $f['DB_DELETED'] . " = 0\n\t\t\torder by " . $c->realm . ", " . $c->uname;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i] = new Credential($uid, $row[$c->did], $row[$c->uname], $row[$c->realm], $row[$c->password], $row[$c->ha1], $row[$c->ha1b], $row[$c->flags]);
     }
     $res->free();
     return $out;
 }
コード例 #13
0
 /**
  *  return array of domain ids which can administer given user
  *
  *
  *  Possible options:
  *	 - none
  *      
  *	@param string $uid		
  *	@param array $opt		associative array of options
  *	@return array			array of domain ids or FALSE on error
  */
 function get_domains_of_admin($uid, $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->domain_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->domain_attrs->cols;
     /* flags */
     $f =& $config->data_sql->domain_attrs->flag_values;
     $an =& $config->attr_names;
     $q = "select " . $c->did . " \n\t\t    from " . $t_name . "\n\t\t\twhere  " . $c->name . "  = '" . $an['admin'] . "' and \n\t\t\t       " . $c->value . " = " . $this->sql_format($uid, "s") . " and \n\t\t\t      (" . $c->flags . " & " . $f['DB_DELETED'] . ") = 0 and\n\t\t\t\t  (" . $c->flags . " & " . $f['DB_FOR_SERWEB'] . ") = " . $f['DB_FOR_SERWEB'];
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i] = $row[$c->did];
     }
     $res->free();
     return $out;
 }
コード例 #14
0
 /**
  *  return new id for a user
  *
  *  Possible options:
  *	 - none
  *      
  *	@param array $opt		associative array of options
  *	@return int				new id or FALSE on error
  */
 function get_new_user_id($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tc_name =& $config->data_sql->credentials->table_name;
     $ta_name =& $config->data_sql->user_attrs->table_name;
     /* col names */
     $cc =& $config->data_sql->credentials->cols;
     $ca =& $config->data_sql->user_attrs->cols;
     /* flags */
     $fc =& $config->data_sql->credentials->flag_values;
     $fa =& $config->data_sql->user_attrs->flag_values;
     $q = "select max(" . $this->get_sql_cast_to_int_funct($cc->uid) . ")\n\t\t    from " . $tc_name . "\n\t\t\twhere " . $this->get_sql_regex_match("^[0-9]+\$", $cc->uid, null);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row1 = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     $q = "select max(" . $this->get_sql_cast_to_int_funct($ca->uid) . ")\n\t\t    from " . $ta_name . "\n\t\t\twhere " . $this->get_sql_regex_match("^[0-9]+\$", $ca->uid, null);
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row2 = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $res->free();
     return max($row1[0], $row2[0]) + 1;
 }
コード例 #15
0
 /**
  *  return flags of domain with given domain ID as associative array
  *
  *  Keys of associative arrays:
  *   - disabled
  *   - deleted
  *
  *  Possible options:
  *	 - none
  *
  *	@param string $did		domain ID
  *	@param array $opt		associative array of options
  *	@return array			domain flags or FALSE on error
  */
 function get_domain_flags($did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($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;
     $q = "select " . $cd->flags . "\n\t\t    from " . $td_name . "\n\t\t\twhere " . $cd->did . "=" . $this->sql_format($did, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $disabled = true;
     $deleted = true;
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $disabled = ($disabled and $row[$cd->flags] & $fd['DB_DISABLED']);
         $deleted = ($deleted and $row[$cd->flags] & $fd['DB_DELETED']);
     }
     $res->free();
     return array('disabled' => $disabled, 'deleted' => $deleted);
 }
コード例 #16
0
 /**
  *  Enable or disable domain
  *
  *  Possible options:
  *
  *    did		(int)   	default: null
  *      id of domain which will be en/disabled
  *      this option is REQUIRED
  *      
  *    disable	(bool)  	default: false
  *      if true domain will be disabled, otherwise wil be enabled
  *      
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function enable_domain($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($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_disable = isset($opt['disable']) ? $opt['disable'] : false;
     if (is_null($o_did)) {
         ErrorHandler::log_errors(PEAR::raiseError('domain for en/disable is not specified'));
         return false;
     }
     $q = "update " . $td_name . " set ";
     if ($o_disable) {
         $q .= $cd->flags . " = " . $cd->flags . " | " . $fd['DB_DISABLED'];
     } else {
         $q .= $cd->flags . " = " . $cd->flags . " & ~" . $fd['DB_DISABLED'];
     }
     $q .= " where " . $cd->did . " = " . $this->sql_format($o_did, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #17
0
 /**
  *  reload domains table of SER from DB
  *
  *  Possible options parameters:
  *	 none
  *
  *	@param array $opt		associative array of options
  *	@param array $errors	error messages
  *	@return bool			TRUE on success, FALSE on failure
  */
 function reload_domains($opt, &$errors)
 {
     global $config;
     $ga_h =& Global_Attrs::singleton();
     /* get current timestamp on DB server */
     if (false === ($now = $this->get_DB_time(null))) {
         return false;
     }
     /* update attribute holding timestamp of last data change */
     if (false === $ga_h->set_attribute($config->attr_names['domain_data_version'], $now)) {
         return false;
     }
     /* If notifing of sip proxies to reload the data is disabled, 
      * finish here
      */
     if (empty($config->domain_reload_ser_notify)) {
         return true;
     }
     /* If SER does not caches domain table, the reload is not needed
      * (and also is not possible) */
     if (empty($config->ser_domain_cache)) {
         return true;
     }
     if ($config->use_rpc) {
         //			if (!$this->connect_to_xml_rpc(null, $errors)) return false;
         $params = array();
         $msg = new XML_RPC_Message('domain.reload', $params);
         $res = $this->rpc_send_to_all($msg, array('break_on_error' => false));
         if (!$res->ok) {
             $cache_varning = false;
             foreach ($res->results as $v) {
                 if (PEAR::isError($v)) {
                     ErrorHandler::log_errors($v);
                     if ($v->getCode() == 400) {
                         $cache_varning = true;
                     }
                 }
             }
             if ($cache_varning) {
                 sw_log("Domain reload failed. May be the domain cache in SER is disabled. " . "Try either enable the cache by set modparam(\"domain\", \"db_mode\", 1) " . "in your ser.cfg or disable reloading domains in serweb by setting " . "\$config->ser_domain_cache = false in config_data_layer.php", PEAR_LOG_ERR);
             }
             return false;
         }
         return true;
     } else {
         /* construct FIFO command */
         $fifo_cmd = ":domain_reload:" . $config->reply_fifo_filename . "\n";
         $message = write2fifo($fifo_cmd, $errors, $status);
         if ($errors) {
             return false;
         }
         if (substr($status, 0, 1) != "2") {
             $errors[] = $status;
             return false;
         }
     }
     return true;
 }
コード例 #18
0
 /**
  *  Update URI table
  *
  *  Possible options:
  *	 - none
  *	
  *	@param	array	$values
  *	@param	array	$filter
  *	@param	array	$opt
  *	@return bool			FALSE on error, TRUE otherwise
  */
 function update_uri($values, $filter, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* 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;
     $an =& $config->attr_names;
     $qw = "";
     if (isset($filter['scheme'])) {
         $qw .= $c->scheme . "   = " . $this->sql_format($filter['scheme'], "s") . " and ";
     }
     if (isset($filter['uid'])) {
         $qw .= $c->uid . "      = " . $this->sql_format($filter['uid'], "s") . " and ";
     }
     if (isset($filter['did'])) {
         $qw .= $c->did . "      = " . $this->sql_format($filter['did'], "s") . " and ";
     }
     if (isset($filter['username'])) {
         $qw .= $c->username . " = " . $this->sql_format($filter['username'], "s") . " and ";
     }
     if (isset($filter['flags'])) {
         $qw .= $c->flags . "    = " . $this->sql_format($filter['flags'], "s") . " and ";
     }
     $qw .= $this->get_sql_bool(true);
     $qs = array();
     if (isset($values['scheme'])) {
         $qs[] = $c->scheme . "   = " . $this->sql_format($values['scheme'], "s");
     }
     if (isset($values['uid'])) {
         $qs[] = $c->uid . "      = " . $this->sql_format($values['uid'], "s");
     }
     if (isset($values['did'])) {
         $qs[] = $c->did . "      = " . $this->sql_format($values['did'], "s");
     }
     if (isset($values['username'])) {
         $qs[] = $c->username . " = " . $this->sql_format($values['username'], "s");
     }
     if (isset($values['flags'])) {
         $qs[] = $c->flags . "    = " . $this->sql_format($values['flags'], "n");
     }
     $qs = implode(", ", $qs);
     $q = "update " . $t_name . " \n\t\t      set " . $qs . "\n\t\t      where " . $qw;
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #19
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;
 }
コード例 #20
0
 /**
  *  Delete credentials from DB
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string		$uid
  *	@param	string		$did
  *	@param	string		$uname
  *	@param	string		$realm
  *	@param	Credential	$new_vals
  *	@param	array		$opt
  *	@return bool
  */
 function update_credentials($uid, $did, $uname, $realm, $new_vals, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($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;
     $set = array();
     if ($new_vals->did_changed()) {
         $set[] = $c->did . " = " . $this->sql_format($new_vals->get_did(), "s");
     }
     if ($new_vals->uname_changed()) {
         $set[] = $c->uname . " = " . $this->sql_format($new_vals->get_uname(), "s");
     }
     if ($new_vals->realm_changed()) {
         $set[] = $c->realm . " = " . $this->sql_format($new_vals->get_realm(), "s");
     }
     if ($new_vals->password_changed()) {
         if ($config->clear_text_pw) {
             $set[] = $c->password . " = " . $this->sql_format($new_vals->get_password(), "s");
         } else {
             $set[] = $c->password . " = " . $this->sql_format("", "s");
         }
     }
     if ($new_vals->ha1_changed()) {
         $set[] = $c->ha1 . " = " . $this->sql_format($new_vals->get_ha1(), "s");
         $set[] = $c->ha1b . " = " . $this->sql_format($new_vals->get_ha1b(), "s");
     }
     if ($new_vals->flags_changed()) {
         $set[] = $c->flags . " = " . $this->sql_format($new_vals->get_flags(), "s");
     }
     if (!count($set)) {
         return true;
     }
     // nothing to change
     $q = "update " . $t_name . "\n\t\t\t  set\t" . implode(", ", $set) . "\n\t\t      where " . $c->uid . "   = " . $this->sql_format($uid, "s") . " and\n\t\t            " . $c->uname . " = " . $this->sql_format($uname, "s") . " and\n\t\t            " . $c->realm . " = " . $this->sql_format($realm, "s");
     if ($config->auth['use_did']) {
         $q .= " and " . $c->did . " = " . $this->sql_format($did, "s");
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #21
0
 function get_IMs($uid)
 {
     global $config, $sess;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     $t_name =& $config->data_sql->msg_silo->table_name;
     /* table's name */
     $c =& $config->data_sql->msg_silo->cols;
     /* col names */
     /* get num rows */
     $q = "select count(*) from " . $t_name . "\n\t\t    where " . $c->uid . " = " . $this->sql_format($uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
     $this->set_num_rows($row[0]);
     $res->free();
     /* if act_row is bigger then num_rows, correct it */
     $this->correct_act_row();
     $q = "select " . $c->mid . ", " . $c->from . ", " . $c->inc_time . ", " . $c->body . " \n\t\t    from " . $t_name . " where " . $c->uid . " = " . $this->sql_format($uid, "s") . $this->get_sql_limit_phrase();
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $timestamp = gmmktime(substr($row[$c->inc_time], 11, 2), substr($row[$c->inc_time], 14, 2), substr($row[$c->inc_time], 17, 2), substr($row[$c->inc_time], 5, 2), substr($row[$c->inc_time], 8, 2), substr($row[$c->inc_time], 0, 4));
         //year
         if (date('Y-m-d', $timestamp) == date('Y-m-d')) {
             $time = "today " . date('H:i', $timestamp);
         } else {
             $time = date('Y-m-d H:i', $timestamp);
         }
         $out[$i]['src_addr'] = htmlspecialchars($row[$c->from]);
         $out[$i]['raw_src_addr'] = $row[$c->from];
         $out[$i]['mid'] = $row[$c->mid];
         $out[$i]['time'] = $time;
         $out[$i]['timestamp'] = $timestamp;
         $out[$i]['body'] = $row[$c->body];
         $out[$i]['url_reply'] = $sess->url("send_im.php?kvrk=" . uniqid("") . "&sip_addr=" . rawURLEncode($row[$c->from]));
         $out[$i]['url_dele'] = $sess->url("message_store.php?kvrk=" . uniqid("") . "&dele_im=" . rawURLEncode($row[$c->mid]));
     }
     $res->free();
     return $out;
 }
コード例 #22
0
 /**
  *  return array of associtive arrays containig domain names
  *
  *  Keys of associative arrays:
  *   - id
  *   - name
  *
  *  Possible options:
  *	 - order_by	(string) - name of column for sorting. If false or empty, 
  *	                       result is not sorted (default: 'name')
  *	 - order_desc (bool) - order descending (default: false)
  *	 - filter    (array) - associative array of pairs (column, value) which 
  *	                       should be returned (default: array)
  *	 - check_deleted_flag (bool) - If true, domains marked as deleted 
  *	                               are not returned (default:true)
  *
  *	@param array $opt		associative array of options
  *	@return array			array of domain names or FALSE on error
  */
 function get_domain($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($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_filter = isset($opt['filter']) ? $opt['filter'] : array();
     $o_order_by = isset($opt['order_by']) ? $opt['order_by'] : "name";
     $o_order_desc = isset($opt['order_desc']) ? "desc" : "";
     $o_check_deleted = isset($opt['check_deleted_flag']) ? $opt['check_deleted_flag'] : true;
     $qw = $this->sql_format(true, "b");
     foreach ($o_filter as $k => $v) {
         $qw .= " and " . $cd->{$k} . " = " . $this->sql_format($v, "s");
     }
     $q_deleted = "";
     if ($o_check_deleted) {
         $q_deleted = " and (" . $cd->flags . " & " . $fd['DB_DELETED'] . ") = 0 ";
     }
     $q = "select " . $cd->did . ", \n\t\t           " . $cd->name . ", \n\t\t\t       " . $cd->flags . " & " . $fd['DB_DISABLED'] . " as disabled,\n\t\t\t       " . $cd->flags . " & " . $fd['DB_CANON'] . " as canon\n\t\t    from " . $td_name . "\n\t\t\twhere " . $qw . $q_deleted;
     if ($o_order_by) {
         if (isset($cd->{$o_order_by})) {
             $q .= " order by " . $cd->{$o_order_by} . " " . $o_order_desc;
         } else {
             $q .= " order by " . $o_order_by . " " . $o_order_desc;
         }
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i]['did'] = $row[$cd->did];
         $out[$i]['name'] = $row[$cd->name];
         $out[$i]['disabled'] = $row['disabled'];
         $out[$i]['canon'] = $row['canon'];
         $out[$i]['primary_key'] = array('did' => &$out[$i]['did'], 'name' => &$out[$i]['name']);
     }
     $res->free();
     return $out;
 }
コード例 #23
0
 /**
  *  Function return IDs of domains marked as deleted
  *
  *
  *  Possible options parameters:
  *
  *	  deleted_before (int)	default:null
  *		if is set, only domains marked as deleted before given timestamp are returned
  *  
  *	@return array	array of domain IDs or FALSE on error
  */
 function get_deleted_domains($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $ta_name =& $config->data_sql->domain_attrs->table_name;
     $td_name =& $config->data_sql->domain->table_name;
     /* col names */
     $ca =& $config->data_sql->domain_attrs->cols;
     $cd =& $config->data_sql->domain->cols;
     /* flags */
     $fa =& $config->data_sql->domain_attrs->flag_values;
     $fd =& $config->data_sql->domain->flag_values;
     $an =& $config->attr_names;
     $opt_deleted_before = isset($opt['deleted_before']) ? $opt['deleted_before'] : null;
     $q1_w = $q2_w = "";
     if (!is_null($opt_deleted_before)) {
         /* get users deleted before given timestamp */
         $o = array("name" => $an['deleted_ts']);
         if (false === ($attrs = $this->get_attr_by_val('domain', $o))) {
             return false;
         }
         $dids = array();
         foreach ($attrs as $v) {
             if ((int) $v['value'] < (int) $opt_deleted_before) {
                 $dids[] = $v['id'];
             }
         }
         $q1_w = " and " . $this->get_sql_in("dom." . $cd->did, $dids, true);
         $q2_w = " and " . $this->get_sql_in("at." . $ca->did, $dids, true);
     }
     $q1 = "select dom." . $cd->did . " as did\n\t\t\t  from " . $td_name . " dom \n\t\t\t  where (dom." . $cd->flags . " & " . $fd['DB_DELETED'] . ") = " . $fd['DB_DELETED'] . $q1_w . " \n\t\t\t  group by dom." . $cd->did;
     $q2 = "select at." . $ca->did . " as did\n\t\t\t  from " . $ta_name . " at \n\t\t\t  where (at." . $ca->flags . " & " . $fa['DB_DELETED'] . ") = " . $fa['DB_DELETED'] . $q2_w . " \n\t\t\t  group by at." . $ca->did;
     $q = "(" . $q1 . ") union (" . $q2 . ")";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[] = $row['did'];
     }
     $res->free();
     return $out;
 }
コード例 #24
0
 /**
  *	get latest versions of files specific for domain
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param array $opt		associative array of options
  *	@return array			array of versions of file or FALSE on failure
  */
 function get_latest_file_versions($did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     /* flags */
     $fd =& $config->data_sql->domain_settings->flag_values;
     /* 
     	clean solution but unfortunately not working in mysql 4.0
     	
     			$q = "select ds.".$cd->filename.", ds.".$cd->version." as ver, ds.".$cd->flags." 
     			      from ".$td_name." ds join (
     				      select ".$cd->filename.", max(".$cd->version.") as ver
     				      from ".$td_name."
     				      where ".$cd->did." = ".$this->sql_format($did, "s")."
     				      group by ".$cd->filename."
     				  ) v on (ds.".$cd->filename." = v.".$cd->filename." and
     				          ds.".$cd->version." = v.ver)
     				  where ds.".$cd->did." = ".$this->sql_format($did, "s")." 
     				  group by ds.".$cd->filename;
     */
     /* This query return multiple rows for each file. Ordering row by 
     		   version is important because older versions are replaced by newest
     		   in output array.
     		 */
     $q = "select " . $cd->filename . ", " . $cd->flags . ", max(" . $cd->version . ") as ver \n\t\t      from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " \n\t\t\t  group by " . $cd->filename . ", " . $cd->flags . "\n\t\t\t  order by ver";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $out[$row[$cd->filename]]['version'] = $row['ver'];
         $out[$row[$cd->filename]]['deleted'] = (bool) ($row[$cd->flags] & $fd["DB_DELETED"]);
         $out[$row[$cd->filename]]['dir'] = (bool) ($row[$cd->flags] & $fd["DB_DIR"]);
     }
     $res->free();
     return $out;
 }
コード例 #25
0
 /**
  *	delete all records of user from speed_dial table
  */
 function delete_user_speed_dial($uid)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $t_name =& $config->data_sql->speed_dial->table_name;
     $ta_name =& $config->data_sql->sd_attrs->table_name;
     /* col names */
     $c =& $config->data_sql->speed_dial->cols;
     $ca =& $config->data_sql->sd_attrs->cols;
     $q = "select " . $c->id . " as id from " . $t_name . " where " . $c->uid . " = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             return true;
         } else {
             ErrorHandler::log_errors($res);
             return false;
         }
     }
     $ids = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $ids[] = $row['id'];
     }
     if (count($ids)) {
         $q = "delete from " . $ta_name . " where " . $this->get_sql_in($ca->id, $ids);
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             if ($res->getCode() == DB_ERROR_NOSUCHTABLE) {
             } else {
                 ErrorHandler::log_errors($res);
                 return false;
             }
         }
     }
     $q = "delete from " . $t_name . " where " . $c->uid . " = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #26
0
 /**
  *  reload domains table of SER from DB
  *
  *  Possible options parameters:
  *   none
  *
  *  @param array $opt       associative array of options
  *  @param array $errors    error messages
  *  @return bool            TRUE on success, FALSE on failure
  */
 function reload_global_attrs($opt, &$errors)
 {
     global $config;
     $ga_h =& Global_Attrs::singleton();
     /* get current timestamp on DB server */
     if (false === ($now = $this->get_DB_time(null))) {
         return false;
     }
     /* update attribute holding timestamp of last data change */
     if (false === $ga_h->set_attribute($config->attr_names['gattr_timestamp'], $now)) {
         return false;
     }
     /* If notifing of sip proxies to reload the data is disabled, 
      * finish here
      */
     if (empty($config->g_attrs_reload_ser_notify)) {
         return true;
     }
     if ($config->use_rpc) {
         //          if (!$this->connect_to_xml_rpc(null, $errors)) return false;
         $params = array();
         $msg = new XML_RPC_Message('gflags.reload', $params);
         $res = $this->rpc_send_to_all($msg, array('break_on_error' => false));
         if (!$res->ok) {
             foreach ($res->results as $v) {
                 if (PEAR::isError($v)) {
                     ErrorHandler::log_errors($v);
                 }
             }
             return false;
         }
         return true;
     } else {
         /* construct FIFO command */
         $fifo_cmd = ":gflags.reload:" . $config->reply_fifo_filename . "\n";
         $message = write2fifo($fifo_cmd, $errors, $status);
         if ($errors) {
             return false;
         }
         if (substr($status, 0, 1) != "2") {
             $errors[] = $status;
             return false;
         }
     }
     return true;
 }
コード例 #27
0
 /**
  *  Get array of uids asociated with given uri
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	array				FALSE on error
  */
 function get_uid_of_uri($sip_uri, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tu_name =& $config->data_sql->uri->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     //parse username and domain from sip uri
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return array();
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return array();
         }
     } else {
         $did = $config->default_did;
     }
     $flags_val = $fu['DB_DISABLED'] | $fu['DB_DELETED'];
     $q = "select " . $cu->uid . " as uid,\n\t\t           " . $cu->flags . " as flags\n\t\t    from " . $tu_name . "\n\t\t\twhere  " . $cu->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t\t       " . $cu->username . " = " . $this->sql_format($uname, "s") . " and \n\t\t\t\t  (" . $cu->flags . " & " . $flags_val . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i]['uid'] = $row['uid'];
         $out[$i]['is_to'] = (bool) ($row['flags'] & $fu['DB_IS_TO']);
         $out[$i]['is_from'] = (bool) ($row['flags'] & $fu['DB_IS_FROM']);
     }
     return $out;
 }
コード例 #28
0
 /**
  *  Add new URI to DB
  *
  *	On error this method returning FALSE.
  *
  *  Possible options:
  *	 - disabled	(bool) - set flag disabled (default: false)
  *	 - canon	(bool) - set flag canonical (default: false)
  *	 - flags	(int)  - Set value of flags directly. If is set, options 
  *	                     'canon' and 'disabled' are ignored. (default: null)
  *
  *	@return bool
  */
 function add_uri($uid, $scheme, $uname, $did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* 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;
     $an =& $config->attr_names;
     /* set default values for options */
     $opt_disabled = isset($opt["disabled"]) ? (bool) $opt["disabled"] : false;
     $opt_canon = isset($opt["canon"]) ? (bool) $opt["canon"] : false;
     $opt_flags = isset($opt["flags"]) ? $opt["flags"] : null;
     if (!is_null($opt_flags)) {
         $flags = $opt_flags;
     } else {
         $ga =& Global_attrs::singleton();
         if (false === ($flags = $ga->get_attribute($an['uri_default_flags']))) {
             return false;
         }
         if (!is_numeric($flags)) {
             ErrorHandler::log_errors(PEAR::raiseError("Global attribute '" . $an['uri_default_flags'] . "' is not defined or is not a number Can't create URI."));
             return false;
         }
         if ($opt_disabled) {
             $flags = $flags | $f['DB_DISABLED'];
         }
         if ($opt_canon) {
             $flags = $flags | $f['DB_CANON'];
         }
     }
     $q = "insert into " . $t_name . "(\n\t             " . $c->uid . ", " . $c->scheme . ", " . $c->username . ", " . $c->did . ", " . $c->flags . ")\n\t\t      values (" . $this->sql_format($uid, "s") . ", \n\t\t\t          " . $this->sql_format($scheme, "s") . ", \n\t\t\t          " . $this->sql_format($uname, "s") . ", \n\t\t\t\t\t  " . $this->sql_format($did, "s") . ", \n\t\t\t\t\t  " . $this->sql_format($flags, "n") . ")";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #29
0
 /**
  *  Update attribute type group
  *
  *  On error this method returning FALSE.
  *
  *  Possible options:
  *   - none
  *  
  *  @param  string      $old_group_name   Name of group to rename
  *  @param  string      $new_group_name   New name for the group
  *  @param  array       $opt        Array of options
  *  @return bool
  */
 function rename_attr_type_group($old_group_name, $new_group_name, $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->attr_types->table_name;
     /* col names */
     $c =& $config->data_sql->attr_types->cols;
     $q = "update " . $t_name . " \n              set   " . $c->group . " = " . $this->sql_format($new_group_name, "s") . "\n              where " . $c->group . " = " . $this->sql_format($old_group_name, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }
コード例 #30
0
 /**
  *	delete file specific for a domain from db
  *
  *  Possible options parameters:
  *		none
  *
  *	@param string $did		domain id
  *	@param string $file		filename (with path)
  *	@param string $version	version of file
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success or FALSE on failure
  */
 function del_file_version($did, $file, $version, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain_settings->table_name;
     /* col names */
     $cd =& $config->data_sql->domain_settings->cols;
     $q = "delete from " . $td_name . " \n\t\t\t  where " . $cd->did . " = " . $this->sql_format($did, "s") . " and\n\t\t\t        " . $cd->filename . " = " . $this->sql_format($file, "s") . " and\n\t\t\t        " . $cd->version . " = " . $this->sql_format($version, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     return true;
 }