From: Ralf Ertzinger Date: Sat, 20 Dec 2008 15:16:33 +0000 (+0100) Subject: - Add authentication support X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=xmlrtorrent.git;a=commitdiff_plain;h=6cfd0a2c87ccb3ce8f49f1b122b1eab7ab3bc1b8 - Add authentication support - Add some colors - Add .penis support --- diff --git a/xmlrtorrent.pl b/xmlrtorrent.pl index 2089ce8..3adbe27 100644 --- a/xmlrtorrent.pl +++ b/xmlrtorrent.pl @@ -23,6 +23,8 @@ my @outputstack = (undef); my $PARAMS = { 'XMLURL' => 'http://localhost/RPC2', + 'USERNAME' => '', + 'PASSWORD' => '', }; # activate debug here @@ -86,7 +88,7 @@ sub write_irssi { my @text = @_; my $output = $outputstack[0]; - $text[0] = 'xmlrtorrent: ' . $text[0]; + $text[0] = '%%mxmlrtorrent: %%n' . $text[0]; if (defined($output) and ref($output)) { $output->print(sprintf(shift(@text), @text), MSGLEVEL_CLIENTCRAP); @@ -164,7 +166,7 @@ sub check_for_link { push_output($witem); # Look if there is a torrent link in there - $message =~ m|(http://\S*\.torrent)|; + $message =~ m,(http://\S*\.(?:torrent|penis)),; $m = $1; while (defined($m)) { write_debug('Torrent-URL: %s', $m); @@ -199,18 +201,26 @@ sub cmd_queue { write_debug('Sending %s to rtorrent', $u); unless(defined($rtorrent->load_start($u))) { - write_irssi('Error sending URL %s: %s', $u, $rtorrent->errstr()); + write_irssi('%%RError sending URL %s: %s', $u, $rtorrent->errstr()); } else { + write_irssi('%s enqueued', $u); delete($torrentlist{$id}); } + } elsif ('add' eq $subcmd) { + unless(defined($id)) { + return; + } + $torrentlist{$torrentindex++} = {'CHANNEL' => '', 'NICK' => '', 'URL' => $id}; } elsif (('list' eq $subcmd) or !defined($subcmd)) { write_irssi('List of queued torrents'); foreach (sort(keys(%torrentlist))) { - write_irssi(' %d: %s@%s: %s', $_, + write_irssi(' %3d: %s@%s: %s', $_, $torrentlist{$_}->{'NICK'}, $torrentlist{$_}->{'CHANNEL'}, $torrentlist{$_}->{'URL'}); } + } else { + write_irssi('Unknown subcommand: %s', $subcmd); } } @@ -219,18 +229,20 @@ sub cmd_remote { my ($subcmd, $id, @params) = @_; my $rqueue; - if ('queue' eq $subcmd) { + if (('list' eq $subcmd) or !defined($subcmd)) { unless(defined($rqueue = $rtorrent->download_list())) { write_irssi('Error getting list of downloads: %s', $rtorrent->errstr()); return; } + write_irssi('List of rempote torrents'); foreach (@{$rqueue}) { - write_irssi('%s%s: %sB/%sB done, %sb/s up, %sb/s down', + write_irssi('%s%s: %sB/%sB done (%d%%), %sB/s up, %sB/s down', $_->[6]?'*':' ', $_->[0], format_number($_->[2]), format_number($_->[1]), + ($_->[2]*100)/$_->[1], format_number($_->[3]), format_number($_->[4])); } @@ -261,7 +273,10 @@ sub cmd_set { if(exists($PARAMS->{$key})) { $conf->{'xmlrtorrent'}->{$key} = $val; if ('XMLURL' eq $key) { - unless(defined($rtorrent = xmlrtorrent->new('XMLURL' => $conf->{'xmlrtorrent'}->{'XMLURL'}))) { + unless(defined($rtorrent = xmlrtorrent->new( + 'XMLURL' => $conf->{'xmlrtorrent'}->{'XMLURL'}, + 'USERNAME' => $conf->{'xmlrtorrent'}->{'USERNAME'}, + 'USERNAME' => $conf->{'xmlrtorrent'}->{'PASSWORD'}))) { write_irssi('Could not initialize XMLRPC instance'); return; } @@ -317,7 +332,10 @@ sub init_xmlrtorrent { } } - unless(defined($rtorrent = xmlrtorrent->new('XMLURL' => $conf->{'xmlrtorrent'}->{'XMLURL'}))) { + unless(defined($rtorrent = xmlrtorrent->new( + 'XMLURL' => $conf->{'xmlrtorrent'}->{'XMLURL'}, + 'USERNAME' => $conf->{'xmlrtorrent'}->{'USERNAME'}, + 'USERNAME' => $conf->{'xmlrtorrent'}->{'PASSWORD'}))) { write_irssi('Could not initialize XMLRPC instance'); return; } @@ -356,6 +374,8 @@ sub cmdhandler { if (exists($xmlrtorrent_commands->{$cmd})) { $xmlrtorrent_commands->{$cmd}->(@params); + } else { + write_irssi('Unknown command: %s', $cmd); } pop_output(); diff --git a/xmlrtorrent.pm b/xmlrtorrent.pm index 92cd1aa..b1c41b9 100644 --- a/xmlrtorrent.pm +++ b/xmlrtorrent.pm @@ -9,11 +9,15 @@ sub new { my $class = shift; my $self = {@_}; - unless(exists($self->{'XMLURL'}) && defined($self->{'XMLURL'})) { + unless(exists($self->{'XMLURL'}) and defined($self->{'XMLURL'})) { return undef; } $self->{'__RPCClient'} = RPC::XML::Client->new($self->{'XMLURL'}); + if ((exists($self->{'USERNAME'}) and exists($self->{'PASSWORD'})) and + ($self->{'USERNAME'} ne '')) { + $self->{'__RPCClient'}->credentials('', $self->{'USERNAME'}, $self->{'PASSWORD'}); + } return bless($self, $class); }