diff --git a/Blacklight/CouchPotato.php b/Blacklight/CouchPotato.php index 13a939533..4e50783b9 100755 --- a/Blacklight/CouchPotato.php +++ b/Blacklight/CouchPotato.php @@ -50,9 +50,9 @@ class CouchPotato /** * CouchPotato constructor. * - * @param \Blacklight\http\BasePage $page + * @param \App\Http\Controllers\BasePageController $page */ - public function __construct(BasePage $page) + public function __construct($page) { $this->cpurl = ! empty($page->userdata['cp_url']) ? $page->userdata['cp_url'] : ''; $this->cpapi = ! empty($page->userdata['cp_api']) ? $page->userdata['cp_api'] : ''; diff --git a/Blacklight/NZBGet.php b/Blacklight/NZBGet.php index 76f4b267b..a9f956382 100755 --- a/Blacklight/NZBGet.php +++ b/Blacklight/NZBGet.php @@ -76,7 +76,7 @@ class NZBGet * Construct. * Set up full URL. * - * @var \BasePage + * @var \App\Http\Controllers\BasePageController * @throws \Exception */ public function __construct(&$page) diff --git a/Blacklight/SABnzbd.php b/Blacklight/SABnzbd.php index eb5c2e9b4..b528279f4 100755 --- a/Blacklight/SABnzbd.php +++ b/Blacklight/SABnzbd.php @@ -93,14 +93,15 @@ class SABnzbd /** * SABnzbd constructor. * + * @param \App\Http\Controllers\BasePageController $page + * * @throws \Exception */ - public function __construct() + public function __construct($page) { - $user = Auth::user(); - $this->uid = Auth::id(); - $this->rsstoken = $user['rsstoken']; - $this->serverurl = url('/'); + $this->uid = $page->userdata['id']; + $this->rsstoken = $page->userdata['rsstoken']; + $this->serverurl = $page->serverurl; $this->client = new Client(['verify' => false]); // Set up properties. @@ -111,14 +112,14 @@ class SABnzbd $this->apikey = $_COOKIE['sabnzbd_'.$this->uid.'__apikey']; $this->priority = $_COOKIE['sabnzbd_'.$this->uid.'__priority'] ?? 0; $this->apikeytype = $_COOKIE['sabnzbd_'.$this->uid.'__apitype'] ?? 1; - } elseif (! empty($user['sabapikey']) && ! empty($user['saburl'])) { - $this->url = $user['saburl']; - $this->apikey = $user['sabapikey']; - $this->priority = $user['sabpriority']; - $this->apikeytype = $user['sabapikeytype']; + } elseif (! empty($page->userdata['sabapikey']) && ! empty($page->userdata['saburl'])) { + $this->url = $page->userdata['saburl']; + $this->apikey = $page->userdata['sabapikey']; + $this->priority = $page->userdata['sabpriority']; + $this->apikeytype = $page->userdata['sabapikeytype']; } $this->integrated = self::INTEGRATION_TYPE_USER; - switch ((int) $user['queuetype']) { + switch ((int) $page->userdata['queuetype']) { case 1: case 2: $this->integratedBool = true; @@ -132,7 +133,7 @@ class SABnzbd case self::INTEGRATION_TYPE_NONE: $this->integrated = self::INTEGRATION_TYPE_NONE; // This is for nzbget. - if ($user['queuetype'] === 2) { + if ($page->userdata['queuetype'] === 2) { $this->integratedBool = true; } break; diff --git a/Changelog b/Changelog index d1c83db32..77501dfa4 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-16 DariusIII + * Chg: Add controller for send to functions * Chg: Optimize queue controller * Chg: Add NZBGetController and route * Chg: Update headermenu.tpl in all themes diff --git a/app/Http/Controllers/SendReleaseController.php b/app/Http/Controllers/SendReleaseController.php new file mode 100644 index 000000000..1c843019b --- /dev/null +++ b/app/Http/Controllers/SendReleaseController.php @@ -0,0 +1,124 @@ +setPrefs(); + if (empty($request->input('id'))) { + $this->show404(); + } else { + $cp = new CouchPotato($this); + + if (empty($cp->cpurl)) { + $this->show404(); + } + + if (empty($cp->cpapi)) { + $this->show404(); + } + $id = $request->input('id'); + $cp->sendToCouchPotato($id); + } + } + + /** + * @param \Illuminate\Http\Request $request + * + * @throws \Exception + */ + public function sabNzbd(Request $request) + { + $this->setPrefs(); + if (empty($request->input('id'))) { + $this->show404(); + } + + $sab = new SABnzbd($this); + + if (empty($sab->url)) { + $this->show404(); + } + + if (empty($sab->apikey)) { + $this->show404(); + } + + $guid = $request->input('id'); + + $sab->sendToSab($guid); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @throws \Exception + */ + public function nzbGet(Request $request) + { + $this->setPrefs(); + if (empty($request->input('id'))) { + $this->show404(); + } + + $nzbget = new NZBGet($this); + + if (empty($nzbget->url)) { + $this->show404(); + } + + if (empty($nzbget->username)) { + $this->show404(); + } + + if (empty($nzbget->password)) { + $this->show404(); + } + + $guid = $request->input('id'); + + $nzbget->sendURLToNZBGet($guid); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @throws \Exception + */ + public function queue(Request $request) + { + $this->setPrefs(); + if (empty($request->input('id'))) { + $this->show404(); + } + + $user = User::find(Auth::id()); + if ((int) $user['queuetype'] !== 2) { + $sab = new SABnzbd($this); + if (empty($sab->url)) { + $this->show404(); + } + if (empty($sab->apikey)) { + $this->show404(); + } + $sab->sendToSab($request->input('id')); + } elseif ((int) $user['queuetype'] === 2) { + $nzbget = new NZBGet($this); + $nzbget->sendURLToNZBGet($request->input('id')); + } + } +} diff --git a/public/pages/sabqueuedata.php b/public/pages/sabqueuedata.php deleted file mode 100644 index e3f5e4a20..000000000 --- a/public/pages/sabqueuedata.php +++ /dev/null @@ -1,76 +0,0 @@ -show403(); -} - -$sab = new SABnzbd($page); - -$output = ''; - -$json = $sab->getAdvQueue(); - -if ($json !== false) { - $obj = json_decode($json); - $queue = $obj->{'queue'}; - $count = 1; - - $output .= - "
-
Speed:
".$obj->{'speed'}."B/s
-
Queued:
".round($obj->{'mbleft'}, 2).'MB / '.round($obj->{'mb'}, 2).'MB'."
-
Status:
".ucwords(strtolower($obj->{'state'}))."
-
Free (temp):
".round($obj->{'diskspace1'})."GB
-
Free Space:
".round($obj->{'diskspace2'})."GB
-
Stats:
".preg_replace('/\s+\|\s+| /', ',', $obj->{'loadavg'}).'
-
'; - - if (count($queue) > 0) { - $output .= - " - - - - - - - - - - - - - - "; - - foreach ($queue->{'slots'} as $item) { - if (strpos($item->{'filename'}, 'fetch NZB') === false) { - $output .= - ''. - "'. - "'. - "'. - "'. - "'. - "'. - "". - "". - "". - ''; - $count++; - } - } - $output .= - ' -
#NameSizeLeftDoneTime LeftDeletePause allResume all
".$count.'".$item->{'filename'}.'".round($item->{'mb'}, 2).' MB".round($item->{'mbleft'}, 2).' MB".($item->{'mb'} === 0 ? 0 : round(100 - ($item->{'mbleft'} / $item->{'mb'}) * 100)).'%".$item->{'timeleft'}.'DeletePauseResume
'; - } else { - $output .= "

The queue is currently empty.

"; - } -} else { - $output .= "

Error retrieving queue.

"; -} - -echo $output; diff --git a/public/pages/sendtocouch.php b/public/pages/sendtocouch.php deleted file mode 100644 index 42b5dde82..000000000 --- a/public/pages/sendtocouch.php +++ /dev/null @@ -1,24 +0,0 @@ -show403(); -} - -if (empty(request()->input('id'))) { - $page->show404(); -} else { - $cp = new CouchPotato($page); - - if (empty($cp->cpurl)) { - $page->show404(); - } - - if (empty($cp->cpapi)) { - $page->show404(); - } - $id = request()->input('id'); - $cp->sendToCouchPotato($id); -} diff --git a/public/pages/sendtonzbget.php b/public/pages/sendtonzbget.php deleted file mode 100644 index 0a988d462..000000000 --- a/public/pages/sendtonzbget.php +++ /dev/null @@ -1,30 +0,0 @@ -show403(); -} - -if (empty(request()->input('id'))) { - $page->show404(); -} - -$nzbget = new NZBGet($page); - -if (empty($nzbget->url)) { - $page->show404(); -} - -if (empty($nzbget->username)) { - $page->show404(); -} - -if (empty($nzbget->password)) { - $page->show404(); -} - -$guid = request()->input('id'); - -$nzbget->sendURLToNZBGet($guid); diff --git a/public/pages/sendtoqueue.php b/public/pages/sendtoqueue.php deleted file mode 100644 index 8cab9a2fd..000000000 --- a/public/pages/sendtoqueue.php +++ /dev/null @@ -1,29 +0,0 @@ -show403(); -} - -if (empty(request()->input('id'))) { - $page->show404(); -} - -$user = User::find(Auth::id()); -if ((int) $user['queuetype'] !== 2) { - $sab = new SABnzbd($page); - if (empty($sab->url)) { - $page->show404(); - } - if (empty($sab->apikey)) { - $page->show404(); - } - $sab->sendToSab(request()->input('id')); -} elseif ((int) $user['queuetype'] === 2) { - $nzbget = new NZBGet($page); - $nzbget->sendURLToNZBGet(request()->input('id')); -} diff --git a/public/pages/sendtosab.php b/public/pages/sendtosab.php deleted file mode 100644 index 5c3869d29..000000000 --- a/public/pages/sendtosab.php +++ /dev/null @@ -1,26 +0,0 @@ -show403(); -} - -if (empty(request()->input('id'))) { - $page->show404(); -} - -$sab = new SABnzbd($page); - -if (empty($sab->url)) { - $page->show404(); -} - -if (empty($sab->apikey)) { - $page->show404(); -} - -$guid = request()->input('id'); - -$sab->sendToSab($guid); diff --git a/routes/web.php b/routes/web.php index 41dfdd1ea..6ab59a989 100644 --- a/routes/web.php +++ b/routes/web.php @@ -165,6 +165,22 @@ Route::get('nzbgetqueuedata', 'QueueController@nzbget'); Route::post('nzbgetqueuedata', 'QueueController@nzbget'); -Route::get('sabnzbdqueuedata', 'QueueController@sabnzbd'); +Route::get('sabqueuedata', 'QueueController@sabnzbd'); -Route::post('sabnzbdqueuedata', 'QueueController@sabnzbd'); +Route::post('sabqueuedata', 'QueueController@sabnzbd'); + +Route::get('sendtosab', 'SendReleaseController@sabNzbd'); + +Route::post('sendtosab', 'SendReleaseController@sabNzbd'); + +Route::get('sendtonzbget', 'SendReleaseController@nzbGet'); + +Route::post('sendtonzbget', 'SendReleaseController@nzbGet'); + +Route::get('sendtoqueue', 'SendReleaseController@queue'); + +Route::post('sendtoqueue', 'SendReleaseController@queue'); + +Route::get('sendtocouch', 'SendReleaseController@couchPotato'); + +Route::post('sendtocouch', 'SendReleaseController@couchPotato');