source: genesis/tools/FreeBSD6_x/g_list.pl@ 5722

Last change on this file since 5722 was 5722, checked in by rick, 17 years ago

Made the genesis configuration machine independed and documented how-to
install it

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.8 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 $local_conf_file="./genesis.conf.local";
9do($local_conf_file) || die("Cann't open $local_conf_file");
10
11do($conf_file) || die("Cann't open $conf_file");
12
13
14my $HTML=1;
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 print "$_[0] \n";
23};
24
25sub filelist {
26 foreach $file ( sort @filelist) {
27 if( $HTML) {
28 print "$file<BR>\n";
29 }
30 else {
31 print "$file\n";
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 print "$node<BR>\n";
57 }
58 else {
59 print "$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 printline("Content-type: text/html\n\n");
83}
84else {
85 $HTML=1;
86 printline("Content-type: text/html\n\n");
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("<H2>Please wait while updating svn...</H2><P><PRE>");
97 select(STDERR); $| = 1; # make unbuffered
98 select(STDOUT); $| = 1; # make unbuffered
99 system("$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 print <<EOF;
135</BODY>
136</HTML>
137EOF
138}
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 (revision: $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 print "$node\n";
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 printf "<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 print "<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 else {
326 print $pr;
327 };
328};
Note: See TracBrowser for help on using the repository browser.