/**
  *  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;
 }
Ejemplo n.º 2
0
    /** Informational */
    define('PEAR_LOG_INFO', 6);
    /** Debug-level messages */
    define('PEAR_LOG_DEBUG', 7);
}
/** require functions */
require_once $_SERWEB["corefunctionsdir"] . "functions.php";
require_once $_SERWEB["corefunctionsdir"] . "exceptions.php";
/** require Smarty and create Smarty instance */
require $_SERWEB["corefunctionsdir"] . "smarty_serweb.php";
$smarty = new Smarty_Serweb();
/** require data layer for work with data store and create instance of it */
require_once $_SERWEB["corefunctionsdir"] . "data_layer.php";
/** require modules */
require_once $_SERWEB["corefunctionsdir"] . "load_modules.php";
/* 
 *  create instance of data_layer binded to proxy where is stored account  
 *  of currently authenticated user 
 */
$GLOBALS['data_auth'] = CData_Layer::singleton("auth_user");
/*  reference $data to $data_auth */
$GLOBALS['data'] =& $GLOBALS['data_auth'];
/** require page layout */
require_once $_SERWEB["corefunctionsdir"] . "page.php";
require_once $_SERWEB["corefunctionsdir"] . "load_phplib.php";
phplib_load("sess");
require_once $_SERWEB["corefunctionsdir"] . "load_lang.php";
phplib_load(array("auth", "perm"));
require_once $_SERWEB["corefunctionsdir"] . "load_apu.php";
$GLOBALS['controler']->add_required_javascript('core/phplib.js');
init_modules();
Ejemplo n.º 3
0
function test_db_version()
{
    global $config;
    $out = "";
    $errors = array();
    $data = CData_Layer::singleton("auth_user", $errors);
    if (!$data->connect_to_db($errors)) {
        $out .= "Can't connect to DB. Error: " . implode("; ", $errors);
        return array(2, $out);
    }
    $q = "select * from version;";
    $res = $data->db->query($q);
    if (DB::isError($res)) {
        log_errors($res, $errors);
        $out .= "Can't check. Error: " . implode("; ", $errors);
        return array(3, $out);
    }
    $t_versions = array();
    while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
        $t_versions[$row['table_name']] = $row['table_version'];
    }
    $res->free();
    $warning = false;
    $tables = get_object_vars($config->data_sql);
    foreach ($tables as $k => $v) {
        if (!isset($v->table_name) or !isset($v->version)) {
            continue;
        }
        if (!isset($t_versions[$v->table_name])) {
            $out .= "<div class='TversionNOK'>Expected version of table '" . $v->table_name . "' is " . $v->version . ", but version of this table in your DB can't be checked - may be the table does not exists.</div>";
            $warning = true;
        } elseif ($t_versions[$v->table_name] != $v->version) {
            $out .= "<div class='TversionNOK'>Expected version of table '" . $v->table_name . "' is " . $v->version . ", but version of this table in your DB is " . $t_versions[$v->table_name] . "</div>";
            $warning = true;
        } else {
            $out .= "<div class='TversionOK'>Version of table '" . $v->table_name . "' matches.</div>";
        }
    }
    if ($warning) {
        $out .= "<br />Versions of some tables do not match. This may not be in the way... " . "But in the case SerWeb displays errors in SQL queries, this is the reason and " . "you will have to reinstall your database.";
        return array(3, $out);
    }
    return array(1, $out);
}
Ejemplo n.º 4
0
    /** Warning conditions */
    define('PEAR_LOG_WARNING', 4);
    /** Normal but significant */
    define('PEAR_LOG_NOTICE', 5);
    /** Informational */
    define('PEAR_LOG_INFO', 6);
    /** Debug-level messages */
    define('PEAR_LOG_DEBUG', 7);
}
/** require functions */
require_once $_SERWEB["functionsdir"] . "functions.php";
/** require Smarty and create Smarty instance */
require $_SERWEB["smartydir"] . "smarty_serweb.php";
$smarty = new Smarty_Serweb();
/** require data layer for work with data store and create instance of it */
require_once $_SERWEB["functionsdir"] . "data_layer.php";
/** require modules */
require_once $_SERWEB["functionsdir"] . "load_modules.php";
/* 
 *  create instance of data_layer binded to proxy where is stored account  
 *  of currently authenticated user 
 */
