Subversion Repositories Sites.tela-botanica.org

Compare Revisions

Ignore whitespace Rev 419 → Rev 420

/trunk/wikini/maj_wikini/tools/libs/Html.php
New file
0,0 → 1,141
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
 
/**
* Standard Html Login form
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Authentication
* @package Auth
* @author Martin Jansen <mj@php.net>
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Html.php,v 1.10 2006/08/10 02:15:40 aashley Exp $
* @link http://pear.php.net/package/Auth
* @since File available since Release 1.3.0
*/
 
/**
* Standard Html Login form
*
* @category Authentication
* @package Auth
* @author Yavor Shahpasov <yavo@netsmart.com.cy>
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version Release: @package_version@ File: $Revision: 1.10 $
* @link http://pear.php.net/package/Auth
* @since Class available since Release 1.3.0
*/
class Auth_Frontend_Html {
// {{{ render()
 
/**
* Displays the login form
*
* @param object The calling auth instance
* @param string The previously used username
* @return void
*/
function render(&$caller, $username = '') {
$loginOnClick = 'return true;';
// Try To Use Challene response
// TODO javascript might need some improvement for work on other browsers
if($caller->advancedsecurity && $caller->storage->supportsChallengeResponse() ) {
 
// Init the secret cookie
$caller->session['loginchallenege'] = md5(microtime());
 
print "\n";
print '<script language="JavaScript">'."\n";
 
 
print "\n";
print ' function securePassword() { '."\n";
print ' var pass = document.getElementById(\''.$caller->getPostPasswordField().'\');'."\n";
print ' var secret = document.getElementById(\'authsecret\')'."\n";
//print ' alert(pass);alert(secret); '."\n";
 
// If using md5 for password storage md5 the password before
// we hash it with the secret
// print ' alert(pass.value);';
if ($caller->storage->getCryptType() == 'md5' ) {
print ' pass.value = hex_md5(pass.value); '."\n";
#print ' alert(pass.value);';
}
 
print ' pass.value = hex_md5(pass.value+\''.$caller->session['loginchallenege'].'\'); '."\n";
// print ' alert(pass.value);';
print ' secret.value = 1;'."\n";
print ' var doLogin = document.getElementById(\'doLogin\')'."\n";
print ' doLogin.disabled = true;'."\n";
print ' return true;';
print ' } '."\n";
print '</script>'."\n";;
print "\n";
 
$loginOnClick = ' return securePassword(); ';
}
 
print '<center>'."\n";
 
$status = '';
if (!empty($caller->status) && $caller->status == AUTH_EXPIRED) {
$status = '<i>Your session has expired. Please login again!</i>'."\n";
} else if (!empty($caller->status) && $caller->status == AUTH_IDLED) {
$status = '<i>You have been idle for too long. Please login again!</i>'."\n";
} else if (!empty ($caller->status) && $caller->status == AUTH_WRONG_LOGIN) {
$status = '<i>Wrong login data!</i>'."\n";
} else if (!empty ($caller->status) && $caller->status == AUTH_SECURITY_BREACH) {
$status = '<i>Security problem detected. </i>'."\n";
}
print '<form method="post" action="'.$caller->server['PHP_SELF'].'" '
.'onSubmit="'.$loginOnClick.'">'."\n";
print '<table border="0" cellpadding="2" cellspacing="0" '
.'summary="login form" align="center" >'."\n";
print '<tr>'."\n";
print ' <td colspan="2" bgcolor="#eeeeee"><strong>Login </strong>'
.$status.'</td>'."\n";
print '</tr>'."\n";
print '<tr>'."\n";
print ' <td>Username:</td>'."\n";
print ' <td><input type="text" id="'.$caller->getPostUsernameField()
.'" name="'.$caller->getPostUsernameField().'" value="' . $username
.'" /></td>'."\n";
print '</tr>'."\n";
print '<tr>'."\n";
print ' <td>Password:</td>'."\n";
print ' <td><input type="password" id="'.$caller->getPostPasswordField()
.'" name="'.$caller->getPostPasswordField().'" /></td>'."\n";
print '</tr>'."\n";
print '<tr>'."\n";
//onClick=" '.$loginOnClick.' "
print ' <td colspan="2" bgcolor="#eeeeee"><input value="Login" '
.'id="doLogin" name="doLogin" type="submit" /></td>'."\n";
print '</tr>'."\n";
print '</table>'."\n";
 
// Might be a good idea to make the variable name variable
print '<input type="hidden" id="authsecret" name="authsecret" value="" />';
print '</form>'."\n";
print '</center>'."\n";
}
 
// }}}
}
 
?>
/trunk/wikini/maj_wikini/tools/libs/class.plugins.php
New file
0,0 → 1,279
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of DotClear.
# Copyright (c) 2004 Olivier Meunier and contributors. All rights
# reserved.
#
# DotClear 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.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
 
/*
Classe de gestion des plugins et des thèmes
*/
 
