Rev 1165 | Rev 1194 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1151 | arune | 1 | <?php |
| 2 | |||
| 1158 | arune | 3 | require(dirname(__FILE__)."/config.php"); |
| 4 | |||
| 1160 | arune | 5 | if (isset($_GET["function"])) |
| 1159 | arune | 6 | { |
| 1160 | arune | 7 | switch ($_GET["function"]) |
| 8 | { |
||
| 9 | case "getMeetingsRestOfDay": |
||
| 10 | if (isset($_GET["shortname"])) |
||
| 11 | { |
||
| 12 | echo getMeetingsRestOfDay($_GET["shortname"]); |
||
| 13 | } |
||
| 14 | break; |
||
| 15 | |||
| 16 | case "bookMeeting": |
||
| 1162 | arune | 17 | if (isset($_GET["from"]) && isset($_GET["to"])) |
| 18 | { |
||
| 19 | |||
| 20 | } |
||
| 1160 | arune | 21 | break; |
| 22 | |||
| 23 | //case "": |
||
| 24 | // |
||
| 25 | //break; |
||
| 1161 | arune | 26 | } |
| 1159 | arune | 27 | } |
| 28 | |||
| 1160 | arune | 29 | function getMeetingsRestOfDay($shortname) |
| 1151 | arune | 30 | { |
| 1160 | arune | 31 | global $Calender; |
| 32 | global $wsdl; |
||
| 33 | $founditem = false; |
||
| 34 | |||
| 35 | foreach($Calender as $item) |
||
| 36 | { |
||
| 37 | if ($item->Shortname == $shortname) |
||
| 38 | { |
||
| 39 | $founditem = $item; |
||
| 40 | break; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($founditem !== false) |
||
| 45 | { |
||
| 46 | $FindItem->Traversal = "Shallow"; |
||
| 47 | $FindItem->ItemShape->BaseShape = "AllProperties"; |
||
| 48 | $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar"; |
||
| 1162 | arune | 49 | /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */ |
| 50 | $FindItem->CalendarView->StartDate = date("c"); //"2009-04-07T08:00:00Z"; |
||
| 51 | $FindItem->CalendarView->EndDate = date("c", strtotime("+9 hour")); //"2009-04-08T00:00:00Z"; |
||
| 52 | //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n"; |
||
| 53 | |||
| 1160 | arune | 54 | stream_wrapper_unregister('https'); |
| 55 | stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol"); |
||
| 56 | |||
| 1169 | arune | 57 | $returndata = "{ \n\tshortname:'".$shortname."',\n\tmeetings:[\n"; |
| 1160 | arune | 58 | try |
| 59 | { |
||
| 1161 | arune | 60 | $client = new ExchangeNTLMSoapClient($wsdl); |
| 61 | $client->user = $founditem->UserName; |
||
| 62 | $client->pass = $founditem->Password; |
||
| 1160 | arune | 63 | $result = $client->FindItem($FindItem); |
| 64 | if ($result) |
||
| 65 | { |
||
| 1163 | arune | 66 | //print_array($result); |
| 67 | $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem; |
||
| 68 | //print_array($calendaritems); |
||
| 69 | for ($i = 0; $i < count($calendaritems); $i++) |
||
| 70 | { |
||
| 1169 | arune | 71 | if (count($calendaritems) > 1) |
| 72 | { |
||
| 73 | $item = $calendaritems[$i]; |
||
| 74 | } |
||
| 75 | else |
||
| 76 | { |
||
| 77 | $item = $calendaritems; |
||
| 78 | } |
||
| 79 | $returndata .= "\t\t{\n"; |
||
| 80 | $returndata .= "\t\torganizer:'".$item->Organizer->Mailbox->Name."',\n"; |
||
| 81 | $returndata .= "\t\tstart:'".date("G:i", strtotime($item->Start))."',\n"; |
||
| 82 | $returndata .= "\t\tend:'".date("G:i", strtotime($item->End))."'\n"; |
||
| 83 | $returndata .= "\t\t}"; |
||
| 84 | if ($i+1 < count($calendaritems)) |
||
| 85 | { |
||
| 86 | $returndata .= ",\n"; |
||
| 87 | } |
||
| 1162 | arune | 88 | } |
| 1160 | arune | 89 | } |
| 90 | |||
| 91 | } |
||
| 92 | catch (SoapFault $exception) |
||
| 93 | { |
||
| 1169 | arune | 94 | return "{ error:'".$exception."',\nshortname:'".$shortname."'}\n"; |
| 1160 | arune | 95 | } |
| 1151 | arune | 96 | |
| 1164 | arune | 97 | stream_wrapper_restore('https'); |
| 1169 | arune | 98 | $returndata .= "\n\t]\n}\n"; |
| 1164 | arune | 99 | return $returndata; |
| 1160 | arune | 100 | } |
| 101 | else |
||
| 102 | { |
||
| 1169 | arune | 103 | return "{ error:'Unknown shortname',\nshortname:'".$shortname."'}\n"; |
| 1160 | arune | 104 | } |
| 105 | } |
||
| 1151 | arune | 106 | |
| 107 | |||
| 108 | function print_array($var) |
||
| 109 | { |
||
| 1163 | arune | 110 | echo "<pre>\n"; |
| 111 | print_r($var); |
||
| 112 | echo "</pre>\n"; |
||
| 1151 | arune | 113 | } |
| 114 | |||
| 115 | class NTLMSoapClient extends SoapClient { |
||
| 1163 | arune | 116 | function __doRequest($request, $location, $action, $version) |
| 117 | { |
||
| 118 | global $exchangeurl; |
||
| 119 | $location=$exchangeurl; //override url to exchange server |
||
| 1159 | arune | 120 | |
| 1163 | arune | 121 | $headers = array( 'Method: POST', |
| 1159 | arune | 122 | 'Connection: Keep-Alive', |
| 123 | 'User-Agent: PHP-SOAP-CURL', |
||
| 124 | 'Content-Type: text/xml; charset=utf-8', |
||
| 125 | 'SOAPAction: "'.$action.'"', |
||
| 126 | ); |
||
| 1163 | arune | 127 | $this->__last_request_headers = $headers; |
| 128 | $ch = curl_init($location); |
||
| 129 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
| 130 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
||
| 131 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
| 132 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
||
| 133 | curl_setopt($ch, CURLOPT_POST, true ); |
||
| 134 | curl_setopt($ch, CURLOPT_POSTFIELDS, $request); |
||
| 135 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
||
| 136 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
||
| 137 | curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass); |
||
| 138 | $response = curl_exec($ch); |
||
| 1159 | arune | 139 | |
| 1161 | arune | 140 | /*$myfile = "/tmp/debugex.txt"; |
| 141 | $fh = fopen($myfile, 'w+') or die("can't open file"); |
||
| 142 | fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n"); |
||
| 143 | fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
||
| 144 | fwrite($fh, "reponse: ". $response."\n\n"); |
||
| 145 | fclose($fh); |
||
| 146 | */ |
||
| 1163 | arune | 147 | |
| 148 | return $response; |
||
| 149 | } |
||
| 150 | |||
| 151 | function __getLastRequestHeaders() |
||
| 152 | { |
||
| 153 | return implode("\n", $this->__last_request_headers)."\n"; |
||
| 154 | } |
||
| 1151 | arune | 155 | } |
| 156 | |||
| 1161 | arune | 157 | class ExchangeNTLMSoapClient extends NTLMSoapClient |
| 158 | { |
||
| 159 | public $user = ''; |
||
| 160 | public $password = ''; |
||
| 161 | } |
||
| 1151 | arune | 162 | |
| 163 | class NTLMStream |
||
| 164 | { |
||
| 1163 | arune | 165 | private $path; |
| 166 | private $mode; |
||
| 167 | private $options; |
||
| 168 | private $opened_path; |
||
| 169 | private $buffer; |
||
| 170 | private $pos; |
||
| 1151 | arune | 171 | |
| 1159 | arune | 172 | /** |
| 173 | * Open the stream |
||
| 174 | * |
||
| 175 | * @param unknown_type $path |
||
| 176 | * @param unknown_type $mode |
||
| 177 | * @param unknown_type $options |
||
| 178 | * @param unknown_type $opened_path |
||
| 179 | * @return unknown |
||
| 180 | */ |
||
| 1163 | arune | 181 | public function stream_open($path, $mode, $options, $opened_path) |
| 182 | { |
||
| 183 | echo "[NTLMStream::stream_open] $path , mode=$mode \n"; |
||
| 184 | $this->path = $path; |
||
| 185 | $this->mode = $mode; |
||
| 186 | $this->options = $options; |
||
| 187 | $this->opened_path = $opened_path; |
||
| 188 | $this->createBuffer($path); |
||
| 189 | return true; |
||
| 190 | } |
||
| 1151 | arune | 191 | |
| 1159 | arune | 192 | /** |
| 193 | * Close the stream |
||
| 194 | * |
||
| 195 | */ |
||
| 1163 | arune | 196 | public function stream_close() |
| 197 | { |
||
| 198 | echo "[NTLMStream::stream_close] \n"; |
||
| 199 | curl_close($this->ch); |
||
| 200 | } |
||
| 1151 | arune | 201 | |
| 1159 | arune | 202 | /** |
| 203 | * Read the stream |
||
| 204 | * |
||
| 205 | * @param int $count number of bytes to read |
||
| 206 | * @return content from pos to count |
||
| 207 | */ |
||
| 1163 | arune | 208 | public function stream_read($count) |
| 209 | { |
||
| 210 | echo "[NTLMStream::stream_read] $count \n"; |
||
| 211 | if(strlen($this->buffer) == 0) |
||
| 212 | { |
||
| 213 | return false; |
||
| 214 | } |
||
| 215 | $read = substr($this->buffer,$this->pos, $count); |
||
| 216 | $this->pos += $count; |
||
| 217 | return $read; |
||
| 218 | } |
||
| 1151 | arune | 219 | |
| 1159 | arune | 220 | /*** |
| 221 | * write the stream |
||
| 222 | * |
||
| 223 | * @param $data |
||
| 224 | * @return |
||
| 225 | */ |
||
| 1163 | arune | 226 | public function stream_write($data) |
| 227 | { |
||
| 228 | echo "[NTLMStream::stream_write] \n"; |
||
| 229 | if(strlen($this->buffer) == 0) |
||
| 230 | { |
||
| 231 | return false; |
||
| 232 | } |
||
| 233 | return true; |
||
| 234 | } |
||
| 1151 | arune | 235 | |
| 1159 | arune | 236 | /** |
| 237 | * |
||
| 238 | * @return true if eof else false |
||
| 239 | */ |
||
| 1163 | arune | 240 | public function stream_eof() |
| 241 | { |
||
| 242 | echo "[NTLMStream::stream_eof] "; |
||
| 243 | if($this->pos > strlen($this->buffer)) |
||
| 244 | { |
||
| 245 | echo "true \n"; |
||
| 246 | return true; |
||
| 247 | } |
||
| 248 | echo "false \n"; |
||
| 249 | return false; |
||
| 250 | } |
||
| 1151 | arune | 251 | |
| 1159 | arune | 252 | /** |
| 253 | * @return int the position of the current read pointer |
||
| 254 | */ |
||
| 1163 | arune | 255 | public function stream_tell() |
| 256 | { |
||
| 257 | echo "[NTLMStream::stream_tell] \n"; |
||
| 258 | return $this->pos; |
||
| 259 | } |
||
| 1151 | arune | 260 | |
| 1159 | arune | 261 | /** |
| 262 | * Flush stream data |
||
| 263 | */ |
||
| 1163 | arune | 264 | public function stream_flush() |
| 265 | { |
||
| 266 | echo "[NTLMStream::stream_flush] \n"; |
||
| 267 | $this->buffer = null; |
||
| 268 | $this->pos = null; |
||
| 269 | } |
||
| 1151 | arune | 270 | |
| 1159 | arune | 271 | /** |
| 272 | * Stat the file, return only the size of the buffer |
||
| 273 | * |
||
| 274 | * @return array stat information |
||
| 275 | */ |
||
| 1163 | arune | 276 | public function stream_stat() |
| 277 | { |
||
| 278 | echo "[NTLMStream::stream_stat] \n"; |
||
| 279 | $this->createBuffer($this->path); |
||
| 280 | $stat = array( 'size' => strlen($this->buffer), ); |
||
| 281 | return $stat; |
||
| 282 | } |
||
| 1151 | arune | 283 | |
| 1159 | arune | 284 | /** |
| 285 | * Stat the url, return only the size of the buffer |
||
| 286 | * |
||
| 287 | * @return array stat information |
||
| 288 | */ |
||
| 1163 | arune | 289 | public function url_stat($path, $flags) |
| 290 | { |
||
| 291 | echo "[NTLMStream::url_stat] \n"; |
||
| 292 | $this->createBuffer($path); |
||
| 293 | $stat = array( 'size' => strlen($this->buffer), ); |
||
| 294 | return $stat; |
||
| 295 | } |
||
| 1151 | arune | 296 | |
| 1163 | arune | 297 | /* Create the buffer by requesting the url through cURL */ |
| 298 | private function createBuffer($path) |
||
| 299 | { |
||
| 300 | if($this->buffer) |
||
| 301 | { |
||
| 302 | return; |
||
| 303 | } |
||
| 304 | echo "[NTLMStream::createBuffer] create buffer from : $path \n"; |
||
| 305 | $this->ch = curl_init($path); |
||
| 306 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); |
||
| 307 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); |
||
| 308 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
||
| 309 | curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
||
| 310 | curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); |
||
| 311 | curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass); |
||
| 312 | echo $this->buffer = curl_exec($this->ch); |
||
| 313 | |||
| 314 | echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n"; |
||
| 315 | $this->pos = 0; |
||
| 316 | /*$myfile = "/tmp/debugex.txt"; |
||
| 317 | $fh = fopen($myfile, 'w+') or die("can't open file"); |
||
| 318 | fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n"); |
||
| 319 | fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n"); |
||
| 320 | fwrite($fh, "reponse: ". $response."\n\n"); |
||
| 321 | fclose($fh); |
||
| 322 | */ |
||
| 323 | } |
||
| 1159 | arune | 324 | } |
| 1151 | arune | 325 | |
| 326 | ?> |