source: genesis/tools/wleiden.pl@ 905

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

svn revision info added to named.conf files.

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