class plugins
{
var $location;
var $type;
var $_xml;
var $p_list = array();
function plugins($location,$type='plugin')
{
if (is_dir($location)) {
$this->location = $location.'/';
} else {
$this->location = NULL;
}
$this->type = $type;
}
function getPlugins($active_only=true)
{
if (($list_files = $this->_readDir()) !== false)
{
$this->p_list = array();
foreach ($list_files as $entry => $pfile)
{
if (($info = $this->_getPluginInfo($pfile)) !== false) {
if (($active_only && $info['active']) || !$active_only) {
$this->p_list[$entry] = $info;
}
}
}
ksort($this->p_list);
return true;
}
else
{
return false;
}
}
function getPluginsList()
{
return $this->p_list;
}
function getFunctions($f='functions.php')
{
$res = array();
if (($list_files = $this->_readDir()) !== false)
{
foreach ($list_files as $entry => $pfile)
{
if (file_exists(dirname($pfile).'/'.$f)) {
$res[] = dirname($pfile).'/'.$f;
}
}
}
return $res;
}
function loadCallbacks()
{
$res['onPost'] = array();
$ires = array_keys($res);
foreach ($this->p_list as $k => $v)
{
# Chargement des fichiers events.php
if (file_exists($this->location.$k.'/events.php'))
{
require_once $this->location.$k.'/events.php';
foreach ($v['callbacks'] as $f)
{
if (in_array($f[0],$ires))
{
$pf = explode('::',$f[1]);
if (count($pf) == 2 && is_callable($pf)) {
$res[$f[0]][] = $pf;
}
}
}
}
}
return $res;
}
function loadl10n($p)
{
if (defined('DC_LANG')) {
if (dc_encoding == 'UTF-8') {
l10n::set($this->location.$p.'/l10n/'.DC_LANG.'-utf8/main');
} else {
l10n::set($this->location.$p.'/l10n/'.DC_LANG.'/main');
}
}
}
function switchStatus($p)
{
$xml_path = $this->location.$p.'/desc.xml';
$p_info = $this->_getPluginInfo($xml_path);
$xml = implode('',file($xml_path));
$active = (integer) !$p_info['active'];
$xml = preg_replace('|(<'.$this->type.'[^>]*?active=)"([^"]+)([^>]*>)|ms',
'$1"'.$active.'$3',$xml);
if (!files::putContent($xml_path,$xml)) {
return false;
}
return true;
}
/* Installation d'un plugin */
function install($url)
{
$dest = $this->location.'/'.basename($url);
if ((!file_exists($dest)) && ($err = files::copyRemote($url,$dest) !== true)) {
return $err;
}
else
{
if (($content = @implode('',@gzfile($dest))) === false) {
return __('Cannot open file');
} else {
if (($list = unserialize($content)) === false)
{
return __('Plugin not valid');
}
else
{
if (is_dir($this->location.'/'.$list['name']))
{
/*if (files::deltree($this->location.'/'.$list['name']) === false)
{
return 'Impossible de supprimer le plugin existant';
}*/
unlink($dest);
return __('This plugin still exists. Delete it before.');
}
foreach ($list['dirs'] as $d)
{
mkdir ($this->location.'/'.$d,fileperms($this->location));
chmod($this->location.'/'.$d,fileperms($this->location));
}
foreach ($list['files'] as $f => $v)
{
$v = base64_decode($v);
$fp = fopen($this->location.'/'.$f,'w');
fwrite($fp,$v,strlen($v));
fclose($fp);
chmod($this->location.'/'.$f,fileperms($this->location) & ~0111);
}
unlink($dest);
}
}
}
return true;
}
/* Lecture d'un répertoire à la recherche des desc.xml */
function _readDir()
{
if ($this->location === NULL) {
return false;
}
$res = array();
$d = dir($this->location);
# Liste du répertoire des plugins
while (($entry = $d->read()) !== false)
{
if ($entry != '.' && $entry != '..' &&
is_dir($this->location.$entry) && file_exists($this->location.$entry.'/desc.xml'))
{
$res[$entry] = $this->location.$entry.'/desc.xml';
}
}
return $res;
}
function _getPluginInfo($p)
{
if (file_exists($p))
{
$this->_current_tag_cdata = '';
$this->_p_info = array('name'=>NULL,'version'=>NULL,
'active'=>NULL,'author'=>NULL,'label'=>NULL,
'desc'=>NULL,'callbacks'=>array());
$this->_xml = xml_parser_create('ISO-8859-1');
xml_parser_set_option($this->_xml, XML_OPTION_CASE_FOLDING, false);
xml_set_object($this->_xml, $this);
xml_set_element_handler($this->_xml,'_openTag','_closeTag');
xml_set_character_data_handler($this->_xml, '_cdata');
xml_parse($this->_xml,implode('',file($p)));
xml_parser_free($this->_xml);
if (!empty($this->_p_info['name'])) {
return $this->_p_info;
} else {
return false;
}
}
}
function _openTag($p,$tag,$attr)
{
if ($tag == $this->type && !empty($attr['name']))
{
$this->_p_info['name'] = $attr['name'];
$this->_p_info['version'] = (!empty($attr['version'])) ? $attr['version'] : NULL;
$this->_p_info['active'] = (!empty($attr['active'])) ? (boolean) $attr['active'] : false;
}
if ($tag == 'callback') {
$this->_p_info['callbacks'][] = array($attr['event'],$attr['function']);
}
}
function _closeTag($p,$tag)
{
switch ($tag)
{
case 'author':
case 'label':
case 'desc':
$this->_p_info[$tag] = $this->_current_tag_cdata;
break;
}
}
function _cdata($p,$cdata)
{
$this->_current_tag_cdata = $cdata;
}
}
 
?>
/trunk/wikini/maj_wikini/tools/libs/class.wiki.php
New file
0,0 → 1,56
<?php
require_once('wakka.config.php');
 
// Une classe minimal wiki pour l'acces à la base de donnée
 
class Wiki
{
var $dblink;
var $VERSION;
 
// constructor
function Wiki($config)
{
$this->config = $config;
// some host do not allow mysql_pconnect
$this->dblink = @mysql_connect (
$this->config["mysql_host"],
$this->config["mysql_user"],
$this->config["mysql_password"]);
if ($this->dblink)
{
if (!@mysql_select_db($this->config["mysql_database"], $this->dblink))
{
@mysql_close($this->dblink);
$this->dblink = false;
}
}
$this->VERSION = WAKKA_VERSION;
 
}
 
 
// DATABASE
function Query($query)
{
if (!$result = mysql_query($query, $this->dblink))
{
ob_end_clean();
die("Query failed: ".$query." (".mysql_error().")");
}
return $result;
}
function LoadSingle($query) { if ($data = $this->LoadAll($query)) return $data[0]; }
function LoadAll($query)
{
$data=array();
if ($r = $this->Query($query))
{
while ($row = mysql_fetch_assoc($r)) $data[] = $row;
mysql_free_result($r);
}
return $data;
}
 
}
?>
/trunk/wikini/maj_wikini/tools/libs/lib.files.php
New file
0,0 → 1,328
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of DotClear.
# Copyright (c) 2004 Olivier Meunier and contributors. All rights
# reserved.
#
# DotClear 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.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
 
