source: genesis/tools/g_list.pl@ 6767

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

Added display of version of FreeBSD expected

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.9 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
8# my $conf_file="/home/genesis/tools/genesis.conf";
9# do($conf_file) || die("Cann't open $conf_file");
10die "Run with the preamble in cgi-bin"
11 unless defined $conf_file;
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=~/cgi-bin\/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 print "Content-type: text/plain\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 $home");
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 'info') {
81 g_info($hostname);
82 }
83 elsif( $file eq 'config') {
84 g_print($hostname);
85 }
86 else {
87 foreach my $tmpFile ( sort @filelist) {
88 if( $file eq $tmpFile ) {
89 g_generate($file);
90 };
91 };
92 };
93};
94
95#plaats de sluit HTML tags
96if( $HTML) {
97 print <<EOF;
98</BODY>
99</HTML>
100EOF
101}
102
103
104#Het opbouwen van het begin scherm
105sub g_list {
106 my $version = 1;
107 $version = $1 if $ENV{"QUERY_STRING"}=~/version=(\d+)/i;
108
109 if( $HTML) {
110 my $svn_version=svn_version("$ndir");
111 if( $svn_version=~/Last Changed Rev: (\d+)/) {
112 $revision=$1;
113 };
114 printline("<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>");
115 printline("$svn_version");
116 printline("</PRE>");
117 printline("<FORM METHOD=get ACTION=$source>");
118 printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
119 printline("</FORM>");
120 printline("<TABLE BORDER=1>");
121 };
122
123 opendir(DIR, $ndir) || die "can't opendir $home: $!";
124 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
125 closedir DIR;
126 foreach $dir (sort @dirs) {
127 if( $dir=~/attic/ ) {
128 next;
129 };
130 my $node = $dir;
131 if( ! $HTML ) {
132 print "$node\n";
133 }
134 else {
135 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
136 foreach $file (sort @filelist) {
137 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
138 };
139 };
140 };
141 if( $HTML ) {
142 printline("</TABLE><P>");
143 };
144};
145
146#ophalen svn versie
147sub svn_version {
148 local($file,$char)=@_;
149 local($svn_version);
150 $svn_version=`$svn info $file`;
151 if( $char ne '' ) {
152 $svn_version=~s/^([^$char].*)/$char $1/mgi;
153 };
154 return($svn_version);
155};
156
157# Print info on this node; version of the OS
158# expected, etc..
159sub g_info {
160 my $config="$ndir/$node/$configfile";
161 parse_config($config);
162
163 $release = 'unknown' unless $release;
164 $node_config_version = 0 unless $node_config_version;
165 $genesis_control = 'NO' unless $genesis_control;
166 $OS = 'Unknown' unless $OS;
167 print <<"EOM";
168$OS $release $node_config_version $genesis_control
169#
170# Operating system release: $OS on $release
171# Node Config script version: $node_config_version
172# Under Gensis control: $genesis_control
173#
174EOM
175}
176
177#netjes de configuratie printen
178sub g_print {
179 my $config="$ndir/$node/$configfile";
180 parse_config($config);
181
182 printline("<H1>Genesis configuratie voor: $node</H1><P>");
183 printline("<PRE>" . svn_version($config) . "</PRE><P>");
184
185
186 my $TP='';
187 if( $tproxy !~ m/no/i ) {
188 $TP .= "\n";
189 $TP .= "Tproxy on cidr range $tproxy";
190 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
191 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
192 };
193
194 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>");
195 printline("master_ip=$master_ip");
196 printline("AGGREGATE=$AGGREGATE");
197 printline("");
198 printline("gw_open=$gw_open");
199 printline("nodetype=$nodetype");
200 printline("nodename=$nodename");
201 printline("");
202 printline("NS_forward=$NS_forward");
203 printline("NS_resolv=$NS_resolv");
204 printline("");
205 printline("location=$location");
206 printline("DISK=$DISK");
207 printline("");
208 printline("X=$X");
209 printline("Y=$Y");
210 printline("");
211 printline("Operating system: $OS / $release");
212 printline("Config management: Version $node_config_version, Used: $genesis_control");
213 printline("");
214 printline("$TP");
215 printline("</PRE></TD></TR>");
216
217 foreach $if( sort keys %config) {
218 if( $if=~/^(.*):\d+/ ) {
219 $subs{$1}++;
220 };
221 };
222
223 foreach $if( sort keys %config) {
224 if( $if=~/^([^:]+)/ ) {
225 $mymain=$1;
226 }
227 else {
228 $mymain='';
229 };
230
231 if( $if!~/:\d+/ ) {
232 $main=1;$cc='66'
233 }
234 else {
235 $main=0;
236 $cc='cc';
237 };
238
239 if(! ($ip=$IP{$if}) ) {
240 $ip='dhcp?';
241 };
242 if( $TYPE{$if}=~/wireless/ ) {
243 $color="#${cc}FFFF";
244 };
245 if( $TYPE{$if}=~/ethernet/) {
246 $color="#FFFF${cc}";
247 };
248
249 $cfg=$config{$if};
250 $cfg=~s/(.*KEY.*=).*/${1}***********/;
251 $cfg=~s/(.*PWD.*=).*/${1}***********/;
252 $cfg=~s/(.*CODE.*=).*/${1}***********/;
253 $cfg=~s/(.*PASS.*=).*/${1}***********/;
254
255 if( $main) {
256 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};
257 $c=4;
258 }
259 else {
260 $c=3;
261 print "<TR bgcolor=$color>";
262 };
263 $cfg=~s/</&lt;/gi;
264 $cfg=~s/>/&gt;/gi;
265
266 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>");
267 printline("<TR><TD COLSPAN=$c><PRE>");
268 printline("$cfg");
269 printline("</PRE></TD>");
270 printline("<TR><TD COLSPAN=$c>&nbsp;</TD>");
271 };
272 printline("</TABLE>");
273};
274
275
276
277#Generen config
278sub g_generate {
279 my $file=$_[0];
280 $config="$ndir/$node/$configfile";
281 $svn_versiont=svn_version($toolfile,$char);
282 $svn_versionc=svn_version($config,$char);
283
284 if( $svn_versiont=~/Last Changed Rev: (\d+)/ ) {
285 $tool_rev=$1;
286 };
287 if( $svn_versionc=~/Last Changed Rev: (\d+)/ ) {
288 $config_rev=$1;
289 };
290
291 if( $tool_rev >= $config_rev) {
292 $svn_version=$svn_versiont . $svn_versionc;
293 }
294 else {
295 $svn_version=$svn_versionc;
296 };
297
298 if( $HTML) {
299 printline("<H1>Genesis $file voor: $hostname</H1><P>");
300 };
301
302 parse_config($config);
303 $pr=do_it($file);
304
305
306 if( $HTML ) {
307 $pr=~s/</&lt;/gi;
308 printline("<PRE>$pr</PRE>");
309 }
310 else {
311 print $pr;
312 };
313};
Note: See TracBrowser for help on using the repository browser.