source: genesis/tools/g_list.pl@ 4126

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

Updating unbufferd

  • 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 exec '$svn update $home';
81 printline("</PRE>");
82 printline("<H2>Done.<H2><P>");
83 printline("Click <A HREF=$source>here</A>");
84 printline("if you're not forwarded automaticly in 5 seconds.<P>");
85 printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
86 }
87 else {
88 g_list( );
89 };
90}
91else {
92 if( $file eq '') {
93 foreach $file ( sort @filelist) {
94 if( $HTML) {
95 print "$file<BR>\n";
96 }
97 else {
98 print "$file\n";
99 };
100 };
101 }
102 elsif( $file eq 'config') {
103 g_print($hostname);
104 }
105 else {
106 foreach my $tmpFile ( sort @filelist) {
107 if( $file eq $tmpFile ) {
108 g_generate($file);
109 };
110 };
111 };
112};
113
114#plaats de sluit HTML tags
115if( $HTML) {
116 print <<EOF;
117</BODY>
118</HTML>
119EOF
120}
121
122
123#Het opbouwen van het begin scherm
124sub g_list {
125 if( $HTML) {
126 my $svn_version=svn_version("$ndir");
127 if( $svn_version=~/Last Changed Rev: (\d+)/) {
128 $revision=$1;
129 };
130 printline("<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>");
131 printline("$svn_version");
132 printline("</PRE>");
133 printline("<FORM METHOD=get ACTION=$source>");
134 printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
135 printline("</FORM>");
136 printline("<TABLE BORDER=1>");
137 };
138
139 opendir(DIR, $ndir) || die "can't opendir $home: $!";
140 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
141 closedir DIR;
142 foreach $dir (sort @dirs) {
143 if( $dir=~/attic/ ) {
144 next;
145 };
146 my $node = $dir;
147 if( ! $HTML ) {
148 print "$node\n";
149 }
150 else {
151 printline("<TR><TD><A HREF=g_list.pl/$node/config>$node</A></TD>");
152 foreach $file (sort @filelist) {
153 printline("<TD><A HREF=g_list.pl/$node/$file>$file</A></TD>\n");
154 };
155 };
156 };
157 if( $HTML ) {
158 printline("</TABLE><P>");
159 };
160};
161
162
163
164#ophalen svn versie
165sub svn_version {
166 local($file,$char)=@_;
167 local($svn_version);
168 $svn_version=`$svn info $file`;
169 if( $char ne '' ) {
170 $svn_version=~s/^([^$char].*)/$char $1/mgi;
171 };
172 return($svn_version);
173};
174
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("OS=$OS");
212 printline("");
213 printline("$TP");
214 printline("</PRE></TD></TR>");
215
216 foreach $if( sort keys %config) {
217 if( $if=~/^(.*):\d+/ ) {
218 $subs{$1}++;
219 };
220 };
221
222 foreach $if( sort keys %config) {
223 if( $if=~/^([^:]+)/ ) {
224 $mymain=$1;
225 }
226 else {
227 $mymain='';
228 };
229
230 if( $if!~/:\d+/ ) {
231 $main=1;$cc='66'
232 }
233 else {
234 $main=0;
235 $cc='cc';
236 };
237
238 if(! ($ip=$IP{$if}) ) {
239 $ip='dhcp?';
240 };
241 if( $TYPE{$if}=~/wireless/ ) {
242 $color="#${cc}FFFF";
243 };
244 if( $TYPE{$if}=~/ethernet/) {
245 $color="#FFFF${cc}";
246 };
247
248 $cfg=$config{$if};
249 $cfg=~s/(.*KEY.*=).*/${1}***********/;
250 $cfg=~s/(.*PWD.*=).*/${1}***********/;
251 $cfg=~s/(.*CODE.*=).*/${1}***********/;
252 $cfg=~s/(.*PASS.*=).*/${1}***********/;
253
254 if( $main) {
255 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};
256 $c=4;
257 }
258 else {
259 $c=3;
260 print "<TR bgcolor=$color>";
261 };
262 $cfg=~s/</&lt;/gi;
263 $cfg=~s/>/&gt;/gi;
264
265 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>");
266 printline("<TR><TD COLSPAN=$c><PRE>");
267 printline("$cfg");
268 printline("</PRE></TD>");
269 printline("<TR><TD COLSPAN=$c>&nbsp;</TD>");
270 };
271 printline("</TABLE>");
272};
273
274
275
276#Generen config
277sub g_generate {
278 my $file=$_[0];
279 $config="$ndir/$node/$configfile";
280 $svn_versiont=svn_version($toolfile,$char);
281 $svn_versionc=svn_version($config,$char);
282
283 if( $svn_versiont=~/Last Changed Rev: (\d+)/ ) {
284 $tool_rev=$1;
285 };
286 if( $svn_versionc=~/Last Changed Rev: (\d+)/ ) {
287 $config_rev=$1;
288 };
289
290 if( $tool_rev >= $config_rev) {
291 $svn_version=$svn_versiont . $svn_versionc;
292 }
293 else {
294 $svn_version=$svn_versionc;
295 };
296
297 if( $HTML) {
298 printline("<H1>Genesis $file voor: $hostname</H1><P>");
299 };
300
301 parse_config($config);
302 $pr=do_it($file);
303
304
305 if( $HTML ) {
306 $pr=~s/</&lt;/gi;
307 printline("<PRE>$pr</PRE>");
308 }
309 else {
310 print $pr;
311 };
312};
Note: See TracBrowser for help on using the repository browser.