Agent-TCLI

 view release on metacpan or  search on metacpan

bin/agent_tail.pl  view on Meta::CPAN


agent_tail - Run a TCLI Agent with the Tail package enabled.

=head1 SYNOPSIS

=over 12

=item B<agent_tail>

B<username>S<=>I<username>
B<password>S<=>I<password>
B<domain>S<=>I<domain>
[B<resource>S<=>I<resource>]
[B<host>S<=>I<XMPP server>]
[B<help>]
[B<man>]
[B<verbose>]

=back

=head1 OPTIONS AND ARGUMENTS

=over 8

=item B<username>

The XMPP user the Agent will log in as, without the domain.
Required unless the script has been edited to enable a default user.

=item B<password>

The password to be used by the Agent to log in to the XMPP server.
Required unless the script has been edited to enable a default password.

=item B<domain>

The XMPP domain of the user account of the Agent.
Required unless the script has been edited to enable a default domain.

=item B<resource>

The XMPP resource. Defaults to 'tcli' if not provided.

bin/agent_tail.pl  view on Meta::CPAN

and/or modify it under the same terms as Perl itself.

=cut

# Useful for debugging or just seeing what the Agent is doing.
sub VERBOSE () { 0 }

# Process optional parameters from the command line and assign defaults.
use Getopt::Lucid qw(:all);

my ($opt, $verbose,$domain,$username,$password,$resource,$host);

eval {$opt = Getopt::Lucid->getopt([
		Param("domain|d"),
		Param("username|u"),
		Param("password|p"),
		Param("resource|r"),
		Param("host"),
		Counter("verbose|v"),
		Switch("help"),
		Switch("man"),
	])};

if($@)
{
	print "ERROR: $@ \n";
	pod2usage(1);
}

pod2usage(1)  if ($opt->get_help);
pod2usage(VERBOSE => 2)  if ($opt->get_man);

$verbose = $opt->get_verbose ? $opt->get_verbose : VERBOSE;

# Optionally set default jabber/xmpp parameters to log in with
$username = $opt->get_username ? $opt->get_username : 'agent';
$password = $opt->get_password ? $opt->get_password : 'agent';
$resource = $opt->get_resource ? $opt->get_resource : 'tcli';
$domain = $opt->get_domain ? $opt->get_domain : 'example.com';
$host = $opt->get_host ? $opt->get_host : $domain;

# Error if options not set and not provided.
pod2usage(1) if ($username eq 'agent' or $domain eq 'example.com');

# Load required modules

use POE;						# POE is required for all Agents

bin/agent_tail.pl  view on Meta::CPAN

#	Agent::TCLI::User->new(
#		'id'		=> 'conference_room@conference'.$domain,
#		'protocol'	=> 'xmpp_groupchat',
#		'auth'		=> 'master',
#	),
);

Agent::TCLI::Transport::XMPP->new(
     'jid'		=> Net::XMPP::JID->new($username.'@'.$domain.'/'.$resource),
     'jserver'	=> $host,
	 'jpassword'=> $password,
	 'peers'	=> \@users,

	 'xmpp_process_time'=> 1,

     'verbose'    => \$verbose,        # Verbose sets level or warnings

     'control_options'	=> {
	     'packages' 		=> \@packages,
     },
);

lib/Agent/TCLI.pm  view on Meta::CPAN

modules easier by providing Base classes that offer much of the
needed functionality to support the standardized, easy to learn human
interface. The goal is to allow users to add new functionality without
having then spend a lot of time learning the particular syntax of a
new tool.

=head1 GETTING STARTED

The quickest way to start running an agent is to run the provided Tail Agent:

	tail_agent user=<user> password=<example> domain=<example.com>

One must fist have created a Jabber/XMPP account for the agent to log in to.
One can then log in with a Jabber client using the same user ID and password
and communicate with the Agent. The Agnet will be logged in using the
resource 'tcli'. Jabber clients vary in how to start a chat with onself
at a different resource, so please see your Jabber client documentation
for details.

=head1 COMPONENTS

The following modules make up the core of the TCLI system.

=head2 Agent::TCLI::Control

lib/Agent/TCLI/Package/XMPP.pm  view on Meta::CPAN

    - ASCII
  help: Protocol that user is allowed access on.
  manual: >
    Protocol that user is allowed access on. Currently only xmpp and
    xmpp-groupchat are supported by Transport::XMPP. If the protocol
    is xmpp-groupchat, the Transport will automatically join the
    conference room when the user is added.
  type: Param
