function init($conf)
 {
     $complex_conf = array('autoInit' => false, 'session' => array('name' => $conf['auth_session_name'], 'varname' => 'ludata'), 'login' => array('method' => 'post', 'username' => 'handle', 'password' => 'passwd', 'force' => false, 'function' => '', 'remember' => 'rememberMe'), 'logout' => array('trigger' => 'logout', 'redirect' => $conf['auth_exit_page'], 'destroy' => true, 'method' => 'get', 'function' => ''), 'authContainers' => array(array('type' => 'DB', 'name' => 'DB_Local', 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'dsn' => $conf['auth_dsn'], 'allowDuplicateHandles' => 0, 'authTable' => 'liveuser_users', 'authTableCols' => array('user_id' => 'auth_user_id', 'handle' => 'handle', 'passwd' => 'passwd', 'lastlogin' => 'lastlogin', 'is_active' => 'is_active'))), 'permContainer' => array('dsn' => $conf['auth_dsn'], 'type' => 'DB_Medium', 'prefix' => 'liveuser_'));
     $this->auth_handler_ = LiveUser::singleton($complex_conf);
     $error = $this->auth_handler_->init();
     return $error;
 }
示例#2
0
function removeUser($permId)
{
    global $auth, $perm;
    if (is_object($auth) && is_object($perm)) {
        $authData = $perm->getAuthUserId($permId);
        if (LiveUser::isError($authData)) {
            return $authData;
        }
        $result = $auth->removeUser($authData['auth_user_id']);
        if (LiveUser::isError($result)) {
            return $result;
        }
        return $perm->removeUser($permId);
    }
    return FALSE;
}
示例#3
0
                    $tpl->touchBlock('idled');
                    break;
                case LIVEUSER_STATUS_EXPIRED:
                    $tpl->touchBlock('expired');
                    break;
                default:
                    $tpl->touchBlock('failure');
                    break;
            }
        }
    }
    $tpl->show();
    exit;
}
// Create new LiveUser (LiveUser) object.
// We´ll only use the auth container, permissions are not used.
$LU =& LiveUser::factory($LUOptions);
$LU->dispatcher->addObserver('forceLogin', 'forceLogin');
if (!$LU->init()) {
    var_dump($LU->getErrors());
    die;
}
$logout = array_key_exists('logout', $_REQUEST) ? $_REQUEST['logout'] : false;
if ($logout) {
    $LU->logout(true);
    showLoginForm($LU);
}
define('AREA_NEWS', 1);
define('RIGHT_NEWS_NEW', 1);
define('RIGHT_NEWS_CHANGE', 2);
define('RIGHT_NEWS_DELETE', 3);
示例#4
0
 /**
  * Handles the retrieval of the login data from the rememberMe cookie.
  *
  * @return bool true on success or false on failure
  *
  * @access public
  */
 function readRememberCookie()
 {
     if (!array_key_exists('cookie', $this->_options) || !array_key_exists($this->_options['cookie']['name'], $_COOKIE)) {
         return false;
     }
     if (strlen($_COOKIE[$this->_options['cookie']['name']]) < 65 || preg_match('/[^a-z0-9]/i', substr($_COOKIE[$this->_options['cookie']['name']], 0, 64))) {
         $this->deleteRememberCookie();
     }
     $cookieData = $_COOKIE[$this->_options['cookie']['name']];
     $store_id = substr($cookieData, 0, 32);
     $passwd_id = substr($cookieData, 32, 32);
     $handle = substr($cookieData, 64);
     $dir = $this->_options['cookie']['savedir'];
     $fh = @fopen($dir . '/' . $store_id . '.lu', 'rb');
     if (!$fh) {
         $this->deleteRememberCookie();
         $this->stack->push(LIVEUSER_ERROR_CONFIG, 'exception', array(), 'Cannot open file for reading');
         return false;
     }
     $fields = fread($fh, 4096);
     fclose($fh);
     if (!$fields) {
         $this->deleteRememberCookie();
         $this->stack->push(LIVEUSER_ERROR_CONFIG, 'exception', array(), 'Cannot read file');
         return false;
     }
     $serverData = @unserialize(LiveUser::cryptRC4($fields, $this->_options['cookie']['secret'], false));
     if (!is_array($serverData) || count($serverData) != 2) {
         $this->deleteRememberCookie();
         $this->stack->push(LIVEUSER_ERROR_COOKIE, 'exception', array(), 'Incorrect array structure');
         return false;
     }
     if ($serverData[0] != $passwd_id) {
         // Delete cookie if it's not valid, keeping it messes up the
         // authentication process
         $this->deleteRememberCookie();
         $this->stack->push(LIVEUSER_ERROR_COOKIE, 'error', array(), 'Passwords hashes do not match in cookie in LiveUser::readRememberMeCookie()');
         return false;
     }
     return array('handle' => $handle, 'passwd' => $serverData[1]);
 }
