1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Api; |
4
|
|
|
|
5
|
|
|
use Apps\Model\Basic\Antivirus; |
6
|
|
|
use Extend\Core\Arch\ApiController; |
7
|
|
|
use Ffcms\Core\App; |
8
|
|
|
use Ffcms\Core\Exception\ForbiddenException; |
9
|
|
|
use Ffcms\Core\Helper\FileSystem\File; |
10
|
|
|
use Ffcms\Core\Helper\Type\Str; |
11
|
|
|
use Ffcms\Core\Helper\Url; |
12
|
|
|
|
13
|
|
|
class Main extends ApiController |
14
|
|
|
{ |
15
|
|
|
public function actionIndex() |
16
|
|
|
{ |
17
|
|
|
$this->setJsonHeader(); |
18
|
|
|
return json_encode(['status' => 1, 'value' => 'Welcome, man!']); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Elfinder injector file listing |
23
|
|
|
* @throws ForbiddenException |
24
|
|
|
*/ |
25
|
|
|
public function actionFiles() |
26
|
|
|
{ |
27
|
|
|
$user = App::$User->identity(); |
28
|
|
|
|
29
|
|
|
if ($user === null || !$user->isAuth() || !$user->getRole()->can('admin/main/files')) { |
30
|
|
|
throw new ForbiddenException('This action is not allowed!'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// legacy lib can throw some shits |
34
|
|
|
error_reporting(0); |
35
|
|
|
$this->setJsonHeader(); |
36
|
|
|
|
37
|
|
|
$connector = new \elFinderConnector(new \elFinder([ |
38
|
|
|
'locale' => '', |
39
|
|
|
'roots' => [ |
40
|
|
|
['driver' => 'LocalFileSystem', 'path' => root . '/upload/', 'URL' => App::$Alias->scriptUrl . '/upload/'] |
41
|
|
|
] |
42
|
|
|
])); |
43
|
|
|
|
44
|
|
|
$connector->run(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Make scan and display scan iteration data |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function actionAntivirus() |
52
|
|
|
{ |
53
|
|
|
$scanner = new Antivirus(); |
54
|
|
|
|
55
|
|
|
$this->setJsonHeader(); |
56
|
|
|
return json_encode($scanner->make()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Remove previous scan files |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function actionAntivirusclear() |
64
|
|
|
{ |
65
|
|
|
File::remove('/Private/Antivirus/Infected.json'); |
66
|
|
|
File::remove('/Private/Antivirus/ScanFiles.json'); |
67
|
|
|
|
68
|
|
|
$this->setJsonHeader(); |
69
|
|
|
return json_encode(['status' => 1]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Show scan results |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function actionAntivirusresults() |
77
|
|
|
{ |
78
|
|
|
$response = null; |
|
|
|
|
79
|
|
|
if (!File::exist('/Private/Antivirus/Infected.json')) { |
80
|
|
|
$response = ['status' => 0]; |
81
|
|
|
} else { |
82
|
|
|
$data = json_decode(File::read('/Private/Antivirus/Infected.json')); |
83
|
|
|
$compile = []; |
84
|
|
|
foreach ($data as $file => $sign) { |
85
|
|
|
$file = Str::replace('\\', '/', Str::sub($file, strlen(root))); |
86
|
|
|
$compile[$file][] = $sign; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$response = ['status' => 1, 'data' => $compile]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->setJsonHeader(); |
93
|
|
|
return json_encode($response); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Download news from ffcms.org server and show it with caching & saving |
98
|
|
|
* @return string|null |
99
|
|
|
*/ |
100
|
|
|
public function actionNews() |
101
|
|
|
{ |
102
|
|
|
$this->setJsonHeader(); |
103
|
|
|
// get ffcms news if cache is not available |
104
|
|
|
$news = null; |
|
|
|
|
105
|
|
|
if (App::$Cache->get('download.ffcms.api.news.'.$this->lang) !== null) { |
106
|
|
|
$news = App::$Cache->get('download.ffcms.api.news.'.$this->lang); |
107
|
|
|
} else { |
108
|
|
|
$news = Url::download('https://ffcms.org/api/api/news?lang=' . $this->lang); |
109
|
|
|
if ($news !== null && !Str::likeEmpty($news)) { |
110
|
|
|
App::$Cache->set('download.ffcms.api.news.'.$this->lang, $news, 3600 * 12); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $news; |
115
|
|
|
} |
116
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.