|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace User; |
|
4
|
|
|
|
|
5
|
|
|
class access |
|
6
|
|
|
{ |
|
7
|
|
|
private $config; |
|
8
|
|
|
/** |
|
9
|
|
|
* User instance. |
|
10
|
|
|
* |
|
11
|
|
|
* @var \User\user |
|
12
|
|
|
*/ |
|
13
|
|
|
private $user; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(\User\user $user) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->config = \Filemanager\file::file(__DIR__ . '/config/access/global.json', ['superuser' => '*']); |
|
|
|
|
|
|
18
|
|
|
$this->user = $user; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
function check() |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get access lists. |
|
27
|
|
|
* |
|
28
|
|
|
* @return array |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getAccess() |
|
31
|
|
|
{ |
|
32
|
|
|
return \Filemanager\file::get($this->config, true); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get root config.json. |
|
37
|
|
|
* |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
private function config() |
|
41
|
|
|
{ |
|
42
|
|
|
return \Filemanager\file::get(ROOT . '/config.json', true); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private $managedAccess; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get list of managed access, that requires spesific user roles. |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
public function get_managed_access() |
|
53
|
|
|
{ |
|
54
|
|
|
if (!$this->managedAccess) { |
|
55
|
|
|
$app = $this->config(); |
|
56
|
|
|
if (isset($app['app'])) { |
|
57
|
|
|
$app = $app['app']; |
|
58
|
|
|
} else { |
|
59
|
|
|
throw new \MVC\Exception('Config failed, no `app` property', 1); |
|
60
|
|
|
} |
|
61
|
|
|
$read = \Filemanager\scan::scandir(ROOT . '/' . $app['views']); |
|
62
|
|
|
$flist = []; |
|
63
|
|
|
foreach ($read as $files) { |
|
64
|
|
|
$flist[] = \MVC\helper::get_url_path($files['path']); |
|
65
|
|
|
} |
|
66
|
|
|
$flist = array_map(function ($path) use ($app) { |
|
67
|
|
|
//strip extensions |
|
68
|
|
|
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $path); |
|
69
|
|
|
/** |
|
70
|
|
|
* Group ignore patterns. |
|
71
|
|
|
*/ |
|
72
|
|
|
$patterns = [ |
|
73
|
|
|
// ignore static file and form controller |
|
74
|
|
|
"\-f.php$|\.(js|css|json|txt|log|htaccess|gitignore)$", |
|
75
|
|
|
// ignore not special access |
|
76
|
|
|
"\/(login|logout|signup|test)\.php$", |
|
77
|
|
|
// ignore unmanaged zones |
|
78
|
|
|
"\/(fb|css|chat|comments|curl|snippets|vpngate|blog|server|php|proxy|im3|telkomsel|byu|axis|google|auth|agc|alquran|img|tools|coupon|login|test)\/", |
|
79
|
|
|
// ignore public access |
|
80
|
|
|
"^\/{$app['views']}\/(index|dashboard|profile|php-socket|user)\.php$", |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
$ignore = preg_match_all('/' . implode('|', $patterns) . '/s', $path); |
|
84
|
|
|
if (!$ignore) { |
|
85
|
|
|
return $withoutExt; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return null; |
|
89
|
|
|
}, $flist); |
|
90
|
|
|
|
|
91
|
|
|
$this->managedAccess = array_values(array_filter($flist)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $this->managedAccess; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|