-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathPackageStartInstallForm.class.php
More file actions
executable file
·252 lines (212 loc) · 7.95 KB
/
PackageStartInstallForm.class.php
File metadata and controls
executable file
·252 lines (212 loc) · 7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
namespace wcf\acp\form;
use wcf\acp\page\PackageInstallationConfirmPage;
use wcf\data\package\installation\queue\PackageInstallationQueue;
use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
use wcf\data\package\Package;
use wcf\form\AbstractForm;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
use wcf\system\package\PackageArchive;
use wcf\system\package\validation\PackageValidationException;
use wcf\system\package\validation\PackageValidationManager;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\FileUtil;
use wcf\util\HeaderUtil;
/**
* Shows the package install and update form.
*
* @author Marcel Werk
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class PackageStartInstallForm extends AbstractForm
{
/**
* @inheritDoc
*/
public $activeMenuItem = 'wcf.acp.menu.link.package.install';
/**
* updated package object
* @var ?Package
*/
public $package;
/**
* data of the uploaded package
* @var string[]
*/
public $uploadPackage = [];
/**
* archive of the installation/update package
* @var PackageArchive
*/
public $archive;
/**
* package installation/update queue
* @var PackageInstallationQueue
*/
public $queue;
/**
* location of the package uploaded via style import
* @var string
*/
public $stylePackageImportLocation = '';
#[\Override]
public function readParameters()
{
parent::readParameters();
$this->stylePackageImportLocation = WCF::getSession()->getVar('stylePackageImportLocation');
if ($this->stylePackageImportLocation) {
$_POST['t'] = WCF::getSession()->getSecurityToken();
}
}
#[\Override]
public function readFormParameters()
{
parent::readFormParameters();
if (!$this->stylePackageImportLocation) {
if (isset($_FILES['uploadPackage'])) {
$this->uploadPackage = $_FILES['uploadPackage'];
}
}
}
#[\Override]
public function validate()
{
parent::validate();
if ($this->stylePackageImportLocation) {
if (ENABLE_ENTERPRISE_MODE && !WCF::getUser()->hasOwnerAccess()) {
throw new IllegalLinkException();
}
try {
$this->validateUploadPackage($this->stylePackageImportLocation);
} catch (UserInputException $e) {
WCF::getSession()->unregister('stylePackageImportLocation');
throw $e;
}
} elseif (!empty($this->uploadPackage['name'])) {
if (ENABLE_ENTERPRISE_MODE && !WCF::getUser()->hasOwnerAccess()) {
throw new IllegalLinkException();
}
$this->validateUploadPackage();
} else {
throw new UserInputException('uploadPackage');
}
}
/**
* Validates the upload package input.
*
* @return void
* @throws UserInputException
*/
protected function validateUploadPackage(string $filename = '')
{
$this->activeTabMenuItem = 'upload';
if (empty($filename)) {
if (empty($this->uploadPackage['tmp_name'])) {
if (isset($_FILES['uploadPackage']) && $_FILES['uploadPackage']['error'] === \UPLOAD_ERR_INI_SIZE) {
throw new UserInputException('uploadPackage', 'exceedsPhpLimit');
}
throw new UserInputException('uploadPackage', 'uploadFailed');
}
// get filename
$this->uploadPackage['name'] = FileUtil::getTemporaryFilename(
'package_',
\preg_replace('!^.*(?=\.(?:tar\.gz|tgz|tar)$)!i', '', \basename($this->uploadPackage['name']))
);
if (!@\move_uploaded_file($this->uploadPackage['tmp_name'], $this->uploadPackage['name'])) {
throw new UserInputException('uploadPackage', 'uploadFailed');
}
$filename = $this->uploadPackage['name'];
}
if (!PackageValidationManager::getInstance()->validate($filename, false)) {
$exception = PackageValidationManager::getInstance()->getException();
if ($exception instanceof PackageValidationException) {
WCF::getTPL()->assign([
'validationException' => $exception,
]);
throw new UserInputException('uploadPackage', 'noValidPackage');
}
}
$requirements = PackageValidationManager::getInstance()
->getPackageValidationArchive()
->getArchive()
->getOpenRequirements();
foreach ($requirements as $requirement) {
if ($requirement['name'] !== 'com.woltlab.wcf') {
continue;
}
if ($requirement['action'] !== 'update') {
continue;
}
if (!isset($requirement['file'])) {
continue;
}
$existingVersion = \explode('.', $requirement['existingVersion']);
$minversion = \explode('.', $requirement['minversion']);
if (
$existingVersion[0] !== $minversion[0]
|| $existingVersion[1] !== $minversion[1]
) {
throw new UserInputException('uploadPackage', 'majorUpgrade');
}
}
$this->package = PackageValidationManager::getInstance()->getPackageValidationArchive()->getPackage();
}
#[\Override]
public function save()
{
parent::save();
// get new process no
$processNo = PackageInstallationQueue::getNewProcessNo();
// obey foreign key
$packageID = $this->package ? $this->package->packageID : null;
$archive = null;
if ($this->stylePackageImportLocation) {
$archive = $this->stylePackageImportLocation;
} elseif (!empty($this->uploadPackage['tmp_name'])) {
$archive = $this->uploadPackage['name'];
}
// insert queue
$isApplication = PackageValidationManager::getInstance()->getPackageValidationArchive()->getArchive()->getPackageInfo('isApplication');
$this->queue = PackageInstallationQueueEditor::create([
'processNo' => $processNo,
'userID' => WCF::getUser()->userID,
'package' => PackageValidationManager::getInstance()->getPackageValidationArchive()->getArchive()->getPackageInfo('name'),
'packageName' => PackageValidationManager::getInstance()->getPackageValidationArchive()->getArchive()->getLocalizedPackageInfo('packageName'),
'packageID' => $packageID,
'archive' => $archive,
'action' => $this->package != null ? 'update' : 'install',
'isApplication' => !$isApplication ? '0' : '1',
]);
$this->saved();
HeaderUtil::redirect(LinkHandler::getInstance()->getControllerLink(
PackageInstallationConfirmPage::class,
[
'queueID' => $this->queue->queueID,
]
));
exit;
}
#[\Override]
public function assignVariables()
{
parent::assignVariables();
$majorMinorVersion = \preg_replace('/^(\d+\.\d+)\..*$/', '\\1', \WCF_VERSION);
WCF::getTPL()->assign([
'package' => $this->package,
'installingImportedStyle' => $this->stylePackageImportLocation != '',
'majorMinorVersion' => $majorMinorVersion,
]);
}
#[\Override]
public function show()
{
if (!WCF::getSession()->getPermission('admin.configuration.package.canInstallPackage') && !WCF::getSession()->getPermission('admin.configuration.package.canUpdatePackage')) {
throw new PermissionDeniedException();
}
parent::show();
}
}