source: genesis/tools/FreeBSD6_x/wleiden.pl@ 5722

Last change on this file since 5722 was 5722, checked in by rick, 17 years ago

Made the genesis configuration machine independed and documented how-to
install it

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