class files
{
function scandir($d,$order=0)
{
$res = array();
if (($dh = @opendir($d)) !== false)
{
while (($f = readdir($dh)) !== false) {
$res[] = $f;
}
closedir($dh);
sort($res);
if ($order == 1) {
rsort($res);
}
return $res;
}
else
{
return false;
}
}
function isDeletable($f)
{
if (is_file($f)) {
return is_writable(dirname($f));
} elseif (is_dir($f)) {
return (is_writable(dirname($f)) && count(files::scandir($f)) <= 2);
}
}
# Suppression récursive d'un répertoire (rm -rf)
function deltree($dir)
{
$current_dir = opendir($dir);
while($entryname = readdir($current_dir))
{
if (is_dir($dir.'/'.$entryname) and ($entryname != '.' and $entryname!='..'))
{
if (!files::deltree($dir.'/'.$entryname)) {
return false;
}
}
elseif ($entryname != '.' and $entryname!='..')
{
if (!@unlink($dir.'/'.$entryname)) {
return false;
}
}
}
closedir($current_dir);
return @rmdir($dir);
}
function touch($f)
{
if (is_writable($f)) {
$c = implode('',file($f));
if ($fp = @fopen($f,'w')) {
fwrite($fp,$c,strlen($c));
fclose($fp);
}
}
}
function secureFile($f)
{
if (is_file($f))
{
@chmod($f,0600);
if (is_readable($f)) {
return true;
} else {
@chmod($f,0660);
if (is_readable($f)) {
return true;
} else {
@chmod($f,0666);
}
}
}
}
function makeDir($f)
{
if (@mkdir($f,fileperms(dirname($f))) === false) {
return false;
}
@chmod($f,fileperms(dirname($f)));
}
function putContent($f, $f_content)
{
if (is_writable($f))
{
if ($fp = @fopen($f, 'w'))
{
fwrite($fp,$f_content,strlen($f_content));
fclose($fp);
return true;
}
}
return false;
}
function size($size)
{
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;
if($size < $kb) {
return $size." B";
}
else if($size < $mb) {
return round($size/$kb,2)." KB";
}
else if($size < $gb) {
return round($size/$mb,2)." MB";
}
else if($size < $tb) {
return round($size/$gb,2)." GB";
}
else {
return round($size/$tb,2)." TB";
}
}
# Copier d'un fichier binaire distant
function copyRemote($src,$dest)
{
if (($fp1 = @fopen($src,'r')) === false)
{
return __('An error occured while downloading the file.');
}
else
{
if (($fp2 = @fopen($dest,'w')) === false)
{
fclose($fp1);
return __('An error occured while writing the file.');
}
else
{
while (($buffer = fgetc($fp1)) !== false) {
fwrite($fp2,$buffer);
}
fclose($fp1);
fclose($fp2);
return true;
}
}
}
# Fonctions de création de packages
#
function getDirList($dirName)
{
static $filelist = array();
static $dirlist = array();
$exclude_list=array('.','..','.svn');
if (empty($res)) {
$res = array();
}
$dirName = preg_replace('|/$|','',$dirName);
if (!is_dir($dirName)) {
return false;
}
$dirlist[] = $dirName;
$d = dir($dirName);
while($entry = $d->read())
{
if (!in_array($entry,$exclude_list))
{
if (is_dir($dirName.'/'.$entry))
{
if ($entry != 'CVS')
{
files::getDirList($dirName.'/'.$entry);
}
}
else
{
$filelist[] = $dirName.'/'.$entry;
}
}
}
$d->close();
return array('dirs'=>$dirlist, 'files'=>$filelist);
}
function makePackage($name,$dir,$remove_path='',$gzip=true)
{
if ($gzip && !function_exists('gzcompress')) {
return false;
}
if (($filelist = files::getDirList($dir)) === false) {
return false;
}
$res = array ('name' => $name, 'dirs' => array(), 'files' => array());
foreach ($filelist['dirs'] as $v) {
$res['dirs'][] = preg_replace('/^'.preg_quote($remove_path,'/').'/','',$v);
}
foreach ($filelist['files'] as $v) {
$f_content = base64_encode(file_get_contents($v));
$v = preg_replace('/^'.preg_quote($remove_path,'/').'/','',$v);
$res['files'][$v] = $f_content;
}
$res = serialize($res);
if ($gzip) {
$res = gzencode($res);
}
return $res;
}
}
 
 
class path
{
function real($p,$strict=true)
{
$os = (DIRECTORY_SEPARATOR == '\\') ? 'win' : 'nix';
# Chemin absolu ou non ?
if ($os == 'win') {
$_abs = preg_match('/^\w+:/',$p);
} else {
$_abs = substr($p,0,1) == '/';
}
# Transformation du chemin, forme std
if ($os == 'win') {
$p = str_replace('\\','/',$p);
}
# Ajout de la racine du fichier appelant si
if (!$_abs) {
$p = dirname($_SERVER['SCRIPT_FILENAME']).'/'.$p;
}
# Nettoyage
$p = preg_replace('|/+|','/',$p);
if (strlen($p) > 1) {
$p = preg_replace('|/$|','',$p);
}
$_start = '';
if ($os == 'win') {
list($_start,$p) = explode(':',$p);
$_start .= ':/';
} else {
$_start = '/';
}
$p = substr($p,1);
# Parcours
$P = explode('/',$p);
$res = array();
for ($i=0;$i<count($P);$i++)
{
if ($P[$i] == '.') {
continue;
}
if ($P[$i] == '..') {
if (count($res) > 0) {
array_pop($res);
}
} else {
array_push($res,$P[$i]);
}
}
$p = $_start.implode('/',$res);
if ($strict && !@file_exists($p)) {
return false;
}
return $p;
}
}
?>
/trunk/wikini/maj_wikini/tools/libs/lib.compat.php
New file
0,0 → 1,64
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of DotClear.
# Copyright (c) 2004 Olivier Meunier and contributors. All rights
# reserved.
#
# DotClear 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.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
 
/* Missing functions
source : http://pear.php.net/package/PHP_Compat
*/
 
/* files_get_contents */
if (!function_exists('file_get_contents'))
{
function file_get_contents($filename, $incpath = false, $resource_context = null)
{
if (false === $fh = fopen($filename, 'rb', $incpath))
{
trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
return false;
}
clearstatcache();
if ($fsize = filesize($filename))
{
$data = fread($fh, $fsize);
}
else
{
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}
fclose($fh);
return $data;
}
}
 
