Subversion Repositories oidplus

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. # if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
  4. # if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
  5.  
  6. require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
  7. require_once __DIR__ . '/../../includes/ipv4_functions.inc.php';
  8.  
  9. class VolcanoSearchIPv4 implements VolcanoSearchProvider {
  10.         public static function checkId($id) {
  11.                 return self::strEqual($id, 'ipv4', true); // is always case insensitive
  12.         }
  13.  
  14.         public static function calcDistance($candidate, $searchterm) {
  15.                 return ipv4_distance($searchterm, $candidate); // TODO: richtig rum?
  16.         }
  17.  
  18.         protected static function strEqual($str1, $str2, $caseInsensitive = false) {
  19.                 if ($caseInsensitive) {
  20.                         return strtolower($str1) == strtolower($str2);
  21.                 } else {
  22.                         return $str1 == $str2;
  23.                 }
  24.         }
  25. }
  26.  
  27. require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
  28. VolcanoDB::registerSearchProvider(new VolcanoSearchIPv4());
  29.  
  30. # --- TEST
  31.  
  32. /*
  33. $x = new VolcanoSearchIPv4();
  34.  
  35. assert($x->calcDistance('192.168.0.0/16',  '192.168.64.0/18') ===  2);
  36. assert($x->calcDistance('192.168.64.0/18', '192.168.64.0/18') ===  0);
  37. assert($x->calcDistance('192.168.64.0/20', '192.168.64.0/18') === -2);
  38.  
  39. assert($x->calcDistance('192.168.69.200/31', '192.168.69.202/31') === false);
  40. assert($x->calcDistance('192.168.69.200/32', '192.168.69.201/32') === false);
  41. assert($x->calcDistance('192.168.69.200',    '192.168.69.201')    === false);
  42.  
  43. assert($x->calcDistance('95.211.38.42/32', '95.211.38.42') === 0);
  44. assert($x->calcDistance('95.211.38.42', '95.211.38.42/32') === 0);
  45. */
  46.