forked from maloninc/iRemoteWipe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wiper.php
233 lines (199 loc) · 6.63 KB
/
wiper.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/***********************************************
* File : wiper.php
* Project :
* Descr : This backend is ONLY for
* remote wipe
*
* Created : 12.14.2009
* Author : Hiroyuki Nakamura (hiroyuki@maloninc.com)
************************************************/
include_once('diffbackend.php');
define('WIPER_DB', '/var/db/wiper/wiper.db');
define('LDAP_SERVER', 'your.server');
define('LDAP_DOMAIN', 'dc=your,dc=server');
class BackendWiper extends BackendDiff {
var $_user;
var $_devid;
var $_protocolversion;
function Logon($user, $domain, $pass) {
debugLog('Wiper::Logon: ' . $user . '/'. $pass);
if( $user == "" ) {
debugLog('Wiper::Logon: No user name.');
}
if( $pass == "" ) {
debugLog('Wiper::Logon: No password.');
}
$link_id = ldap_connect(LDAP_SERVER, 389);
if(! $link_id){
debugLog('Wiper::Logon: Cannot connect LDAP server.');
}
if(! ldap_set_option($link_id, LDAP_OPT_PROTOCOL_VERSION, 3)){
debugLog('Wiper::Logon: Failed to set v3 protocol.');
}
$dn = LDAP_DOMAIN;
$filter = "(&(objectclass=person)(userPassword=*)(|(uid=$user)(cn=$user)) )";
$attributes = array( 'cn', 'userpassword', 'uid');
$search = ldap_search($link_id, $dn, $filter, $attributes);
$info = ldap_get_entries($link_id, $search);
if($info['count'] == 0) {
debugLog("Wiper::Logon: No such ID: $user");
return false;
}
if(! ldap_bind($link_id, $info[0]['dn'], $pass)){
debugLog("Wiper::Logon: Invalid Password: $user");
return false;
}
return true;
}
function Logoff() {
debugLog('Wiper::Logoff');
return true;
}
function Setup($user, $devid, $protocolversion) {
debugLog('Wiper::Setup');
$this->_user = $user;
$this->_devid = $devid;
$this->_protocolversion = $protocolversion;
return true;
}
function SendMail($rfc822, $forward = false, $reply = false, $parent = false) {
return false;
}
function GetWasteBasket() {
return false;
}
function GetMessageList($folderid, $cutoffdate) {
debugLog('Wiper::GetMessageList('.$folderid.')');
$messages = array();
return $messages;
}
function GetFolderList() {
debugLog('Wiper::GetFolderList()');
$contacts = array();
$folder = $this->StatFolder("root");
$contacts[] = $folder;
return $contacts;
}
function GetFolder($id) {
debugLog('Wiper::GetFolder('.$id.')');
if($id == "root") {
$folder = new SyncFolder();
$folder->serverid = $id;
$folder->parentid = "0";
$folder->displayname = "iRemoteWipe";
$folder->type = SYNC_FOLDER_TYPE_CONTACT;
return $folder;
} else return false;
}
function StatFolder($id) {
debugLog('Wiper::StatFolder('.$id.')');
$folder = $this->GetFolder($id);
$stat = array();
$stat["id"] = $id;
$stat["parent"] = $folder->parentid;
$stat["mod"] = $folder->displayname;
return $stat;
}
function GetAttachmentData($attname) {
return false;
}
function GetMessage($folderid, $id, $truncsize) {
debugLog('Wiper::GetMessage('.$folderid.', '.$id.', ..)');
return false;;
}
function SetReadFlag($folderid, $id, $flags) {
return false;
}
function ChangeMessage($folderid, $id, $message) {
debugLog('Wiper::ChangeMessage('.$folderid.', '.$id.', ..)');
}
function MoveMessage($folderid, $id, $newfolderid) {
debugLog('Wiper::MoveMessage('.$folderid.', '.$id.', ..)');
return false;
}
// -----------------------------------
function escape($data){
if (is_array($data)) {
foreach ($data as $key => $val) {
$data[$key] = $this->escape($val);
}
return $data;
}
$data = str_replace("\r\n", "\n", $data);
$data = str_replace("\r", "\n", $data);
$data = str_replace(array('\\', ';', ',', "\n"), array('\\\\', '\\;', '\\,', '\\n'), $data);
return u2wi($data);
}
function unescape($data){
$data = str_replace(array('\\\\', '\\;', '\\,', '\\n','\\N'),array('\\', ';', ',', "\n", "\n"),$data);
return $data;
}
function getDeviceRWStatus($user, $pass, $devid) {
debugLog('Wiper::getDeviceRWStatus');
$dbh = new PDO('sqlite:'.WIPER_DB, null, null);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$sth = $dbh->prepare('select rwstatus from wipe_table where user = ? and devid = ?');
$sth->execute(array($user, $devid));
$result = $sth->fetch();
if($result == null) {
$sth = $dbh->prepare('insert into wipe_table values(?, ?, ?, 0)');
$sth->execute(array($user, $devid, SYNC_PROVISION_RWSTATUS_NA));
return false;
}
}catch(PDOException $e){
debugLog(" ".$e->getMessage());
}
$status = $result[0];
$dbh = null;
return $status;
}
function setDeviceRWStatus($user, $pass, $devid, $status) {
debugLog('Wiper::setDeviceRWStatus: '.$status);
$dbh = new PDO('sqlite:'.WIPER_DB, null, null);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$sth = $dbh->prepare('update wipe_table set status = ? where user = ? and devid = ?');
$sth->execute(array($status, $user, $devid));
}catch(PDOException $e){
debugLog(" ".$e->getMessage());
}
$dbh = null;
return true;;
}
function getPolicyKey($user, $pass, $devid) {
debugLog('Wiper::getPolicyKey');
$dbh = new PDO('sqlite:'.WIPER_DB, null, null);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$sth = $dbh->prepare('select policykey from wipe_table where user = ? and devid = ?');
$sth->execute(array($user, $devid));
$result = $sth->fetch();
if($result == null) {
$sth = $dbh->prepare('insert into wipe_table values(?, ?, ?, 1)');
$sth->execute(array($user, $devid, SYNC_PROVISION_RWSTATUS_NA));
return false;
}
}catch(PDOException $e){
debugLog(" ".$e->getMessage());
}
$key = $result[0];
$dbh = null;
return $key;
}
function setPolicyKey($policykey, $devid) {
debugLog('Wiper::setPolicyKey: ' . $policykey . ' ' . $devid);
$dbh = new PDO('sqlite:'.WIPER_DB, null, null);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$sth = $dbh->prepare('update wipe_table set policykey = ? where devid = ?');
$sth->execute(array($policykey, $devid));
}catch(PDOException $e){
debugLog(" ".$e->getMessage());
}
$dbh = null;
return true;
}
};
?>