示例#5
0
error_reporting(E_ALL);
// right definitions
define('ACCESS', 3);
define('LAUNCH_ATOMIC_BOMB', 4);
define('FLY_ALIEN_SPACE_CRAFT', 5);
// Include configuration.
require_once 'conf.php';
// The error handling stuff is not needed and used only for debugging
// while LiveUser is not yet mature
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'eHandler');
function eHandler($errObj)
{
    echo '<hr /><span style="color: red;">' . $errObj->getMessage() . ':<br />' . $errObj->getUserinfo() . '</span><hr />';
}
// Create new LiveUser object
$LU = LiveUser::factory($liveuserConfig);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Example Area51</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    <!--
    table {
        background-color: #CCCCCC;
        border-color: 1px solid #000;
    }
    body {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 12px;
示例#6
0
 /**
  * Gets the auth ID of a user.
  *
  * @access  public
  * @param   string  Perm user ID.
  * @return  mixed   Permission ID or MDB2 error.
  */
 function getAuthUserId($permId)
 {
     return LiveUser::raiseError(LIVEUSER_NOT_SUPPORTED, null, null, 'Method not supported by this container');
 }
示例#7
0
 /**
  * Finds and gets full userinfo by filtering inside the auth container
  *
  * @param  array auth params (as for getUsers() from the auth container
  * @return array|bool Array with userinfo if found on success or false otherwise
  *
  * @access private
  */
 function _getUsersByAuth($authParams = array())
 {
     if (!is_object($this->auth) || !is_object($this->perm)) {
         $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', array('msg' => 'Perm and/or Auth container not set.'));
         return false;
     }
     $first = $authParams['select'] == 'row';
     $authUsers = $this->auth->getUsers($authParams);
     if (!$authUsers) {
         return $authUsers;
     }
     if ($first) {
         $authUsers = array($authUsers);
     }
     $users = array();
     foreach ($authUsers as $authData) {
         $permParams = array('filters' => array('auth_user_id' => $authData['auth_user_id'], 'auth_container_name' => $this->authContainerName), 'select' => 'row');
         $permData = $this->perm->getUsers($permParams);
         if (!$permData) {
             continue;
         }
         if ($first) {
             return LiveUser::arrayMergeClobber($authData, $permData);
         }
         $users[] = LiveUser::arrayMergeClobber($authData, $permData);
     }
     return $users;
 }
示例#8
0
 /**
  * Encrypts a password for storage in a backend container.
  * Uses the algorithm defined in the passwordEncryptionMode property.
  *
  * @param string  encryption type
  * @return string the encrypted password
  *
  * @access public
  */
 function encryptPW($plainPW)
 {
     return LiveUser::encryptPW($plainPW, $this->passwordEncryptionMode, $this->secret);
 }
示例#9
0
 /**
  * Return a textual error message for a LiveUser error code.
  *
  * @access  public
  * @param   int     error code
  * @return  string  error message
  */
 function errorMessage($value)
 {
     // make the variable static so that it only has to do the defining on the first call
     static $errorMessages;
     // define the varies error messages
     if (!isset($errorMessages)) {
         $errorMessages = array(LIVEUSER_ERROR => 'Unknown error', LIVEUSER_ERROR_NOT_SUPPORTED => 'Feature not supported', LIVEUSER_ERROR_CONFIG => 'Config file error', LIVEUSER_ERROR_MISSING_DEPS => 'Missing package depedencies', LIVEUSER_ERROR_MISSING_LOGINFUNCTION => 'Login function not found', LIVEUSER_ERROR_MISSING_LOGOUTFUNCTION => 'Logout function not found', LIVEUSER_ERROR_COOKIE => 'Remember Me cookie error', LIVEUSER_STATUS_EXPIRED => 'User session has expired', LIVEUSER_STATUS_ISINACTIVE => 'User is set to inactive', LIVEUSER_STATUS_PERMINITERROR => 'Cannot instantiate permission container', LIVEUSER_STATUS_AUTHINITERROR => 'Cannot instantiate authentication configuration', LIVEUSER_STATUS_AUTHNOTFOUND => 'Cannot retrieve Auth object from session', LIVEUSER_STATUS_UNKNOWN => 'Something went wrong in whatever you were trying to do', LIVEUSER_STATUS_LOGGEDOUT => 'User was logged out correctly');
     }
     // If this is an error object, then grab the corresponding error code
     if (LiveUser::isError($value)) {
         $value = $value->getCode();
     }
     // return the textual error message corresponding to the code
     return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[LIVEUSER_ERROR];
 }
示例#10
0
 /**
  * Gets all users with handle, passwd, authId,
  * lastlogin, is_active and individual rights.
  *
  * The array will look like this:
  * <code>
  * $userData[0]['auth_user_id']       = 'wujha433gawefawfwfiuj2ou9823r98h';
  *             ['handle']       = 'myLogin';
  *             ['passwd']     = 'd346gs2gwaeiuhaeiuuweijfjuwaefhj';
  *             ['lastlogin']    = 1254801292; (Unix timestamp)
  *             ['is_active']     = 1; (1 = yes, 0 = no)
  * </code>
  *
  * @access  public
  * @param   array  filters to apply to fetched data
  * @param   array  custom fields you wane to be returned
  * @return  mixed  Array with user data or error object.
  */
 function getUsers($filters = array(), $customFields = array())
 {
     return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTED, null, null, 'getUsers(): Method not supported by this container');
 }
