|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
declare(strict_types=1); |
|
21
|
|
|
|
|
22
|
|
|
namespace MikoPBX\Common\Providers; |
|
23
|
|
|
|
|
24
|
|
|
use MikoPBX\Modules\Config\WebUIConfigInterface; |
|
25
|
|
|
use Phalcon\Acl\Adapter\Memory as AclList; |
|
26
|
|
|
use Phalcon\Acl\Component; |
|
27
|
|
|
use Phalcon\Acl\Enum as AclEnum; |
|
28
|
|
|
use Phalcon\Acl\Role as AclRole; |
|
29
|
|
|
use Phalcon\Di\DiInterface; |
|
30
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Makes the Access Control List (ACL). |
|
34
|
|
|
* |
|
35
|
|
|
* This method creates a new AclList object and sets the default action to AclEnum::DENY. It then adds two roles, |
|
36
|
|
|
* admins and guest, to the ACL, and sets the default permissions such that admins are allowed to perform any |
|
37
|
|
|
* action and guest is denied access to any action. |
|
38
|
|
|
* |
|
39
|
|
|
* Finally, it uses the PBXConfModulesProvider class to allow modules to modify the ACL, and returns the modified ACL. |
|
40
|
|
|
* |
|
41
|
|
|
* @return AclList The Access Control List. |
|
42
|
|
|
*/ |
|
43
|
|
|
class AclProvider implements ServiceProviderInterface |
|
44
|
|
|
{ |
|
45
|
|
|
public const SERVICE_NAME = 'ACL'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Register ACL service provider |
|
49
|
|
|
* |
|
50
|
|
|
* @param \Phalcon\Di\DiInterface $di |
|
51
|
|
|
*/ |
|
52
|
|
|
public function register(DiInterface $di): void |
|
53
|
|
|
{ |
|
54
|
|
|
$di->setShared( |
|
55
|
|
|
self::SERVICE_NAME, |
|
56
|
|
|
function (){ |
|
57
|
|
|
$acl = new AclList(); |
|
58
|
|
|
$acl->setDefaultAction(AclEnum::DENY); |
|
59
|
|
|
|
|
60
|
|
|
// Register roles |
|
61
|
|
|
$acl->addRole(new AclRole('admins', 'Admins')); |
|
62
|
|
|
$acl->addRole(new AclRole('guest', 'Guests')); |
|
63
|
|
|
|
|
64
|
|
|
// Default permissions |
|
65
|
|
|
$acl->allow('admins', '*', '*'); |
|
66
|
|
|
$acl->deny('guest', '*', '*'); |
|
67
|
|
|
|
|
68
|
|
|
// Modules HOOK |
|
69
|
|
|
PBXConfModulesProvider::hookModulesProcedure(WebUIConfigInterface::ON_AFTER_ACL_LIST_PREPARED, [&$acl]); |
|
70
|
|
|
|
|
71
|
|
|
// Allow to show ERROR controllers to everybody |
|
72
|
|
|
$acl->addComponent(new Component('Errors'), ['show401', 'show404', 'show500']); |
|
73
|
|
|
$acl->allow('*', 'Errors', ['show401', 'show404', 'show500']); |
|
74
|
|
|
|
|
75
|
|
|
// Allow to show session controllers actions to everybody |
|
76
|
|
|
$acl->addComponent(new Component('Session'), ['index', 'start', 'changeLanguage', 'end']); |
|
77
|
|
|
$acl->allow('*', 'Session', ['index', 'start', 'changeLanguage', 'end']); |
|
78
|
|
|
|
|
79
|
|
|
return $acl; |
|
80
|
|
|
} |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |