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