source: genesis/tools/g_list.pl@ 4028

Last change on this file since 4028 was 4025, checked in by dirkx, 20 years ago

Add tproxy enable/disable to HTML page too

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