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

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

Genesis config cleanups

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