App-pepper

 view release on metacpan or  search on metacpan

lib/App/pepper.pm  view on Meta::CPAN

    exit;
}

my $handlers = {
    'timeout'        => \&handle_timeout,
    'ssl'            => \&handle_ssl,
    'host'            => \&handle_host,
    'port'            => \&handle_port,
    'credentials'    => \&handle_credentials,
    'id'            => \&handle_id,
    'pw'            => \&handle_pw,
    'newpw'            => \&handle_newpw,
    'connect'        => \&handle_connect,
    'login'            => \&handle_login,
    'logout'        => \&handle_logout,
    'hello'            => \&handle_hello,
    'check'            => \&handle_check,
    'info'            => \&handle_info,
    'poll'            => \&handle_poll,
    'help'            => \&handle_help,
    'send'            => \&handle_send,
    'BEGIN'            => \&handle_begin,
    'exit'            => \&handle_exit,
    'transfer'        => \&handle_transfer,
    'clone'            => \&handle_clone,
    'delete'        => \&handle_delete,
    'renew'            => \&handle_renew,
    'create'        => \&handle_create,
    'edit'            => \&handle_edit,
    'cert'            => \&handle_cert,
    'key'            => \&handle_key,
    'restore'        => \&handle_restore,
    'update'        => \&handle_update,
};

our $term;
$term = Term::ReadLine->new('pepper') if (-t STDIN && -t STDOUT);

my $outfh = ($term ? \*STDOUT : \*STDERR);

my $prompt = 'pepper> ';

my $histfile = $ENV{'HOME'}.'/.pepper_history';

my $xml = XML::LibXML->new;

if ($term) {
    $term->ReadHistory($histfile) if ('Term::ReadLine::Gnu' eq $term->ReadLine);

    note('Welcome to pepper!');

    note(color('yellow').'> For best results, install Term::ReadLine::Gnu <'.color('reset')) if ($term && 'Term::ReadLine::Gnu' ne $term->ReadLine);
}

my $epp = App::pepper::EPPClient->new(
    'host'                => '',
    'connect'            => undef,
    'debug'                => $opt->{'debug'},
    'login'                => undef,
    'reconnect'            => 0,
    'verify'            => ($opt->{'insecure'} ? undef : 1),
    'ca_file'            => Mozilla::CA::SSL_ca_file(),
    'lang'                => ($opt->{'lang'} ? $opt->{'lang'} : 'en'),
    'appname'           => sprintf('Pepper %s', $VERSION),
    'login_security'    => $opt->{'login-security'},
);

execute_command('ssl off')                                                if ($opt->{'nossl'});
execute_command(sprintf('timeout %d',    $opt->{'timeout'}))                if ($opt->{'timeout'});
execute_command(sprintf('port %d',    $   opt->{'port'}))                    if ($opt->{'port'});
execute_command(sprintf('host "%s"',    quotemeta($opt->{'host'})))        if ($opt->{'host'});
execute_command(sprintf('id "%s"',        quotemeta($opt->{'user'})))        if ($opt->{'user'});
execute_command(sprintf('pw "%s"',        quotemeta($opt->{'pass'})))        if ($opt->{'pass'});
execute_command(sprintf('newpw "%s"',    quotemeta($opt->{'newpw'})))    if ($opt->{'newpw'});
execute_command(sprintf('cert "%s"',    quotemeta($opt->{'cert'})))        if ($opt->{'cert'});
execute_command(sprintf('key "%s"',        quotemeta($opt->{'key'})))        if ($opt->{'key'});

if ($epp->{'user'} ne '' && $epp->{'pass'} ne '') {
    execute_command('login');

} elsif ($epp->{'host'} ne '') {
    execute_command('connect');

}

if ($opt->{'exec'}) {
    execute_command($opt->{'exec'});
    handle_exit();

} elsif ($term) {
    note("Entering interactive mode, exit with Ctrl-D, Ctrl-C or 'exit'");

} else {
    note("Entering batch mode");

}

#
# main loop
#
my $last;
while (1) {
    $prompt = sprintf('pepper (%s@%s)> ', $epp->{'user'}, $epp->{'host'}) if ($epp->authenticated);

    my $command;
    if ($term) {
        $command = $term->readline($prompt);

    } else {
        $command = <STDIN>;
        chomp($command);

        # remove any trailing comment
        $command =~ s/\#.*//g;
    }

    if (!defined($command)) {
        last;

    } elsif ($command ne '') {
        if ($term && $command eq '!!') {



( run in 3.307 seconds using v1.01-cache-2.11-cpan-e1769b4cff6 )