source: genesis/tools/proxy-8.0/g_list.pl@ 7452

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

Make the update button work again (not live output anymore, but working it is :-))

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1#!/usr/bin/perl
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 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=~/.*g_list.pl\/(.*)$/) {
69 ($node,$file)=split(/\//,$1);
70 $title="$node $file";
71 if ( $debug ) { print "Node: $node\n"; }
72 if ( $debug ) { print "File: $file\n"; }
73}
74else {
75 $title="listing";
76};
77
78
79#controleer wat de browser is
80#en zorgen dan er de nodige tags geprint worden
81$browser=$ENV{'HTTP_USER_AGENT'};
82if( $browser=~/curl|wget|fetch/i) {
83 $HTML=0;
84}
85else {
86 $HTML=1;
87 printline("<HTML>");
88 printline("<TITLE>Genesis $title</TITLE>");
89 printline("<BODY BGcolor=white>");
90};
91
92
93#als geen node gespecificeerd dan kijken of svn geupdate is gevraagd
94if( $node eq '') {
95 if( $ENV{"QUERY_STRING"}=~/update/i) {
96 printline("<PRE>");
97 #select(STDERR); $| = 1; # make unbuffered
98 #select(STDOUT); $| = 1; # make unbuffered
99 printline(`$svn update $ndir`);
100 printline("</PRE>");
101 printline("<H2>Done.<H2><P>");
102 printline("Click <A HREF=$source>here</A>");
103 printline("if you're not forwarded automaticly in 5 seconds.<P>");
104 printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
105 }
106 else {
107 g_list( );
108 }
109}
110elsif( $node eq 'filelist' ) {
111 filelist( );
112}
113elsif( $node eq 'nodelist' ) {
114 nodelist( );
115}
116else {
117 if( $file eq '') {
118 filelist( );
119 }
120 elsif( $file eq 'config') {
121 g_print($hostname);
122 }
123 else {
124 foreach my $tmpFile ( sort @filelist) {
125 if( $file eq $tmpFile ) {
126 g_generate($file);
127 };
128 };
129 };
130};
131
132#plaats de sluit HTML tags
133if( $HTML) {
134 printline("</BODY></HTML>");
135}
136
137$output = join('',@HTTP_BODY);
138print "Content-Length: " . length($output) . " \n";
139print "Content-type: text/html\n\n";
140print $output;
141
142
143#Het opbouwen van het begin scherm
144sub g_list {
145 if( $HTML) {
146 my $svn_version=svn_version("$ndir");
147 if( $svn_version=~/Last Changed Rev: (\d+)/) {
148 $revision=$1;
149 };
150 printline("<H1>Genesis config - last changed rev $revision</H1><P>\n<PRE>");
151 printline("$svn_version");
152 printline("</PRE>");
153 printline("<FORM METHOD=get ACTION=$source>");
154 printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
155 printline("</FORM>");
156 printline("<TABLE BORDER=1>");
157 };
158
159 @dirs = listnodes( );
160 foreach $dir (sort @dirs) {
161 if( $dir=~/attic/ ) {
162 next;
163 };
164 my $node = $dir;
165 if( ! $HTML ) {
166 printline("$node");
167 }
168 else {
169 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
170 foreach $file (sort @filelist) {
171 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
172 };
173 };
174 };
175 if( $HTML ) {
176 printline("</TABLE><P>");
177 };
178};
179
180
181
182#ophalen svn versie
183sub svn_version {
184 local($file)=@_;
185 local($svn_version);
186 $svn_version=`$svn info $file`;
187 return($svn_version);
188};
189
190
191
192#netjes de configuratie printen
193sub g_print {
194 my $config="$ndir/$node/$configfile";
195 parse_config($config);
196
197 printline("<H1>Genesis configuratie voor: $node</H1><P>");
198 printline("<PRE>" . svn_version($config) . "</PRE><P>");
199
200
201 no warnings "once";
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 no warnings "once";
289};
290
291
292
293#Generen config
294sub g_generate {
295 my $file=$_[0];
296 $config="$ndir/$node/$configfile";
297 $svn_versiont=svn_version($toolfile);
298 $svn_versionc=svn_version($config);
299
300 if( $svn_versiont=~/Last Changed Rev: (\d+)/ ) {
301 $tool_rev=$1;
302 };
303 if( $svn_versionc=~/Last Changed Rev: (\d+)/ ) {
304 $config_rev=$1;
305 };
306
307 if( $tool_rev >= $config_rev) {
308 $svn_version=$svn_versiont . $svn_versionc;
309 }
310 else {
311 $svn_version=$svn_versionc;
312 };
313
314 if( $HTML) {
315 printline("<H1>Genesis $file voor: $hostname</H1><P>");
316 };
317
318 parse_config($config);
319 $pr=do_it($file);
320
321
322 if( $HTML ) {
323 $pr=~s/</&lt;/gi;
324 printline("<PRE>$pr</PRE>");
325 } else {
326 @HTTP_BODY = $pr;
327 };
328};
Note: See TracBrowser for help on using the repository browser.