setPrefs(); $userData = User::find(Auth::id()); if (! $userData) { $this->show404(); } $this->smarty->assign('user', $userData); $queueType = $error = ''; $queue = null; switch (Settings::settingValue('apps.sabnzbplus.integrationtype')) { case SABnzbd::INTEGRATION_TYPE_NONE: if ($userData['queuetype'] === 2) { $queueType = 'NZBGet'; $queue = new NZBGet($this); } break; case SABnzbd::INTEGRATION_TYPE_USER: switch ((int) $userData['queuetype']) { case 1: $queueType = 'Sabnzbd'; $queue = new SABnzbd($this); break; case 2: $queueType = 'NZBGet'; $queue = new NZBGet($this); break; } break; } if ($queue !== null) { if ($queueType === 'Sabnzbd') { if (empty($queue->url)) { $error = 'ERROR: The Sabnzbd URL is missing!'; } if (empty($queue->apikey)) { if ($error === '') { $error = 'ERROR: The Sabnzbd API key is missing!'; } else { $error .= ' The Sabnzbd API key is missing!'; } } } if ($error === '') { if ($request->has('del')) { $queue->delFromQueue($request->input('del')); } if ($request->has('pause')) { $queue->pauseFromQueue($request->input('pause')); } if ($request->has('resume')) { $queue->resumeFromQueue($request->input('resume')); } if ($request->has('pall')) { $queue->pauseAll(); } if ($request->has('rall')) { $queue->resumeAll(); } $this->smarty->assign('serverURL', $queue->url); } } $this->smarty->assign(['queueType' => $queueType, 'error' => $error, 'user', User::class]); $title = 'Your '.$queueType.' Download Queue'; $meta_title = 'View'.$queueType.' Queue'; $meta_keywords = 'view,'.strtolower($queueType).',queue'; $meta_description = 'View'.$queueType.' Queue'; $content = $this->smarty->fetch('viewqueue.tpl'); $this->smarty->assign([ 'title' => $title, 'content' => $content, 'meta_title' => $meta_title, 'meta_keywords' => $meta_keywords, 'meta_description' => $meta_description, ]); $this->pagerender(); } /** * @throws \Exception */ public function nzbget() { $this->setPrefs(); $nzbGet = new NZBGet($this); $output = ''; $data = $nzbGet->getQueue(); if ($data !== false) { if (\count($data) > 0) { $status = $nzbGet->status(); if ($status !== false) { $output .= "
Avg Speed:
".Utility::bytesToSizeString($status['AverageDownloadRate'], 2)."/s
Speed:
".Utility::bytesToSizeString($status['DownloadRate'], 2)."/s
Limit:
".Utility::bytesToSizeString($status['DownloadLimit'], 2)."/s
Queue Left(no pars):
".Utility::bytesToSizeString($status['RemainingSizeLo'], 2)."
Free Space:
".Utility::bytesToSizeString($status['FreeDiskSpaceMB'] * 1024000, 2)."
Status:
".($status['Download2Paused'] === 1 ? 'Paused' : 'Downloading').'
'; } $count = 1; $output .= ""; foreach ($data as $item) { $output .= ''. "'. "'. "'. "'. "'. "'. "". "". "". ''; $count++; } $output .= '
# Name Size Left(+pars) Done Status Delete Pause all Resume all
".$count.'".$item['NZBName'].'".$item['FileSizeMB'].' MB".$item['RemainingSizeMB'].' MB".($item['FileSizeMB'] === 0 ? 0 : round(100 - ($item['RemainingSizeMB'] / $item['FileSizeMB']) * 100)).'%".($item['ActiveDownloads'] > 0 ? 'Downloading' : 'Paused').'DeletePauseResume
'; } else { $output .= "

The queue is currently empty.

"; } } else { $output .= "

Error retreiving queue.

"; } echo $output; } /** * @throws \Exception */ public function sabnzbd() { $this->setPrefs(); $sab = new SABnzbd($this); $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 .= '
# Name Size Left Done Time Left Delete Pause all Resume 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; } /** * @throws \Exception */ public function nzbVortex() { $this->setPrefs(); try { if (isset($_GET['isAjax'])) { $vortex = new NZBVortex; // I guess we Ajax this way. if (isset($_GET['getOverview'])) { $overview = $vortex->getOverview(); $this->smarty->assign('overview', $overview); $content = $this->smarty->fetch('nzbvortex-ajax.tpl'); echo $content; exit; } if (isset($_GET['addQueue'])) { $nzb = $_GET['addQueue']; $vortex->addQueue($nzb); exit; } if (isset($_GET['resume'])) { $vortex->resume((int) $_GET['resume']); exit; } if (isset($_GET['pause'])) { $vortex->pause((int) $_GET['pause']); exit; } if (isset($_GET['moveup'])) { $vortex->moveUp((int) $_GET['moveup']); exit; } if (isset($_GET['movedown'])) { $vortex->moveDown((int) $_GET['movedown']); exit; } if (isset($_GET['movetop'])) { $vortex->moveTop((int) $_GET['movetop']); exit; } if (isset($_GET['movebottom'])) { $vortex->moveBottom((int) $_GET['movebottom']); exit; } if (isset($_GET['delete'])) { $vortex->delete((int) $_GET['delete']); exit; } if (isset($_GET['filelist'])) { $response = $vortex->getFilelist((int) $_GET['filelist']); echo json_encode($response); exit; } } } catch (\Exception $e) { header('HTTP/1.1 500 Internal Server Error'); printf($e->getMessage()); exit; } $title = 'NZBVortex'; $content = $this->smarty->fetch('nzbvortex.tpl'); $this->smarty->assign( [ 'title' => $title, 'content' => $content, ] ); $this->pagerender(); } }