Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 225 → Rev 226

/trunk_oldversion/plugins/auth/false.inc.php
0,0 → 1,35
<?php
 
# if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
 
class VolcanoAuthFalse implements VolcanoAuthProvider {
public static function checkId($id) {
return self::strEqual($id, 'false', true); // is always case insensitive
}
 
public static function checkAuth($candidate, $token) {
return false;
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerAuthProvider(new VolcanoAuthFalse());
 
# --- TEST
 
/*
$x = new VolcanoAuthFalse();
assert(!$x->checkAuth('', ''));
*/
 
/trunk_oldversion/plugins/auth/ip.inc.php
0,0 → 1,44
<?php
 
# if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../includes/ip_function.inc.php';
require_once __DIR__ . '/../../includes/ipv4_functions.inc.php';
require_once __DIR__ . '/../../includes/ipv6_functions.inc.php';
 
require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
 
class VolcanoAuthIP implements VolcanoAuthProvider {
public static function checkId($id) {
return self::strEqual($id, 'ip', true); // is always case insensitive
}
 
public static function checkAuth($candidate, $token) {
$ip = get_real_ip();
if (strpos($candidate, ':') !== false) {
return ipv6_in_cidr($candidate, $ip);
} else {
return ipv4_in_cidr($candidate, $ip);
}
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerAuthProvider(new VolcanoAuthIP());
 
# --- TEST
 
/*
$x = new VolcanoAuthIP();
assert( $x->checkAuth('217/8', ''));
assert( $x->checkAuth('::1/128', ''));
*/
/trunk_oldversion/plugins/auth/md5.inc.php
0,0 → 1,37
<?php
 
# if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
 
class VolcanoAuthMD5 implements VolcanoAuthProvider {
public static function checkId($id) {
return self::strEqual($id, 'md5', true); // is always case insensitive
}
 
public static function checkAuth($candidate, $token) {
return md5($token) === $candidate; // TODO salt
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerAuthProvider(new VolcanoAuthMD5());
 
# --- TEST
 
/*
$x = new VolcanoAuthMD5();
assert( $x->checkAuth('d41d8cd98f00b204e9800998ecf8427e', ''));
assert( $x->checkAuth('098f6bcd4621d373cade4e832627b4f6', 'test'));
assert(!$x->checkAuth('987bcab01b929eb2c07877b224215c92', 'xyz'));
*/
 
/trunk_oldversion/plugins/auth/plain.inc.php
0,0 → 1,37
<?php
 
# if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
 
class VolcanoAuthPlain implements VolcanoAuthProvider {
public static function checkId($id) {
return self::strEqual($id, 'plain', true); // is always case insensitive
}
 
public static function checkAuth($candidate, $token) {
return $token === $candidate; // TODO case?
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerAuthProvider(new VolcanoAuthPlain());
 
# --- TEST
 
/*
$x = new VolcanoAuthPlain();
assert( $x->checkAuth('', ''));
assert( $x->checkAuth('test', 'test'));
assert(!$x->checkAuth('beta', 'xyz'));
*/
 
/trunk_oldversion/plugins/auth/sha1.inc.php
0,0 → 1,37
<?php
 
# if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
 
class VolcanoAuthSHA1 implements VolcanoAuthProvider {
public static function checkId($id) {
return self::strEqual($id, 'sha1', true); // is always case insensitive
}
 
public static function checkAuth($candidate, $token) {
return sha1($token) === $candidate; // TODO salt
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerAuthProvider(new VolcanoAuthSHA1());
 
# --- TEST
 
/*
$x = new VolcanoAuthSHA1();
assert( $x->checkAuth('da39a3ee5e6b4b0d3255bfef95601890afd80709', ''));
assert( $x->checkAuth('a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 'test'));
assert(!$x->checkAuth('a295e0bdde1938d1fbfd343e5a3e569e868e1465', 'xyz'));
*/
 
/trunk_oldversion/plugins/auth/true.inc.php
0,0 → 1,35
<?php
 
# if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
 
class VolcanoAuthTrue implements VolcanoAuthProvider {
public static function checkId($id) {
return self::strEqual($id, 'true', true); // is always case insensitive
}
 
public static function checkAuth($candidate, $token) {
return true;
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerAuthProvider(new VolcanoAuthTrue());
 
# --- TEST
 
/*
$x = new VolcanoAuthTrue();
assert($x->checkAuth('', ''));
*/