---
Agent::TCLI::Parameter:
  name: password
  constraints:
    - ASCII
  help: A password for the user.
  manual: >
    A password for the user. For a private XMPP chatroom,
    this is used to log on. It is not used anywhere else currently.
  type: Param
---
Agent::TCLI::Command:
  call_style: session
  command: tcli_xmpp
  contexts:
    ROOT:
      - jabber
      - xmpp

lib/Agent/TCLI/Package/XMPP.pm  view on Meta::CPAN

  handler: peer
  help: 'add peers that the transport talks to'
  manual: >
    The peer command allows one to add or delete users from the list of
    peers that the Transport will communicate with. Currently this list of
    peers is not savable.
  name: peer-add
  parameters:
    auth:
    id:
    password:
    protocol:
  required:
    auth:
    id:
    protocol:
  topic: admin
  usage: xmpp peer add id=peer@example.com protocol=xmpp auth=master
---
Agent::TCLI::Command:
  call_style: session

lib/Agent/TCLI/Package/XMPP.pm  view on Meta::CPAN

    The delete command allows one to delete users from the list of
    peers that the Transport will communicate with. When the user is
    deleted, they will not be able to begin new sessions, but existing
    sessions may continue. The delete command will accept all the same
    parameters as the add command, although it ignores everything
    but the id.
  name: peer-delete
  parameters:
    auth:
    id:
    password:
    protocol:
  required:
    id:
  topic: admin
  usage: xmpp peer add id=peer@example.com protocol=xmpp auth=master
...

}

=item peer

lib/Agent/TCLI/Transport/Base.pm  view on Meta::CPAN


	my $txt = '';
	my ($code, $value);

	if ($attr eq 'peers')
	{
		# loop over the users
		foreach my $peer ( @{$self->peers} )
		{
			$txt .= "\nid: ".$peer->id."\nprotocol: ".$peer->protocol.
				"\nauth: ".$peer->auth."\npassword: ******\n";
			$code = 200;
		}
	}
	elsif ($attr eq 'controls')
	{
		# loop over the controls
		foreach my $control ( keys %{$self->controls} )
		{
			$txt .= "\nid: ".$control->id."\n";
			$code = 200;

lib/Agent/TCLI/Transport/XMPP.pm  view on Meta::CPAN

=cut
my @jid 	   :Field('All' => 'jid', 'Type' => 'Net::XMPP::JID' );

=item jserver

B<jserver> will only accept SCALAR type values.

=cut
my @jserver 	   :Field('All' => 'jserver' );

=item jpassword

The password for the transport to use to log in to the server.
B<jpassword> will only accept scalar type values.

=cut
my @jpassword  :Field('All' => 'jpassword');

=item xmpp_debug

Sets the debug (verbosity) level for the XMPP libraries

=cut
my @xmpp_debug			:Field  :All('xmpp_debug');

=item xmpp_process_time

lib/Agent/TCLI/Transport/XMPP.pm  view on Meta::CPAN

# Validate deep arguments
#    $self->Verbose("Validating arguments \n" ,1);
#	my %jabber_connection = validate ($args->{'jabber_connection'}, {
#        jabber_package	=> { regex => qr/^POE::Component::Jabber/,
#                            type => Params::Validate::SCALAR | Params::Validate::SCALARREF },
#		server			=> { type => Params::Validate::SCALAR | Params::Validate::SCALARREF },
#		port			=> { optional => 1, default => 5222,
#							callbacks =>
#							{ 'is a number' => sub {  Scalar::Utils->looks_like_a_number($_[0]) }
#							}},
#		password		=> 	{ type => Params::Validate::SCALAR | Params::Validate::SCALARREF },
#	});


}

=back

=head2 METHODS

=over

lib/Agent/TCLI/Transport/XMPP.pm  view on Meta::CPAN

    $xmpp->SetIQCallBacks(
		'tcli:request'	=> {
			'get'	=>	$session->postback('recv_iqRequest'),
		#	'set'	=>	function,
			'result'=>	$session->postback('recv_iqResponse'),
			},
	);

	$self->set(\@xmpp, $xmpp);

	$kernel->yield('Login') if (defined( $self->jpassword ));

	return ($self->alias."_start whohoo");
} # End sub start