$data_auth = CData_Layer::singleton("auth_user", $errors);
/*  reference $data to $data_auth */
$data =& $data_auth;
/* include domain depending config and activate it */
$domain_config = new CDomain_config();
$domain_config->activate_domain_config();
unset($domain_config);
/** require page layout */
require_once $_SERWEB["functionsdir"] . "page.php";
Ejemplo n.º 5
0
 /**
  *  Get status of user specified by sip-uri
  *
  *	Return status: 'unknown', 'nonlocal', 'notexists', 'offline', 'online'
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	string				FALSE on error
  */
 function get_status($sip_uri, $opt)
 {
     global $config;
     /* create connection to proxy where are stored data of user */
     if (isModuleLoaded('xxl') and $this->name != "get_status_tmp") {
         $tmp_data =& CData_Layer::singleton("get_status_tmp", $errors);
         $tmp_data->set_xxl_user_id($sip_uri);
         //$tmp_data->expect_user_id_may_not_exists(); //need this?
         return $tmp_data->get_status($sip_uri, $errors);
     }
     $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;
     $tl_name =& $config->data_sql->location->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     $cl =& $config->data_sql->location->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     $an =& $config->attr_names;
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return "unknown";
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return "nonlocal";
         }
     } else {
         if ($realm != $config->domain) {
             return "nonlocal";
         }
         $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 . " = '" . $did . "' 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 "notexists";
     }
     $uid = $row['uid'];
     $o = array("uid" => $uid, "did" => $did);
     if (false === ($show = Attributes::get_attribute($an['show_status'], $o))) {
         return false;
     }
     if (!$show) {
         return 'unknown';
     }
     $q = "select count(*)\n\t\t    from " . $tl_name . "\n\t\t\twhere  " . $cl->uid . " = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     if (!($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
         ErrorHandler::log_errors(PEAR::raiseError("Can't fetch data from DB"));
         return false;
     }
     if ($row[0]) {
         return "online";
     } else {
         return "offline";
     }
 }
Ejemplo n.º 6
0
 function xxl_init()
 {
     global $sess, $sess_xxl_selected_proxy, $perm;
     // register session variable sess_xxl_selected_proxy
     if (!$sess->is_registered('sess_xxl_selected_proxy')) {
         $sess->register('sess_xxl_selected_proxy');
     }
     if (!isset($sess_xxl_selected_proxy)) {
         $sess_xxl_selected_proxy = null;
     }
     // get $user_id if admin want work with some setting of user
     if (isset($perm) and $perm->have_perm("admin")) {
         // set initial value of sess_xxl_selected_proxy to same proxy where user has account
         if (isModuleLoaded('xxl') and is_null($sess_xxl_selected_proxy)) {
             if (false !== ($proxy_uri = $GLOBALS['data_auth']->get_home_proxy($this->errors))) {
                 $sess_xxl_selected_proxy = array('proxy' => $proxy_uri);
             }
         }
         // in XXL version and if is set sess_xxl_selected_proxy
         // create new instance of data_layer binded to seleceted proxy
         // note that data_layer binded to currently logged user is still
         // in variable $data_auth
         if (isModuleLoaded('xxl') and $sess_xxl_selected_proxy) {
             $GLOBALS['data_selected_proxy'] = CData_Layer::singleton("selected_proxy", $this->errors);
             $GLOBALS['data_selected_proxy']->setup_by_another_instance($GLOBALS['data_auth']);
             if (false === $GLOBALS['data_selected_proxy']->set_home_proxy($sess_xxl_selected_proxy['proxy'])) {
                 die("Can't connect to DB");
                 break;
             }
             $GLOBALS['data'] =& $GLOBALS['data_selected_proxy'];
         }
     }
 }