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

Last change on this file since 7123 was 7123, checked in by rick, 15 years ago

Initial setup off dnsmasq configuration

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