annotate doc/ucis.ano/bgp_graph/bgp_path_list_xml.php @ 1260:f5ad11b817f1 draft default tip master

switched to using the git subdomain for git repo url
author epoch <epoch@hack.thebackupbox.net>
date Sat, 09 Oct 2021 09:21:28 +0000
parents 15b952d82e4c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
1 #!/usr/bin/php
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
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
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
4
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
5 $file = STDIN;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
6 $paths = array();
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
7
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
8 while (!feof($file)) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
9 if (seekto($file, '<as-path>') === FALSE) break;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
10 seekto($file, '<segment');
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
11 seekto($file, '>');
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
12 $endofsection = FALSE;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
13 $path = $mynode;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
14 while (!feof($file)) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
15 if (seekto($file, '<') === FALSE) break;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
16 switch (fread($file, 4)) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
17 case 'asn>': break;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
18 case '/seg': $endofsection = TRUE; break;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
19 default: die('unknown tag at '.(ftell($file)-4));
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
20 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
21 if ($endofsection) break;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
22 $asn = seekto($file, '</asn>');
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
23 $path .= ' '.$asn;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
24 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
25 if (in_array($path, $paths)) continue;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
26 $paths[] = $path;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
27 print($path."\n");
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
28 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
29
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
30 function seekto($f, $str) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
31 $part = '';
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
32 $i = 0;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
33 $len = strlen($str);
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
34 while ($i < $len && !feof($f)) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
35 $c = fgetc($f);
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
36 if ($c === FALSE) return FALSE;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
37 if ($c == $str[$i]) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
38 $i++;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
39 } else {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
40 if ($i) {
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
41 $i = 0;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
42 $part = '';
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
43 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
44 $part .= $c;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
45 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
46 }
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
47 return $part;
4dbe5bf653bb Added bgp graph scripts
ivo <ivo@UFO-Net.nl>
parents:
diff changeset
48 }