Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ManagementControlBackupDownloadLogic | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateImpl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
executeImpl | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\ManagementControl; |
6 | |
7 | use PeServer\App\Models\Domain\AppArchiver; |
8 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
9 | use PeServer\Core\Collection\Arr; |
10 | use PeServer\Core\Collection\OrderBy; |
11 | use PeServer\Core\Http\HttpStatus; |
12 | use PeServer\Core\IO\File; |
13 | use PeServer\Core\IO\Path; |
14 | use PeServer\Core\Mime; |
15 | use PeServer\Core\Mvc\LogicCallMode; |
16 | use PeServer\Core\Mvc\LogicParameter; |
17 | use PeServer\Core\SizeConverter; |
18 | use PeServer\Core\Throws\HttpStatusException; |
19 | |
20 | class ManagementControlBackupDownloadLogic extends PageLogicBase |
21 | { |
22 | public function __construct(LogicParameter $parameter, private AppArchiver $appArchiver) |
23 | { |
24 | parent::__construct($parameter); |
25 | } |
26 | |
27 | protected function validateImpl(LogicCallMode $callMode): void |
28 | { |
29 | //NOP |
30 | } |
31 | |
32 | protected function executeImpl(LogicCallMode $callMode): void |
33 | { |
34 | $unsafeFileName = $this->getRequest('file_name'); |
35 | $safeFileName = Path::getFileName($unsafeFileName); |
36 | if ($safeFileName !== $unsafeFileName) { |
37 | $this->logger->warn('これはもう攻撃: {0}', $unsafeFileName); |
38 | throw new HttpStatusException(HttpStatus::NotFound); |
39 | } |
40 | |
41 | $filePath = Path::combine($this->appArchiver->getDirectory(), $safeFileName); |
42 | if (!File::exists($filePath)) { |
43 | throw new HttpStatusException(HttpStatus::NotFound); |
44 | } |
45 | |
46 | $this->setDownloadContent(Mime::ZIP, $safeFileName, File::readContent($filePath)); |
47 | } |
48 | } |