if (!function_exists('is_a'))
{
function is_a($obj, $classname)
{
if (strtolower(get_class($obj)) == strtolower($classname)) {
return true;
} else {
return(is_subclass_of($obj, $classname));
}
}
}
?>
/trunk/wikini/maj_wikini/tools/libs/lib.form.php
New file
0,0 → 1,137
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of DotClear.
# Copyright (c) 2004 Olivier Meunier and contributors. All rights
# reserved.
#
# DotClear 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.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
 
class form
{
function combo($name,$arryData,$default='',$class='',$id='',$tabindex='')
{
$res = '<select name="'.$name.'" ';
if($class != '')
$res .= 'class="'.$class.'" ';
if($tabindex != '')
$res .= 'tabindex="'.$tabindex.'" ';
if($id != '')
$res .= 'id="'.$id.'" ';
else
$res .= 'id="'.$name.'" ';
$res .= '>'."\n";
foreach($arryData as $k => $v)
{
$res .= '<option value="'.$v.'"';
if($v == $default)
$res .= ' selected="selected"';
$res .= '>'.$k.'</option>'."\n";
}
$res .= '</select>'."\n";
return $res;
}
function radio($name, $value, $checked='', $class='', $id='')
{
$res = '<input type="radio" name="'.$name.'" value="'.$value.'" ';
if($class != '') {
$res .= 'class="'.$class.'" ';
}
if($id != '') {
$res .= 'id="'.$id.'" ';
}
if (($checked === 0) or $checked >= 1) {
$res .= 'checked="checked" ';
}
$res .= '/>'."\n";
return $res;
}
 
function checkbox($name, $value, $checked='', $class='', $id='')
{
$res = '<input type="checkbox" name="'.$name.'" value="'.$value.'"';
if($class != '')
$res .= 'class="'.$class.'" ';
if($id != '') {
$res .= 'id="'.$id.'" ';
}
 
if($checked != '') {
$res.='checked="checked"';
}
$res .= ' />'."\n";
 
return $res;
}
 
function field($id,$size,$max,$default='',$tabindex='',$html='')
{
if (is_array($id)) {
$name = $id[0];
$id = isset($id[1]) ? $id[1] : '';
} else {
$name = $id;
}
$res = '<input type="text" size="'.$size.'" name="'.$name.'" ';
$res .= ($id != '') ? 'id="'.$id.'" ' : '';
$res .= ($max != '') ? 'maxlength="'.$max.'" ' : '';
$res .= ($tabindex != '') ? 'tabindex="'.$tabindex.'" ' : '';
$res .= ($default != '') ? 'value="'.$default.'" ' : '';
$res .= $html;
$res .= ' />';
return $res;
}
function textArea($id,$cols,$rows,$default='',$tabindex='',$html='')
{
$res = '<textarea cols="'.$cols.'" rows="'.$rows.'" ';
$res .= 'name="'.$id.'" id="'.$id.'" ';
$res .= ($tabindex != '') ? 'tabindex="'.$tabindex.'" ' : '';
$res .= $html.'>';
$res .= $default;
$res .= '</textarea>';
return $res;
}
function hidden($id,$value)
{
return '<input type="hidden" name="'.$id.'" value="'.$value.'" />';
}
}
?>
/trunk/wikini/maj_wikini/tools/libs/lib.buffer.php
New file
0,0 → 1,46
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of DotClear.
# Copyright (c) 2004 Olivier Meunier and contributors. All rights
# reserved.
#
# DotClear 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.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
 
class buffer
{
function init()
{
$GLOBALS['__dc_buffer'] = NULL;
}
function clean()
{
$GLOBALS['__dc_buffer'] = NULL;
}
function getContent()
{
return $GLOBALS['__dc_buffer'];
}
function str($str)
{
$GLOBALS['__dc_buffer'] .= $str;
}
}
 
?>
/trunk/wikini/maj_wikini/tools/libs/Auth.php
New file
0,0 → 1,1093
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
 
/**
* The main include file for Auth package
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Authentication
* @package Auth
* @author Martin Jansen <mj@php.net>
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Auth.php,v 1.107 2006/08/10 03:01:15 aashley Exp $
* @link http://pear.php.net/package/Auth
*/
 
/**
* Returned if session exceeds idle time
*/
define('AUTH_IDLED', -1);
/**
* Returned if session has expired
*/
define('AUTH_EXPIRED', -2);
/**
* Returned if container is unable to authenticate user/password pair
*/
define('AUTH_WRONG_LOGIN', -3);
/**
* Returned if a container method is not supported.
*/
define('AUTH_METHOD_NOT_SUPPORTED', -4);
/**
* Returned if new Advanced security system detects a breach
*/
define('AUTH_SECURITY_BREACH', -5);
 
