Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/inc/authentication.php
<?php   
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    /**
    @version $Id: authentication.php,v 1.8 2004/04/06 18:26:10 ordnas Exp $
    @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
    @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
    */

	// check if the password file exists
	if(!file_exists($GLOBALS['ZI']['installer_data_dir'].'.htpasswd')){
        if(
            basename(getenv('SCRIPT_FILENAME')) != 'authentication.php' &&
            basename(getenv('SCRIPT_FILENAME')) != 'about.php'){
            // redirect to create a new login
            header('Location: '.$chdir.'authentication.php?mode=setup');
            exit;
        }
	} else {
        if(ZI_INIT_MODE != 'RE'){
            // ask username and password of installation administrator
            //require_once "PEAR.php";
            require_once 'Auth/HTTP.php';
            
            $options['sessionName'] = 'PEAR_Auth';
            $options['dsn']         = $GLOBALS['ZI']['installer_data_dir'].".htpasswd";
            
            $zi_auth = new Auth_HTTP('File', $GLOBALS['ZI']['installer_data_dir'].".htpasswd");
            $zi_auth->setRealm('ZZ/OSS Installer Client (ZIC)');
            $zi_auth->setCancelText(zi_cancel_text());
            $zi_auth->start();
        } else {
            // keep the session going
            session_start();
            
            // a dirty hack on checking if user has properly authenticated
            // with PEAR::Auth previously
            
            // unfortunately, we cannot set the session name when using the file container,
            // because Auth::Auth() grabs the first char of the provided filepath as
            // the session name
            $zi_auth_name = $GLOBALS['ZI']['installer_data_dir'].".htpasswd";
            $zi_auth_name = $zi_auth_name[0];
            
            if(!$_SESSION[$zi_auth_name]['registered'] || !isset($_SESSION[$zi_auth_name]['username'])){
                header('Location: index.php');
                exit;
            }
            
            // the following is a hack to make the getUsername() method available for the footer
            class ZZOSS_InstallerAuth
            {
                function getUsername()
                {
                    $zi_auth_name = $GLOBALS['ZI']['installer_data_dir'].".htpasswd";
                    $zi_auth_name = $zi_auth_name[0];
                    return $_SESSION[$zi_auth_name]['username'];
                }
            }
            
            $zi_auth = new ZZOSS_InstallerAuth;
        }
    }

	function zi_cancel_text()
	{
	  	// create a nice looking cancel text :)
		ob_start();
		?>
        <b>Error 401 - Access denied</b>
        <p>If you don't remember your login data anymore, remove from your server the <em>.htpasswd</em> 
        file in the data directory of the installer. 
        Then create a new login by accessing the installer again.</p>
		<?php
		$cancel_text = ob_get_contents();
		ob_end_clean();
		return $cancel_text;
	}
?>
Return current item: ZZ/OSS Installer