source: genesis/tools/wleiden.pl@ 1095

Last change on this file since 1095 was 1095, checked in by jasper, 21 years ago

snmpd ook via tcp

  • Property svn:executable set to *
File size: 23.3 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 ($c 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
696EOD
697#foreach $ns (split(/\s+/,$NS_forward))
698# {$dhcp.="option domain-name-servers ${ns};\n";}
699 {$dhcp.="option domain-name-servers ${master_ip};\n";}
700
701$dhcp.="\n\n";
702
703$zebra= sprintf <<EOZ;
704! -*- zebra -*-
705!
706! Zebra configuration for $hostname
707!
708! Generated by $source
709! on $now
710!
711! DO NOT CHANGE!
712!
713! $author
714! home=/usr/local/etc/zebra/zebra.conf
715!
716$svn_version
717
718hostname $hostname
719password getronics
720enable password getronics
721
722! Interfaces
723
724interface lo0
725 description loopback
726 ip address 127.0.0.1/8
727
728
729EOZ
730
731$ospfd=init_ospfd();
732
733$mrtg=sprintf <<EOM;
734
735#
736# mrtg configuration for $hostname
737#
738# Generated by $source
739# on $now
740#
741# DO NOT CHANGE!
742#
743# $author
744# home=/etc/mrtg
745#
746$svn_version
747
748Workdir: /var/www/html/mrtg
749
750
751#
752#
753#
754
755Target[${hostname}_load]: `/usr/local/sbin/cpuload.pl`
756MaxBytes[${hostname}_load]: 1000
757Title[${hostname}_load]: CPU load on $hostname
758PageTop[${hostname}_load]: <H1>CPU load on ${hostname}</H1>
759Options[${hostname}_load]: transparent, gauge, nopercent
760Legendi[${hostname}_load]: 5min
761Legendo[${hostname}_load]: 15min
762ShortLegend[${hostname}_load]: %
763YLegend[${hostname}_load]: %
764WithPeak[${hostname}_load]: wmy
765
766Target[${hostname}_mem]: `/usr/local/sbin/memusage.pl`
767MaxBytes[${hostname}_mem]: 256000000
768Title[${hostname}_mem]: Memory usage on ${hostname}
769PageTop[${hostname}_mem]: <H1>Memory usage on ${hostname}</H1>
770Options[${hostname}_mem]: transparent, gauge, nopercent
771Legendi[${hostname}_mem]: free
772Legendo[${hostname}_mem]: swap
773ShortLegend[${hostname}_mem]: Bytes
774YLegend[${hostname}_mem]: Bytes
775WithPeak[${hostname}_mem]: wmy
776
777Target[${hostname}_up]: `/usr/local/sbin/uptime.pl`
778MaxBytes[${hostname}_up]: 10000
779Title[${hostname}_up]: ${hostname} Uptime
780PageTop[${hostname}_up]: <H1>${hostname} Uptime</H1>
781Options[${hostname}_up]: transparent, gauge, nopercent
782Legendi[${hostname}_up]: uptime
783Legendo[${hostname}_up]:
784ShortLegend[${hostname}_up]: Days
785YLegend[${hostname}_up]: Days
786WithPeak[${hostname}_up]: wmy
787
788EOM
789
790$rcconf.=sprintf <<EORC1;
791# This file is read by /etc/rc.conf - and specific to wireless
792# leiden. Please make all changes in Genesis.
793#
794# Generated by $source
795# on $now
796#
797# $author
798#
799$svn_version
800
801hostname="$hostname.wLeiden.NET"
802location="$location"
803
804#ifconfig_lo0_alias0="inet $master_ip/32"
805EORC1
806
807#$freebsd.=sprintf <<EOFB1;
808# Wireless Leiden startup script om wireless kaarten te initialiseren
809#
810# Generated by $source
811# on $now
812#
813# $author
814# home=/etc/wl/freebsd.sh
815#
816#$svn_version
817#EOFB1
818
819$resolv.=sprintf <<EOR1;
820search wleiden.net .
821
822# Local machine / own nameserver.
823nameserver 127.0.0.1
824EOR1
825
826#foreach $ns (split(/\s+/,$NS_resolv)) {
827# $resolv.="nameserver $ns\n";
828#}
829
830foreach $if (sort keys %config) {
831 foreach $ns (split(/[\s$separator]+/,$OSPF_NEIGHBORS{$if})) {
832 next unless $ns =~ m/\d+/;
833 $resolv.="# Nameserver on adjacent node - $DESC{$if} over $if\nnameserver $ns\n\n";
834 };
835};
836
837
838
839$named.=sprintf <<EON1;
840# named.conf
841#
842# Generated by $source
843# on $now
844#
845# $author
846# home=/etc/namedb/named.conf
847#
848$svn_version
849
850options {
851 directory "/var/db/namedb";
852 forward only;
853 forwarders {
854 172.31.255.1; // Proxy.Demon.wLeiden.NET
855 172.18.8.66; // Internet GW Jasper
856// 172.17.32.66; // Internet GW Dirkx
857EON1
858
859%x=();
860foreach $ns (split(/\s+/,$NS_forward)) {
861 next if $ns eq $master_ip;
862 $named.=" ${ns};\n";
863 $x{ $ns } = 1;
864 }
865
866foreach $if (sort keys %config) {
867 foreach $ns (split(/[\s$separator]+/,$OSPF_NEIGHBORS{$if})) {
868 next unless $ns =~ m/\d+/;
869 $x{ $ns } = 0;
870 };
871};
872
873#foreach(sort keys(%x)) {
874# next if $x{$_};
875# $named.="// $_; // Next door Neighbour..\n";
876# }
877
878$named.=sprintf <<EON2;
879 };
880};
881
882zone "." {
883 type hint;
884 file "/etc/namedb/named.root";
885};
886
887zone "0.0.127.IN-ADDR.ARPA" {
888 type master;
889 file "/etc/namedb/localhost.rev";
890};
891
892zone "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" {
893 type master;
894 file "/etc/namedb/localhost-v6.rev";
895};
896
897EON2
898
899push (@ZONES,"wLeiden.NET");
900for ($i=16;$i<32;$i++) {push(@ZONES,"$i.172.in-addr.arpa");}
901foreach $zone (@ZONES)
902{
903 $named.=sprintf<<EON3;
904zone "$zone" {
905 type slave;
906 file "slave-$zone";
907 masters { 172.18.8.66; 212.61.66.38;};
908};
909
910EON3
911}
912
913
914$snmpd=<<EOM;
915# /usr/local/share/snmp/snmpd.local.conf
916# overwrites/augments the data in snmpd.conf
917# which is identical on each node with data
918# specific to this node.
919#
920EOM
921
922$snmpd .= qq|
923# Location of the physical node.
924#
925syslocation "$location"
926
927| if defined $location;
928
929$snmpd .= qq|
930# Location of the physical node.
931#
932syscontact "$contact"
933
934| if defined $contact;
935
936$snmpd .=
937 "# Verify that disk is RO\n".
938 "sh diskro /usr/local/sbin/diskro.sh\n\n"
939 if ($DISK eq 'FLASH');
940
941$snmpd.=<<EOM;
942
943# Also listen to tcp
944agentaddress 161,tcp:161
945
946
947# end of file
948EOM
949}
950
951
952
953sub init_ospfd
954{
955
956 local($init)=sprintf <<EOO;
957! -*- ospfd -*-
958!
959! osfpd configuration for $hostname
960!
961! Configuration generated by $source
962! on $now
963!
964! DO NOT CHANGE!
965!
966! $author
967! home=/usr/local/etc/zebra/ospfd.conf
968!
969$svn_version
970
971hostname $hostname
972password getronics
973enable password getronics
974
975interface lo0
976EOO
977 return($init);
978}
979
980
981sub mrtg1
982{
983$mrtg.=sprintf <<EOM2;
984Target[${if}_traf]: `/usr/local/sbin/ipchains_traf.pl ${if}`
985MaxBytes[${if}_traf]: $SPEED{$if}
986Title[${if}_traf]: Traffic Analysis ${if} $SDESC{$if}
987PageTop[${if}_traf]: <H1>Traffic on $if $DESC{$if}</H1>
988Options[${if}_traf]: transparent
989WithPeak[${if}_traf]: wmy
990
991EOM2
992
993if ($functions_only<1)
994{
995 ipchains("-N ${if}-i");
996 ipchains("-N ${if}-o");
997 ipchains("-I input -i ${if} -j ${if}-i");
998 ipchains("-I output -i ${if} -j ${if}-o");
999
1000}
1001 if ($TYPE{$if}=~/wireless/i)
1002 {
1003 $mrtg.=sprintf <<EOM3;
1004Target[${if}_quality]: `/usr/local/sbin/wlan_quality.pl ${if}`
1005MaxBytes1[${if}_quality]: 100
1006MaxBytes2[${if}_quality]: 100
1007Title[${if}_quality]: Quality $if $SDESC{$if}
1008PageTop[${if}_quality]: <H1>Quality $if $DESC{$if}</H1>
1009Options[${if}_quality]: transparent, gauge, nopercent
1010Legendi[${if}_quality]: Quality
1011Legendo[${if}_quality]: Noise
1012ShortLegend[${if}_quality]: /100
1013YLegend[${if}_quality]: /100
1014WithPeak[${if}_quality]: wmy
1015
1016Target[${if}_rate]: `/usr/local/sbin/wlan_bitrate.pl ${if}`
1017MaxBytes1[${if}_rate]: 11
1018MaxBytes2[${if}_rate]: 11
1019Title[${if}_rate]: Bitrate $if $SDESC{$if}
1020PageTop[${if}_rate]: <H1>Bitrate $if $DESC{$if}</H1>
1021Options[${if}_rate]: transparent, gauge, nopercent
1022Legendi[${if}_rate]: Bitrate
1023ShortLegend[${if}_rate]: Mb/s
1024YLegend[${if}_rate]: Mb/s
1025WithPeak[${if}_rate]: wmy
1026
1027EOM3
1028 if ($MODE{$if}=~/master/i)
1029 {
1030 $mrtg.=sprintf <<EOM4;
1031Target[${if}_users]: `/usr/local/sbin/wlan_users.pl ${if}`
1032MaxBytes[${if}_users]: 100
1033Title[${if}_users]: Users on $if $SDESC{$if}
1034PageTop[${if}_users]: <H1>Users on $if $DESC{$if}</H1>
1035Options[${if}_users]: transparent, gauge, nopercent
1036Legendi[${if}_users]: Users
1037ShortLegend[${if}_users]: users
1038YLegend[${if}_users]: users
1039WithPeak[${if}_users]: wmy
1040
1041EOM4
1042 }
1043 } # wireless
1044
1045
1046}
1047
1048sub mrtg2
1049{
1050$mrtg.=sprintf <<EOM5;
1051Target[${if}_lat]: `/usr/local/sbin/latency.pl $p`
1052MaxBytes1[${if}_lat]: 100
1053MaxBytes2[${if}_lat]: 200
1054Title[${if}_lat]: Latency/PktLoss Analysis to $p on $if $SDESC{$if}
1055PageTop[${if}_lat]: <H1>Latency/PktLoss to $p on $if $DESC{$if}</H1>
1056Options[${if}_lat]: transparent, gauge, nopercent
1057Legendi[${if}_lat]: PacketLoss%
1058Legendo[${if}_lat]: Max Latency (ms)
1059ShortLegend[${if}_lat]: %/ms
1060YLegend[${if}_lat]: %/ms
1061WithPeak[${if}_lat]: wmy
1062
1063EOM5
1064
1065}
1066
1067sub ahum
1068{
1069 print "AHUM!\n";
1070}
1071
1072#return(1);
1073
Note: See TracBrowser for help on using the repository browser.