From ca2e135cba556b6d4a2e1512292b8ffaae0b9089 Mon Sep 17 00:00:00 2001 From: KodeStar Date: Mon, 5 Mar 2018 19:38:23 +0000 Subject: [PATCH] closes #122, closes #82, --- app/SupportedApps/Nzbget.php | 20 ++++++------ app/SupportedApps/Pihole.php | 9 +++--- app/SupportedApps/Plexpy.php | 9 +++--- app/SupportedApps/Runeaudio.php | 5 +-- app/SupportedApps/Sabnzbd.php | 31 +++++++++++-------- public/js/app.js | 7 +++-- resources/assets/js/app.js | 7 +++-- resources/lang/en/app.php | 1 + .../views/supportedapps/nzbget.blade.php | 5 +++ .../views/supportedapps/pihole.blade.php | 5 +++ .../views/supportedapps/plexpy.blade.php | 4 +++ .../views/supportedapps/proxmox.blade.php | 5 +++ .../views/supportedapps/runeaudio.blade.php | 5 +++ .../views/supportedapps/sabnzbd.blade.php | 6 ++++ 14 files changed, 81 insertions(+), 38 deletions(-) diff --git a/app/SupportedApps/Nzbget.php b/app/SupportedApps/Nzbget.php index fc28b82f..aa2f7ecf 100644 --- a/app/SupportedApps/Nzbget.php +++ b/app/SupportedApps/Nzbget.php @@ -39,25 +39,27 @@ class Nzbget implements Contracts\Applications, Contracts\Livestats { } public function executeConfig() { - $output = ''; + $html = ''; + $active = 'inactive'; $res = $this->buildRequest('status'); $data = json_decode($res->getBody()); //$data->result->RemainingSizeMB = '10000000'; //$data->result->DownloadRate = '100000000'; - $size = $data->result->RemainingSizeMB; - $rate = $data->result->DownloadRate; - $queue_size = format_bytes($size*1000*1000, false, ' ', ''); - $current_speed = format_bytes($rate, false, ' '); + if($data) { + $size = $data->result->RemainingSizeMB; + $rate = $data->result->DownloadRate; + $queue_size = format_bytes($size*1000*1000, false, ' ', ''); + $current_speed = format_bytes($rate, false, ' '); - if($size > 0 || $rate > 0) { - $output = ' + $active = ($size > 0 || $rate > 0) ? 'active' : 'inactive'; + $html = '
  • Queue'.$queue_size.'
  • Speed'.$current_speed.'/s
'; } - return $output; + return json_encode(['status' => $active, 'html' => $html]); } public function buildRequest($endpoint) { @@ -73,7 +75,7 @@ class Nzbget implements Contracts\Applications, Contracts\Livestats { $api_url = $rebuild_url.'/jsonrpc/'.$endpoint; - $client = new Client(['http_errors' => false]); + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); $res = $client->request('GET', $api_url); return $res; diff --git a/app/SupportedApps/Pihole.php b/app/SupportedApps/Pihole.php index 00e76e92..b695b32f 100644 --- a/app/SupportedApps/Pihole.php +++ b/app/SupportedApps/Pihole.php @@ -39,17 +39,18 @@ class Pihole implements Contracts\Applications, Contracts\Livestats { public function executeConfig() { - $output = ''; + $html = ''; + $active = 'active'; $res = $this->buildRequest(); $data = json_decode($res->getBody()); - $output = ' + $html = '
  • Domains
    Blocked
    '.$data->domains_being_blocked.'
  • Blocked
    Today
    '.$data->ads_blocked_today.'
'; - return $output; + return json_encode(['status' => $active, 'html' => $html]); } public function buildRequest() @@ -62,7 +63,7 @@ class Pihole implements Contracts\Applications, Contracts\Livestats { $api_url = $url.'/api.php'; //die( $api_url.' --- '); - $client = new Client(['http_errors' => false]); + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); $res = $client->request('GET', $api_url); return $res; diff --git a/app/SupportedApps/Plexpy.php b/app/SupportedApps/Plexpy.php index 93aac88e..5c25f1c2 100644 --- a/app/SupportedApps/Plexpy.php +++ b/app/SupportedApps/Plexpy.php @@ -44,18 +44,19 @@ class Plexpy implements Contracts\Applications, Contracts\Livestats { } public function executeConfig() { - $output = ''; + $html = ''; + $active = 'active'; $res = $this->buildRequest('get_activity'); $data = json_decode($res->getBody()); $stream_count = $data->response->data->stream_count; - $output = ' + $html = '
  • Stream Count'.$stream_count.'
