Subversion Repositories HomeAutomation

Rev

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