1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RBAC implementation for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-rbac |
6
|
|
|
* @package hipanel-rbac |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\rbac\console; |
12
|
|
|
|
13
|
|
|
use hipanel\rbac\RbacIniterInterface; |
14
|
|
|
use hiqdev\yii\compat\yii; |
15
|
|
|
use yii\base\Module; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class RbacController. |
19
|
|
|
* |
20
|
|
|
* Usage: `hidev rbac/init` |
21
|
|
|
*/ |
22
|
|
|
class RbacController extends \yii\console\Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var RbacIniterInterface |
26
|
|
|
*/ |
27
|
|
|
protected $initer; |
28
|
|
|
|
29
|
|
|
public function __construct($id, Module $module, RbacIniterInterface $initer, $config = []) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($id, $module, $config); |
32
|
|
|
|
33
|
|
|
$this->initer = $initer; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public $defaultAction = 'show'; |
37
|
|
|
|
38
|
|
|
public function actionInit() |
39
|
|
|
{ |
40
|
|
|
$auth = yii::getApp()->get('authManager'); |
41
|
|
|
$this->initer->init($auth); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function actionReinit() |
45
|
|
|
{ |
46
|
|
|
$auth = yii::getApp()->get('authManager'); |
47
|
|
|
$this->initer->reinit($auth); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function actionShow() |
51
|
|
|
{ |
52
|
|
|
$auth = yii::getApp()->get('authManager'); |
53
|
|
|
|
54
|
|
|
echo "Permissions:\n"; |
55
|
|
|
$permissions = $auth->getPermissions(); |
56
|
|
|
ksort($permissions); |
57
|
|
|
foreach ($permissions as $name => $perm) { |
58
|
|
|
echo " $perm->name $perm->description\n"; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
echo "Roles:\n"; |
62
|
|
|
foreach ($auth->getRoles() as $name => $role) { |
63
|
|
|
$children = implode(',', array_keys($auth->getChildren($name))); |
64
|
|
|
printf(" %-12s %s\n", "$role->name:", $children); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
echo "Assignments:\n"; |
68
|
|
|
foreach ($auth->getAllAssignments() as $userId => $roles) { |
69
|
|
|
$roles = implode(',', array_keys($roles)); |
70
|
|
|
printf(" %-12s %s\n", "$userId:", $roles); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function actionPlantuml() |
75
|
|
|
{ |
76
|
|
|
$path = dirname(__DIR__, 2) . '/docs/test.txt'; |
77
|
|
|
|
78
|
|
|
$auth = yii::getApp()->get('authManager'); |
79
|
|
|
$plant = new PlantUML($auth); |
80
|
|
|
|
81
|
|
|
$uml = $plant->build(); |
82
|
|
|
|
83
|
|
|
file_put_contents($path, $uml); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|