source: genesis/tools/g_list.pl@ 4102

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

Update didn't work

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1#!/usr/bin/perl -w
2#
3#
4#
5
6
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";
16
17#(inter)net env
18my $hostname=`hostname`;
19chomp($hostname);
20my $cgi_dir="http://$hostname/cgi-bin";
21my $source="$cgi_dir/g_list.pl";
22
23#path variablen
24my $home="/home/genesis";
25my $ndir="$home/nodes";
26my $toolfile="$home/tools/wleiden.pl";
27
28#exec vars
29my $svn="/usr/local/bin/svn";
30
31######################## END OF CONFIG ##########################
32my $HTML=1;
33
34#laden van tool file
35do($toolfile) || die("Cann't open $toolfile");
36
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};
42
43
44#REQUEST parsen
45$request=$ENV{'REQUEST_URI'};
46if( $request=~/cgi-bin\/g_list.pl\/(.*)$/) {
47 ($node,$file)=split(/\//,$1);
48 $title="$node $file";
49}
50else {
51 $title="listing";
52};
53
54
55#controleer wat de browser is
56#en zorgen dan er de nodige tags geprint worden
57$browser=$ENV{'HTTP_USER_AGENT'};
58if( $browser=~/curl|wget|fetch/i) {
59 $HTML=0;
60 printline("Content-type: text/html\n\n");
61}
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};
69
70
71#als geen node gespecificeerd dan kijken of svn geupdate is gevraagd
72if( $node eq '') {
73 if( $ENV{"QUERY_STRING"}=~/update/i) {
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 {
90 if( $file eq '') {
91 foreach $file ( sort @filelist) {
92 if( $HTML) {
93 print "$file<BR>\n";
94 }
95 else {
96 print "$file\n";
97 };
98 };
99 }
100 elsif( $file eq 'config') {
101 g_print($hostname);
102 }
103 else {
104 foreach my $tmpFile ( sort @filelist) {
105 if( $file eq $tmpFile ) {
106 g_generate($file);
107 };
108 };
109 };
110};
111
112#plaats de sluit HTML tags
113if( $HTML) {
114 print <<EOF;
115</BODY>
116</HTML>
117EOF
118}
119
120
121#Het opbouwen van het begin scherm
122sub g_list {
123 if( $HTML) {
124 my $svn_version=svn_version("$ndir");
125 if( $svn_version=~/Last Changed Rev: (\d+)/) {
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 };
136
137 opendir(DIR, $ndir) || die "can't opendir $home: $!";
138 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
139 closedir DIR;
140 foreach $dir (sort @dirs) {
141 if( $dir=~/attic/ ) {
142 next;
143 };
144 my $node = $dir;
145 if( ! $HTML ) {
146 print "$node\n";
147 }
148 else {
149 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
150 foreach $file (sort @filelist) {
151 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
152 };
153 };
154 };
155 if( $HTML ) {
156 printline("</TABLE><P>");
157 };
158};
159
160
161
162#ophalen svn versie
163sub svn_version {
164 local($file,$char)=@_;
165 local($svn_version);
166 $svn_version=`$svn info $file`;
167 if( $char ne '' ) {
168 $svn_version=~s/^([^$char].*)/$char $1/mgi;
169 };
170 return($svn_version);
171};
172
173
174
175#netjes de configuratie printen
176sub g_print {
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>");
182
183
184 my $TP='';
185 if( $tproxy !~ m/no/i ) {
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 };
191
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>");
213
214 foreach $if( sort keys %config) {
215 if( $if=~/^(.*):\d+/ ) {
216 $subs{$1}++;
217 };
218 };
219
220 foreach $if( sort keys %config) {
221 if( $if=~/^([^:]+)/ ) {
222 $mymain=$1;
223 }
224 else {
225 $mymain='';
226 };
227
228 if( $if!~/:\d+/ ) {
229 $main=1;$cc='66'
230 }
231 else {
232 $main=0;
233 $cc='cc';
234 };
235
236 if(! ($ip=$IP{$if}) ) {
237 $ip='dhcp?';
238 };
239 if( $TYPE{$if}=~/wireless/ ) {
240 $color="#${cc}FFFF";
241 };
242 if( $TYPE{$if}=~/ethernet/) {
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}***********/;
251
252 if( $main) {
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;
262
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>");
270};
271
272
273
274#Generen config
275sub g_generate {
276 my $file=$_[0];
277 $config="$ndir/$node/wleiden.conf";
278 $svn_versiont=svn_version($toolfile,$char);
279 $svn_versionc=svn_version($config,$char);
280
281 if( $svn_versiont=~/Last Changed Rev: (\d+)/ ) {
282 $tool_rev=$1;
283 };
284 if( $svn_versionc=~/Last Changed Rev: (\d+)/ ) {
285 $config_rev=$1;
286 };
287
288 if( $tool_rev >= $config_rev) {
289 $svn_version=$svn_versiont . $svn_versionc;
290 }
291 else {
292 $svn_version=$svn_versionc;
293 };
294
295 if( $HTML) {
296 printline("<H1>Genesis $file voor: $hostname</H1><P>");
297 };
298
299 parse_config($config);
300 $pr=do_it($file);
301
302
303 if( $HTML ) {
304 $pr=~s/</&lt;/gi;
305 printline("<PRE>$pr</PRE>");
306 }
307 else {
308 print $pr;
309 };
310};
Note: See TracBrowser for help on using the repository browser.