1 | <? |
---|
2 | function genSectionEntete() { |
---|
3 | $content = "default:\n"; |
---|
4 | $content .= " community: public\n"; |
---|
5 | $content .= " snmpport: 161\n\n"; |
---|
6 | |
---|
7 | $buffer = "<TR><TD id=title>Section Entête:</TD></TR>"; |
---|
8 | $buffer .= "<TR><TD>default:<BR />"; |
---|
9 | $buffer .= "community: public<BR />"; |
---|
10 | $buffer .= "snmpport: 161</TD></TR>"; |
---|
11 | |
---|
12 | echo $buffer ; |
---|
13 | |
---|
14 | return $content ; |
---|
15 | |
---|
16 | } |
---|
17 | |
---|
18 | |
---|
19 | function genSectionSwitch() { |
---|
20 | |
---|
21 | $content = "switch:\n"; |
---|
22 | $buffer = "<TR><TD id=title>Section switch</TD></TR>"; |
---|
23 | $resultat = selectSwitch("") ; |
---|
24 | if ( !is_string($resultat) ) { |
---|
25 | |
---|
26 | while ( $rowSwitch = mysql_fetch_assoc($resultat) ) { |
---|
27 | $content .= " - hostname: " . $rowSwitch['idSwitch'] . "\n"; |
---|
28 | $content .= " location: " . $rowSwitch['location'] . "\n"; |
---|
29 | $content .= " level: " . $rowSwitch['level'] . "\n"; |
---|
30 | $content .= " portignore: \n"; |
---|
31 | $content .= "\n\n\n"; |
---|
32 | $buffer .= "<TR><TD>".$rowSwitch['idSwitch']."<BR />" |
---|
33 | .$rowSwitch['location']."<BR />" |
---|
34 | .$rowSwitch['level']."<BR />" |
---|
35 | .$rowSwitch['portignore']."</TD></TR>"; |
---|
36 | } |
---|
37 | |
---|
38 | } |
---|
39 | echo $buffer ; |
---|
40 | return $content; |
---|
41 | } |
---|
42 | |
---|
43 | function genSectionNetwork() { |
---|
44 | $content = "network:\n"; |
---|
45 | $buffer = "<TR><TD id=title>Section Netwotk</TD></TR>"; |
---|
46 | $resultat = selectNetwork("") ; |
---|
47 | if ( !is_string($resultat) ) { |
---|
48 | |
---|
49 | //TODO: attention je n'ai pas pris en compte dans la génération du fichier plusieurs plage reseau pour un nom reseau |
---|
50 | while ( $rowNetwork = mysql_fetch_assoc($resultat) ) { |
---|
51 | $content .= " " . $rowNetwork['nameNetwork'] . ":\n"; |
---|
52 | $content .= " ip-subnet:\n"; |
---|
53 | $content .= " - add: ".$rowNetwork['idNetwork'] . "\n"; |
---|
54 | $content .= " interface: " . $rowNetwork['interface'] . "\n"; |
---|
55 | $content .= " main-router: " . $rowNetwork['mainRouter'] . "\n"; |
---|
56 | $content .= "\n\n\n"; |
---|
57 | |
---|
58 | $buffer .="<TR><TD>".$rowNetwork['nameNetwork']."<BR />" |
---|
59 | ."ip-subnet:<BR />" |
---|
60 | ."- add: ".$rowNetwork['idNetwork']."<BR />" |
---|
61 | ."interface: ".$rowNetwork['interface']."<BR />" |
---|
62 | ."main-router: ".$rowNetwork['mainRouter'] ."</TD></TR>"; |
---|
63 | } |
---|
64 | } |
---|
65 | echo $buffer ; |
---|
66 | |
---|
67 | return $content ; |
---|
68 | } |
---|
69 | |
---|
70 | function genSectionRouter() { |
---|
71 | |
---|
72 | $content = "router:\n"; |
---|
73 | |
---|
74 | $filter = "type = 'routeur'"; |
---|
75 | $resultat = selectDevice($filter) ; |
---|
76 | if ( !is_string($resultat) ) { |
---|
77 | |
---|
78 | while ( $rowDev = mysql_fetch_assoc($resultat) ) { |
---|
79 | $content .= " - hostname: " . $rowDev['hostname'] . "\n"; |
---|
80 | $content .= " mac-address: " . $rowDev['mac'] . "\n"; |
---|
81 | $buffer .= "<TR><TD> - hostname: ".$rowDev['hostname']."<BR />" |
---|
82 | ."mac-address: ".$rowDev['mac']."</TD></TR>"; |
---|
83 | } |
---|
84 | } |
---|
85 | echo $buffer ; |
---|
86 | $content .="\n\n"; |
---|
87 | |
---|
88 | return $content ; |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | function genKlaskConf() { |
---|
95 | |
---|
96 | $fileKlask = "./klask/klask.conf"; |
---|
97 | |
---|
98 | if (!$handle=fopen($fileKlask, "w+")) { |
---|
99 | $buffer = "Open file $fileKlask: [FAILED]"; |
---|
100 | return $buffer; |
---|
101 | } |
---|
102 | |
---|
103 | $content = genSectionEntete() ; |
---|
104 | $content .= genSectionNetwork() ; |
---|
105 | $content .= genSectionRouter() ; |
---|
106 | $content .= genSectionSwitch() ; |
---|
107 | |
---|
108 | if (!fwrite($handle, $content)) { |
---|
109 | $buffer = "Write in file $fileKlask: [FAILED]"; |
---|
110 | return $buffer; |
---|
111 | } |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | function klaskCommand($idRight) { |
---|
116 | $pathKlask = "sudo /usr/sbin/klask" ; |
---|
117 | |
---|
118 | $buffet = ""; |
---|
119 | if ($idRight == "exportdb" ) { |
---|
120 | $command=exec($pathKlask." ".$idRight , $ret) ; |
---|
121 | |
---|
122 | $cpt=0; |
---|
123 | $buffer = "<TR><TD id=title>Switch</TD><TD id=title>Ports</TD><TD id=title>Hostname</TD><TD id=title>IP</TD><TD id=title>Mac</TD><TD id=title>Date</TD></TR>"; |
---|
124 | foreach ($ret as $line) { |
---|
125 | $cpt++; |
---|
126 | if ($cpt > 2) { |
---|
127 | $buffer2 = str_replace('[ ]+', ' ' , trim($line)); |
---|
128 | $Tsplit = split('[ ]+', $buffer2); |
---|
129 | $buffer .= "<TR><TD id='klask'>".trim($Tsplit[0]) ."</TD><TD id='klask'> ". trim($Tsplit[1]) . "</TD><TD id='klask'>". trim($Tsplit[3]) . "</TD><TD id='klask'> " . trim($Tsplit[4]) ."</TD><TD id='klask'>" . trim($Tsplit[5]) . "</TD><TD id=klask>" . trim($Tsplit[6]) ." " . $Tsplit[7] ."</TD></TR>"; |
---|
130 | } |
---|
131 | } |
---|
132 | return $buffer ; |
---|
133 | |
---|
134 | }else{ |
---|
135 | |
---|
136 | if ($idRight == "updatesw") { |
---|
137 | |
---|
138 | $command=exec($pathKlask." ".$idRight , $ret) ; |
---|
139 | $buffer = ""; |
---|
140 | foreach ( $ret as $line ) { |
---|
141 | $buffer .= "$line <BR>"; |
---|
142 | } |
---|
143 | return $buffer ; |
---|
144 | }else{ |
---|
145 | if ($idRight == "updatedb") { |
---|
146 | |
---|
147 | $command=exec($pathKlask." ".$idRight , $ret) ; |
---|
148 | $buffer = ""; |
---|
149 | foreach ( $ret as $line ) { |
---|
150 | $buffer = "$line <BR>"; |
---|
151 | } |
---|
152 | return $buffer ; |
---|
153 | }else{ |
---|
154 | if ($idRight == "exportsw") { |
---|
155 | |
---|
156 | $command=exec($pathKlask." ".$idRight , $ret) ; |
---|
157 | $buffer = ""; |
---|
158 | foreach ( $ret as $line ) { |
---|
159 | if (fnmatch("Switch parent and children port inter-connection", $line)) { |
---|
160 | $buffer .= "<TR><TD COLSPAN=5>Switch parent and children port inter-connection</TD></TR>"; |
---|
161 | }else{ |
---|
162 | if ( fnmatch("Switch output port and parent port connection", $line)) { |
---|
163 | $buffer .= "<TR><TD COLSPAN=5>Switch output port and parent port connection</TD></TR>"; |
---|
164 | }else{ |
---|
165 | $buffer2 = str_replace('[ ]+', ' ' , trim($line)); |
---|
166 | $buffer2 = str_replace('[<--+]', ' ' , trim($buffer2)); |
---|
167 | $Tsplit = split('[ ]+', $buffer2); |
---|
168 | $buffer .= "<TR><TD id='klask'>".trim($Tsplit[0]) ."</TD><TD id='klask'> ". trim($Tsplit[1]) . "</TD><TD id='klask'>". trim($Tsplit[3]) . "</TD><TD id=klask>". trim($Tsplit[4])."</TD></TR>"; |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | return $buffer ; |
---|
173 | }else{ |
---|
174 | if ( $idRight == "genmap") { |
---|
175 | $command=exec($pathKlask." exportsw -f dot > ./klask/map.dot" , $ret) ; |
---|
176 | $command=exec("dot -Tjpg ./klask/map.dot > ./klask/map.jpg", $ret); |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | function KlaskSearch($ip) { |
---|
187 | $pathKlask = "sudo /usr/sbin/klask" ; |
---|
188 | $command=exec($pathKlask." search " ."$ip", $ret) ; |
---|
189 | $buffer = ""; |
---|
190 | $cpt=0; |
---|
191 | foreach ( $ret as $line ) { |
---|
192 | $cpt++; |
---|
193 | if ( $cpt == 2 ) { |
---|
194 | if ( !empty($line) ) { |
---|
195 | $buffer2 = str_replace('[ ]+', ' ' , trim($line)); |
---|
196 | $Tsplit = split('[ ]+', $buffer2); |
---|
197 | $buffer = "<B>Nom: </B>" . $Tsplit[2] ."<BR />"; |
---|
198 | $buffer .= "<B>IP: </B> " . $Tsplit[3] . "<BR />"; |
---|
199 | $buffer .= "<B>Mac: </B> " . $Tsplit[4] . "<BR />"; |
---|
200 | $buffer .= "<B>Connecté au Switch: </B>" . $Tsplit[0]. "<BR />"; |
---|
201 | $buffer .= "<B>Port: </B>" . $Tsplit[1]; |
---|
202 | return $buffer ; |
---|
203 | }else{ |
---|
204 | return "" ; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | ?> |
---|