This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_kopano.php
153 lines (139 loc) · 4.52 KB
/
user_kopano.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
OS<?php
/**
* ownCloud - kopano
*/
include("mapi/mapi.util.php");
include("mapi/mapicode.php");
include("mapi/mapidefs.php");
include("mapi/mapitags.php");
class OC_USER_KOPANO extends OC_User_Backend {
protected $kopano_session;
protected $kopano_store;
protected $kopano_server;
protected $kopano_users;
protected $kopano_user_name;
protected $kopano_user_pass;
function __construct() {
$this->kopano_server = OCP\Config::getAppValue('kopano', 'kopano_server', OC_APP_KOPANO_DEFAULT_SERVER);
$this->kopano_user_name = OCP\Config::getAppValue('kopano', 'kopano_user_name', OC_APP_KOPANO_DEFAULT_USER_NAME);
$this->kopano_user_pass = OCP\Config::getAppValue('kopano', 'kopano_user_pass', OC_APP_KOPANO_DEFAULT_USER_PASS);
}
private function getKopanoSession(){
$this->kopano_session = mapi_logon_zarafa($this->kopano_user_name, $this->kopano_user_pass, $this->kopano_server, NULL, NULL);
if($this->kopano_session)
return true;
OCP\Util::writeLog('OC_USER_KOPANO', "Cannot get kopano session", 3);
return false;
}
private function getDefaultStore(){
if(!$this->kopano_store){
if($this->getKopanoSession()){
$msgStoresTable = mapi_getmsgstorestable($this->kopano_session);
$msgStores = mapi_table_queryallrows($msgStoresTable, array(PR_DEFAULT_STORE, PR_ENTRYID));
$storeEntryId = false;
foreach($msgStores as $row){
if($row[PR_DEFAULT_STORE]){
$storeEntryId = $row[PR_ENTRYID];
}
}
if(!$storeEntryId){
OCP\Util::writeLog('OC_USER_KOPANO', "Cannot get message store id", 3);
return false;
}
$this->kopano_store = mapi_openmsgstore($this->kopano_session, $storeEntryId);
}
if(!$this->kopano_store){
OCP\Util::writeLog('OC_USER_KOPANO', "Cannot get message store!", 3);
return false;
}
return true;
}
return false;
}
public function checkAdminUser(){
if($this->getDefaultStore()){
$info = mapi_zarafa_getuser($this->kopano_store, $this->getUser());
if(!$info)
return false;
return $info["admin"];
}
return false;
}
public function checkPassword($uid, $password){
OCP\Util::writeLog('OC_USER_KOPANO', "checking password for $uid", 3);
$session = mapi_logon_zarafa($uid, $password, $this->kopano_server);
if(!$session){
OCP\Util::writeLog('OC_USER_KOPANO', "Logon failed for '$uid'", 3);
return false;
}
//get the users mailaddress and set it
$msgStoresTable = mapi_getmsgstorestable($session);
$msgStores = mapi_table_queryallrows($msgStoresTable, array(PR_DEFAULT_STORE, PR_ENTRYID));
$storeEntryId = false;
foreach($msgStores as $row){
if($row[PR_DEFAULT_STORE]){
$storeEntryId = $row[PR_ENTRYID];
}
}
if($storeEntryId){
$store = mapi_openmsgstore($session, $storeEntryId);
if($store){
$info = mapi_zarafa_getuser($store, $uid);
if($info){
$email = $info["emailaddress"];
OCP\Config::setUserValue($uid, 'settings', 'email', $email);
} else {
OCP\Util::writeLog('OC_USER_KOPANO', "Error getting user info for $uid", 3);
}
}
}
return $uid;
}
public function deleteUser($uid){
OCP\Util::writeLog('OC_USER_KOPANO', 'Not possible to delete kopano users from web frontend', 3);
return false;
}
public function setPassword ( $uid, $password ) {
OCP\Util::writeLog('OC_USER_KOPANO', 'Setting user password from web frontend using kopano user backend ist not implemented', 3);
return false;
}
public function getUsers($search = '', $limit = 10, $offset = 0){
OCP\Util::writeLog('OC_USER_KOPANO', 'getUsers: searching for:"'. $search . '"', 3);
if(count($this->kopano_users) == 0){
$this->kopano_users = array();
$userList = array();
if(!$this->getDefaultStore())
return $this->kopano_users;
$userList = mapi_zarafa_getuserlist($this->kopano_store);
foreach($userList as $userName => $userData){
if($userName == "SYSTEM")
continue;
array_push($this->kopano_users, $userName);
}
}
$kopano_users = $this->kopano_users;
$this->userSearch = $search;
if(!empty($this->userSearch)) {
$kopano_users = array_filter($kopano_users, array($this, 'userMatchesFilter'));
}
if($limit == -1) {
$limit = null;
}
return array_slice($kopano_users, $offset, $limit);
}
public function userMatchesFilter($user) {
return (strripos($user, $this->userSearch) !== false);
}
public function userExists($uid){
if(!$uid)
return false;
$users = $this->getUsers();
$exists = in_array($uid, $users);
if(!$exists){
OCP\Util::writeLog('OC_USER_KOPANO', "User '$uid' does not exist!", 3 );
return false;
}
return true;
}
}
?>