|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\BasePageController; |
|
6
|
|
|
use Blacklight\NZBExport; |
|
7
|
|
|
use Blacklight\NZBImport; |
|
8
|
|
|
use Blacklight\Releases; |
|
9
|
|
|
use Blacklight\utility\Utility; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
|
|
12
|
|
|
class AdminNzbController extends BasePageController |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param \Illuminate\Http\Request $request |
|
16
|
|
|
* |
|
17
|
|
|
* @throws \Exception |
|
18
|
|
|
*/ |
|
19
|
|
|
public function import(Request $request) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->setAdminPrefs(); |
|
22
|
|
|
|
|
23
|
|
|
$filesToProcess = []; |
|
24
|
|
|
if ($this->isPostBack()) { |
|
25
|
|
|
$useNzbName = false; |
|
26
|
|
|
$deleteNZB = true; |
|
27
|
|
|
// Get the list of NZB files from php /tmp folder if nzb files were uploaded. |
|
28
|
|
|
if (isset($_FILES['uploadedfiles'])) { |
|
29
|
|
|
foreach ($_FILES['uploadedfiles']['error'] as $key => $error) { |
|
30
|
|
|
if ($error === UPLOAD_ERR_OK) { |
|
31
|
|
|
$tmp_name = $_FILES['uploadedfiles']['tmp_name'][$key]; |
|
32
|
|
|
$name = $_FILES['uploadedfiles']['name'][$key]; |
|
|
|
|
|
|
33
|
|
|
$filesToProcess[] = $tmp_name; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
} else { |
|
37
|
|
|
|
|
38
|
|
|
// Check if the user wants to use the file name as the release name. |
|
39
|
|
|
$useNzbName = ($request->has('usefilename') && $request->input('usefilename') === 'on'); |
|
40
|
|
|
|
|
41
|
|
|
// Check if the user wants to delete the NZB file when done importing. |
|
42
|
|
|
$deleteNZB = ($request->has('deleteNZB') && $request->input('deleteNZB') === 'on'); |
|
43
|
|
|
|
|
44
|
|
|
// Get the path the user set in the browser if he put one. |
|
45
|
|
|
$path = ($request->has('folder') ? $request->input('folder') : ''); |
|
46
|
|
|
if (substr($path, \strlen($path) - 1) !== DS) { |
|
47
|
|
|
$path .= DS; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// Get the files from the user specified path. |
|
51
|
|
|
$filesToProcess = glob($path.'*.nzb'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (\count($filesToProcess) > 0) { |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
// Create a new instance of NZBImport and send it the file locations. |
|
57
|
|
|
$NZBImport = new NZBImport(['Browser' => true, 'Settings' => null]); |
|
58
|
|
|
|
|
59
|
|
|
$this->smarty->assign( |
|
|
|
|
|
|
60
|
|
|
'output', |
|
61
|
|
|
$NZBImport->beginImport($filesToProcess, $useNzbName, $deleteNZB) |
|
|
|
|
|
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$meta_title = $title = 'Import Nzbs'; |
|
67
|
|
|
$content = $this->smarty->fetch('nzb-import.tpl'); |
|
|
|
|
|
|
68
|
|
|
$this->smarty->assign(compact('title', 'meta_title', 'content')); |
|
69
|
|
|
$this->adminrender(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param \Illuminate\Http\Request $request |
|
74
|
|
|
* |
|
75
|
|
|
* @throws \Exception |
|
76
|
|
|
*/ |
|
77
|
|
|
public function export(Request $request) |
|
78
|
|
|
{ |
|
79
|
|
|
if (Utility::isCLI()) { |
|
80
|
|
|
exit('This script is only for exporting from the web, use the script in misc/testing'. |
|
|
|
|
|
|
81
|
|
|
PHP_EOL); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->setAdminPrefs(); |
|
85
|
|
|
$rel = new Releases(); |
|
86
|
|
|
|
|
87
|
|
|
if ($this->isPostBack()) { |
|
88
|
|
|
$path = $request->input('folder'); |
|
89
|
|
|
$postFrom = ($request->input('postfrom') ?? ''); |
|
90
|
|
|
$postTo = ($request->input('postto') ?? ''); |
|
91
|
|
|
$group = ($request->input('group') === '-1' ? 0 : (int) $request->input('group')); |
|
92
|
|
|
$gzip = ($request->input('gzip') === '1'); |
|
93
|
|
|
|
|
94
|
|
|
if ($path !== '') { |
|
95
|
|
|
$NE = new NZBExport([ |
|
96
|
|
|
'Browser' => true, 'Settings' => null, |
|
97
|
|
|
'Releases' => $rel, |
|
98
|
|
|
]); |
|
99
|
|
|
$retVal = $NE->beginExport( |
|
100
|
|
|
[ |
|
101
|
|
|
$path, |
|
102
|
|
|
$postFrom, |
|
103
|
|
|
$postTo, |
|
104
|
|
|
$group, |
|
105
|
|
|
$gzip, |
|
106
|
|
|
] |
|
107
|
|
|
); |
|
108
|
|
|
} else { |
|
109
|
|
|
$retVal = 'Error, a path is required!'; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$this->smarty->assign( |
|
113
|
|
|
[ |
|
114
|
|
|
'folder' => $path, |
|
115
|
|
|
'output' => $retVal, |
|
116
|
|
|
'fromdate' => $postFrom, |
|
117
|
|
|
'todate' => $postTo, |
|
118
|
|
|
'group' => $request->input('group'), |
|
119
|
|
|
'gzip' => $request->input('gzip'), |
|
120
|
|
|
] |
|
121
|
|
|
); |
|
122
|
|
|
} else { |
|
123
|
|
|
$this->smarty->assign( |
|
124
|
|
|
[ |
|
125
|
|
|
'fromdate' => $rel->getEarliestUsenetPostDate(), |
|
126
|
|
|
'todate' => $rel->getLatestUsenetPostDate(), |
|
127
|
|
|
] |
|
128
|
|
|
); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
$meta_title = $title = 'Export Nzbs'; |
|
132
|
|
|
$this->smarty->assign( |
|
133
|
|
|
[ |
|
134
|
|
|
'gziplist' => [1 => 'True', 0 => 'False'], |
|
135
|
|
|
'grouplist' => $rel->getReleasedGroupsForSelect(true), |
|
136
|
|
|
] |
|
137
|
|
|
); |
|
138
|
|
|
$content = $this->smarty->fetch('nzb-export.tpl'); |
|
139
|
|
|
$this->smarty->assign(compact('title', 'meta_title', 'content')); |
|
140
|
|
|
$this->adminrender(); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|