root / plugins / xbnbt / xbnbt_peers @ eaf6c2d7
Historique | Voir | Annoter | Télécharger (2,55 ko)
| 1 | e5443a48 | fireba11 | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # |
||
| 3 | # Copyright (C) 2007 Florian Schnabel |
||
| 4 | # |
||
| 5 | # This program is free software; you can redistribute it and/or |
||
| 6 | # modify it under the terms of the GNU General Public License |
||
| 7 | # as published by the Free Software Foundation; version 2 dated June, |
||
| 8 | # 1991. |
||
| 9 | # |
||
| 10 | # This program is distributed in the hope that it will be useful, |
||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | # GNU General Public License for more details. |
||
| 14 | # |
||
| 15 | # You should have received a copy of the GNU General Public License |
||
| 16 | # along with this program; if not, write to the Free Software |
||
| 17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 18 | # |
||
| 19 | # Capabilites |
||
| 20 | # config |
||
| 21 | # autoconf |
||
| 22 | # |
||
| 23 | # Config values |
||
| 24 | # host [optional] |
||
| 25 | # port [optional] |
||
| 26 | # realm [optional] |
||
| 27 | # user |
||
| 28 | # pass |
||
| 29 | # |
||
| 30 | # You need to set up user credentials of a user with admin rights on the tracker. |
||
| 31 | # |
||
| 32 | # $Log$ |
||
| 33 | # Revision 0.2 2007/02/22 19:40:00 fireba11 |
||
| 34 | # added autoconf functionality |
||
| 35 | # added config values |
||
| 36 | # |
||
| 37 | # Revision 0.1 2007/02/20 17:00:00 fireba11 |
||
| 38 | # Created by fireba11 |
||
| 39 | # |
||
| 40 | # Magick markers (optional): |
||
| 41 | #%# family=auto |
||
| 42 | #%# capabilities=autoconf |
||
| 43 | |||
| 44 | my $host = $ENV{'host'} || 'localhost';
|
||
| 45 | my $port = $ENV{'port'} || '6969';
|
||
| 46 | my $realm = $ENV{'realm'} || 'BNBT';
|
||
| 47 | my $user = $ENV{'user'} || '';
|
||
| 48 | my $pass = $ENV{'pass'} || '';
|
||
| 49 | |||
| 50 | if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
|
||
| 51 | print "graph_title xbnbt peers\n"; |
||
| 52 | print "graph_args --base 1000 -l 0\n"; |
||
| 53 | print "graph_vlabel peers\n"; |
||
| 54 | eaf6c2d7 | dipohl | print "graph_category torrent\n"; |
| 55 | e5443a48 | fireba11 | print "peers.label peers\n"; |
| 56 | print "seeds.label seeds\n"; |
||
| 57 | print "leechers.label leechers\n"; |
||
| 58 | print "unique.label unique\n"; |
||
| 59 | exit 0; |
||
| 60 | } |
||
| 61 | |||
| 62 | use LWP; |
||
| 63 | my $browser = LWP::UserAgent->new; |
||
| 64 | |||
| 65 | $browser->credentials($host.':'.$port, $realm, $user => $pass); |
||
| 66 | my $response = $browser->get('http://'.$host.':'.$port.'/xstats.html');
|
||
| 67 | |||
| 68 | if ($response->content =~ /xpeerstats.*?odd">(\d*).*?even">(\d*).*?odd">(\d*).*?even">(\d*)/s) {
|
||
| 69 | $peers = $1; |
||
| 70 | $seeds = $2; |
||
| 71 | $leechers = $3; |
||
| 72 | $unique = $4; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ( defined $ARGV[0] and $ARGV[0] eq "autoconf") {
|
||
| 76 | if (! $response->is_success) {
|
||
| 77 | print 'no (Error: ', $response->header('WWW-Authenticate') || ' Error accessing', $response->status_line, ' at http://'.$host.':'.$port.'/xstats.html Aborting)';
|
||
| 78 | exit 1; |
||
| 79 | } elsif (! defined $peers ) {
|
||
| 80 | print "no (Unable to find peer values within the page from the given URL.)"; |
||
| 81 | exit 1; |
||
| 82 | } else {
|
||
| 83 | print "yes"; |
||
| 84 | exit 0; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | |||
| 89 | print "peers.value ".$peers."\nseeds.value ". $seeds."\nleechers.value ". $leechers."\nunique.value ". $unique; |
