[4081] | 1 | #!/usr/bin/perl -w
|
---|
[813] | 2 | #
|
---|
[4174] | 3 | # Copyright 2005 Stichting Wireless Leiden
|
---|
| 4 | # maart 2004 rick@wirelessleiden.nl
|
---|
[813] | 5 | #
|
---|
| 6 |
|
---|
[4174] | 7 | # Config located at other file
|
---|
[4187] | 8 | my $conf_file="/home/genesis/tools/FreeBSD5_x/genesis.conf";
|
---|
[4174] | 9 | do($conf_file) || die("Cann't open $conf_file");
|
---|
| 10 | ################ END OF CONFIG ##########################
|
---|
[826] | 11 |
|
---|
[4075] | 12 | #variablen
|
---|
| 13 | my $time=gmtime();
|
---|
[4084] | 14 | my $source=`/bin/hostname`;
|
---|
[4075] | 15 | chomp($source);
|
---|
[813] | 16 |
|
---|
| 17 |
|
---|
[4078] | 18 | #slurp IP berekeningen info
|
---|
[4081] | 19 | do ("$IP_pmPath") || die ("Cann't open $IP_pmPath");
|
---|
[4078] | 20 | #slurp dns info
|
---|
[4081] | 21 | do ("$dnsheader_confPath") || die ("Cann't open $dnsheader_confPath");
|
---|
[813] | 22 |
|
---|
[4078] | 23 |
|
---|
[4075] | 24 | #zoek uit of het master_ip addr voorkomt in de configs
|
---|
| 25 | #belangrijk van aliassen
|
---|
| 26 | sub master_ipNotUsed {
|
---|
| 27 | if( $debug ) {
|
---|
| 28 | print "running master_ipNotUsed...\n";
|
---|
[813] | 29 | }
|
---|
[4075] | 30 | foreach my $if (keys %config) {
|
---|
| 31 | if( $IP{$if} =~ /([0-9\.]+).*/ ) {
|
---|
| 32 | if( $1 eq $master_ip ) {
|
---|
| 33 | return(0);
|
---|
| 34 | };
|
---|
| 35 | };
|
---|
| 36 | };
|
---|
| 37 | return(1);
|
---|
| 38 | };
|
---|
[813] | 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
[4075] | 42 | sub genHeader {
|
---|
| 43 | my $comment = $_[0];
|
---|
| 44 | my $output =
|
---|
| 45 | "$comment This file specific to wireless\n" .
|
---|
| 46 | "$comment leiden. Please make all changes in Genesis.\n" .
|
---|
| 47 | "$comment\n" .
|
---|
| 48 | "$comment Generated by $source\n" .
|
---|
| 49 | "$comment on $time\n" .
|
---|
| 50 | "$comment\n" .
|
---|
| 51 | "$comment $author\n" .
|
---|
| 52 | "$comment\n\n\n";
|
---|
| 53 | return ($output);
|
---|
| 54 | };
|
---|
[813] | 55 |
|
---|
| 56 |
|
---|
[4075] | 57 | sub txtconfig {
|
---|
[4081] | 58 | my $output = "";
|
---|
| 59 | foreach $interface (keys %config) {
|
---|
| 60 | $output .= $config{$interface};
|
---|
| 61 | };
|
---|
[4075] | 62 | return($output);
|
---|
| 63 | };
|
---|
[813] | 64 |
|
---|
| 65 |
|
---|
[4075] | 66 | sub dhcpd_conf {
|
---|
| 67 | my $output = genHeader("#");
|
---|
| 68 | $output .=
|
---|
[4105] | 69 | "option domain-name \"$domain\";\n" .
|
---|
[4075] | 70 | " \n" .
|
---|
| 71 | "default-lease-time 7200;\n" .
|
---|
| 72 | "max-lease-time 2592000;\n" .
|
---|
| 73 | "\n" .
|
---|
| 74 | "ddns-update-style none;\n" .
|
---|
| 75 | "\n" .
|
---|
| 76 | "# Hack for the WET11\n" .
|
---|
| 77 | "#\n" .
|
---|
| 78 | "always-broadcast on;\n" .
|
---|
| 79 | "\n" .
|
---|
| 80 | "option domain-name-servers ${master_ip};\n" .
|
---|
| 81 | "\n";
|
---|
[813] | 82 |
|
---|
[4075] | 83 | foreach my $interface (sort keys %config) {
|
---|
| 84 | if( $interface =~ /^[a-z]+[0-9]+$/i ) {
|
---|
| 85 | (my $ip, my $netmask) = split('/', $IP{$interface});
|
---|
| 86 | my $subnet = IP::toSubnet($netmask);
|
---|
| 87 | my $broadcast = IP::getBroadcastAddr($ip, $subnet);
|
---|
| 88 | my $network = IP::getNetworkAddr($ip, $subnet);
|
---|
| 89 |
|
---|
| 90 | $output .=
|
---|
| 91 | "# $interface $DESC{$interface}\n";
|
---|
| 92 |
|
---|
| 93 | if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) {
|
---|
| 94 | my $dhcp_part = $ip;
|
---|
| 95 | $dhcp_part =~ s/[0-9]+$//;
|
---|
| 96 | (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i;
|
---|
| 97 | $dhcp_start = $dhcp_part . $dhcp_start;
|
---|
| 98 | $dhcp_stop = $dhcp_part . $dhcp_stop;
|
---|
| 99 | $output .=
|
---|
| 100 | "subnet $network netmask $subnet {\n" .
|
---|
| 101 | " range $dhcp_start $dhcp_stop;\n" .
|
---|
| 102 | " option broadcast-address $broadcast;\n" .
|
---|
| 103 | " option subnet-mask $subnet;\n" .
|
---|
| 104 | " option routers $ip;\n" .
|
---|
[4939] | 105 | $DHCP_STATIC{$if} .
|
---|
[4075] | 106 | "}\n" .
|
---|
| 107 | "\n";
|
---|
[813] | 108 | }
|
---|
[4075] | 109 | else {
|
---|
| 110 | $output .=
|
---|
| 111 | "subnet $network netmask $subnet {not authoritative; }\n" .
|
---|
| 112 | "\n";
|
---|
| 113 | };
|
---|
| 114 | };
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 | return($output);
|
---|
| 118 | };
|
---|
[813] | 119 |
|
---|
[4075] | 120 | sub named_conf {
|
---|
| 121 | my $output = genHeader("#");
|
---|
| 122 | $output .=
|
---|
| 123 | "options {\n" .
|
---|
[4245] | 124 | " directory \"/etc/namedb\"\;\n" .
|
---|
[4248] | 125 | " pid-file \"/var/run/named.pid\"\;\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 {
|
---|
[4186] | 209 | $output .= "ifconfig_$if=\"inet $IP{$interface}";
|
---|
| 210 | $output .= " $CARD_OPTION{$interface}";
|
---|
[4981] | 211 | if ($TYPE{$if} =~ /wireless/i) {
|
---|
| 212 | $output .= "\"\t# rc.local: " unless $NG;
|
---|
[4186] | 213 | $output .= " ssid $ESSID{$interface}";
|
---|
| 214 | if( $MODE{$if}=~/master/i ) {
|
---|
| 215 | $output .= " channel $CHANNEL{$interface}";
|
---|
| 216 | $output .= " mediaopt hostap";
|
---|
| 217 | }
|
---|
| 218 | else {
|
---|
| 219 | $output .= "";
|
---|
| 220 | };
|
---|
| 221 | };
|
---|
| 222 | $output .= "\"\n";
|
---|
[4075] | 223 | };
|
---|
| 224 | };
|
---|
| 225 | return($output);
|
---|
[4024] | 226 | };
|
---|
| 227 |
|
---|
[906] | 228 |
|
---|
[4075] | 229 | sub resolv_conf {
|
---|
| 230 | my $output = genHeader"#";
|
---|
[829] | 231 |
|
---|
[4075] | 232 | $output .=
|
---|
| 233 | "search wleiden.net.\n" .
|
---|
| 234 | "nameserver 127.0.0.1\n" .
|
---|
| 235 | "\n";
|
---|
[813] | 236 |
|
---|
[4075] | 237 | foreach my $if (sort keys %config) {
|
---|
| 238 | if( exists $POINT_TO_POINT{$if} ) {
|
---|
| 239 | foreach my $ip ($POINT_TO_POINT{$if}) {
|
---|
| 240 | $output .= "nameserver $ip # $DESC{$if}\n";
|
---|
| 241 | };
|
---|
| 242 | };
|
---|
| 243 | };
|
---|
| 244 | return($output);
|
---|
[813] | 245 | };
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 |
|
---|
[4075] | 249 | sub snmpd_local_conf {
|
---|
| 250 | my $output = genHeader("#");
|
---|
| 251 | my $masterNotUsed = master_ipNotUsed();
|
---|
| 252 | $output .=
|
---|
| 253 | "# Location of the physical node.\n" .
|
---|
| 254 | "#\n" .
|
---|
| 255 | "syslocation \"$location\"\n" .
|
---|
| 256 | "#\n" .
|
---|
| 257 | "# Maintained by\n" .
|
---|
| 258 | "syscontact \"$contact\"\n" .
|
---|
| 259 | "\n";
|
---|
[813] | 260 |
|
---|
[4075] | 261 | if( $DISK =~ /flash/i ) {
|
---|
| 262 | $output .= "# Verify that disk is RO\n";
|
---|
| 263 | $output .= "sh diskro /usr/local/sbin/diskro.sh\n\n";
|
---|
| 264 | };
|
---|
[813] | 265 |
|
---|
[4075] | 266 | $output .= "agentaddress 161,tcp:161\n";
|
---|
[813] | 267 |
|
---|
[4075] | 268 | if( $masterNotUsed ) {
|
---|
| 269 | $output .= "agentaddress $master_ip\n";
|
---|
| 270 | };
|
---|
| 271 |
|
---|
| 272 | foreach my $if (keys %config) {
|
---|
| 273 | if( $IP{$if} =~ /([0-9\.]+).*/ ) {
|
---|
| 274 | $output .= "agentaddress $1\n";
|
---|
| 275 | };
|
---|
| 276 | };
|
---|
| 277 | return($output);
|
---|
[813] | 278 | };
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 |
|
---|
[4075] | 282 | sub parse_config {
|
---|
[4081] | 283 | my $workingfile = $_[0];
|
---|
[4075] | 284 | do($workingfile) || die("Cann't open/parse $workingfile");
|
---|
[4081] | 285 | foreach my $if (keys %config) {
|
---|
| 286 | my $cfg=$config{$if};
|
---|
[4075] | 287 | while ($cfg) {
|
---|
| 288 | $cfg=~s/^([^\n\r]+)[\r\n]*//m;
|
---|
[4081] | 289 | my $line=$1;
|
---|
[4075] | 290 | $line=~s/\s*#.*//;
|
---|
[4081] | 291 | if (((my $name, my $value)=split(/=/,$line)) eq 2) {
|
---|
| 292 | my $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\";$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}";
|
---|
[4075] | 293 | eval($doit);
|
---|
| 294 | };
|
---|
| 295 | $cfg=~s/[\r\n]*$//m;
|
---|
| 296 | };
|
---|
[4046] | 297 | };
|
---|
| 298 | };
|
---|
[1095] | 299 |
|
---|
[4174] | 300 | sub authorized_keys {
|
---|
| 301 | my $output = genHeader("#");
|
---|
| 302 | if( -e "$global_keyPath" ) {
|
---|
| 303 | open( GLOBAL, "$global_keyPath" ) || die ("Cann't open $global_keyPath");
|
---|
| 304 | $output .= join("", <GLOBAL>);
|
---|
| 305 | close( GLOBAL );
|
---|
| 306 | }
|
---|
| 307 | else {
|
---|
| 308 | $output .= "# No $global_keyPath\n";
|
---|
| 309 | };
|
---|
| 310 |
|
---|
| 311 | if( -e "$ndir/$nodetype$nodename/$ssh_file" ) {
|
---|
| 312 | open( NODE, "$ndir/$nodetype$nodename/$ssh_file" ) || die ("Cann't open $home/$nodename/$ssh_file");
|
---|
| 313 | $output .= join("", <NODE>);
|
---|
| 314 | close( NODE );
|
---|
| 315 | }
|
---|
| 316 | else {
|
---|
| 317 | $output .= "# No $ndir/$nodetype$nodename/$ssh_file\n";
|
---|
| 318 | };
|
---|
| 319 |
|
---|
| 320 | return($output);
|
---|
| 321 | };
|
---|
| 322 |
|
---|
[4075] | 323 | sub do_it {
|
---|
| 324 | my $file = $_[0];
|
---|
| 325 | my $body = "";
|
---|
[813] | 326 |
|
---|
[4075] | 327 | $file =~ s/\./_/g;
|
---|
| 328 | $body=&$file;
|
---|
| 329 | return($body);
|
---|
| 330 | };
|
---|
[813] | 331 |
|
---|
[4081] | 332 | if( exists $ARGV[0] ) {
|
---|
[4079] | 333 | if( exists $ARGV[1] ) {
|
---|
| 334 | parse_config($ARGV[0]);
|
---|
| 335 | print do_it($ARGV[1]);
|
---|
| 336 | }
|
---|
| 337 | else {
|
---|
| 338 | print "Usage `perl wleiden.pl 'inputfile' 'outputfile'`\n";
|
---|
| 339 | };
|
---|
[4075] | 340 | };
|
---|
[4081] | 341 |
|
---|
[4981] | 342 |
|
---|
| 343 | sub rc_local {
|
---|
| 344 | my $output = genHeader("#");
|
---|
| 345 | if ($NG) {
|
---|
| 346 | $output .= "# Replaced by ssid et.al. info in rc.node.local\n";
|
---|
| 347 | $output .= "exit 0";
|
---|
| 348 | return $output;
|
---|
| 349 | }
|
---|
| 350 | foreach my $if (sort keys %config) {
|
---|
| 351 | if( ($if =~ /^wi[0-9]$/i) and ($TYPE{$if} =~ /wireless/i) ) {
|
---|
| 352 | $output .=
|
---|
| 353 | "$wicontrol -i $if -s $SDESC{$if} # Nickname\n" .
|
---|
| 354 | "#$wicontrol -i $if -t 7 # TXrate\n" .
|
---|
| 355 | "$wicontrol -i $if -P 0 # PowerSave\n" .
|
---|
| 356 | "$wicontrol -i $if -Z # Zero SNR cache\n";
|
---|
| 357 | if( $MODE{$if}=~/master/i ) {
|
---|
| 358 | $output .=
|
---|
| 359 | "$wicontrol -i $if -p 6 # hostap mode\n" .
|
---|
| 360 | "$wicontrol -i $if -c 1 # broadcasting essid on\n" .
|
---|
| 361 | "$wicontrol -i $if -n $ESSID{$if} # network name\n" .
|
---|
| 362 | "$wicontrol -i $if -q $ESSID{$if} # ESSID\n" .
|
---|
| 363 | "$wicontrol -i $if -f $CHANNEL{$if}# Channel\n";
|
---|
| 364 | }
|
---|
| 365 | else {
|
---|
| 366 | $output .=
|
---|
| 367 | "$wicontrol -i $if -p 1 # Client mode (managed)\n" .
|
---|
| 368 | "$wicontrol -i $if -n $ESSID{$if} # ESSID\n" .
|
---|
| 369 | "# No channel - client follows\n" .
|
---|
| 370 | "# $wicontrol -i $if -f 0 # Channel\n";
|
---|
| 371 | };
|
---|
| 372 | $output .= "\n";
|
---|
| 373 | };
|
---|
| 374 | };
|
---|
| 375 | return($output);
|
---|
| 376 | };
|
---|
| 377 |
|
---|
[4081] | 378 | 1;
|
---|