source: genesis/tools/wleiden.pl@ 1604

Last change on this file since 1604 was 1469, checked in by dirkx, 21 years ago

Adding hack for the WET11 devices - may increase traffic slightly

  • Property svn:executable set to *
File size: 23.4 KB
Line 
1#! /usr/bin/perl
2#
3#
4# aug 2002, jasper\@WirelessLeiden.NL
5#
6
7
8$now=localtime($unow=time());
9
10$config='/etc/wl/wleiden.conf';
11$domain='wLeiden.NET';
12
13$ifconfig='/sbin/ifconfig';
14$iwconfig='/sbin/iwconfig';
15$ipchains='/sbin/ipchains';
16$indexmaker='/usr/bin/indexmaker';
17$sroute='/sbin/route';
18$OSPFPWD='huppel';
19$separator=';';
20$author='feb 2003 jasper@WirelessLeiden.NL';
21$wicontrol='/usr/sbin/wicontrol';
22
23if ($functions_only) {goto functions;}
24$source='/etc/wl/wleiden.pl';
25
26do($config) || die;
27parse_config();
28
29
30$hostname=`/bin/hostname |cut -d . -f 1`;chomp($hostname);
31$maxmask= pack("CCCC", 255, 255, 255, 255);
32
33
34if (! $ARGV[0]) {die "use start/stop/startall";}
35
36if ($ARGV[1]=~/debug/i) {$DEBUG=1;}
37if ($ARGV[0]=~/start/i)
38{
39
40######################################################################
41do_it();
42
43open_files();
44$nwcfg.="$indexmaker /etc/mrtg/mrtg.cfg> /var/www/html/mrtg/index.html 2> /dev/null\n";
45
46print_files();close_files();
47
48system("chmod 755 /etc/wl/nwcfg.sh;/etc/wl/nwcfg.sh");
49
50if ($DEBUG) {die "DEBUGGING!";}
51
52if ($DEBUG) {print "\nDEBUG: making mrtg index.\n";}
53
54changeline("/etc/sysconfig/dhcpd","DHCPDARGS","DHCPDARGS=\"$dhcpints\"");
55
56#if ($DEBUG) {print "\nDEBUG: reloading firewall.\n";}
57#$nwcfg.="/usr/local/sbin/firewall\n";
58
59if ($DEBUG) {print "\nDEBUG: restarting daemons.\n";}
60
61if ($ARGV[0]=~/startall/) {$restart='restart';}
62else {$restart='condrestart';}
63$nwcfg.="/etc/init.d/dhcpd $restart\n";
64$nwcfg.="/etc/init.d/zebra $restart\n";
65$nwcfg.="/etc/init.d/ospfd $restart\n";
66$nwcfg.="/etc/init.d/httpd $restart\n";
67$nwcfg.="/etc/init.d/named $restart\n";
68
69
70########################################################################
71} else # geen start -> stop
72{
73 $nwcfg.="$ifconfig lo:1 down\n";
74
75 foreach $if (keys %config)
76 {
77 $nwcfg.="$ifconfig $if down\n";
78 }
79}
80
81
82exit;
83
84########################################################################
85
86functions:
87
88$ahum=1;
89
90sub do_it
91{
92 if ($OS=~/FreeBSD/i) {$FreeBSD=1;}
93 elsif ($OS=~/Linux/i) {$Linux=1;}
94
95init_files();
96
97#system("/sbin/modprobe ipv6");
98#system("/sbin/modprobe ipchains");
99
100$nwcfg.="$ifconfig lo:1 down\n";
101#print "ifconfig lo:1 $master_ip\n";
102#$nwcfg.="$ifconfig lo:1 $master_ip netmask 255.255.255.255\n"; # altijd up!
103
104$last='';
105foreach $if (sort {$b <=> $a} keys %config)
106{
107 if ($TYPE{$if}=~/wireless/) {$last=$if}
108} if ($last) {iwconfig("$last &> /dev/null");} # Laatste het eerste...
109
110$keys=1;
111foreach $if (sort keys %config)
112{
113 if ($if=~/^([^:]+):(\d+)/) {$mymain=$1;$mysub=$2;} else {$mymain='';}
114
115 if ($functions_only<1) {print "Doing interface: $if IP: $IP{$if}\n";}
116
117 if ($if!~/:\d+/) {$main=1;} else {$main=0;}
118
119 ##################### DOWN
120 if ($DOWN{$if}=~/yes/)
121 { print "$if configured DOWN.\n";
122 $nwcfg.="$ifconfig $if 127.0.0.1 down\n";
123
124 if ($main)
125 {
126 $zebra1.=sprintf <<EOZ3;
127
128interface $if
129 description $DESC{$if}
130 ip address 127.0.0.1/0
131 shutdown
132
133EOZ3
134 $ospfd2{$if}.=" interface $if\n\n";
135 }
136 next; # Interface down.
137 }
138 ##################### DOWN
139 if ($main)
140 {
141 $if=~/(\d+)/;$ifnum=$1;
142 $nick="${nodename}$ifnum.$domain";
143
144 if ($TYPE{$if}=~/wireless/)
145 {
146
147 if ($SDESC{$if}) {$nick="$SDESC{$if}.$nick";}
148#print "$nick\n";
149 if (iwconfig("$if mode $MODE{$if}"))
150 {
151 if ($DEBUG) {print "\nDEBUG: iwconfig $if mode $MODE{$if} essid $ESSID{$if} nick $nick ap $AP{$if} channel $CHANNEL{$if} sens $SENS{$if} txpower $TXPOWER{$if} rate $RATE{$if}\n";}
152 iwconfig("$if essid $ESSID{$if}");
153 iwconfig("$if nick $nick");
154
155 $freebsd.=sprintf<<EOFB33;
156$wicontrol -i $if -s $nick # Nickname
157#$wicontrol -i $if -t 7 # TXpower
158$wicontrol -i $if -P 0 # PowerSave
159$wicontrol -i $if -Z # Zero SNR cache
160EOFB33
161 if ($MODE{$if}=~/master/i)
162 {
163 $freebsd.=sprintf<<EOFB3;
164$wicontrol -i $if -p 6 # hostap mode
165$wicontrol -i $if -n $ESSID{$if} # network name
166$wicontrol -i $if -q $ESSID{$if} # ESSID
167$wicontrol -i $if -c 1 # broadcasting essid on
168EOFB3
169 } else {
170 $freebsd.=sprintf<<EOFB4;
171$wicontrol -i $if -p 1 # Client mode (managed)
172$wicontrol -i $if -n $ESSID{$if} # ESSID
173EOFB4
174 }
175 if ($AP{$if}) {iwconfig("$if ap $AP{$if}");}
176
177if ($MODE{$if}=~/master/) {
178 if ($CHANNEL{$if}) {
179 $freebsd.="$wicontrol -i $if -f $CHANNEL{$if} # Channel\n";
180 } else {
181 $freebsd .= "# WARNING - master but no channel defined.\n";
182 };
183} else {
184 $freebsd.="# No channel - client follows\n# $wicontrol -i $if -f 0 # Channel\n";
185}
186
187 if ($SENS{$if}) {iwconfig("$if sens $SENS{$if}");}
188 if ($TXPOWER{$if}) {iwconfig("$if txpower $TXPOWER{$if}");}
189 if ($RATE{$if}) {iwconfig("$if rate $RATE{$if}");}
190 } #else { print "ERROR: Could not configure interface $if\n";next;}
191
192 $rcconf.="\nifconfig_$if=\"inet $IP{$if} -promisc\"\n";
193 #$rcconf.="ifconfig_$if=\"inet $IP{$if} -promisc \"\n ssid $ESSID{$if} \\"\n";
194 #if ($CHANNEL{$if}) {$rcconf.=" channel $CHANNEL{$if}";}
195 #$rcconf.="\\\n stationname $nick\"\n";
196 #if ($MODE{$if}=~/master/) {$rcconf.="#mediaopt hostap\n";}
197 #$rcconf.="\n";
198
199 $freebsd.="\n";
200 } # if wireless
201 mrtg1();
202 if ($OS=~/FreeBSD/)
203{
204 $ospfd2{$if}.=sprintf <<EOO2;
205
206interface $if
207 ip ospf message-digest-key 1 md5 $OSPFPWD
208 ip ospf authentication message-digest
209EOO2
210
211 $keys++;
212
213 $zebra.=sprintf <<EOZ2;
214
215interface $if
216 description $DESC{$if}
217 no shutdown
218EOZ2
219}
220
221 } ###################### MAIN
222
223 if ($OS=~/Linux/)
224{
225 $ospfd2{$if}.=sprintf <<EOO21;
226
227interface $if
228 ip ospf message-digest-key 1 md5 $OSPFPWD
229 ip ospf authentication message-digest
230EOO21
231 $keys++;
232
233 $zebra.=sprintf <<EOZ21;
234
235interface $if
236 description $DESC{$if}
237 no shutdown
238EOZ21
239}
240
241 if ($IP{$if})
242 {
243 $zebra.=sprintf " ip address $IP{$if}\n";
244 ($ip,$netmask,$broadcast,$network,$width)=calc_ip($IP{$if});
245 if ($netmask == '0.0.0.0')
246{print "Forgot netmask in config $hostname $if: $IP{$if}!\n";
247die "Forgot netmask in config $hostname $if: $IP{$if}!\n";
248}
249
250# if ($DEBUG) {print("\nDEBUG: $ifconfig $if $ip netmask $netmask broadcast $broadcast up\n");}
251 if ($DEBUG) {print("\nDEBUG: $if $ip $netmask $network $broadcast\n");}
252
253 if (! $main) {$nwcfg.="$ifconfig $mymain up\n";}
254 $nwcfg.="$ifconfig $if $ip down\n";
255 $nwcfg.="$ifconfig $if $ip netmask $netmask broadcast $broadcast up\n";
256 if ($main)
257 {
258 if ($TYPE{$if}!~/wireless/) {$rcconf.="\nifconfig_$if=\"inet $IP{$if}\"\n";}
259 } else {$rcconf.="ifconfig_${mymain}_alias${mysub}=\"inet $IP{$if}\"\n";}
260 }
261 if (($OS=~/Linux/) || ($main)) {$zebra.= "\n";}
262
263 if ($ROUTE{$if})
264 {
265 if ($DEBUG) {print "\nDEBUG: ROUTE: $ROUTE{$if}\n";}
266
267 foreach $r (split(/$separator/,$ROUTE{$if}))
268 {
269 if ($DEBUG) {print "\nDEBUG: ROUTE2: $r\n";}
270
271 $r=~/([^\/ ]+)\/?(\S+)\s+(\S+)/;
272 $R="$1/$2";$gw=$3;$nm=$2;
273 ($route,$r_netmask,$r_broadcast,$r_network,$r_width)=calc_ip($R);
274 if ($R eq '0.0.0.0/0')
275 { $doit="$sroute add default gw $gw dev $mymain";
276 $rcconf.="\ndefaultrouter=\"$gw\"\n\n";
277 }
278 elsif ($nm eq 32) {$doit="$sroute add $route gw $gw dev $mymain";}
279 else {$doit="$sroute add -net $route netmask $r_netmask gw $gw dev $mymain";}
280
281 if ($DEBUG) {print "\nROUTE3: $doit\n";}
282 $nwcfg.="$doit\n";
283 if ($R eq '0.0.0.0/0') {$ospfd3.=" default-information originate\n"}
284 else
285 {
286 $area=get_area($R);
287 $ospfd4.="! static route $R\nnetwork $R area $area\n\n";
288 $NW{$area}.="$network/$width ";
289 }
290 $zebra.="ip route $r\n";
291 }
292 }
293
294 ($ip,$netmask,$broadcast,$network,$width)=calc_ip($IP{$if});
295 if (($DHCP{$if}) && ($DHCP{$if}!~/off|no/i))
296 {
297 ($from,$upto)=split(/-/,$DHCP{$if});
298 $ip=~/(^\d+\.\d+\.\d+)\.\d+$/;
299 $dip=$1;
300 $dhcp.=sprintf <<EOD2;
301
302 #
303 # $if $DESC{$if}
304 #
305 subnet $network netmask $netmask {
306 range $dip.$from $dip.$upto;
307 option broadcast-address $broadcast;
308 option subnet-mask $netmask;
309 option routers $ip;
310 $DHCP_STATIC{$if}
311 }
312
313EOD2
314 if ($dhcpints!~/$mymain/) {$dhcpints.=" $mymain";}
315 } # DHCP
316 else
317 {
318 if ( ($main) ) #|| ($DHCP{$mymain}=~/off|no/i))
319 { # niet als main wel dhcp heeft.
320 $dhcp.="subnet $network netmask $netmask {not authoritative; } # $if\n\n";
321 }
322 }
323 if ($OSPF_NEIGHBORS{$if}=~/no/i)
324 {
325 if ($main) {$OSPF_PASSIVE{$if}=1;}
326 }
327
328 if ($OSPF_AREA{$if}!~/no/i)
329 {
330 ($ip,$netmask,$broadcast,$network,$width)=calc_ip($IP{$if});
331
332 if ($IP{$if})
333 {
334# if (($OSPF_NEIGHBORS{$if}!~/no/) ||
335 if ($OSPF_AREA{$if} eq '') {$area=get_area($network);}
336 else {$area=int($OSPF_AREA{$if});}
337
338 $ospfd4.="! $if ($DESC{$if})\nnetwork $network/$width area $area\n\n";
339 $NW{$area}.="$network/$width ";
340 }
341
342 if ($OSPF_BROADCAST{$if}=~/no/i)
343 {
344 if ($main)
345 {
346#if ($DEBUG) {print "DEBUG: OSPF_NEIGHBORS{$if}: ($OSPF1_NEIGHBORS{$if})\n";}
347 $OSPFD_NONBROADCAST{$if}=1;
348 }
349 if ($OSPF_NEIGHBORS{$if}!~/no/i)
350 {
351 foreach $n (split(/[\s$separator]+/,$OSPF_NEIGHBORS{$if}))
352 {
353 if ($DEBUG) {print "DEBUG: OSPF2_NEIGHBOR{$if}: [$n]\n";}
354 $ospfd5.="! $if link: $SDESC{$if}\n neighbor $n\n\n";
355 }
356 if ($main) {$OSPF_PASSIVE{$if}=0;}
357 else {$OSPF_PASSIVE{$mymain}=0;}
358 } #ospf_neighbors
359 }
360
361 } # ospf_area
362
363 if ($POINT_TO_POINT{$if})
364 {
365 foreach $p (split(/$separator/,$POINT_TO_POINT{$if}))
366 {
367 mrtg2();
368 } #foreach $pointtopoint
369 } # pointopoint
370} # foreach if
371
372foreach $if (sort keys %config)
373{
374 if ($if!~/:\d+/) {$main=1;} else {$main=0;}
375 if ($main)
376 {
377 $ospfd2.=$ospfd2{$if};
378 if ($OSPF_PASSIVE{$if})
379 {
380 $ospfd22.=" passive-interface $if\n";
381 }
382 if ($OSPFD_NONBROADCAST{$if})
383 {
384 $ospfd2.= " ip ospf network non-broadcast\n";
385 }
386 if ($OSPF_COST{$if})
387 {
388 $ospfd2.=" ip ospf cost $OSPF_COST{$if}\n";
389 }
390
391 }
392}
393
394 $zebra.= "\n\nlog file /var/log/zebra.log\n\n";
395
396foreach $area (keys %NW)
397{
398 if ($area eq 0) {next;}
399 $nwa=0xffffffff;
400 foreach $nw (split(/\s+/,$NW{$area}))
401 {
402 ($ip,$width)=split(/\//,$nw);
403 ($a,$b,$c,$d)=split(/\./,$ip);
404 ($II)=($a<<24)+($b<<16)+($c<<8)+$d;
405 if ($width eq 32) {$nm=0xffffffff;}
406 else {$nm=0xffffffff-1<<(31-$width);}
407
408 $II=$II & $nm;
409 $nwa=$nwa & $II;
410# $ospfd.=sprintf ("NW-$area: $nw ==> %08x enne %08x\n",$II,$nwa);
411 }
412 $nwa=itoadr($nwa);
413
414 if ($AGGREGATE) {$agg=$AGGREGATE;}
415 else {$agg=21;}
416
417 if (($nwa!~/^172\.16\./) && ($area > 0))
418 { $ospfarea.="area $area range $nwa/$agg substitute $nwa/$agg\n"; }
419
420 $ospf21.="! area $area authentication message-digest\n";
421}
422
423
424$ospfd.=sprintf <<EOOL;
425
426! ================> interfaces <================
427
428$ospfd2
429
430! ================> OSPF router <================
431router ospf
432 ospf router-id $master_ip
433 $ospfd21
434
435 passive-interface lo0
436$ospfd22
437
438!default
439$ospfd3
440
441$ospfarea
442
443! ================> networks <================
444$ospfd4
445
446! ================> neighbors <================
447$ospfd5
448
449log file /var/log/ospf.log
450
451EOOL
452# $rcconf.="\n\n" . $freebsd;
453}
454
455sub get_area
456{
457 local($IP)=@_;
458 local($range);
459 local($ip,$netmask,$broadcast,$network,$width);
460 local($a,$b,$c,$d)=split(/\./,$IP);
461 local($II)=($a<<24)+($b<<16)+($c<<8)+$d;
462 local($ii,$ip,$nm,$I2);
463
464# for ($i=0;$i<=$maxareas;$i++)
465# {
466# $ii=$II[$i];
467# $nm=$NM[$i];
468# $I2=$II & $nm;
469##$ospfd.=sprintf "i=$i\t $RANGE[$i]\t ii=$ii\t nm=$nm\t I2=$I2 $II $IP $a,$b,$c,$d\n";
470# if ($I2 == $ii) {return($AREA[$i]);}
471# }
472# return(12345);
473
474 $area=1;
475 if ($b eq 16) {$area=0;}
476 elsif ($c < 128) {$area=($b * 10)}
477 else {$area=(1+($b*10));}
478 if ($area > 255) {$area/=10;}
479 return($area);
480}
481
482
483sub read_areas
484{
485 $maxareas=0;
486 open(AC,"$home/areas.conf") || die;
487 while (<AC>)
488 {
489 chomp();
490 s/#.*$//;
491 if (! $_) {next;}
492 ($area,$range,$desc,$counter,$junk)=split(/\s+/);
493 $AREA[$maxareas]=$area;
494 $RANGE[$maxareas]=$range;
495 $DESC[$maxareas]=$desc;
496
497 ($ip,$width)=split(/\//,$range);
498 ($a,$b,$c,$d)=split(/\./,$ip);
499 $ii=($a<<24)+($b<<16)+($c<<8)+$d;
500
501 if ($width eq 32) {$nm=0xffffffff;}
502 else {$nm=0xffffffff-1<<(31-$width);}
503 $II[$maxareas]=$ii;
504 $NM[$maxareas]=$nm;
505
506 $maxareas++;
507 }
508 close(AC);
509}
510
511sub parse_config
512{
513 foreach $if (keys %config)
514 {
515 $cfg=$config{$if};
516if (! $html) {print "Parsing interface: $if\n";}
517 while ($cfg)
518 {
519 $cfg=~s/^([^\n\r]+)[\r\n]*//m;
520 $line=$1;
521 $line=~s/\s*#.*//;
522 if ((($name,$value)=split(/=/,$line)) eq 2)
523 {
524 if ($name eq 'ESSID') {$value=lc($value);}
525#print "VAL($name)=$value\n";
526 $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}";
527#print "DOIT: [$doit]\n";
528 eval($doit);
529 }
530#print "CFG:[$cfg]\n";
531 $cfg=~s/[\r\n]*$//m;
532 }
533 }
534if ($functions_only<1) {print "Done parsing config.\n";}
535}
536
537sub iwconfig
538{
539 local($line)=@_;
540 $nwcfg.="$iwconfig $line\n";
541
542}
543
544sub ipchains
545{
546 local($line)=@_;
547 return(system("$ipchains $line"));
548}
549
550#($a,$b,$c,$d) = unpack('C4',$addr[0]);
551
552#$IP = pack("CCCC", 152, 2, 128, 184); # create IP address
553#($var1, $var2, $var3, $var4) = unpack("CCCC", $IP); #inverse of the above
554
555
556
557sub calc_ip
558{ local($i)=@_;
559 local($a,$b,$c,$d);
560 local($ip,$width)=split(/\//,$i);
561 local($a,$b,$c,$d)=split(/\./,$ip);
562 local($ii)=($a<<24)+($b<<16)+($c<<8)+$d;
563
564 if ($width eq 32) {$nm=0xffffffff;}
565 else {$nm=0xffffffff-1<<(31-$width);}
566 $nw=($ii & $nm);
567 $br=$nw | (0xffffffff & ~$nm);
568 $netmask=itoadr($nm);;
569 $broadcast=itoadr($br);;
570 $network=itoadr($nw); # $i=itoadr($ii);
571
572# printf "ip=$ip|width=$width|nm=%0x|$netmask|br=%0x|$broadcast|$i|\n",$nm,$br;
573
574 return($ip,$netmask,$broadcast,$network,$width);
575}
576
577sub itoadr
578{
579 local($ip)=@_;
580 local($a,$b,$c,$d);
581 $a=($ip & 0xff000000) >> 24;
582 $b=($ip & 0x00ff0000) >> 16;
583 $c=($ip & 0x0000ff00) >> 8;
584 $d=($ip & 0x000000ff);
585 return("$a.$b.$c.$d");
586}
587
588sub changeline
589{
590 local($file,$old,$new)=@_;
591 open(OLD,$file) || die "Could not open old file: $file\n";
592 open(NEW,">$file.genesis.$$") || die "Could not create new file: $file.genesis.$$";
593 while(<OLD>)
594 {
595 if (/$old/) {print NEW "$new\n";}
596 else {print NEW $_;}
597 }
598 close(NEW);
599 close(OLD);
600 rename("$file.genesis.$$",$file) || die "Could not overwrite old file: $file";
601}
602
603
604sub open_files
605{
606 open (SH,">/etc/wireless.conf.sh"); # Voor firewall script.
607 open (NWCFG,">/etc/wl/nwcfg.sh"); # Voor network config
608 open (DHCP,">/etc/dhcpd.conf") || die "Could not create dhcpd.conf";
609 open (ZEBRA,">/etc/zebra/zebra.conf") || die "Could not create zebra.conf";
610 open (OSPFD,">/etc/zebra/ospfd.conf") || die "Could not create ospfd.conf";
611 open (MRTG,">/etc/mrtg/mrtg.cfg") || die "Could not create mrtg.cfg";
612 open (RCCONF,">/etc/rc.conf") || die "Could not create rc.conf";
613 open (FREEBSD,">/etc/rc.node.conf") || die "Could not create rc.node.conf";
614 open (RESOLV,">/etc/resolv.conf") || die "Could not create resolv.conf";
615 open (NAMED,">/etc/named.conf") || die "Could not create named.conf";
616}
617
618
619sub close_files
620{
621 close (SH);
622 close (NWCFG);
623 close (DHCP);
624 close (ZEBRA);
625 close (OSPFD);
626 close (MRTG);
627 close(RCCONF);
628 close(FREEBSD);
629 close(RESOLV);
630 close(NAMED);
631}
632
633sub print_files
634{
635 print SH $sh;
636 print NWCFG $nwcfg;
637 print DHCP $dhcp;
638 print ZEBRA $zebra;
639 print OSPFD $ospfd;
640 print MRTG $mrtg;
641 print RCFONG $rcconf;
642 print FREEBSD $freebsd;
643 print RESOLV $resolv;
644 print NAMED $named;
645}
646
647
648sub init_files
649{
650$sh=sprintf <<EOSH;
651#! /bin/bash
652#
653# Generated by $source
654# on $now
655#
656$svn_version
657
658
659gw_open=$gw_open
660EOSH
661
662$nwcfg=sprintf <<EONW;
663#! /bin/bash
664#
665# Generated by $source
666# on $now
667#
668# DO NOT CHANGE!
669#
670# $author
671# home: /etc/wl/nwcfg
672#
673$svn_version
674
675EONW
676
677
678$dhcp=sprintf <<EOD;
679# dhcpd.conf
680#
681# Generated by $source
682# on $now
683#
684# $author
685# home: /usr/local/etc/dhcpd.conf
686#
687$svn_version
688
689option domain-name "$domain";
690
691default-lease-time 7200;
692max-lease-time 2592000;
693
694ddns-update-style none;
695
696# Hack for the WET11
697#
698always-broadcast on;
699
700EOD
701#foreach $ns (split(/\s+/,$NS_forward))
702# {$dhcp.="option domain-name-servers ${ns};\n";}
703 {$dhcp.="option domain-name-servers ${master_ip};\n";}
704
705$dhcp.="\n\n";
706
707$zebra= sprintf <<EOZ;
708! -*- zebra -*-
709!
710! Zebra configuration for $hostname
711!
712! Generated by $source
713! on $now
714!
715! DO NOT CHANGE!
716!
717! $author
718! home=/usr/local/etc/zebra/zebra.conf
719!
720$svn_version
721
722hostname $hostname
723password getronics
724enable password getronics
725
726! Interfaces
727
728interface lo0
729 description loopback
730 ip address 127.0.0.1/8
731
732
733EOZ
734
735$ospfd=init_ospfd();
736
737$mrtg=sprintf <<EOM;
738
739#
740# mrtg configuration for $hostname
741#
742# Generated by $source
743# on $now
744#
745# DO NOT CHANGE!
746#
747# $author
748# home=/etc/mrtg
749#
750$svn_version
751
752Workdir: /var/www/html/mrtg
753
754
755#
756#
757#
758
759Target[${hostname}_load]: `/usr/local/sbin/cpuload.pl`
760MaxBytes[${hostname}_load]: 1000
761Title[${hostname}_load]: CPU load on $hostname
762PageTop[${hostname}_load]: <H1>CPU load on ${hostname}</H1>
763Options[${hostname}_load]: transparent, gauge, nopercent
764Legendi[${hostname}_load]: 5min
765Legendo[${hostname}_load]: 15min
766ShortLegend[${hostname}_load]: %
767YLegend[${hostname}_load]: %
768WithPeak[${hostname}_load]: wmy
769
770Target[${hostname}_mem]: `/usr/local/sbin/memusage.pl`
771MaxBytes[${hostname}_mem]: 256000000
772Title[${hostname}_mem]: Memory usage on ${hostname}
773PageTop[${hostname}_mem]: <H1>Memory usage on ${hostname}</H1>
774Options[${hostname}_mem]: transparent, gauge, nopercent
775Legendi[${hostname}_mem]: free
776Legendo[${hostname}_mem]: swap
777ShortLegend[${hostname}_mem]: Bytes
778YLegend[${hostname}_mem]: Bytes
779WithPeak[${hostname}_mem]: wmy
780
781Target[${hostname}_up]: `/usr/local/sbin/uptime.pl`
782MaxBytes[${hostname}_up]: 10000
783Title[${hostname}_up]: ${hostname} Uptime
784PageTop[${hostname}_up]: <H1>${hostname} Uptime</H1>
785Options[${hostname}_up]: transparent, gauge, nopercent
786Legendi[${hostname}_up]: uptime
787Legendo[${hostname}_up]:
788ShortLegend[${hostname}_up]: Days
789YLegend[${hostname}_up]: Days
790WithPeak[${hostname}_up]: wmy
791
792EOM
793
794$rcconf.=sprintf <<EORC1;
795# This file is read by /etc/rc.conf - and specific to wireless
796# leiden. Please make all changes in Genesis.
797#
798# Generated by $source
799# on $now
800#
801# $author
802#
803$svn_version
804
805hostname="$hostname.wLeiden.NET"
806location="$location"
807
808#ifconfig_lo0_alias0="inet $master_ip/32"
809EORC1
810
811#$freebsd.=sprintf <<EOFB1;
812# Wireless Leiden startup script om wireless kaarten te initialiseren
813#
814# Generated by $source
815# on $now
816#
817# $author
818# home=/etc/wl/freebsd.sh
819#
820#$svn_version
821#EOFB1
822
823$resolv.=sprintf <<EOR1;
824search wleiden.net .
825
826# Local machine / own nameserver.
827nameserver 127.0.0.1
828EOR1
829
830#foreach $ns (split(/\s+/,$NS_resolv)) {
831# $resolv.="nameserver $ns\n";
832#}
833
834foreach $if (sort keys %config) {
835 foreach $ns (split(/[\s$separator]+/,$OSPF_NEIGHBORS{$if})) {
836 next unless $ns =~ m/\d+/;
837 $resolv.="# Nameserver on adjacent node - $DESC{$if} over $if\nnameserver $ns\n\n";
838 };
839};
840
841
842
843$named.=sprintf <<EON1;
844# named.conf
845#
846# Generated by $source
847# on $now
848#
849# $author
850# home=/etc/namedb/named.conf
851#
852$svn_version
853
854options {
855 directory "/var/db/namedb";
856 forward only;
857 forwarders {
858 172.31.255.1; // Proxy.Demon.wLeiden.NET
859 172.18.8.66; // Internet GW Jasper
860// 172.17.32.66; // Internet GW Dirkx
861EON1
862
863%x=();
864foreach $ns (split(/\s+/,$NS_forward)) {
865 next if $ns eq $master_ip;
866 $named.=" ${ns};\n";
867 $x{ $ns } = 1;
868 }
869
870foreach $if (sort keys %config) {
871 foreach $ns (split(/[\s$separator]+/,$OSPF_NEIGHBORS{$if})) {
872 next unless $ns =~ m/\d+/;
873 $x{ $ns } = 0;
874 };
875};
876
877#foreach(sort keys(%x)) {
878# next if $x{$_};
879# $named.="// $_; // Next door Neighbour..\n";
880# }
881
882$named.=sprintf <<EON2;
883 };
884};
885
886zone "." {
887 type hint;
888 file "/etc/namedb/named.root";
889};
890
891zone "0.0.127.IN-ADDR.ARPA" {
892 type master;
893 file "/etc/namedb/localhost.rev";
894};
895
896zone "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" {
897 type master;
898 file "/etc/namedb/localhost-v6.rev";
899};
900
901EON2
902
903push (@ZONES,"wLeiden.NET");
904for ($i=16;$i<32;$i++) {push(@ZONES,"$i.172.in-addr.arpa");}
905foreach $zone (@ZONES)
906{
907 $named.=sprintf<<EON3;
908zone "$zone" {
909 type slave;
910 file "slave-$zone";
911 masters { 172.18.8.66; 212.61.66.38;};
912};
913
914EON3
915}
916
917
918$snmpd=<<EOM;
919# /usr/local/share/snmp/snmpd.local.conf
920# overwrites/augments the data in snmpd.conf
921# which is identical on each node with data
922# specific to this node.
923#
924mibs +LIGHT80211-MIB
925EOM
926
927$snmpd .= qq|
928# Location of the physical node.
929#
930syslocation "$location"
931
932| if defined $location;
933
934$snmpd .= qq|
935# Location of the physical node.
936#
937syscontact "$contact"
938
939| if defined $contact;
940
941$snmpd .=
942 "# Verify that disk is RO\n".
943 "sh diskro /usr/local/sbin/diskro.sh\n\n"
944 if ($DISK eq 'FLASH');
945
946$snmpd.=<<EOM;
947
948# Also listen to tcp
949agentaddress 161,tcp:161
950
951
952# end of file
953EOM
954}
955
956
957
958sub init_ospfd
959{
960
961 local($init)=sprintf <<EOO;
962! -*- ospfd -*-
963!
964! osfpd configuration for $hostname
965!
966! Configuration generated by $source
967! on $now
968!
969! DO NOT CHANGE!
970!
971! $author
972! home=/usr/local/etc/zebra/ospfd.conf
973!
974$svn_version
975
976hostname $hostname
977password getronics
978enable password getronics
979
980interface lo0
981EOO
982 return($init);
983}
984
985
986sub mrtg1
987{
988$mrtg.=sprintf <<EOM2;
989Target[${if}_traf]: `/usr/local/sbin/ipchains_traf.pl ${if}`
990MaxBytes[${if}_traf]: $SPEED{$if}
991Title[${if}_traf]: Traffic Analysis ${if} $SDESC{$if}
992PageTop[${if}_traf]: <H1>Traffic on $if $DESC{$if}</H1>
993Options[${if}_traf]: transparent
994WithPeak[${if}_traf]: wmy
995
996EOM2
997
998if ($functions_only<1)
999{
1000 ipchains("-N ${if}-i");
1001 ipchains("-N ${if}-o");
1002 ipchains("-I input -i ${if} -j ${if}-i");
1003 ipchains("-I output -i ${if} -j ${if}-o");
1004
1005}
1006 if ($TYPE{$if}=~/wireless/i)
1007 {
1008 $mrtg.=sprintf <<EOM3;
1009Target[${if}_quality]: `/usr/local/sbin/wlan_quality.pl ${if}`
1010MaxBytes1[${if}_quality]: 100
1011MaxBytes2[${if}_quality]: 100
1012Title[${if}_quality]: Quality $if $SDESC{$if}
1013PageTop[${if}_quality]: <H1>Quality $if $DESC{$if}</H1>
1014Options[${if}_quality]: transparent, gauge, nopercent
1015Legendi[${if}_quality]: Quality
1016Legendo[${if}_quality]: Noise
1017ShortLegend[${if}_quality]: /100
1018YLegend[${if}_quality]: /100
1019WithPeak[${if}_quality]: wmy
1020
1021Target[${if}_rate]: `/usr/local/sbin/wlan_bitrate.pl ${if}`
1022MaxBytes1[${if}_rate]: 11
1023MaxBytes2[${if}_rate]: 11
1024Title[${if}_rate]: Bitrate $if $SDESC{$if}
1025PageTop[${if}_rate]: <H1>Bitrate $if $DESC{$if}</H1>
1026Options[${if}_rate]: transparent, gauge, nopercent
1027Legendi[${if}_rate]: Bitrate
1028ShortLegend[${if}_rate]: Mb/s
1029YLegend[${if}_rate]: Mb/s
1030WithPeak[${if}_rate]: wmy
1031
1032EOM3
1033 if ($MODE{$if}=~/master/i)
1034 {
1035 $mrtg.=sprintf <<EOM4;
1036Target[${if}_users]: `/usr/local/sbin/wlan_users.pl ${if}`
1037MaxBytes[${if}_users]: 100
1038Title[${if}_users]: Users on $if $SDESC{$if}
1039PageTop[${if}_users]: <H1>Users on $if $DESC{$if}</H1>
1040Options[${if}_users]: transparent, gauge, nopercent
1041Legendi[${if}_users]: Users
1042ShortLegend[${if}_users]: users
1043YLegend[${if}_users]: users
1044WithPeak[${if}_users]: wmy
1045
1046EOM4
1047 }
1048 } # wireless
1049
1050
1051}
1052
1053sub mrtg2
1054{
1055$mrtg.=sprintf <<EOM5;
1056Target[${if}_lat]: `/usr/local/sbin/latency.pl $p`
1057MaxBytes1[${if}_lat]: 100
1058MaxBytes2[${if}_lat]: 200
1059Title[${if}_lat]: Latency/PktLoss Analysis to $p on $if $SDESC{$if}
1060PageTop[${if}_lat]: <H1>Latency/PktLoss to $p on $if $DESC{$if}</H1>
1061Options[${if}_lat]: transparent, gauge, nopercent
1062Legendi[${if}_lat]: PacketLoss%
1063Legendo[${if}_lat]: Max Latency (ms)
1064ShortLegend[${if}_lat]: %/ms
1065YLegend[${if}_lat]: %/ms
1066WithPeak[${if}_lat]: wmy
1067
1068EOM5
1069
1070}
1071
1072sub ahum
1073{
1074 print "AHUM!\n";
1075}
1076
1077#return(1);
1078
Note: See TracBrowser for help on using the repository browser.