source: genesis/tools/wleiden.pl@ 4085

Last change on this file since 4085 was 4084, checked in by rick, 20 years ago

Bug config fixes

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