source: genesis/config/iris/node/FreeBSD/8.0-RELEASE/g_list.pl

Last change on this file was 8945, checked in by rick, 14 years ago

Ugly hack to make the 'Update' button work behind a http proxy.

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