1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\AdminModule\Controller; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
19
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
20
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
21
|
|
|
use Symfony\Component\Routing\Exception\RouteNotFoundException; |
22
|
|
|
use Symfony\Component\Routing\RouterInterface; |
23
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
24
|
|
|
use Zikula\AdminModule\Entity\AdminCategoryEntity; |
25
|
|
|
use Zikula\AdminModule\Entity\RepositoryInterface\AdminCategoryRepositoryInterface; |
26
|
|
|
use Zikula\AdminModule\Entity\RepositoryInterface\AdminModuleRepositoryInterface; |
27
|
|
|
use Zikula\AdminModule\Helper\UpdateCheckHelper; |
28
|
|
|
use Zikula\Bundle\CoreBundle\Controller\AbstractController; |
29
|
|
|
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; |
30
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\CapabilityApiInterface; |
31
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
32
|
|
|
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface; |
33
|
|
|
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuCollector; |
34
|
|
|
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuInterface; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Route("/admininterface") |
38
|
|
|
*/ |
39
|
|
|
class AdminInterfaceController extends AbstractController |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @Route("/header") |
43
|
|
|
* |
44
|
|
|
* Open the admin container |
45
|
|
|
*/ |
46
|
|
|
public function headerAction(RequestStack $requestStack): Response |
47
|
|
|
{ |
48
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/header.html.twig', [ |
49
|
|
|
'caller' => $requestStack->getMasterRequest()->attributes->all() |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Route("/footer") |
55
|
|
|
* |
56
|
|
|
* Close the admin container |
57
|
|
|
*/ |
58
|
|
|
public function footerAction( |
59
|
|
|
RequestStack $requestStack, |
60
|
|
|
ExtensionRepositoryInterface $extensionRepository |
61
|
|
|
): Response { |
62
|
|
|
$caller = $requestStack->getMasterRequest()->attributes->all(); |
63
|
|
|
$caller['info'] = $extensionRepository->get($caller['_zkModule']); |
64
|
|
|
|
65
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/footer.html.twig', [ |
66
|
|
|
'caller' => $caller, |
67
|
|
|
'symfonyVersion' => Kernel::VERSION, |
68
|
|
|
'phpVersion' => PHP_VERSION |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Route("/breadcrumbs", methods = {"GET"}) |
74
|
|
|
* |
75
|
|
|
* Admin breadcrumbs |
76
|
|
|
*/ |
77
|
|
|
public function breadcrumbsAction( |
78
|
|
|
RequestStack $requestStack, |
79
|
|
|
ExtensionRepositoryInterface $extensionRepository, |
80
|
|
|
AdminModuleRepositoryInterface $adminModuleRepository, |
81
|
|
|
AdminCategoryRepositoryInterface $adminCategoryRepository |
82
|
|
|
): Response { |
83
|
|
|
if (!$this->hasPermission('ZikulaAdminModule::', '::', ACCESS_ADMIN)) { |
84
|
|
|
throw new AccessDeniedException(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$masterRequest = $requestStack->getMasterRequest(); |
88
|
|
|
$caller = $masterRequest->attributes->all(); |
89
|
|
|
$caller['info'] = $extensionRepository->get($caller['_zkModule']); |
90
|
|
|
|
91
|
|
|
$requestedCid = $masterRequest->attributes->get('acid'); |
92
|
|
|
$defaultCid = empty($requestedCid) ? $this->getVar('startcategory') : $requestedCid; |
93
|
|
|
|
94
|
|
|
$categoryId = $defaultCid; |
95
|
|
|
if (!empty($caller['_zkModule']) && 'ZikulaAdminModule' !== $caller['_zkModule']) { |
96
|
|
|
$moduleRelation = $adminModuleRepository->findOneBy(['mid' => $caller['info']['id']]); |
97
|
|
|
if (null !== $moduleRelation) { |
98
|
|
|
$categoryId = $moduleRelation->getCid(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
$caller['category'] = $adminCategoryRepository->find($categoryId); |
102
|
|
|
|
103
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/breadCrumbs.html.twig', [ |
104
|
|
|
'caller' => $caller |
105
|
|
|
]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @Route("/securityanalyzer") |
110
|
|
|
* |
111
|
|
|
* Display security analyzer |
112
|
|
|
*/ |
113
|
|
|
public function securityanalyzerAction( |
114
|
|
|
Request $request, |
115
|
|
|
ZikulaHttpKernelInterface $kernel, |
116
|
|
|
VariableApiInterface $variableApi |
117
|
|
|
): Response { |
118
|
|
|
if (!$this->hasPermission('ZikulaAdminModule::', '::', ACCESS_ADMIN)) { |
119
|
|
|
throw new AccessDeniedException(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$hasSecurityCenter = $kernel->isBundle('ZikulaSecurityCenterModule'); |
123
|
|
|
|
124
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/securityAnalyzer.html.twig', [ |
125
|
|
|
'security' => [ |
126
|
|
|
'updatecheck' => $variableApi->getSystemVar('updatecheck'), |
127
|
|
|
'scactive' => $hasSecurityCenter, |
128
|
|
|
// check for outputfilter |
129
|
|
|
'useids' => $hasSecurityCenter && 1 === $variableApi->getSystemVar('useids'), |
130
|
|
|
'idssoftblock' => $variableApi->getSystemVar('idssoftblock') |
131
|
|
|
] |
132
|
|
|
]); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @Route("/updatecheck") |
137
|
|
|
* |
138
|
|
|
* Display update check |
139
|
|
|
* |
140
|
|
|
* @throws AccessDeniedException Thrown if the user doesn't have admin permission for the module |
141
|
|
|
*/ |
142
|
|
|
public function updatecheckAction( |
143
|
|
|
RequestStack $requestStack, |
144
|
|
|
ZikulaHttpKernelInterface $kernel, |
145
|
|
|
UpdateCheckHelper $updateCheckHelper |
146
|
|
|
): Response { |
147
|
|
|
if (!$this->hasPermission('ZikulaAdminModule::', '::', ACCESS_ADMIN)) { |
148
|
|
|
throw new AccessDeniedException(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$masterRequest = $requestStack->getMasterRequest(); |
152
|
|
|
|
153
|
|
|
return $this->render('@ZikulaAdminModule/AdminInterface/updateCheck.html.twig', [ |
154
|
|
|
'mode' => $kernel->getEnvironment(), |
155
|
|
|
'caller' => [ |
156
|
|
|
'_route' => $masterRequest->attributes->get('_route'), |
157
|
|
|
'_route_params' => $masterRequest->attributes->get('_route_params') |
158
|
|
|
], |
159
|
|
|
'updateCheckHelper' => $updateCheckHelper |
160
|
|
|
]); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @Route("/menu") |
165
|
|
|
* |
166
|
|
|
* Display admin menu |
167
|
|
|
* |
168
|
|
|
* @throws AccessDeniedException Thrown if the user doesn't have admin permission for the module |
169
|
|
|
*/ |
170
|
|
|
public function menuAction( |
171
|
|
|
RequestStack $requestStack, |
172
|
|
|
RouterInterface $router, |
173
|
|
|
ExtensionRepositoryInterface $extensionRepository, |
174
|
|
|
ExtensionMenuCollector $extensionMenuCollector, |
175
|
|
|
CapabilityApiInterface $capabilityApi, |
176
|
|
|
AdminModuleRepositoryInterface $adminModuleRepository, |
177
|
|
|
AdminCategoryRepositoryInterface $adminCategoryRepository |
178
|
|
|
): Response { |
179
|
|
|
if (!$this->hasPermission('ZikulaAdminModule::', '::', ACCESS_ADMIN)) { |
180
|
|
|
throw new AccessDeniedException(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$masterRequest = $requestStack->getMasterRequest(); |
184
|
|
|
$currentRequest = $requestStack->getCurrentRequest(); |
185
|
|
|
|
186
|
|
|
// get caller info |
187
|
|
|
$caller = []; |
188
|
|
|
$caller['_zkModule'] = $masterRequest->attributes->get('_zkModule'); |
189
|
|
|
$caller['_zkType'] = $masterRequest->attributes->get('_zkType'); |
190
|
|
|
$caller['_zkFunc'] = $masterRequest->attributes->get('_zkFunc'); |
191
|
|
|
$caller['path'] = $masterRequest->getPathInfo(); |
192
|
|
|
$caller['info'] = !empty($caller['_zkModule']) ? $extensionRepository->get($caller['_zkModule']) : []; |
193
|
|
|
|
194
|
|
|
// category we are in |
195
|
|
|
$requestedCid = $masterRequest->attributes->get('acid'); |
196
|
|
|
$defaultCid = empty($requestedCid) ? $this->getVar('startcategory') : $requestedCid; |
197
|
|
|
|
198
|
|
|
$categoryId = $defaultCid; |
199
|
|
|
if (!empty($caller['_zkModule']) && 'ZikulaAdminModule' !== $caller['_zkModule']) { |
200
|
|
|
$moduleRelation = $adminModuleRepository->findOneBy(['mid' => $caller['info']['id']]); |
201
|
|
|
if (null !== $moduleRelation) { |
202
|
|
|
$categoryId = $moduleRelation->getCid(); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
$caller['category'] = $adminCategoryRepository->find($categoryId); |
206
|
|
|
|
207
|
|
|
// mode requested |
208
|
|
|
$mode = $currentRequest->attributes->has('mode') ? $currentRequest->attributes->get('mode') : 'categories'; |
209
|
|
|
$mode = in_array($mode, ['categories', 'modules']) ? $mode : 'categories'; |
210
|
|
|
// template requested |
211
|
|
|
$template = $currentRequest->attributes->has('template') ? $currentRequest->attributes->get('template') : 'tabs'; |
212
|
|
|
$template = in_array($template, ['tabs', 'panel']) ? $template : 'tabs'; |
213
|
|
|
|
214
|
|
|
// get admin capable modules |
215
|
|
|
$adminModules = $capabilityApi->getExtensionsCapableOf('admin'); |
216
|
|
|
|
217
|
|
|
// sort modules by displayname |
218
|
|
|
$moduleNames = []; |
219
|
|
|
foreach ($adminModules as $key => $module) { |
220
|
|
|
$moduleNames[$key] = $module['displayname']; |
221
|
|
|
} |
222
|
|
|
array_multisort($moduleNames, SORT_ASC, $adminModules); |
223
|
|
|
|
224
|
|
|
$moduleCategories = $adminCategoryRepository->getIndexedCollection('cid'); |
225
|
|
|
$menuModules = []; |
226
|
|
|
$menuCategories = []; |
227
|
|
|
foreach ($adminModules as $adminModule) { |
228
|
|
|
if (!$this->hasPermission($adminModule['name'] . '::', '::', ACCESS_EDIT)) { |
229
|
|
|
continue; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
$categoryAssignment = $adminModuleRepository->findOneBy(['mid' => $adminModule['id']]); |
233
|
|
|
if (null !== $categoryAssignment) { |
234
|
|
|
$catid = $categoryAssignment->getCid(); |
235
|
|
|
$order = $categoryAssignment->getSortorder(); |
236
|
|
|
} else { |
237
|
|
|
$catid = $this->getVar('startcategory'); |
238
|
|
|
$order = 999; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$menuText = $adminModule['displayname']; |
242
|
|
|
|
243
|
|
|
// url |
244
|
|
|
try { |
245
|
|
|
$menuTextUrl = isset($adminModule['capabilities']['admin']['route']) |
246
|
|
|
? $router->generate($adminModule['capabilities']['admin']['route']) |
247
|
|
|
: ''; |
248
|
|
|
} catch (RouteNotFoundException $routeNotFoundException) { |
249
|
|
|
$menuTextUrl = 'javascript:void(0)'; |
250
|
|
|
$menuText .= ' (<i class="fas fa-exclamation-triangle"></i> ' . $this->trans('invalid route') . ')'; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
$moduleName = (string)$adminModule['name']; |
254
|
|
|
$extensionMenu = $extensionMenuCollector->get($moduleName, ExtensionMenuInterface::TYPE_ADMIN); |
255
|
|
|
if (isset($extensionMenu) && 'modules' === $mode && 'tabs' === $template) { |
256
|
|
|
$extensionMenu->setChildrenAttribute('class', 'dropdown-menu'); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$module = [ |
260
|
|
|
'menutexturl' => $menuTextUrl, |
261
|
|
|
'menutext' => $menuText, |
262
|
|
|
'menutexttitle' => $adminModule['description'], |
263
|
|
|
'modname' => $adminModule['name'], |
264
|
|
|
'order' => $order, |
265
|
|
|
'id' => $adminModule['id'], |
266
|
|
|
'extensionMenu' => $extensionMenu, |
267
|
|
|
'icon' => $adminModule['icon'] |
268
|
|
|
]; |
269
|
|
|
|
270
|
|
|
$menuModules[$adminModule['name']] = $module; |
271
|
|
|
|
272
|
|
|
// category menu |
273
|
|
|
if (!$this->hasPermission('ZikulaAdminModule:Category:', $moduleCategories[$catid]['name'] . '::' . $moduleCategories[$catid]['cid'], ACCESS_ADMIN)) { |
274
|
|
|
continue; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$categorySortOrder = $moduleCategories[$catid]['sortorder']; |
278
|
|
|
$menuCategories[$categorySortOrder]['title'] = $moduleCategories[$catid]['name']; |
279
|
|
|
$menuCategories[$categorySortOrder]['url'] = $router->generate('zikulaadminmodule_admin_adminpanel', [ |
280
|
|
|
'acid' => $moduleCategories[$catid]['cid'] |
281
|
|
|
]); |
282
|
|
|
$menuCategories[$categorySortOrder]['description'] = $moduleCategories[$catid]['description']; |
283
|
|
|
$menuCategories[$categorySortOrder]['icon'] = $moduleCategories[$catid]['icon']; |
284
|
|
|
$menuCategories[$categorySortOrder]['cid'] = $moduleCategories[$catid]['cid']; |
285
|
|
|
$menuCategories[$categorySortOrder]['modules'][$adminModule['name']] = $module; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
// add empty categories |
289
|
|
|
/** @var AdminCategoryEntity[] $moduleCategories */ |
290
|
|
|
foreach ($moduleCategories as $moduleCategory) { |
291
|
|
|
if (array_key_exists($moduleCategory->getSortorder(), $menuCategories)) { |
292
|
|
|
continue; |
293
|
|
|
} |
294
|
|
|
if (!$this->hasPermission('ZikulaAdminModule:Category:', $moduleCategory->getName() . '::' . $moduleCategory->getCid(), ACCESS_ADMIN)) { |
295
|
|
|
continue; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
$menuCategories[$moduleCategory->getSortOrder()] = [ |
299
|
|
|
'title' => $moduleCategory->getName(), |
300
|
|
|
'url' => $router->generate('zikulaadminmodule_admin_adminpanel', [ |
301
|
|
|
'acid' => $moduleCategory->getCid() |
302
|
|
|
]), |
303
|
|
|
'description' => $moduleCategory->getDescription(), |
304
|
|
|
'cid' => $moduleCategory->getCid(), |
305
|
|
|
'modules' => [] |
306
|
|
|
]; |
307
|
|
|
} |
308
|
|
|
ksort($menuCategories); |
309
|
|
|
$fullTemplateName = $mode . '.' . $template; |
310
|
|
|
|
311
|
|
|
return $this->render("@ZikulaAdminModule/AdminInterface/${fullTemplateName}.html.twig", [ |
312
|
|
|
'adminMenu' => ('categories' === $mode) ? $menuCategories : $menuModules, |
313
|
|
|
'mode' => $mode, |
314
|
|
|
'caller' => $caller |
315
|
|
|
]); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|