示例#11
0
$as->requireAuth();
$saml_attributes = $as->getAttributes();
session_write_close();
// now - let's continue with the session handling that would normally be done
// by Maharas init.php
// the main thin is that it sets the session cookie name back to what it should be
// session_name(get_config('cookieprefix') . 'mahara');
// and starts the session again
// ***********************************************************************
// copied from original init.php
// ***********************************************************************
// Only do authentication once we know the page theme, so that the login form
// can have the correct theming.
require_once dirname(dirname(dirname(__FILE__))) . '/auth/lib.php';
$SESSION = Session::singleton();
$USER = new LiveUser();
$THEME = new Theme($USER);
// The installer does its own auth_setup checking, because some upgrades may
// break logging in and so need to allow no logins.
if (!defined('INSTALLER')) {
    auth_setup();
}
if (get_config('siteclosed')) {
    if ($USER->admin) {
        if (get_config('disablelogin')) {
            $USER->logout();
        } else {
            if (!defined('INSTALLER')) {
                redirect('/admin/upgrade.php');
            }
        }
示例#12
0
    }
} else {
    $liveuserConfig['login']['username'] = '';
    $liveuserConfig['login']['password'] = '';
}
/*  Setting $liveuserConfig['login']['username'] and $liveuserConfig['login']['password']
*   to '' causes the login to be ignored by the LiveUser system.
*   In Liveuser.php during the tryLogin function on line 665,  
*   it sees the handle is empty.  It then tries to login based on a cookie,
*   but in line 171 that _options['cookie'] is not set so it goes to line 693
*   sees that _options['login']['username'] and _options['login']['password'] 
*   are empty, tries to run _options['login']['function'] which is also set to ''
*   so it fails out of the if and hits line 715 where it returns false negating the login.
*/
// instantiate a LiveUser object from the config array
$liveuser =& LiveUser::factory($liveuserConfig);
if (isset($_REQUEST['username']) && !isset($_REQUEST['cancel_login'])) {
    if ($totalDelay > EWIKI_LIVEUSER_LOGIN_SHUTDOWN_DELAY) {
        $liveuser->logout();
    } else {
        //Get data as we would for logging
        $loginData = ewiki_liveuser_get_login_data();
        liveuser_loglogin();
        //Tests login, updates $username
        if ($username = $liveuser->getHandle()) {
            //Clear delay flags with matching handle, php session, ssl session, and ip
            // (today only)
            $liveuserDB->query('
                UPDATE `liveweb_login_log` set delay=0 
                WHERE time> DATE_SUB(NOW(), INTERVAL 1 DAY) 
                AND auth_user_handle=? AND php_session_id=?
示例#13
0
<?php

$dsn = 'mysql://*****:*****@localhost/lutest';
error_reporting(E_ALL);
$DOC_ROOT = $_SERVER['DOCUMENT_ROOT'];
$USER_DIR = '/martin';
$PROJECT_NAME = '/hem';
$APP_ROOT = $DOC_ROOT . $USER_DIR . $PROJECT_NAME;
$PEAR_DIR = $APP_ROOT . '/pear';
$APP_FRAMEWORK_DIR = $APP_ROOT . '/framework';
$PATH = $PEAR_DIR . ":" . $APP_FRAMEWORK_DIR;
ini_set('include_path', ':' . $PATH . ':' . ini_get('include_path'));
$conf = array('autoInit' => true, 'session' => array('name' => 'PHPSESSION', 'varname' => 'ludata'), 'login' => array('method' => 'post', 'username' => 'handle', 'password' => 'passwd', 'force' => false, 'function' => '', 'remember' => 'rememberMe'), 'logout' => array('trigger' => 'logout', 'redirect' => 'home.php', 'destroy' => true, 'method' => 'get', 'function' => ''), 'authContainers' => array(array('type' => 'DB', 'name' => 'DB_Local', 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'dsn' => $dsn, 'allowDuplicateHandles' => 0, 'authTable' => 'liveuser_users', 'authTableCols' => array('required' => array('auth_user_id' => array('type' => 'text', 'name' => 'auth_user_id'), 'handle' => array('type' => 'text', 'name' => 'handle'), 'passwd' => array('type' => 'text', 'name' => 'passwd')), 'optional' => array('lastlogin' => array('type' => 'timestamp', 'name' => 'lastlogin'), 'is_active' => array('type' => 'boolean', 'name' => 'is_active'), 'owner_user_id' => array('type' => 'integer', 'name' => 'owner_user_id'), 'owner_group_id' => array('type' => 'integer', 'name' => 'owner_group_id')), 'custom' => array()))), 'permContainer' => array('dsn' => $dsn, 'type' => 'DB_Medium', 'prefix' => 'liveuser_'));
require_once 'LiveUser.php';
$LU =& LiveUser::factory($conf);
示例#14
0
 /**
  * Finds and gets userinfo by his userID, customFields can
  *  also be gotten
  *
  * Untested: it most likely doesn't work.
  *
  * @access public
  * @param mixed User ID
  * @param   array  custom fields you want to be returned. If not specified
  *                 the basic set of fields is returned. The keys are the
  *                 names and the values
  * @return mixed Array with userinfo if found else error object
  */
 function getUser($userId, $customFields = array())
 {
     if (is_object($this->auth) && is_object($this->perm)) {
         if (is_array($this->auth->authTableCols['user_id'])) {
             $user_auth_id = $this->auth->authTableCols['user_id']['name'];
             $type = $this->auth->authTableCols['user_id']['type'];
         } else {
             $user_auth_id = $this->auth->authTableCols['user_id'];
             $type = '';
         }
         $filters = array($user_auth_id => array('op' => '=', 'value' => $userId, 'cond' => '', 'type' => $type));
         $search = $this->auth->getUsers($filters, $customFields);
         if (LiveUser::isError($search)) {
             return $search;
         }
         return $search;
     }
     return LiveUser::raiseError(LIVEUSER_ERROR, null, null, 'Perm or Auth container couldn\\t be started.');
 }
示例#15
0
 /**
  * Return a textual error message for a LiveUser error code.
  *
  * @access  public
  * @param   mixed   error code or error object
  * @return  string  error message
  */
 function errorMessage($value)
 {
     // make the variable static so that it only has to do the defining on the first call
     static $errorMessages;
     // define the varies error messages
     if (!isset($errorMessages)) {
         $errorMessages = array(LIVEUSER_ERROR => 'Unknown error', LIVEUSER_ERROR_NOT_SUPPORTED => 'Feature not supported', LIVEUSER_ERROR_CONFIG => 'Config file error', LIVEUSER_ERROR_MISSING_DEPS => 'Missing package depedencies', LIVEUSER_ERROR_MISSING_LOGINFUNCTION => 'Login function not found', LIVEUSER_ERROR_MISSING_LOGOUTFUNCTION => 'Logout function not found', LIVEUSER_ERROR_COOKIE => 'Remember Me cookie error');
     }
     // If this is an error object, then grab the corresponding error code
     if (LiveUser::isError($value)) {
         $value = $value->getCode();
     }
     // return the textual error message corresponding to the code
     return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[LIVEUSER_ERROR];
 }
示例#16
0
<?php

require_once dirname(__FILE__) . '/bundled-libs/MDB2/MDB2.php';
require_once dirname(__FILE__) . '/bundled-libs/LiveUser/LiveUser.php';
require_once 'config.php';
$dsn = array('phptype' => $config['database']['dbengine'], 'username' => $config['database']['dbusername'], 'password' => $config['database']['dbpassword'], 'hostspec' => $config['database']['dbhostname'], 'database' => $config['database']['dbname']);
$db =& MDB2::connect($dsn);
if (PEAR::isError($db)) {
    echo $db->getMessage() . ' ' . $db->getUserInfo();
}
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$conf = array('debug' => true, 'session' => array('name' => 'PHPSESSION', 'varname' => 'ludata'), 'login' => array('force' => false), 'logout' => array('destroy' => true), 'authContainers' => array(array('type' => 'MDB2', 'expireTime' => 3600, 'idleTime' => 1800, 'allowDuplicateHandles' => 0, 'allowEmptyPasswords' => 0, 'passwordEncryptionMode' => 'MD5', 'storage' => array('dsn' => $dsn, 'alias' => array('lastlogin' => 'last_login', 'is_active' => 'is_active', 'owner_user_id' => 'owner_user_id', 'owner_group_id' => 'owner_group_id', 'email' => 'email'), 'fields' => array('lastlogin' => 'timestamp', 'is_active' => 'boolean', 'owner_user_id' => 'integer', 'owner_group_id' => 'integer', 'email' => 'text'), 'tables' => array('users' => array('fields' => array('lastlogin' => false, 'is_active' => false, 'owner_user_id' => false, 'owner_group_id' => false, 'email' => false)))))));
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$LU = LiveUser::singleton($conf);
if (!$LU->init()) {
    var_dump($LU->getErrors());
    die;
}
$handle = array_key_exists('handle', $_REQUEST) ? $_REQUEST['handle'] : null;
$passwd = array_key_exists('passwd', $_REQUEST) ? $_REQUEST['passwd'] : null;
$logout = array_key_exists('logout', $_REQUEST) ? $_REQUEST['logout'] : false;
if ($logout) {
    //  $LU->logout(true);
    $LU->logout(false);
    // does not delete the RememberMe cookie
} elseif (!$LU->isLoggedIn() || $handle && $LU->getProperty('handle') != $handle) {
    if (!$handle) {
        $LU->login(null, null, true);
    } else {
        $LU->login($handle, $passwd, false);
    }
示例#17
0
}
$saml_attributes = $as->getAttributes();
@session_write_close();
// now - let's continue with the session handling that would normally be done
// by Maharas init.php
// the main thin is that it sets the session cookie name back to what it should be
// session_name(get_config('cookieprefix') . 'mahara');
// and starts the session again
// ***********************************************************************
// copied from original init.php
// ***********************************************************************
// Only do authentication once we know the page theme, so that the login form
// can have the correct theming.
require_once dirname(dirname(dirname(__FILE__))) . '/auth/lib.php';
$SESSION = Session::singleton();
$USER = new LiveUser();
$THEME = new Theme($USER);
// ***********************************************************************
// END of copied stuff from original init.php
// ***********************************************************************
// restart the session for Mahara
@session_start();
if (!$SESSION->get('wantsurl')) {
    $SESSION->set('wantsurl', preg_replace('/\\&login$/', '', $wantsurl));
}
// now start the hunt for the associated authinstance for the organisation attached to the saml_attributes
global $instance;
$instance = auth_saml_find_authinstance($saml_attributes);
// if we don't have an auth instance then this is a serious failure
if (!$instance) {
    throw new UserNotFoundException(get_string('errorbadinstitution', 'auth.saml'));
示例#18
0
文件: init.php 项目: rboyatt/mahara
    exit("Site closed for upgrade.\n");
}
if (!defined('CLI')) {
    header('Content-type: text/html; charset=UTF-8');
    // Ensure that, by default, the response is not cached
    header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
    header('Expires: ' . gmdate('D, d M Y H:i:s', 507686400) . ' GMT');
    header('Pragma: no-cache');
    // Prevent clickjacking through iframe tags
    header('X-Frame-Options: SAMEORIGIN');
}
// Only do authentication once we know the page theme, so that the login form
// can have the correct theming.
require_once 'auth/lib.php';
$SESSION = Session::singleton();
$USER = new LiveUser();
if (function_exists('local_init_user')) {
    local_init_user();
}
// try to set the theme, or catch the thrown exception (eg if the name is invalid)
try {
    $THEME = new Theme($USER);
} catch (SystemException $exception) {
    // set the theme to 'default' and put up an error message
    $THEME = new Theme('raw');
    $SESSION->add_error_msg($exception->getMessage());
}
if ($siteclosedforupgrade && $USER->admin) {
    if (get_config('disablelogin')) {
        $USER->logout();
    } else {
示例#19
0
 /**
  *
  *
  *
  * @param array &$storageConf Array with the storage configuration
  * @return boolean true on success, false on failure.
  *
  * @access public
  */
 function init(&$storageConf)
 {
     if (is_array($storageConf)) {
         $keys = array_keys($storageConf);
         foreach ($keys as $key) {
             if (isset($this->{$key})) {
                 $this->{$key} =& $storageConf[$key];
             }
         }
     }
     require_once 'LiveUser/Perm/Storage/Globals.php';
     if (empty($this->tables)) {
         $this->tables = $GLOBALS['_LiveUser']['perm']['tables'];
     } else {
         $this->tables = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['perm']['tables'], $this->tables);
     }
     if (empty($this->fields)) {
         $this->fields = $GLOBALS['_LiveUser']['perm']['fields'];
     } else {
         $this->fields = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['perm']['fields'], $this->fields);
     }
     if (empty($this->alias)) {
         $this->alias = $GLOBALS['_LiveUser']['perm']['alias'];
     } else {
         $this->alias = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['perm']['alias'], $this->alias);
     }
     return true;
 }
示例#20
0
 /**
  * Constructor
  *
  * @param  mixed $connectoptions  connection options
  * @return void
  */
 function &LiveUser_Perm_Container_XML_Simple(&$connectOptions)
 {
     if (is_array($connectOptions)) {
         foreach ($connectOptions as $key => $value) {
             if (isset($this->{$key})) {
                 $this->{$key} = $value;
             }
         }
         if (!is_file($this->file)) {
             if (is_file(getenv('DOCUMENT_ROOT') . $this->file)) {
                 $this->file = getenv('DOCUMENT_ROOT') . $this->file;
             } else {
                 return LiveUser::raiseError(LIVEUSER_ERROR_MISSING_DEPS, null, null, "Perm initialisation failed. Can't find xml file.");
             }
         }
         if ($this->file) {
             if (class_exists('XML_Tree')) {
                 $tree =& new XML_Tree($this->file);
                 $err =& $tree->getTreeFromFile();
                 if (PEAR::isError($err)) {
                     return $err;
                 } else {
                     $this->tree = $tree;
                     $this->init_ok = true;
                 }
             } else {
                 $this->_error = true;
                 return LiveUser::raiseError(LIVEUSER_ERROR_MISSING_DEPS, null, null, "Perm initialisation failed. Can't find XML_Tree class.");
             }
         } else {
             return LiveUser::raiseError(LIVEUSER_ERROR_MISSING_DEPS, null, null, "Perm initialisation failed. Can't find xml file.");
         }
     }
 }
示例#21
0
 /**
  * Assign subgroup to parent group.
  *
  * First checks that the child group does not have a parent group
  * already assigned to it. If so it returns an error object
  *
  * @access public
  * @param  integer id of parent group
  * @param  integer id of child group
  * @return mixed boolean, MDB2 Error object or LiveUser Error Object
  */
 function assignSubgroup($group_id, $subgroup_id)
 {
     $query = 'SELECT subgroup_id FROM
               ' . $this->prefix . 'group_subgroups
               WHERE subgroup_id=' . $this->dbc->quote($subgroup_id, 'integer');
     if (!is_null($this->dbc->queryOne($query))) {
         return LiveUser::raiseError(LIVEUSER_ERROR, null, null, 'Child group already has a parent group');
     }
     $query = 'INSERT INTO
               ' . $this->prefix . 'group_subgroups
               (group_id, subgroup_id)
             VALUES
               (
                 ' . $this->dbc->quote($group_id, 'integer') . ',
                 ' . $this->dbc->quote($subgroup_id, 'integer') . '
               )';
     $result = $this->dbc->query($query);
     return $result;
 }
示例#22
0
 /**
  * Load and initialize the storage container.
  *
  * @param array Array with the configuration
  * @return bool true on success or false on failure
  *
  * @access public
  */
 function init(&$conf)
 {
     if (!array_key_exists('storage', $conf)) {
         $this->stack->push(LIVEUSER_ERROR, 'exception', array('msg' => 'Missing storage configuration array'));
         return false;
     }
     if (is_array($conf)) {
         $keys = array_keys($conf);
         foreach ($keys as $key) {
             if (isset($this->{$key})) {
                 $this->{$key} =& $conf[$key];
             }
         }
     }
     $this->_storage =& LiveUser::storageFactory($conf['storage']);
     if ($this->_storage === false) {
         end($conf['storage']);
         $key = key($conf['storage']);
         $this->stack->push(LIVEUSER_ERROR, 'exception', array('msg' => 'Could not instanciate perm storage container: ' . $key));
         return false;
     }
     return true;
 }
示例#23
0
 function create_registered_user($profilefields = array())
 {
     global $registration, $SESSION, $USER;
     require_once get_config('libroot') . 'user.php';
     db_begin();
     // Move the user record to the usr table from the registration table
     $registrationid = $registration->id;
     unset($registration->id);
     unset($registration->expiry);
     if ($expirytime = get_config('defaultregistrationexpirylifetime')) {
         $registration->expiry = db_format_timestamp(time() + $expirytime);
     }
     $registration->lastlogin = db_format_timestamp(time());
     $authinstance = get_record('auth_instance', 'institution', $registration->institution, 'authname', $registration->authtype ? $registration->authtype : 'internal');
     if (false == $authinstance) {
         throw new ConfigException('No ' . ($registration->authtype ? $registration->authtype : 'internal') . ' auth instance for institution');
     }
     if (!empty($registration->extra)) {
         // Additional user settings were added during confirmation
         $extrafields = unserialize($registration->extra);
     }
     $user = new User();
     $user->active = 1;
     $user->authinstance = $authinstance->id;
     $user->firstname = $registration->firstname;
     $user->lastname = $registration->lastname;
     $user->email = $registration->email;
     $user->username = get_new_username($user->firstname . $user->lastname);
     $user->passwordchange = 1;
     // Points that indicate the user is a "new user" who should be restricted from spammy activities.
     // We count these down when they do good things; when they have 0 they're no longer a "new user"
     if (is_using_probation()) {
         $user->probation = get_config('probationstartingpoints');
     } else {
         $user->probation = 0;
     }
     if ($registration->institution != 'mahara') {
         if (count_records_select('institution', "name != 'mahara'") == 1 || $registration->pending == 2) {
             if (get_config_plugin('artefact', 'file', 'institutionaloverride')) {
                 $user->quota = get_field('institution', 'defaultquota', 'name', $registration->institution);
             }
         }
     }
     create_user($user, $profilefields);
     // If the institution is 'mahara' then don't do anything
     if ($registration->institution != 'mahara') {
         $institutions = get_records_select_array('institution', "name != 'mahara'");
         // If there is only one available, join it without requiring approval
         if (count($institutions) == 1) {
             $user->join_institution($registration->institution);
         } else {
             if ($registration->pending == 2) {
                 if (get_config('requireregistrationconfirm') || get_field('institution', 'registerconfirm', 'name', $registration->institution)) {
                     $user->join_institution($registration->institution);
                 }
             } else {
                 if ($registration->authtype && $registration->authtype != 'internal') {
                     $auth = AuthFactory::create($authinstance->id);
                     if ($auth->weautocreateusers) {
                         $user->join_institution($registration->institution);
                     } else {
                         $user->add_institution_request($registration->institution);
                     }
                 } else {
                     $user->add_institution_request($registration->institution);
                 }
             }
         }
         if (!empty($extrafields->institutionstaff)) {
             // If the user isn't a member yet, this does nothing, but that's okay, it'll
             // only be set after successful confirmation.
             set_field('usr_institution', 'staff', 1, 'usr', $user->id, 'institution', $registration->institution);
         }
     }
     if (!empty($registration->lang) && $registration->lang != 'default') {
         set_account_preference($user->id, 'lang', $registration->lang);
     }
     // Delete the old registration record
     delete_records('usr_registration', 'id', $registrationid);
     db_commit();
     // Log the user in and send them to the homepage
     $USER = new LiveUser();
     $USER->reanimate($user->id, $authinstance->id);
     if (function_exists('local_post_register')) {
         local_post_register($registration);
     }
     $SESSION->add_ok_msg(get_string('registrationcomplete', 'mahara', get_config('sitename')));
     $SESSION->set('resetusername', true);
     redirect();
 }
示例#24
0
 /**
  * Initializes database storage container.
  * Goes through the storage config and turns each value into
  * a var
  *
  * @param array Storage Configuration
  * @param array containing the database structure (tables, fields, alias)
  * @return bool true on success and false on failure
  *
  * @access public
  */
 function init(&$storageConf, $structure)
 {
     if (is_array($storageConf)) {
         $keys = array_keys($storageConf);
         foreach ($keys as $key) {
             if (isset($this->{$key})) {
                 $this->{$key} =& $storageConf[$key];
             }
         }
     }
     if (empty($this->tables)) {
         $this->tables = $structure['tables'];
     } else {
         $this->tables = LiveUser::arrayMergeClobber($structure['tables'], $this->tables);
     }
     if (empty($this->fields)) {
         $this->fields = $structure['fields'];
     } else {
         $this->fields = LiveUser::arrayMergeClobber($structure['fields'], $this->fields);
     }
     if (empty($this->alias)) {
         $this->alias = $structure['alias'];
     } else {
         $this->alias = LiveUser::arrayMergeClobber($structure['alias'], $this->alias);
     }
     return true;
 }
示例#25
0
 /**
  * Gets auth and perm container objects back from session and tries
  * to give them an active database/whatever connection again.
  *
  * @return boolean true on success or false on failure
  *
  * @access private
  */
 function _unfreeze()
 {
     if (!$this->_options['session']['force_start']) {
         if (!isset($_REQUEST[$this->_options['session']['name']])) {
             return false;
         }
         $this->_startSession();
     }
     if (isset($_SESSION[$this->_options['session']['varname']]['auth']) && is_array($_SESSION[$this->_options['session']['varname']]['auth']) && isset($_SESSION[$this->_options['session']['varname']]['auth_name']) && strlen($_SESSION[$this->_options['session']['varname']]['auth_name']) > 0) {
         $containerName = $_SESSION[$this->_options['session']['varname']]['auth_name'];
         $auth =& LiveUser::authFactory($this->_authContainers[$containerName], $containerName);
         if ($auth === false) {
             return false;
         }
         if ($auth->unfreeze($_SESSION[$this->_options['session']['varname']]['auth'])) {
             $auth->backendArrayIndex = $_SESSION[$this->_options['session']['varname']]['auth_name'];
             $this->_auth =& $auth;
             if (isset($_SESSION[$this->_options['session']['varname']]['perm']) && $_SESSION[$this->_options['session']['varname']]['perm']) {
                 $perm =& LiveUser::permFactory($this->_permContainer);
                 if ($perm === false) {
                     return $perm;
                 }
                 if ($this->_options['cache_perm']) {
                     $result = $perm->unfreeze($this->_options['session']['varname']);
                 } else {
                     $result = $perm->mapUser($auth->getProperty('auth_user_id'), $auth->backendArrayIndex);
                 }
                 if ($result) {
                     $this->_perm =& $perm;
                 }
             }
             $this->_status = LIVEUSER_STATUS_UNFROZEN;
             $this->dispatcher->post($this, 'onUnfreeze');
             return true;
         }
     }
     return false;
 }
示例#26
0
 /**
  * Initialize the storage container
  *
  * @param  array   array containing the configuration.
  * @return bool true on success or false on failure
  *
  * @access  public
  */
 function init(&$conf)
 {
     // Sanity check, is there a storage container defined in the configuration.
     if (!array_key_exists('storage', $conf)) {
         $this->stack->push(LIVEUSER_ADMIN_ERROR, 'exception', array('msg' => 'Missing storage configuration array'));
         return false;
     }
     // Set the config to class vars.
     if (is_array($conf)) {
         $keys = array_keys($conf);
         foreach ($keys as $key) {
             if (isset($this->{$key})) {
                 $this->{$key} =& $conf[$key];
             }
         }
     }
     // Create the storage class, if and error occures, add it to the stack and return false.
     $this->_storage =& LiveUser::storageFactory($conf['storage'], 'LiveUser_Admin_Perm_');
     if ($this->_storage === false) {
         end($conf['storage']);
         $key = key($conf['storage']);
         $this->stack->push(LIVEUSER_ERROR, 'exception', array('msg' => 'Could not instanciate perm storage container: ' . $key));
         return false;
     }
     return true;
 }
示例#27
0
<?php

require_once 'MDB.php';
require_once 'LiveUser.php';
// Plase configure the following file according to your environment
$db_user = '******';
$db_pass = '******';
$db_host = 'localhost';
$db_name = 'pear_test';
$dsn = "mysql://{$db_user}:{$db_pass}@{$db_host}/{$db_name}";
$db = MDB::connect($dsn, array('sequence_col_name' => 'id'));
if (MDB::isError($db)) {
    echo $db->getMessage() . ' ' . $db->getUserInfo();
}
$db->setFetchMode(MDB_FETCHMODE_ASSOC);
$conf = array('autoInit' => true, 'session' => array('name' => 'PHPSESSION', 'varname' => 'ludata'), 'login' => array('method' => 'post', 'username' => 'handle', 'password' => 'passwd', 'force' => false, 'function' => '', 'remember' => 'rememberMe'), 'logout' => array('trigger' => 'logout', 'redirect' => 'home.php', 'destroy' => true, 'method' => 'get', 'function' => ''), 'authContainers' => array(array('type' => 'MDB', 'name' => 'MDB_Local', 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'dsn' => $dsn, 'allowDuplicateHandles' => 0, 'authTable' => 'liveuser_users', 'authTableCols' => array('user_id' => array('name' => 'auth_user_id', 'type' => 'text'), 'handle' => array('name' => 'handle', 'type' => 'text'), 'passwd' => array('name' => 'passwd', 'type' => 'text'), 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), 'is_active' => array('name' => 'is_active', 'type' => 'boolean'), 'owner_user_id' => array('name' => 'owner_user_id', 'type' => 'integer'), 'owner_group_id' => array('name' => 'owner_group_id', 'type' => 'integer')))), 'permContainer' => array('dsn' => $dsn, 'type' => 'MDB_Medium', 'prefix' => 'liveuser_'));
function logOut()
{
}
function logIn()
{
}
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$usr = LiveUser::singleton($conf);
$usr->setLoginFunction('logIn');
$usr->setLogOutFunction('logOut');
$e = $usr->init();
if (PEAR::isError($e)) {
    //var_dump($usr);
    die($e->getMessage() . ' ' . $e->getUserinfo());
}
示例#28
0
 /**
  * Add a user
  *
  * @access  public
  * @param   string   $authId    Auth user ID of the user that should be added.
  * @param   string   $authname  Auth container name.
  * @param   int         $type      User type (constants defined in Perm/Common.php) (optional).
  * @param   mixed  $permId    If specificed no new ID will be automatically generated instead
  * @return mixed    string (perm_user_id) or DB Error object
  */
 function addUser($authId, $authName = null, $type = LIVEUSER_USER_TYPE_ID, $permId = null)
 {
     if (!$this->init_ok) {
         return false;
     }
     if (is_null($authName)) {
         return LiveUser::raiseError(LIVEUSER_ERROR, null, null, 'Auth name has to be passed with the function');
     }
     if (is_null($permId)) {
         $permId = $this->dbc->nextId($this->prefix . 'perm_users', true);
     }
     $query = '
         INSERT INTO
             ' . $this->prefix . 'perm_users
             (perm_user_id, auth_user_id, perm_type, auth_container_name)
         VALUES
             (
             ' . (int) $permId . ',
             ' . $this->dbc->quoteSmart($authId) . ',
             ' . (int) $type . ',
             ' . $this->dbc->quoteSmart($authName) . '
             )';
     $result = $this->dbc->query($query);
     if (DB::isError($result)) {
         return $result;
     }
     return $permId;
 }
示例#29
0
 /**
  * Checks if a user with the given perm_user_id exists in the
  * permission container and returns true on success.
  *
  * @access public
  * @param  integer  The users id in the permission table.
  * @return boolean  true if the id was found, else false.
  */
 function userExists($user_id)
 {
     return LiveUser::raiseError(LIVEUSER_ERROR_NOT_SUPPORTED, null, null, 'userExists(): Method not supported by this container');
 }
                'dsn' => $dsn,
                'prefix' => 'liveuser_',
                'alias' => array(),
                'fields' => array(),
                'tables' => array()
                )
            )
        )
    );

// load custom liveuser configuration
$filename = CS_PATH_CONFIG.DIR_SEP.'liveuser_configuration_ext.php';
if (file_exists($filename)) {
    include($filename);
}

require_once(CS_PATH_PEAR_LOCAL.DIR_SEP.'LiveUser'.DIR_SEP.'Admin.php');

$GLOBALS['LiveUser'] = LiveUser::singleton($liveuserConfig);
if (!$GLOBALS['LiveUser']->init()) {
    exit(0);
}
$GLOBALS['LiveUserAdmin'] = LiveUser_Admin::singleton($liveuserConfig);
if (!$GLOBALS['LiveUserAdmin']->init()) {
    exit(0);
}

$g_permissions = $GLOBALS['LiveUserAdmin']->perm->outputRightsConstants('array');

?>