Mercurial > hg > anonet-resdb
annotate doc/ucis.ano/bgp_graph/bgp_path_list_xml.php @ 937:dfb7ded25d66 draft
updated ns1.wakawaka.ano ip
author | wakawaka <nobody@nowhere> |
---|---|
date | Tue, 13 Mar 2012 22:31:30 +0000 |
parents | 15b952d82e4c |
children |
rev | line source |
---|---|
28 | 1 #!/usr/bin/php |
2 <?php | |
31
15b952d82e4c
PHP gets the environment in $_SERVER, not $ENV.
Nick <nick@somerandomnick.ano>
parents:
30
diff
changeset
|
3 $mynode = array_key_exists('LOCALNODE',$_SERVER)?$_SERVER['LOCALNODE']:0; |
28 | 4 |
5 $file = STDIN; | |
6 $paths = array(); | |
7 | |
8 while (!feof($file)) { | |
9 if (seekto($file, '<as-path>') === FALSE) break; | |
10 seekto($file, '<segment'); | |
11 seekto($file, '>'); | |
12 $endofsection = FALSE; | |
13 $path = $mynode; | |
14 while (!feof($file)) { | |
15 if (seekto($file, '<') === FALSE) break; | |
16 switch (fread($file, 4)) { | |
17 case 'asn>': break; | |
18 case '/seg': $endofsection = TRUE; break; | |
19 default: die('unknown tag at '.(ftell($file)-4)); | |
20 } | |
21 if ($endofsection) break; | |
22 $asn = seekto($file, '</asn>'); | |
23 $path .= ' '.$asn; | |
24 } | |
25 if (in_array($path, $paths)) continue; | |
26 $paths[] = $path; | |
27 print($path."\n"); | |
28 } | |
29 | |
30 function seekto($f, $str) { | |
31 $part = ''; | |
32 $i = 0; | |
33 $len = strlen($str); | |
34 while ($i < $len && !feof($f)) { | |
35 $c = fgetc($f); | |
36 if ($c === FALSE) return FALSE; | |
37 if ($c == $str[$i]) { | |
38 $i++; | |
39 } else { | |
40 if ($i) { | |
41 $i = 0; | |
42 $part = ''; | |
43 } | |
44 $part .= $c; | |
45 } | |
46 } | |
47 return $part; | |
48 } |