#!/usr/bin/perl -w use CDB_File; use warnings; use strict; # globals my $qd = "/var/qmail"; my $aliases = "/etc/aliases.cdb"; my $validsmtproutes = "/var/qmail/validsmtproutes"; my $cdboutput = "$qd/control/validrcptto.cdb"; my $vpopmailbin = "/home/vpopmail/bin"; my $live = 0; my %list; sub dop( $ ) { if( not $live ) { my $val = shift; print( $val . "\n" ); } } sub readin( $ ) { my $pathname = shift; if( not -f $pathname ) { die( "Cannot open: $pathname" ); } tie( my %h, 'CDB_File', $pathname ) or die( "I cannot tie $pathname" ); while( ( my $key, my $value ) = each( %h ) ) { $list{$key} = 1; } untie( %h ); } sub printfile { while( ( my $key, my $value ) = each( %list ) ) { dop( $key ); } } sub findfiles { opendir( D, $validsmtproutes ) or die( "I cannot open the directory $validsmtproutes" ); while( my $file = readdir( D ) ) { chomp( $file ); if( -d "$validsmtproutes/$file" ) { next; dop( $file . " is dir "); } next if( -d $file || $file eq "." || $file eq ".." ); readin( $validsmtproutes . "/" . $file ); } closedir( D ); } sub writefile { my $c = CDB_File->new( $cdboutput, "$cdboutput.tmp" ); while( ( my $key, my $value ) = each( %list ) ) { $c->insert( $key, "\0" ); } $c->finish; } findfiles; #printfile; writefile;