Location: PHPKode > projects > Aukyla Document Management System > plugins/LoginHandlers/passwd_LoginHandler.php
<?php
/*
     passwd_LoginHandler.php, the default passwd login handler.
     Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg

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

     This program 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 General Public License for
     more details.

     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

     For any questions, comments or whatever, you may mail me at: hide@address.com
*/

require_once('Constants.php');
require_once('LoginHandler.php');

/**
 * @brief The default passwd login handler.
 *
 * This login handler uses the passwd and group files that come with Aukyla,
 * they do not use the host system's files.
 */
class passwd_LoginHandler implements LoginHandler
{
	public function login($submittedUsername, $submittedPassword)
	{
		return $this->setUsername($submittedUsername, $submittedPassword);
	}

	public function username()
	{
		return $this->username;
	}

	public function setUsername($submittedUsername, $submittedPassword = false)
	{
		$this->users = array();
		$this->fullName = array();
		$this->userMail = array();
		$this->ipRange = array();

		// open the passwd file
		if(($lines = file(AUKYLA_DIR.'/config/passwd')) === false)
		{
			die('Could not open passwd file!');
		}

		// match username
		$result = false;
		foreach($lines as $line)
		{
			list($username, $fullName, $userMail, $password) = explode(':', trim($line), 4);
			$ipRange = '';
			if(strchr($password, ':'))
			{
				list($password, $ipRange) = explode(':', $password, 2);
			}
			$this->users[] = $username;
			$this->fullName[$username] = $fullName;
			$this->userMail[$username] = $userMail;
			$this->ipRange[$username] = $ipRange;
			if($username == $submittedUsername)
			{
				if($submittedPassword == false ||
				   crypt($submittedPassword, $password) == $password)
				{
					$this->username = $username;

					$result = true;
				}
			}
		}

		if(isset($this->username) == false && $submittedPassword == false)
		{
			$this->username = $submittedUsername;
		}

		return $result;
	}

	public function fullName($username)
	{
		return $this->fullName[$username];
	}

	public function userMail($username)
	{
		return $this->userMail[$username];
	}

	public function ipRange($username)
	{
		return $this->ipRange[$username];
	}

	public function users()
	{
		return $this->users;
	}

	public function usersOfGroup($group)
	{
		if(isset($this->groups) == false)
		{
			$this->initializeGroups();
		}

		if(isset($this->usersOfGroup[$group]) == false)
		{
			return array();
		}
		else
		{
			return $this->usersOfGroup[$group];
		}
	}

	public function groups()
	{
		if(isset($this->groups) == false)
		{
			$this->initializeGroups();
		}

		return $this->groups;
	}

	public function memberGroups($username)
	{
		if(isset($this->memberGroups) == false)
		{
			$this->initializeGroups();
		}

		if(isset($this->memberGroups[$username]) == false)
		{
			return array();
		}
		else
		{
			return $this->memberGroups[$username];
		}
	}

	public function logout()
	{
	}

	private function initializeGroups()
	{
		// open the group file
		if(($lines = file(AUKYLA_DIR.'/config/group')) === false)
		{
			die('Could not open group file!');
		}

		// walk through the group/users relations
		$this->groups = array();
		$this->memberGroups = array();
		foreach($lines as $line)
		{
			list($group, $users) = explode(':', trim($line), 2);
			$this->usersOfGroup[$group] = array();
			$userlist = explode(',', $users);
			foreach($userlist as $user)
			{
				if(isset($this->memberGroups[$user]) == false)
				{
					$this->memberGroups[$user] = array();
				}
				$this->memberGroups[$user][] = $group;
				$this->usersOfGroup[$group][] = $user;
			}
			$this->groups[] = $group;
		}
	}

	private $username;
	private $fullName;
	private $userMail;
	private $ipRange;
	private $users;
	private $groups;
	private $memberGroups;
	private $usersOfGroup;
}

?>
Return current item: Aukyla Document Management System