Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. # Volcano Format
  4.  
  5. error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED);
  6.  
  7. class VOF_Category {
  8.         public $nid;
  9.         public $localrootElement;
  10.         public $localrootFile;
  11.         public $authrootElement;
  12.         public $authrootFile;
  13.  
  14.         public function __construct($nid, $localrootElement, $localrootFile, $authrootElement, $authrootFile) {
  15.                 $this->nid = $nid;
  16.                 $this->localrootElement = $localrootElement;
  17.                 $this->localrootFile = $localrootFile;
  18.                 $this->authrootElement = $authrootElement;
  19.                 $this->authrootFile = $authrootFile;
  20.         }
  21. }
  22.  
  23. $categories = array();
  24. include __DIR__ . '/local_config.inc.php';
  25.  
  26.  
  27.  
  28. # Aufruf:
  29. # nid, obj, route[]
  30. print_r(show_obj('1.3.6.1.4.1.37476.9999.1.2.3.4', 'oid', array(
  31. '1.3.6.1.4.1.37476',
  32. '1.3.6.1.4.1.37476.9999',
  33. '1.3.6.1.4.1.37476.9999.1',
  34. '1.3.6.1.4.1.37476.9999.1.2',
  35. '1.3.6.1.4.1.37476.9999.1.2.3'
  36. )));
  37. die();
  38.  
  39.  
  40.  
  41. $req_cat = $_GET['cat']; # todo als hash (nid, localelement)
  42. $req_obj = $_GET['obj'];
  43.  
  44. if ($req_cat == '') {
  45.         // List all categories
  46.         list_nids();
  47. } else {
  48.         // List specific object
  49.         $cat = get_cat($req_cat);
  50.         $title = $cat->nid . ' - ' . $req_obj;
  51.         echo "<h1>$title</h1>";
  52.         $localRoot = $cat->localrootElement;
  53. }
  54.  
  55. function list_nids($categories) {
  56.         echo '<ul>';
  57.         foreach ($categories as $x) {
  58.                 $id = cat_id($x);
  59.                 $desc = $x->nid;
  60.                 echo '<li><a href="?cat='.$id.'">'.$desc.'</a></li>';
  61.         }
  62.         echo '</ul>';
  63. }
  64.  
  65. function cat_id($cat) {
  66.         return sha1($cat->nid.':'.$cat->localrootElement);
  67. }
  68.  
  69. function get_cat($categoryId, $categories) {
  70.         foreach ($categories as $cat) {
  71.                 if ($categoryId == cat_id($cat)) return $cat;
  72.         }
  73.         return false;
  74. }
  75.  
  76.  
  77. function show_obj($obj, $nid, $route) {
  78.         global $categories;
  79.         foreach ($categories as $c) {
  80.                 if (($c->nid == $nid) && ($c->localrootElement == $route[0])) {
  81.                         $cur_obj = $c->localrootElement;
  82.                         $cur_fil = $c->localrootFile;
  83.                 }
  84.         }
  85.         if (!isset($cur_obj)) return false;
  86.         if (!isset($cur_fil)) return false;
  87.  
  88.         foreach ($route as $i => $r) {
  89.                 if ($i == 0) continue;
  90.                 $x = search_delegation_file($cur_fil, $nid, $cur_obj, $r);
  91.                 if ($x === false) return false;
  92.                 if ($x != '') $cur_file = $x;
  93.                 $cur_obj = $r;
  94.         }
  95.  
  96.         return array($cur_fil, $cur_obj);
  97. }
  98.  
  99. function search_delegation_file($file, $nid, $rootobj, $childobj) {
  100.         $cont = file($file); # todo: cache
  101.  
  102.         echo "R=$rootobj, C=$childobj => ";
  103.         if (substr($childobj.'.', 0, strlen($rootobj)+1) == $rootobj.'.') {
  104.                 $childobj = substr($childobj, strlen($rootobj)+1);
  105.         }
  106.         echo "$childobj\n";
  107.  
  108.         foreach ($cont as $c) {
  109.                 preg_match_all("@^\s*$nid:$rootobj\s+delegation\s+$childobj\s*(.+)\$@", $c, $m);
  110.                 if (!isset($m[1][0])) continue;
  111.                 $x = $m[1][0];
  112.                 $x = trim($x);
  113.                 if ($x == '<here>') $x = '';
  114.                 return $x;
  115.         }
  116.         return false;
  117. }
  118.  
  119. ?>
  120.