source: genesis/tools/g_list.pl@ 6539

Last change on this file since 6539 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
RevLine 
[4081]1#!/usr/bin/perl -w
[2592]2#
[4174]3# Copyright 2005 Stichting Wireless Leiden
4# Rick van der Zwet
[2592]5#
6
[4174]7# Config located at other file
[5000]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;
[4075]12
[4086]13my $HTML=1;
[2592]14
[4081]15#laden van tool file
16do($toolfile) || die("Cann't open $toolfile");
17
[4064]18#gebruik van simple subje om ervoor te zorgen dat de print netjes in het
19#programma gestopt kan worden
20sub printline {
[4990]21 print "$_[0]\n";
[4064]22};
[2592]23
24
[4081]25#REQUEST parsen
26$request=$ENV{'REQUEST_URI'};
[4087]27if( $request=~/cgi-bin\/g_list.pl\/(.*)$/) {
[4081]28 ($node,$file)=split(/\//,$1);
29 $title="$node $file";
30}
31else {
32 $title="listing";
33};
[4064]34
35
[4081]36#controleer wat de browser is
37#en zorgen dan er de nodige tags geprint worden
[2592]38$browser=$ENV{'HTTP_USER_AGENT'};
[4087]39if( $browser=~/curl|wget|fetch/i) {
[4064]40 $HTML=0;
[5000]41 print "Content-type: text/plain\n\n";
[2592]42}
[4064]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};
[2592]50
51
[4081]52#als geen node gespecificeerd dan kijken of svn geupdate is gevraagd
[4087]53if( $node eq '') {
54 if( $ENV{"QUERY_STRING"}=~/update/i) {
[4127]55 printline("<H2>Please wait while updating svn...</H2><P><PRE>");
[4064]56 select(STDERR); $| = 1; # make unbuffered
57 select(STDOUT); $| = 1; # make unbuffered
[4128]58 system("$svn update $home");
[4064]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 {
[4087]70 if( $file eq '') {
[4081]71 foreach $file ( sort @filelist) {
[4087]72 if( $HTML) {
[4064]73 print "$file<BR>\n";
74 }
75 else {
76 print "$file\n";
77 };
78 };
79 }
[5000]80 elsif( $file eq 'info') {
81 g_info($hostname);
82 }
[4087]83 elsif( $file eq 'config') {
[4064]84 g_print($hostname);
85 }
[4075]86 else {
[4081]87 foreach my $tmpFile ( sort @filelist) {
[4075]88 if( $file eq $tmpFile ) {
[4081]89 g_generate($file);
[4075]90 };
91 };
[4064]92 };
93};
[2592]94
[4081]95#plaats de sluit HTML tags
[4087]96if( $HTML) {
[4064]97 print <<EOF;
[2592]98</BODY>
99</HTML>
100EOF
101}
102
[4081]103
104#Het opbouwen van het begin scherm
[4064]105sub g_list {
[5000]106 my $version = 1;
107 $version = $1 if $ENV{"QUERY_STRING"}=~/version=(\d+)/i;
108
[4087]109 if( $HTML) {
[4086]110 my $svn_version=svn_version("$ndir");
[4087]111 if( $svn_version=~/Last Changed Rev: (\d+)/) {
[4064]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 };
[2592]122
123 opendir(DIR, $ndir) || die "can't opendir $home: $!";
124 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
[4064]125 closedir DIR;
126 foreach $dir (sort @dirs) {
[4087]127 if( $dir=~/attic/ ) {
[4064]128 next;
129 };
[4086]130 my $node = $dir;
[4087]131 if( ! $HTML ) {
[4086]132 print "$node\n";
[4064]133 }
134 else {
[4086]135 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
[4081]136 foreach $file (sort @filelist) {
[4086]137 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
[4064]138 };
139 };
140 };
[4087]141 if( $HTML ) {
142 printline("</TABLE><P>");
143 };
[4064]144};
[2592]145
[4081]146#ophalen svn versie
[4064]147sub svn_version {
148 local($file,$char)=@_;
149 local($svn_version);
150 $svn_version=`$svn info $file`;
[4087]151 if( $char ne '' ) {
[4064]152 $svn_version=~s/^([^$char].*)/$char $1/mgi;
153 };
154 return($svn_version);
[4025]155};
[2592]156
[5000]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);
[4025]162
[5000]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}
[4081]176
177#netjes de configuratie printen
[4064]178sub g_print {
[4104]179 my $config="$ndir/$node/$configfile";
[4081]180 parse_config($config);
181
182 printline("<H1>Genesis configuratie voor: $node</H1><P>");
183 printline("<PRE>" . svn_version($config) . "</PRE><P>");
[4025]184
[2592]185
[4081]186 my $TP='';
[4087]187 if( $tproxy !~ m/no/i ) {
[4081]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 };
[2592]193
[4081]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("");
[5000]211 printline("Operating system: $OS / $release");
212 printline("Config management: Version $node_config_version, Used: $genesis_control");
[4081]213 printline("");
214 printline("$TP");
215 printline("</PRE></TD></TR>");
[2592]216
[4087]217 foreach $if( sort keys %config) {
218 if( $if=~/^(.*):\d+/ ) {
[4081]219 $subs{$1}++;
220 };
221 };
[2592]222
[4087]223 foreach $if( sort keys %config) {
224 if( $if=~/^([^:]+)/ ) {
[4081]225 $mymain=$1;
226 }
227 else {
228 $mymain='';
229 };
230
[4087]231 if( $if!~/:\d+/ ) {
[4081]232 $main=1;$cc='66'
233 }
234 else {
235 $main=0;
236 $cc='cc';
237 };
238
[4087]239 if(! ($ip=$IP{$if}) ) {
[4081]240 $ip='dhcp?';
241 };
[4087]242 if( $TYPE{$if}=~/wireless/ ) {
[4081]243 $color="#${cc}FFFF";
244 };
[4087]245 if( $TYPE{$if}=~/ethernet/) {
[4081]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}***********/;
[2592]254
[4087]255 if( $main) {
[4081]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;
[2592]265
[4081]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>");
[4064]273};
[2592]274
275
[4081]276
277#Generen config
[4064]278sub g_generate {
[4081]279 my $file=$_[0];
[4104]280 $config="$ndir/$node/$configfile";
[4081]281 $svn_versiont=svn_version($toolfile,$char);
282 $svn_versionc=svn_version($config,$char);
[2592]283
[4087]284 if( $svn_versiont=~/Last Changed Rev: (\d+)/ ) {
[4081]285 $tool_rev=$1;
286 };
[4087]287 if( $svn_versionc=~/Last Changed Rev: (\d+)/ ) {
[4081]288 $config_rev=$1;
289 };
290
[4087]291 if( $tool_rev >= $config_rev) {
[4081]292 $svn_version=$svn_versiont . $svn_versionc;
293 }
[4064]294 else {
[4081]295 $svn_version=$svn_versionc;
296 };
[2592]297
[4087]298 if( $HTML) {
[4081]299 printline("<H1>Genesis $file voor: $hostname</H1><P>");
300 };
[2592]301
[4081]302 parse_config($config);
303 $pr=do_it($file);
[2592]304
305
[4087]306 if( $HTML ) {
[4081]307 $pr=~s/</&lt;/gi;
308 printline("<PRE>$pr</PRE>");
309 }
310 else {
311 print $pr;
[4064]312 };
313};
Note: See TracBrowser for help on using the repository browser.