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

Last change on this file since 7384 was 7384, checked in by ad, 15 years ago

delete all-server option in dnsmasq.conf

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