Rev 1159 | Rev 1161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1159 | Rev 1160 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | 4 | ||
| 5 | - | ||
| 6 | stream_wrapper_unregister('https'); |
- | |
| 7 | stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol"); |
- | |
| 8 | - | ||
| 9 | $wsdl = "/var/www/exchangeIntegration/Services.wsdl"; |
- | |
| 10 | $client = new ExchangeNTLMSoapClient($wsdl); |
- | |
| 11 | - | ||
| 12 |
|
5 | if (isset($_GET["function"])) |
| 13 | //print_array($client->__getTypes()); |
- | |
| 14 | echo "test<br>"; |
- | |
| 15 | - | ||
| 16 | $FindItem->Traversal = "Shallow"; |
- | |
| 17 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
- | |
| 18 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
- | |
| 19 | $FindItem->CalendarView->StartDate = "2009-04-07T00:00:00Z"; |
- | |
| 20 | $FindItem->CalendarView->EndDate = "2009-04-08T00:00:00Z"; |
- | |
| 21 | - | ||
| 22 | try |
- | |
| 23 | { |
- | |
| 24 | $result = $client->FindItem($FindItem); |
- | |
| 25 | } |
- | |
| 26 | catch (SoapFault $exception) |
- | |
| 27 | { |
- | |
| 28 | echo 'EXCEPTION<pre>'.$exception.'</pre>'; |
- | |
| 29 | echo "<br>"; |
- | |
| 30 | } |
- | |
| 31 | - | ||
| 32 | if ($result) |
- | |
| 33 | { |
6 | { |
| 34 |
|
7 | switch ($_GET["function"]) |
| - | 8 | { |
|
| 35 |
|
9 | case "getMeetingsRestOfDay": |
| 36 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
- | |
| 37 |
|
10 | if (isset($_GET["shortname"])) |
| - | 11 | { |
|
| 38 |
|
12 | echo getMeetingsRestOfDay($_GET["shortname"]); |
| 39 | |
13 | } |
| - | 14 | break; |
|
| - | 15 | ||
| 40 |
|
16 | case "bookMeeting": |
| - | 17 | break; |
|
| - | 18 | ||
| - | 19 | //case "": |
|
| 41 |
|
20 | // |
| - | 21 | //break; |
|
| 42 | } |
22 | } |
| 43 | 23 | ||
| 44 |
|
24 | function getMeetingsRestOfDay($shortname) |
| 45 | 25 | { |
|
| - | 26 | global $Calender; |
|
| - | 27 | global $wsdl; |
|
| - | 28 | $founditem = false; |
|
| - | 29 | ||
| - | 30 | foreach($Calender as $item) |
|
| - | 31 | { |
|
| - | 32 | if ($item->Shortname == $shortname) |
|
| - | 33 | { |
|
| - | 34 | $founditem = $item; |
|
| - | 35 | break; |
|
| - | 36 | } |
|
| - | 37 | } |
|
| 46 | 38 | ||
| - | 39 | if ($founditem !== false) |
|
| - | 40 | { |
|
| - | 41 | $user = $founditem->UserName; |
|
| - | 42 | $pass = $founditem->Password; |
|
| - | 43 | ||
| - | 44 | $FindItem->Traversal = "Shallow"; |
|
| - | 45 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
|
| - | 46 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
|
| - | 47 | $FindItem->CalendarView->StartDate = "2009-04-07T00:00:00Z"; |
|
| - | 48 | $FindItem->CalendarView->EndDate = "2009-04-08T00:00:00Z"; |
|
| - | 49 | ||
| - | 50 | stream_wrapper_unregister('https'); |
|
| - | 51 | stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol"); |
|
| - | 52 | ||
| - | 53 | try |
|
| - | 54 | { |
|
| - | 55 | $client = new NTLMSoapClient($wsdl); |
|
| - | 56 | $result = $client->FindItem($FindItem); |
|
| - | 57 | if ($result) |
|
| - | 58 | { |
|
| - | 59 | //print_array($result); |
|
| - | 60 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
|
| - | 61 | //print_array($calendaritems); |
|
| - | 62 | foreach($calendaritems as $item) |
|
| - | 63 | { |
|
| - | 64 | return "Organizer: ".$item->Organizer->Mailbox->Name." Start: ".$item->Start." End: ".$item->End."<br>"; |
|
| - | 65 | } |
|
| - | 66 | } |
|
| - | 67 | ||
| - | 68 | } |
|
| - | 69 | catch (SoapFault $exception) |
|
| - | 70 | { |
|
| 47 |
|
71 | return "<error>".$exception."</error>"; |
| - | 72 | } |
|
| 48 | 73 | ||
| 49 | stream_wrapper_restore('https'); |
74 | stream_wrapper_restore('https'); |
| - | 75 | } |
|
| - | 76 | else |
|
| - | 77 | { |
|
| - | 78 | return "<error>Unknown shortname</error>"; |
|
| - | 79 | } |
|
| 50 | 80 | ||
| - | 81 | ||
| - | 82 | //echo "<br>OBS tidszon+sommartid?? nu sommartid, ett möte som ovan gav start 13:00 var egentligen 15:00<br>OBS utf? teckenkodning<br>"; |
|
| - | 83 | } |
|
| 51 | 84 | ||
| 52 | 85 | ||
| 53 | function print_array($var) |
86 | function print_array($var) |
| 54 | { |
87 | { |
| 55 | echo "<pre>\n"; |
88 | echo "<pre>\n"; |
| Line 58... | Line 91... | ||
| 58 | } |
91 | } |
| 59 | 92 | ||
| 60 | class NTLMSoapClient extends SoapClient { |
93 | class NTLMSoapClient extends SoapClient { |
| 61 | function __doRequest($request, $location, $action, $version) |
94 | function __doRequest($request, $location, $action, $version) |
| 62 | { |
95 | { |
| - | 96 | global $user; |
|
| - | 97 | global $pass; |
|
| - | 98 | global $exchangeurl; |
|
| 63 | $location=$exchangeurl; //override url to exchange server |
99 | $location=$exchangeurl; //override url to exchange server |
| 64 | 100 | ||
| 65 | $headers = array( 'Method: POST', |
101 | $headers = array( 'Method: POST', |
| 66 | 'Connection: Keep-Alive', |
102 | 'Connection: Keep-Alive', |
| 67 | 'User-Agent: PHP-SOAP-CURL', |
103 | 'User-Agent: PHP-SOAP-CURL', |
| Line 76... | Line 112... | ||
| 76 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
112 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| 77 | curl_setopt($ch, CURLOPT_POST, true ); |
113 | curl_setopt($ch, CURLOPT_POST, true ); |
| 78 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
114 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
| 79 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
115 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 80 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
116 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
| 81 | curl_setopt($ch, CURLOPT_USERPWD, |
117 | curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$pass); |
| 82 | $response = curl_exec($ch); |
118 | $response = curl_exec($ch); |
| 83 | 119 | ||
| 84 | //$myfile = "/tmp/debugex.txt"; |
120 | //$myfile = "/tmp/debugex.txt"; |
| 85 | //$fh = fopen($myfile, 'a+') or die("can't open file"); |
121 | //$fh = fopen($myfile, 'a+') or die("can't open file"); |
| 86 | //fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
122 | //fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
| Line 91... | Line 127... | ||
| 91 | } |
127 | } |
| 92 | 128 | ||
| 93 | function __getLastRequestHeaders() |
129 | function __getLastRequestHeaders() |
| 94 | { |
130 | { |
| 95 | return implode("\n", $this->__last_request_headers)."\n"; |
131 | return implode("\n", $this->__last_request_headers)."\n"; |
| 96 | } |
132 | } |
| 97 | } |
133 | } |
| 98 | 134 | ||
| 99 | class ExchangeNTLMSoapClient extends NTLMSoapClient |
- | |
| 100 | { |
- | |
| 101 | protected $user = 'rum1'; |
- | |
| 102 | protected $password = 'rum1'; |
- | |
| 103 | } |
- | |
| 104 | 135 | ||
| 105 | class NTLMStream |
136 | class NTLMStream |
| 106 | { |
137 | { |
| 107 | private $path; |
138 | private $path; |
| 108 | private $mode; |
139 | private $mode; |
| Line 148... | Line 179... | ||
| 148 | * @return content from pos to count |
179 | * @return content from pos to count |
| 149 | */ |
180 | */ |
| 150 | public function stream_read($count) |
181 | public function stream_read($count) |
| 151 | { |
182 | { |
| 152 | echo "[NTLMStream::stream_read] $count \n"; |
183 | echo "[NTLMStream::stream_read] $count \n"; |
| 153 | if(strlen($this->buffer) == 0) |
184 | if(strlen($this->buffer) == 0) |
| 154 | { |
185 | { |
| 155 | return false; |
186 | return false; |
| 156 | } |
187 | } |
| 157 | $read = substr($this->buffer,$this->pos, $count); |
188 | $read = substr($this->buffer,$this->pos, $count); |
| 158 | $this->pos += $count; |
189 | $this->pos += $count; |
| Line 227... | Line 258... | ||
| 227 | * Stat the url, return only the size of the buffer |
258 | * Stat the url, return only the size of the buffer |
| 228 | * |
259 | * |
| 229 | * @return array stat information |
260 | * @return array stat information |
| 230 | */ |
261 | */ |
| 231 | public function url_stat($path, $flags) |
262 | public function url_stat($path, $flags) |
| 232 | { |
263 | { |
| 233 | echo "[NTLMStream::url_stat] \n"; |
264 | echo "[NTLMStream::url_stat] \n"; |
| 234 | $this->createBuffer($path); |
265 | $this->createBuffer($path); |
| 235 | $stat = array( 'size' => strlen($this->buffer), ); |
266 | $stat = array( 'size' => strlen($this->buffer), ); |
| 236 | return $stat; |
267 | return $stat; |
| 237 | } |
268 | } |
| 238 | 269 | ||
| 239 | /* Create the buffer by requesting the url through cURL */ |
270 | /* Create the buffer by requesting the url through cURL */ |
| 240 | private function createBuffer($path) |
271 | private function createBuffer($path) |
| 241 | { |
272 | { |
| - | 273 | global $user; |
|
| - | 274 | global $pass; |
|
| 242 | if($this->buffer) |
275 | if($this->buffer) |
| 243 | { |
276 | { |
| 244 | return; |
277 | return; |
| 245 | } |
278 | } |
| 246 | echo "[NTLMStream::createBuffer] create buffer from : $path \n"; |
279 | echo "[NTLMStream::createBuffer] create buffer from : $path \n"; |
| Line 248... | Line 281... | ||
| 248 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
281 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
| 249 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
282 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
| 250 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
283 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
| 251 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
284 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 252 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
285 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
| 253 | curl_setopt($this->ch, CURLOPT_USERPWD, |
286 | curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass); |
| 254 | echo $this->buffer = curl_exec($this->ch); |
287 | echo $this->buffer = curl_exec($this->ch); |
| 255 | 288 | ||
| 256 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n"; |
289 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n"; |
| 257 | $this->pos = 0; |
290 | $this->pos = 0; |
| 258 | } |
291 | } |
| 259 | } |
292 | } |
| 260 | - | ||
| 261 | class ExchangeNTLMStream extends NTLMStream |
- | |
| 262 | { |
- | |
| 263 | protected $user = 'rum1'; |
- | |
| 264 | protected $password = 'rum1'; |
- | |
| 265 | } |
- | |
| 266 | - | ||
| 267 | - | ||
| 268 | 293 | ||
| 269 | ?> |
294 | ?> |