source: genesis/tools/g_list.pl@ 4104

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

Made it even more generic

  • 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#naming vars
32my $configfile="wleiden.conf";
33
34######################## END OF CONFIG ##########################
35my $HTML=1;
36
37#laden van tool file
38do($toolfile) || die("Cann't open $toolfile");
39
40#gebruik van simple subje om ervoor te zorgen dat de print netjes in het
41#programma gestopt kan worden
42sub printline {
43 print "$_[0] \n";
44};
45
46
47#REQUEST parsen
48$request=$ENV{'REQUEST_URI'};
49if( $request=~/cgi-bin\/g_list.pl\/(.*)$/) {
50 ($node,$file)=split(/\//,$1);
51 $title="$node $file";
52}
53else {
54 $title="listing";
55};
56
57
58#controleer wat de browser is
59#en zorgen dan er de nodige tags geprint worden
60$browser=$ENV{'HTTP_USER_AGENT'};
61if( $browser=~/curl|wget|fetch/i) {
62 $HTML=0;
63 printline("Content-type: text/html\n\n");
64}
65else {
66 $HTML=1;
67 printline("Content-type: text/html\n\n");
68 printline("<HTML>");
69 printline("<TITLE>Genesis $title</TITLE>");
70 printline("<BODY BGcolor=white>");
71};
72
73
74#als geen node gespecificeerd dan kijken of svn geupdate is gevraagd
75if( $node eq '') {
76 if( $ENV{"QUERY_STRING"}=~/update/i) {
77 select(STDERR); $| = 1; # make unbuffered
78 select(STDOUT); $| = 1; # make unbuffered
79 printline("<H2>Please wait while updating svn...</H2><P><PRE>");
80 system("$svn update $home");
81 close(SVN);
82 printline("</PRE>");
83 printline("<H2>Done.<H2><P>");
84 printline("Click <A HREF=$source>here</A>");
85 printline("if you're not forwarded automaticly in 5 seconds.<P>");
86 printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
87 }
88 else {
89 g_list( );
90 };
91}
92else {
93 if( $file eq '') {
94 foreach $file ( sort @filelist) {
95 if( $HTML) {
96 print "$file<BR>\n";
97 }
98 else {
99 print "$file\n";
100 };
101 };
102 }
103 elsif( $file eq 'config') {
104 g_print($hostname);
105 }
106 else {
107 foreach my $tmpFile ( sort @filelist) {
108 if( $file eq $tmpFile ) {
109 g_generate($file);
110 };
111 };
112 };
113};
114
115#plaats de sluit HTML tags
116if( $HTML) {
117 print <<EOF;
118</BODY>
119</HTML>
120EOF
121}
122
123
124#Het opbouwen van het begin scherm
125sub g_list {
126 if( $HTML) {
127 my $svn_version=svn_version("$ndir");
128 if( $svn_version=~/Last Changed Rev: (\d+)/) {
129 $revision=$1;
130 };
131 printline("<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>");
132 printline("$svn_version");
133 printline("</PRE>");
134 printline("<FORM METHOD=get ACTION=$source>");
135 printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
136 printline("</FORM>");
137 printline("<TABLE BORDER=1>");
138 };
139
140 opendir(DIR, $ndir) || die "can't opendir $home: $!";
141 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
142 closedir DIR;
143 foreach $dir (sort @dirs) {
144 if( $dir=~/attic/ ) {
145 next;
146 };
147 my $node = $dir;
148 if( ! $HTML ) {
149 print "$node\n";
150 }
151 else {
152 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
153 foreach $file (sort @filelist) {
154 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
155 };
156 };
157 };
158 if( $HTML ) {
159 printline("</TABLE><P>");
160 };
161};
162
163
164
165#ophalen svn versie
166sub svn_version {
167 local($file,$char)=@_;
168 local($svn_version);
169 $svn_version=`$svn info $file`;
170 if( $char ne '' ) {
171 $svn_version=~s/^([^$char].*)/$char $1/mgi;
172 };
173 return($svn_version);
174};
175
176
177
178#netjes de configuratie printen
179sub g_print {
180 my $config="$ndir/$node/$configfile";
181 parse_config($config);
182
183 printline("<H1>Genesis configuratie voor: $node</H1><P>");
184 printline("<PRE>" . svn_version($config) . "</PRE><P>");
185
186
187 my $TP='';
188 if( $tproxy !~ m/no/i ) {
189 $TP .= "\n";
190 $TP .= "Tproxy on cidr range $tproxy";
191 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
192 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
193 };
194
195 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>");
196 printline("master_ip=$master_ip");
197 printline("AGGREGATE=$AGGREGATE");
198 printline("");
199 printline("gw_open=$gw_open");
200 printline("nodetype=$nodetype");
201 printline("nodename=$nodename");
202 printline("");
203 printline("NS_forward=$NS_forward");
204 printline("NS_resolv=$NS_resolv");
205 printline("");
206 printline("location=$location");
207 printline("DISK=$DISK");
208 printline("");
209 printline("X=$X");
210 printline("Y=$Y");
211 printline("");
212 printline("OS=$OS");
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.