/**
* PEAR::Auth
*
* The PEAR::Auth class provides methods for creating an
* authentication system using PHP.
*
* @category Authentication
* @package Auth
* @author Martin Jansen <mj@php.net>
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version Release: @package_version@ File: $Revision: 1.107 $
* @link http://pear.php.net/package/Auth
*/
class Auth {
 
// {{{ properties
 
/**
* Auth lifetime in seconds
*
* If this variable is set to 0, auth never expires
*
* @var integer
* @see setExpire(), checkAuth()
*/
var $expire = 0;
 
/**
* Has the auth session expired?
*
* @var bool
* @see checkAuth()
*/
var $expired = false;
 
/**
* Maximum idletime in seconds
*
* The difference to $expire is, that the idletime gets
* refreshed each time checkAuth() is called. If this
* variable is set to 0, idletime is never checked.
*
* @var integer
* @see setIdle(), checkAuth()
*/
var $idle = 0;
 
/**
* Is the maximum idletime over?
*
* @var boolean
* @see checkAuth()
*/
var $idled = false;
 
/**
* Storage object
*
* @var object
* @see Auth(), validateLogin()
*/
var $storage = '';
 
/**
* User-defined function that creates the login screen
*
* @var string
*/
var $loginFunction = '';
 
/**
* Should the login form be displayed
*
* @var bool
* @see setShowlogin()
*/
var $showLogin = true;
/**
* Is Login Allowed from this page
*
* @var bool
* @see setAllowLogin
*/
var $allowLogin = true;
 
/**
* Current authentication status
*
* @var string
*/
var $status = '';
 
/**
* Username
*
* @var string
*/
var $username = '';
 
/**
* Password
*
* @var string
*/
var $password = '';
 
/**
* Login callback function name
*
* @var string
* @see setLoginCallback()
*/
var $loginCallback = '';
 
/**
* Failed Login callback function name
*
* @var string
* @see setFailedLoginCallback()
*/
var $loginFailedCallback = '';
 
/**
* Logout callback function name
*
* @var string
* @see setLogoutCallback()
*/
var $logoutCallback = '';
 
/**
* Auth session-array name
*
* @var string
*/
var $_sessionName = '_authsession';
 
/**
* Package Version
*
* @var string
*/
var $version = "@version@";
 
/**
* Flag to use advanced security
* When set extra checks will be made to see if the
* user's IP or useragent have changed across requests.
* Turned off by default to preserve BC.
*
* @var boolean
*/
var $advancedsecurity = false;
 
/**
* Username key in POST array
*
* @var string
*/
var $_postUsername = 'username';
 
/**
* Password key in POST array
*
* @var string
*/
var $_postPassword = 'password';
 
/**
* Holds a reference to the session auth variable
* @var array
*/
var $session;
 
/**
* Holds a reference to the global server variable
* @var array
*/
var $server;
 
/**
* Holds a reference to the global post variable
* @var array
*/
var $post;
 
/**
* Holds a reference to the global cookie variable
* @var array
*/
var $cookie;
 
/**
* A hash to hold various superglobals as reference
* @var array
*/
var $authdata;
/**
* How many times has checkAuth been called
* var int
*/
var $authChecks = 0;
 
// }}}
// {{{ Auth() [constructor]
 
/**
* Constructor
*
* Set up the storage driver.
*
* @param string Type of the storage driver
* @param mixed Additional options for the storage driver
* (example: if you are using DB as the storage
* driver, you have to pass the dsn string here)
*
* @param string Name of the function that creates the login form
* @param boolean Should the login form be displayed if neccessary?
* @return void
*/
function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
{
$this->applyAuthOptions($options);
 
// Start the session suppress error if already started
if(!session_id()){
@session_start();
if(!session_id()) {
// Throw error
include_once 'PEAR.php';
PEAR::throwError('Session could not be started by Auth, '
.'possibly headers are already sent, try putting '
.'ob_start in the beginning of your script');
}
}
 
// Make Sure Auth session variable is there
if( !isset($_SESSION[$this->_sessionName])
&& !isset($GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName])) {
isset($_SESSION)
? $_SESSION[$this->_sessionName] = array()
: $GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName] = array();
}
 
// Assign Some globals to internal references, this will replace _importGlobalVariable
isset($_SESSION)
? $this->session =& $_SESSION[$this->_sessionName]
: $this->session =& $GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName] ;
isset($_SERVER)
? $this->server =& $_SERVER
: $this->server =& $GLOBALS['HTTP_SERVER_VARS'];
isset($_POST)
? $this->post =& $_POST
: $this->post =& $GLOBALS['HTTP_POST_VARS'];
isset($_COOKIE)
? $this->cookie =& $_COOKIE
: $this->cookie =& $GLOBALS['HTTP_COOKIE_VARS'];
//isset($_GET) ? $var = &$_GET : $var = &$GLOBALS['HTTP_GET_VARS'];
 
if ($loginFunction != '' && is_callable($loginFunction)) {
$this->loginFunction = $loginFunction;
}
 
if (is_bool($showLogin)) {
$this->showLogin = $showLogin;
}
 
if (is_object($storageDriver)) {
$this->storage =& $storageDriver;
// Pass a reference to auth to the container, ugly but works
// this is used by the DB container to use method setAuthData not staticaly.
$this->storage->_auth_obj =& $this;
} else {
// $this->storage = $this->_factory($storageDriver, $options);
//
$this->storage_driver = $storageDriver;
$this->storage_options =& $options;
}
}
 
// }}}
// {{{ applyAuthOptions()
 
/**
* Set the Auth options
*
* Some options which are Auth specific will be applied
* the rest will be left for usage by the container
*
* @param array An array of Auth options
* @return array The options which were not applied
* @access private
*/
function &applyAuthOptions(&$options)
{
if(is_array($options)){
if (!empty($options['sessionName'])) {
$this->_sessionName = $options['sessionName'];
unset($options['sessionName']);
}
if (isset($options['allowLogin'])) {
$this->allowLogin = $options['allowLogin'];
unset($options['allowLogin']);
}
if (!empty($options['postUsername'])) {
$this->_postUsername = $options['postUsername'];
unset($options['postUsername']);
}
if (!empty($options['postPassword'])) {
$this->_postPassword = $options['postPassword'];
unset($options['postPassword']);
}
if (isset($options['advancedsecurity'])) {
$this->advancedsecurity = $options['advancedsecurity'];
unset($options['advancedsecurity']);
}
}
return($options);
}
 
// }}}
// {{{ _loadStorage()
/**
* Load Storage Driver if not already loaded
*
* Suspend storage instantiation to make Auth lighter to use
* for calls which do not require login
*
* @return bool True if the conainer is loaded, false if the container
* is already loaded
* @access private
*/
function _loadStorage()
{
if(!is_object($this->storage)) {
$this->storage =& $this->_factory($this->storage_driver,
$this->storage_options);
$this->storage->_auth_obj =& $this;
return(true);
}
return(false);
}
 
// }}}
// {{{ _factory()
 
/**
* Return a storage driver based on $driver and $options
*
* @static
* @param string $driver Type of storage class to return
* @param string $options Optional parameters for the storage class
* @return object Object Storage object
* @access private
*/
function &_factory($driver, $options = '')
{
$storage_class = 'Auth_Container_' . $driver;
include_once $driver . '.php';
$obj =& new $storage_class($options);
return $obj;
}
 
