/**
  *	Validate given credentials and return UID if they are valid
  *
  *	@static
  *	@param	string	$username	
  *	@param	string	$did		
  *	@param	string	$password	
  *	@param	array	$optionals		
  *	@return	string				UID if credentials are valid, false otherwise
  */
 function validate_credentials($username, $did, $password, &$optionals)
 {
     global $lang_str, $data_auth, $config;
     $o_check_pw = isset($optionals['check_pw']) ? (bool) $optionals['check_pw'] : true;
     $data_auth->add_method('check_credentials');
     $data_auth->add_method('get_domain_flags');
     // check flags of domain
     if (false === ($flags = $data_auth->get_domain_flags($did, null))) {
         return false;
     }
     if ($flags['disabled']) {
         sw_log("validate_credentials: authentication failed: domain with id '" . $did . "' is disabled", PEAR_LOG_INFO);
         ErrorHandler::add_error($lang_str['account_disabled']);
         return false;
     }
     if ($flags['deleted']) {
         sw_log("validate_credentials: authentication failed: domain with id '" . $did . "' is deleted", PEAR_LOG_INFO);
         ErrorHandler::add_error($o_check_pw ? $lang_str['bad_username'] : $lang_str['err_no_user']);
         return false;
     }
     // find the realm
     sw_log("validate_credentials: looking for realm of domain with did: " . $did, PEAR_LOG_DEBUG);
     $opt = array("did" => $did);
     if (false === ($realm = Attributes::get_attribute($config->attr_names['digest_realm'], $opt))) {
         return false;
     }
     $optionals['realm'] = $realm;
     // chceck credentials
     sw_log("validate_credentials: checking credentials (username:did:realm): " . $username . ":" . $did . ":" . $realm, PEAR_LOG_DEBUG);
     $opt = array();
     $opt['check_pass'] = $o_check_pw;
     if ($config->clear_text_pw) {
         $opt['hash'] = 'clear';
         $ha = $password;
     } else {
         $opt['hash'] = 'ha1';
         $ha = md5($username . ":" . $realm . ":" . $password);
     }
     $uid = $data_auth->check_credentials($username, $did, $realm, $ha, $opt);
     if (is_int($uid) and $uid == -3) {
         sw_log("validate_credentials: authentication failed: account disabled ", PEAR_LOG_INFO);
         ErrorHandler::add_error($lang_str['account_disabled']);
         return false;
     }
     if (is_int($uid) and $uid <= 0) {
         sw_log("validate_credentials: authentication failed: bad username, did, realm or password ", PEAR_LOG_INFO);
         ErrorHandler::add_error($o_check_pw ? $lang_str['bad_username'] : $lang_str['err_no_user']);
         return false;
     }
     if (is_null($uid)) {
         sw_log("validate_credentials: authentication failed: no user ID", PEAR_LOG_INFO);
         ErrorHandler::add_error($o_check_pw ? $lang_str['bad_username'] : $lang_str['err_no_user']);
         return false;
     }
     return $uid;
 }
 function action_register(&$errors)
 {
     global $config, $data, $lang_str;
     $an =& $config->attr_names;
     /* generate confirmation string */
     $confirm = md5(uniqid(rand()));
     /* obtain password */
     if ($this->opt['choose_passw']) {
         $password = $_POST['passwd'];
     } else {
         /* generate new password */
         $password = substr(md5(uniqid('')), 0, 5);
     }
     if (!$this->opt['create_new_domain']) {
         /* get domain name */
         $domains =& Domains::singleton();
         if (false === ($domain_name = $domains->get_domain_name($this->did))) {
             $data->transaction_rollback();
             return false;
         }
     } else {
         $domain_name = $this->opt['create_new_domain'];
     }
     /* set value of option 'require_confirmation' */
     if (is_null($this->opt['require_confirmation'])) {
         $o = array();
         /* if creating new domain we does not know the DID */
         if (!$this->opt['create_new_domain']) {
             $o['did'] = $this->did;
         }
         if (false === ($this->opt['require_confirmation'] = Attributes::get_attribute($an['require_conf'], $o))) {
             return false;
         }
     }
     if (false === $data->transaction_start()) {
         return false;
     }
     if ($this->opt['create_new_domain']) {
         $sem = new Shm_Semaphore(__FILE__, "s", 1, 0600);
         /* set semaphore to be sure there will not be generated same 
            domain id for two domains */
         if (!$sem->acquire()) {
             $data->transaction_rollback();
             return false;
         }
         if (false === ($this->did = Domains::generate_new_did($this->opt['create_new_domain']))) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         $opt = array("enabled" => !$this->opt['require_confirmation']);
         if (false === DomainManipulator::add_alias($this->did, $this->opt['create_new_domain'], $opt)) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         $a_vals = array("alias" => $this->opt['create_new_domain']);
         if (false === DomainManipulator::update_domain_attrs($this->did, $a_vals)) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         $sem->release();
     }
     /* prepare array of attributes */
     $opt = array();
     $attrs = Attributes::post_attrs_to_array($this->attributes, $opt);
     /* add subscriber */
     $opts = array("disabled" => $this->opt['require_confirmation']);
     if (false === Registration::add_subscriber($_POST['uname'], $this->did, $password, $attrs, $opts)) {
         $data->transaction_rollback();
         return false;
     }
     $uid = $opts['uid'];
     $realm = $opts['realm'];
     $serweb_user =& SerwebUser::instance($uid, $_POST['uname'], $this->did, $realm);
     $user_param = $serweb_user->to_get_param();
     /* get handler of user attrs */
     $ua =& User_Attrs::singleton($uid);
     /* get handler of domain attrs */
     $da =& Domain_Attrs::singleton($this->did);
     if (!is_null($this->opt['set_lang_attr'])) {
         $u_lang = $this->opt['set_lang_attr'];
         /* get the attr_type of the lang attribute */
         $at_handler =& Attr_types::singleton();
         if (false === ($lang_type = $at_handler->get_attr_type($an['lang']))) {
             $data->transaction_rollback();
             return false;
         }
         if (is_null($lang_type)) {
             ErrorHandler::add_error("Type of attribute 'lang' doesn't exists");
             $data->transaction_rollback();
             return false;
         }
         /* format the value */
         $lang_type->check_value($u_lang);
         /* store lang into DB */
         if (false === $ua->set_attribute($an['lang'], $u_lang)) {
             $data->transaction_rollback();
             return false;
         }
     }
     if ($this->opt['create_new_domain']) {
         /* when creating new domain, set admin privilege for the user */
         if (false === $ua->set_attribute($an['is_admin'], "1")) {
             $data->transaction_rollback();
             return false;
         }
         /* and assign user as admin of the domain */
         if (false === $da->set_attribute($an['admin'], array($uid))) {
             $data->transaction_rollback();
             return false;
         }
     }
     if ($this->opt['require_confirmation']) {
         if (false === $ua->set_attribute($an['confirmation'], $confirm)) {
             $data->transaction_rollback();
             return false;
         }
         if (false === $ua->set_attribute($an['pending_ts'], time())) {
             $data->transaction_rollback();
             return false;
         }
         if ($this->opt['create_new_domain']) {
             if (false === $da->set_attribute($an['confirmation'], $confirm)) {
                 $data->transaction_rollback();
                 return false;
             }
             if (false === $da->set_attribute($an['pending_ts'], time())) {
                 $data->transaction_rollback();
                 return false;
             }
         }
     }
     if ($this->opt['create_numeric_alias']) {
         $sem = new Shm_Semaphore(__FILE__, "s", 1, 0600);
         /* set semaphore to be sure there will not be same aliases for two users */
         if (!$sem->acquire()) {
             $data->transaction_rollback();
             return false;
         }
         // generate alias number
         if (false === ($alias = $data->get_new_alias_number($this->did, null))) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         /* store alias to URI table */
         $o = array('disabled' => $this->opt['require_confirmation'], 'canon' => false);
         if (false === $data->add_uri($uid, 'sip', $alias, $this->did, $o)) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         /* reset the semaphore */
         if (!$sem->release()) {
             $data->transaction_rollback();
             return false;
         }
     }
     $sip_address = "sip:" . $_POST['uname'] . "@" . $domain_name;
     $login_url = $config->root_uri . ($this->opt['admin_login'] ? $config->admin_pages_path : $config->user_pages_path) . $this->opt['login_script'];
     $admin_url = $config->root_uri . $config->admin_pages_path . $this->opt['login_script'];
     $username = $config->fully_qualified_name_on_login ? $_POST['uname'] . "@" . $domain_name : $_POST['uname'];
     $confirmation_url = $config->root_uri . $config->user_pages_path . $this->opt['confirmation_script'] . "?nr=" . $confirm . (isModuleLoaded('xxl') ? "&pr=" . RawURLEncode(base64_encode($proxy['proxy'])) : "");
     if (is_null($this->opt['mail_file_conf'])) {
         $this->opt['mail_file_conf'] = $this->opt['mail_file'];
     }
     if ($this->opt['create_new_domain']) {
         if ($this->opt['require_confirmation']) {
             $mail_file = $this->opt['mail_file_domain_conf'];
         } else {
             $mail_file = $this->opt['mail_file_domain'];
         }
     } else {
         if ($this->opt['require_confirmation']) {
             $mail_file = $this->opt['mail_file_conf'];
         } else {
             $mail_file = $this->opt['mail_file'];
         }
     }
     $mail = read_lang_txt_file($mail_file, "txt", $_SESSION['lang'], array(array("domain", $domain_name), array("sip_address", $sip_address), array("login_url", $login_url), array("admin_url", $admin_url), array("confirmation_url", $confirmation_url), array("username", $username), array("password", $password), array("email", isset($_POST[$an['email']]) ? $_POST[$an['email']] : ""), array("first_name", isset($_POST[$an['fname']]) ? $_POST[$an['fname']] : ""), array("last_name", isset($_POST[$an['lname']]) ? $_POST[$an['lname']] : "")));
     if ($mail === false) {
         /* needn't write message to log. It's written by function read_lang_txt_file */
         $errors[] = $lang_str['err_sending_mail'];
         $data->transaction_rollback();
         return false;
     }
     $o = array('did' => $this->did);
     if (false === ($from_header = Attributes::get_attribute($an['contact_email'], $o))) {
         return false;
     }
     if ($from_header) {
         $mail['headers']['from'] = $from_header;
     }
     if (!send_mail($_POST[$an['email']], $mail['body'], $mail['headers'])) {
         $errors[] = $lang_str['err_sending_mail'];
         $this->controler->_form_load_defaults();
         $data->transaction_rollback();
         return false;
     }
     if (false === $data->transaction_commit()) {
         return false;
     }
     if ($this->opt['redirect_on_register']) {
         $this->controler->change_url_for_reload($this->opt['redirect_on_register']);
     }
     return array("m_user_registered=" . RawURLEncode($this->opt['instance_id']), "reg_sip_adr=" . RawURLEncode($sip_address), "require_conf=" . RawURLEncode($this->opt['require_confirmation']), $user_param);
     //$user_param sets the user_id holding ny controller
 }
