From fa1298bfdef42a32716c30e1713c9bc14d292832 Mon Sep 17 00:00:00 2001 From: XciD Date: Tue, 25 Feb 2014 10:50:59 +0100 Subject: [PATCH] Add IP/Port --- plugins/rtorrent/rtom_allsessions_mem | 0 plugins/rtorrent/rtom_allsessions_peers | 99 ++++++++++++++++--------- plugins/rtorrent/rtom_allsessions_spdd | 95 ++++++++++++++++-------- plugins/rtorrent/rtom_allsessions_vol | 81 +++++++++++--------- 4 files changed, 177 insertions(+), 98 deletions(-) mode change 100644 => 100755 plugins/rtorrent/rtom_allsessions_mem mode change 100644 => 100755 plugins/rtorrent/rtom_allsessions_peers mode change 100644 => 100755 plugins/rtorrent/rtom_allsessions_spdd mode change 100644 => 100755 plugins/rtorrent/rtom_allsessions_vol diff --git a/plugins/rtorrent/rtom_allsessions_mem b/plugins/rtorrent/rtom_allsessions_mem old mode 100644 new mode 100755 diff --git a/plugins/rtorrent/rtom_allsessions_peers b/plugins/rtorrent/rtom_allsessions_peers old mode 100644 new mode 100755 index c704ec13..a6d29144 --- a/plugins/rtorrent/rtom_allsessions_peers +++ b/plugins/rtorrent/rtom_allsessions_peers @@ -28,11 +28,16 @@ # # Configuration example # -# [rtom_peers] -# user username -# env.src socket -# env.socket /home/usernametorrent/.socket/rpc.socket,/home/usernametorrent/.socket/rpc2.socket -# env.category Category +# [rtom_allsessions_*] +# user username +# env.src socket +# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket +# env.category Category +# +# [rtom_allsessions_*] +# user username +# env.port 5000,5001,5002,5003 +# env.category Category # #%# family=auto @@ -67,9 +72,10 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { use IO::Socket; -my @sockets = split /,/, $ENV{"socket"} || ""; -my $mem = 0; my $src = $ENV{"src"} || ""; +my @sockets = split /,/, $ENV{"socket"} || ""; +my $ip = $ENV{"ip"} || "127.0.0.1"; +my @ports = split /,/, $ENV{"port"} || ""; my $pattern = qr/<(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; my $tpattern = qr/[0-9A-F]{20}/; @@ -78,7 +84,6 @@ my $line = "d. my $llen = length $line; my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; my $hlen = length $header; -$line = "${hlen}:${header},${line}"; my $tor = 0; my $tot = 0; @@ -89,34 +94,60 @@ my $ppline = ""; my $out = 0; my $pla = 0; -for $socket (@sockets) -{ - if ( ( defined $src ) && ( $src eq "socket" ) ) { - socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ); - connect( SOCK, sockaddr_un( $socket ) ); - } - print SOCK $line; - flush SOCK; - - while ( $line = ) { - if ( $line =~ /$tpattern/ ) { - $tor += 1; - } elsif ( $line =~ /$pattern/ ) { - $tot += 1; - $enc += $2; - $line = ; - $line =~ /$pattern/; - $inc += $2; - } - $ppline = $pline; - $pline = $line; - } - close (SOCK); - - $out = $out + $tot - $inc; - $pla = $pla + $tot - $enc; +if ( ( defined $src ) && ( $src eq "socket" ) ) { + for $socket (@sockets) + { + socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; + connect( SOCK, sockaddr_un( $socket ) ) or die $!; + my $line = "${hlen}:${header},${line}"; + print SOCK $line; + flush SOCK; + while ( $line = ) { + if ( $line =~ /$tpattern/ ) { + $tor += 1; + } elsif ( $line =~ /$pattern/ ) { + $tot += 1; + $enc += $2; + $line = ; + $line =~ /$pattern/; + $inc += $2; + } + $ppline = $pline; + $pline = $line; + } + close (SOCK); + $out = $out + $tot - $inc; + $pla = $pla + $tot - $enc; + } +} else { + for $port (@ports) + { + socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); + connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); + my $line = "${hlen}:${header},${line}"; + print SOCK $line; + flush SOCK; + while ( $line = ) { + if ( $line =~ /$tpattern/ ) { + $tor += 1; + } elsif ( $line =~ /$pattern/ ) { + $tot += 1; + $enc += $2; + $line = ; + $line =~ /$pattern/; + $inc += $2; + } + $ppline = $pline; + $pline = $line; + } + close (SOCK); + $out = $out + $tot - $inc; + $pla = $pla + $tot - $enc; + } } + + print "torrents.value ${tor}\ntotal.value ${tot}\nencrypted.value ${enc}\nplain.value ${pla}\nincoming.value ${inc}\noutgoing.value ${out}\n"; exit; diff --git a/plugins/rtorrent/rtom_allsessions_spdd b/plugins/rtorrent/rtom_allsessions_spdd old mode 100644 new mode 100755 index be226160..4fa9f5d2 --- a/plugins/rtorrent/rtom_allsessions_spdd +++ b/plugins/rtorrent/rtom_allsessions_spdd @@ -40,12 +40,16 @@ # # Configuration example # -# [rtom_spdd] +# [rtom_allsessions_*] # user username # env.src socket -# env.socket /home/user/torrent/.socket/rpc.socket,/home/user2/torrent/.socket/rpc2.socket -# env.category Sometext +# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket +# env.category Category # +# [rtom_allsessions_*] +# user username +# env.port 5000,5001,5002,5003 +# env.category Category # #%# family=auto @@ -82,43 +86,72 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { } use IO::Socket; -my @sockets = split /,/, $ENV{"socket"} || ""; my $src = $ENV{"src"} || ""; +my @sockets = split /,/, $ENV{"socket"} || ""; +my $ip = $ENV{"ip"} || "127.0.0.1"; +my @ports = split /,/, $ENV{"port"} || ""; + +my $pattern = qr/<(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; +my $line = "system.multicallmethodNameget_up_totalparamsmethodNameget_down_totalparamsmethodNameget_upload_rateparamsmethodNameget_download_rateparams"; +my $llen = length $line; +my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; +my $hlen = length $header; my $up = -1; my $down = -1; -for $socket (@sockets) -{ - my $pattern = qr/<(int|i4|i8|ex\.i8)>([-]{0,1}\d+)<\/(int|i4|i8|ex\.i8)><\/value>/; - my $line = "system.multicallmethodNameget_up_totalparamsmethodNameget_down_totalparamsmethodNameget_upload_rateparamsmethodNameget_download_rateparams"; - my $llen = length $line; - my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; - my $hlen = length $header; - $line = "${hlen}:${header},${line}"; - if ( ( defined $src ) && ( $src eq "socket" ) ) { - socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ); - connect( SOCK, sockaddr_un( $socket ) ); - } - - print SOCK $line; - flush SOCK; - my $up_tmp = -1; - my $down_tmp = -1; - while (( $up_tmp == -1 ) && ( $line = ) ) { - if ( $line =~ /$pattern/ ) { - $up_tmp = $2; +if ( ( defined $src ) && ( $src eq "socket" ) ) { + for $socket (@sockets) + { + socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; + connect( SOCK, sockaddr_un( $socket ) ) or die $!; + my $line = "${hlen}:${header},${line}"; + print SOCK $line; + flush SOCK; + my $up_tmp = -1; + my $down_tmp = -1; + while (( $up_tmp == -1 ) && ( $line = ) ) { + if ( $line =~ /$pattern/ ) { + $up_tmp = $2; + } } - } - while (( $down_tmp == -1 ) && ( $line = ) ) { - if ( $line =~ /$pattern/ ) { - $down_tmp = $2; + while (( $down_tmp == -1 ) && ( $line = ) ) { + if ( $line =~ /$pattern/ ) { + $down_tmp = $2; + } } + close (SOCK); + $up = $up + $up_tmp; + $down = $down + $down_tmp; + } +} else { + for $port (@ports) + { + socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); + connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); + my $line = "${hlen}:${header},${line}"; + print SOCK $line; + flush SOCK; + my $up_tmp = -1; + my $down_tmp = -1; + while (( $up_tmp == -1 ) && ( $line = ) ) { + if ( $line =~ /$pattern/ ) { + $up_tmp = $2; + } + } + while (( $down_tmp == -1 ) && ( $line = ) ) { + if ( $line =~ /$pattern/ ) { + $down_tmp = $2; + } + } + close (SOCK); + $up = $up + $up_tmp; + $down = $down + $down_tmp; } - close (SOCK); - $up = $up + $up_tmp; - $down = $down + $down_tmp; } + + + print "up.value ${up}\ndown.value ${down}\n"; exit; diff --git a/plugins/rtorrent/rtom_allsessions_vol b/plugins/rtorrent/rtom_allsessions_vol old mode 100644 new mode 100755 index 57b819e4..6e6a5de7 --- a/plugins/rtorrent/rtom_allsessions_vol +++ b/plugins/rtorrent/rtom_allsessions_vol @@ -28,11 +28,16 @@ # # Configuration example # -# [rtom_vol] -# user username -# env.src socket -# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc2.socket -# env.category Sometext +# [rtom_allsessions_*] +# user username +# env.src socket +# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket +# env.category Category +# +# [rtom_allsessions_*] +# user username +# env.port 5000,5001,5002,5003 +# env.category Category # #%# family=auto @@ -71,40 +76,50 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { use IO::Socket; -my @sockets = split /,/, $ENV{"socket"} || ""; my $src = $ENV{"src"} || ""; +my @sockets = split /,/, $ENV{"socket"} || ""; +my $ip = $ENV{"ip"} || "127.0.0.1"; +my @ports = split /,/, $ENV{"port"} || ""; my $pattern = qr/([A-Z0-9]+)<\/string><\/value>/; -my $line; -my $llenmy; -my $header; -my $hlen; - -my $num; foreach ( @views ) { - $num = 0; - for $socket (@sockets){ - if ( ( defined $src ) && ( $src eq "socket" ) ) { - socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ); - connect( SOCK, sockaddr_un( $socket ) ); - } + my $num = 0; + my $line = "d.multicall${_}d.get_hash="; + my $llen = length $line; + my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; + my $hlen = length $header; - $line = "d.multicall${_}d.get_hash="; - $llen = length $line; - $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000"; - $hlen = length $header; - $line = "${hlen}:${header},${line}"; - - print SOCK $line; - flush SOCK; - - while ( $line = ) { - if ( $line =~ /$pattern/ ) { - $num++; - } - } - close (SOCK); + if ( ( defined $src ) && ( $src eq "socket" ) ) { + for $socket (@sockets) + { + socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die; + connect( SOCK, sockaddr_un( $socket ) ) or die $!; + my $line = "${hlen}:${header},${line}"; + print SOCK $line; + flush SOCK; + while ( $line = ) { + if ( $line =~ /$pattern/ ) { + $num++; + } + } + close (SOCK); + } + } else { + for $port (@ports) + { + socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ); + connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) ); + my $line = "${hlen}:${header},${line}"; + print SOCK $line; + flush SOCK; + while ( $line = ) { + if ( $line =~ /$pattern/ ) { + $num++; + } + } + close (SOCK); + } } print "${_}.value ${num}\n"; }