Rev 1158 | Rev 1160 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1158 | Rev 1159 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | 2 | ||
| 3 | require(dirname(__FILE__)."/config.php"); |
3 | require(dirname(__FILE__)."/config.php"); |
| 4 | - | ||
| 5 | - | ||
| 6 | 4 | ||
| 7 | 5 | ||
| 8 | stream_wrapper_unregister('https'); |
6 | stream_wrapper_unregister('https'); |
| 9 | stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol"); |
7 | stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol"); |
| 10 | 8 | ||
| 11 |
|
9 | $wsdl = "/var/www/exchangeIntegration/Services.wsdl"; |
| 12 | $wsdl = $server.$basedir."/Services.wsdl.php"; |
- | |
| 13 | $client = new ExchangeNTLMSoapClient($wsdl); |
10 | $client = new ExchangeNTLMSoapClient($wsdl); |
| 14 | 11 | ||
| 15 | //print_array($client->__getFunctions()); |
12 | //print_array($client->__getFunctions()); |
| - | 13 | //print_array($client->__getTypes()); |
|
| 16 | echo "test<br>"; |
14 | echo "test<br>"; |
| 17 | 15 | ||
| 18 | $FindItem->Traversal = "Shallow"; |
16 | $FindItem->Traversal = "Shallow"; |
| 19 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
17 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
| 20 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
18 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
| 21 | $FindItem->CalendarView->StartDate = "2009-04-07T00:00:00Z"; |
19 | $FindItem->CalendarView->StartDate = "2009-04-07T00:00:00Z"; |
| 22 | $FindItem->CalendarView->EndDate = "2009-04-08T00:00:00Z"; |
20 | $FindItem->CalendarView->EndDate = "2009-04-08T00:00:00Z"; |
| 23 | 21 | ||
| - | 22 | try |
|
| - | 23 | { |
|
| 24 | $result = $client->FindItem($FindItem); |
24 | $result = $client->FindItem($FindItem); |
| - | 25 | } |
|
| - | 26 | catch (SoapFault $exception) |
|
| - | 27 | { |
|
| - | 28 | echo 'EXCEPTION<pre>'.$exception.'</pre>'; |
|
| - | 29 | echo "<br>"; |
|
| - | 30 | } |
|
| - | 31 | ||
| 25 | if ($result) |
32 | if ($result) |
| 26 | { |
33 | { |
| 27 | //echo "<br>result:<br>"; |
34 | //echo "<br>result:<br>"; |
| 28 |
|
35 | print_array($result); |
| 29 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
36 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
| 30 | print_array($calendaritems); |
37 | print_array($calendaritems); |
| 31 | foreach($calendaritems as $item) |
38 | foreach($calendaritems as $item) |
| 32 | { |
39 | { |
| 33 | echo "Organizer: ".$item->Organizer->Mailbox->Name." Start: ".$item->Start." End: ".$item->End."<br>"; |
40 | echo "Organizer: ".$item->Organizer->Mailbox->Name." Start: ".$item->Start." End: ".$item->End."<br>"; |
| Line 51... | Line 58... | ||
| 51 | } |
58 | } |
| 52 | 59 | ||
| 53 | class NTLMSoapClient extends SoapClient { |
60 | class NTLMSoapClient extends SoapClient { |
| 54 | function __doRequest($request, $location, $action, $version) |
61 | function __doRequest($request, $location, $action, $version) |
| 55 | { |
62 | { |
| - | 63 | $location=$exchangeurl; //override url to exchange server |
|
| - | 64 | ||
| - | 65 | $headers = array( 'Method: POST', |
|
| - | 66 | 'Connection: Keep-Alive', |
|
| - | 67 | 'User-Agent: PHP-SOAP-CURL', |
|
| 56 |
|
68 | 'Content-Type: text/xml; charset=utf-8', |
| - | 69 | 'SOAPAction: "'.$action.'"', |
|
| - | 70 | ); |
|
| 57 | $this->__last_request_headers = $headers; |
71 | $this->__last_request_headers = $headers; |
| 58 | $ch = curl_init($location); |
72 | $ch = curl_init($location); |
| 59 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
73 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 60 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
74 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 61 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
75 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| Line 64... | Line 78... | ||
| 64 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
78 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
| 65 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
79 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 66 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
80 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
| 67 | curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password); |
81 | curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password); |
| 68 | $response = curl_exec($ch); |
82 | $response = curl_exec($ch); |
| - | 83 | ||
| - | 84 | //$myfile = "/tmp/debugex.txt"; |
|
| - | 85 | //$fh = fopen($myfile, 'a+') or die("can't open file"); |
|
| - | 86 | //fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
|
| - | 87 | //fwrite($fh, "reponse: ". $response."\n\n"); |
|
| - | 88 | //fclose($fh); |
|
| - | 89 | ||
| 69 | return $response; |
90 | return $response; |
| 70 | } |
91 | } |
| 71 | 92 | ||
| 72 | function __getLastRequestHeaders() |
93 | function __getLastRequestHeaders() |
| 73 | { |
94 | { |
| 74 | return implode("\n", $this->__last_request_headers)."\n"; |
95 | return implode("\n", $this->__last_request_headers)."\n"; |
| 75 | } |
96 | } |
| 76 | } |
97 | } |
| 77 | 98 | ||
| 78 | class ExchangeNTLMSoapClient extends NTLMSoapClient |
99 | class ExchangeNTLMSoapClient extends NTLMSoapClient |
| 79 | { |
100 | { |
| 80 | protected $user = |
101 | protected $user = 'rum1'; |
| 81 | protected $password = |
102 | protected $password = 'rum1'; |
| 82 | } |
103 | } |
| 83 | 104 | ||
| 84 | class NTLMStream |
105 | class NTLMStream |
| 85 | { |
106 | { |
| 86 | private $path; |
107 | private $path; |
| Line 88... | Line 109... | ||
| 88 | private $options; |
109 | private $options; |
| 89 | private $opened_path; |
110 | private $opened_path; |
| 90 | private $buffer; |
111 | private $buffer; |
| 91 | private $pos; |
112 | private $pos; |
| 92 | 113 | ||
| - | 114 | /** |
|
| - | 115 | * Open the stream |
|
| - | 116 | * |
|
| - | 117 | * @param unknown_type $path |
|
| - | 118 | * @param unknown_type $mode |
|
| - | 119 | * @param unknown_type $options |
|
| - | 120 | * @param unknown_type $opened_path |
|
| - | 121 | * @return unknown |
|
| - | 122 | */ |
|
| 93 | public function stream_open($path, $mode, $options, $opened_path) |
123 | public function stream_open($path, $mode, $options, $opened_path) |
| 94 | { |
124 | { |
| 95 | echo "[NTLMStream::stream_open] $path , mode=$mode |
125 | echo "[NTLMStream::stream_open] $path , mode=$mode \n"; |
| 96 | $this->path = $path; |
126 | $this->path = $path; |
| 97 | $this->mode = $mode; |
127 | $this->mode = $mode; |
| 98 | $this->options = $options; |
128 | $this->options = $options; |
| 99 | $this->opened_path = $opened_path; |
129 | $this->opened_path = $opened_path; |
| 100 | $this->createBuffer($path); |
130 | $this->createBuffer($path); |
| 101 | return true; |
131 | return true; |
| 102 | } |
132 | } |
| 103 | 133 | ||
| - | 134 | /** |
|
| - | 135 | * Close the stream |
|
| - | 136 | * |
|
| - | 137 | */ |
|
| 104 | public function stream_close() |
138 | public function stream_close() |
| 105 | { |
139 | { |
| 106 | echo "[NTLMStream::stream_close] |
140 | echo "[NTLMStream::stream_close] \n"; |
| 107 | curl_close($this->ch); |
141 | curl_close($this->ch); |
| 108 | } |
142 | } |
| 109 | 143 | ||
| - | 144 | /** |
|
| - | 145 | * Read the stream |
|
| - | 146 | * |
|
| - | 147 | * @param int $count number of bytes to read |
|
| - | 148 | * @return content from pos to count |
|
| - | 149 | */ |
|
| 110 | public function stream_read($count) |
150 | public function stream_read($count) |
| 111 | { |
151 | { |
| 112 | echo "[NTLMStream::stream_read] $count |
152 | echo "[NTLMStream::stream_read] $count \n"; |
| 113 | if(strlen($this->buffer) == 0) |
153 | if(strlen($this->buffer) == 0) |
| 114 | { |
154 | { |
| 115 | return false; |
155 | return false; |
| 116 | } |
- | |
| 117 | $read = substr($this->buffer,$this->pos, $count); |
- | |
| 118 | $this->pos += $count; return $read; |
- | |
| 119 | } |
156 | } |
| - | 157 | $read = substr($this->buffer,$this->pos, $count); |
|
| - | 158 | $this->pos += $count; |
|
| - | 159 | return $read; |
|
| - | 160 | } |
|
| 120 | 161 | ||
| - | 162 | /*** |
|
| - | 163 | * write the stream |
|
| - | 164 | * |
|
| - | 165 | * @param $data |
|
| - | 166 | * @return |
|
| - | 167 | */ |
|
| 121 | public function stream_write($data) |
168 | public function stream_write($data) |
| 122 | { |
169 | { |
| 123 | echo "[NTLMStream::stream_write] |
170 | echo "[NTLMStream::stream_write] \n"; |
| 124 | if(strlen($this->buffer) == 0) |
171 | if(strlen($this->buffer) == 0) |
| 125 | { |
172 | { |
| 126 | return false; |
173 | return false; |
| 127 | } |
174 | } |
| 128 | return true; |
175 | return true; |
| 129 | } |
176 | } |
| 130 | 177 | ||
| - | 178 | /** |
|
| - | 179 | * |
|
| - | 180 | * @return true if eof else false |
|
| - | 181 | */ |
|
| 131 | public function stream_eof() |
182 | public function stream_eof() |
| 132 | { |
183 | { |
| 133 | echo "[NTLMStream::stream_eof] "; |
184 | echo "[NTLMStream::stream_eof] "; |
| 134 | if($this->pos > strlen($this->buffer)) |
185 | if($this->pos > strlen($this->buffer)) |
| 135 | { |
186 | { |
| 136 | echo "true |
187 | echo "true \n"; |
| 137 | return true; |
188 | return true; |
| 138 | } |
189 | } |
| 139 | echo "false |
190 | echo "false \n"; |
| 140 | return false; |
191 | return false; |
| 141 | } |
192 | } |
| 142 | 193 | ||
| - | 194 | /** |
|
| 143 |
|
195 | * @return int the position of the current read pointer |
| - | 196 | */ |
|
| 144 | public function stream_tell() |
197 | public function stream_tell() |
| 145 | { |
198 | { |
| 146 | echo "[NTLMStream::stream_tell] |
199 | echo "[NTLMStream::stream_tell] \n"; |
| 147 | return $this->pos; |
200 | return $this->pos; |
| 148 | } |
201 | } |
| 149 | 202 | ||
| - | 203 | /** |
|
| - | 204 | * Flush stream data |
|
| - | 205 | */ |
|
| 150 | public function stream_flush() |
206 | public function stream_flush() |
| 151 | { |
207 | { |
| 152 | echo "[NTLMStream::stream_flush] |
208 | echo "[NTLMStream::stream_flush] \n"; |
| 153 | $this->buffer = null; |
209 | $this->buffer = null; |
| 154 | $this->pos = null; |
210 | $this->pos = null; |
| 155 | } |
211 | } |
| 156 | 212 | ||
| - | 213 | /** |
|
| - | 214 | * Stat the file, return only the size of the buffer |
|
| - | 215 | * |
|
| - | 216 | * @return array stat information |
|
| - | 217 | */ |
|
| 157 | public function stream_stat() |
218 | public function stream_stat() |
| 158 | { |
219 | { |
| 159 | echo "[NTLMStream::stream_stat] |
220 | echo "[NTLMStream::stream_stat] \n"; |
| 160 | $this->createBuffer($this->path); |
221 | $this->createBuffer($this->path); |
| 161 | $stat = array( 'size' => strlen($this->buffer), ); |
222 | $stat = array( 'size' => strlen($this->buffer), ); |
| 162 | return $stat; |
223 | return $stat; |
| 163 | } |
224 | } |
| 164 | 225 | ||
| - | 226 | /** |
|
| - | 227 | * Stat the url, return only the size of the buffer |
|
| - | 228 | * |
|
| - | 229 | * @return array stat information |
|
| - | 230 | */ |
|
| 165 | public function url_stat($path, $flags) |
231 | public function url_stat($path, $flags) |
| 166 | { |
232 | { |
| 167 | echo "[NTLMStream::url_stat] |
233 | echo "[NTLMStream::url_stat] \n"; |
| 168 | $this->createBuffer($path); |
234 | $this->createBuffer($path); |
| 169 | $stat = array( 'size' => strlen($this->buffer), ); |
235 | $stat = array( 'size' => strlen($this->buffer), ); |
| 170 | return $stat; |
236 | return $stat; |
| 171 | } |
237 | } |
| 172 | 238 | ||
| Line 175... | Line 241... | ||
| 175 | { |
241 | { |
| 176 | if($this->buffer) |
242 | if($this->buffer) |
| 177 | { |
243 | { |
| 178 | return; |
244 | return; |
| 179 | } |
245 | } |
| 180 | echo "[NTLMStream::createBuffer] create buffer from : $path |
246 | echo "[NTLMStream::createBuffer] create buffer from : $path \n"; |
| 181 | $this->ch = curl_init($path); |
247 | $this->ch = curl_init($path); |
| 182 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
248 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
| 183 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
249 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
| 184 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
250 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
| 185 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
251 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
| 186 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
252 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
| 187 | curl_setopt($this->ch, CURLOPT_USERPWD, |
253 | curl_setopt($this->ch, CURLOPT_USERPWD, $this->user.':'.$this->password); |
| 188 | $this->user.':'.$this->password); |
- | |
| 189 | echo $this->buffer = curl_exec($this->ch); |
254 | echo $this->buffer = curl_exec($this->ch); |
| - | 255 | ||
| 190 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes |
256 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n"; |
| 191 | $this->pos = 0; |
257 | $this->pos = 0; |
| 192 | } |
258 | } |
| 193 | } |
259 | } |
| 194 | 260 | ||
| 195 | class ExchangeNTLMStream extends NTLMStream |
261 | class ExchangeNTLMStream extends NTLMStream |
| 196 | { |
262 | { |
| 197 | protected $user = |
263 | protected $user = 'rum1'; |
| 198 | protected $password = |
264 | protected $password = 'rum1'; |
| 199 | } |
265 | } |
| 200 | 266 | ||
| 201 | 267 | ||
| 202 | 268 | ||
| 203 | ?> |
269 | ?> |