~gokdeniz/netconfgen/trunk

« back to all changes in this revision

Viewing changes to netconfgen.pl

  • Committer: Gokdeniz Karadag
  • Date: 2012-12-29 01:49:21 UTC
  • Revision ID: gokdenizk@gmail.com-20121229014921-t5hh1w0ivxwu02s1
Modify the warning banner at the beginning of files

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
                }
139
139
 
140
140
                if ($state eq "hosts") {
141
 
                        # $_ =~ s/(.*)#.*/\1/;  # Remove commets
142
141
 
143
142
                        $numelems = (($CONFVER eq "2") ? 9 : 7);
144
143
                        @elements = split /\|/, $_, $numelems; # Split line into tokens
183
182
                        print_dns_v4_rev($host, $ipv4);
184
183
                        print_dns_v6_rev($host, $ipv6addr);
185
184
                        if ($CONFVER eq "2") {
186
 
                @fw4rules = parse_fw_rules($fw4str);
187
 
                @fw6rules = parse_fw_rules($fw6str);
188
 
                print_fw($FW4, $ipv4, $FW4_CMD, @fw4rules);
189
 
                print_fw($FW6, $ipv6, $FW6_CMD, @fw6rules);
190
 
            }
 
185
                                @fw4rules = parse_fw_rules($fw4str);
 
186
                                @fw6rules = parse_fw_rules($fw6str);
 
187
                                print_fw($FW4, $ipv4, $FW4_CMD, @fw4rules);
 
188
                                print_fw($FW6, $ipv6, $FW6_CMD, @fw6rules);
 
189
                        }
191
190
                }
192
191
 
193
192
        }
263
262
# the required output files
264
263
sub finish_setup() {
265
264
        my $fhandles;
 
265
        my $autowarn = "FILE AUTOMATICALLY GENERATED BY netconfgen. DO NOT EDIT!!!";
266
266
 
267
267
        &do_backup;
268
268
 
282
282
        open $DNSREV6, "> $OUTDIR/$DNS_v6_REV_FILENAME" or 
283
283
                        die "FATAL: Could not open $OUTDIR/$DNS_v6_REV_FILENAME for writing\n";
284
284
        push @fhandles, $DNSREV6;
285
 
    
286
 
    if ($CONFVER eq "2") {
287
 
        open $FW4, "> $OUTDIR/$FW_v4_FILENAME" or
288
 
                die "FATAL: Could not open $OUTDIR/$FW_v4_FILENAME for writing\n";
289
 
        push @fhandles, $FW4;
290
 
 
291
 
        open $FW6, "> $OUTDIR/$FW_v6_FILENAME" or
292
 
                die "FATAL: Could not open $OUTDIR/$FW_v6_FILENAME for writing\n";
293
 
        push @fhandles, $FW6;
294
 
    }
295
 
 
 
285
        
296
286
        foreach (@IPv4_REV_ZONES) {
297
287
                my ($zone,$fn) = split(/:/, $_);
298
288
                open $DNSREV4{$zone}, "> $OUTDIR/$fn" or
302
292
 
303
293
        # @fhandles now contains all DNS/Bind related filehandles we will ever
304
294
        # have open. So print a nice message to each file reminding the user
305
 
        # not to mess with the automaticly gernated file!
 
295
        # not to mess with the automatically generated file!
306
296
        foreach (@fhandles) {
307
 
                print $_ "; AUTOMATICLY GENERATED FILE -- DO NOT EDIT\n";
308
 
                print $_ "; I REALLY MEAN DO NOT EDIT!!\n";
 
297
                print $_ "; $autowarn\n";
309
298
        }
310
299
 
311
300
        foreach (@DHCP_REALMS) {
312
301
                my ($realm,$fn) = split(/:/, $_);
313
302
                open $DHCP_CONF{$realm},  "> $OUTDIR/$fn" or
314
 
                        die "FATAL: Could not open $OUTDIR/$fn  for writing\n";
 
303
                        die "FATAL: Could not open $OUTDIR/$fn for writing\n";
315
304
                my $tmpfh = $DHCP_CONF{$realm};
316
 
                print $tmpfh "# AUTOMATICLY GENERATED FILE -- DO NOT EDIT\n";
317
 
                print $tmpfh "# I REALLY MEAN DO NOT EDIT!!\n";
 
305
                print $tmpfh "# $autowarn\n";
318
306
                push @fhandles, $DHCP_CONF{$realm};
319
307
        }
 
308
 
 
309
        if ($CONFVER eq "2") {
 
310
                open $FW4, "> $OUTDIR/$FW_v4_FILENAME" or
 
311
                        die "FATAL: Could not open $OUTDIR/$FW_v4_FILENAME for writing\n";
 
312
                print $FW4 "# $autowarn\n";
 
313
                push @fhandles, $FW4;
 
314
 
 
315
                open $FW6, "> $OUTDIR/$FW_v6_FILENAME" or
 
316
                        die "FATAL: Could not open $OUTDIR/$FW_v6_FILENAME for writing\n";
 
317
                print $FW6 "# $autowarn\n";
 
318
                push @fhandles, $FW6;
 
319
        }
 
320
 
320
321
        return @fhandles;
321
322
}
322
323
 
389
390
                $revaddr = `ipv6calc --in ipv6addr $ipv6addr --out revnibbles.arpa`;
390
391
                chomp $revaddr;
391
392
                if ($revaddr =~ /^([a-fA-F0-9]\.){32}ip6.arpa.$/ ) {
392
 
                                # each 4 Bits of the address is 2 characters wide (nibble + dot)
393
 
                                # therefor: the number of nibbles we need is  (128-prefixlen)/4
394
 
                                # then multiply with two to account for the dot 
395
 
                                # then subtract 1 to get rid of the trailing dot.
396
 
                                $revaddr = substr($revaddr, 0, (128-$PREFIXLEN)/2-1); 
397
 
                                print $DNSREV6 "$revaddr\tIN PTR\t$host.$DOMAIN.\n";
 
393
                        # each 4 Bits of the address is 2 characters wide (nibble + dot)
 
394
                        # therefore: the number of nibbles we need is  (128-prefixlen)/4
 
395
                        # then multiply with two to account for the dot 
 
396
                        # then subtract 1 to get rid of the trailing dot.
 
397
                        $revaddr = substr($revaddr, 0, (128-$PREFIXLEN)/2-1); 
 
398
                        print $DNSREV6 "$revaddr\tIN PTR\t$host.$DOMAIN.\n";
398
399
                }
399
400
                else { # ipv6calc returned bogus data
400
401
                        print STDERR "ERROR: ipv6calc generated stupid results for host $host (reverse entry)\n";
451
452
        }
452
453
}
453
454
 
 
455
# vi: noexpandtab