1#!/usr/bin/perl -w
2# Simple example of using Atheme's XMLRPC server with perl RPC::XML.
3# $Id: perlxmlrpc.pl 8403 2007-06-03 21:34:06Z jilles $
4
5require RPC::XML;
6require RPC::XML::Client;
7
8my $cli = RPC::XML::Client->new('http://127.0.0.1:8080/xmlrpc');
9my $resp;
10my $authcookie = undef;
11my $login;
12my $password;
13my $sourceip = '::1'; # something clearly different
14
15open(TTY, "+</dev/tty") or die "open /dev/tty: $!";
16print TTY "login: ";
17$login = <TTY>;
18exit 0 if ($login eq '');
19system("stty -echo </dev/tty");
20print TTY "Password:";
21$password = <TTY>;
22system("stty echo </dev/tty");
23print TTY "\n";
24exit 0 if ($password eq '');
25
26$resp = $cli->simple_request('atheme.login', $login, $password, $sourceip);
27if (defined $resp)
28{
29	if (ref $resp)
30	{
31		print "Response(ref):";
32		print " ", $_, "=", $resp->{$_} foreach keys %$resp;
33		print "\n";
34	}
35	else
36	{
37		print "Response: $resp\n";
38		$authcookie = $resp;
39	}
40}
41else
42{
43	print "Failed: ", $RPC::XML::ERROR, "\n";
44}
45
46if (defined $authcookie)
47{
48	$resp = $cli->simple_request('atheme.command', $authcookie, $login, $sourceip, 'ChanServ', 'DEOP', '#irc', 'jilles');
49	#$resp = $cli->simple_request('atheme.command', $authcookie, $login, '.', 'ChanServ', 'KICK', '#irc', 'jilles', 'xmlrpc test');
50	#$resp = $cli->simple_request('atheme.command', $authcookie, $login, '.', 'ChanServ', 'INFO', '#irc');
51	#$resp = $cli->simple_request('atheme.command', $authcookie, $login, '.', 'ChanServ', 'FLAGS', '#irc');
52	if (defined $resp)
53	{
54		if (ref $resp)
55		{
56			print "Response(ref):";
57			print " ", $_, "=", $resp->{$_} foreach keys %$resp;
58			print "\n";
59		}
60		else
61		{
62			print "Response: $resp\n";
63		}
64	}
65	else
66	{
67		print "Failed: ", $RPC::XML::ERROR, "\n";
68	}
69	$resp = $cli->simple_request('atheme.logout', $authcookie, $login);
70}
71