Exemplo n.º 1
0
/**
 *	Get real name of the user
 */
function get_user_real_name($user)
{
    global $config;
    $at =& $config->attr_names;
    $attrs =& User_Attrs::singleton($user->get_uid());
    if (false === ($fname = $attrs->get_attribute($at['fname']))) {
        return false;
    }
    if (false === ($lname = $attrs->get_attribute($at['lname']))) {
        return false;
    }
    return array('fname' => $fname, 'lname' => $lname, 'uname' => $user->get_username(), 'realm' => $user->get_domainname());
}
Exemplo n.º 2
0
 /**
  *	Get value of attribute
  *	
  *	This function search in order uri, user, domain and global tracks 
  *	for attribute value and return value from the first track where find it.
  *	
  *	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
  *	
  *	@param	string	$name	name of the attribute
  *	@param	array	$opt	options
  *	@return	mixed			value of attribute or FALSE on error
  */
 function get_attribute($name, $opt)
 {
     /* set default values for options */
     $opt_uid = isset($opt["uid"]) ? $opt["uid"] : null;
     $opt_did = isset($opt["did"]) ? $opt["did"] : null;
     $opt_uri = isset($opt["uri"]) ? $opt["uri"] : null;
     if (!is_null($opt_uri)) {
         $attrs =& Uri_Attrs::singleton($opt_uri['scheme'], $opt_uri['username'], $opt_uri['did']);
         if (false === ($attr = $attrs->get_attribute($name))) {
             return false;
         }
         if (!is_null($attr)) {
             return $attr;
         }
     }
     if (!is_null($opt_uid)) {
         $attrs =& User_Attrs::singleton($opt_uid);
         if (false === ($attr = $attrs->get_attribute($name))) {
             return false;
         }
         if (!is_null($attr)) {
             return $attr;
         }
     }
     if (!is_null($opt_did)) {
         $attrs =& Domain_Attrs::singleton($opt_did);
         if (false === ($attr = $attrs->get_attribute($name))) {
             return false;
         }
         if (!is_null($attr)) {
             return $attr;
         }
     }
     $attrs =& Global_Attrs::singleton();
     if (false === ($attr = $attrs->get_attribute($name))) {
         return false;
     }
     if (!is_null($attr)) {
         return $attr;
     }
     /* attribute not found */
     return null;
 }
Exemplo n.º 3
0
 /**
  *	Get permissions of user with given UID 
  *	
  *	This function return the permissions of user in array
  *
  *	@static
  *	@param	string	$uid
  *	@param	array	$opt		
  *	@return	array				array of permissions or FALSE on error
  */
 function find_out_perms($uid, $opt)
 {
     global $lang_str, $data_auth, $config;
     $an = $config->attr_names;
     $perms = array();
     $attrs =& User_Attrs::singleton($uid);
     if (false === ($attrib = $attrs->get_attribute($an["is_admin"]))) {
         return false;
     }
     if ($attrib) {
         $perms[] = 'admin';
     }
     if (false === ($attrib = $attrs->get_attribute($an["is_hostmaster"]))) {
         return false;
     }
     if ($attrib) {
         $perms[] = 'hostmaster';
     }
     return $perms;
 }
Exemplo n.º 4
0
 function action_update(&$errors)
 {
     global $available_languages, $config;
     $_SESSION['lang'] = $_POST['ls_language'];
     if ($this->opt['save_to_cookie']) {
         setcookie('serweb_lang', $_SESSION['lang'], time() + 31536000, $config->root_path);
     }
     if ($this->opt['save_to_user_attr']) {
         $an =& $config->attr_names;
         $attrs =& User_Attrs::singleton($this->controler->user_id->get_uid());
         if (false === $attrs->set_attribute($an['lang'], $available_languages[$_SESSION['lang']][2])) {
             return false;
         }
     }
     return array("m_ls_updated=" . RawURLEncode($this->opt['instance_id']));
 }
