[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
|
---|
| 8 | my $conf_file="/home/genesis/tools/genesis.conf";
|
---|
| 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" .
|
---|
| 105 | "}\n" .
|
---|
| 106 | "\n";
|
---|
[813] | 107 | }
|
---|
[4075] | 108 | else {
|
---|
| 109 | $output .=
|
---|
| 110 | "subnet $network netmask $subnet {not authoritative; }\n" .
|
---|
| 111 | "\n";
|
---|
| 112 | };
|
---|
| 113 | };
|
---|
| 114 | };
|
---|
| 115 |
|
---|
| 116 | return($output);
|
---|
| 117 | };
|
---|
[813] | 118 |
|
---|
[4075] | 119 | sub named_conf {
|
---|
| 120 | my $output = genHeader("#");
|
---|
| 121 | $output .=
|
---|
| 122 | "options {\n" .
|
---|
| 123 | " directory \"/var/db/namedb\"\;\n" .
|
---|
[4105] | 124 | " forwarders {\n";
|
---|
| 125 | foreach my $forward (@forwarder) {
|
---|
| 126 | $output .= "$forward;\n";
|
---|
| 127 | };
|
---|
[4115] | 128 | $output .=
|
---|
[4091] | 129 | " };\n" .
|
---|
| 130 | "};\n" .
|
---|
[4075] | 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";
|
---|
[813] | 148 |
|
---|
| 149 |
|
---|
[4075] | 150 | foreach my $tmpZone (sort keys %zone) {
|
---|
| 151 | my $dnsZone = $zone{$tmpZone};
|
---|
| 152 | $output .=
|
---|
| 153 | "zone \"$tmpZone\" {\n" .
|
---|
| 154 | " type slave\;\n" .
|
---|
[4084] | 155 | " file \"slave-$tmpZone\"\;\n" .
|
---|
[4075] | 156 | " masters {\n";
|
---|
| 157 | foreach my $tmpIP (sort @$dnsZone) {
|
---|
| 158 | $output .= " $tmpIP\;\n";
|
---|
[3897] | 159 | };
|
---|
[4075] | 160 | $output .=
|
---|
| 161 | " };\n" .
|
---|
| 162 | "};\n" .
|
---|
| 163 | "\n";
|
---|
[3897] | 164 | };
|
---|
[4075] | 165 |
|
---|
| 166 | return($output);
|
---|
[3897] | 167 | };
|
---|
| 168 |
|
---|
| 169 |
|
---|
[813] | 170 |
|
---|
[4089] | 171 | sub rc_node_local {
|
---|
[4075] | 172 | my $output = genHeader("#");
|
---|
| 173 | my $masterNotUsed = master_ipNotUsed();
|
---|
| 174 | $output.=
|
---|
[4105] | 175 | "hostname=\"$nodetype$nodename.$domain\"\n" .
|
---|
[4075] | 176 | "location=\"$location\"\n" .
|
---|
| 177 | "\n";
|
---|
[813] | 178 |
|
---|
[4075] | 179 | if( $tproxy ) {
|
---|
| 180 | if( $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/ ) {
|
---|
| 181 | $output .=
|
---|
| 182 | "# Tproxy is ran on this system\n".
|
---|
| 183 | "tproxy_enable='YES'\n".
|
---|
| 184 | "tproxy_range='$tproxy'\n".
|
---|
| 185 | "\n";
|
---|
| 186 | }
|
---|
| 187 | elsif( $tproxy !~ m/no/i ) {
|
---|
| 188 | $output .= "# WARNING - specification propably wrong - check " .
|
---|
| 189 | "genesis. It should be a pure CIDR\n";
|
---|
| 190 | };
|
---|
| 191 | };
|
---|
| 192 |
|
---|
| 193 | $output .= "ifconfig_lo0_alias0=\"inet 172.31.255.1/32\"\n";
|
---|
| 194 | if( $masterNotUsed ) {
|
---|
| 195 | $output .= "ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
|
---|
| 196 | }
|
---|
| 197 | else {
|
---|
| 198 | $output .= "#ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
|
---|
| 199 | };
|
---|
[813] | 200 |
|
---|
[4075] | 201 | foreach my $interface (sort keys %config) {
|
---|
| 202 | (my $if, my $number) = split(/:/, $interface);
|
---|
[4203] | 203 | if( defined $number ) {
|
---|
| 204 | $output .= "ifconfig_$if\_alias$number=\"inet $IP{$interface}\"";
|
---|
| 205 | }
|
---|
| 206 | else {
|
---|
| 207 | $output .= "ifconfig_$if=\"inet $IP{$interface}\"\t";
|
---|
| 208 | };
|
---|
| 209 | ## add some extra link information
|
---|
| 210 | $output .= "\t# $DESC{$interface}\n";
|
---|
[4075] | 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 |
|
---|
[4174] | 318 | sub authorized_keys {
|
---|
| 319 | my $output = genHeader("#");
|
---|
| 320 | if( -e "$global_keyPath" ) {
|
---|
| 321 | open( GLOBAL, "$global_keyPath" ) || die ("Cann't open $global_keyPath");
|
---|
| 322 | $output .= join("", <GLOBAL>);
|
---|
| 323 | close( GLOBAL );
|
---|
| 324 | }
|
---|
| 325 | else {
|
---|
| 326 | $output .= "# No $global_keyPath\n";
|
---|
| 327 | };
|
---|
| 328 |
|
---|
| 329 | if( -e "$ndir/$nodetype$nodename/$ssh_file" ) {
|
---|
| 330 | open( NODE, "$ndir/$nodetype$nodename/$ssh_file" ) || die ("Cann't open $home/$nodename/$ssh_file");
|
---|
| 331 | $output .= join("", <NODE>);
|
---|
| 332 | close( NODE );
|
---|
| 333 | }
|
---|
| 334 | else {
|
---|
| 335 | $output .= "# No $ndir/$nodetype$nodename/$ssh_file\n";
|
---|
| 336 | };
|
---|
| 337 |
|
---|
| 338 | return($output);
|
---|
| 339 | };
|
---|
| 340 |
|
---|
[4075] | 341 | sub do_it {
|
---|
| 342 | my $file = $_[0];
|
---|
| 343 | my $body = "";
|
---|
[813] | 344 |
|
---|
[4075] | 345 | $file =~ s/\./_/g;
|
---|
| 346 | $body=&$file;
|
---|
| 347 | return($body);
|
---|
| 348 | };
|
---|
[813] | 349 |
|
---|
[4081] | 350 | if( exists $ARGV[0] ) {
|
---|
[4079] | 351 | if( exists $ARGV[1] ) {
|
---|
| 352 | parse_config($ARGV[0]);
|
---|
| 353 | print do_it($ARGV[1]);
|
---|
| 354 | }
|
---|
| 355 | else {
|
---|
| 356 | print "Usage `perl wleiden.pl 'inputfile' 'outputfile'`\n";
|
---|
| 357 | };
|
---|
[4075] | 358 | };
|
---|
[4081] | 359 |
|
---|
| 360 | 1;
|
---|