Subversion Repositories HomeAutomation

Rev

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

  1. <?php
  2.  
  3. require(dirname(__FILE__)."/config.php");
  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. //print_array($client->__getFunctions());
  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. {
  34.   //echo "<br>result:<br>";
  35.   print_array($result);
  36.   $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
  37.   print_array($calendaritems);
  38.   foreach($calendaritems as $item)
  39.   {
  40.     echo "Organizer: ".$item->Organizer->Mailbox->Name." Start: ".$item->Start." End: ".$item->End."<br>";
  41.   }
  42. }
  43.  
  44. 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>";
  45.  
  46.  
  47. echo "<br><br>slut test<br>";
  48.  
  49. stream_wrapper_restore('https');
  50.  
  51.  
  52.  
  53. function print_array($var)
  54. {
  55.     echo "<pre>\n";
  56.     print_r($var);
  57.     echo "</pre>\n";
  58. }
  59.  
  60. class NTLMSoapClient extends SoapClient {
  61.   function __doRequest($request, $location, $action, $version)
  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',
  68.             'Content-Type: text/xml; charset=utf-8',
  69.             'SOAPAction: "'.$action.'"',
  70.             );
  71.     $this->__last_request_headers = $headers;
  72.     $ch = curl_init($location);
  73.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  74.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  75.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  76.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  77.     curl_setopt($ch, CURLOPT_POST, true );
  78.     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  79.     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  80.     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  81.     curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
  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.    
  90.     return $response;
  91.   }
  92.  
  93.   function __getLastRequestHeaders()
  94.   {
  95.     return implode("\n", $this->__last_request_headers)."\n";
  96.   }
  97. }
  98.  
  99. class ExchangeNTLMSoapClient extends NTLMSoapClient
  100. {
  101.   protected $user = 'rum1';
  102.   protected $password = 'rum1';
  103. }
  104.  
  105. class NTLMStream
  106. {
  107.   private $path;
  108.   private $mode;
  109.   private $options;
  110.   private $opened_path;
  111.   private $buffer;
  112.   private $pos;
  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.      */
  123.   public function stream_open($path, $mode, $options, $opened_path)
  124.   {
  125.     echo "[NTLMStream::stream_open] $path , mode=$mode \n";
  126.     $this->path = $path;
  127.     $this->mode = $mode;
  128.     $this->options = $options;
  129.     $this->opened_path = $opened_path;
  130.     $this->createBuffer($path);
  131.     return true;
  132.   }
  133.  
  134.     /**
  135.      * Close the stream
  136.      *
  137.      */
  138.   public function stream_close()
  139.   {
  140.     echo "[NTLMStream::stream_close] \n";
  141.     curl_close($this->ch);
  142.   }
  143.  
  144.     /**
  145.      * Read the stream
  146.      *
  147.      * @param int $count number of bytes to read
  148.      * @return content from pos to count
  149.      */
  150.   public function stream_read($count)
  151.   {
  152.     echo "[NTLMStream::stream_read] $count \n";
  153.     if(strlen($this->buffer) == 0)
  154.     {
  155.       return false;
  156.     }
  157.     $read = substr($this->buffer,$this->pos, $count);
  158.     $this->pos += $count;
  159.     return $read;
  160.   }
  161.  
  162.     /***
  163.      * write the stream
  164.      *
  165.      * @param $data
  166.      * @return
  167.      */
  168.   public function stream_write($data)
  169.   {
  170.     echo "[NTLMStream::stream_write] \n";
  171.     if(strlen($this->buffer) == 0)
  172.     {
  173.       return false;
  174.     }
  175.     return true;
  176.   }
  177.  
  178.     /**
  179.      *
  180.      * @return true if eof else false
  181.      */
  182.   public function stream_eof()
  183.   {
  184.     echo "[NTLMStream::stream_eof] ";
  185.     if($this->pos > strlen($this->buffer))
  186.     {
  187.       echo "true \n";
  188.       return true;
  189.     }
  190.     echo "false \n";
  191.     return false;
  192.   }
  193.  
  194.     /**
  195.      * @return int the position of the current read pointer
  196.      */
  197.   public function stream_tell()
  198.   {
  199.     echo "[NTLMStream::stream_tell] \n";
  200.     return $this->pos;
  201.   }
  202.  
  203.     /**
  204.      * Flush stream data
  205.      */
  206.   public function stream_flush()
  207.   {
  208.     echo "[NTLMStream::stream_flush] \n";
  209.     $this->buffer = null;
  210.     $this->pos = null;
  211.   }
  212.  
  213.     /**
  214.      * Stat the file, return only the size of the buffer
  215.      *
  216.      * @return array stat information
  217.      */
  218.   public function stream_stat()
  219.   {
  220.     echo "[NTLMStream::stream_stat] \n";
  221.     $this->createBuffer($this->path);
  222.     $stat = array( 'size' => strlen($this->buffer), );
  223.     return $stat;
  224.   }
  225.  
  226.     /**
  227.      * Stat the url, return only the size of the buffer
  228.      *
  229.      * @return array stat information
  230.      */
  231.   public function url_stat($path, $flags)
  232.   {
  233.     echo "[NTLMStream::url_stat] \n";
  234.     $this->createBuffer($path);
  235.     $stat = array( 'size' => strlen($this->buffer), );
  236.     return $stat;
  237.   }
  238.  
  239.   /* Create the buffer by requesting the url through cURL */
  240.   private function createBuffer($path)
  241.   {
  242.     if($this->buffer)
  243.     {
  244.       return;
  245.     }
  246.     echo "[NTLMStream::createBuffer] create buffer from : $path \n";
  247.     $this->ch = curl_init($path);
  248.     curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
  249.     curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
  250.     curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  251.     curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  252.     curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  253.     curl_setopt($this->ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
  254.     echo $this->buffer = curl_exec($this->ch);
  255.    
  256.     echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n";
  257.     $this->pos = 0;
  258.   }
  259. }
  260.  
  261. class ExchangeNTLMStream extends NTLMStream
  262. {
  263.   protected $user = 'rum1';
  264.   protected $password = 'rum1';
  265. }
  266.  
  267.  
  268.  
  269. ?>
  270.