Subversion Repositories HomeAutomation

Rev

Rev 1159 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. <?php
  2.  
  3. stream_wrapper_unregister('https');
  4. stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol");
  5.  
  6. $wsdl = "/var/www/exchange/Services.wsdl";
  7. $client = new ExchangeNTLMSoapClient($wsdl);
  8.  
  9. //print_array($client->__getFunctions());
  10. echo "test<br>";
  11.  
  12. $FindItem->Traversal = "Shallow";
  13. $FindItem->ItemShape->BaseShape = "AllProperties";
  14. $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
  15. $FindItem->CalendarView->StartDate = "2009-04-07T00:00:00Z";
  16. $FindItem->CalendarView->EndDate = "2009-04-08T00:00:00Z";
  17.  
  18. $result = $client->FindItem($FindItem);
  19. if ($result)
  20. {
  21.   //echo "<br>result:<br>";
  22.   //print_array($result);
  23.   $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
  24.   print_array($calendaritems);
  25.   foreach($calendaritems as $item)
  26.   {
  27.     echo "Organizer: ".$item->Organizer->Mailbox->Name." Start: ".$item->Start." End: ".$item->End."<br>";
  28.   }
  29. }
  30.  
  31. 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>";
  32.  
  33.  
  34. echo "<br><br>slut test<br>";
  35.  
  36. stream_wrapper_restore('https');
  37.  
  38.  
  39.  
  40. function print_array($var)
  41. {
  42.     echo "<pre>\n";
  43.     print_r($var);
  44.     echo "</pre>\n";
  45. }
  46.  
  47. class NTLMSoapClient extends SoapClient {
  48.   function __doRequest($request, $location, $action, $version)
  49.   {
  50.     $headers = array( 'Method: POST', 'Connection: Keep-Alive', 'User-Agent: PHP-SOAP-CURL', 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: "'.$action.'"', );
  51.     $this->__last_request_headers = $headers;
  52.     $ch = curl_init($location);
  53.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  54.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  55.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  56.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  57.     curl_setopt($ch, CURLOPT_POST, true );
  58.     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  59.     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  60.     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  61.     curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
  62.     $response = curl_exec($ch);
  63.     return $response;
  64.   }
  65.  
  66.   function __getLastRequestHeaders()
  67.   {
  68.     return implode("\n", $this->__last_request_headers)."\n";
  69.   }
  70. }
  71.  
  72. class ExchangeNTLMSoapClient extends NTLMSoapClient
  73. {
  74.   protected $user = 'xyz';
  75.   protected $password = 'xyz';
  76. }
  77.  
  78. class NTLMStream
  79. {
  80.   private $path;
  81.   private $mode;
  82.   private $options;
  83.   private $opened_path;
  84.   private $buffer;
  85.   private $pos;
  86.  
  87.   public function stream_open($path, $mode, $options, $opened_path)
  88.   {
  89.     echo "[NTLMStream::stream_open] $path , mode=$mode <br>";
  90.     $this->path = $path;
  91.     $this->mode = $mode;
  92.     $this->options = $options;
  93.     $this->opened_path = $opened_path;
  94.     $this->createBuffer($path);
  95.     return true;
  96.   }
  97.  
  98.   public function stream_close()
  99.   {
  100.     echo "[NTLMStream::stream_close] <br>";
  101.     curl_close($this->ch);
  102.   }
  103.  
  104.   public function stream_read($count)
  105.   {
  106.     echo "[NTLMStream::stream_read] $count <br>";
  107.     if(strlen($this->buffer) == 0)
  108.     {
  109.       return false;
  110.     }
  111.     $read = substr($this->buffer,$this->pos, $count);
  112.     $this->pos += $count; return $read;
  113.   }
  114.  
  115.   public function stream_write($data)
  116.   {
  117.     echo "[NTLMStream::stream_write] <br>";
  118.     if(strlen($this->buffer) == 0)
  119.     {
  120.       return false;
  121.     }
  122.     return true;
  123.   }
  124.  
  125.   public function stream_eof()
  126.   {
  127.     echo "[NTLMStream::stream_eof] ";
  128.     if($this->pos > strlen($this->buffer))
  129.     {
  130.       echo "true <br>";
  131.       return true;
  132.     }
  133.     echo "false <br>";
  134.     return false;
  135.   }
  136.  
  137.   /* return the position of the current read pointer */
  138.   public function stream_tell()
  139.   {
  140.     echo "[NTLMStream::stream_tell] <br>";
  141.     return $this->pos;
  142.   }
  143.  
  144.   public function stream_flush()
  145.   {
  146.     echo "[NTLMStream::stream_flush] <br>";
  147.     $this->buffer = null;
  148.     $this->pos = null;
  149.   }
  150.  
  151.   public function stream_stat()
  152.   {
  153.     echo "[NTLMStream::stream_stat] <br>";
  154.     $this->createBuffer($this->path);
  155.     $stat = array( 'size' => strlen($this->buffer), );
  156.     return $stat;
  157.   }
  158.  
  159.   public function url_stat($path, $flags)
  160.   {
  161.     echo "[NTLMStream::url_stat] <br>";
  162.     $this->createBuffer($path);
  163.     $stat = array( 'size' => strlen($this->buffer), );
  164.     return $stat;
  165.   }
  166.  
  167.   /* Create the buffer by requesting the url through cURL */
  168.   private function createBuffer($path)
  169.   {
  170.     if($this->buffer)
  171.     {
  172.       return;
  173.     }
  174.     echo "[NTLMStream::createBuffer] create buffer from : $path <br>";
  175.     $this->ch = curl_init($path);
  176.     curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
  177.     curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
  178.     curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  179.     curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  180.     curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  181.     curl_setopt($this->ch, CURLOPT_USERPWD,
  182.     $this->user.':'.$this->password);
  183.     echo $this->buffer = curl_exec($this->ch);
  184.     echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes <br>";
  185.     $this->pos = 0;
  186.   }
  187. }
  188.  
  189. class ExchangeNTLMStream extends NTLMStream
  190. {
  191.   protected $user = 'xyz';
  192.   protected $password = 'xyz';
  193. }
  194.  
  195.  
  196.  
  197. ?>
  198.