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

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

Bind configuration is going to the next level

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