/**
 *	Function read array of URIs and for each URI get the domain id,
 *	obtain value of attribute 'send_missed_calls'. If at least one attribute
 *	is true, this function return 1. Otherwise return 0. 
 *
 *	If no domain has the attribute set, the output of function depends on global 
 *	attribute 'send_missed_calls'
 *	
 *	@param	array	$uris
 *	@return	int				or FALSE on error
 */
function get_send_mc_of_dom($uris, &$mail_from)
{
    global $config;
    $an = $config->attr_names;
    $send = null;
    $mail_from = null;
    foreach ($uris as $uri) {
        $da =& Domain_Attrs::singleton($uri->get_did());
        if (false === ($s = $da->get_attribute($an['send_mc']))) {
            return false;
        }
        if (is_null($send)) {
            $send = $s;
        } else {
            $send = ($send or $s);
        }
        if ($s and !$mail_from) {
            $o = array('did' => $uri->get_did());
            if (false === ($from_header = Attributes::get_attribute($an['contact_email'], $o))) {
                return false;
            }
            if ($from_header) {
                $mail_from = $from_header;
            }
        }
    }
    if (is_null($send)) {
        $ga =& Global_Attrs::singleton();
        if (false === ($send = $ga->get_attribute($an['send_mc']))) {
            return false;
        }
    }
    return $send ? 1 : 0;
}
Beispiel #4
0
require "prepend.php";
$form_submit = array('type' => 'image', 'text' => $lang_str['b_register'], 'src' => get_path_to_buttons("btn_register.gif", $_SESSION['lang']));
if (!$config->multidomain) {
    $did = $config->default_did;
} else {
    $did = $data->get_did_by_realm($config->domain, null);
    if (false === $did or is_null($did)) {
        ErrorHandler::add_error("Can't obtain domain ID of domain you want register in (" . $config->domain . "). See the serweb log for more info.");
        $controler->set_template_name('_default.tpl');
        $controler->start();
        exit;
    }
}
do {
    $opt = array("did" => $did);
    if (false === ($addr = Attributes::get_attribute($config->attr_names['contact_email'], $opt))) {
        break;
    }
    if (!$addr) {
        $addr = $config->mail_header_from;
    }
    $smarty->assign('infomail', $addr);
} while (false);
$register = new apu_registration();
$register->set_opt('form_name', 'form1');
$register->set_opt('form_submit', $form_submit);
$register->set_opt('terms_file', "terms.txt");
$register->set_opt('mail_file', "mail_register.txt");
$register->set_opt('mail_file_conf', "mail_register_conf.txt");
$register->set_opt('confirmation_script', "reg/confirmation.php");
$register->set_opt('register_in_domain', $did);
 function validate_form(&$errors)
 {
     global $config, $data, $lang_str;
     if (false === parent::validate_form($errors)) {
         return false;
     }
     //if fully quantified username is given
     if ($this->opt['fully_qualified_name']) {
         // parse username and domain from it
         if (ereg("^([^@]+)@(.+)", $_POST['fp_uname'], $regs)) {
             $username = $regs[1];
             $domain = $regs[2];
         } else {
             sw_log("Get password failed: unsuported format of username. Can't parse username and domain part", PEAR_LOG_INFO);
             $errors[] = $lang_str['err_no_user'];
             return false;
         }
     } else {
         $username = $_POST['fp_uname'];
         $domain = $this->opt['domain'];
     }
     $data->set_xxl_user_id('sip:' . $username . '@' . $domain);
     $data->expect_user_id_may_not_exists();
     /* get did */
     $opt = array();
     $did = call_user_func_array(array($this->opt['auth_class'], 'find_out_did'), array($domain, &$opt));
     if (false === $did) {
         return false;
     }
     if (is_null($did)) {
         sw_log("Forgotten password: did not found for domain name: " . $domain, PEAR_LOG_DEBUG);
         ErrorHandler::add_error($lang_str['domain_not_found']);
         return false;
     }
     $o = array("did" => $did);
     if (false === ($realm = Attributes::get_attribute($config->attr_names['digest_realm'], $o))) {
         return false;
     }
     /* validate credentials */
     $o = array('check_pw' => false);
     $uid = call_user_func_array(array($this->opt['auth_class'], 'validate_credentials'), array($username, $did, null, &$o));
     if (false === $uid) {
         return false;
     }
     $this->sip_user['uname'] = $username;
     $this->sip_user['realm'] = isset($o['realm']) ? $o['realm'] : "";
     $this->sip_user['uid'] = $uid;
     $this->sip_user['did'] = $did;
     $this->did = $did;
     return true;
 }
 /**
  *  set timezone which is used by date/time formating function to timezone 
  *  of user
  *
  *  @param string $uid  user to which timezone should be set - if not given $this->user_id is used
  */
 function set_timezone($uid = null)
 {
     global $config;
     if (is_null($uid)) {
         $uid = $this->user_id->get_uid();
     }
     $an =& $config->attr_names;
     /* if timezone is already set for this user, do not set it again */
     if (is_null($this->is_set_timezone) or $this->is_set_timezone != $uid) {
         $o = array('uid' => $uid);
         if (false === ($tz = Attributes::get_attribute($an['timezone'], $o))) {
             return false;
         }
         if (!is_null($tz)) {
             putenv("TZ=" . $tz);
             //set timezone
             $this->is_set_timezone = $uid;
         }
     }
     return true;
 }
