source: genesis/tools/g_list.pl@ 3624

Last change on this file since 3624 was 2592, checked in by jasper, 20 years ago

g_list.pl -> svn

  • Property svn:executable set to *
File size: 6.5 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
172 print <<EOXY;
173<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>
174master_ip=$master_ip
175AGGREGATE=$AGGREGATE
176
177gw_open=$gw_open
178nodetype=$nodetype
179nodename=$nodename
180
181NS_forward=$NS_forward
182NS_resolv=$NS_resolv
183
184location=$location
185DISK=$DISK
186
187X=$X
188Y=$Y
189
190
191OS=$OS
192</PRE></TD></TR>
193EOXY
194
195 foreach $if (sort keys %config)
196 {
197 if ($if=~/^(.*):\d+/) {$subs{$1}++;}
198 }
199
200 foreach $if (sort keys %config)
201 {
202 if ($if=~/^([^:]+)/) {$mymain=$1;} else {$mymain='';}
203 if ($if!~/:\d+/) {$main=1;$cc='66'} else {$main=0;$cc='cc';}
204 if (! ($ip=$IP{$if})) {$ip='dhcp?';}
205 if ($TYPE{$if}=~/wireless/) {$color="#${cc}FFFF";}
206 if ($TYPE{$if}=~/ethernet/) {$color="#FFFF${cc}";}
207
208 $cfg=$config{$if};
209 $cfg=~s/(.*KEY.*=).*/${1}***********/;
210 $cfg=~s/(.*PWD.*=).*/${1}***********/;
211 $cfg=~s/(.*CODE.*=).*/${1}***********/;
212 $cfg=~s/(.*PASS.*=).*/${1}***********/;
213
214 if ($main) {printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};$c=4}
215 else {$c=3;print "<TR bgcolor=$color>";}
216 $cfg=~s/</&lt;/gi;
217 $cfg=~s/>/&gt;/gi;
218
219 print <<EOP;
220<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>
221<TR><TD COLSPAN=$c><PRE>
222$cfg
223</PRE></TD>
224<TR><TD COLSPAN=$c>&nbsp;</TD>
225
226EOP
227 }
228 print "</TABLE>\n";
229 }
230}
231
232
233sub g_generate
234{
235 ($file,$hostname)=@_;
236
237#print "[$file][$hostname]\n";
238 $config="$ndir/$hostname/wleiden.conf";
239
240
241 if (! -r $config)
242 {
243 if ($HTML) {print "<H1>File $file not found: $config</H1><P>\n";}
244 else {print "File $file not found: $config\n";}
245
246 } else
247 {
248 if ($file=~/(ospfd|zebra)/) {$char='!';} else {$char='#';}
249
250 $svn_versiont=svn_version($toolfile,$char);
251 $svn_versionc=svn_version($config,$char);
252
253 if ($svn_versiont=~/Last Changed Rev: (\d+)/) {$tool_rev=$1;}
254 if ($svn_versionc=~/Last Changed Rev: (\d+)/) {$config_rev=$1;}
255
256#print "[$tool_rev $config_rev]<BR>\n";
257 if ($tool_rev >= $config_rev)
258 {$svn_version=$svn_versiont . $svn_versionc;}
259 else {$svn_version=$svn_versionc;}
260
261
262 if ($HTML) {print "<H1>Genesis $file voor: $hostname</H1><P>\n";}
263
264 do($config) || die;
265 parse_config();
266 read_areas();
267 do_it();
268
269 if ($file=~/ospfd.conf/) {$pr=$ospfd;}
270 if ($file=~/zebra.conf/) {$pr=$zebra;}
271 if ($file=~/dhcpd.conf/) {$pr=$dhcp;}
272 if ($file=~/snmpd.local.conf/){$pr=$snmpd;}
273 if ($file=~/mrtg.cfg/) {$pr=$mrtg;}
274 if ($file=~/linux.sh/) {$pr=$nwcfg;}
275 if ($file=~/sh/) {$pr=$sh;}
276 if ($file=~/rc.node.local/) {$pr=$rcconf;}
277 if ($file=~/rc.local/) {$pr=$freebsd;}
278 if ($file=~/resolv.conf/) {$pr=$resolv;}
279 if ($file=~/named.conf/) {$pr=$named;}
280
281 if ($HTML)
282 {
283 $pr=~s/</&lt;/gi;$mrtg=~s/>/&gt;/gi;
284 print "<PRE>$pr</PRE>\n";
285 } else {print $pr;}
286 }
287}
Note: See TracBrowser for help on using the repository browser.