Exemplo n.º 5
0
/**
 *	send missed calls to all subescribers
 */
function send_missed_calls()
{
    global $config, $data;
    $an = $config->attr_names;
    $opt = array('count_only' => true);
    /* count users */
    if (false === ($users_cnt = $data->get_users(array(), $opt))) {
        return false;
    }
    $step = 500;
    $data->set_showed_rows($step);
    for ($i = 0; $i < $users_cnt; $i += $step) {
        $data->set_act_row($i);
        $opt = array('order_by' => "uid", 'get_aliases' => true);
        /* get list of users and values of theirs attributes up_send_daily_missed_calls */
        if (false === ($users = $data->get_users(array(), $opt))) {
            return false;
        }
        foreach ($users as $row) {
            $ua =& User_Attrs::singleton($row['uid']);
            if (false === ($send = $ua->get_attribute($an['send_mc']))) {
                return false;
            }
            /* if email address is not filled skip this user */
            if (!$row['email_address']) {
                continue;
            }
            $mail_from = null;
            if (false === ($dom_send = get_send_mc_of_dom($row['uris'], $mail_from))) {
                return false;
            }
            if (is_null($send)) {
                $send = $dom_send;
            }
            if ($send) {
                if (false === send_mail_with_missed_calls($row['uid'], $row['email_address'], $mail_from)) {
                    return false;
                }
            }
            //free memory allocated by user attributes and uris
            URIs::free($row['uid']);
            User_Attrs::free($row['uid']);
        }
        unset($users);
    }
}
Exemplo n.º 6
0
 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 action_send_pass(&$errors)
 {
     global $data, $config, $lang_str;
     if (isset($_GET['pr'])) {
         $proxy = base64_decode($_GET['pr']);
         if ($proxy and isModuleLoaded('xxl')) {
             if (false === $data->set_home_proxy($proxy)) {
                 return false;
             }
         }
     }
     if (isModuleLoaded('xxl') and !$proxy) {
         $errors[] = $lang_str['err_reg_conf_not_exists_conf_num'];
         return false;
     }
     if (empty($_GET['u'])) {
         $errors[] = $lang_str['err_reg_conf_not_exists_conf_num'];
         return false;
     }
     $an =& $config->attr_names;
     /* get uid */
     $o = array('name' => $an['confirmation'], 'value' => $this->nr);
     if (false === ($attrs = $data->get_attr_by_val("user", $o))) {
         return false;
     }
     if (empty($attrs[0]['id'])) {
         ErrorHandler::add_error($lang_str['err_reg_conf_not_exists_conf_num']);
         return false;
     }
     $uid = $attrs[0]['id'];
     /* recreate instance of SerwebUser class from get param */
     $serweb_user =& SerwebUser::recreate_from_get_param($_GET['u']);
     /* and compare if uid obtained from user_attrs match to uid inside $serweb_user object */
     if ($uid != $serweb_user->get_uid()) {
         ErrorHandler::add_error($lang_str['err_reg_conf_not_exists_conf_num']);
         return false;
     }
     /* get email address of user */
     $user_attrs =& User_Attrs::singleton($uid);
     if (false === ($email = $user_attrs->get_attribute($an['email']))) {
         return false;
     }
     /* generate new password */
     $password = substr(md5(uniqid('')), 0, 5);
     if (false === $data->set_password_to_user($serweb_user, $password, $errors)) {
         return false;
     }
     $mail = read_lang_txt_file($this->opt['mail_file_pass'], "txt", $_SESSION['lang'], array(array("domain", $this->opt['domain']), array("password", $password)));
     if ($mail === false) {
         /* needn't write message to log. It's written by function read_lang_txt_file */
         $errors[] = $lang_str['err_sending_mail'];
         return false;
     }
     if (false === $this->set_from_header($mail['headers'])) {
         return false;
     }
     if (!send_mail($email, $mail['body'], $mail['headers'])) {
         $errors[] = $lang_str['err_sending_mail'];
         return false;
     }
     /* unset attribute confirmation */
     if (false === $user_attrs->unset_attribute($an['confirmation'])) {
         return false;
     }
     return array("m_fp_pass_sended=" . RawURLEncode($this->opt['instance_id']));
 }
 /**
  *  Enable or disable user account
  *
  *  Possible options:
  *    - uid	  (string) - uid of user which should be enabled/disabled
  *                       this option is required (default: null)
  *    - disable (bool) - if true user will be disabled, otherwise will 
  *                       be enabled (default: false)
  *      
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function enable_user($opt)
 {
     global $config, $data;
     $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;
     $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;
     $o_uid = isset($opt['uid']) ? $opt['uid'] : null;
     $o_disable = isset($opt['disable']) ? $opt['disable'] : false;
     if (is_null($o_uid)) {
         ErrorHandler::log_errors(PEAR::raiseError('subscriber which should be enabled or disabled is not specified'));
         return false;
     }
     if (false === $this->transaction_start()) {
         return false;
     }
     $q = "update " . $tc_name . " set ";
     if ($o_disable) {
         $q .= $cc->flags . " = " . $cc->flags . " | " . $fc['DB_DISABLED'];
     } else {
         $q .= $cc->flags . " = " . $cc->flags . " & ~" . $fc['DB_DISABLED'];
     }
     $q .= " where " . $cc->uid . " = " . $this->sql_format($o_uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     $q = "update " . $tu_name . " set ";
     if ($o_disable) {
         $q .= $cu->flags . " = " . $cu->flags . " | " . $fu['DB_DISABLED'];
     } else {
         $q .= $cu->flags . " = " . $cu->flags . " & ~" . $fu['DB_DISABLED'];
     }
     $q .= " where " . $cu->uid . " = " . $this->sql_format($o_uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     if (!$o_disable) {
         /*
          *	Unset attributes of pending users if they are set
          */
         $user_attrs =& User_Attrs::singleton($o_uid);
         if (false === $user_attrs->unset_attribute($an['confirmation'])) {
             $this->transaction_rollback();
             return false;
         }
         if (false === $user_attrs->unset_attribute($an['pending_ts'])) {
             $this->transaction_rollback();
             return false;
         }
     }
     if (false === $this->transaction_commit()) {
         return false;
     }
     return true;
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
0
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;

}
Exemplo n.º 11
0
 function create_html_form(&$errors)
 {
     global $data, $config;
     parent::create_html_form($errors);
     $attr_types =& Attr_types::singleton();
     //get list of attributes
     if (false === ($this->attr_types =& $attr_types->get_attr_types())) {
         return false;
     }
     switch ($this->opt['attrs_kind']) {
         case "uri":
             // get uri_attrs
             $this->uri_attrs =& Uri_Attrs::singleton($this->uri_scheme, $this->uri_uname, $this->uri_did);
             if (false === ($uri_attrs = $this->uri_attrs->get_attributes())) {
                 return false;
             }
         case "user":
             // get user_attrs
             $this->user_attrs =& User_Attrs::singleton($this->uid);
             if (false === ($user_attrs = $this->user_attrs->get_attributes())) {
                 return false;
             }
         case "domain":
             // get domain_attrs
             $this->domain_attrs =& Domain_Attrs::singleton($this->did);
             if (false === ($domain_attrs = $this->domain_attrs->get_attributes())) {
                 return false;
             }
         case "global":
             // get global_attrs
             $this->global_attrs =& Global_Attrs::singleton();
             if (false === ($global_attrs = $this->global_attrs->get_attributes())) {
                 return false;
             }
     }
     $this->attr_values = array();
     foreach ($this->attr_types as $k => $v) {
         if ($this->opt['attrs_kind'] == 'uri' and !$this->attr_types[$k]->is_for_URIs()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'user' and !$this->attr_types[$k]->is_for_users()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'domain' and !$this->attr_types[$k]->is_for_domains()) {
             continue;
         } elseif ($this->opt['attrs_kind'] == 'global' and !$this->attr_types[$k]->is_for_globals()) {
             continue;
         }
         switch ($this->opt['attrs_kind']) {
             case "uri":
                 if (isset($uri_attrs[$k])) {
                     $this->attr_values[$k] = $uri_attrs[$k];
                     break;
                 }
             case "user":
                 if (isset($user_attrs[$k])) {
                     $this->attr_values[$k] = $user_attrs[$k];
                     break;
                 }
             case "domain":
                 if (isset($domain_attrs[$k])) {
                     $this->attr_values[$k] = $domain_attrs[$k];
                     break;
                 }
             case "global":
                 if (isset($global_attrs[$k])) {
                     $this->attr_values[$k] = $global_attrs[$k];
                     break;
                 }
         }
         /*
          *	If the value of attribute is not found, set it as null
          */
         if (!isset($this->attr_values[$k])) {
             $this->attr_values[$k] = null;
         }
     }
     // if option 'atributes' is not given, that mean we will work with all attributes
     if (empty($this->opt['attributes'])) {
         foreach ($this->attr_values as $k => $v) {
             // work only with attributes which have access to read
             if ($this->access_to_read($k)) {
                 $this->opt['attributes'][] = $k;
             }
         }
     } else {
         foreach ($this->opt['attributes'] as $k => $v) {
             if (!array_key_exists($v, $this->attr_values)) {
                 log_errors(PEAR::RaiseError("Attribute named '" . $v . "' does not exists"), $errors);
                 unset($this->opt['attributes'][$k]);
             }
         }
     }
     //except unwanted arguments
     $this->opt['attributes'] = array_diff($this->opt['attributes'], $this->opt['exclude_attributes']);
     //save avaiable attrs before are filtered by group
     $this->all_avaiable_attrs = $this->opt['attributes'];
     if (!empty($this->opt['attrs_group'])) {
         foreach ($this->opt['attributes'] as $k => $v) {
             // work only with attributes from specified group
             if ($this->attr_types[$v]->get_group() != $this->opt['attrs_group']) {
                 unset($this->opt['attributes'][$k]);
             }
         }
     }
     //set options to attributes
     foreach ($this->opt['attributes'] as $att) {
         if (isset($this->opt['attrs_options'][$att]) and is_array($this->opt['attrs_options'][$att])) {
             foreach ($this->opt['attrs_options'][$att] as $k => $v) {
                 $this->attr_types[$att]->set_opt($k, $v);
             }
         }
     }
     // add elements to form object
     foreach ($this->opt['attributes'] as $att) {
         if (!$this->access_to_change($att)) {
             continue;
         }
         //if attribute cannot be changed, do not add it ot the form
         $opt = array();
         $opt['err_msg'] = isset($this->opt['error_messages'][$att]) ? $this->opt['error_messages'][$att] : null;
         $this->attr_types[$att]->form_element($this->f, $this->attr_values[$att], $opt);
         $this->js_on_subm .= $this->attr_types[$att]->validation_js_before();
         $this->js_on_subm_2 .= $this->attr_types[$att]->validation_js_after();
     }
     if (!empty($this->opt['validate_js_funct'])) {
         $this->js_on_subm_2 .= $this->opt['validate_js_funct'];
     }
 }