=item stop

Mostly just a placeholder.

=cut

lib/Agent/TCLI/Transport/XMPP.pm  view on Meta::CPAN

			if ( defined( $self->controls ) &&
				exists( $self->controls->{ $user->id.'-groupchat' } ) )
			{
				# should already be logged on?
			    $self->Verbose("JoinPeerRooms: already connected to ".$user->id ,2);
				return;
			}
			$kernel->yield('JoinChatRoom',
				$user->get_name,		# room name
				$user->get_domain,		# server
				$user->password,		# secret
			)
		}
	}
}

sub JoinChatRoom {
	my ($kernel,  $self, $room, $server, $secret) =
	  @_[KERNEL, OBJECT,  ARG0,    ARG1,   	ARG2];
    $self->Verbose("JoinChatroom: $room at $server ",2);

    $self->xmpp->MUCJoin(
    	'room'		=> $room,
		'server'	=> $server,
		'nick'		=> $self->jid->GetUserID,
		'password'	=> defined($secret) ? $secret : undef,
	);
}

sub Login {
	my ($kernel,  $self, ) =
	  @_[KERNEL, OBJECT, ];

	my $txt = '';

	# make connection

lib/Agent/TCLI/Transport/XMPP.pm  view on Meta::CPAN

		hostname	=> $jserver[$$self],
	);

	my @login;
	if ( $xmpp[$$self]->Connected()  )
	{
		#log in
		$self->Verbose("login: XMPP trying login as ".$self->jid()->GetUserID );
		@login = $xmpp[$$self]->AuthSend(
			username	=> $self->jid()->GetUserID,
			password	=> $jpassword[$$self],
			resource	=> $self->jid()->GetResource,
		);
		$self->Verbose("login: Did login for ".$self->jid()->GetUserID." Got ".$login[0] );

		if ( defined($login[0]) && $login[0] eq 'ok')
		{
		    $kernel->yield('Online');
		}
		elsif ( defined($login[1]) )
		{

lib/Agent/TCLI/User.pm  view on Meta::CPAN


Note that commands must choose from the above to determine if a user can
do anything. Not very robust, but hey, it's not even 1.0 yet.

Every user should be defined with an B<auth>, but currently this is not
being checked anywhere.

=cut
my @auth 	:Field	:All('auth');

=item password

A password for the user.

For a private XMPP chatroom, this is used to log on. It is not used anywhere
else currently.

=cut
my @password		:Field
					:All('password');

# RemindHacker: I wrote a Eclipse Perl template csxattr for new attributes.

# Standard class utils are inherited

=back

=head2 METHODS

=head2 new (lots of stuff)

t/TCLI.Control.Interactive.t  view on Meta::CPAN

	])};
if($@) {die "ERROR: $@";}

if ($opt->get_blib)
{
	use lib 'blib/lib';
}

$verbose = $opt->get_verbose ? $opt->get_verbose : VERBOSE;

# xmpp username/password to log in with
$poe_td = $opt->get_poe_debug;
$poe_te = $opt->get_poe_event;

sub POE::Kernel::TRACE_DEFAULT  () { $poe_td }
sub POE::Kernel::TRACE_EVENTS  () { $poe_te }

use Agent::TCLI::Transport::Test;
use Agent::TCLI::Testee;
use POE;

t/TCLI.Control.t  view on Meta::CPAN

	])};
if($@) {die "ERROR: $@";}

if ($opt->get_blib)
{
	use lib 'blib/lib';
}

$verbose = $opt->get_verbose ? $opt->get_verbose : VERBOSE;

# xmpp username/password to log in with
$poe_td = $opt->get_poe_debug;
$poe_te = $opt->get_poe_event;

sub POE::Kernel::TRACE_DEFAULT  () { $poe_td }
sub POE::Kernel::TRACE_EVENTS  () { $poe_te }

use Agent::TCLI::Transport::Test;
use Agent::TCLI::Testee;
use POE;

t/TCLI.Package.XMPP.t  view on Meta::CPAN


use Test::More tests => 32;
use lib 'blib/lib';
use warnings;
use strict;

use Getopt::Lucid qw(:all);

sub VERBOSE () { 0 }

