forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHestiaAuth.php
More file actions
125 lines (100 loc) · 3.05 KB
/
Copy pathHestiaAuth.php
File metadata and controls
125 lines (100 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* This file is part of the FileGator package.
*
* (c) Milos Stojanovic <alcalbg@gmail.com>
*
* For the full copyright and license information, please view the LICENSE file
*/
namespace Filegator\Services\Auth\Adapters;
use Filegator\Services\Auth\AuthInterface;
use Filegator\Services\Auth\User;
use Filegator\Services\Auth\UsersCollection;
use Filegator\Services\Service;
/**
* @codeCoverageIgnore
*/
class HestiaAuth implements Service, AuthInterface
{
protected $permissions = [];
protected $private_repos = false;
protected $hestia_user = '';
public function init(array $config = [])
{
if (isset($_SESSION['user'])) {
$v_user = $_SESSION['user'];
}
if (isset($_SESSION['look']) && $_SESSION['look'] != 'admin' && $v_user === 'admin') {
$v_user = $_SESSION['look'];
}
$this->hestia_user = $v_user;
$this->permissions = isset($config['permissions']) ? (array)$config['permissions'] : [];
$this->private_repos = isset($config['private_repos']) ? (bool)$config['private_repos'] : false;
}
public function user(): ?User
{
$cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
exec ($cmd." ".escapeshellarg($this->hestia_user )." json", $output, $return_var);
if ($return_var == 0) {
$data = json_decode(implode('', $output), true);
$hestia_user_info = $data[$this->hestia_user];
return $this->transformUser($hestia_user_info);
}
return $this->getGuest();
}
public function transformUser($hstuser): User
{
$user = new User();
$user->setUsername($this->hestia_user);
$user->setName($this->hestia_user . " (" . $hstuser['FNAME'] . " " . $hstuser['LNAME'] . ")");
$user->setRole('user');
$user->setPermissions($this->permissions);
$user->setHomedir('/');
return $user;
}
public function authenticate($username, $password): bool
{
# Auth is handled by Hestia
return false;
}
public function forget()
{
// Logout return to Hestia
return $this->getGuest();
}
public function store(User $user)
{
return null; // not used
}
public function update($username, User $user, $password = ''): User
{
// Password change is handled by Hestia
return $this->user();
}
public function add(User $user, $password): User
{
return new User(); // not used
}
public function delete(User $user)
{
return true; // not used
}
public function find($username): ?User
{
return null; // not used
}
public function allUsers(): UsersCollection
{
return new UsersCollection(); // not used
}
public function getGuest(): User
{
$guest = new User();
$guest->setUsername('guest');
$guest->setName('Guest');
$guest->setRole('guest');
$guest->setHomedir('/');
$guest->setPermissions([]);
return $guest;
}
}