Rev 1215 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1215 | Rev 1217 | ||
|---|---|---|---|
| 1 | <?php |
1 | <?php |
| 2 | 2 | ||
| 3 | require(dirname(__FILE__)."/config.php"); |
3 | require(dirname(__FILE__)."/config.php"); |
| 4 | 4 | ||
| 5 | /* |
5 | /* |
| 6 | |
6 | |
| 7 | http://www.howtoforge.com/talking-soap-with-exchange |
7 | http://www.howtoforge.com/talking-soap-with-exchange |
| 8 | |
8 | |
| 9 | */ |
9 | */ |
| 10 | 10 | ||
| 11 | if (isset($_GET["function"])) |
11 | if (isset($_GET["function"])) |
| 12 | { |
12 | { |
| 13 | switch ($_GET["function"]) |
13 | switch ($_GET["function"]) |
| 14 | { |
14 | { |
| 15 | case "getMeetingsRestOfDay": |
15 | case "getMeetingsRestOfDay": |
| 16 | if (isset($_GET["shortname"])) |
16 | if (isset($_GET["shortname"])) |
| 17 | { |
17 | { |
| 18 | echo getMeetingsRestOfDay($_GET["shortname"]); |
18 | echo getMeetingsRestOfDay($_GET["shortname"]); |
| 19 | } |
19 | } |
| 20 | break; |
20 | break; |
| 21 | 21 | ||
| 22 | case "bookMeeting": |
22 | case "bookMeeting": |
| 23 | if (isset($_GET["from"]) && isset($_GET["to"]) && isset($_GET["shortname"])) |
23 | if (isset($_GET["from"]) && isset($_GET["to"]) && isset($_GET["shortname"])) |
| 24 | { |
24 | { |
| 25 | if (preg_match("/^\d\d:\d\d$/", $_GET["from"]) && preg_match("/^\d\d:\d\d$/", $_GET["to"])) |
25 | if (preg_match("/^\d\d:\d\d$/", $_GET["from"]) && preg_match("/^\d\d:\d\d$/", $_GET["to"])) |
| 26 | { |
26 | { |
| 27 | echo bookMeeting($_GET["shortname"], $_GET["from"], $_GET["to"]); |
27 | echo bookMeeting($_GET["shortname"], $_GET["from"], $_GET["to"]); |
| 28 | } |
28 | } |
| 29 | } |
29 | } |
| 30 | break; |
30 | break; |
| 31 | 31 | ||
| 32 | //case "": |
32 | //case "": |
| 33 | // |
33 | // |
| 34 | //break; |
34 | //break; |
| 35 | } |
35 | } |
| 36 | } |
36 | } |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | /* |
39 | /* |
| 40 | Book meeting |
40 | Book meeting |
| 41 | Return a JSON formed string with the result |
41 | Return a JSON formed string with the result |
| 42 | */ |
42 | */ |
| 43 | function bookMeeting($shortname, $bookFrom, $bookTo) |
43 | function bookMeeting($shortname, $bookFrom, $bookTo) |
| 44 | { |
44 | { |
| 45 | global $Calender; |
45 | global $Calender; |
| 46 | global $wsdl; |
46 | global $wsdl; |
| 47 | $founditem = false; |
47 | $founditem = false; |
| 48 | 48 | ||
| 49 | foreach($Calender as $item) |
49 | foreach($Calender as $item) |
| 50 | { |
50 | { |
| 51 | if ($item->Shortname == $shortname) |
51 | if ($item->Shortname == $shortname) |
| 52 | { |
52 | { |
| 53 | $founditem = $item; |
53 | $founditem = $item; |
| 54 | break; |
54 | break; |
| 55 | } |
55 | } |
| 56 | } |
56 | } |
| 57 | 57 | ||
| - | 58 | $bookingsOk = true; |
|
| - | 59 | ||
| - | 60 | $bookings = json_decode(getMeetingsRestOfDay($shortname)); |
|
| - | 61 | //print_array($bookings); |
|
| - | 62 | //echo $bookings; |
|
| - | 63 | if ($bookings->{'error'}) |
|
| - | 64 | { |
|
| - | 65 | $bookingsOk = false; |
|
| - | 66 | } |
|
| - | 67 | ||
| - | 68 | if ($bookings->{'meetings'}) |
|
| - | 69 | { |
|
| - | 70 | foreach ($bookings->{'meetings'} as $meeting) |
|
| - | 71 | { |
|
| - | 72 | $meetStart = strtotime($meeting->{'start'}); |
|
| - | 73 | $meetEnd = strtotime($meeting->{'end'}); |
|
| - | 74 | $start = strtotime($bookFrom); |
|
| - | 75 | $end = strtotime($bookTo); |
|
| - | 76 | //echo $meeting->{'start'}." "; |
|
| - | 77 | if (($start >= $meetStart && $start < $meetEnd) |
|
| - | 78 | || ($end > $meetStart && $end <= $meetEnd) |
|
| - | 79 | || ($start <= $meetStart && $end >= $meetEnd)) |
|
| - | 80 | { |
|
| - | 81 | $bookingsOk = false; |
|
| - | 82 | break; |
|
| - | 83 | } |
|
| - | 84 | } |
|
| - | 85 | } |
|
| - | 86 | ||
| 58 | if ($founditem !== false) |
87 | if ($founditem !== false && $bookingsOk) |
| 59 | { |
88 | { |
| 60 | $CreateItem->SendMeetingInvitations = "SendToNone"; |
89 | $CreateItem->SendMeetingInvitations = "SendToNone"; |
| 61 | $CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "calendar"; |
90 | $CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "calendar"; |
| 62 | $CreateItem->Items->CalendarItem = array(); |
91 | $CreateItem->Items->CalendarItem = array(); |
| 63 | $CreateItem->Items->CalendarItem[0]->Subject = "Booking from panel"; |
92 | $CreateItem->Items->CalendarItem[0]->Subject = "Booking from panel"; |
| 64 | /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */ |
93 | /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */ |
| 65 | $CreateItem->Items->CalendarItem[0]->Start = date("c",strtotime($bookFrom)); // "2009-05-22T17:00:00Z" ISO date format. Z denotes UTC time |
94 | $CreateItem->Items->CalendarItem[0]->Start = date("c",strtotime($bookFrom)); // "2009-05-22T17:00:00Z" ISO date format. Z denotes UTC time |
| 66 | $CreateItem->Items->CalendarItem[0]->End = date("c",strtotime($bookTo)); |
95 | $CreateItem->Items->CalendarItem[0]->End = date("c",strtotime($bookTo)); |
| 67 | $CreateItem->Items->CalendarItem[0]->IsAllDayEvent = false; |
96 | $CreateItem->Items->CalendarItem[0]->IsAllDayEvent = false; |
| 68 | $CreateItem->Items->CalendarItem[0]->LegacyFreeBusyStatus = "Busy"; |
97 | $CreateItem->Items->CalendarItem[0]->LegacyFreeBusyStatus = "Busy"; |
| 69 | $CreateItem->Items->CalendarItem[0]->Location = $founditem->Shortname; |
98 | $CreateItem->Items->CalendarItem[0]->Location = $founditem->Shortname; |
| 70 | $CreateItem->Items->CalendarItem[0]->Categories->String = "Meeting"; |
99 | $CreateItem->Items->CalendarItem[0]->Categories->String = "Meeting"; |
| 71 | 100 | ||
| 72 | stream_wrapper_unregister('https'); |
101 | stream_wrapper_unregister('https'); |
| 73 | stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol"); |
102 | stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol"); |
| 74 | 103 | ||
| 75 | try |
104 | try |
| 76 | { |
105 | { |
| 77 | $client = new ExchangeNTLMSoapClient($wsdl); |
106 | $client = new ExchangeNTLMSoapClient($wsdl); |
| 78 | $client->user = $founditem->UserName; |
107 | $client->user = $founditem->UserName; |
| 79 | $client->pass = $founditem->Password; |
108 | $client->pass = $founditem->Password; |
| 80 | $result = $client->CreateItem($CreateItem); |
109 | $result = $client->CreateItem($CreateItem); |
| 81 | if ($result) |
110 | if ($result) |
| 82 | { |
111 | { |
| 83 | //print_array($result); |
112 | //print_array($result); |
| 84 | if ($result->ResponseMessages->CreateItemResponseMessage->ResponseClass == "Success") |
113 | if ($result->ResponseMessages->CreateItemResponseMessage->ResponseClass == "Success") |
| 85 | { |
114 | { |
| 86 | $returndata = "{ result:'success',\nshortname:'".$shortname."'}\n"; |
115 | $returndata = "{ result:'success',\nshortname:'".$shortname."'}\n"; |
| 87 | } |
116 | } |
| 88 | else |
117 | else |
| 89 | { |
118 | { |
| 90 | $errorcode=$result->ResponseMessages->CreateItemResponseMessage->MessageText; |
119 | $errorcode=$result->ResponseMessages->CreateItemResponseMessage->MessageText; |
| 91 | $returndata = "{ result:'error',\nerror:'".$errorcode."',\nshortname:'".$shortname."'}\n"; |
120 | $returndata = "{ result:'error',\nerror:'".$errorcode."',\nshortname:'".$shortname."'}\n"; |
| 92 | } |
121 | } |
| 93 | } |
122 | } |
| 94 | else |
123 | else |
| 95 | { |
124 | { |
| 96 | $returdata = "{ error:'No result',\nshortname:'".$shortname."'}\n"; |
125 | $returdata = "{ error:'No result',\nshortname:'".$shortname."'}\n"; |
| 97 | } |
126 | } |
| 98 | 127 | ||
| 99 | } |
128 | } |
| 100 | catch (SoapFault $exception) |
129 | catch (SoapFault $exception) |
| 101 | { |
130 | { |
| 102 | $returdata = "{ error:'".$exception."',\nshortname:'".$shortname."'}\n"; |
131 | $returdata = "{ error:'".$exception."',\nshortname:'".$shortname."'}\n"; |
| 103 | } |
132 | } |
| 104 | 133 | ||
| 105 | stream_wrapper_restore('https'); |
134 | stream_wrapper_restore('https'); |
| 106 | return $returndata; |
135 | return $returndata; |
| - | 136 | } |
|
| - | 137 | else if ($founditem === false) |
|
| - | 138 | { |
|
| - | 139 | return "{ error:'Unknown shortname',\nshortname:'".$shortname."'}\n"; |
|
| 107 | } |
140 | } |
| 108 | else |
141 | else |
| 109 | { |
142 | { |
| 110 | return "{ error: |
143 | return "{ error:'Double booking',\nshortname:'".$shortname."'}\n"; |
| 111 | } |
144 | } |
| 112 | } |
145 | } |
| 113 | 146 | ||
| 114 | 147 | ||
| 115 | /* |
148 | /* |
| 116 | 149 | ||
| 117 | stdClass Object |
150 | stdClass Object |
| 118 | ( |
151 | ( |
| 119 | [ResponseMessages] => stdClass Object |
152 | [ResponseMessages] => stdClass Object |
| 120 | ( |
153 | ( |
| 121 | [CreateItemResponseMessage] => stdClass Object |
154 | [CreateItemResponseMessage] => stdClass Object |
| 122 | ( |
155 | ( |
| 123 | [ResponseCode] => NoError |
156 | [ResponseCode] => NoError |
| 124 | [ResponseClass] => Success |
157 | [ResponseClass] => Success |
| 125 | [Items] => stdClass Object |
158 | [Items] => stdClass Object |
| 126 | ( |
159 | ( |
| 127 | [CalendarItem] => stdClass Object |
160 | [CalendarItem] => stdClass Object |
| 128 | ( |
161 | ( |
| 129 | [ItemId] => stdClass Object |
162 | [ItemId] => stdClass Object |
| 130 | ( |
163 | ( |
| 131 | [Id] => |
164 | [Id] => |
| 132 | AAAcAEVudGVyLktvbmZlcmVuc3J1bUBxcnRlY2guc2UARgAAAAAAWx3xkPMlnUyMluTTqIdb4AcAdM/rfM3YaEeMsdYGn8jOeAAAAClWOAAAK68xOGjBUkCXHxa/+2eMqAAah/ErtAAA |
165 | AAAcAEVudGVyLktvbmZlcmVuc3J1bUBxcnRlY2guc2UARgAAAAAAWx3xkPMlnUyMluTTqIdb4AcAdM/rfM3YaEeMsdYGn8jOeAAAAClWOAAAK68xOGjBUkCXHxa/+2eMqAAah/ErtAAA |
| 133 | [ChangeKey] => DwAAABYAAAArrzE4aMFSQJcfFr/7Z4yoABqH8Tu3 |
166 | [ChangeKey] => DwAAABYAAAArrzE4aMFSQJcfFr/7Z4yoABqH8Tu3 |
| 134 | ) |
167 | ) |
| 135 | ) |
168 | ) |
| 136 | ) |
169 | ) |
| 137 | ) |
170 | ) |
| 138 | ) |
171 | ) |
| 139 | ) |
172 | ) |
| 140 | 173 | ||
| 141 | stdClass Object |
174 | stdClass Object |
| 142 | ( |
175 | ( |
| 143 | [ResponseMessages] => stdClass Object |
176 | [ResponseMessages] => stdClass Object |
| 144 | ( |
177 | ( |
| 145 | [CreateItemResponseMessage] => stdClass Object |
178 | [CreateItemResponseMessage] => stdClass Object |
| 146 | ( |
179 | ( |
| 147 | [MessageText] => EndDate is earlier than StartDate |
180 | [MessageText] => EndDate is earlier than StartDate |
| 148 | [ResponseCode] => ErrorCalendarEndDateIsEarlierThanStartDate |
181 | [ResponseCode] => ErrorCalendarEndDateIsEarlierThanStartDate |
| 149 | [DescriptiveLinkKey] => 0 |
182 | [DescriptiveLinkKey] => 0 |
| 150 | [ResponseClass] => Error |
183 | [ResponseClass] => Error |
| 151 | [Items] => stdClass Object |
184 | [Items] => stdClass Object |
| 152 | ( |
185 | ( |
| 153 | ) |
186 | ) |
| 154 | ) |
187 | ) |
| 155 | ) |
188 | ) |
| 156 | ) |
189 | ) |
| 157 | */ |
190 | */ |
| 158 | 191 | ||
| 159 | 192 | ||
| 160 | 193 | ||
| 161 | /* |
194 | /* |
| 162 | Get all meetings from now and 9 hours later |
195 | Get all meetings from now and 9 hours later |
| 163 | Return a JSON formed string |
196 | Return a JSON formed string |
| 164 | */ |
197 | */ |
| 165 | function getMeetingsRestOfDay($shortname) |
198 | function getMeetingsRestOfDay($shortname) |
| 166 | { |
199 | { |
| 167 | global $Calender; |
200 | global $Calender; |
| 168 | global $wsdl; |
201 | global $wsdl; |
| 169 | $founditem = false; |
202 | $founditem = false; |
| 170 | 203 | ||
| 171 | foreach($Calender as $item) |
204 | foreach($Calender as $item) |
| 172 | { |
205 | { |
| 173 | if ($item->Shortname == $shortname) |
206 | if ($item->Shortname == $shortname) |
| 174 | { |
207 | { |
| 175 | $founditem = $item; |
208 | $founditem = $item; |
| 176 | break; |
209 | break; |
| 177 | } |
210 | } |
| 178 | } |
211 | } |
| 179 | 212 | ||
| 180 | if ($founditem !== false) |
213 | if ($founditem !== false) |
| 181 | { |
214 | { |
| 182 | $FindItem->Traversal = "Shallow"; |
215 | $FindItem->Traversal = "Shallow"; |
| 183 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
216 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
| 184 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
217 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
| 185 | /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */ |
218 | /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */ |
| 186 | $FindItem->CalendarView->StartDate = date("c"); //"2009-04-07T08:00:00Z"; |
219 | $FindItem->CalendarView->StartDate = date("c"); //"2009-04-07T08:00:00Z"; |
| 187 | $FindItem->CalendarView->EndDate = date("c", strtotime("+ |
220 | $FindItem->CalendarView->EndDate = date("c", strtotime("+12 hour")); //"2009-04-08T00:00:00Z"; |
| 188 | //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n"; |
221 | //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n"; |
| 189 | 222 | ||
| 190 | stream_wrapper_unregister('https'); |
223 | stream_wrapper_unregister('https'); |
| 191 | stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol"); |
224 | stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol"); |
| 192 | 225 | ||
| 193 | $returndata = "{ \n\tshortname |
226 | $returndata = "{ \n\t\"shortname\":\"".$shortname."\",\n\t\"meetings\":[\n"; |
| 194 | try |
227 | try |
| 195 | { |
228 | { |
| 196 | $client = new ExchangeNTLMSoapClient($wsdl); |
229 | $client = new ExchangeNTLMSoapClient($wsdl); |
| 197 | $client->user = $founditem->UserName; |
230 | $client->user = $founditem->UserName; |
| 198 | $client->pass = $founditem->Password; |
231 | $client->pass = $founditem->Password; |
| 199 | $result = $client->FindItem($FindItem); |
232 | $result = $client->FindItem($FindItem); |
| 200 | if ($result) |
233 | if ($result) |
| 201 | { |
234 | { |
| 202 | //print_array($result); |
235 | //print_array($result); |
| 203 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
236 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
| 204 | //print_array($calendaritems); |
237 | //print_array($calendaritems); |
| 205 | for ($i = 0; $i < count($calendaritems); $i++) |
238 | for ($i = 0; $i < count($calendaritems); $i++) |
| 206 | { |
239 | { |
| 207 | if (count($calendaritems) > 1) |
240 | if (count($calendaritems) > 1) |
| 208 | { |
241 | { |
| 209 | $item = $calendaritems[$i]; |
242 | $item = $calendaritems[$i]; |
| 210 | } |
243 | } |
| 211 | else |
244 | else |
| 212 | { |
245 | { |
| 213 | $item = $calendaritems; |
246 | $item = $calendaritems; |
| 214 | } |
247 | } |
| 215 | $returndata .= "\t\t{\n"; |
248 | $returndata .= "\t\t{\n"; |
| 216 | $returndata .= "\t\torganizer |
249 | $returndata .= "\t\t\"organizer\":\"".$item->Organizer->Mailbox->Name."\",\n"; |
| 217 | $returndata .= "\t\tsubject |
250 | $returndata .= "\t\t\"subject\":\"".$item->Subject."\",\n"; |
| 218 | $returndata .= "\t\t |
251 | $returndata .= "\t\t\"start\":\"".date("G:i", strtotime($item->Start))."\",\n"; |
| 219 | $returndata .= "\t\tend: |
252 | $returndata .= "\t\t\"end\":\"".date("G:i", strtotime($item->End))."\"\n"; |
| 220 | $returndata .= "\t\t}"; |
253 | $returndata .= "\t\t}"; |
| 221 | if ($i+1 < count($calendaritems)) |
254 | if ($i+1 < count($calendaritems)) |
| 222 | { |
255 | { |
| 223 | $returndata .= ",\n"; |
256 | $returndata .= ",\n"; |
| 224 | } |
257 | } |
| 225 | } |
258 | } |
| 226 | } |
259 | } |
| 227 | else |
260 | else |
| 228 | { |
261 | { |
| 229 |
|
262 | //return "{ \"error\":\"No result\",\n\"shortname\":\"".$shortname."\"}\n"; |
| 230 | } |
263 | } |
| 231 | } |
264 | } |
| 232 | catch (SoapFault $exception) |
265 | catch (SoapFault $exception) |
| 233 | { |
266 | { |
| 234 |
|
267 | //return "{ \"error\":\"".$exception."\",\n\"shortname\":\"".$shortname."\"}\n"; |
| 235 | } |
268 | } |
| 236 | 269 | ||
| 237 | stream_wrapper_restore('https'); |
270 | stream_wrapper_restore('https'); |
| 238 | $returndata .= "\n\t]\n}\n"; |
271 | $returndata .= "\n\t]\n}\n"; |
| 239 | return $returndata; |
272 | return $returndata; |
| 240 | } |
273 | } |
| 241 | else |
274 | else |
| 242 | { |
275 | { |
| 243 | return "{ error: |
276 | return "{ \"error\":\"Unknown shortname\",\n\"shortname\":\"".$shortname."\"}\n"; |
| 244 | } |
277 | } |
| 245 | } |
278 | } |
| 246 | 279 | ||
| 247 | 280 | ||
| 248 | function print_array($var) |
281 | function print_array($var) |
| 249 | { |
282 | { |
| 250 | echo "<pre>\n"; |
283 | echo "<pre>\n"; |
| 251 | print_r($var); |
284 | print_r($var); |
| 252 | echo "</pre>\n"; |
285 | echo "</pre>\n"; |
| 253 | } |
286 | } |
| 254 | 287 | ||
| 255 | class NTLMSoapClient extends SoapClient { |
288 | class NTLMSoapClient extends SoapClient { |
| 256 | function __doRequest($request, $location, $action, $version) |
289 | function __doRequest($request, $location, $action, $version) |
| 257 | { |
290 | { |
| 258 | global $exchangeurl; |
291 | global $exchangeurl; |
| 259 | $location=$exchangeurl; //override url to exchange server |
292 | $location=$exchangeurl; //override url to exchange server |
| 260 | 293 | ||
| 261 | $headers = array( 'Method: POST', |
294 | $headers = array( 'Method: POST', |
| 262 | 'Connection: Keep-Alive', |
295 | 'Connection: Keep-Alive', |
| 263 | 'User-Agent: PHP-SOAP-CURL', |
296 | 'User-Agent: PHP-SOAP-CURL', |
| 264 | 'Content-Type: text/xml; charset=utf-8', |
297 | 'Content-Type: text/xml; charset=utf-8', |
| 265 | 'SOAPAction: "'.$action.'"', |
298 | 'SOAPAction: "'.$action.'"', |
| 266 | ); |
299 | ); |
| 267 | $this->__last_request_headers = $headers; |
300 | $this->__last_request_headers = $headers; |
| 268 | $ch = curl_init($location); |
301 | $ch = curl_init($location); |
| 269 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
302 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 270 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
303 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 271 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
304 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 272 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
305 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| 273 | curl_setopt($ch, CURLOPT_POST, true ); |
306 | curl_setopt($ch, CURLOPT_POST, true ); |
| 274 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
307 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
| 275 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
308 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 276 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
309 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
| 277 | curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass); |
310 | curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass); |
| 278 | $response = curl_exec($ch); |
311 | $response = curl_exec($ch); |
| 279 | 312 | ||
| 280 | /*$myfile = "/tmp/debugex.txt"; |
313 | /*$myfile = "/tmp/debugex.txt"; |
| 281 | $fh = fopen($myfile, 'w+') or die("can't open file"); |
314 | $fh = fopen($myfile, 'w+') or die("can't open file"); |
| 282 | fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n"); |
315 | fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n"); |
| 283 | fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
316 | fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
| 284 | fwrite($fh, "reponse: ". $response."\n\n"); |
317 | fwrite($fh, "reponse: ". $response."\n\n"); |
| 285 | fclose($fh); |
318 | fclose($fh); |
| 286 | */ |
319 | */ |
| 287 | 320 | ||
| 288 | return $response; |
321 | return $response; |
| 289 | } |
322 | } |
| 290 | 323 | ||
| 291 | function __getLastRequestHeaders() |
324 | function __getLastRequestHeaders() |
| 292 | { |
325 | { |
| 293 | return implode("\n", $this->__last_request_headers)."\n"; |
326 | return implode("\n", $this->__last_request_headers)."\n"; |
| 294 | } |
327 | } |
| 295 | } |
328 | } |
| 296 | 329 | ||
| 297 | class ExchangeNTLMSoapClient extends NTLMSoapClient |
330 | class ExchangeNTLMSoapClient extends NTLMSoapClient |
| 298 | { |
331 | { |
| 299 | public $user = ''; |
332 | public $user = ''; |
| 300 | public $password = ''; |
333 | public $password = ''; |
| 301 | } |
334 | } |
| 302 | 335 | ||
| 303 | class NTLMStream |
336 | class NTLMStream |
| 304 | { |
337 | { |
| 305 | private $path; |
338 | private $path; |
| 306 | private $mode; |
339 | private $mode; |
| 307 | private $options; |
340 | private $options; |
| 308 | private $opened_path; |
341 | private $opened_path; |
| 309 | private $buffer; |
342 | private $buffer; |
| 310 | private $pos; |
343 | private $pos; |
| 311 | 344 | ||
| 312 | /** |
345 | /** |
| 313 | * Open the stream |
346 | * Open the stream |
| 314 | * |
347 | * |
| 315 | * @param unknown_type $path |
348 | * @param unknown_type $path |
| 316 | * @param unknown_type $mode |
349 | * @param unknown_type $mode |
| 317 | * @param unknown_type $options |
350 | * @param unknown_type $options |
| 318 | * @param unknown_type $opened_path |
351 | * @param unknown_type $opened_path |
| 319 | * @return unknown |
352 | * @return unknown |
| 320 | */ |
353 | */ |
| 321 | public function stream_open($path, $mode, $options, $opened_path) |
354 | public function stream_open($path, $mode, $options, $opened_path) |
| 322 | { |
355 | { |
| 323 | echo "[NTLMStream::stream_open] $path , mode=$mode \n"; |
356 | echo "[NTLMStream::stream_open] $path , mode=$mode \n"; |
| 324 | $this->path = $path; |
357 | $this->path = $path; |
| 325 | $this->mode = $mode; |
358 | $this->mode = $mode; |
| 326 | $this->options = $options; |
359 | $this->options = $options; |
| 327 | $this->opened_path = $opened_path; |
360 | $this->opened_path = $opened_path; |
| 328 | $this->createBuffer($path); |
361 | $this->createBuffer($path); |
| 329 | return true; |
362 | return true; |
| 330 | } |
363 | } |
| 331 | 364 | ||
| 332 | /** |
365 | /** |
| 333 | * Close the stream |
366 | * Close the stream |
| 334 | * |
367 | * |
| 335 | */ |
368 | */ |
| 336 | public function stream_close() |
369 | public function stream_close() |
| 337 | { |
370 | { |
| 338 | echo "[NTLMStream::stream_close] \n"; |
371 | echo "[NTLMStream::stream_close] \n"; |
| 339 | curl_close($this->ch); |
372 | curl_close($this->ch); |
| 340 | } |
373 | } |
| 341 | 374 | ||
| 342 | /** |
375 | /** |
| 343 | * Read the stream |
376 | * Read the stream |
| 344 | * |
377 | * |
| 345 | * @param int $count number of bytes to read |
378 | * @param int $count number of bytes to read |
| 346 | * @return content from pos to count |
379 | * @return content from pos to count |
| 347 | */ |
380 | */ |
| 348 | public function stream_read($count) |
381 | public function stream_read($count) |
| 349 | { |
382 | { |
| 350 | echo "[NTLMStream::stream_read] $count \n"; |
383 | echo "[NTLMStream::stream_read] $count \n"; |
| 351 | if(strlen($this->buffer) == 0) |
384 | if(strlen($this->buffer) == 0) |
| 352 | { |
385 | { |
| 353 | return false; |
386 | return false; |
| 354 | } |
387 | } |
| 355 | $read = substr($this->buffer,$this->pos, $count); |
388 | $read = substr($this->buffer,$this->pos, $count); |
| 356 | $this->pos += $count; |
389 | $this->pos += $count; |
| 357 | return $read; |
390 | return $read; |
| 358 | } |
391 | } |
| 359 | 392 | ||
| 360 | /*** |
393 | /*** |
| 361 | * write the stream |
394 | * write the stream |
| 362 | * |
395 | * |
| 363 | * @param $data |
396 | * @param $data |
| 364 | * @return |
397 | * @return |
| 365 | */ |
398 | */ |
| 366 | public function stream_write($data) |
399 | public function stream_write($data) |
| 367 | { |
400 | { |
| 368 | echo "[NTLMStream::stream_write] \n"; |
401 | echo "[NTLMStream::stream_write] \n"; |
| 369 | if(strlen($this->buffer) == 0) |
402 | if(strlen($this->buffer) == 0) |
| 370 | { |
403 | { |
| 371 | return false; |
404 | return false; |
| 372 | } |
405 | } |
| 373 | return true; |
406 | return true; |
| 374 | } |
407 | } |
| 375 | 408 | ||
| 376 | /** |
409 | /** |
| 377 | * |
410 | * |
| 378 | * @return true if eof else false |
411 | * @return true if eof else false |
| 379 | */ |
412 | */ |
| 380 | public function stream_eof() |
413 | public function stream_eof() |
| 381 | { |
414 | { |
| 382 | echo "[NTLMStream::stream_eof] "; |
415 | echo "[NTLMStream::stream_eof] "; |
| 383 | if($this->pos > strlen($this->buffer)) |
416 | if($this->pos > strlen($this->buffer)) |
| 384 | { |
417 | { |
| 385 | echo "true \n"; |
418 | echo "true \n"; |
| 386 | return true; |
419 | return true; |
| 387 | } |
420 | } |
| 388 | echo "false \n"; |
421 | echo "false \n"; |
| 389 | return false; |
422 | return false; |
| 390 | } |
423 | } |
| 391 | 424 | ||
| 392 | /** |
425 | /** |
| 393 | * @return int the position of the current read pointer |
426 | * @return int the position of the current read pointer |
| 394 | */ |
427 | */ |
| 395 | public function stream_tell() |
428 | public function stream_tell() |
| 396 | { |
429 | { |
| 397 | echo "[NTLMStream::stream_tell] \n"; |
430 | echo "[NTLMStream::stream_tell] \n"; |
| 398 | return $this->pos; |
431 | return $this->pos; |
| 399 | } |
432 | } |
| 400 | 433 | ||
| 401 | /** |
434 | /** |
| 402 | * Flush stream data |
435 | * Flush stream data |
| 403 | */ |
436 | */ |
| 404 | public function stream_flush() |
437 | public function stream_flush() |
| 405 | { |
438 | { |
| 406 | echo "[NTLMStream::stream_flush] \n"; |
439 | echo "[NTLMStream::stream_flush] \n"; |
| 407 | $this->buffer = null; |
440 | $this->buffer = null; |
| 408 | $this->pos = null; |
441 | $this->pos = null; |
| 409 | } |
442 | } |
| 410 | 443 | ||
| 411 | /** |
444 | /** |
| 412 | * Stat the file, return only the size of the buffer |
445 | * Stat the file, return only the size of the buffer |
| 413 | * |
446 | * |
| 414 | * @return array stat information |
447 | * @return array stat information |
| 415 | */ |
448 | */ |
| 416 | public function stream_stat() |
449 | public function stream_stat() |
| 417 | { |
450 | { |
| 418 | echo "[NTLMStream::stream_stat] \n"; |
451 | echo "[NTLMStream::stream_stat] \n"; |
| 419 | $this->createBuffer($this->path); |
452 | $this->createBuffer($this->path); |
| 420 | $stat = array( 'size' => strlen($this->buffer), ); |
453 | $stat = array( 'size' => strlen($this->buffer), ); |
| 421 | return $stat; |
454 | return $stat; |
| 422 | } |
455 | } |
| 423 | 456 | ||
| 424 | /** |
457 | /** |
| 425 | * Stat the url, return only the size of the buffer |
458 | * Stat the url, return only the size of the buffer |
| 426 | * |
459 | * |
| 427 | * @return array stat information |
460 | * @return array stat information |
| 428 | */ |
461 | */ |
| 429 | public function url_stat($path, $flags) |
462 | public function url_stat($path, $flags) |
| 430 | { |
463 | { |
| 431 | echo "[NTLMStream::url_stat] \n"; |
464 | echo "[NTLMStream::url_stat] \n"; |
| 432 | $this->createBuffer($path); |
465 | $this->createBuffer($path); |
| 433 | $stat = array( 'size' => strlen($this->buffer), ); |
466 | $stat = array( 'size' => strlen($this->buffer), ); |
| 434 | return $stat; |
467 | return $stat; |
| 435 | } |
468 | } |
| 436 | 469 | ||
| 437 | /* Create the buffer by requesting the url through cURL */ |
470 | /* Create the buffer by requesting the url through cURL */ |
| 438 | private function createBuffer($path) |
471 | private function createBuffer($path) |
| 439 | { |
472 | { |
| 440 | if($this->buffer) |
473 | if($this->buffer) |
| 441 | { |
474 | { |
| 442 | return; |
475 | return; |
| 443 | } |
476 | } |
| 444 | echo "[NTLMStream::createBuffer] create buffer from : $path \n"; |
477 | echo "[NTLMStream::createBuffer] create buffer from : $path \n"; |
| 445 | $this->ch = curl_init($path); |
478 | $this->ch = curl_init($path); |
| 446 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
479 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
| 447 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
480 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
| 448 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
481 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
| 449 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
482 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 450 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
483 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
| 451 | curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass); |
484 | curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass); |
| 452 | echo $this->buffer = curl_exec($this->ch); |
485 | echo $this->buffer = curl_exec($this->ch); |
| 453 | 486 | ||
| 454 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n"; |
487 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n"; |
| 455 | $this->pos = 0; |
488 | $this->pos = 0; |
| 456 | /*$myfile = "/tmp/debugex.txt"; |
489 | /*$myfile = "/tmp/debugex.txt"; |
| 457 | $fh = fopen($myfile, 'w+') or die("can't open file"); |
490 | $fh = fopen($myfile, 'w+') or die("can't open file"); |
| 458 | fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n"); |
491 | fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n"); |
| 459 | fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
492 | fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
| 460 | fwrite($fh, "reponse: ". $response."\n\n"); |
493 | fwrite($fh, "reponse: ". $response."\n\n"); |
| 461 | fclose($fh); |
494 | fclose($fh); |
| 462 | */ |
495 | */ |
| 463 | } |
496 | } |
| 464 | } |
497 | } |
| 465 | 498 | ||
| 466 | ?> |
499 | ?> |
| 467 | 500 | ||