source: genesis/tools/FreeBSD5_x/g_list.pl@ 5230

Last change on this file since 5230 was 5230, checked in by rick, 19 years ago

Made more generic
/filelist will be filelist
/nodelist will return nodelist

added option to remove certain dirs at the nodedir

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