'; - return $output; + return json_encode(['status' => $active, 'html' => $html]); } public function buildRequest($endpoint) { @@ -67,7 +68,7 @@ class Plexpy implements Contracts\Applications, Contracts\Livestats { $api_url = $url.'/api/v2?apikey='.$apikey.'&cmd='.$endpoint; - $client = new Client(['http_errors' => false]); + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); $res = $client->request('GET', $api_url); return $res; diff --git a/app/SupportedApps/Runeaudio.php b/app/SupportedApps/Runeaudio.php index 9a149b50..92353d7e 100644 --- a/app/SupportedApps/Runeaudio.php +++ b/app/SupportedApps/Runeaudio.php @@ -40,6 +40,7 @@ class Runeaudio implements Contracts\Applications, Contracts\Livestats { public function executeConfig() { $output = ''; + $active = 'active'; $artist = ''; $song_title = ''; $res = $this->buildRequest('currentsong'); @@ -71,7 +72,7 @@ class Runeaudio implements Contracts\Applications, Contracts\Livestats { $output = $output.''; - return $output; + return json_encode(['status' => $active, 'html' => $output]); } public function buildRequest($endpoint) @@ -84,7 +85,7 @@ class Runeaudio implements Contracts\Applications, Contracts\Livestats { $api_url = $url.'/command/?cmd='.$endpoint; //die( $api_url.' --- '); - $client = new Client(['http_errors' => false]); + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); $res = $client->request('GET', $api_url); return $res; diff --git a/app/SupportedApps/Sabnzbd.php b/app/SupportedApps/Sabnzbd.php index fab7cf51..4e78c735 100644 --- a/app/SupportedApps/Sabnzbd.php +++ b/app/SupportedApps/Sabnzbd.php @@ -44,25 +44,27 @@ class Sabnzbd implements Contracts\Applications, Contracts\Livestats { } public function executeConfig() { - $output = ''; + $html = ''; + $active = 'inactive'; $res = $this->buildRequest('queue'); $data = json_decode($res->getBody()); //$data->result->RemainingSizeMB = '10000000'; //$data->result->DownloadRate = '100000000'; - $size = $data->queue->mbleft; - $rate = $data->queue->kbpersec; - $queue_size = format_bytes($size*1000*1000, false, ' ', ''); - $current_speed = format_bytes($rate*1000, false, ' '); + if($data) { + $size = $data->queue->mbleft; + $rate = $data->queue->kbpersec; + $queue_size = format_bytes($size*1000*1000, false, ' ', ''); + $current_speed = format_bytes($rate*1000, false, ' '); - if($size > 0 || $rate > 0) { - $output = ' -
    -
  • Queue'.$queue_size.'
  • -
  • Speed'.$current_speed.'/s
  • -
+ $active = ($size > 0 || $rate > 0) ? 'active' : 'inactive'; + $html = ' +
    +
  • Queue'.$queue_size.'
  • +
  • Speed'.$current_speed.'/s
  • +
