From edda48f0666d9178a64f6e9bdfeb93b2f4bd0118 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 19 Apr 2018 14:51:03 +0200 Subject: [PATCH] Add NzbController --- Changelog | 1 + app/Http/Controllers/Admin/NzbController.php | 153 +++++++++++++++++++ public/oldadmin/nzb-export.php | 72 --------- public/oldadmin/nzb-import.php | 61 -------- routes/web.php | 4 + 5 files changed, 158 insertions(+), 133 deletions(-) create mode 100644 app/Http/Controllers/Admin/NzbController.php delete mode 100644 public/oldadmin/nzb-export.php delete mode 100644 public/oldadmin/nzb-import.php diff --git a/Changelog b/Changelog index 224eb36eb..b0bf70dd1 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-19 DariusIII + * Chg: Add NzbController * Chg: Add MusicController * Chg: Add MovieController * Chg: Add MenuController diff --git a/app/Http/Controllers/Admin/NzbController.php b/app/Http/Controllers/Admin/NzbController.php new file mode 100644 index 000000000..2387ca0c0 --- /dev/null +++ b/app/Http/Controllers/Admin/NzbController.php @@ -0,0 +1,153 @@ +setAdminPrefs(); + + $filesToProcess = []; + if ($this->isPostBack()) { + $useNzbName = false; + $deleteNZB = true; + // Get the list of NZB files from php /tmp folder if nzb files were uploaded. + if (isset($_FILES['uploadedfiles'])) { + foreach ($_FILES['uploadedfiles']['error'] as $key => $error) { + if ($error === UPLOAD_ERR_OK) { + $tmp_name = $_FILES['uploadedfiles']['tmp_name'][$key]; + $name = $_FILES['uploadedfiles']['name'][$key]; + $filesToProcess[] = $tmp_name; + } + } + } else { + + // Check if the user wants to use the file name as the release name. + $useNzbName = ($request->has('usefilename') && $request->input('usefilename') === 'on'); + + // Check if the user wants to delete the NZB file when done importing. + $deleteNZB = ($request->has('deleteNZB') && $request->input('deleteNZB') === 'on'); + + // Get the path the user set in the browser if he put one. + $path = ($request->has('folder') ? $request->input('folder') : ''); + if (substr($path, \strlen($path) - 1) !== DS) { + $path .= DS; + } + + // Get the files from the user specified path. + $filesToProcess = glob($path.'*.nzb'); + } + + if (\count($filesToProcess) > 0) { + + // Create a new instance of NZBImport and send it the file locations. + $NZBImport = new NZBImport(['Browser' => true, 'Settings' => $this->pdo]); + + $this->smarty->assign( + 'output', + $NZBImport->beginImport($filesToProcess, $useNzbName, $deleteNZB) + ); + } + } + + $title = 'Import Nzbs'; + $content = $this->smarty->fetch('nzb-import.tpl'); + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @throws \Exception + */ + public function export(Request $request) + { + if (Utility::isCLI()) { + exit('This script is only for exporting from the web, use the script in misc/testing'. + PHP_EOL); + } + + $this->setAdminPrefs(); + $rel = new Releases(['Settings' => $this->pdo]); + + if ($this->isPostBack()) { + + $path = $request->input('folder'); + $postFrom = ($request->input('postfrom') ?? ''); + $postTo = ($request->input('postto') ?? ''); + $group = ($request->input('group') === '-1' ? 0 : (int) $request->input('group')); + $gzip = ($request->input('gzip') === '1'); + + if ($path !== '') { + $NE = new NZBExport([ + 'Browser' => true, 'Settings' => $this->pdo, + 'Releases' => $rel, + ]); + $retVal = $NE->beginExport( + [ + $path, + $postFrom, + $postTo, + $group, + $gzip, + ] + ); + } else { + $retVal = 'Error, a path is required!'; + } + + $this->smarty->assign( + [ + 'folder' => $path, + 'output' => $retVal, + 'fromdate' => $postFrom, + 'todate' => $postTo, + 'group' => $request->input('group'), + 'gzip' => $request->input('gzip'), + ] + ); + } else { + $this->smarty->assign( + [ + 'fromdate' => $rel->getEarliestUsenetPostDate(), + 'todate' => $rel->getLatestUsenetPostDate(), + ] + ); + } + + $title = 'Export Nzbs'; + $this->smarty->assign( + [ + 'gziplist' => [1 => 'True', 0 => 'False'], + 'grouplist' => $rel->getReleasedGroupsForSelect(true), + ] + ); + $content = $this->smarty->fetch('nzb-export.tpl'); + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + $this->adminrender(); + } +} diff --git a/public/oldadmin/nzb-export.php b/public/oldadmin/nzb-export.php deleted file mode 100644 index 0bb2a220f..000000000 --- a/public/oldadmin/nzb-export.php +++ /dev/null @@ -1,72 +0,0 @@ -setAdminPrefs(); -$rel = new Releases(['Settings' => $page->pdo]); - -if ($page->isPostBack()) { - $retVal = $path = ''; - - $path = request()->input('folder'); - $postFrom = (request()->input('postfrom') ?? ''); - $postTo = (request()->input('postto') ?? ''); - $group = (request()->input('group') === '-1' ? 0 : (int) request()->input('group')); - $gzip = (request()->input('gzip') === '1'); - - if ($path !== '') { - $NE = new NZBExport([ - 'Browser' => true, 'Settings' => $page->pdo, - 'Releases' => $rel, - ]); - $retVal = $NE->beginExport( - [ - $path, - $postFrom, - $postTo, - $group, - $gzip, - ] - ); - } else { - $retVal = 'Error, a path is required!'; - } - - $page->smarty->assign( - [ - 'folder' => $path, - 'output' => $retVal, - 'fromdate' => $postFrom, - 'todate' => $postTo, - 'group' => request()->input('group'), - 'gzip' => request()->input('gzip'), - ] - ); -} else { - $page->smarty->assign( - [ - 'fromdate' => $rel->getEarliestUsenetPostDate(), - 'todate' => $rel->getLatestUsenetPostDate(), - ] - ); -} - -$page->title = 'Export Nzbs'; -$page->smarty->assign( - [ - 'gziplist' => [1 => 'True', 0 => 'False'], - 'grouplist' => $rel->getReleasedGroupsForSelect(true), - ] -); -$page->content = $page->smarty->fetch('nzb-export.tpl'); -$page->adminrender(); diff --git a/public/oldadmin/nzb-import.php b/public/oldadmin/nzb-import.php deleted file mode 100644 index 3622a32fd..000000000 --- a/public/oldadmin/nzb-import.php +++ /dev/null @@ -1,61 +0,0 @@ -setAdminPrefs(); - -$filesToProcess = []; -if ($page->isPostBack()) { - $useNzbName = false; - $deleteNZB = true; - // Get the list of NZB files from php /tmp folder if nzb files were uploaded. - if (isset($_FILES['uploadedfiles'])) { - foreach ($_FILES['uploadedfiles']['error'] as $key => $error) { - if ($error === UPLOAD_ERR_OK) { - $tmp_name = $_FILES['uploadedfiles']['tmp_name'][$key]; - $name = $_FILES['uploadedfiles']['name'][$key]; - $filesToProcess[] = $tmp_name; - } - } - } else { - - // Check if the user wants to use the file name as the release name. - $useNzbName = (request()->has('usefilename') && request()->input('usefilename') === 'on'); - - // Check if the user wants to delete the NZB file when done importing. - $deleteNZB = (request()->has('deleteNZB') && request()->input('deleteNZB') === 'on'); - - // Get the path the user set in the browser if he put one. - $path = (request()->has('folder') ? request()->input('folder') : ''); - if (substr($path, strlen($path) - 1) !== DS) { - $path .= DS; - } - - // Get the files from the user specified path. - $filesToProcess = glob($path.'*.nzb'); - } - - if (count($filesToProcess) > 0) { - - // Create a new instance of NZBImport and send it the file locations. - $NZBImport = new NZBImport(['Browser' => true, 'Settings' => $page->pdo]); - - $page->smarty->assign( - 'output', - $NZBImport->beginImport($filesToProcess, $useNzbName, $deleteNZB) - ); - } -} - -$page->title = 'Import Nzbs'; -$page->content = $page->smarty->fetch('nzb-import.tpl'); -$page->adminrender(); diff --git a/routes/web.php b/routes/web.php index 789a86e44..8e9569d40 100644 --- a/routes/web.php +++ b/routes/web.php @@ -311,5 +311,9 @@ Route::middleware('admin')->prefix('admin')->group(function () { Route::post('music-list', 'MusicController@index'); Route::get('music-edit', 'MusicController@edit'); Route::post('music-edit', 'MusicController@edit'); + Route::get('nzb-import', 'NzbController@import'); + Route::post('nzb-import', 'NzbController@import'); + Route::get('nzb-export', 'NzbController@export'); + Route::post('nzb-export', 'NzbController@export'); }); });