// }}}
// {{{ assignData()
 
/**
* Assign data from login form to internal values
*
* This function takes the values for username and password
* from $HTTP_POST_VARS/$_POST and assigns them to internal variables.
* If you wish to use another source apart from $HTTP_POST_VARS/$_POST,
* you have to derive this function.
*
* @global $HTTP_POST_VARS, $_POST
* @see Auth
* @return void
* @access private
*/
function assignData()
{
if ( isset($this->post[$this->_postUsername])
&& $this->post[$this->_postUsername] != '') {
$this->username = (get_magic_quotes_gpc() == 1
? stripslashes($this->post[$this->_postUsername])
: $this->post[$this->_postUsername]);
}
if ( isset($this->post[$this->_postPassword])
&& $this->post[$this->_postPassword] != '') {
$this->password = (get_magic_quotes_gpc() == 1
? stripslashes($this->post[$this->_postPassword])
: $this->post[$this->_postPassword] );
}
}
 
// }}}
// {{{ start()
 
/**
* Start new auth session
*
* @return void
* @access public
*/
function start()
{
$this->assignData();
if (!$this->checkAuth() && $this->allowLogin) {
$this->login();
}
}
 
// }}}
// {{{ login()
 
/**
* Login function
*
* @return void
* @access private
*/
function login()
{
$login_ok = false;
$this->_loadStorage();
// Check if using challenge response
(isset($this->post['authsecret']) && $this->post['authsecret'] == 1)
? $usingChap = true
: $usingChap = false;
 
// When the user has already entered a username, we have to validate it.
if (!empty($this->username)) {
if (true === $this->storage->fetchData($this->username, $this->password, $usingChap)) {
$this->session['challengekey'] = md5($this->username.$this->password);
$login_ok = true;
}
}
 
if (!empty($this->username) && $login_ok) {
$this->setAuth($this->username);
if (is_callable($this->loginCallback)) {
call_user_func_array($this->loginCallback, array($this->username, $this));
}
}
 
// If the login failed or the user entered no username,
// output the login screen again.
if (!empty($this->username) && !$login_ok) {
$this->status = AUTH_WRONG_LOGIN;
if (is_callable($this->loginFailedCallback)) {
call_user_func_array($this->loginFailedCallback, array($this->username, $this));
}
}
 
if ((empty($this->username) || !$login_ok) && $this->showLogin) {
if (is_callable($this->loginFunction)) {
call_user_func_array($this->loginFunction, array($this->username, $this->status, $this));
} else {
// BC fix Auth used to use drawLogin for this
// call is sub classes implement this
if (is_callable(array($this, 'drawLogin'))) {
return $this->drawLogin($this->username, $this);
}
 
// New Login form
include_once 'Html.php';
return Auth_Frontend_Html::render($this, $this->username);
}
} else {
return;
}
}
 
// }}}
// {{{ setExpire()
 
/**
* Set the maximum expire time
*
* @param integer time in seconds
* @param bool add time to current expire time or not
* @return void
* @access public
*/
function setExpire($time, $add = false)
{
$add ? $this->expire += $time : $this->expire = $time;
}
 
// }}}
// {{{ setIdle()
 
/**
* Set the maximum idle time
*
* @param integer time in seconds
* @param bool add time to current maximum idle time or not
* @return void
* @access public
*/
function setIdle($time, $add = false)
{
$add ? $this->idle += $time : $this->idle = $time;
}
 
// }}}
// {{{ setSessionName()
 
/**
* Set name of the session to a customized value.
*
* If you are using multiple instances of PEAR::Auth
* on the same domain, you can change the name of
* session per application via this function.
* This will chnage the name of the session variable
* auth uses to store it's data in the session
*
* @param string New name for the session
* @return void
* @access public
*/
function setSessionName($name = 'session')
{
$this->_sessionName = '_auth_'.$name;
isset($_SESSION)
? $this->session =& $_SESSION[$this->_sessionName]
: $this->session =& $GLOBALS['HTTP_SESSION_VARS'][$this->_sessionName] ;
}
 
// }}}
// {{{ setShowLogin()
 
/**
* Should the login form be displayed if neccessary?
*
* @param bool show login form or not
* @return void
* @access public
*/
function setShowLogin($showLogin = true)
{
$this->showLogin = $showLogin;
}
 
// }}}
// {{{ setAllowLogin()
 
/**
* Should the login form be displayed if neccessary?
*
* @param bool show login form or not
* @return void
* @access public
*/
function setAllowLogin($allowLogin = true)
{
$this->allowLogin = $allowLogin;
}
 
// }}}
// {{{ setLoginCallback()
/**
* Register a callback function to be called on user login.
* The function will receive two parameters, the username and a reference to the auth object.
*
* @param string callback function name
* @return void
* @see setLogoutCallback()
* @access public
*/
function setLoginCallback($loginCallback)
{
$this->loginCallback = $loginCallback;
}
 
// }}}
// {{{ setFailedLoginCallback()
 
/**
* Register a callback function to be called on failed user login.
* The function will receive a single parameter, the username and a reference to the auth object.
*
* @param string callback function name
* @return void
* @access public
*/
function setFailedLoginCallback($loginFailedCallback)
{
$this->loginFailedCallback = $loginFailedCallback;
}
 
// }}}
// {{{ setLogoutCallback()
 
/**
* Register a callback function to be called on user logout.
* The function will receive three parameters, the username and a reference to the auth object.
*
* @param string callback function name
* @return void
* @see setLoginCallback()
* @access public
*/
function setLogoutCallback($logoutCallback)
{
$this->logoutCallback = $logoutCallback;
}
 
// }}}
// {{{ setAuthData()
 
/**
* Register additional information that is to be stored
* in the session.
*
* @param string Name of the data field
* @param mixed Value of the data field
* @param boolean Should existing data be overwritten? (default
* is true)
* @return void
* @access public
*/
function setAuthData($name, $value, $overwrite = true)
{
if (!empty($this->session['data'][$name]) && $overwrite == false) {
return;
}
$this->session['data'][$name] = $value;
}
 
// }}}
// {{{ getAuthData()
 
