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