#!/usr/bin/perl -w # # Copyright 2005 Stichting Wireless Leiden # maart 2004 rick@wirelessleiden.nl # # Config located at other file my $conf_file="./genesis.conf"; do($conf_file) || die("Cann't open $conf_file"); ################ END OF CONFIG ########################## #variablen my $time=gmtime(); my $source=`/bin/hostname`; chomp($source); #slurp IP berekeningen info do ("$IP_pmPath") || die ("Cann't open $IP_pmPath"); #slurp dns info #do ("$dnsheader_confPath") || die ("Cann't open $dnsheader_confPath"); #zoek uit of het master_ip addr voorkomt in de configs #belangrijk van aliassen sub master_ipNotUsed { if( $debug ) { print "running master_ipNotUsed...\n"; } foreach my $if (keys %config) { if( $IP{$if} =~ /([0-9\.]+).*/ ) { if( $1 eq $master_ip ) { return(0); }; }; }; return(1); }; sub genHeader { my $comment = $_[0]; my $output = "$comment This file specific to wireless\n" . "$comment leiden. Please make all changes in Genesis.\n" . "$comment\n" . "$comment Generated by $source\n" . "$comment on $time\n" . "$comment\n" . "$comment $author\n" . "$comment\n\n\n"; return ($output); }; sub txtconfig { my $output = ""; foreach $interface (keys %config) { $output .= $config{$interface}; }; return($output); }; sub dnsmasq_conf { my $output = genHeader("#"); $output .= "# DHCP server options \n" . "dhcp-authoritative \n" . "dhcp-fqdn \n" . "domain=dhcp.$nodename.$domain. \n" . "domain-needed \n" . "expand-hosts \n" . "\n" . "# Low memory footprint \n" . "cache-size=10000 \n" . "\n"; foreach my $interface (sort keys %config) { if( $interface =~ /^[a-z]+[0-9]+$/i ) { (my $ip, my $netmask) = split('/', $IP{$interface}); my $subnet = IP::toSubnet($netmask); $output .= "## $interface $DESC{$interface}\n"; if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) { my $dhcp_part = $ip; $dhcp_part =~ s/[0-9]+$//; (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i; $dhcp_start = $dhcp_part . $dhcp_start; $dhcp_stop = $dhcp_part . $dhcp_stop; $output .= "dhcp-range=$interface,$dhcp_start,$dhcp_stop,$subnet,4h\n"; foreach my $dhcp_static (split(';', $DHCP_STATIC{$interface})) { $output .= "dhcp-host=$dhcp_static\n"; }; $output .= "\n"; } else { $output .= "# not autoritive \n\n"; }; }; }; return($output); }; sub dhcpd_conf { my $output = genHeader("#"); $output .= "option domain-name \"$domain\";\n" . " \n" . "default-lease-time 7200;\n" . "max-lease-time 2592000;\n" . "\n" . "ddns-update-style none;\n" . "\n" . "# Hack for the WET11\n" . "#\n" . "always-broadcast on;\n" . "\n" . "option domain-name-servers ${master_ip};\n" . "\n"; foreach my $interface (sort keys %config) { if( $interface =~ /^[a-z]+[0-9]+$/i ) { (my $ip, my $netmask) = split('/', $IP{$interface}); my $subnet = IP::toSubnet($netmask); my $broadcast = IP::getBroadcastAddr($ip, $subnet); my $network = IP::getNetworkAddr($ip, $subnet); $output .= "# $interface $DESC{$interface}\n"; if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) { my $dhcp_part = $ip; $dhcp_part =~ s/[0-9]+$//; (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i; $dhcp_start = $dhcp_part . $dhcp_start; $dhcp_stop = $dhcp_part . $dhcp_stop; $output .= "subnet $network netmask $subnet {\n" . " range $dhcp_start $dhcp_stop;\n" . " option broadcast-address $broadcast;\n" . " option subnet-mask $subnet;\n" . " option routers $ip;\n" . $DHCP_STATIC{$if} . "}\n" . "\n"; } else { $output .= "subnet $network netmask $subnet {not authoritative; }\n" . "\n"; }; }; }; return($output); }; sub named_conf { my $output = genHeader("#"); $output .= "options {\n" . " directory \"/etc/namedb\"\;\n" . " pid-file \"/var/run/named/pid\"\;\n" . " forwarders {\n"; foreach my $forward (@forwarder) { $output .= "$forward;\n"; }; $output .= " };\n" . "};\n" . "\n" . "\n" . "zone \"\.\" {\n" . " type hint;\n" . " file \"/etc/namedb/named.root\"\;\n" . "}\;\n" . "\n" . "zone \"0\.0\.127\.IN-ADDR.ARPA\" {\n" . " type master\;\n" . " file \"/etc/namedb/master/localhost.rev\"\;\n" . "}\;\n" . "\n" . "zone \"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.INT\" {\n" . " type master\;\n" . " file \"/etc/namedb/master/localhost-v6.rev\"\;\n" . "};\n" . "\n"; foreach my $tmpZone (sort keys %zone) { my $dnsZone = $zone{$tmpZone}; $output .= "zone \"$tmpZone\" {\n" . " type slave\;\n" . " file \"slave/slave-$tmpZone\"\;\n" . " masters {\n"; foreach my $tmpIP (sort @$dnsZone) { $output .= " $tmpIP\;\n"; }; $output .= " };\n" . "};\n" . "\n"; }; return($output); }; sub wleiden_conf { # Generate our header my $output = genHeader("#"); # Get al proxies opendir(BIN, $ndir) or die "Can't open $dir: $!"; @proxyfiles = grep(/proxy/, readdir(BIN)); closedir(BIN); # Walk through all our config files and get master_ip (and are up) @proxies = (); foreach $file (@proxyfiles) { $nfile = "$ndir/$file/wleiden.conf"; parse_config($nfile); if ($status == "up") { $proxies[$proxyid] = $master_ip; } } # Print the Ip's in shell variable script format $output .= "PROXIES=`cat <); close( GLOBAL ); } else { $output .= "# No $global_keyPath\n"; }; if( -e "$ndir/$nodetype$nodename/$ssh_file" ) { open( NODE, "$ndir/$nodetype$nodename/$ssh_file" ) || die ("Cann't open $home/$nodename/$ssh_file"); $output .= join("", ); close( NODE ); } else { $output .= "# No $ndir/$nodetype$nodename/$ssh_file\n"; }; return($output); }; sub do_it { my $file = $_[0]; my $body = ""; $file =~ s/\./_/g; $body=&$file; return($body); }; if( exists $ARGV[0] ) { if( exists $ARGV[1] ) { parse_config($ARGV[0]); print do_it($ARGV[1]); } else { print "Usage `perl wleiden.pl 'inputfile' 'outputfile'`\n"; }; }; 1;