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

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

Cosmetic:

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