Subversion Repositories HomeAutomation

Rev

Rev 1151 | Rev 1159 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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