/trunk_oldversion/plugins/.htaccess |
---|
0,0 → 1,3 |
Order Deny,Allow |
Deny From All |
/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('', '')); |
*/ |
/trunk_oldversion/plugins/field_extenders/1_depth.inc.php |
---|
0,0 → 1,22 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
class OIDDepthFieldExtender implements OIDPlusFieldExtenders { |
public static function processOID($oid, &$out, &$oidplusobj) { |
$out[] = 'oid-depth:'.self::oid_depth($oid); |
} |
protected static function oid_depth($oid) { |
# TODO: in oid_utils hinzufügen |
if ($oid == '.') return 0; |
if ($oid[0] != '.') $oid = ".$oid"; |
return substr_count($oid, '.'); |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new OIDDepthFieldExtender()); |
/trunk_oldversion/plugins/field_extenders/2_der.inc.php |
---|
0,0 → 1,16 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
require_once __DIR__ . '/../../includes/OidDerConverter.class.phps'; |
class DEREncodingFieldExtender implements OIDPlusFieldExtenders { |
public static function processOID($oid, &$out, &$oidplusobj) { |
$out[] = 'der-encoding:'.OidDerConverter::hexarrayToStr(OidDerConverter::oidToDER($oid)); |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new DEREncodingFieldExtender()); |
/trunk_oldversion/plugins/field_extenders/3_uuid.inc.php |
---|
0,0 → 1,39 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
require_once __DIR__ . '/../../includes/uuid_utils.inc.php'; |
class UUIDFieldExtender implements OIDPlusFieldExtenders { |
public static function processOID($oid, &$out, &$oidplusobj) { |
$r = oid_to_uuid($oid); |
if ($r === false) { |
$uuid_level = 0; |
} else { |
if (oid_depth($oid) == 2) { |
$uuid_level = 1; |
} else { |
$uuid_level = 2; |
} |
} |
# TODO: more configuration values, e.g. to hide namebased UUIDs |
if (($uuid_level == 0) || ($uuid_level == 2) || ($oidplusobj->getConfigValue('namebased_uuids_for_pure_uuids') == '1')) { |
$out[] = 'namebased-uuid-sha1:'.gen_uuid_sha1_namebased(UUID_NAMEBASED_NS_OID, $oid); |
$out[] = 'namebased-uuid-md5:'.gen_uuid_md5_namebased(UUID_NAMEBASED_NS_OID, $oid); |
} |
if ($uuid_level == 1) { |
$out[] = 'uuid:'.$r; |
} |
if ($uuid_level == 2) { |
$out[] = 'origin-uuid:'.$r; |
} |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new UUIDFieldExtender()); |
/trunk_oldversion/plugins/field_extenders/4_oidinfo.inc.php |
---|
0,0 → 1,73 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
require_once __DIR__ . '/../../includes/uuid_utils.inc.php'; |
// TODO: use oidinfo api phps |
// TODO: output warning if OID is illegal! |
class OIDInfoFieldExtender implements OIDPlusFieldExtenders { |
public static function getURL($oid) { |
if ($oid[0] == '.') { |
$oid = substr($oid, 1); |
} |
return 'http://www.oid-info.com/get/'.$oid; |
} |
// currently not used |
public static function oidMayBeCreated($oid) { |
if ($oid[0] == '.') { |
$oid = substr($oid, 1); |
} |
# Ping API |
$v = @file_get_contents('https://www.viathinksoft.de/~daniel-marschall/oid-repository/ping_oid.php?oid='.$oid); |
$v = substr($v, 1, 1); |
if (trim($v) === '1') return true; |
if (trim($v) === '0') return false; |
// TODO: exception |
return null; |
} |
public static function oidAvailable($oid) { |
if ($oid[0] == '.') { |
$oid = substr($oid, 1); |
} |
# Ping API |
$v = @file_get_contents('https://www.viathinksoft.de/~daniel-marschall/oid-repository/ping_oid.php?oid='.$oid); |
$v = substr($v, 0, 1); |
if (trim($v) === '2') return true; // existing and approved |
if (trim($v) === '1') return false; // not approved |
if (trim($v) === '0') return false; // not existing |
# Fallback |
$url = self::getURL($oid); |
$responsecode = get_http_response_code($url); |
return ($responsecode == 200); |
} |
public static function processOID($oid, &$out, &$oidplusobj) { |
if (self::oidAvailable($oid)) { |
$url = self::getURL($oid); |
$out[] = "cross-ref:$url"; |
} |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new OIDInfoFieldExtender()); |
# --- |
# TODO: -> functions.inc.php |
function get_http_response_code($theURL) { |
# http://php.net/manual/de/function.get-headers.php#97684 |
$headers = get_headers($theURL); |
return substr($headers[0], 9, 3); |
} |
/trunk_oldversion/plugins/field_extenders/5_asn1_search.inc.php |
---|
0,0 → 1,81 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
require_once __DIR__ . '/../../includes/uuid_utils.inc.php'; |
class ASN1SearchFieldExtender implements OIDPlusFieldExtenders { |
private static function detectDirectAsn1Notation($x, &$xx, $oidplusobj) { |
# At your root, you can define your own asn1-notation |
# FUT: as alternative, we could have "invisible" OIDs (cannot be queried) which give information about non-root OIDs |
$asn1path = $oidplusobj->getValuesOf($x, 'asn1-notation', true); |
if (count($asn1path) > 0) { |
$oidplusobj->stripAttribs($x, 'asn1-notation'); |
$asn1path = trim($asn1path[0]); |
if (!asn1_path_valid($asn1path)) { |
throw new VolcanoException("ASN.1 notation '$asn1path' is invalid"); # TODO: source? |
} |
$asn1path = preg_replace('@^\\s*\\{(.+)\\}\\s*$@', '\\1', $asn1path); |
$asn1path_neu = ''; |
$asn1path = str_replace("\t", ' ', $asn1path); |
$z = explode(' ', $asn1path); |
foreach ($z as $za) { |
$za = trim($za); |
if ($za == '') continue; |
$asn1path_neu .= "$za "; |
} |
$asn1path_neu = trim($asn1path_neu); |
$xx[] = $asn1path_neu; |
return true; |
} |
return false; |
} |
public static function processOID($oid, &$out, &$oidplusobj) { |
$xx = array(); |
$x = $oid; |
do { |
$toparc = oid_toparc($x); |
if (self::detectDirectAsn1Notation($x, $xx, $oidplusobj)) break; |
$ids = $oidplusobj->getIdentifiers($x); |
$id = null; |
foreach ($ids as $m) { |
if (oid_id_is_valid($m)) { |
$id = $m; |
break; |
} |
} |
if (is_null($id)) { |
$xx[] = $toparc; |
} else { |
$xx[] = "$id($toparc)"; |
} |
} while (($x = oid_up($x)) != '.'); |
$xx = array_reverse($xx); |
if (count($xx) > 0) { |
$asn1path = '{ '.implode(' ', $xx).' }'; |
if (!asn1_path_valid($asn1path)) { |
throw new VolcanoException("ASN.1 notation '$asn1path' is invalid"); # TODO: source? |
} |
$out[] = "asn1-notation: $asn1path"; |
} |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new ASN1SearchFieldExtender()); |
/trunk_oldversion/plugins/field_extenders/6_iri_search.inc.php |
---|
0,0 → 1,78 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
require_once __DIR__ . '/../../includes/oid_utils.inc.php'; |
require_once __DIR__ . '/../../includes/uuid_utils.inc.php'; |
class IRISearchFieldExtender implements OIDPlusFieldExtenders { |
private static function detectDirectIRINotation($x, &$xx, $oidplusobj) { |
# At your root, you can define your own iri-notation |
# FUT: as alternative, we could have "invisible" OIDs (cannot be queried) which give information about non-root OIDs |
$iripath = $oidplusobj->getValuesOf($x, 'iri-notation', true); |
if (count($iripath) > 0) { |
$oidplusobj->stripAttribs($x, 'iri-notation'); |
$iripath = trim($iripath[0]); |
if (!iri_valid($iripath)) { |
throw new VolcanoException("IRI notation '$iripath' is invalid"); # TODO: source? |
} |
$iripath = trim($iripath); |
assert(substr($iripath, 0, 1) == '/'); |
$iripath = substr($iripath, 1); |
$xx[] = $iripath; |
return true; |
} |
return false; |
} |
public static function processOID($oid, &$out, &$oidplusobj) { |
$xx = array(); |
$x = $oid; |
do { |
$toparc = oid_toparc($x); |
if (self::detectDirectIRINotation($x, $xx, $oidplusobj)) break; |
$ids = $oidplusobj->getUnicodeLabels($x); |
$id = null; |
foreach ($ids as $m) { |
if (iri_arc_valid($m)) { |
$id = $m; |
break; |
} |
} |
if (is_null($id)) { |
$xx[] = $toparc; |
} else { |
$xx[] = $id; |
} |
} while (($x = oid_up($x)) != '.'); |
$xx = array_reverse($xx); |
if (count($xx) > 0) { |
$iripath = '/'.implode('/', $xx); |
if (!iri_valid($iripath)) { |
throw new VolcanoException("IRI notation '$iripath' is invalid"); # TODO: source? |
} |
# TODO: soll das auch für die existierenden "iri-notation" felder angewandt werden? |
$iripath = iri_add_longarcs($iripath); |
$out[] = "iri-notation: $iripath"; |
} |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new IRISearchFieldExtender()); |
/trunk_oldversion/plugins/field_extenders/7_doi_url.inc.php |
---|
0,0 → 1,43 |
<?php |
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.'); |
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.'); |
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php'; |
require_once __DIR__ . '/../../includes/uuid_utils.inc.php'; |
class DOILinkFieldExtender implements OIDPlusFieldExtenders { |
public static function findDOI($oid, &$oidplusobj) { |
$indexes = $oidplusobj->getDatasets($oid, 'index'); |
$found_doi = null; |
foreach ($indexes as $index) { |
$params = $index['attrib_params']; |
$is_doi = false; |
foreach ($params as $param) { |
if (strtolower(trim($param)) == 'doi') { |
$is_doi = true; |
break; |
} |
} |
if ($is_doi) { |
$found_doi = trim($index['value']); |
break; |
} |
} |
return $found_doi; |
} |
public static function processOID($oid, &$out, &$oidplusobj) { |
$doi = self::findDOI($oid, $oidplusobj); |
if (!is_null($doi)) { |
$out[] = "doi-resolve:http://dx.doi.org/$doi"; |
} |
} |
} |
require_once __DIR__ . '/../../core/2_OIDPlus.class.php'; |
OIDPlus::registerFieldExtender(new DOILinkFieldExtender()); |
/trunk_oldversion/plugins/search/doi.inc.php |
---|
0,0 → 1,54 |
<?php |
# TODO: das kann ohne suffix auskommen: http://dx.doi.org/10.1038/ |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
class VolcanoSearchDOI implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'doi', true); // is always case insensitive |
} |
public static function calcDistance($candidate, $searchterm) { |
$y = explode('/', $searchterm); |
$x = explode('/', $candidate); |
$dist = count($y)-count($x); |
for ($i=0; $i<min(count($x),count($y)); $i++) { |
if ($x[$i] != $y[$i]) return false; |
} |
return $dist; |
} |
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::registerSearchProvider(new VolcanoSearchDOI()); |
# --- TEST |
$x = new VolcanoSearchDOI(); |
assert($x->calcDistance('10.1000', '10.1000/1') == 1); |
assert($x->calcDistance('10.1000/1', '10.1000') == -1); |
assert($x->calcDistance('10.1000', '10.1000') == 0); |
assert($x->calcDistance('10.1001', '10.1000') === false); |
assert($x->calcDistance('10.1000/1/2/3', '10.1000/1/2/3/4/5') == 2); |
assert($x->calcDistance('10.1000/1/2/3', '10.1000/1/2/3') == 0); |
assert($x->calcDistance('10.1000/1/2/3/4/5', '10.1000/1/2/3') == -2); |
assert($x->calcDistance('10.1000/1/2/x', '10.1000/1/2/3/4/5') === false); |
assert($x->calcDistance('10.1000/1/2/x', '10.1000/1/2/3') === false); |
assert($x->calcDistance('10.1000/1/2/x/4/5', '10.1000/1/2/3') === false); |
/trunk_oldversion/plugins/search/domain.inc.php |
---|
0,0 → 1,67 |
<?php |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
class VolcanoSearchDomain implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'domain', true); // is always case insensitive |
} |
protected static function tryNormalize($term) { |
// TODO: also validate syntax |
$ary = explode(':', $term); |
$term = $ary[0]; |
if (substr($term, -1, 1) != '.') $term .= '.'; |
return $term; |
} |
public static function calcDistance($candidate, $searchterm) { |
// TODO: punycode? |
$candidate = self::tryNormalize($candidate); |
$searchterm = self::tryNormalize($searchterm); |
if (strlen($candidate) <= strlen($searchterm)) { |
$cmp = substr($searchterm, strlen($searchterm)-strlen($candidate)); |
if (!self::strEqual($cmp, $candidate, true)) return false; |
$subdoms = substr($searchterm, 0, strlen($searchterm)-strlen($candidate)); |
return substr_count($subdoms, '.'); |
} else { |
$cmp = substr($candidate, strlen($candidate)-strlen($searchterm)); |
if (!self::strEqual($cmp, $searchterm, true)) return false; |
$too_specific = substr($candidate, 0, strlen($candidate)-strlen($searchterm)); |
return -substr_count($too_specific, '.'); |
} |
} |
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::registerSearchProvider(new VolcanoSearchDomain()); |
# --- TEST |
/* |
$x = new VolcanoSearchDomain(); |
assert($x->calcDistance('de.', 'viathinksoft.DE.') == 1); |
assert($x->calcDistance('de.', 'viathinksoft.de.') == 1); |
assert($x->calcDistance('viathinksoft.de.', 'viathinksoft.de.') == 0); |
assert($x->calcDistance('viathinksoft.DE.', 'viathinksoft.de.') == 0); |
assert($x->calcDistance('www.viathinksoft.de.', 'viathinksoft.de.') == -1); |
assert($x->calcDistance('de.', 'viathinksoft.xx.') === false); |
assert($x->calcDistance('viathinksoft.de.', 'viathinksoft.xx.') === false); |
assert($x->calcDistance('www.viathinksoft.de.', 'viathinksoft.xx.') === false); |
*/ |
/trunk_oldversion/plugins/search/ipv4.inc.php |
---|
0,0 → 1,45 |
<?php |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
require_once __DIR__ . '/../../includes/ipv4_functions.inc.php'; |
class VolcanoSearchIPv4 implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'ipv4', true); // is always case insensitive |
} |
public static function calcDistance($candidate, $searchterm) { |
return ipv4_distance($searchterm, $candidate); // TODO: richtig rum? |
} |
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::registerSearchProvider(new VolcanoSearchIPv4()); |
# --- TEST |
/* |
$x = new VolcanoSearchIPv4(); |
assert($x->calcDistance('192.168.0.0/16', '192.168.64.0/18') === 2); |
assert($x->calcDistance('192.168.64.0/18', '192.168.64.0/18') === 0); |
assert($x->calcDistance('192.168.64.0/20', '192.168.64.0/18') === -2); |
assert($x->calcDistance('192.168.69.200/31', '192.168.69.202/31') === false); |
assert($x->calcDistance('192.168.69.200/32', '192.168.69.201/32') === false); |
assert($x->calcDistance('192.168.69.200', '192.168.69.201') === false); |
assert($x->calcDistance('95.211.38.42/32', '95.211.38.42') === 0); |
assert($x->calcDistance('95.211.38.42', '95.211.38.42/32') === 0); |
*/ |
/trunk_oldversion/plugins/search/ipv6.inc.php |
---|
0,0 → 1,42 |
<?php |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
require_once __DIR__ . '/../../includes/ipv6_functions.inc.php'; |
class VolcanoSearchIPv6 implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'ipv6', true); // is always case insensitive |
} |
public static function calcDistance($candidate, $searchterm) { |
return ipv6_distance($searchterm, $candidate); // TODO: richtig rum? |
} |
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::registerSearchProvider(new VolcanoSearchIPv6()); |
# --- TEST |
/* |
$x = new VolcanoSearchIPv6(); |
assert($x->calcDistance('2001:1ae0::/27', '2001:1af8::/29') == 2); |
assert($x->calcDistance('2001:1af8::/29', '2001:1af8::/29') == 0); |
assert($x->calcDistance('2001:1af8::/31', '2001:1af8::/29') == -2); |
assert($x->calcDistance('2002:1af8:4100:a061:0001::1335/127', '2001:1af8:4100:a061:0001::1336/127') === false); |
assert($x->calcDistance('2001:1af8:4100:a061:0001::1337/128', '2001:1af8:4100:a061:0001::1336/128') === false); |
assert($x->calcDistance('2001:1af8:4100:a061:0001::1337', '2001:1af8:4100:a061:0001::1336') === false); |
*/ |
/trunk_oldversion/plugins/search/str.inc.php |
---|
0,0 → 1,37 |
<?php |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
class VolcanoSearchStr implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'str', true); // is always case insensitive |
} |
public static function calcDistance($candidate, $searchterm) { |
return (self::strEqual($candidate, $searchterm, false)) ? 0 : -1; |
} |
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::registerSearchProvider(new VolcanoSearchStr()); |
# --- TEST |
/* |
$x = new VolcanoSearchStr(); |
assert($x->calcDistance('a', 'a') == 0); |
assert($x->calcDistance('a', 'A') == -1); |
assert($x->calcDistance('a', 'b') == -1); |
*/ |
/trunk_oldversion/plugins/search/stri.inc.php |
---|
0,0 → 1,37 |
<?php |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
class VolcanoSearchStrI implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'stri', true); // is always case insensitive |
} |
public static function calcDistance($candidate, $searchterm) { |
return (self::strEqual($candidate, $searchterm, true)) ? 0 : -1; |
} |
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::registerSearchProvider(new VolcanoSearchStrI()); |
# --- TEST |
/* |
$x = new VolcanoSearchStrI(); |
assert($x->calcDistance('a', 'a') == 0); |
assert($x->calcDistance('a', 'A') == 0); |
assert($x->calcDistance('a', 'b') == -1); |
*/ |
/trunk_oldversion/plugins/search/uuid.inc.php |
---|
0,0 → 1,54 |
<?php |
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.'); |
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.'); |
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php'; |
class VolcanoSearchUUID implements VolcanoSearchProvider { |
public static function checkId($id) { |
return self::strEqual($id, 'guid', true) || self::strEqual($id, 'uuid', true); // is always case insensitive |
} |
protected static function tryNormalize($term) { |
// TODO: also validate syntax |
$term = str_replace('{', '', $term); |
$term = str_replace('}', '', $term); |
$term = strtolower($term); |
return $term; |
} |
public static function calcDistance($candidate, $searchterm) { |
$candidate = self::tryNormalize($candidate); |
$searchterm = self::tryNormalize($searchterm); |
if ($candidate == $searchterm) { |
return 0; |
} else { |
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::registerSearchProvider(new VolcanoSearchUUID()); |
# --- TEST |
/* |
$x = new VolcanoSearchUUID(); |
assert($x->calcDistance('fd3c657c-0728-4769-b608-db5ece442c97', '8338af1c-61ea-41c1-aded-c836846ae22d') === false); |
assert($x->calcDistance('fd3c657c-0728-4769-b608-db5ece442c97', 'fd3c657c-0728-4769-b608-db5ece442c97') === 0); |
assert($x->calcDistance('fd3c657c-0728-4769-b608-db5ece442c97', '{FD3c657c-0728-4769-b608-db5ece442C97}') === 0); |
assert($x->calcDistance('{fd3C657C-0728-4769-b608-db5ece442c97}', 'fd3c657c-0728-4769-b608-db5ece442c97') === 0); |
*/ |