source: genesis/tools/iris/wleiden.pl@ 7382

Last change on this file since 7382 was 7382, checked in by huub, 15 years ago

dnsmasq.conf de bogus-priv optie eruit; resolv.conf alleen proxies als nameservers

  • Property svn:executable set to *
File size: 8.7 KB
Line 
1#!/usr/bin/perl -w
2#
3# Copyright 2005 Stichting Wireless Leiden
4# maart 2004 rick@wirelessleiden.nl
5#
6
7# Config located at other file
8my $conf_file="./genesis.conf";
9do($conf_file) || die("Cann't open $conf_file");
10################ END OF CONFIG ##########################
11
12#variablen
13my $time=gmtime();
14my $source=`/bin/hostname`;
15chomp($source);
16
17
18#slurp IP berekeningen info
19do ("$IP_pmPath") || die ("Cann't open $IP_pmPath");
20#slurp dns info
21do ("$dnsheader_confPath") || die ("Cann't open $dnsheader_confPath");
22
23
24#zoek uit of het master_ip addr voorkomt in de configs
25#belangrijk van aliassen
26sub master_ipNotUsed {
27 if( $debug ) {
28 print "running master_ipNotUsed...\n";
29 }
30 foreach my $if (keys %config) {
31 if( $IP{$if} =~ /([0-9\.]+).*/ ) {
32 if( $1 eq $master_ip ) {
33 return(0);
34 };
35 };
36 };
37 return(1);
38};
39
40
41
42sub genHeader {
43 my $comment = $_[0];
44 my $output =
45 "$comment This file specific to wireless\n" .
46 "$comment leiden. Please make all changes in Genesis.\n" .
47 "$comment\n" .
48 "$comment Generated by $source\n" .
49 "$comment on $time\n" .
50 "$comment\n" .
51 "$comment $author\n" .
52 "$comment\n\n\n";
53 return ($output);
54};
55
56
57sub txtconfig {
58 my $output = "";
59 foreach $interface (keys %config) {
60 $output .= $config{$interface};
61 };
62 return($output);
63};
64
65
66sub dnsmasq_conf {
67 my $output = genHeader("#");
68 $output .=
69 "# Query all upstream dns servers by default\n" .
70 "all-servers \n" .
71 "# DHCP server options \n" .
72 "dhcp-authoritative \n" .
73 "dhcp-fqdn \n" .
74 "domain=dhcp.$nodename.$domain. \n" .
75 "domain-needed \n" .
76 "expand-hosts \n" .
77 "\n" .
78 "# Low memory footprint \n" .
79 "cache-size=10000 \n" .
80 "\n";
81
82 foreach my $interface (sort keys %config) {
83 if( $interface =~ /^[a-z]+[0-9]+$/i ) {
84 (my $ip, my $netmask) = split('/', $IP{$interface});
85 my $subnet = IP::toSubnet($netmask);
86
87 $output .=
88 "## $interface $DESC{$interface}\n";
89
90 if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) {
91 my $dhcp_part = $ip;
92 $dhcp_part =~ s/[0-9]+$//;
93 (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i;
94 $dhcp_start = $dhcp_part . $dhcp_start;
95 $dhcp_stop = $dhcp_part . $dhcp_stop;
96 $output .= "dhcp-range=$interface,$dhcp_start,$dhcp_stop,$subnet,24h\n\n";
97 }
98 else {
99 $output .= "# not autoritive \n\n";
100 };
101 };
102 };
103
104 return($output);
105};
106
107
108sub dhcpd_conf {
109 my $output = genHeader("#");
110 $output .=
111 "option domain-name \"$domain\";\n" .
112 " \n" .
113 "default-lease-time 7200;\n" .
114 "max-lease-time 2592000;\n" .
115 "\n" .
116 "ddns-update-style none;\n" .
117 "\n" .
118 "# Hack for the WET11\n" .
119 "#\n" .
120 "always-broadcast on;\n" .
121 "\n" .
122 "option domain-name-servers ${master_ip};\n" .
123 "\n";
124
125 foreach my $interface (sort keys %config) {
126 if( $interface =~ /^[a-z]+[0-9]+$/i ) {
127 (my $ip, my $netmask) = split('/', $IP{$interface});
128 my $subnet = IP::toSubnet($netmask);
129 my $broadcast = IP::getBroadcastAddr($ip, $subnet);
130 my $network = IP::getNetworkAddr($ip, $subnet);
131
132 $output .=
133 "# $interface $DESC{$interface}\n";
134
135 if ( $DHCP{$interface} =~ /[0-9]+\-[0-9]+/i ) {
136 my $dhcp_part = $ip;
137 $dhcp_part =~ s/[0-9]+$//;
138 (my $dhcp_start, my $dhcp_stop) = $DHCP{$interface} =~ /([0-9]+)\-([0-9]+)/i;
139 $dhcp_start = $dhcp_part . $dhcp_start;
140 $dhcp_stop = $dhcp_part . $dhcp_stop;
141 $output .=
142 "subnet $network netmask $subnet {\n" .
143 " range $dhcp_start $dhcp_stop;\n" .
144 " option broadcast-address $broadcast;\n" .
145 " option subnet-mask $subnet;\n" .
146 " option routers $ip;\n" .
147 $DHCP_STATIC{$if} .
148 "}\n" .
149 "\n";
150 }
151 else {
152 $output .=
153 "subnet $network netmask $subnet {not authoritative; }\n" .
154 "\n";
155 };
156 };
157 };
158
159 return($output);
160};
161
162sub named_conf {
163 my $output = genHeader("#");
164 $output .=
165 "options {\n" .
166 " directory \"/etc/namedb\"\;\n" .
167 " pid-file \"/var/run/named/pid\"\;\n" .
168 " forwarders {\n";
169 foreach my $forward (@forwarder) {
170 $output .= "$forward;\n";
171 };
172 $output .=
173 " };\n" .
174 "};\n" .
175 "\n" .
176 "\n" .
177 "zone \"\.\" {\n" .
178 " type hint;\n" .
179 " file \"/etc/namedb/named.root\"\;\n" .
180 "}\;\n" .
181 "\n" .
182 "zone \"0\.0\.127\.IN-ADDR.ARPA\" {\n" .
183 " type master\;\n" .
184 " file \"/etc/namedb/master/localhost.rev\"\;\n" .
185 "}\;\n" .
186 "\n" .
187 "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" .
188 " type master\;\n" .
189 " file \"/etc/namedb/master/localhost-v6.rev\"\;\n" .
190 "};\n" .
191 "\n";
192
193
194 foreach my $tmpZone (sort keys %zone) {
195 my $dnsZone = $zone{$tmpZone};
196 $output .=
197 "zone \"$tmpZone\" {\n" .
198 " type slave\;\n" .
199 " file \"slave/slave-$tmpZone\"\;\n" .
200 " masters {\n";
201 foreach my $tmpIP (sort @$dnsZone) {
202 $output .= " $tmpIP\;\n";
203 };
204 $output .=
205 " };\n" .
206 "};\n" .
207 "\n";
208 };
209
210 return($output);
211};
212
213
214
215sub rc_node_local {
216 my $output = genHeader("#");
217 my $masterNotUsed = master_ipNotUsed();
218 $output.=
219 "hostname=\"$nodetype$nodename.$domain\"\n" .
220 "location=\"$location\"\n" .
221 "\n";
222
223 if( $tproxy ) {
224 if( $tproxy =~ m/\d+\.\d+\.\d+\.\d+\/\d+/ ) {
225 $output .=
226 "# Tproxy is ran on this system\n".
227 "tproxy_enable='YES'\n".
228 "tproxy_range='$tproxy'\n".
229 "\n";
230 }
231 elsif( $tproxy !~ m/no/i ) {
232 $output .= "# WARNING - specification propably wrong - check " .
233 "genesis. It should be a pure CIDR\n";
234 };
235 };
236
237 $output .= "ifconfig_lo0_alias0=\"inet 172.31.255.1/32\"\n";
238 if( $masterNotUsed ) {
239 $output .= "ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
240 }
241 else {
242 $output .= "#ifconfig_lo0_alias1=\"inet $master_ip/32\"\n\n";
243 };
244
245 foreach my $interface (sort keys %config) {
246 (my $if, my $number) = split(/:/, $interface);
247 if( defined $number ) {
248 $output .= "ifconfig_$if\_alias$number=\"inet $IP{$interface}\"\n";
249 }
250 else {
251 $output .= "ifconfig_$if=\"inet $IP{$interface}";
252 $output .= " $CARD_OPTION{$interface}";
253 if( $TYPE{$if} =~ /wireless/i ) {
254 $output .= " ssid $ESSID{$interface}";
255 if ( $SUBTYPE{$if} =~ /802.11a/i ) {
256 $output .= " mode 11a";
257 } elsif ( $SUBTYPE{$if} =~ /802.11g/i ) {
258 $output .= " mode 11g";
259 } else {
260 # Default output
261 $output .= " mode 11b";
262 }
263
264 if( $MODE{$if}=~/master/i ) {
265 $output .= " channel $CHANNEL{$interface}";
266 $output .= " mediaopt hostap";
267 }
268 else {
269 $output .= "";
270 };
271 };
272 $output .= "\"\n";
273 };
274 };
275 return($output);
276};
277
278
279sub resolv_conf {
280 my $output = genHeader"#";
281
282 $output .=
283 "search wleiden.net.\n" .
284 "# Try local (cache) first \n" .
285 "nameserver 127.0.0.1\n" .
286 "\n";
287
288 $output .=
289 "# proxies are also nameservers \n" .
290 "nameserver 172.17.8.68 # proxy1\n" .
291 "nameserver 172.17.143.4 # proxy2\n" .
292 "nameserver 172.20.128.98 # proxy3\n" .
293 "nameserver 172.16.2.254 # proxy4\n" .
294 "nameserver 172.19.168.66 # proxy5\n" .
295 "nameserver 172.16.3.146 # proxy6\n" .
296 "nameserver 172.17.16.66 # proxy62\n" .
297 "nameserver 172.22.0.66 # proxy_zwaluw\n";
298
299 return($output);
300};
301
302
303sub parse_config {
304 my $workingfile = $_[0];
305 do($workingfile) || die("Cann't open/parse $workingfile");
306 foreach my $if (keys %config) {
307 my $cfg=$config{$if};
308 while ($cfg) {
309 $cfg=~s/^([^\n\r]+)[\r\n]*//m;
310 my $line=$1;
311 $line=~s/\s*#.*//;
312 if (((my $name, my $value)=split(/=/,$line)) eq 2) {
313 my $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\";$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}";
314 eval($doit);
315 };
316 $cfg=~s/[\r\n]*$//m;
317 };
318 };
319};
320
321sub authorized_keys {
322 my $output = genHeader("#");
323 if( -e "$global_keyPath" ) {
324 open( GLOBAL, "$global_keyPath" ) || die ("Cann't open $global_keyPath");
325 $output .= join("", <GLOBAL>);
326 close( GLOBAL );
327 }
328 else {
329 $output .= "# No $global_keyPath\n";
330 };
331
332 if( -e "$ndir/$nodetype$nodename/$ssh_file" ) {
333 open( NODE, "$ndir/$nodetype$nodename/$ssh_file" ) || die ("Cann't open $home/$nodename/$ssh_file");
334 $output .= join("", <NODE>);
335 close( NODE );
336 }
337 else {
338 $output .= "# No $ndir/$nodetype$nodename/$ssh_file\n";
339 };
340
341 return($output);
342};
343
344sub do_it {
345 my $file = $_[0];
346 my $body = "";
347
348 $file =~ s/\./_/g;
349 $body=&$file;
350 return($body);
351};
352
353if( exists $ARGV[0] ) {
354 if( exists $ARGV[1] ) {
355 parse_config($ARGV[0]);
356 print do_it($ARGV[1]);
357 }
358 else {
359 print "Usage `perl wleiden.pl 'inputfile' 'outputfile'`\n";
360 };
361};
362
3631;
Note: See TracBrowser for help on using the repository browser.