File: perlxmlrpc.pl

package info (click to toggle)
atheme-services 6.0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 9,556 kB
  • sloc: ansic: 66,611; sh: 6,519; php: 5,028; perl: 2,773; makefile: 741; sed: 16; ruby: 15; python: 3
file content (70 lines) | stat: -rwxr-xr-x 1,771 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl -w
# Simple example of using Atheme's XMLRPC server with perl RPC::XML.
# $Id: perlxmlrpc.pl 8403 2007-06-03 21:34:06Z jilles $

require RPC::XML;
require RPC::XML::Client;

my $cli = RPC::XML::Client->new('http://127.0.0.1:8080/xmlrpc');
my $resp;
my $authcookie = undef;
my $login;
my $password;
my $sourceip = '::1'; # something clearly different

open(TTY, "+</dev/tty") or die "open /dev/tty: $!";
print TTY "login: ";
$login = <TTY>;
exit 0 if ($login eq '');
system("stty -echo </dev/tty");
print TTY "Password:";
$password = <TTY>;
system("stty echo </dev/tty");
print TTY "\n";
exit 0 if ($password eq '');

$resp = $cli->simple_request('atheme.login', $login, $password, $sourceip);
if (defined $resp)
{
	if (ref $resp)
	{
		print "Response(ref):";
		print " ", $_, "=", $resp->{$_} foreach keys %$resp;
		print "\n";
	}
	else
	{
		print "Response: $resp\n";
		$authcookie = $resp;
	}
}
else
{
	print "Failed: ", $RPC::XML::ERROR, "\n";
}

if (defined $authcookie)
{
	$resp = $cli->simple_request('atheme.command', $authcookie, $login, $sourceip, 'ChanServ', 'DEOP', '#irc', 'jilles');
	#$resp = $cli->simple_request('atheme.command', $authcookie, $login, '.', 'ChanServ', 'KICK', '#irc', 'jilles', 'xmlrpc test');
	#$resp = $cli->simple_request('atheme.command', $authcookie, $login, '.', 'ChanServ', 'INFO', '#irc');
	#$resp = $cli->simple_request('atheme.command', $authcookie, $login, '.', 'ChanServ', 'FLAGS', '#irc');
	if (defined $resp)
	{
		if (ref $resp)
		{
			print "Response(ref):";
			print " ", $_, "=", $resp->{$_} foreach keys %$resp;
			print "\n";
		}
		else
		{
			print "Response: $resp\n";
		}
	}
	else
	{
		print "Failed: ", $RPC::XML::ERROR, "\n";
	}
	$resp = $cli->simple_request('atheme.logout', $authcookie, $login);
}