IPTables-IPv4-DBTarpit
view release on metacpan or search on metacpan
lib/IPTables/IPv4/DBTarpit/Inst.pm view on Meta::CPAN
append as " write" or " read".
=cut
sub cpfromto {
my($from,$to) = @_;
my $failed = '';
if ( -e $from && open(R,$from)) {
if (open(W,'>'.$to)) {
while(<R>) {
print W $_;
}
close R;
close W;
} else {
close R;
$failed = $to . ' write';
}
} else {
$failed = $from . ' read';
}
return $failed;
}
=item * $rv = write_conf($file,$hashref,$prefix);
Writes the contents of $hashref to $file. Returns false on success, else
an error string describing the problem is returned. If $prefix is present
then any "key" written must start with $prefix".
i.e. Takes a hash ref of the form below and writes a file.
$hashref = {
VALUE1 => 'something',
VALUE2 => 'something else',
};
results are in a file that looks like:
# [file name] date & time
# This file was automatically generated by [caller file name]
#
# Don't edit this file, edit [caller file name] instead.
#
my $CONFIG = {
VALUE1 => 'something',
VALUE2 => 'something else',
};
$CONFIG;
=cut
sub write_conf {
my($file,$hp,$pre) = @_;
return "argument 2 is not a hash reference" unless ref $hp;
my $W = local *W;
return "could not open $file for write"
unless open($W,'>'.$file);
$file =~ m|([^/]+)$|;
my $whoami = (caller)[1];
print $W qq|# $1 |, scalar localtime(), q|
#
# This configuration file was automatically generated by '|. $whoami .q|'
#
# Don't edit this file, edit '|. $whoami .q|' instead.
#
my $CONFIG = {
|;
foreach(sort keys %$hp) {
next if $pre && $_ !~ /^$pre/;
print $W qq|\t'$_'\t=> '|. $hp->{$_},"',\n";
}
print $W "};\n";
close $W;
0;
}
=item * dialog($name,$CONFIG,@defaults);
Updates %$CONFIG by engaging in a dialog with the user about module $name
(only used a prompt). The user is asked to confirm
or enter a new value for the @default array.
input: $name, text string
$CONFIG, hash ref
@defaults
$CONFIG = {
VALUE1 => 'something',
VALUE2 => 'something else',
};
@defaults = (
# key
'VALUE1', 'new thing', 'prompt for new',
'VALUEA', 'new A', 'prompt for A',
}
returns: nothing
VALUE1 is overwritten and the user prompted for new. VALUE2 is left
untouched, VALUEA is prompted for A. %$CONFIG is updated.
For SpamCannibal users, warns if SPMCNBL_DAEMON_DIR and DBTP_DAEMON_DIR are
not the same.
=cut
my @errmsg = (
'The directories for daemon installation of',
'The database environment for installation of',
'The primary database names for installation of',
'The secondary database names for installation of',
);
my @spam_parms = qw(
SPMCNBL_DAEMON_DIR
SPMCNBL_ENVIRONMENT
SPMCNBL_DB_TARPIT
SPMCNBL_DB_ARCHIVE
);
( run in 2.166 seconds using v1.01-cache-2.11-cpan-e93a5daba3e )