#!/usr/bin/perl -w # # Copyright 2005 Stichting Wireless Leiden # Rick van der Zwet # # Config located at other file # my $conf_file="/home/genesis/tools/genesis.conf"; # do($conf_file) || die("Cann't open $conf_file"); die "Run with the preamble in cgi-bin" unless defined $conf_file; my $HTML=1; #laden van tool file do($toolfile) || die("Cann't open $toolfile"); #gebruik van simple subje om ervoor te zorgen dat de print netjes in het #programma gestopt kan worden sub printline { print "$_[0]\n"; }; #REQUEST parsen $request=$ENV{'REQUEST_URI'}; if( $request=~/cgi-bin\/g_list.pl\/(.*)$/) { ($node,$file)=split(/\//,$1); $title="$node $file"; } else { $title="listing"; }; #controleer wat de browser is #en zorgen dan er de nodige tags geprint worden $browser=$ENV{'HTTP_USER_AGENT'}; if( $browser=~/curl|wget|fetch/i) { $HTML=0; print "Content-type: text/plain\n\n"; } else { $HTML=1; printline("Content-type: text/html\n\n"); printline(""); printline("
"); select(STDERR); $| = 1; # make unbuffered select(STDOUT); $| = 1; # make unbuffered system("$svn update $home"); printline(""); printline("
"); printline("Click here"); printline("if you're not forwarded automaticly in 5 seconds.
");
printline("");
}
else {
g_list( );
};
}
else {
if( $file eq '') {
foreach $file ( sort @filelist) {
if( $HTML) {
print "$file \n ");
};
};
#ophalen svn versie
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);
};
# Print info on this node; version of the OS
# expected, etc..
sub g_info {
my $config="$ndir/$node/$configfile";
parse_config($config);
$release = 'unknown' unless $release;
$node_config_version = 0 unless $node_config_version;
$genesis_control = 'NO' unless $genesis_control;
$OS = 'Unknown' unless $OS;
print <<"EOM";
$OS $release $node_config_version $genesis_control
#
# Operating system release: $OS on $release
# Node Config script version: $node_config_version
# Under Gensis control: $genesis_control
#
EOM
}
#netjes de configuratie printen
sub g_print {
my $config="$ndir/$node/$configfile";
parse_config($config);
printline(" ");
printline(" ");
my $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+/;
};
printline(" ");
};
parse_config($config);
$pr=do_it($file);
if( $HTML ) {
$pr=~s/</gi;
printline("
\n";
}
else {
print "$file\n";
};
};
}
elsif( $file eq 'info') {
g_info($hostname);
}
elsif( $file eq 'config') {
g_print($hostname);
}
else {
foreach my $tmpFile ( sort @filelist) {
if( $file eq $tmpFile ) {
g_generate($file);
};
};
};
};
#plaats de sluit HTML tags
if( $HTML) {
print <Genesis config (revision: $revision):
");
printline("$svn_version");
printline("
");
printline("");
printline("");
};
opendir(DIR, $ndir) || die "can't opendir $home: $!";
@dirs = grep { /^[^\.]/ && -d "$ndir/$_" } readdir(DIR);
closedir DIR;
foreach $dir (sort @dirs) {
if( $dir=~/attic/ ) {
next;
};
my $node = $dir;
if( ! $HTML ) {
print "$node\n";
}
else {
printline("
$node ");
foreach $file (sort @filelist) {
printline("$file \n");
};
};
};
if( $HTML ) {
printline("Genesis configuratie voor: $node
" . svn_version($config) . "
");
};
#Generen config
sub g_generate {
my $file=$_[0];
$config="$ndir/$node/$configfile";
$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;
};
if( $tool_rev >= $config_rev) {
$svn_version=$svn_versiont . $svn_versionc;
}
else {
$svn_version=$svn_versionc;
};
if( $HTML) {
printline(" ");
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 "");
printline("master_ip=$master_ip");
printline("AGGREGATE=$AGGREGATE");
printline("");
printline("gw_open=$gw_open");
printline("nodetype=$nodetype");
printline("nodename=$nodename");
printline("");
printline("NS_forward=$NS_forward");
printline("NS_resolv=$NS_resolv");
printline("");
printline("location=$location");
printline("DISK=$DISK");
printline("");
printline("X=$X");
printline("Y=$Y");
printline("");
printline("Operating system: $OS / $release");
printline("Config management: Version $node_config_version, Used: $genesis_control");
printline("");
printline("$TP");
printline("
$if \n",(1+$subs{$if})*3,$subs{$if};
$c=4;
}
else {
$c=3;
print "";
};
$cfg=~s/</gi;
$cfg=~s/>/>/gi;
printline(" $if $ip $DESC{$if}($SDESC{$if}) ");
printline(" ");
printline("");
printline("$cfg");
printline("
");
};
printline("Genesis $file voor: $hostname
$pr
");
}
else {
print $pr;
};
};