/**
* Get additional information that is stored in the session.
*
* If no value for the first parameter is passed, the method will
* return all data that is currently stored.
*
* @param string Name of the data field
* @return mixed Value of the data field.
* @access public
*/
function getAuthData($name = null)
{
if (!isset($this->session['data'])) {
return null;
}
if(!isset($name)) {
return $this->session['data'];
}
if (isset($name) && isset($this->session['data'][$name])) {
return $this->session['data'][$name];
}
return null;
}
 
// }}}
// {{{ setAuth()
 
/**
* Register variable in a session telling that the user
* has logged in successfully
*
* @param string Username
* @return void
* @access public
*/
function setAuth($username)
{
// #2021 - Change the session id to avoid session fixation attacks php 4.3.3 >
// session_regenerate_id(true);
 
if (!isset($this->session) || !is_array($this->session)) {
$this->session = array();
}
 
if (!isset($this->session['data'])) {
$this->session['data'] = array();
}
 
$this->session['sessionip'] = isset($this->server['REMOTE_ADDR'])
? $this->server['REMOTE_ADDR']
: '';
$this->session['sessionuseragent'] = isset($this->server['HTTP_USER_AGENT'])
? $this->server['HTTP_USER_AGENT']
: '';
 
// This should be set by the container to something more safe
// Like md5(passwd.microtime)
if(empty($this->session['challengekey'])) {
$this->session['challengekey'] = md5($username.microtime());
}
 
$this->session['challengecookie'] = md5($this->session['challengekey'].microtime());
setcookie('authchallenge', $this->session['challengecookie']);
 
$this->session['registered'] = true;
$this->session['username'] = $username;
$this->session['timestamp'] = time();
$this->session['idle'] = time();
}
 
// }}}
// {{{ setAdvancedSecurity()
/**
* Enables advanced security checks
*
* Currently only ip change and useragent change
* are detected
* @todo Add challenge cookies - Create a cookie which changes every time
* and contains some challenge key which the server can verify with
* a session var cookie might need to be crypted (user pass)
* @param bool Enable or disable
* @return void
* @access public
*/
function setAdvancedSecurity($flag=true)
{
$this->advancedsecurity = $flag;
}
 
// }}}
// {{{ checkAuth()
 
/**
* Checks if there is a session with valid auth information.
*
* @access public
* @return boolean Whether or not the user is authenticated.
*/
function checkAuth()
{
$this->authChecks++;
if (isset($this->session)) {
// Check if authentication session is expired
if ( $this->expire > 0
&& isset($this->session['timestamp'])
&& ($this->session['timestamp'] + $this->expire) < time()) {
$this->expired = true;
$this->status = AUTH_EXPIRED;
$this->logout();
return false;
}
 
// Check if maximum idle time is reached
if ( $this->idle > 0
&& isset($this->session['idle'])
&& ($this->session['idle'] + $this->idle) < time()) {
$this->idled = true;
$this->status = AUTH_IDLED;
$this->logout();
return false;
}
 
if ( isset($this->session['registered'])
&& isset($this->session['username'])
&& $this->session['registered'] == true
&& $this->session['username'] != '') {
Auth::updateIdle();
 
if ($this->advancedsecurity) {
// Only Generate the challenge once
if($this->authChecks == 1) {
$this->session['challengecookieold'] = $this->session['challengecookie'];
$this->session['challengecookie'] = md5($this->session['challengekey'].microtime());
setcookie('authchallenge', $this->session['challengecookie']);
}
// Check for ip change
if ( isset($this->server['REMOTE_ADDR'])
&& $this->session['sessionip'] != $this->server['REMOTE_ADDR']) {
// Check if the IP of the user has changed, if so we
// assume a man in the middle attack and log him out
$this->expired = true;
$this->status = AUTH_SECURITY_BREACH;
$this->logout();
return false;
}
// Check for useragent change
if ( isset($this->server['HTTP_USER_AGENT'])
&& $this->session['sessionuseragent'] != $this->server['HTTP_USER_AGENT']) {
// Check if the User-Agent of the user has changed, if
// so we assume a man in the middle attack and log him out
$this->expired = true;
$this->status = AUTH_SECURITY_BREACH;
$this->logout();
return false;
}
// Check challenge cookie here, if challengecookieold is not set
// this is the first time and check is skipped
// TODO when user open two pages similtaneuly (open in new window,open
// in tab) auth breach is caused find out a way around that if possible
if ( isset($this->session['challengecookieold'])
&& $this->session['challengecookieold'] != $this->cookie['authchallenge']) {
$this->expired = true;
$this->status = AUTH_SECURITY_BREACH;
$this->logout();
$this->login();
return false;
}
}
 
return true;
}
}
return false;
}
 
// }}}
// {{{ staticCheckAuth() [static]
 
/**
* Statically checks if there is a session with valid auth information.
*
* @access public
* @see checkAuth
* @return boolean Whether or not the user is authenticated.
* @static
*/
function staticCheckAuth($options = null)
{
static $staticAuth;
if(!isset($staticAuth)) {
$staticAuth = new Auth('null', $options);
}
return $staticAuth->checkAuth();
}
 
// }}}
// {{{ getAuth()
 
/**
* Has the user been authenticated?
*
* @access public
* @return bool True if the user is logged in, otherwise false.
*/
function getAuth()
{
return $this->checkAuth();
}
 
// }}}
// {{{ logout()
 
/**
* Logout function
*
* This function clears any auth tokens in the currently
* active session and executes the logout callback function,
* if any
*
* @access public
* @return void
*/
function logout()
{
if (is_callable($this->logoutCallback)) {
call_user_func_array($this->logoutCallback, array($this->session['username'], $this));
}
 
$this->username = '';
$this->password = '';
$this->session = null;
}
 
// }}}
// {{{ updateIdle()
 
/**
* Update the idletime
*
* @access private
* @return void
*/
function updateIdle()
{
$this->session['idle'] = time();
}
 
// }}}
// {{{ getUsername()
 
/**
* Get the username
*
* @return string
* @access public
*/
function getUsername()
{
if (isset($this->session['username'])) {
return($this->session['username']);
}
return('');
}
 
// }}}
// {{{ getStatus()
 
