source: genesis/tools/FreeBSD7_x/g_list.pl@ 6958

Last change on this file since 6958 was 6958, checked in by rick, 15 years ago

Made output buffered, allowing Content-Header to be set correctly, fixing warnings/complains of curl/fetch.

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