source: genesis/tools/g_list.pl@ 4095

Last change on this file since 4095 was 4090, checked in by rick, 20 years ago

Update didn't work

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