#! /usr/bin/perl # # # $home="/home/genesis/"; $ndir="$home/nodes"; $html=1; $baseref='http://rambo.wleiden.net'; $base_href="baseref/cgi-bin"; $source="$base_href/g_list.pl"; $svn='/usr/local/bin/svn'; $toolfile="wleiden.pl"; $functions_only=1;do $toolfile || die; $request=$ENV{'REQUEST_URI'}; if ($request=~/cgi-bin\/g_list.pl\/(.*)$/) { ($hostname,$file)=split(/\//,$1); $title="$hostname $file"; } else {$title="listing";} $browser=$ENV{'HTTP_USER_AGENT'}; if ($browser=~/curl|wget|fetch/i) {$HTML=0; print "Content-type: text/html\n\n"; # print "Doing: [$hostname][$file]\n"; } else {$HTML=1; print < Genesis $title EOH } #foreach $key (keys %ENV) {print "$key=$ENV{$key}
\n";} if ($hostname eq '') { if ($ENV{"QUERY_STRING"}=~/update/i) { select(STDERR); $| = 1; # make unbuffered select(STDOUT); $| = 1; # make unbuffered print "

Please wait while updating svn...

\n";
     	     system("$svn update $ndir");
	     close(SVN);
	     print <

Done.

Click here if you're not forwarded automaticly in 5 seconds.

\n EOZ } else {g_list();} } else { $dir="$ndir/$hostname"; if (! -d $dir ) { if ($HTML) {print "

Host $hostname not found: $dir

\n";} else {print "Host $hostname not found: $dir\n";} } elsif ($file eq '') { foreach $file ('txtconfig','config','dhcpd.conf','zebra.conf','ospfd.conf', 'rc.local','rc.node.local','resolv.conf', 'named.conf','snmpd.local.conf') { if ($HTML) {print "$file
\n";} else {print "$file\n";} } } elsif ($file eq 'config') {g_print($hostname);} elsif ($file eq 'txtconfig') {$HTML=0;g_print($hostname);} 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)/) {g_generate($file,$hostname);} } if ($HTML) { print < EOF } sub g_list { if ($HTML) { $svn_version=svn_version("$ndir"); if ($svn_version=~/Last Changed Rev: (\d+)/) {$revision=$1;} print "

Genesis config (revision: $revision):

\n

";
	print $svn_version;
	print <
EOX } opendir(DIR, $ndir) || die "can't opendir $home: $!"; @dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR); closedir DIR; foreach $dir (sort @dirs) { if ($dir=~/attic/) {next;} $hostname=$dir; if (! $HTML) {print "$hostname\n";} else { print "\n"; foreach $file ('linux.sh','dhcpd.conf','zebra.conf','ospfd.conf', 'rc.node.local','rc.local','resolv.conf','named.conf', 'snmpd.local.conf') { print "\n\n"; } } } if ($HTML) { #print "
$hostname$file

\n";} print <

EOX } } sub svn_version { local($file,$char)=@_; local($svn_version); $svn_version=`$svn info $file`; if ($char ne '') {$svn_version=~s/^([^$char].*)/$char $1/mgi;} return($svn_version); } sub g_print { local($hostname)=@_; $config="$ndir/$hostname/wleiden.conf"; if (! $HTML) { print svn_version($config,'#'); #print "Ahum\n"; open (CFG,$config) || die; while () {print $_;} close(CFG); } else { print "

Genesis configuratie voor: $hostname

\n"; print "

" . svn_version($config) . "

\n"; do($config) || die; parse_config(); $TP=''; if ($tproxy !~ m/no/i) { $TP .= "\n"; $TP .= "Tproxy on cidr range $tproxy"; $TP .= "WARNING - specification propably wrong - should be a cidr" unless $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/; }; print <

master_ip=$master_ip
AGGREGATE=$AGGREGATE

gw_open=$gw_open
nodetype=$nodetype
nodename=$nodename

NS_forward=$NS_forward
NS_resolv=$NS_resolv

location=$location
DISK=$DISK

X=$X
Y=$Y

OS=$OS

$TP
EOXY foreach $if (sort keys %config) { if ($if=~/^(.*):\d+/) {$subs{$1}++;} } foreach $if (sort keys %config) { if ($if=~/^([^:]+)/) {$mymain=$1;} else {$mymain='';} if ($if!~/:\d+/) {$main=1;$cc='66'} else {$main=0;$cc='cc';} if (! ($ip=$IP{$if})) {$ip='dhcp?';} if ($TYPE{$if}=~/wireless/) {$color="#${cc}FFFF";} if ($TYPE{$if}=~/ethernet/) {$color="#FFFF${cc}";} $cfg=$config{$if}; $cfg=~s/(.*KEY.*=).*/${1}***********/; $cfg=~s/(.*PWD.*=).*/${1}***********/; $cfg=~s/(.*CODE.*=).*/${1}***********/; $cfg=~s/(.*PASS.*=).*/${1}***********/; if ($main) {printf "$if\n",(1+$subs{$if})*3,$subs{$if};$c=4} else {$c=3;print "";} $cfg=~s//>/gi; print <$if$ip$DESC{$if}($SDESC{$if})
$cfg
  EOP } print "\n"; } } sub g_generate { ($file,$hostname)=@_; #print "[$file][$hostname]\n"; $config="$ndir/$hostname/wleiden.conf"; if (! -r $config) { if ($HTML) {print "

File $file not found: $config

\n";} else {print "File $file not found: $config\n";} } else { if ($file=~/(ospfd|zebra)/) {$char='!';} else {$char='#';} $svn_versiont=svn_version($toolfile,$char); $svn_versionc=svn_version($config,$char); if ($svn_versiont=~/Last Changed Rev: (\d+)/) {$tool_rev=$1;} if ($svn_versionc=~/Last Changed Rev: (\d+)/) {$config_rev=$1;} #print "[$tool_rev $config_rev]
\n"; if ($tool_rev >= $config_rev) {$svn_version=$svn_versiont . $svn_versionc;} else {$svn_version=$svn_versionc;} if ($HTML) {print "

Genesis $file voor: $hostname

\n";} do($config) || die; parse_config(); read_areas(); do_it(); if ($file=~/ospfd.conf/) {$pr=$ospfd;} if ($file=~/zebra.conf/) {$pr=$zebra;} if ($file=~/dhcpd.conf/) {$pr=$dhcp;} if ($file=~/snmpd.local.conf/){$pr=$snmpd;} if ($file=~/mrtg.cfg/) {$pr=$mrtg;} if ($file=~/linux.sh/) {$pr=$nwcfg;} if ($file=~/sh/) {$pr=$sh;} if ($file=~/rc.node.local/) {$pr=$rcconf;} if ($file=~/rc.local/) {$pr=$freebsd;} if ($file=~/resolv.conf/) {$pr=$resolv;} if ($file=~/named.conf/) {$pr=$named;} if ($HTML) { $pr=~s//>/gi; print "

$pr
\n"; } else {print $pr;} } }