Exemplo n.º 12
0
 function create_html_form(&$errors)
 {
     global $config;
     parent::create_html_form($errors);
     $an =& $config->attr_names;
     $ua =& User_Attrs::singleton($this->user_id->get_uid());
     if (false === ($this->acl = $ua->get_attribute($an['acl']))) {
         return false;
     }
     if (is_null($this->acl)) {
         $this->acl = array();
     }
     if ($this->opt['allow_edit']) {
         /* get admin ACL control privileges */
         $user_attrs =& User_Attrs::singleton($_SESSION['auth']->get_uid());
         if (false === ($this->acl_control = $user_attrs->get_attribute($an['acl_control']))) {
             return false;
         }
         if (is_null($this->acl_control)) {
             $this->acl_control = array();
         }
         /* add form elements */
         foreach ($this->acl_control as $row) {
             $this->f->add_element(array("type" => "checkbox", "name" => "acl_chk_" . $row, "checked" => in_array($row, $this->acl) ? "1" : "0", "value" => "1"));
         }
     }
 }
Exemplo n.º 13
0
 function action_login(&$errors)
 {
     global $lang_str, $config;
     unset($_SESSION['auth']);
     // set cookie only if not doing http redirect because
     // $_POST['remember_uname'] is not set during redirect
     if (!isset($_GET["redir_id"])) {
         if (isset($_POST['remember_uname']) and $_POST['remember_uname']) {
             setcookie('serwebuser', $_POST['uname'], time() + 31536000, null, $this->opt['cookie_domain']);
         } else {
             setcookie('serwebuser', '', time(), null, $this->opt['cookie_domain']);
         }
         //delete cookie
     }
     if (isModuleLoaded('xxl') and $this->opt['xxl_redirect_after_login']) {
         xxl_http_redirect(array("get_params" => array("uname" => $this->username, "realm" => $this->realm, "pass" => $this->password, "redir_id" => $this->opt['instance_id'])));
     }
     $_SESSION['auth'] = new $this->opt['auth_class']();
     $_SESSION['auth']->authenticate_as($this->uid, $this->username, $this->did, $this->realm);
     if (is_array($this->perms)) {
         $_SESSION['auth']->set_perms($this->perms);
     }
     sw_log("User login: redirecting to page: " . $this->opt['redirect_on_login'], PEAR_LOG_DEBUG);
     $this->controler->change_url_for_reload($this->opt['redirect_on_login']);
     if ($this->opt['set_lang_attr']) {
         $an =& $config->attr_names;
         /* get the lang attribute */
         $ua_handler =& User_Attrs::singleton($this->uid);
         if (false === ($u_lang = $ua_handler->get_attribute($an['lang']))) {
             return false;
         }
         /* if lang attribute is not set, set it */
         if (is_null($u_lang)) {
             $u_lang = $_SESSION['lang'];
             /* get the attr_type of the lang attribute */
             $at_handler =& Attr_types::singleton();
             if (false === ($lang_type = $at_handler->get_attr_type($an['lang']))) {
                 return false;
             }
             if (is_null($lang_type)) {
                 ErrorHandler::add_error("Type of attribute 'lang' doesn't exists");
                 return false;
             }
             /* format the value */
             $lang_type->check_value($u_lang);
             /* store lang into DB */
             if (false === $ua_handler->set_attribute($an['lang'], $u_lang)) {
                 return false;
             }
         }
     }
     if ($this->opt['unset_lang_on_login']) {
         unset($_SESSION['lang']);
     }
     return true;
 }