/**
* Get the current status
*
* @return string
* @access public
*/
function getStatus()
{
return $this->status;
}
 
// }}}
// {{{ getPostUsernameField()
/**
* Gets the post varible used for the username
*
* @return string
* @access public
*/
function getPostUsernameField()
{
return($this->_postUsername);
}
 
// }}}
// {{{ getPostPasswordField()
 
/**
* Gets the post varible used for the username
*
* @return string
* @access public
*/
function getPostPasswordField()
{
return($this->_postPassword);
}
 
// }}}
// {{{ sessionValidThru()
 
/**
* Returns the time up to the session is valid
*
* @access public
* @return integer
*/
function sessionValidThru()
{
if (!isset($this->session['idle'])) {
return 0;
}
if ($this->idle == 0) {
return 0;
}
return ($this->session['idle'] + $this->idle);
}
 
// }}}
// {{{ listUsers()
 
/**
* List all users that are currently available in the storage
* container
*
* @access public
* @return array
*/
function listUsers()
{
$this->_loadStorage();
return $this->storage->listUsers();
}
 
// }}}
// {{{ addUser()
 
/**
* Add user to the storage container
*
* @access public
* @param string Username
* @param string Password
* @param mixed Additional parameters
* @return mixed True on success, PEAR error object on error
* and AUTH_METHOD_NOT_SUPPORTED otherwise.
*/
function addUser($username, $password, $additional = '')
{
$this->_loadStorage();
return $this->storage->addUser($username, $password, $additional);
}
 
// }}}
// {{{ removeUser()
 
/**
* Remove user from the storage container
*
* @access public
* @param string Username
* @return mixed True on success, PEAR error object on error
* and AUTH_METHOD_NOT_SUPPORTED otherwise.
*/
function removeUser($username)
{
$this->_loadStorage();
return $this->storage->removeUser($username);
}
 
// }}}
// {{{ changePassword()
 
/**
* Change password for user in the storage container
*
* @access public
* @param string Username
* @param string The new password
* @return mixed True on success, PEAR error object on error
* and AUTH_METHOD_NOT_SUPPORTED otherwise.
*/
function changePassword($username, $password)
{
$this->_loadStorage();
return $this->storage->changePassword($username, $password);
}
 
// }}}
 
}
?>
/trunk/wikini/maj_wikini/tools/libs/Container.php
New file
0,0 → 1,224
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
 
/**
* Auth_Container Base Class
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Authentication
* @package Auth
* @author Martin Jansen <mj@php.net>
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Container.php,v 1.23 2006/03/02 06:53:08 aashley Exp $
* @link http://pear.php.net/package/Auth
*/
 
/**
* Storage class for fetching login data
*
* @category Authentication
* @package Auth
* @author Martin Jansen <mj@php.net>
* @author Adam Ashley <aashley@php.net>
* @copyright 2001-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version Release: @package_version@ File: $Revision: 1.23 $
* @link http://pear.php.net/package/Auth
*/
class Auth_Container
{
 
// {{{ properties
 
/**
* User that is currently selected from the storage container.
*
* @access public
*/
var $activeUser = "";
 
// }}}
// {{{ Auth_Container() [constructor]
 
/**
* Constructor
*
* Has to be overwritten by each storage class
*
* @access public
*/
function Auth_Container()
{
}
 
// }}}
// {{{ fetchData()
 
/**
* Fetch data from storage container
*
* Has to be overwritten by each storage class
*
* @access public
*/
function fetchData($username, $password, $isChallengeResponse=false)
{
}
 
// }}}
// {{{ verifyPassword()
 
/**
* Crypt and verfiy the entered password
*
* @param string Entered password
* @param string Password from the data container (usually this password
* is already encrypted.
* @param string Type of algorithm with which the password from
* the container has been crypted. (md5, crypt etc.)
* Defaults to "md5".
* @return bool True, if the passwords match
*/
function verifyPassword($password1, $password2, $cryptType = "md5")
{
switch ($cryptType) {
case "crypt" :
return ( crypt($password1, $password2) == $password2 );
break;
case "none" :
case "" :
return ($password1 == $password2);
break;
case "md5" :
return (md5($password1) == $password2);
break;
default :
if (function_exists($cryptType)) {
return ($cryptType($password1) == $password2);
} elseif (method_exists($this,$cryptType)) {
return ($this->$cryptType($password1) == $password2);
} else {
return false;
}
break;
}
}
 
// }}}
// {{{ supportsChallengeResponse()
/**
* Returns true if the container supports Challenge Response
* password authentication
*/
function supportsChallengeResponse()
{
return(false);
}
 
// }}}
// {{{ getCryptType()
/**
* Returns the crypt current crypt type of the container
*
* @return string
*/
function getCryptType()
{
return('');
}
 
// }}}
// {{{ listUsers()
 
/**
* List all users that are available from the storage container
*/
function listUsers()
{
return AUTH_METHOD_NOT_SUPPORTED;
}
 
// }}}
// {{{ getUser()
 
/**
* Returns a user assoc array
*
* Containers which want should overide this
*
* @param string The username
*/
function getUser($username)
{
$users = $this->listUsers();
if ($users === AUTH_METHOD_NOT_SUPPORTED) {
return AUTH_METHOD_NOT_SUPPORTED;
}
for ($i=0; $c = count($users), $i<$c; $i++) {
if ($users[$i]['username'] == $username) {
return $users[$i];
}
}
return false;
}
 
// }}}
// {{{ addUser()
 
/**
* Add a new user to the storage container
*
* @param string Username
* @param string Password
* @param array Additional information
*
* @return boolean
*/
function addUser($username, $password, $additional=null)
{
return AUTH_METHOD_NOT_SUPPORTED;
}
 
// }}}
// {{{ removeUser()
 
/**
* Remove user from the storage container
*
* @param string Username
*/
function removeUser($username)
{
return AUTH_METHOD_NOT_SUPPORTED;
}
 
// }}}
// {{{ changePassword()
 
/**
* Change password for user in the storage container
*
* @param string Username
* @param string The new password
*/
function changePassword($username, $password)
{
return AUTH_METHOD_NOT_SUPPORTED;
}
 
// }}}
 
}
 
?>