AOLserver-CtrlPort

 view release on metacpan or  search on metacpan

lib/AOLserver/CtrlPort.pm  view on Meta::CPAN


    ns_section "ns/server/${servername}/module/nscp/users"
        ns_param user "username:3G5/H31peci.o:"
                           # That's "username:password"

    ns_section "ns/server/${servername}/modules"
        ns_param nscp ${bindir}/nscp.so

This lets AOLserver enable the control port on server C<myhostname> on port
3334. Authentication is on, the username is C<username> and the
password is C<password> (hashed to C<3G5/H31peci.o> with a program
like C<htpasswd>).

=head2 METHODS

=over 4

=item AOLserver::CtrlPort-E<gt>new(...)

Creates a new control port client object. The following options
are available to the constructor:

=over 4

=item Port

The port AOLserver is listening to for control port commands.

=item Host

The control port C<address> as defined in the configuration.

=item Timeout

Number of seconds after which the client will time out if the
server doesn't send a response.

=item User

User name for control port login defaults to the empty string
for non-protected control ports.

=item Password

Password for control port login defaults to the empty string
for non-protected control ports.

=back

=cut

############################################################
sub new {
############################################################
    my ($class, @options) = @_;

    my %options = (
        Timeout         => 10,
        #Port            => '3456',
        Host            => 'localhost',
        Prompt          => '/> $/',
        User            => '',
        Password        => '',
        @options);

    my $user   = $options{User};
    my $passwd = $options{Password};

    delete $options{User};
    delete $options{Password};

    my $t = Net::Telnet->new(%options);

    DEBUG("Connecting to port=$options{Host}:$options{Port}");
    $t->open();

    my $self = { telnet => $t,
               };

    $t->login("", "");

    DEBUG("Waiting for prompt");
    $t->waitfor();

    bless $self, $class;
}

=item $conn->send_cmds("$cmd1\ncmd2\n...")

Send one or more commands, separated by newlines, AOLserver's
control port. The method will return the server's response as a string.
Typically, this will look like

    $out = $conn->send_cmds(<<EOT);
        info tclversion
        info commands
    EOT

and return the newline-separated response as a single string.

=cut

############################################################
sub send_cmds {
############################################################
    my ($self, $lines) = @_;

    my $output = "";
    my $line_output;

    for (split "\n", $lines) {
        DEBUG("Send: [$_]");
        $line_output = join "", $self->{telnet}->cmd("$_");
        # Last line is the prompt, scrap it
        $line_output =~ s/^.*\Z//m;
        DEBUG("Recv: [$line_output]");
        $output .= $line_output;
    }

    return $output;
}



( run in 0.658 second using v1.01-cache-2.11-cpan-e1769b4cff6 )