source: genesis/tools/wleiden.pl@ 919

Last change on this file since 919 was 906, checked in by jasper, 22 years ago

static routes aan ospfd.conf toegevoegd.

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