Beispiel #7
0
 /**
  *	Create new subscriber
  *
  *	Create credentials, uris and user_attrs
  *
  *	Options:
  *	 - 'disabled' - create the subscriber disabled
  *	
  *	
  *	@param	string	$username
  *	@param	string	$did
  *	@param	string	$password
  *	@param	array	$attrs
  *	@param	array	$opts
  *	@return	bool
  *	@static
  */
 function add_subscriber($username, $did, $password, $attrs, &$opts)
 {
     global $config, $data;
     $an =& $config->attr_names;
     include_module("uri");
     $data->add_method('add_credentials');
     $data->add_method('add_uri');
     $o_disabled = isset($opts['disabled']) ? (bool) $opts['disabled'] : false;
     /* get realm */
     $opt = array("did" => $did);
     if (false === ($realm = Attributes::get_attribute($an['digest_realm'], $opt))) {
         return false;
     }
     $opts['realm'] = $realm;
     /* generate uid */
     if (false === ($uid = Registration::get_uid($username, $realm))) {
         return false;
     }
     $opts['uid'] = $uid;
     if (false === $data->transaction_start()) {
         return false;
     }
     /* store credentials */
     $o = array('disabled' => $o_disabled);
     if (false === $data->add_credentials($uid, $did, $username, $realm, $password, $o)) {
         $data->transaction_rollback();
         return false;
     }
     /* store uri */
     $o = array('disabled' => $o_disabled, 'canon' => true);
     if (false === $data->add_uri($uid, 'sip', $username, $did, $o)) {
         $data->transaction_rollback();
         return false;
     }
     /* store attributes */
     $ua =& User_Attrs::singleton($uid);
     foreach ($attrs as $k => $v) {
         if (false === $ua->set_attribute($k, $v)) {
             $data->transaction_rollback();
             return false;
         }
     }
     if (false === $ua->set_attribute($an['datetime_created'], gmdate("Y-m-d H:i:s"))) {
         $data->transaction_rollback();
         return false;
     }
     if (false === $data->transaction_commit()) {
         return false;
     }
     return true;
 }
 /**
  *	check if user exists
  */
 function is_user_exists($uname, $did)
 {
     global $config;
     if (isModuleLoaded('xxl')) {
         die('method is_user_exists not correctly implemented in XXL mode');
         if (!$this->connect_to_xml_rpc(array("uri" => "sip:" . $uname . "@" . $udomain), $errors)) {
             return false;
         }
         $params = array(new XML_RPC_Value("sip:" . $uname . "@" . $udomain, 'string'));
         $msg = new XML_RPC_Message('get_proxy', $params);
         $res = $this->rpc->send($msg);
         if ($this->rpc_is_error($res)) {
             if ($res->getCode() == "404") {
                 return 1;
             }
             log_errors($res, $errors);
             return 0;
         }
         return -3;
     } else {
         $errors = array();
         if (!$this->connect_to_db($errors)) {
             ErrorHandler::add_error($errors);
             return 0;
         }
         /* table's name */
         $tc_name =& $config->data_sql->credentials->table_name;
         $tu_name =& $config->data_sql->uri->table_name;
         /* col names */
         $cc =& $config->data_sql->credentials->cols;
         $cu =& $config->data_sql->uri->cols;
         /* flags */
         $fc =& $config->data_sql->credentials->flag_values;
         $fu =& $config->data_sql->uri->flag_values;
         $an =& $config->attr_names;
         /* get digest realm of given domain */
         $opt = array("did" => $did);
         if (false === ($d_realm = Attributes::get_attribute($an['digest_realm'], $opt))) {
             return false;
         }
         $q = "select count(*) from " . $tc_name . " \n\t\t\t    where lower(" . $cc->uname . ")=lower(" . $this->sql_format($uname, "s") . ") and \n\t\t\t\t      " . $cc->realm . " = " . $this->sql_format($d_realm, "s");
         if ($config->auth['use_did']) {
             $q .= " and " . $cc->did . " = " . $this->sql_format($did, "s");
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             return 0;
         }
         $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
         $res->free();
         if ($row[0]) {
             sw_log("Credentials for user (username, did) - (" . $uname . ", " . $did . ") already exists", PEAR_LOG_DEBUG);
             return -1;
         }
         /* 
          *	Credentials not found, check uri table 
          */
         $q = "select count(*) from " . $tu_name . " \n\t\t\t    where lower(" . $cu->username . ")=lower(" . $this->sql_format($uname, "s") . ") and \n\t\t\t\t      lower(" . $cu->did . ")=lower(" . $this->sql_format($did, "s") . ")";
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             return 0;
         }
         $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
         $res->free();
         if ($row[0]) {
             sw_log("Uri for user (username, did) - (" . $uname . ", " . $did . ") already exists", PEAR_LOG_DEBUG);
             return -2;
         }
         return 1;
     }
 }
