Location: PHPKode > projects > Liki - The LaTeX Wiki > liki/lib/auth.php
<?php
/*
    Copyright (C) 2004 The Liki Programming Team.
 
    This file is part of Liki.

    Liki 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.

    Liki 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 Liki; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
class auth {
	function auth($_GET,$_POST,&$_SESSION,$likiparms){
		$this->likiparms = $likiparms;
		session_start(); 
		header("Cache-control: private"); //fix for iE :-(
		$this->updateAuth($_GET,$_POST,$_SESSION,$likiparms);
	}
	function updateAuth($_GET,$_POST,&$_SESSION,$likiparms){
		$this->loggedin = false;
		if(isset($_GET['logout'])){
			$_SESSION = array();
			session_destroy(); 
		}
		if(isset($_POST['password']) && isset($_POST['user'])){
			$try_pass = md5($_POST['password']);
			$try_user = md5($_POST['user']);
			if(isset($likiparms['users']['MD5'.md5($_POST['user'])]) && $likiparms['users']['MD5'.md5($_POST['user'])]['pass'] == $try_pass){
   				$_SESSION['pass'] = $try_pass; 
				$_SESSION['user'] = $try_user;
				$this->password = $try_pass;
				$this->user = $try_user;
				$this->loggedin = true;
			}
		}
		else if(isset($_SESSION['pass']) &&  isset($_SESSION['user']) &&  $likiparms['users']['MD5'.$_SESSION['user']]['pass'] == $_SESSION['pass']){
			$this->loggedin = true;
			$this->password = $_SESSION['pass'];
			$this->user = $_SESSION['user'];
		}
		if(isset($this->user))
			$this->username = $likiparms['users']['MD5'.$this->user]['name'];
	}
	function authTex($type,&$page){
		if(!$page->exists()){
			$diff_links = $page->getBackLinks();
			if($count = $diff_links->count())
				while($p=$diff_links->next())//for($i=0; $i<=$count; $i++)
					switch ($type){
						case 'read' :
							if($this->likiparms['liki']['public_read'] == '1'
							|| ($this->likiparms['liki']['global_read'] == '1' && $this->loggedin) 
							|| ($this->loggedin && substr_count($p->get('read'),$this->user))
							|| ($this->loggedin && $this->likiparms['liki']['su'] ==$this->user))
								return true;
							return false; break;
						case 'edit' :
							if( ($this->loggedin && substr_count($p->get('edit'),$this->user))
							|| ($this->likiparms['liki']['global_edit'] == '1' && $this->loggedin) 
							|| $this->likiparms['liki']['public_edit'] == '1'
							|| ($this->loggedin && substr_count($p->get('owner'),$this->user)) 
							|| ($this->loggedin && $this->likiparms['liki']['su'] ==$this->user)) 
								return true;
							return false; break;
						case 'owner' :
							if($this->loggedin &&(substr_count($p->get('owner'),$this->user) || $this->likiparms['liki']['su'] == $this->user))
								return true;
							return false; break;
					}
			else 
				return false;
		}
		else {	
			switch ($type){
				case 'read' :
					if($this->likiparms['liki']['public_read'] == '1'
					|| ($this->likiparms['liki']['global_read'] == '1' && $this->loggedin) 
					|| ($this->loggedin && substr_count($page->get('read'),$this->user))
					|| ($this->loggedin && $this->likiparms['liki']['su'] ==$this->user)) 
						return true;
					return false; break;
				case 'edit' :
					if( ($this->loggedin && substr_count($page->get('edit'),$this->user))
					|| ($this->likiparms['liki']['global_edit'] == '1' && $this->loggedin) 
					|| $this->likiparms['liki']['public_edit'] == '1'
					|| ($this->loggedin && substr_count($page->get('owner'),$this->user)) 
					|| ($this->loggedin && $this->likiparms['liki']['su'] ==$this->user)) 
						return true;
					return false; break;
				case 'owner' :
					if($this->loggedin &&(substr_count($page->get('owner'),$this->user) || $this->likiparms['liki']['su'] ==$this->user))
						return true;
					return false; break;
			}
		}
		return false;
	}

	function authGfx($type,$page){
		//can edit a Gfx if they have edit perms on the parent.
		//allow for gfx upload without prior linkage?
		return $this->authTex($type,$page);
	}
	function authCheckout(){
		return ($this-loggedin || $this->likiparms['liki']['public_read'] || $this->likiparms['liki']['public_edit'] || $this->likiparms['liki']['public_compiled']);
	}
	function authCfg(){
		return ($this->likiparms['users']['MD5'.$this->user]['editconfig'] == 1 || $this->likiparms['liki']['su'] ==$this->user);
	}
	function authUsers(){
		return ($this->likiparms['users']['MD5'.$this->user]['addusers'] == 1 || $this->likiparms['liki']['su'] ==$this->user);
	}
	function authFileUpload(){
		return $this->likiparms['liki']['su'] ==$this->user;
	}

}
?>
Return current item: Liki - The LaTeX Wiki