source: genesis/tools/wleiden.pl@ 824

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

SVN version numers added to tools/wleiden.pl

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