function determine_lang(){
    global $config, $data, $available_languages;
    $an = &$config->attr_names;
    $did = null;


    // Lang forced
    if (!empty($config->force_lang) && isset($available_languages[$config->force_lang])) {
        $_SESSION['lang'] = $config->force_lang;
    }

    
    // If session variable is set, obtain language from it
    if (isset($_SESSION['lang'])){
        if (isset($available_languages[$_SESSION['lang']])) return $_SESSION['lang'];
        else unset($_SESSION['lang']);
    }

    // Lang is not know yet
    // try to findout user's language by checking user attribute

    if (isset($_SESSION['auth']) and 
        is_a($_SESSION['auth'], 'Auth') and
        $_SESSION['auth']->is_authenticated()){

        $uid = $_SESSION['auth']->get_uid();
        $did = $_SESSION['auth']->get_did(); //for checking domain attribute later

        $attrs = &User_Attrs::singleton($uid);
        $lang = lang_detect($attrs->get_attribute($an['lang']), 3);
        if (false != $lang) return $lang;

    }
    

    // try to findout user's language by checking cookie

    if (!empty($_COOKIE['serweb_lang']) and isset($available_languages[$_COOKIE['serweb_lang']])){
        return $_COOKIE['serweb_lang'];
    }

    // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
    
    if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $accepted    = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $acceptedCnt = count($accepted);
        for ($i = 0; $i < $acceptedCnt; $i++) {
            $lang = lang_detect($accepted[$i], 1);
            if (false != $lang) return $lang;
        }
    }
    
    // try to findout user's language by checking its HTTP_USER_AGENT variable

    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        $lang = lang_detect($_SERVER['HTTP_USER_AGENT'], 2);
        if (false != $lang) return $lang;
    }

    // try to findout user's language by checking domain or global attribute

    if (empty($config->do_not_set_lang_by_domain)){
        if (is_null($did)){ // if user is not authenticated yet
                            // get did of domain from http request
            $data->add_method('get_did_by_realm');
            $did = $data->get_did_by_realm($config->domain, null);
            if (false === $did) $did = null;
        }
    }
    else{
        $did = null;
    }

    $o = array();
    if (!is_null($did)) $o['did'] = $did;
    $lang = lang_detect(Attributes::get_attribute($an['lang'], $o), 3);
    if (false != $lang) return $lang;


    if (!is_null($lang) and isset($available_languages[$lang])) return $lang;


    // Didn't catch any valid lang : we use the default settings
    
    return $config->default_lang;

}
Beispiel #10
0
 /**
  *	Create form elements for attributes
  *	
  *	Create form elements for attributes within form object and presets 
  *	the default values of attributes
  *	
  *	Alowed options:
  *		- uid (string)	-	uid of user track
  *		- did (string)	-	did of domain track
  *		- uri (array)	-	identifies uri track. Have to have three 
  *							components: scheme, username and did
  *		- get_values (bool) - 	if true, return current values of attributes 
  *		                        as associative array in option 'attr_values'
  *	
  *	
  *	@param	array	$attributes		list of attributes
  *	@param	object	$f				form object
  *	@param	string	$js_before		javascript called before form validation
  *	@param	string	$js_after		javascript called after form validation
  *	@param	array	$opt			options
  *	@return	bool					TRUE on success or FALSE on error
  */
 function attrs_to_form($attributes, &$f, &$js_before, &$js_after, &$opt)
 {
     $a_opt = array();
     /* set values for options */
     if (isset($opt["uid"])) {
         $a_opt["uid"] = $opt["uid"];
     }
     if (isset($opt["did"])) {
         $a_opt["did"] = $opt["did"];
     }
     if (isset($opt["uri"])) {
         $a_opt["uri"] = $opt["uri"];
     }
     //get list of attributes
     $at_h =& Attr_types::singleton();
     if (false === ($attr_types =& $at_h->get_attr_types())) {
         return false;
     }
     $attr_values = array();
     foreach ($attributes as $attr) {
         if (false === ($val = Attributes::get_attribute($attr, $a_opt))) {
             return false;
         }
         $attr_values[$attr] = $val;
     }
     // add elements to form object
     foreach ($attributes as $attr) {
         $f_opt = array();
         if (!isset($attr_types[$attr])) {
             $msg = __FILE__ . ":" . __LINE__ . " - Attribute named '" . $attr . "' do not exists - exiting";
             sw_log($msg, PEAR_LOG_CRIT);
             die($msg);
         }
         $attr_types[$attr]->form_element($f, $attr_values[$attr], $f_opt);
         $js_before .= $attr_types[$attr]->validation_js_before();
         $js_after .= $attr_types[$attr]->validation_js_after();
     }
     if (!empty($opt['get_values'])) {
         $opt['attr_values'] = $attr_values;
     }
     return true;
 }
