From 24469eb2fadcab6889ab0f5a7235a2dd7a42f3c0 Mon Sep 17 00:00:00 2001 From: shuaiscott Date: Fri, 8 Jun 2018 13:58:17 -0600 Subject: [PATCH 1/2] Adding Enhanced Deluge --- app/SupportedApps/Deluge.php | 103 +++++++++++++++++- .../views/supportedapps/deluge.blade.php | 11 ++ 2 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 resources/views/supportedapps/deluge.blade.php diff --git a/app/SupportedApps/Deluge.php b/app/SupportedApps/Deluge.php index 5fb05dcc..5af9de5a 100644 --- a/app/SupportedApps/Deluge.php +++ b/app/SupportedApps/Deluge.php @@ -1,6 +1,7 @@ login()[0]; + switch($res->getStatusCode()) { + case 200: + $data = json_decode($res->getBody()); + if(!isset($data->result) || is_null($data->result) || $data->result == false) { + echo 'Failed: Invalid Credentials'; + } else { + echo 'Successfully connected to the API'; + } + break; + case 401: + echo 'Failed: Invalid credentials'; + break; + case 404: + echo 'Failed: Please make sure your URL is correct and that there is a trailing slash'; + break; + default: + echo 'Something went wrong... Code: '.$res->getStatusCode(); + break; + } + } + public function executeConfig() + { + $html = ''; + $active = 'active'; + $jar = $this->login()[1]; + $res = $this->getDetails($jar); + $data = json_decode($res->getBody()); + $download_rate = $data->result->stats->download_rate; + $upload_rate = $data->result->stats->upload_rate; + $seed_count = $data->result->filters->state[2]; + $leech_count = $data->result->filters->state[1]; + $html = ' + + + '; + return json_encode(['status' => $active, 'html' => $html]); + } + public function getDetails($jar) + { + $config = $this->config; + $url = $config->url; + $url = rtrim($url, '/'); + $api_url = $url.'/json'; + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); + $res = $client->request('POST', $api_url, [ + 'body' => '{"method": "web.update_ui", "params": [["none"], {}], "id": 1}', + 'cookies' => $jar, + 'headers' => ['content-type' => 'application/json', 'Accept' => 'application/json'] + ]); + return $res; + } + public function login() + { + $config = $this->config; + $url = $config->url; + $password = $config->password; + $url = rtrim($url, '/'); + $api_url = $url.'/json'; + $jar = new \GuzzleHttp\Cookie\CookieJar(); + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); + $res = $client->request('POST', $api_url, [ + 'body' => '{"method": "auth.login", "params": ["'.$password.'"], "id": 1}', + 'cookies' => $jar, + 'headers' => ['content-type' => 'application/json', 'Accept' => 'application/json'] + ]); + return array($res,$jar); + } + + function formatBytes($bytes, $precision = 2) { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + // Uncomment one of the following alternatives + $bytes /= pow(1024, $pow); + // $bytes /= (1 << (10 * $pow)); + + return round($bytes, $precision) . ' ' . $units[$pow] . 'ps'; + } +} diff --git a/resources/views/supportedapps/deluge.blade.php b/resources/views/supportedapps/deluge.blade.php new file mode 100644 index 00000000..70f86a5d --- /dev/null +++ b/resources/views/supportedapps/deluge.blade.php @@ -0,0 +1,11 @@ +

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

+
+ +
+ + {!! Form::text('config[password]', null, array('placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item')) !!} +
+
+ +
+
From a161210a4a38761dd45ea6d7dbea31ef9a81cd8d Mon Sep 17 00:00:00 2001 From: Scott Carlson Date: Fri, 8 Jun 2018 15:39:57 -0500 Subject: [PATCH 2/2] Moving Deluge to Enhanced List --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4698a872..33ab4a1c 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,7 @@ Supported applications are recognized by the title of the application as entered **Enhanced** - CouchPotato +- Deluge - NZBGet - Pihole - PlexPy @@ -43,7 +44,6 @@ Supported applications are recognized by the title of the application as entered **Foundation** - AirSonic - Cardigann -- Deluge - DokuWiki - Duplicati - Emby