'; } - return $output; + return json_encode(['status' => $active, 'html' => $html]); } public function buildRequest($endpoint) { @@ -70,12 +72,15 @@ class Sabnzbd implements Contracts\Applications, Contracts\Livestats { $url = $config->url; $apikey = $config->apikey; + //print_r($config); + //die(); + $url = rtrim($url, '/'); $api_url = $url.'/api?output=json&apikey='.$apikey.'&mode='.$endpoint; //die( $api_url.' --- '); - $client = new Client(['http_errors' => false]); + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); $res = $client->request('GET', $api_url); return $res; diff --git a/public/js/app.js b/public/js/app.js index 7c559614..c5b88db9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -28,9 +28,10 @@ $.when( $.ready ).then(function() { (function worker() { $.ajax({ url: '/get_stats/'+id, + dataType: 'json', success: function(data) { - container.html(data); - if(data != '') timer = increaseby; + container.html(data.html); + if(data.status == 'active') timer = increaseby; else { if(timer < max_timer) timer += 2000; } @@ -130,7 +131,7 @@ $.when( $.ready ).then(function() { var apiurl = $('#create input[name=url]').val(); - var override_url = $('#create input[name=override_url]'); + var override_url = $('#override_url'); if(override_url.length && override_url.val() != '') { apiurl = override_url; } diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 0bb37e4b..507d23d6 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -19,9 +19,10 @@ $.when( $.ready ).then(function() { (function worker() { $.ajax({ url: '/get_stats/'+id, + dataType: 'json', success: function(data) { - container.html(data); - if(data != '') timer = increaseby; + container.html(data.html); + if(data.status == 'active') timer = increaseby; else { if(timer < max_timer) timer += 2000; } @@ -121,7 +122,7 @@ $.when( $.ready ).then(function() { var apiurl = $('#create input[name=url]').val(); - var override_url = $('#create input[name=override_url]'); + var override_url = $('#override_url'); if(override_url.length && override_url.val() != '') { apiurl = override_url; } diff --git a/resources/lang/en/app.php b/resources/lang/en/app.php index 7ca35146..920b26ed 100644 --- a/resources/lang/en/app.php +++ b/resources/lang/en/app.php @@ -65,6 +65,7 @@ return [ 'apps.add_tag' => 'Add tag', 'apps.tag_name' => 'Tag name', 'apps.tags' => 'Tags', + 'apps.override' => 'If different to main url', 'url' => 'Url', 'title' => 'Title', diff --git a/resources/views/supportedapps/nzbget.blade.php b/resources/views/supportedapps/nzbget.blade.php index f90873d2..a52fe293 100644 --- a/resources/views/supportedapps/nzbget.blade.php +++ b/resources/views/supportedapps/nzbget.blade.php @@ -1,6 +1,11 @@

{{ __('app.apps.config') }} ({{ __('app.optional') }})

+
+ + {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} +
+
{!! Form::text('config[username]', null, array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!} diff --git a/resources/views/supportedapps/pihole.blade.php b/resources/views/supportedapps/pihole.blade.php index 23323569..9fb61b5c 100644 --- a/resources/views/supportedapps/pihole.blade.php +++ b/resources/views/supportedapps/pihole.blade.php @@ -2,6 +2,11 @@
+
+ + {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} +
+
{!! Form::hidden('config[enabled]', '0') !!} diff --git a/resources/views/supportedapps/plexpy.blade.php b/resources/views/supportedapps/plexpy.blade.php index e5e2fb1f..2a4a44ba 100644 --- a/resources/views/supportedapps/plexpy.blade.php +++ b/resources/views/supportedapps/plexpy.blade.php @@ -1,6 +1,10 @@

{{ __('app.apps.config') }} ({{ __('app.optional') }})

+
+ + {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} +
{!! Form::text('config[apikey]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item')) !!} diff --git a/resources/views/supportedapps/proxmox.blade.php b/resources/views/supportedapps/proxmox.blade.php index 7bce9b4b..10c1ab34 100644 --- a/resources/views/supportedapps/proxmox.blade.php +++ b/resources/views/supportedapps/proxmox.blade.php @@ -1,6 +1,11 @@

{{ __('app.apps.config') }} ({{ __('app.optional') }})

+
+ + {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} +
+
{!! Form::text('config[username]', null, array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!} diff --git a/resources/views/supportedapps/runeaudio.blade.php b/resources/views/supportedapps/runeaudio.blade.php index e0a6b92f..c5167163 100644 --- a/resources/views/supportedapps/runeaudio.blade.php +++ b/resources/views/supportedapps/runeaudio.blade.php @@ -2,6 +2,11 @@
+
+ + {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} +
+
{!! Form::hidden('config[enabled]', '0') !!} diff --git a/resources/views/supportedapps/sabnzbd.blade.php b/resources/views/supportedapps/sabnzbd.blade.php index fdfd2697..e59fc4d8 100644 --- a/resources/views/supportedapps/sabnzbd.blade.php +++ b/resources/views/supportedapps/sabnzbd.blade.php @@ -1,6 +1,12 @@

{{ __('app.apps.config') }} ({{ __('app.optional') }})

+ +
+ + {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} +
+
{!! Form::text('config[apikey]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item')) !!}