Beispiel #11
0
/** include all others necessary files */
require "prepend.php";
if (!$config->multidomain) {
    $did = $config->default_did;
} else {
    $did = $data->get_did_by_realm($config->domain, null);
    if (false === $did or is_null($did)) {
        ErrorHandler::add_error("Can't obtain domain ID of domain you want log in (" . $config->domain . "). See the serweb log for more info.");
        $controler->set_template_name('_default.tpl');
        $controler->start();
        exit;
    }
}
do {
    $opt = array("did" => $did);
    if (false === ($uname_assign_mode = Attributes::get_attribute($config->attr_names['uname_asign_mode'], $opt))) {
        break;
    }
    $smarty->assign('allow_register', $uname_assign_mode != 'adminonly');
} while (false);
$smarty->assign('allow_domain_reg', $config->allow_self_domain_register);
$login = new apu_login();
$login->set_opt("auth_class", "phplib_Auth");
unset($page_attributes['tab_collection']);
$page_attributes['logout'] = false;
$page_attributes['self_account_delete'] = false;
$smarty->assign('domain', $config->domain);
if (isset($_GET['m_sc_user_self_deleted'])) {
    $controler->messages[] = array("long" => $lang_str['msg_self_account_delete_l']);
}
$controler->add_apu($login);
 /**
  *  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";
     }
 }
Beispiel #13
0
$_phplib_page_open = array("sess" => "phplib_Session", "auth" => "phplib_Auth");
$_required_modules = array('uri');
$_required_apu = array('apu_uri_user', 'apu_sorter');
/** include all others necessary files */
require "prepend.php";
$apu = new apu_uri_user();
$sr = new apu_sorter();
$apu->set_sorter($sr);
// set allowed domain
if (false === ($dom = $_SESSION['auth']->get_did())) {
    $dom = array();
} else {
    $dom = array($dom);
}
$apu->set_opt('allowed_domains', $dom);
// set max URIs per user
$an =& $config->attr_names;
$o = array('uid' => $_SESSION['auth']->get_uid(), 'did' => $_SESSION['auth']->get_did());
if (false === ($max_uris = Attributes::get_attribute($an['max_uri_user'], $o))) {
    return false;
}
if (!is_null($max_uris)) {
    $apu->set_opt('max_uris', $max_uris);
} else {
    $apu->set_opt('max_uris', 0);
}
$page_attributes['user_name'] = get_user_real_name($_SESSION['auth']->get_logged_user());
$controler->add_apu($apu);
$controler->add_apu($sr);
$controler->set_template_name('u_uri.tpl');
$controler->start();
 function get_realm($did)
 {
     global $config;
     $opt = array("did" => $_POST['cr_domain']);
     if (false === ($realm = Attributes::get_attribute($config->attr_names['digest_realm'], $opt))) {
         return false;
     }
     return $realm;
 }