Exemplo n.º 14
0
 function create_html_form(&$errors)
 {
     global $config;
     parent::create_html_form($errors);
     $an =& $config->attr_names;
     $ua =& User_Attrs::singleton($this->user_id->get_uid());
     if (false === ($user_attrs = $ua->get_attributes())) {
         return false;
     }
     $this->privileges['is_admin'] = isset($user_attrs[$an['is_admin']]) ? $user_attrs[$an['is_admin']] : false;
     $this->privileges['hostmaster'] = isset($user_attrs[$an['is_hostmaster']]) ? $user_attrs[$an['is_hostmaster']] : false;
     $this->privileges['acl_control'] = isset($user_attrs[$an['acl_control']]) ? $user_attrs[$an['acl_control']] : array();
     /* add form elements */
     foreach ($config->grp_values as $row) {
         $this->f->add_element(array("type" => "checkbox", "name" => "pr_chk_" . $row, "checked" => in_array($row, $this->privileges['acl_control']) ? "1" : "0", "value" => "1"));
     }
     $this->f->add_element(array("type" => "checkbox", "name" => "pr_chk_hostmaster", "checked" => isset($this->privileges['hostmaster'][0]) and $this->privileges['hostmaster'][0] ? "1" : "0", "value" => "1"));
     $this->f->add_element(array("type" => "checkbox", "name" => "pr_chk_is_admin", "checked" => isset($this->privileges['is_admin'][0]) and $this->privileges['is_admin'][0] ? "1" : "0", "value" => "1", "extrahtml" => "onclick='disable_chk(this);'"));
     $js = "\n\t\t\t/* disable other checkboxes if is_admin checkbox is not checked */\n\t\t\n\t\t\tfunction disable_chk(is_admin){\n\t\t\t\tf=is_admin.form;\n\n\t\t\t\tdis = !is_admin.checked;\n\n\t\t\t\tif (f.pr_chk_hostmaster)        f.pr_chk_hostmaster.disabled = dis;\n\t\t";
     foreach ($config->grp_values as $row) {
         $js .= "\n\t\t\t\tif (f.pr_chk_" . $row . ") f.pr_chk_" . $row . ".disabled = dis;";
     }
     $js .= "\n\t\t\t}\n\n\t\t\t/* disable other checkboxes if is_admin checkbox is not checked */\n\t\t\tdisable_chk(document." . $this->opt['form_name'] . ".pr_chk_is_admin);\n\n\t\t";
     $this->controler->set_onload_js($js);
 }
 /**
  *  Mark user account as deleted
  *
  *	Possible options:
  *	  - uid	(string) - uid of user which should be enabled/disabled
  *	    this option is required (default: null)
  *	  - delete_asap (bool) - if is true, user will be deleted as soon 
  *	    as possible (on next cleaning of database) (default: false)
  *	  - undelete (bool) - undelete user (default: false)
  *      
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function mark_user_deleted($opt)
 {
     global $config, $data;
     $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;
     $tu_name =& $config->data_sql->uri->table_name;
     /* col names */
     $cc =& $config->data_sql->credentials->cols;
     $ca =& $config->data_sql->user_attrs->cols;
     $cu =& $config->data_sql->uri->cols;
     /* flags */
     $fc =& $config->data_sql->credentials->flag_values;
     $fa =& $config->data_sql->user_attrs->flag_values;
     $fu =& $config->data_sql->uri->flag_values;
     $an =& $config->attr_names;
     $o_uid = isset($opt['uid']) ? $opt['uid'] : null;
     $o_del_asap = isset($opt['delete_asap']) ? (bool) $opt['delete_asap'] : false;
     $o_undelete = isset($opt['undelete']) ? (bool) $opt['undelete'] : false;
     if (is_null($o_uid)) {
         ErrorHandler::log_errors(PEAR::raiseError('subscriber which should be marked as deleted is not specified'));
         return false;
     }
     if (false === $this->transaction_start()) {
         return false;
     }
     $user_attrs =& User_Attrs::singleton($o_uid);
     if ($o_undelete) {
         if (false === $user_attrs->unset_attribute($an['deleted_ts'])) {
             $this->transaction_rollback();
             return false;
         }
     } else {
         $val = $o_del_asap ? 1 : time();
         if (false === $user_attrs->set_attribute($an['deleted_ts'], $val)) {
             $this->transaction_rollback();
             return false;
         }
     }
     $q = "update " . $tc_name . " set ";
     if ($o_undelete) {
         $q .= $cc->flags . " = " . $cc->flags . " & ~" . $fc['DB_DELETED'];
     } else {
         $q .= $cc->flags . " = " . $cc->flags . " | " . $fc['DB_DELETED'];
     }
     $q .= " where " . $cc->uid . " = " . $this->sql_format($o_uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     $q = "update " . $ta_name . " set ";
     if ($o_undelete) {
         $q .= $ca->flags . " = " . $ca->flags . " & ~" . $fa['DB_DELETED'];
     } else {
         $q .= $ca->flags . " = " . $ca->flags . " | " . $fa['DB_DELETED'];
     }
     $q .= " where " . $ca->uid . " = " . $this->sql_format($o_uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     $q = "update " . $tu_name . " set ";
     if ($o_undelete) {
         $q .= $cu->flags . " = " . $cu->flags . " & ~" . $fu['DB_DELETED'];
     } else {
         $q .= $cu->flags . " = " . $cu->flags . " | " . $fu['DB_DELETED'];
     }
     $q .= " where " . $cu->uid . " = " . $this->sql_format($o_uid, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     if (false === $this->transaction_commit()) {
         return false;
     }
     return true;
 }
 function action_confirm_reg(&$errors)
 {
     global $data, $config, $lang_str;
     if (isset($_GET['pr'])) {
         $proxy['proxy'] = base64_decode($_GET['pr']);
         if ($proxy['proxy']) {
             if (false === $data->set_home_proxy($proxy['proxy'])) {
                 return false;
             }
         }
     }
     if (isModuleLoaded('xxl') and !$proxy['proxy']) {
         $errors[] = $lang_str['err_reg_conf_not_exists_conf_num'];
         return false;
     }
     $an =& $config->attr_names;
     /* get uid */
     $o = array('name' => $an['confirmation'], 'value' => $this->nr);
     if (false === ($attrs = $data->get_attr_by_val("user", $o))) {
         return false;
     }
     if (empty($attrs[0]['id'])) {
         $this->wrong_nr = true;
         ErrorHandler::add_error($lang_str['err_reg_conf_not_exists_conf_num']);
         return false;
     }
     $uid = $attrs[0]['id'];
     /* get did - for the case that domain has been created during registration */
     $o = array('name' => $an['confirmation'], 'value' => $this->nr);
     if (false === ($attrs = $data->get_attr_by_val("domain", $o))) {
         return false;
     }
     $did = null;
     if (!empty($attrs[0]['id'])) {
         $did = $attrs[0]['id'];
     }
     if (false === $data->transaction_start()) {
         return false;
     }
     // first enable domain
     if (!is_null($did)) {
         $dm_h =& DomainManipulator::singleton($did);
         if (false === $dm_h->enable_domain(true)) {
             return false;
         }
         $domain_attrs =& Domain_Attrs::singleton($did);
         if (false === $domain_attrs->unset_attribute($an['confirmation'])) {
             $data->transaction_rollback();
             return false;
         }
         if (false === $domain_attrs->unset_attribute($an['pending_ts'])) {
             $data->transaction_rollback();
             return false;
         }
     }
     $o = array("uid" => $uid, "disable" => false);
     if (false === $data->enable_user($o)) {
         $data->transaction_rollback();
         return false;
     }
     $user_attrs =& User_Attrs::singleton($uid);
     if (false === $user_attrs->unset_attribute($an['confirmation'])) {
         $data->transaction_rollback();
         return false;
     }
     if (false === $user_attrs->unset_attribute($an['pending_ts'])) {
         $data->transaction_rollback();
         return false;
     }
     if (false === $data->transaction_commit()) {
         return false;
     }
     if ($this->opt['setup_jabber_account']) {
         ErrorHandler::add_error("Registration in jabber not maintained, please set \$config->setup_jabber_account=false in config file.");
         # Jabber Gateway registration
         $res = reg_jab($user_id->uname);
         if ($res != 0) {
             $res = $res + 1;
             log_errors(PEAR::raise_error("jabber registration failed: <" . $user_id->uname . "> [" . $res . "]"), $errors);
             return array("confirmation_ok=1", "conf_jabber_failed=1");
         }
     }
     return array("confirmation_ok=1");
 }