|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Apps\Model\Admin\Main\EntityDeleteRoute; |
|
6
|
|
|
use Apps\Model\Admin\Main\FormAddRoute; |
|
7
|
|
|
use Extend\Core\Arch\AdminController; |
|
8
|
|
|
use Ffcms\Core\App; |
|
9
|
|
|
use Ffcms\Core\Exception\SyntaxException; |
|
10
|
|
|
use Ffcms\Core\Helper\FileSystem\File; |
|
11
|
|
|
use Ffcms\Core\Helper\Type\Str; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class Main. Admin main controller - index page, settings, file manager, security and etc. |
|
15
|
|
|
* @package Apps\Controller\Admin |
|
16
|
|
|
*/ |
|
17
|
|
|
class Main extends AdminController |
|
18
|
|
|
{ |
|
19
|
|
|
public $type = 'app'; |
|
20
|
|
|
|
|
21
|
|
|
// import heavy actions |
|
22
|
|
|
use Main\ActionIndex { |
|
23
|
|
|
index as actionIndex; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
use Main\ActionSettings { |
|
27
|
|
|
settings as actionSettings; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
use Main\ActionUpdates { |
|
|
|
|
|
|
31
|
|
|
updates as actionUpdates; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
use Main\ActionSessions { |
|
35
|
|
|
sessions as actionSessions; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Main constructor. Disable parent inheritance of typical app version checking |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
parent::__construct(false); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Manage files via elFinder |
|
48
|
|
|
* @return string |
|
49
|
|
|
* @throws SyntaxException |
|
50
|
|
|
*/ |
|
51
|
|
|
public function actionFiles(): ?string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->view->render('files', [ |
|
54
|
|
|
'connector' => App::$Alias->scriptUrl . '/api/main/files?lang=' . $this->request->getLanguage() |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Show antivirus view |
|
60
|
|
|
* @return string |
|
61
|
|
|
* @throws SyntaxException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function actionAntivirus(): ?string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->view->render('antivirus'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Set debugging cookie to current user session |
|
70
|
|
|
*/ |
|
71
|
|
|
public function actionDebugcookie(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$cookieProperty = App::$Properties->get('debug'); |
|
74
|
|
|
setcookie($cookieProperty['cookie']['key'], $cookieProperty['cookie']['value'], strtotime('+1 month'), '/', null, null, true); |
|
75
|
|
|
$this->response->redirect('/'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* List available routes |
|
80
|
|
|
* @return string |
|
81
|
|
|
* @throws SyntaxException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function actionRouting(): ?string |
|
84
|
|
|
{ |
|
85
|
|
|
$routingMap = App::$Properties->getAll('Routing'); |
|
86
|
|
|
|
|
87
|
|
|
return $this->view->render('routing', [ |
|
88
|
|
|
'routes' => $routingMap |
|
89
|
|
|
]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Show add form for routing |
|
94
|
|
|
* @return string |
|
95
|
|
|
* @throws SyntaxException |
|
96
|
|
|
*/ |
|
97
|
|
|
public function actionAddroute(): ?string |
|
98
|
|
|
{ |
|
99
|
|
|
$model = new FormAddRoute(true); |
|
100
|
|
|
|
|
101
|
|
|
if (!File::exist('/Private/Config/Routing.php') || !File::writable('/Private/Config/Routing.php')) { |
|
102
|
|
|
App::$Session->getFlashBag()->add('error', __('Routing configuration file is not allowed to write: /Private/Config/Routing.php')); |
|
103
|
|
|
} elseif ($model->send() && $model->validate()) { |
|
104
|
|
|
$model->save(); |
|
105
|
|
|
return $this->view->render('add_route_save'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return $this->view->render('add_route', [ |
|
109
|
|
|
'model' => $model |
|
110
|
|
|
]); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Delete scheme route |
|
115
|
|
|
* @throws SyntaxException |
|
116
|
|
|
* @return string |
|
117
|
|
|
*/ |
|
118
|
|
|
public function actionDeleteroute(): ?string |
|
119
|
|
|
{ |
|
120
|
|
|
$type = (string)$this->request->query->get('type'); |
|
121
|
|
|
$loader = (string)$this->request->query->get('loader'); |
|
122
|
|
|
$source = Str::lowerCase((string)$this->request->query->get('path')); |
|
123
|
|
|
|
|
124
|
|
|
$model = new EntityDeleteRoute($type, $loader, $source); |
|
125
|
|
|
if ($model->send() && $model->validate()) { |
|
126
|
|
|
$model->make(); |
|
127
|
|
|
return $this->view->render('delete_route_save'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $this->view->render('delete_route', [ |
|
131
|
|
|
'model' => $model |
|
132
|
|
|
]); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Clear cached data |
|
137
|
|
|
* @return string |
|
138
|
|
|
* @throws SyntaxException |
|
139
|
|
|
*/ |
|
140
|
|
|
public function actionCache(): ?string |
|
141
|
|
|
{ |
|
142
|
|
|
// check if submited |
|
143
|
|
|
if ($this->request->request->get('clearcache', false)) { |
|
144
|
|
|
// clear cache |
|
145
|
|
|
App::$Cache->clean(); |
|
|
|
|
|
|
146
|
|
|
// add notification & redirect |
|
147
|
|
|
App::$Session->getFlashBag()->add('success', __('Cache cleared successfully')); |
|
148
|
|
|
$this->response->redirect('/'); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
// render output view |
|
152
|
|
|
return $this->view->render('clear_cache', []); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|