1 | #! /usr/bin/perl -w
|
---|
2 | #
|
---|
3 | #
|
---|
4 | #
|
---|
5 |
|
---|
6 | # eerst even een subje om ervoor te zorgen dat de hostname + file bekend
|
---|
7 | # is
|
---|
8 | $request=$ENV{'REQUEST_URI'};
|
---|
9 | if ($request=~/cgi-bin\/g_list.pl\/(.*)$/) {
|
---|
10 | ($hostname,$file)=split(/\//,$1);
|
---|
11 | $title="$hostname $file";
|
---|
12 | }
|
---|
13 | else {
|
---|
14 | $title="listing";
|
---|
15 | };
|
---|
16 |
|
---|
17 | #(inter)net env
|
---|
18 | $cgi_dir="$hostname/cgi-bin";
|
---|
19 | $source="$cgi_dir/g_list.pl";
|
---|
20 |
|
---|
21 | #path variablen
|
---|
22 | $home="/home/wleiden/genesis/";
|
---|
23 | $ndir="$home/nodes";
|
---|
24 | $toolfile="$home/tools/wleiden.pl";
|
---|
25 |
|
---|
26 | #exec vars
|
---|
27 | $svn='/usr/local/bin/svn';
|
---|
28 | $html=1;
|
---|
29 |
|
---|
30 | $functions_only=1;do $toolfile || die;
|
---|
31 |
|
---|
32 | #gebruik van simple subje om ervoor te zorgen dat de print netjes in het
|
---|
33 | #programma gestopt kan worden
|
---|
34 | sub printline {
|
---|
35 | print "$_[0] \n";
|
---|
36 | };
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | $browser=$ENV{'HTTP_USER_AGENT'};
|
---|
42 | if ($browser=~/curl|wget|fetch/i) {
|
---|
43 | $HTML=0;
|
---|
44 | printline("Content-type: text/html\n\n");
|
---|
45 | }
|
---|
46 | else {
|
---|
47 | $HTML=1;
|
---|
48 | printline("Content-type: text/html\n\n");
|
---|
49 | printline("<HTML>");
|
---|
50 | printline("<TITLE>Genesis $title</TITLE>");
|
---|
51 | printline("<BODY BGcolor=white>");
|
---|
52 | printline("<BASE HREF=$hostname>");
|
---|
53 | };
|
---|
54 |
|
---|
55 |
|
---|
56 | if ($hostname eq '') {
|
---|
57 | if ($ENV{"QUERY_STRING"}=~/update/i) {
|
---|
58 | select(STDERR); $| = 1; # make unbuffered
|
---|
59 | select(STDOUT); $| = 1; # make unbuffered
|
---|
60 | printline("<H2>Please wait while updating svn...</H2><P><PRE>");
|
---|
61 | system("$svn update $home");
|
---|
62 | close(SVN);
|
---|
63 | printline("</PRE>");
|
---|
64 | printline("<H2>Done.<H2><P>");
|
---|
65 | printline("Click <A HREF=$source>here</A>");
|
---|
66 | printline("if you're not forwarded automaticly in 5 seconds.<P>");
|
---|
67 | printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
|
---|
68 | }
|
---|
69 | else {
|
---|
70 | g_list( );
|
---|
71 | };
|
---|
72 | }
|
---|
73 | else {
|
---|
74 | $dir="$ndir/$hostname";
|
---|
75 | if (! -d $dir ) {
|
---|
76 | if ($HTML) {
|
---|
77 | print "<H1>Host $hostname not found: $dir</H1><P>\n";
|
---|
78 | }
|
---|
79 | else {
|
---|
80 | print "Host $hostname not found: $dir\n";
|
---|
81 | };
|
---|
82 | }
|
---|
83 | elsif ($file eq '') {
|
---|
84 | foreach $file ('txtconfig','config','dhcpd.conf','zebra.conf','ospfd.conf',
|
---|
85 | 'rc.local','rc.node.local','resolv.conf', 'named.conf',
|
---|
86 | 'snmpd.local.conf') {
|
---|
87 | if ($HTML) {
|
---|
88 | print "$file<BR>\n";
|
---|
89 | }
|
---|
90 | else {
|
---|
91 | print "$file\n";
|
---|
92 | };
|
---|
93 | };
|
---|
94 | }
|
---|
95 | elsif ($file eq 'config') {
|
---|
96 | g_print($hostname);
|
---|
97 | }
|
---|
98 | elsif ($file eq 'txtconfig') {
|
---|
99 | $HTML=0;g_print($hostname);
|
---|
100 | }
|
---|
101 | elsif ($file=~/(dhcpd.conf|mrtg.cfg|zebra.conf|ospfd.conf|sh|linux.sh|rc.node.local|rc.local|resolv.conf|named.conf|snmpd.local.conf)/) {
|
---|
102 | g_generate($file,$hostname);
|
---|
103 | };
|
---|
104 | };
|
---|
105 |
|
---|
106 |
|
---|
107 | if ($HTML) {
|
---|
108 | print <<EOF;
|
---|
109 | </BODY>
|
---|
110 | </HTML>
|
---|
111 | EOF
|
---|
112 | }
|
---|
113 |
|
---|
114 | sub g_list {
|
---|
115 | if ($HTML) {
|
---|
116 | $svn_version=svn_version("$ndir");
|
---|
117 | if ($svn_version=~/Last Changed Rev: (\d+)/) {
|
---|
118 | $revision=$1;
|
---|
119 | };
|
---|
120 | printline("<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>");
|
---|
121 | printline("$svn_version");
|
---|
122 | printline("</PRE>");
|
---|
123 | printline("<FORM METHOD=get ACTION=$source>");
|
---|
124 | printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
|
---|
125 | printline("</FORM>");
|
---|
126 | printline("<TABLE BORDER=1>");
|
---|
127 | };
|
---|
128 |
|
---|
129 | opendir(DIR, $ndir) || die "can't opendir $home: $!";
|
---|
130 | @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
|
---|
131 | closedir DIR;
|
---|
132 | foreach $dir (sort @dirs) {
|
---|
133 | if ($dir=~/attic/) {
|
---|
134 | next;
|
---|
135 | };
|
---|
136 | $hostname=$dir;
|
---|
137 | if (! $HTML) {
|
---|
138 | print "$hostname\n";
|
---|
139 | }
|
---|
140 | else {
|
---|
141 | printline("<TR><TD><A HREF=g_list.pl/$hostname/config>$hostname</A></TD>");
|
---|
142 | foreach $file ('linux.sh','dhcpd.conf','zebra.conf','ospfd.conf',
|
---|
143 | 'rc.node.local','rc.local','resolv.conf','named.conf',
|
---|
144 | 'snmpd.local.conf') {
|
---|
145 | printline("<TD><A HREF=g_list.pl/$hostname/$file>$file</A></TD>\n");
|
---|
146 | };
|
---|
147 | };
|
---|
148 | };
|
---|
149 | printline("</TABLE><P>");
|
---|
150 | };
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 | sub svn_version {
|
---|
155 | local($file,$char)=@_;
|
---|
156 | local($svn_version);
|
---|
157 | $svn_version=`$svn info $file`;
|
---|
158 | if ($char ne '') {
|
---|
159 | $svn_version=~s/^([^$char].*)/$char $1/mgi;
|
---|
160 | };
|
---|
161 | return($svn_version);
|
---|
162 | };
|
---|
163 |
|
---|
164 |
|
---|
165 | sub g_print {
|
---|
166 | local($hostname)=@_;
|
---|
167 | $config="$ndir/$hostname/wleiden.conf";
|
---|
168 |
|
---|
169 | if (! $HTML) {
|
---|
170 | print svn_version($config,'#');
|
---|
171 | open (CFG,$config) || die;
|
---|
172 | while (<CFG>) {print $_;}
|
---|
173 | close(CFG);
|
---|
174 | }
|
---|
175 | else {
|
---|
176 | printline("<H1>Genesis configuratie voor: $hostname</H1><P>");
|
---|
177 | printline("<PRE>" . svn_version($config) . "</PRE><P>");
|
---|
178 |
|
---|
179 | do($config) || die;
|
---|
180 | parse_config();
|
---|
181 |
|
---|
182 | $TP='';
|
---|
183 | if ($tproxy !~ m/no/i) {
|
---|
184 | $TP .= "\n";
|
---|
185 | $TP .= "Tproxy on cidr range $tproxy";
|
---|
186 | $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
|
---|
187 | unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
|
---|
188 | };
|
---|
189 |
|
---|
190 | printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>");
|
---|
191 | printline("master_ip=$master_ip");
|
---|
192 | printline("AGGREGATE=$AGGREGATE");
|
---|
193 | printline("");
|
---|
194 | printline("gw_open=$gw_open");
|
---|
195 | printline("nodetype=$nodetype");
|
---|
196 | printline("nodename=$nodename");
|
---|
197 | printline("");
|
---|
198 | printline("NS_forward=$NS_forward");
|
---|
199 | printline("NS_resolv=$NS_resolv");
|
---|
200 | printline("");
|
---|
201 | printline("location=$location");
|
---|
202 | printline("DISK=$DISK");
|
---|
203 | printline("");
|
---|
204 | printline("X=$X");
|
---|
205 | printline("Y=$Y");
|
---|
206 | printline("");
|
---|
207 | printline("OS=$OS");
|
---|
208 | printline("");
|
---|
209 | printline("$TP");
|
---|
210 | printline("</PRE></TD></TR>");
|
---|
211 |
|
---|
212 | foreach $if (sort keys %config) {
|
---|
213 | if ($if=~/^(.*):\d+/) {
|
---|
214 | $subs{$1}++;
|
---|
215 | };
|
---|
216 | };
|
---|
217 |
|
---|
218 | foreach $if (sort keys %config) {
|
---|
219 | if ($if=~/^([^:]+)/) {
|
---|
220 | $mymain=$1;
|
---|
221 | }
|
---|
222 | else {
|
---|
223 | $mymain='';
|
---|
224 | };
|
---|
225 |
|
---|
226 | if ($if!~/:\d+/) {
|
---|
227 | $main=1;$cc='66'
|
---|
228 | }
|
---|
229 | else {
|
---|
230 | $main=0;
|
---|
231 | $cc='cc';
|
---|
232 | };
|
---|
233 |
|
---|
234 | if (! ($ip=$IP{$if})) {
|
---|
235 | $ip='dhcp?';
|
---|
236 | };
|
---|
237 | if ($TYPE{$if}=~/wireless/) {
|
---|
238 | $color="#${cc}FFFF";
|
---|
239 | };
|
---|
240 | if ($TYPE{$if}=~/ethernet/) {
|
---|
241 | $color="#FFFF${cc}";
|
---|
242 | };
|
---|
243 |
|
---|
244 | $cfg=$config{$if};
|
---|
245 | $cfg=~s/(.*KEY.*=).*/${1}***********/;
|
---|
246 | $cfg=~s/(.*PWD.*=).*/${1}***********/;
|
---|
247 | $cfg=~s/(.*CODE.*=).*/${1}***********/;
|
---|
248 | $cfg=~s/(.*PASS.*=).*/${1}***********/;
|
---|
249 |
|
---|
250 | if ($main) {
|
---|
251 | printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};
|
---|
252 | $c=4;
|
---|
253 | }
|
---|
254 | else {
|
---|
255 | $c=3;
|
---|
256 | print "<TR bgcolor=$color>";
|
---|
257 | };
|
---|
258 | $cfg=~s/</</gi;
|
---|
259 | $cfg=~s/>/>/gi;
|
---|
260 |
|
---|
261 | printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>");
|
---|
262 | printline("<TR><TD COLSPAN=$c><PRE>");
|
---|
263 | printline("$cfg");
|
---|
264 | printline("</PRE></TD>");
|
---|
265 | printline("<TR><TD COLSPAN=$c> </TD>");
|
---|
266 | };
|
---|
267 | printline("</TABLE>");
|
---|
268 | };
|
---|
269 | };
|
---|
270 |
|
---|
271 |
|
---|
272 | sub g_generate {
|
---|
273 | ($file,$hostname)=@_;
|
---|
274 | $config="$ndir/$hostname/wleiden.conf";
|
---|
275 |
|
---|
276 | if (! -r $config) {
|
---|
277 | if ($HTML) {
|
---|
278 | printline("<H1>File $file not found: $config</H1><P>");
|
---|
279 | }
|
---|
280 | else {
|
---|
281 | printline("File $file not found: $config");
|
---|
282 | };
|
---|
283 | }
|
---|
284 | else {
|
---|
285 | if ($file=~/(ospfd|zebra)/) {
|
---|
286 | $char='!';
|
---|
287 | }
|
---|
288 | else {
|
---|
289 | $char='#';
|
---|
290 | };
|
---|
291 |
|
---|
292 | $svn_versiont=svn_version($toolfile,$char);
|
---|
293 | $svn_versionc=svn_version($config,$char);
|
---|
294 |
|
---|
295 | if ($svn_versiont=~/Last Changed Rev: (\d+)/) {
|
---|
296 | $tool_rev=$1;
|
---|
297 | };
|
---|
298 | if ($svn_versionc=~/Last Changed Rev: (\d+)/) {
|
---|
299 | $config_rev=$1;
|
---|
300 | };
|
---|
301 |
|
---|
302 | if ($tool_rev >= $config_rev) {
|
---|
303 | $svn_version=$svn_versiont . $svn_versionc;
|
---|
304 | }
|
---|
305 | else {
|
---|
306 | $svn_version=$svn_versionc;
|
---|
307 | };
|
---|
308 |
|
---|
309 | if ($HTML) {
|
---|
310 | printline("<H1>Genesis $file voor: $hostname</H1><P>");
|
---|
311 | };
|
---|
312 |
|
---|
313 | do($config) || die;
|
---|
314 | parse_config();
|
---|
315 | read_areas();
|
---|
316 | do_it();
|
---|
317 |
|
---|
318 | if ($file=~/ospfd.conf/) {$pr=$ospfd;}
|
---|
319 | if ($file=~/zebra.conf/) {$pr=$zebra;}
|
---|
320 | if ($file=~/dhcpd.conf/) {$pr=$dhcp;}
|
---|
321 | if ($file=~/snmpd.local.conf/) {$pr=$snmpd;}
|
---|
322 | if ($file=~/mrtg.cfg/) {$pr=$mrtg;}
|
---|
323 | if ($file=~/linux.sh/) {$pr=$nwcfg;}
|
---|
324 | if ($file=~/sh/) {$pr=$sh;}
|
---|
325 | if ($file=~/rc.node.local/) {$pr=$rcconf;}
|
---|
326 | if ($file=~/rc.local/) {$pr=$freebsd;}
|
---|
327 | if ($file=~/resolv.conf/) {$pr=$resolv;}
|
---|
328 | if ($file=~/named.conf/) {$pr=$named;}
|
---|
329 |
|
---|
330 | if ($HTML) {
|
---|
331 | $pr=~s/</</gi;$mrtg=~s/>/>/gi;
|
---|
332 | printline("<PRE>$pr</PRE>");
|
---|
333 | }
|
---|
334 | else {
|
---|
335 | print $pr;
|
---|
336 | };
|
---|
337 | };
|
---|
338 | };
|
---|