forked from corbosman/dovecot_impersonate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dovecot_impersonate.php
56 lines (47 loc) · 1.71 KB
/
dovecot_impersonate.php
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
<?php
/**
* This plugin lets you impersonate another user using a master login. Only works with dovecot.
*
* http://wiki.dovecot.org/Authentication/MasterUsers
*
* @author Cor Bosman ([email protected])
*/
class dovecot_impersonate extends rcube_plugin {
private $config;
public function init(): void
{
$this->add_hook('storage_connect', [$this, 'impersonate']);
$this->add_hook('managesieve_connect', [$this, 'impersonate']);
$this->add_hook('authenticate', [$this, 'login']);
$this->add_hook('sieverules_connect', [$this, 'impersonate_sieve']);
}
public function login(array $data): array
{
// find the separator character
$rcmail = rcmail::class::get_instance();
$this->load_config();
$separator = $rcmail->config->get('dovecot_impersonate_separator', '*');
if (strpos($data['user'], $separator)) {
$arr = explode($separator, $data['user']);
if (count($arr) == 2) {
$data['user'] = $arr[0];
$_SESSION['plugin.dovecot_impersonate_master'] = $separator . $arr[1];
}
}
return $data;
}
public function impersonate(array $data): array
{
if (isset($_SESSION['plugin.dovecot_impersonate_master'])) {
$data['user'] = $data['user'] . $_SESSION['plugin.dovecot_impersonate_master'];
}
return $data;
}
public function impersonate_sieve(array $data): array
{
if (isset($_SESSION['plugin.dovecot_impersonate_master'])) {
$data['username'] = $data['username'] . $_SESSION['plugin.dovecot_impersonate_master'];
}
return $data;
}
}