my ($opt, $verbose,$domain,$username,$password,$host, $poe_td, $poe_te);

eval {$opt = Getopt::Lucid->getopt([
		Param("domain"),
		Param("username|u"),
		Param("password|p"),
		Param("host"),
		Counter("poe_debug|d"),
		Counter("poe_event|e"),
		Counter("xmpp_debug|x"),
		Counter("verbose|v"),
	])};
if($@) {die "ERROR: $@";}

$verbose = $opt->get_verbose ? $opt->get_verbose : VERBOSE;

# xmpp username/password to log in with
$username = $opt->get_username ? $opt->get_username : 'testy1';
$password = $opt->get_password ? $opt->get_password : 'testy1';
$domain = $opt->get_domain ? $opt->get_domain : 'testing.erichacker.com';
$host = $opt->get_host ? $opt->get_host : 'testing.erichacker.com';
$poe_td = $opt->get_poe_debug;
$poe_te = $opt->get_poe_event;

sub POE::Kernel::TRACE_DEFAULT  () { $poe_td }
sub POE::Kernel::TRACE_EVENTS  () { $poe_te }

use Agent::TCLI::Transport::Test;
use Agent::TCLI::Testee;

t/TCLI.Package.XMPP.t  view on Meta::CPAN

#	Agent::TCLI::User->new(
#		'id'		=> 'testing@conference.jabber.erichacker.com',
#		'protocol'	=> 'xmpp_groupchat',
#		'auth'		=> 'master',
#	),
);

Agent::TCLI::Transport::XMPP->new(
     'jid'		=> Net::XMPP::JID->new($username.'@'.$domain.'/tcli'),
     'jserver'	=> $host,
#	 'jpassword'=> $password,
	 'peers'	=> \@users,

	 'xmpp_debug' 		=> 0,
	 'xmpp_process_time'=> 1,

     'verbose'    => \$verbose,        # Verbose sets level or warnings
	 'do_verbose'	=> sub { diag( @_ ) },

     'control_options'	=> {
	     'packages' 	=> \@packages,

t/TCLI.Package.XMPP.t  view on Meta::CPAN

$t->ok('xmpp change group_prefix $',"change group_prefix \$");
$t->like_body('xmpp show group_prefix',qr($), "show group_prefix \$");
$t->ok('xmpp change group_prefix :',"change group_prefix :");
$t->like_body('xmpp show group_prefix',qr(\:), "show group_prefix :");

$t->like_body('xmpp peer add id=testy10@testing.erichacker.com protocol=xmpp auth=master',qr(add testy10.testing.erichacker.com successful), "add peer user");
$t->like_body('xmpp show peers ',qr(^id: testy10.testing.erichacker.com$)m, "show peer users");

$t->like_body('xmpp peer add id=me@erichacker.com  auth=master',qr(Invalid Args: Required option 'protocol'), "add peer user no protocol");

$t->like_body('xmpp peer add id=testy11@testing.erichacker.com protocol=xmpp auth=master password=password',qr(add testy11.testing.erichacker.com successful), "add peer user with password");
$t->like_body('xmpp show peers ',qr(^id: testy11.testing.erichacker.com$)m, "show peer users");

$t->like_body('xmpp peer delete id=testy11@testing.erichacker.com',qr(delete testy11.testing.erichacker.com successful), "delete peer user");
$t->unlike_body('xmpp show peers ',qr(^id: testy11.testing.erichacker.com$)m, "show peer users delete");


# Need to shutdown or POE never stops.
$t->ok('xmpp shutdown');

$test_master->run;

t/TCLI.Transport.Test.t  view on Meta::CPAN

{
	use lib 'blib/lib';
}

print "opt->get_verbose(".$opt->get_verbose." )\n";

$verbose = $opt->get_verbose ? $opt->get_verbose  : 0;

print "verbose(".$verbose." )\n";

# xmpp username/password to log in with
$poe_td = $opt->get_poe_debug;
$poe_te = $opt->get_poe_event;

sub POE::Kernel::TRACE_DEFAULT  () { $poe_td }
sub POE::Kernel::TRACE_EVENTS  () { $poe_te }

use Agent::TCLI::Transport::Test;
use Agent::TCLI::Testee;
use POE;



( run in 0.550 second using v1.01-cache-2.11-cpan-49f99fa48dc )