#! /usr/bin/perl # # # use GDBM_File; use Socket; $genesis_dir='/home/jasper/wireless-leiden/svn/genesis/nodes'; $svn='/usr/local/bin/svn'; if ($ARGV[0] eq 'DEBUG') {shift(@ARGV);$DEBUG=1;} else {$DEBUG=0;} #$revision=`$svn info $genesis_dir|grep 'Last Changed Rev:'`; #$revision=~s/Last Changed Rev:\s+(\d+)\D*/$1/s; #$revision_file='/home/wleiden/stats/mrtg/last_cfgmaker_revision'; #$last_revision=`cat $revision_file`; #$last_revision=~s/\D*(\d+)\D*/$1/s; #if ($revision <= $last_revision) #{if ($DEBUG) {print "Nothing to do: $last_revision=$revision\n";} # if ($ARGV[1] eq '') {exit;} #} elsif ($DEBUG) {print "Last revision= [$last_revision] <> [$revision]\n";} #chdir($genesis_dir) || die "Could not cd to $genesis_dir"; foreach $file (glob("$genesis_dir/*/wleiden.conf")) { $file=~s/^$genesis_dir\///; $file=~s/\/wleiden\.conf//gi; #print "FILE: $file\n"; if (! grep(/^$file$/,@NODES)) { push(@NODES,$file); # if ($DEBUG) {print STDERR "Adding node $file\n";} } } open (NODES,">nodes") || die; foreach $node (@NODES) { if ($node=~/(demo|test|vuilnis|vpn)/) {next;} $nodez++; if ($DEBUG) {print STDERR "Doing node $node\n";} make_cfg($node); } close(NODES); sub make_cfg { local($node)=@_; local($r,$if,$main,$wireless)=''; local($X,$Y,$Real_X,$RealY); local(%config,%DESC,%SDESC,%ANTENNA,%BEAMWIDTH,%CABLE,%CHANNEL,%DHCP,%DHCP_STATIC); local(%DIRECTION,%ESSID,%GAIN,%IP,%MODE,%NAT,%OSPF_AREA,%OSPF_BROADCAST); local(%OSPF_NEIGHBORS,%POINT_TO_POINT,%POLAR,%ROUTE,%SENS,%SPEED,%TXPOWER,%TYPE); local($labelpos,$neighbors,$link_file,$int_file); local(%ptp_done); do "$genesis_dir/${node}/wleiden.conf" || return; parse_config(); $XY{"$node-XY"}="$X:$Y"; if ($Real_X) {$XY{"$node-RXY"}="$Real_X:$Real_Y";} $XY{"$node-labelpos"}=$labelpos; if ($nodetype=~/CNode/i) { print NODES "$node=$X,$Y|"; foreach $if (sort keys %config) { if ($if=~/:\d+/) {next;} if ($TYPE{$if}=~/wireless/i) { if ($MODE{$if}=~/master/i) {$s='=';} else {$s=':';} print NODES "$if$s$ESSID{$if}|"; } } print NODES "\n"; } } #make_cfg sub parse_config { foreach $if (keys %config) { $cfg=$config{$if}; #if (! $html) {print "Parsing interface: $if\n";} while ($cfg) { $cfg=~s/^([^\n\r]+)[\r\n]*//m; $line=$1; $line=~s/\s*#.*//; if ((($name,$value)=split(/=/,$line)) eq 2) { #print "VAL($name)=$value\n"; $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}"; #print "DOIT: [$doit]\n"; eval($doit); } #print "CFG:[$cfg]\n"; $cfg=~s/[\r\n]*$//m; } } #if ($functions_only<1) {print "Done parsing config.\n";} }