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