-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataserver.php
More file actions
134 lines (115 loc) · 2.78 KB
/
dataserver.php
File metadata and controls
134 lines (115 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
include_once("config.php");
include_once("lib/domain/domain.php");
include_once("lib/analysis.php");
$data = new graphvis;
$routers = getRouterHosts();
$ips = getIps();
$all_interfaces = getAllInterfaces();
/*
* create nodes for every router
*/
foreach($routers as $host) {
$node = new Node;
// build the node
$node->label = shortname($host->sysname);
$node->id = $host->sysname;
$node->title = $host->sysname;
$node->color = $colors["up-router"];
$node->size = $node_conf["size"];
$node->font = $node_conf["font"];
$node->mass = $node_conf["router-mass"];
// add the node
array_push($data->nodes, $node);
}
/*
* create nodes for every non-router ip
*/
foreach($ips as $ip) {
/*
* check if the ip is attached to a router
*/
if (false==isRouterIp($ip)){
/*
* ip is not on a router draw the node
*/
$node = new Node;
// build the node
$node->label = getNodeLabel($ip);
$node->id = $ip->ip;
$node->title = getNodeTitle($ip);
if (1==$ip->laststatus){
$node->color = $colors["up-host"];
} else {
$node->color = $colors["down-host"];
}
$node->size = $node_conf["size"];
$node->font = $node_conf["font"];
$node->mass = $node_conf["host-mass"];
// add the node
array_push($data->nodes, $node);
}
}
/*
* walk the ips again, this time creating edges from non-routers to appropriate routers
*/
foreach($ips as $ip) {
/*
* check if the ip is attached to a router
*/
if (false==isRouterIp($ip)){
/*
* get the default router for the ip
*/
$rtr_hostname = getRouterForIp($ip);
$edge = new Edge;
$edge->id=uniqid();
$edge->from = $rtr_hostname;
$edge->to = $ip->ip;
$edge->color = $colors["up-edge"];
$edge->width = $edge_conf["width"];
array_push($data->edges, $edge);
}
}
/*
* walk the router ips, this time creating edges from routers to appropriate routers
*/
foreach($all_interfaces as $interface) {
/*
* get the router name for the ip
*/
$interface_hostname =$interface->host;
/*
* get ip object for ip address
*/
$ipObj = getIp($interface->ip);
/*
* get the default router for the ip
*/
$rtr_hostname = getRouterForIp($ipObj);
//echo $interface->ip." : ".$interface_hostname." ".$rtr_hostname."<br>\n";
if (false!=$rtr_hostname){
if ($rtr_hostname!=$interface_hostname){
// var_dump($interface->ip);
$edge = new Edge;
$edge->id=uniqid();
$edge->from = $interface_hostname;
$edge->to = $rtr_hostname;
$edge->color = $colors["up-edge"];
$edge->width = $edge_conf["width"];
array_push($data->edges, $edge);
}
}
}
// add a line b/t the gateways
$edge = new Edge;
$edge->id=uniqid();
$edge->from = "gateway.ascot.khubla.lan";
$edge->to = "gateway.spring.khubla.lan";
$edge->color = "blue";
$edge->width = 2;
$edge->dashes = true;
array_push($data->edges, $edge);
$json = json_encode($data);
echo $json;
?>