source: genesis/tools/wleiden.pl@ 4095

Last change on this file since 4095 was 4091, checked in by rick, 20 years ago

Wrong named.conf forgot brackets

  • Property svn:executable set to *
File size: 7.8 KB
RevLine 
[4081]1#!/usr/bin/perl -w
[813]2#
3#
[4075]4# maart 2004 rick@wirelessleiden.nl
[813]5#
6
[4075]7my $debug=0;
8my $author="feb 2003 jasper\@WirelessLeiden.NL \| maart 2005 rick\@WirelessLeiden.NL";
9my $wicontrol='/usr/sbin/wicontrol';
[4087]10my $IP_pmPath='/home/genesis/tools/IP.pm';
11my $dnsheader_confPath='/home/genesis/dns/dnsheader.conf';
[826]12
[813]13
[4075]14#variablen
15my $time=gmtime();
[4084]16my $source=`/bin/hostname`;
[4075]17chomp($source);
[813]18
19
[4078]20#slurp IP berekeningen info
[4081]21do ("$IP_pmPath") || die ("Cann't open $IP_pmPath");
[4078]22#slurp dns info
[4081]23do ("$dnsheader_confPath") || die ("Cann't open $dnsheader_confPath");
[813]24
[4078]25
[4075]26#zoek uit of het master_ip addr voorkomt in de configs
27#belangrijk van aliassen
28sub master_ipNotUsed {
29 if( $debug ) {
30 print "running master_ipNotUsed...\n";
[813]31 }
[4075]32 foreach my $if (keys %config) {
33 if( $IP{$if} =~ /([0-9\.]+).*/ ) {
34 if( $1 eq $master_ip ) {
35 return(0);
36 };
37 };
38 };
39 return(1);
40};
[813]41
42
43
[4075]44sub genHeader {
45 my $comment = $_[0];
46 my $output =
47 "$comment This file specific to wireless\n" .
48 "$comment leiden. Please make all changes in Genesis.\n" .
49 "$comment\n" .
50 "$comment Generated by $source\n" .
51 "$comment on $time\n" .
52 "$comment\n" .
53 "$comment $author\n" .
54 "$comment\n\n\n";
55 return ($output);
56};
[813]57
58
[4075]59sub txtconfig {
[4081]60 my $output = "";
61 foreach $interface (keys %config) {
62 $output .= $config{$interface};
63 };
[4075]64 return($output);
65};
[813]66
67
[4075]68sub dhcpd_conf {
69 my $output = genHeader("#");
70 $output .=
[4084]71 "option domain-name \"wLeiden.NET\";\n" .
[4075]72 " \n" .
73 "default-lease-time 7200;\n" .
74 "max-lease-time 2592000;\n" .
75 "\n" .
76 "ddns-update-style none;\n" .
77 "\n" .
78 "# Hack for the WET11\n" .
79 "#\n" .
80 "always-broadcast on;\n" .
81 "\n" .
82 "option domain-name-servers ${master_ip};\n" .
83 "\n";
[813]84
[4075]85 foreach my $interface (sort keys %config) {
86 if( $interface =~ /^[a-z]+[0-9]+$/i ) {
87 (my $ip, my $netmask) = split('/', $IP{$interface});
88 my $subnet = IP::toSubnet($netmask);
89 my $broadcast = IP::getBroadcastAddr($ip, $subnet);
90 my $network = IP::getNetworkAddr($ip, $subnet);
91
92 $output .=
93 "# $interface $DESC{$interface}\n";
94
95 if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) {
96 my $dhcp_part = $ip;
97 $dhcp_part =~ s/[0-9]+$//;
98 (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i;
99 $dhcp_start = $dhcp_part . $dhcp_start;
100 $dhcp_stop = $dhcp_part . $dhcp_stop;
101 $output .=
102 "subnet $network netmask $subnet {\n" .
103 " range $dhcp_start $dhcp_stop;\n" .
104 " option broadcast-address $broadcast;\n" .
105 " option subnet-mask $subnet;\n" .
106 " option routers $ip;\n" .
107 "}\n" .
108 "\n";
[813]109 }
[4075]110 else {
111 $output .=
112 "subnet $network netmask $subnet {not authoritative; }\n" .
113 "\n";
114 };
115 };
116 };
117
118 return($output);
119};
[813]120
[4075]121sub named_conf {
122 my $output = genHeader("#");
123 $output .=
124 "options {\n" .
125 " directory \"/var/db/namedb\"\;\n" .
126 " forwarders {\n" .
[4091]127 " 172.17.8.68; // proxy1\n" .
128 " 172.17.143.4; // proxy2\n" .
129 " 172.20.128.98; // proxy3\n" .
130 " };\n" .
131 "};\n" .
[4075]132 "\n" .
133 "\n" .
134 "zone \"\.\" {\n" .
135 " type hint;\n" .
136 " file \"/etc/namedb/named.root\"\;\n" .
137 "}\;\n" .
138 "\n" .
139 "zone \"0\.0\.127\.IN-ADDR.ARPA\" {\n" .
140 " type master\;\n" .
141 " file \"/etc/namedb/localhost.rev\"\;\n" .
142 "}\;\n" .
143 "\n" .
144 "zone \"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\" {\n" .
145 " type master\;\n" .
146 " file \"/etc/namedb/localhost-v6.rev\"\;\n" .
147 "};\n" .
148 "\n";
[813]149
150
[4075]151 foreach my $tmpZone (sort keys %zone) {
152 my $dnsZone = $zone{$tmpZone};
153 $output .=
154 "zone \"$tmpZone\" {\n" .
155 " type slave\;\n" .
[4084]156 " file \"slave-$tmpZone\"\;\n" .
[4075]157 " masters {\n";
158 foreach my $tmpIP (sort @$dnsZone) {
159 $output .= " $tmpIP\;\n";
[3897]160 };
[4075]161 $output .=
162 " };\n" .
163 "};\n" .
164 "\n";
[3897]165 };
[4075]166
167 return($output);
[3897]168};
169
170
[813]171
[4089]172sub rc_node_local {
[4075]173 my $output = genHeader("#");
174 my $masterNotUsed = master_ipNotUsed();
175 $output.=
176 "hostname=\"$nodetype$nodename.wLeiden.NET\"\n" .
177 "location=\"$location\"\n" .
178 "\n";
[813]179
[4075]180 if( $tproxy ) {
181 if( $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/ ) {
182 $output .=
183 "# Tproxy is ran on this system\n".
184 "tproxy_enable='YES'\n".
185 "tproxy_range='$tproxy'\n".
186 "\n";
187 }
188 elsif( $tproxy !~ m/no/i ) {
189 $output .= "# WARNING - specification propably wrong - check " .
190 "genesis. It should be a pure CIDR\n";
191 };
192 };
193
194 $output .= "ifconfig_lo0_alias0=\"inet 172.31.255.1/32\"\n";
195 if( $masterNotUsed ) {
196 $output .= "ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
197 }
198 else {
199 $output .= "#ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
200 };
[813]201
[4075]202 foreach my $interface (sort keys %config) {
203 (my $if, my $number) = split(/:/, $interface);
204 if( defined $number ) {
[4084]205 $output .= "ifconfig_$if\_alias$number=\"inet $IP{$interface}\"\n";
[4075]206 }
207 else {
[4084]208 $output .= "ifconfig_$if=\"inet $IP{$interface}\"\n";
[4075]209 };
210 };
211 return($output);
[4024]212};
213
[4089]214sub rc_local {
[4075]215 my $output = genHeader("#");
216 foreach my $if (sort keys %config) {
217 if( ($if =~ /^wi[0-9]$/i) and ($TYPE{$if} =~ /wireless/i) ) {
218 $output .=
219 "$wicontrol -i $if -s $SDESC{$if} # Nickname\n" .
220 "#$wicontrol -i $if -t 7 # TXrate\n" .
221 "$wicontrol -i $if -P 0 # PowerSave\n" .
222 "$wicontrol -i $if -Z # Zero SNR cache\n";
223 if( $MODE{$if}=~/master/i ) {
224 $output .=
225 "$wicontrol -i $if -p 6 # hostap mode\n" .
226 "$wicontrol -i $if -c 1 # broadcasting essid on\n" .
227 "$wicontrol -i $if -n $ESSID{$if} # network name\n" .
228 "$wicontrol -i $if -q $ESSID{$if} # ESSID\n" .
229 "$wicontrol -i $if -f $CHANNEL{$if}# Channel\n";
230 }
231 else {
232 $output .=
233 "$wicontrol -i $if -p 1 # Client mode (managed)\n" .
234 "$wicontrol -i $if -n $ESSID{$if} # ESSID\n" .
235 "# No channel - client follows\n" .
236 "# $wicontrol -i $if -f 0 # Channel\n";
237 };
238 $output .= "\n";
239 };
240 };
241 return($output);
[906]242};
243
244
245
[4075]246sub resolv_conf {
247 my $output = genHeader"#";
[829]248
[4075]249 $output .=
250 "search wleiden.net.\n" .
251 "nameserver 127.0.0.1\n" .
252 "\n";
[813]253
[4075]254 foreach my $if (sort keys %config) {
255 if( exists $POINT_TO_POINT{$if} ) {
256 foreach my $ip ($POINT_TO_POINT{$if}) {
257 $output .= "nameserver $ip # $DESC{$if}\n";
258 };
259 };
260 };
261 return($output);
[813]262};
263
264
265
[4075]266sub snmpd_local_conf {
267 my $output = genHeader("#");
268 my $masterNotUsed = master_ipNotUsed();
269 $output .=
270 "# Location of the physical node.\n" .
271 "#\n" .
272 "syslocation \"$location\"\n" .
273 "#\n" .
274 "# Maintained by\n" .
275 "syscontact \"$contact\"\n" .
276 "\n";
[813]277
[4075]278 if( $DISK =~ /flash/i ) {
279 $output .= "# Verify that disk is RO\n";
280 $output .= "sh diskro /usr/local/sbin/diskro.sh\n\n";
281 };
[813]282
[4075]283 $output .= "agentaddress 161,tcp:161\n";
[813]284
[4075]285 if( $masterNotUsed ) {
286 $output .= "agentaddress $master_ip\n";
287 };
288
289 foreach my $if (keys %config) {
290 if( $IP{$if} =~ /([0-9\.]+).*/ ) {
291 $output .= "agentaddress $1\n";
292 };
293 };
294 return($output);
[813]295};
296
297
298
[4075]299sub parse_config {
[4081]300 my $workingfile = $_[0];
[4075]301 do($workingfile) || die("Cann't open/parse $workingfile");
[4081]302 foreach my $if (keys %config) {
303 my $cfg=$config{$if};
[4075]304 while ($cfg) {
305 $cfg=~s/^([^\n\r]+)[\r\n]*//m;
[4081]306 my $line=$1;
[4075]307 $line=~s/\s*#.*//;
[4081]308 if (((my $name, my $value)=split(/=/,$line)) eq 2) {
309 my $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\";$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}";
[4075]310 eval($doit);
311 };
312 $cfg=~s/[\r\n]*$//m;
313 };
[4046]314 };
315};
[1095]316
[4075]317sub do_it {
318 my $file = $_[0];
319 my $body = "";
[813]320
[4075]321 $file =~ s/\./_/g;
322 $body=&$file;
323 return($body);
324};
[813]325
[4081]326if( exists $ARGV[0] ) {
[4079]327 if( exists $ARGV[1] ) {
328 parse_config($ARGV[0]);
329 print do_it($ARGV[1]);
330 }
331 else {
332 print "Usage `perl wleiden.pl 'inputfile' 'outputfile'`\n";
333 };
[4075]334};
[4081]335
3361;
Note: See TracBrowser for help on using the repository browser.