source: genesis/config/iris/node/FreeBSD/8.0-RELEASE/wleiden.pl@ 8945

Last change on this file since 8945 was 8802, checked in by richardvm, 14 years ago

New file which prints all proxies in a variable (needed for lvrouted)

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