Agent-TCLI
view release on metacpan or search on metacpan
bin/agent_tail.pl view on Meta::CPAN
# active POE::Sessions
my $alias = 'agent.tail';
# Create new package objects to load for each package.
# Some packages may require extra parameters.
my @packages = (
Agent::TCLI::Package::XMPP->new(
'verbose' => \$verbose , # Optionally set verbosity for the package
# by using a reference, we can later
# change globally while running
),
Agent::TCLI::Package::Tail->new(
'verbose' => \$verbose ,
),
);
# Define the authorized users of the Agent.
my @users = (
# If the Tail agent is to be controlled by a test script, then the user the
lib/Agent/TCLI/Control.pm view on Meta::CPAN
# Universal in this context
elsif ( defined($c[3]) &&
defined($registered_commands[$$self]{$c[0]}{$c[1]}{'GROUP'}) &&
defined($registered_commands[$$self]{$c[0]}{$c[1]}{'GROUP'}{$c[3]})
)
{
$cmd =
$registered_commands[$$self]{$c[0]}{$c[1]}{'GROUP'}{$c[3]}{'.'};
$thisdepth = 3;
}
# $c[3] globally Universal
elsif ( defined($c[3]) &&
defined($registered_commands[$$self]{'UNIVERSAL'}{$c[3]} )
)
{
$cmd =
$registered_commands[$$self]{'UNIVERSAL'}{$c[3]}{'.'};
$thisdepth = 3;
}
elsif (
defined($registered_commands[$$self]{$c[0]}{$c[1]}{$c[2]}{'.'} )
lib/Agent/TCLI/Control.pm view on Meta::CPAN
# Universal in this context
elsif ( defined($c[2]) &&
defined($registered_commands[$$self]{$c[0]}{'GROUP'} ) &&
defined($registered_commands[$$self]{$c[0]}{'GROUP'}{$c[2]} )
)
{
$cmd =
$registered_commands[$$self]{$c[0]}{'GROUP'}{$c[2]}{'.'};
$thisdepth = 2;
}
# $c[2] globally Universal
elsif ( defined($c[2]) &&
defined($registered_commands[$$self]{'UNIVERSAL'}{$c[2]} )
)
{
$cmd =
$registered_commands[$$self]{'UNIVERSAL'}{$c[2]}{'.'};
$thisdepth = 2;
}
elsif ( defined($registered_commands[$$self]{$c[0]}{$c[1]}{'.'} )
)
lib/Agent/TCLI/Control.pm view on Meta::CPAN
# Need to eliminate aliases by checking something.....
$txt .= "\t".$cmd." - ".$cmds->{$cmd}->help." \n"
if ($cmds->{$cmd}->name =~ /$cmd/ ||
$cmds->{$cmd}->topic !~ /general/
);
}
}
($cmds, , ) = $self->ListCommands(['UNIVERSAL']);
if ( $code == 200 )
{
$txt .= "\nThe following global commands are available. \n";
foreach $cmd ( sort keys %{$cmds} )
{
$txt .= " ".$cmd." " unless ($cmds->{$cmd}->topic =~ /debug|admin/);
}
}
# Otherwise txt has error from first ListCommands
$request->Respond($kernel, $txt, $code );
return;
}
# Just the globals please
elsif( $request->args->[0] =~ /global/i )
{
($cmds, $txt, $code ) = $self->ListCommands(['UNIVERSAL']);
if ( $code == 200 )
{
$txt .= "\nThe following global commands are available. \n";
foreach $cmd ( sort keys %{$cmds} )
{
$txt .= "\t".$cmd." - ".$cmds->{$cmd}->help." \n";
}
}
# Otherwise txt has error from first ListCommands
$request->Respond($kernel, $txt, $code );
return;
}
# perhaps we want to ignore the current context
lib/Agent/TCLI/Control.pm view on Meta::CPAN
'command' => 'pre-loaded',
'contexts' => {'ROOT' => [ qw(Hi hi Hello hello)]},
'call_style'=> 'state',
'handler' => 'general'
),
'context' => Agent::TCLI::Command->new(
'name' => 'context',
'help' => "displays the current context",
'usage' => 'context or /context',
'manual' => "Context can be somewhat difficult to understand when one thinks of normal command line interfaces that often retain context differently. ".
"Context is a way of nesting commands, much like a file directory, to make it easier to navigate. There are a few commands, such as 'help' or 'exit' that are global, ".
"but most commands are available only within specific contexts. Well written packages will collect groups of similar commands within a context. ".
"For instance, if one had package of attack commands, one would put them all in an 'attack' context. Instead of typing 'attack one target=example.com', ".
"one could type 'attack' to change to the attack context then type 'one target=example.com' followed by 'two target=example.com' etc. \n\n".
"Furthermore, a well written package will support the setting of default parameters for use within a context. One can then say: \n ".
"\tattack \n\tset target=example.com \n\tone \n\ttwo \n\t...\n\n".
"The full command 'attack one target=example.com' must always be supported, but using context makes it easier to do repetitive tasks manually as well as ".
"allow one to navigate through a command syntax that one's forgotten the details of without too much trouble. \n\n".
"Context has a sense of depth, as in how many commands one has in front of whatever one is currently typing. ".
"An alias to the context command is 'pwd' which stands for Present Working Depth. ".
"Though it may make the Unix geeks happy, they should remember that this is not a file directory structure that one is navigating within.",
lib/auto/Agent/TCLI/Control/config.xml view on Meta::CPAN
<ROOT>Hello</ROOT>
<ROOT>hello</ROOT>
</contexts>
</Command>
<Command name="Verbose" call_style="state" command="pre-loaded" handler="general" help="changes the verbosity of output to logs" topic="admin" usage="Verbose">
<contexts UNIVERSAL="Verbose" />
</Command>
<Command name="Control" call_style="state" command="pre-loaded" handler="establish_context" help="show or set Control variables" topic="admin" usage="Control show local_address">
<contexts ROOT="Control" />
</Command>
<Command name="context" call_style="state" command="pre-loaded" handler="general" help="displays the current context" manual="Context can be somewhat difficult to understand when one thinks of normal command line interfaces that often retain context ...
put them all in an 'attack' context. Instead of typing 'attack one target=example.com', one could type 'attack' to change to the attack context then type 'one target=example.com' followed by 'two target=example.com' etc.
Furthermore, a well written package will support the setting of default parameters for use within a context. One can then say:
attack
set target=example.com
one
two
...
The full command 'attack one target=example.com' must always be supported, but using context makes it easier to do repetitive tasks manually as well as allow one to navigate through a command syntax that one's forgotten the details of without too muc...
t/TCLI.Control.Interactive.t view on Meta::CPAN
$t->is_code( 'help',200, 'help');
$t->is_code( '/',200, 'root context');
$t->is_body( 'context','Context: ROOT','verify root context');
$t->is_code( 'test1',200, 'test1 context');
$t->is_body( 'context','Context: test1','verify test1 context');
$t->like_body( 'help',qr(test1.1.*?test1.2.*?test1.3)s, "help");
$t->like_body( 'help test1.1',qr(test1.x is a test command)s, "help test1.1");
$t->is_code( 'test1.1',200, 'test1.1 context');
$t->is_body( 'context','Context: test1 test1.1','verify test1.1 context');
$t->like_body( 'help',qr(show.*?test1.1.1.*?test1.2.1)s, "help");
$t->like_body( 'help',qr(global.*?exit.*?help)s, "help with globals");
$t->like_body( 'help globals',qr(global.*?exit.*?help)s, "help globals in context");
$t->like_body( 'exit',qr(Context now: test1),"exit ok" );
$t->is_body( 'exit','Context now: ROOT', 'exit Context now: root');
$t->like_body( 'help globals',qr(global.*?exit.*?help)s, "help globals at root");
#manual tests
#$verbose = 2;
#
$t->is_code( 'manual manual',200, 'manual');
$t->is_code( '/',200, 'root context');
$t->is_body( 'context','Context: ROOT','verify root context');
$t->is_code( 'test1',200, 'test1 context');
$t->is_body( 'context','Context: test1','verify test1 context');
$t->like_body( 'manual test1.1',qr(testing TLCI)s, "manual test1.1");
$t->is_code( 'test1.1',200, 'test1.1 context');
$t->is_body( 'context','Context: test1 test1.1','verify test1.1 context');
$t->like_body( 'manual test1.1.1',qr(help for command)s, "manual gives help when not defined");
$t->like_body( 'manual manual',qr(manual command provides detailed)s, "manual for global in context");
$t->like_body( 'exit',qr(Context now: test1),"exit ok" );
$t->is_body( 'exit','Context now: ROOT', 'exit Context now: root');
$test_master->done;
# Control tests
$t->ok('Control show user');
is($t->get_param('id','',1),'test-master@localhost', 'test user check');
$t->ok('Control show auth');
is($t->get_param('auth','',1),'master', 'test auth check');
$t->ok('Control show local_address');
( run in 0.687 second using v1.01-cache-2.11-cpan-49f99fa48dc )