| 1 | #
|
|---|
| 2 | #
|
|---|
| 3 | # maart 2004 rick@wirelessleiden.nl
|
|---|
| 4 | #
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | my $debug=0;
|
|---|
| 8 | my $author="feb 2003 jasper\@WirelessLeiden.NL \| maart 2005 rick\@WirelessLeiden.NL";
|
|---|
| 9 | my $wicontrol='/usr/sbin/wicontrol';
|
|---|
| 10 | my $IP_pmPath='/home/rick/svn/genesis/tools/IP.pm';
|
|---|
| 11 | my $dnsheader_confPath='/home/rick/svn/genesis/dns/dnsheader.conf';
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | #variablen
|
|---|
| 15 | my $workingfile = "";
|
|---|
| 16 | my $time=gmtime();
|
|---|
| 17 | my $source=`/bin/hostname -s`;
|
|---|
| 18 | chomp($source);
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | #slurp IP berekeningen info
|
|---|
| 22 | do ($IP_pmPath) || die ("Cann't open $IP_pmPath");
|
|---|
| 23 | #slurp dns info
|
|---|
| 24 | do ($dnsheader_confPath) || die ("Cann't open $dnsheader_confPath");
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | #zoek uit of het master_ip addr voorkomt in de configs
|
|---|
| 28 | #belangrijk van aliassen
|
|---|
| 29 | sub master_ipNotUsed {
|
|---|
| 30 | if( $debug ) {
|
|---|
| 31 | print "running master_ipNotUsed...\n";
|
|---|
| 32 | }
|
|---|
| 33 | foreach my $if (keys %config) {
|
|---|
| 34 | if( $IP{$if} =~ /([0-9\.]+).*/ ) {
|
|---|
| 35 | if( $1 eq $master_ip ) {
|
|---|
| 36 | return(0);
|
|---|
| 37 | break;
|
|---|
| 38 | };
|
|---|
| 39 | };
|
|---|
| 40 | };
|
|---|
| 41 | return(1);
|
|---|
| 42 | };
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | sub genHeader {
|
|---|
| 47 | my $comment = $_[0];
|
|---|
| 48 | my $output =
|
|---|
| 49 | "$comment This file specific to wireless\n" .
|
|---|
| 50 | "$comment leiden. Please make all changes in Genesis.\n" .
|
|---|
| 51 | "$comment\n" .
|
|---|
| 52 | "$comment Generated by $source\n" .
|
|---|
| 53 | "$comment on $time\n" .
|
|---|
| 54 | "$comment\n" .
|
|---|
| 55 | "$comment $author\n" .
|
|---|
| 56 | "$comment\n\n\n";
|
|---|
| 57 | return ($output);
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | sub txtconfig {
|
|---|
| 63 | my $output = `cat $workingfile`;
|
|---|
| 64 | return($output);
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | sub dhcpd_conf {
|
|---|
| 70 | my $output = genHeader("#");
|
|---|
| 71 | $output .=
|
|---|
| 72 | "option domain-name \"wLeiden.NET\"\n" .
|
|---|
| 73 | " \n" .
|
|---|
| 74 | "default-lease-time 7200;\n" .
|
|---|
| 75 | "max-lease-time 2592000;\n" .
|
|---|
| 76 | "\n" .
|
|---|
| 77 | "ddns-update-style none;\n" .
|
|---|
| 78 | "\n" .
|
|---|
| 79 | "# Hack for the WET11\n" .
|
|---|
| 80 | "#\n" .
|
|---|
| 81 | "always-broadcast on;\n" .
|
|---|
| 82 | "\n" .
|
|---|
| 83 | "option domain-name-servers ${master_ip};\n" .
|
|---|
| 84 | "\n";
|
|---|
| 85 |
|
|---|
| 86 | foreach my $interface (sort keys %config) {
|
|---|
| 87 | if( $interface =~ /^[a-z]+[0-9]+$/i ) {
|
|---|
| 88 | (my $ip, my $netmask) = split('/', $IP{$interface});
|
|---|
| 89 | my $subnet = IP::toSubnet($netmask);
|
|---|
| 90 | my $broadcast = IP::getBroadcastAddr($ip, $subnet);
|
|---|
| 91 | my $network = IP::getNetworkAddr($ip, $subnet);
|
|---|
| 92 |
|
|---|
| 93 | $output .=
|
|---|
| 94 | "# $interface $DESC{$interface}\n";
|
|---|
| 95 |
|
|---|
| 96 | if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) {
|
|---|
| 97 | my $dhcp_part = $ip;
|
|---|
| 98 | $dhcp_part =~ s/[0-9]+$//;
|
|---|
| 99 | (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i;
|
|---|
| 100 | $dhcp_start = $dhcp_part . $dhcp_start;
|
|---|
| 101 | $dhcp_stop = $dhcp_part . $dhcp_stop;
|
|---|
| 102 | $output .=
|
|---|
| 103 | "subnet $network netmask $subnet {\n" .
|
|---|
| 104 | " range $dhcp_start $dhcp_stop;\n" .
|
|---|
| 105 | " option broadcast-address $broadcast;\n" .
|
|---|
| 106 | " option subnet-mask $subnet;\n" .
|
|---|
| 107 | " option routers $ip;\n" .
|
|---|
| 108 | "}\n" .
|
|---|
| 109 | "\n";
|
|---|
| 110 | }
|
|---|
| 111 | else {
|
|---|
| 112 | $output .=
|
|---|
| 113 | "subnet $network netmask $subnet {not authoritative; }\n" .
|
|---|
| 114 | "\n";
|
|---|
| 115 | };
|
|---|
| 116 | };
|
|---|
| 117 | };
|
|---|
| 118 |
|
|---|
| 119 | return($output);
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | sub named_conf {
|
|---|
| 123 | my $output = genHeader("#");
|
|---|
| 124 | $output .=
|
|---|
| 125 | "options {\n" .
|
|---|
| 126 | " directory \"/var/db/namedb\"\;\n" .
|
|---|
| 127 | " forwarders {\n" .
|
|---|
| 128 | " 172.17.8.68; // proxy1\n" .
|
|---|
| 129 | " 172.17.143.4; // proxy2\n" .
|
|---|
| 130 | " 172.20.128.98; // proxy3\n" .
|
|---|
| 131 | "\n" .
|
|---|
| 132 | "\n" .
|
|---|
| 133 | "zone \"\.\" {\n" .
|
|---|
| 134 | " type hint;\n" .
|
|---|
| 135 | " file \"/etc/namedb/named.root\"\;\n" .
|
|---|
| 136 | "}\;\n" .
|
|---|
| 137 | "\n" .
|
|---|
| 138 | "zone \"0\.0\.127\.IN-ADDR.ARPA\" {\n" .
|
|---|
| 139 | " type master\;\n" .
|
|---|
| 140 | " file \"/etc/namedb/localhost.rev\"\;\n" .
|
|---|
| 141 | "}\;\n" .
|
|---|
| 142 | "\n" .
|
|---|
| 143 | "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" .
|
|---|
| 144 | " type master\;\n" .
|
|---|
| 145 | " file \"/etc/namedb/localhost-v6.rev\"\;\n" .
|
|---|
| 146 | "};\n" .
|
|---|
| 147 | "\n";
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | foreach my $tmpZone (sort keys %zone) {
|
|---|
| 151 | my $dnsZone = $zone{$tmpZone};
|
|---|
| 152 | $output .=
|
|---|
| 153 | "zone \"$tmpZone\" {\n" .
|
|---|
| 154 | " type slave\;\n" .
|
|---|
| 155 | " file \"slave/slave-$tmpZone\"\;\n" .
|
|---|
| 156 | " masters {\n";
|
|---|
| 157 | foreach my $tmpIP (sort @$dnsZone) {
|
|---|
| 158 | $output .= " $tmpIP\;\n";
|
|---|
| 159 | };
|
|---|
| 160 | $output .=
|
|---|
| 161 | " };\n" .
|
|---|
| 162 | "};\n" .
|
|---|
| 163 | "\n";
|
|---|
| 164 | };
|
|---|
| 165 |
|
|---|
| 166 | return($output);
|
|---|
| 167 | };
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 | sub rc_conf {
|
|---|
| 172 | my $output = genHeader("#");
|
|---|
| 173 | my $masterNotUsed = master_ipNotUsed();
|
|---|
| 174 | print $masterNotUsed;
|
|---|
| 175 | $output.=
|
|---|
| 176 | "hostname=\"$nodetype$nodename.wLeiden.NET\"\n" .
|
|---|
| 177 | "location=\"$location\"\n" .
|
|---|
| 178 | "\n";
|
|---|
| 179 |
|
|---|
| 180 | if( $tproxy ) {
|
|---|
| 181 | if( $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/ ) {
|
|---|
| 182 | $output .=
|
|---|
| 183 | "# Tproxy is ran on this system\n".
|
|---|
| 184 | "tproxy_enable='YES'\n".
|
|---|
| 185 | "tproxy_range='$tproxy'\n".
|
|---|
| 186 | "\n";
|
|---|
| 187 | }
|
|---|
| 188 | elsif( $tproxy !~ m/no/i ) {
|
|---|
| 189 | $output .= "# WARNING - specification propably wrong - check " .
|
|---|
| 190 | "genesis. It should be a pure CIDR\n";
|
|---|
| 191 | };
|
|---|
| 192 | };
|
|---|
| 193 |
|
|---|
| 194 | $output .= "ifconfig_lo0_alias0=\"inet 172.31.255.1/32\"\n";
|
|---|
| 195 | if( $masterNotUsed ) {
|
|---|
| 196 | $output .= "ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
|
|---|
| 197 | }
|
|---|
| 198 | else {
|
|---|
| 199 | $output .= "#ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
|
|---|
| 200 | };
|
|---|
| 201 |
|
|---|
| 202 | foreach my $interface (sort keys %config) {
|
|---|
| 203 | (my $if, my $number) = split(/:/, $interface);
|
|---|
| 204 | if( defined $number ) {
|
|---|
| 205 | $output .= "ifconfig_$if\_alias$number=\"$IP{$interface}\"\n";
|
|---|
| 206 | }
|
|---|
| 207 | else {
|
|---|
| 208 | $output .= "ifconfig_$if=\"$IP{$interface}\"\n";
|
|---|
| 209 | };
|
|---|
| 210 | };
|
|---|
| 211 | return($output);
|
|---|
| 212 | };
|
|---|
| 213 |
|
|---|
| 214 | sub rc_node_local {
|
|---|
| 215 | my $output = genHeader("#");
|
|---|
| 216 | foreach my $if (sort keys %config) {
|
|---|
| 217 | if( ($if =~ /^wi[0-9]$/i) and ($TYPE{$if} =~ /wireless/i) ) {
|
|---|
| 218 | $output .=
|
|---|
| 219 | "$wicontrol -i $if -s $SDESC{$if} # Nickname\n" .
|
|---|
| 220 | "#$wicontrol -i $if -t 7 # TXrate\n" .
|
|---|
| 221 | "$wicontrol -i $if -P 0 # PowerSave\n" .
|
|---|
| 222 | "$wicontrol -i $if -Z # Zero SNR cache\n";
|
|---|
| 223 | if( $MODE{$if}=~/master/i ) {
|
|---|
| 224 | $output .=
|
|---|
| 225 | "$wicontrol -i $if -p 6 # hostap mode\n" .
|
|---|
| 226 | "$wicontrol -i $if -c 1 # broadcasting essid on\n" .
|
|---|
| 227 | "$wicontrol -i $if -n $ESSID{$if} # network name\n" .
|
|---|
| 228 | "$wicontrol -i $if -q $ESSID{$if} # ESSID\n" .
|
|---|
| 229 | "$wicontrol -i $if -f $CHANNEL{$if}# Channel\n";
|
|---|
| 230 | }
|
|---|
| 231 | else {
|
|---|
| 232 | $output .=
|
|---|
| 233 | "$wicontrol -i $if -p 1 # Client mode (managed)\n" .
|
|---|
| 234 | "$wicontrol -i $if -n $ESSID{$if} # ESSID\n" .
|
|---|
| 235 | "# No channel - client follows\n" .
|
|---|
| 236 | "# $wicontrol -i $if -f 0 # Channel\n";
|
|---|
| 237 | };
|
|---|
| 238 | $output .= "\n";
|
|---|
| 239 | };
|
|---|
| 240 | };
|
|---|
| 241 | return($output);
|
|---|
| 242 | };
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 | sub resolv_conf {
|
|---|
| 247 | my $output = genHeader"#";
|
|---|
| 248 |
|
|---|
| 249 | $output .=
|
|---|
| 250 | "search wleiden.net.\n" .
|
|---|
| 251 | "nameserver 127.0.0.1\n" .
|
|---|
| 252 | "\n";
|
|---|
| 253 |
|
|---|
| 254 | foreach my $if (sort keys %config) {
|
|---|
| 255 | if( exists $POINT_TO_POINT{$if} ) {
|
|---|
| 256 | foreach my $ip ($POINT_TO_POINT{$if}) {
|
|---|
| 257 | $output .= "nameserver $ip # $DESC{$if}\n";
|
|---|
| 258 | };
|
|---|
| 259 | };
|
|---|
| 260 | };
|
|---|
| 261 | return($output);
|
|---|
| 262 | };
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | sub snmpd_local_conf {
|
|---|
| 267 | my $output = genHeader("#");
|
|---|
| 268 | my $masterNotUsed = master_ipNotUsed();
|
|---|
| 269 | $output .=
|
|---|
| 270 | "# Location of the physical node.\n" .
|
|---|
| 271 | "#\n" .
|
|---|
| 272 | "syslocation \"$location\"\n" .
|
|---|
| 273 | "#\n" .
|
|---|
| 274 | "# Maintained by\n" .
|
|---|
| 275 | "syscontact \"$contact\"\n" .
|
|---|
| 276 | "\n";
|
|---|
| 277 |
|
|---|
| 278 | if( $DISK =~ /flash/i ) {
|
|---|
| 279 | $output .= "# Verify that disk is RO\n";
|
|---|
| 280 | $output .= "sh diskro /usr/local/sbin/diskro.sh\n\n";
|
|---|
| 281 | };
|
|---|
| 282 |
|
|---|
| 283 | $output .= "agentaddress 161,tcp:161\n";
|
|---|
| 284 |
|
|---|
| 285 | if( $masterNotUsed ) {
|
|---|
| 286 | $output .= "agentaddress $master_ip\n";
|
|---|
| 287 | };
|
|---|
| 288 |
|
|---|
| 289 | foreach my $if (keys %config) {
|
|---|
| 290 | if( $IP{$if} =~ /([0-9\.]+).*/ ) {
|
|---|
| 291 | $output .= "agentaddress $1\n";
|
|---|
| 292 | };
|
|---|
| 293 | };
|
|---|
| 294 | return($output);
|
|---|
| 295 | };
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 | sub parse_config {
|
|---|
| 300 | $workingfile = $_[0];
|
|---|
| 301 | do($workingfile) || die("Cann't open/parse $workingfile");
|
|---|
| 302 | foreach $if (keys %config) {
|
|---|
| 303 | $cfg=$config{$if};
|
|---|
| 304 | while ($cfg) {
|
|---|
| 305 | $cfg=~s/^([^\n\r]+)[\r\n]*//m;
|
|---|
| 306 | $line=$1;
|
|---|
| 307 | $line=~s/\s*#.*//;
|
|---|
| 308 | if ((($name,$value)=split(/=/,$line)) eq 2) {
|
|---|
| 309 | $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}";
|
|---|
| 310 | eval($doit);
|
|---|
| 311 | };
|
|---|
| 312 | $cfg=~s/[\r\n]*$//m;
|
|---|
| 313 | };
|
|---|
| 314 | };
|
|---|
| 315 | };
|
|---|
| 316 |
|
|---|
| 317 | sub do_it {
|
|---|
| 318 | my $file = $_[0];
|
|---|
| 319 | my $body = "";
|
|---|
| 320 |
|
|---|
| 321 | $file =~ s/\./_/g;
|
|---|
| 322 | $body=&$file;
|
|---|
| 323 | return($body);
|
|---|
| 324 | };
|
|---|
| 325 |
|
|---|
| 326 | if( exists $ARGV[1] ) {
|
|---|
| 327 | parse_config($ARGV[0]);
|
|---|
| 328 | print do_it($ARGV[1]);
|
|---|
| 329 | }
|
|---|
| 330 | else {
|
|---|
| 331 | print "Usage `perl wleiden.pl 'inputfile' 'outputfile'`\n";
|
|---|
| 332 | print "While calling from perl script use:\n";
|
|---|
| 333 | print "parse_config('inputfile')\n";
|
|---|
| 334 | print "do_it('outputfile')\n";
|
|---|
| 335 | };
|
|---|
| 336 |
|
|---|
| 337 | exit 0;
|
|---|