#!/usr/bin/perl use strict; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; use local::nzbget; use local::db; use local::user; my $user = new local::user($ENV{REMOTE_USER}); use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'get_download_speed' => \&get_download_speed, 'get_download_table' => \&get_download_table ); print $pjx->build_html( $cgi, \&Show_HTML); sub get_download_speed { my $cli = new local::nzbget; my $status = $cli->send_request('status') or die "Can't connect to nubget"; return int($status->{DownloadRate}->value/(1024*1024)).'MB/s'; } sub get_download_table { my $html; my $cli = new local::nzbget; my $row = $cli->send_request('listgroups') or die "Can't connect to nubget"; $html.= CGI::start_table(); foreach my $value ( @$row) { my ($download) = local::db::download->retrieve($value->{NZBNicename}->value) or die ' Error in groups'; my $remaining=$value->{RemainingSizeMB}->value; my $total=$value->{FileSizeMB}->value; my $percent = int(100-100*$remaining/$total); $download->size($total); $download->update(); my $cancel; $cancel=a({href=>'/cgi-bin/nzbget/cancel.pl?id='.$value->{NZBNicename}->value},'Abbrechen') if ($download->owner->owner_id() eq $user->get_id()); $html.= Tr(td([$download->category->name,$download->name,$download->owner->name,$percent.'%',$cancel])); #foreach my $key (keys %$value) #{ # $html.= Tr(td([$key,$value->{$key}->value])); #} } $html.= CGI::end_table(); return $html; } sub Show_HTML { use local::menu; my $menu= new local::menu(%ENV); my $html= $menu->start_html('nzbget status'); $html.= < LALALA ; $html.= hr(); $html.= CGI::start_table(); $html.= Tr(td['download speed', div({id=>'speed'},get_download_speed())]); $html.= CGI::end_table(); $html.= hr(); $html.= div({id=>'dls'},get_download_table()); $html.= $menu->end_html(); return $html }