source: genesis/tools/g_list.pl@ 4085

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

Bug fix, update

  • 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="$hostname/cgi-bin";
21my $source="$cgi_dir/g_list.pl";
22
23#path variablen
24my $home="/home/rick/svn/genesis";
25my $ndir="$home/nodes";
26my $toolfile="$home/tools/wleiden.pl";
27
28#exec vars
29my $svn="/usr/local/bin/svn";
30
31######################## END OF CONFIG ##########################
32my $html=1;
33
34#laden van tool file
35do($toolfile) || die("Cann't open $toolfile");
36
37#gebruik van simple subje om ervoor te zorgen dat de print netjes in het
38#programma gestopt kan worden
39sub printline {
40 print "$_[0] \n";
41};
42
43
44#REQUEST parsen
45$request=$ENV{'REQUEST_URI'};
46if ($request=~/cgi-bin\/g_list.pl\/(.*)$/) {
47 ($node,$file)=split(/\//,$1);
48 $title="$node $file";
49}
50else {
51 $title="listing";
52};
53
54
55#controleer wat de browser is
56#en zorgen dan er de nodige tags geprint worden
57$browser=$ENV{'HTTP_USER_AGENT'};
58if ($browser=~/curl|wget|fetch/i) {
59 $HTML=0;
60 printline("Content-type: text/html\n\n");
61}
62else {
63 $HTML=1;
64 printline("Content-type: text/html\n\n");
65 printline("<HTML>");
66 printline("<TITLE>Genesis $title</TITLE>");
67 printline("<BODY BGcolor=white>");
68};
69
70
71#als geen node gespecificeerd dan kijken of svn geupdate is gevraagd
72if ($node eq '') {
73 if ($ENV{"QUERY_STRING"}=~/update/i) {
74 select(STDERR); $| = 1; # make unbuffered
75 select(STDOUT); $| = 1; # make unbuffered
76 printline("<H2>Please wait while updating svn...</H2><P><PRE>");
77 system("$svn update $home");
78 close(SVN);
79 printline("</PRE>");
80 printline("<H2>Done.<H2><P>");
81 printline("Click <A HREF=$source>here</A>");
82 printline("if you're not forwarded automaticly in 5 seconds.<P>");
83 printline("<META HTTP-EQUIV=REFRESH CONTENT=5;URL=$source>");
84 }
85 else {
86 g_list( );
87 };
88}
89else {
90 if ($file eq '') {
91 foreach $file ( sort @filelist) {
92 if ($HTML) {
93 print "$file<BR>\n";
94 }
95 else {
96 print "$file\n";
97 };
98 };
99 }
100 elsif ($file eq 'config') {
101 g_print($hostname);
102 }
103 else {
104 foreach my $tmpFile ( sort @filelist) {
105 if( $file eq $tmpFile ) {
106 g_generate($file);
107 };
108 };
109 };
110};
111
112#plaats de sluit HTML tags
113if ($HTML) {
114 print <<EOF;
115</BODY>
116</HTML>
117EOF
118}
119
120
121#Het opbouwen van het begin scherm
122sub g_list {
123 if ($HTML) {
124 $svn_version=svn_version("$ndir");
125 if ($svn_version=~/Last Changed Rev: (\d+)/) {
126 $revision=$1;
127 };
128 printline("<H1>Genesis config (revision: $revision):</H1><P>\n<PRE>");
129 printline("$svn_version");
130 printline("</PRE>");
131 printline("<FORM METHOD=get ACTION=$source>");
132 printline('<INPUT TYPE="submit" NAME="Update" VALUE="Update">');
133 printline("</FORM>");
134 printline("<TABLE BORDER=1>");
135 };
136
137 opendir(DIR, $ndir) || die "can't opendir $home: $!";
138 @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
139 closedir DIR;
140 foreach $dir (sort @dirs) {
141 if ($dir=~/attic/) {
142 next;
143 };
144 $hostname=$dir;
145 if (! $HTML) {
146 print "$hostname\n";
147 }
148 else {
149 printline("<TR><TD><A HREF=g_list.pl/$hostname/config>$hostname</A></TD>");
150 foreach $file (sort @filelist) {
151 printline("<TD><A HREF=g_list.pl/$hostname/$file>$file</A></TD>\n");
152 };
153 };
154 };
155 printline("</TABLE><P>");
156};
157
158
159
160#ophalen svn versie
161sub svn_version {
162 local($file,$char)=@_;
163 local($svn_version);
164 $svn_version=`$svn info $file`;
165 if ($char ne '') {
166 $svn_version=~s/^([^$char].*)/$char $1/mgi;
167 };
168 return($svn_version);
169};
170
171
172
173#netjes de configuratie printen
174sub g_print {
175 my $config="$ndir/$node/wleiden.conf";
176 parse_config($config);
177
178 printline("<H1>Genesis configuratie voor: $node</H1><P>");
179 printline("<PRE>" . svn_version($config) . "</PRE><P>");
180
181
182 my $TP='';
183 if ($tproxy !~ m/no/i) {
184 $TP .= "\n";
185 $TP .= "Tproxy on cidr range $tproxy";
186 $TP .= "<b>WARNING - specification propably wrong - should be a cidr</b>"
187 unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/;
188 };
189
190 printline("<TABLE BORDER=1><TR><TD COLSPAN=4><PRE>");
191 printline("master_ip=$master_ip");
192 printline("AGGREGATE=$AGGREGATE");
193 printline("");
194 printline("gw_open=$gw_open");
195 printline("nodetype=$nodetype");
196 printline("nodename=$nodename");
197 printline("");
198 printline("NS_forward=$NS_forward");
199 printline("NS_resolv=$NS_resolv");
200 printline("");
201 printline("location=$location");
202 printline("DISK=$DISK");
203 printline("");
204 printline("X=$X");
205 printline("Y=$Y");
206 printline("");
207 printline("OS=$OS");
208 printline("");
209 printline("$TP");
210 printline("</PRE></TD></TR>");
211
212 foreach $if (sort keys %config) {
213 if ($if=~/^(.*):\d+/) {
214 $subs{$1}++;
215 };
216 };
217
218 foreach $if (sort keys %config) {
219 if ($if=~/^([^:]+)/) {
220 $mymain=$1;
221 }
222 else {
223 $mymain='';
224 };
225
226 if ($if!~/:\d+/) {
227 $main=1;$cc='66'
228 }
229 else {
230 $main=0;
231 $cc='cc';
232 };
233
234 if (! ($ip=$IP{$if})) {
235 $ip='dhcp?';
236 };
237 if ($TYPE{$if}=~/wireless/) {
238 $color="#${cc}FFFF";
239 };
240 if ($TYPE{$if}=~/ethernet/) {
241 $color="#FFFF${cc}";
242 };
243
244 $cfg=$config{$if};
245 $cfg=~s/(.*KEY.*=).*/${1}***********/;
246 $cfg=~s/(.*PWD.*=).*/${1}***********/;
247 $cfg=~s/(.*CODE.*=).*/${1}***********/;
248 $cfg=~s/(.*PASS.*=).*/${1}***********/;
249
250 if ($main) {
251 printf "<TR bgcolor=$color><TD ROWSPAN=%d VALIGN=TOP><B>$if</TD>\n",(1+$subs{$if})*3,$subs{$if};
252 $c=4;
253 }
254 else {
255 $c=3;
256 print "<TR bgcolor=$color>";
257 };
258 $cfg=~s/</&lt;/gi;
259 $cfg=~s/>/&gt;/gi;
260
261 printline("<TD>$if</TD><TD><B>$ip</TD><TD>$DESC{$if}($SDESC{$if})</TD>");
262 printline("<TR><TD COLSPAN=$c><PRE>");
263 printline("$cfg");
264 printline("</PRE></TD>");
265 printline("<TR><TD COLSPAN=$c>&nbsp;</TD>");
266 };
267 printline("</TABLE>");
268};
269
270
271
272#Generen config
273sub g_generate {
274 my $file=$_[0];
275 $config="$ndir/$node/wleiden.conf";
276 $svn_versiont=svn_version($toolfile,$char);
277 $svn_versionc=svn_version($config,$char);
278
279 if ($svn_versiont=~/Last Changed Rev: (\d+)/) {
280 $tool_rev=$1;
281 };
282 if ($svn_versionc=~/Last Changed Rev: (\d+)/) {
283 $config_rev=$1;
284 };
285
286 if ($tool_rev >= $config_rev) {
287 $svn_version=$svn_versiont . $svn_versionc;
288 }
289 else {
290 $svn_version=$svn_versionc;
291 };
292
293 if ($HTML) {
294 printline("<H1>Genesis $file voor: $hostname</H1><P>");
295 };
296
297 parse_config($config);
298 $pr=do_it($file);
299
300
301 if ($HTML) {
302 $pr=~s/</&lt;/gi;
303 printline("<PRE>$pr</PRE>");
304 }
305 else {
306 print $pr;
307 };
308};
Note: See TracBrowser for help on using the repository browser.