Diff to loginmanager
| From: | Bertrand Mansion | Date: | Wed, 09 Oct 2002 13:49:46 +0000 |
| Subject: | Diff to loginmanager | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-9962@lists.php.net to get a copy of this message | ||
Hi Markus, Lukas,
Here is a diff for loginmanager so that it accepts PHP config file. XML
config file is still supported and it's backward compatible. I just think
php is much faster and more secure.
2 reasons:
- When calling a .php file from the web, it displays nothing if it's only
composed of variables. If you request a .xml, it will display its content in
most cases.
- Cached content of the xml file will probably go in the /tmp directory for
most users, which is rather insecure.
Here is how the php config file looks like:
<?php
// LiveUser Configuration
$liveuserConfig['sessionName'] = 'PHPSESSION';
$liveuserConfig['sessionVarName'] = 'loginInfo';
$liveuserConfig['handleParamName'] = 'handle';
$liveuserConfig['passwdParamName'] = 'passwd';
$liveuserConfig['loginInputType'] = 'POST';
$liveuserConfig['loginParamName'] = 'what';
$liveuserConfig['logoutParamName'] = 'logout';
// Remember Me
$liveuserConfig['cookieName'] = 'loginInfo';
$liveuserConfig['allowCookies'] = 1;
$liveuserConfig['cookieParamName'] = 'rememberMe';
$liveuserConfig['cookieLifetime'] = 30;
$liveuserConfig['cookieDomain'] = 'localhost';
$liveuserConfig['cookiePath'] = '/';
$liveuserConfig['logoutRedirectURL'] = 'http://www.21st.de/';
// Auth containers
$liveuserConfig['authContainers'][0]['type'] = 'DB';
$liveuserConfig['authContainers'][0]['dsn'] =
'mysql://root:root@localhost/test';
// Perm container
$liveuserConfig['permContainer']['type'] = 'DB_Complex';
$liveuserConfig['permContainer']['dsn'] =
'mysql://root:root@localhost/test';
?>
Index: LoginManager.php =================================================================== RCS file: /repository/pear/Perm_LiveUser/LoginManager.php,v retrieving revision 1.13 diff --unified=3 -r1.13 LoginManager.php --- LoginManager.php 8 Oct 2002 17:04:59 -0000 1.13 +++ LoginManager.php 9 Oct 2002 13:33:38 -0000 @@ -4,6 +4,8 @@ define('LIVEUSER_AREA_COFFEEMAKER', 3); // right defines define('LIVEUSER_RIGHT_MAKE_COFFEE', 6); +$GLOBALS['LIVEUSER_CONFIG_TYPE'] = array('PHP' => '_readConfigFilePHP', + 'XML' => '_readConfigFileXML'); // Include PEAR::XML_Tree class definition require_once("XML/Tree.php"); @@ -42,7 +44,7 @@ * - Pierre-Alain Joye * * Thanks to: - * Björn Schotte, Kristian Köhntopp, Antonio Guerra + * Bjoern Schotte, Kristian Koehntopp, Antonio Guerra * * @author Markus Wolff <wolff@21st.de> * @version $Id: LoginManager.php,v 1.13 2002/10/08 17:04:59 tal Exp $ @@ -207,7 +209,7 @@ * @param string $cacheXML * @access public **/ - function LoginManager($configFile = "", $cacheXML = false) + function LoginManager($configFile = "", $options = false, $type = '') { // Make some basic default settings (in case the config file doesn't // cover everything or doesn't exist @@ -229,8 +231,8 @@ $this->destroySessionOnLogout = true; // Read config file (eventually overrides default settings - if ($configFile != "") { - $this->readConfigFile($configFile, $cacheXML); + if ($configFile != '') { + $this->readConfigFile($configFile, $options, $type); } } @@ -477,6 +479,66 @@ /** * LoginManager::readConfigFile() * + * Reads an configuration file specified in $configFile with the + * proper method depending on file type. + * + * @param string $configFile + * @param mixed $options option for config file parsing + * @param string $type config file type + * @return boolean + * @access public + **/ + function readConfigFile($configFile, $options = false, $type = '') + { + if ($type == '') { + $tokens = explode('.', $configFile); + $type = strtoupper($tokens[count($tokens)-1]); + } + if (in_array($type, array_keys($GLOBALS['LIVEUSER_CONFIG_TYPE']))) { + $methodName = $GLOBALS['CONFIG_CONTAINERS'][$type]; + return $this->$methodName($configFile, $options); + } else { + return false; + //return PEAR::raiseError("Config file type '$type' is not registered in liveUser.", null, PEAR_ERROR_TRIGGER, E_USER_WARNING); + } + } + + /** + * LoginManager::_readConfigFilePHP() + * + * Reads a PHP configuration file specified in $configFile with + * $arrayName as the configuration array and sets the instance vars + * to the values found. + * + * @param string $configFile + * @param string $arrayName name of config array + * @return boolean + * @access public + **/ + function _readConfigFilePHP($configFile, $arrayName) + { + if (is_file($configFile)) { + include_once($configFile); + if (!$arrayName) { + $arrayName = 'liveuserConfig'; + } + if (is_array(${$arrayName})) { + foreach (${$arrayName} as $key => $value) { + $this->$key = $value; + } + return true; + } else { + return false; + //return PEAR::raiseError("Array '$arrayName' does not exist in liveUser config file.", null, PEAR_ERROR_TRIGGER, E_USER_WARNING); + } + } + return false; + //return PEAR::raiseError("Wrong config file path in liveUser::readConfigFile.", null, PEAR_ERROR_TRIGGER, E_USER_WARNING); + } + + /** + * LoginManager::_readConfigFileXML() + * * Reads an XML configuration file specified in $configFile and sets * the class properties accordingly. Not only does this save a lot of * typing, but also allows several applications that use this class to @@ -487,7 +549,7 @@ * @return boolean * @access public **/ - function readConfigFile($configFile, $enableCache=false) + function _readConfigFileXML($configFile, $enableCache = false) { // In the future, this will be cached using PEAR::Cache if // $enableCache is set to true. @@ -564,7 +626,7 @@ return false; } } - + /** * LoginManager::setApplication() *
Index: LoginManager.php =================================================================== RCS file: /repository/pear/Perm_LiveUser/LoginManager.php,v retrieving revision 1.13 diff --unified=3 -r1.13 LoginManager.php --- LoginManager.php 8 Oct 2002 17:04:59 -0000 1.13 +++ LoginManager.php 9 Oct 2002 13:33:38 -0000 @@ -4,6 +4,8 @@ define('LIVEUSER_AREA_COFFEEMAKER', 3); // right defines define('LIVEUSER_RIGHT_MAKE_COFFEE', 6); +$GLOBALS['LIVEUSER_CONFIG_TYPE'] = array('PHP' => '_readConfigFilePHP', + 'XML' => '_readConfigFileXML'); // Include PEAR::XML_Tree class definition require_once("XML/Tree.php"); @@ -42,7 +44,7 @@ * - Pierre-Alain Joye * * Thanks to: - * Björn Schotte, Kristian Köhntopp, Antonio Guerra + * Bjoern Schotte, Kristian Koehntopp, Antonio Guerra * * @author Markus Wolff <wolff@21st.de> * @version $Id: LoginManager.php,v 1.13 2002/10/08 17:04:59 tal Exp $ @@ -207,7 +209,7 @@ * @param string $cacheXML * @access public **/ - function LoginManager($configFile = "", $cacheXML = false) + function LoginManager($configFile = "", $options = false, $type = '') { // Make some basic default settings (in case the config file doesn't // cover everything or doesn't exist @@ -229,8 +231,8 @@ $this->destroySessionOnLogout = true; // Read config file (eventually overrides default settings - if ($configFile != "") { - $this->readConfigFile($configFile, $cacheXML); + if ($configFile != '') { + $this->readConfigFile($configFile, $options, $type); } } @@ -477,6 +479,66 @@ /** * LoginManager::readConfigFile() * + * Reads an configuration file specified in $configFile with the + * proper method depending on file type. + * + * @param string $configFile + * @param mixed $options option for config file parsing + * @param string $type config file type + * @return boolean + * @access public + **/ + function readConfigFile($configFile, $options = false, $type = '') + { + if ($type == '') { + $tokens = explode('.', $configFile); + $type = strtoupper($tokens[count($tokens)-1]); + } + if (in_array($type, array_keys($GLOBALS['LIVEUSER_CONFIG_TYPE']))) { + $methodName = $GLOBALS['CONFIG_CONTAINERS'][$type]; + return $this->$methodName($configFile, $options); + } else { + return false; + //return PEAR::raiseError("Config file type '$type' is not registered in liveUser.", null, PEAR_ERROR_TRIGGER, E_USER_WARNING); + } + } + + /** + * LoginManager::_readConfigFilePHP() + * + * Reads a PHP configuration file specified in $configFile with + * $arrayName as the configuration array and sets the instance vars + * to the values found. + * + * @param string $configFile + * @param string $arrayName name of config array + * @return boolean + * @access public + **/ + function _readConfigFilePHP($configFile, $arrayName) + { + if (is_file($configFile)) { + include_once($configFile); + if (!$arrayName) { + $arrayName = 'liveuserConfig'; + } + if (is_array(${$arrayName})) { + foreach (${$arrayName} as $key => $value) { + $this->$key = $value; + } + return true; + } else { + return false; + //return PEAR::raiseError("Array '$arrayName' does not exist in liveUser config file.", null, PEAR_ERROR_TRIGGER, E_USER_WARNING); + } + } + return false; + //return PEAR::raiseError("Wrong config file path in liveUser::readConfigFile.", null, PEAR_ERROR_TRIGGER, E_USER_WARNING); + } + + /** + * LoginManager::_readConfigFileXML() + * * Reads an XML configuration file specified in $configFile and sets * the class properties accordingly. Not only does this save a lot of * typing, but also allows several applications that use this class to @@ -487,7 +549,7 @@ * @return boolean * @access public **/ - function readConfigFile($configFile, $enableCache=false) + function _readConfigFileXML($configFile, $enableCache = false) { // In the future, this will be cached using PEAR::Cache if // $enableCache is set to true. @@ -564,7 +626,7 @@ return false; } } - + /** * LoginManager::setApplication() *