source: genesis/tools/g_list.pl@ 4075

Last change on this file since 4075 was 4075, checked in by rick, 21 years ago

Rewriten wleiden.pl

  • Property svn:executable set to *
File size: 7.1 KB
Line 
1#! /usr/bin/perl -w
2#
3#
4#
5
6# eerst even een subje om ervoor te zorgen dat de hostname + file bekend
7# is
8$filelist[0]="txtconfig";
9$filelist[1]="dhcpd.conf";
10$filelist[2]="rc.local";
11$filelist[3]="rc.node.local";
12$filelist[4]="resolv.conf";
13$filelist[5]="named.conf";
14$filelist[6]="snmpd.local.conf";
15
16$request=$ENV{'REQUEST_URI'};
17if ($request=~/cgi-bin\/g_list.pl\/(.*)$/) {
18 ($hostname,$file)=split(/\//,$1);
19 $title="$hostname $file";
20}
21else {
22 $title="listing";
23};
24
25#(inter)net env
26$cgi_dir="$hostname/cgi-bin";
27$source="$cgi_dir/g_list.pl";
28
29#path variablen
30$home="/home/rick/svn/genesis/";
31$ndir="$home/nodes";
32$toolfile="$home/tools/wleiden.pl";
33
34#exec vars
35$svn='/usr/local/bin/svn';
36$html=1;
37
38$functions_only=1;
39do $toolfile || die;
40
41#gebruik van simple subje om ervoor te zorgen dat de print netjes in het
42#programma gestopt kan worden
43sub printline {
44 print "$_[0] \n";
45};
46
47
48
49
50$browser=$ENV{'HTTP_USER_AGENT'};
51if ($browser=~/curl|wget|fetch/i) {
52 $HTML=0;
53 printline("Content-type: text/html\n\n");
54}
55else {
56 $HTML=1;
57 printline("Content-type: text/html\n\n");
58 printline("<HTML>");
59 printline("<TITLE>Genesis $title</TITLE>");
60 printline("<BODY BGcolor=white>");
61 printline("<BASE HREF=$hostname>");
62};
63
64
65if ($hostname eq '') {
66 if ($ENV{"QUERY_STRING"}=~/update/i) {
67 select(STDERR); $| = 1; # make unbuffered
68 select(STDOUT); $| = 1; # make unbuffered
69 printline("<H2>Please wait while updating svn...</H2><P><PRE>");
70 system("$svn update $home");
71 close(SVN);
72 printline("</PRE>");
73 printline("<H2>Done.<H2><P>");
74 printline("Click <A HREF=$source>here</A>");
75 printline("if you're not forwarded automaticly in 5 seconds.<P>");
76 printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
77 }
78 else {
79 g_list( );
80 };
81}
82else {
83 $dir="$ndir/$hostname";
84 if (! -d $dir ) {
85 if ($HTML) {
86 print "<H1>Host $hostname not found: $dir</H1><P>\n";
87 }
88 else {
89 print "Host $hostname not found: $dir\n";
90 };
91 }
92 elsif ($file eq '') {
93 foreach $file (@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 elsif ($file eq 'txtconfig') {
106 $HTML=0;g_print($hostname);
107 }
108 else {
109 foreach my $tmpFile (@filelist) {
110 if( $file eq $tmpFile ) {
111 g_generate($file,$hostname);
112 };
113 };
114 };
115};
116
117
118if ($HTML) {
119 print <<EOF;
120</BODY>
121</HTML>
122EOF
123}
124
125sub g_list {
126 if ($HTML) {
127 $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 $hostname=$dir;
148 if (! $HTML) {
149 print "$hostname\n";
150 }
151 else {
152 printline("<TR><TD><A HREF=g_list.pl/$hostname/config>$hostname</A></TD>");
153 foreach $file (@filelist) {
154 printline("<TD><A HREF=g_list.pl/$hostname/$file>$file</A></TD>\n");
155 };
156 };
157 };
158 printline("</TABLE><P>");
159};
160
161
162
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
174sub g_print {
175 local($hostname)=@_;
176 $config="$ndir/$hostname/wleiden.conf";
177
178 if (! $HTML) {
179 print svn_version($config,'#');
180 open (CFG,$config) || die;
181 while (<CFG>) {print $_;}
182 close(CFG);
183 }
184 else {
185 printline("<H1>Genesis configuratie voor: $hostname</H1><P>");
186 printline("<PRE>" . svn_version($config) . "</PRE><P>");
187
188 do($config) || die;
189 parse_config();
190
191 $TP='';
192 if ($tproxy !~ m/no/i) {
193 $TP .= "\n";
194 $TP .= "Tproxy on cidr range $tproxy";
195 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
196 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
197 };
198
199 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>");
200 printline("master_ip=$master_ip");
201 printline("AGGREGATE=$AGGREGATE");
202 printline("");
203 printline("gw_open=$gw_open");
204 printline("nodetype=$nodetype");
205 printline("nodename=$nodename");
206 printline("");
207 printline("NS_forward=$NS_forward");
208 printline("NS_resolv=$NS_resolv");
209 printline("");
210 printline("location=$location");
211 printline("DISK=$DISK");
212 printline("");
213 printline("X=$X");
214 printline("Y=$Y");
215 printline("");
216 printline("OS=$OS");
217 printline("");
218 printline("$TP");
219 printline("</PRE></TD></TR>");
220
221 foreach $if (sort keys %config) {
222 if ($if=~/^(.*):\d+/) {
223 $subs{$1}++;
224 };
225 };
226
227 foreach $if (sort keys %config) {
228 if ($if=~/^([^:]+)/) {
229 $mymain=$1;
230 }
231 else {
232 $mymain='';
233 };
234
235 if ($if!~/:\d+/) {
236 $main=1;$cc='66'
237 }
238 else {
239 $main=0;
240 $cc='cc';
241 };
242
243 if (! ($ip=$IP{$if})) {
244 $ip='dhcp?';
245 };
246 if ($TYPE{$if}=~/wireless/) {
247 $color="#${cc}FFFF";
248 };
249 if ($TYPE{$if}=~/ethernet/) {
250 $color="#FFFF${cc}";
251 };
252
253 $cfg=$config{$if};
254 $cfg=~s/(.*KEY.*=).*/${1}***********/;
255 $cfg=~s/(.*PWD.*=).*/${1}***********/;
256 $cfg=~s/(.*CODE.*=).*/${1}***********/;
257 $cfg=~s/(.*PASS.*=).*/${1}***********/;
258
259 if ($main) {
260 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};
261 $c=4;
262 }
263 else {
264 $c=3;
265 print "<TR bgcolor=$color>";
266 };
267 $cfg=~s/</&lt;/gi;
268 $cfg=~s/>/&gt;/gi;
269
270 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>");
271 printline("<TR><TD COLSPAN=$c><PRE>");
272 printline("$cfg");
273 printline("</PRE></TD>");
274 printline("<TR><TD COLSPAN=$c>&nbsp;</TD>");
275 };
276 printline("</TABLE>");
277 };
278};
279
280
281sub g_generate {
282 ($file,$hostname)=@_;
283 $config="$ndir/$hostname/wleiden.conf";
284
285 if (! -r $config) {
286 if ($HTML) {
287 printline("<H1>File $file not found: $config</H1><P>");
288 }
289 else {
290 printline("File $file not found: $config");
291 };
292 }
293 else {
294 $svn_versiont=svn_version($toolfile,$char);
295 $svn_versionc=svn_version($config,$char);
296
297 if ($svn_versiont=~/Last Changed Rev: (\d+)/) {
298 $tool_rev=$1;
299 };
300 if ($svn_versionc=~/Last Changed Rev: (\d+)/) {
301 $config_rev=$1;
302 };
303
304 if ($tool_rev >= $config_rev) {
305 $svn_version=$svn_versiont . $svn_versionc;
306 }
307 else {
308 $svn_version=$svn_versionc;
309 };
310
311 if ($HTML) {
312 printline("<H1>Genesis $file voor: $hostname</H1><P>");
313 };
314
315 parse_config($config);
316 $pr=do_it($file);
317
318
319 if ($HTML) {
320 $pr=~s/</&lt;/gi;$mrtg=~s/>/&gt;/gi;
321 printline("<PRE>$pr</PRE>");
322 }
323 else {
324 print $pr;
325 };
326 };
327};
Note: See TracBrowser for help on using the repository browser.