Hallo,
UPDATE 2010-01-10:
mit Version 2.2 funktioniert es, da hier PHP 5.3.1 an Board ist.
habe zuhause Exchange 2007 und würde gerne meine Termine und Mails über PHP und IPS anschauen. Nach einigem googlen habe ich dann die folgende Seite gefunden: Talking-SOAP-with-Exchange und war dann zum Teil erfolgreich
Kurze Erklärung:
Man braucht natürlich php_soap.dll und php_curl.dll und noch die ssleay32.dll Hier runterzuladen
Im Verzeichnis „scripts“ fehlen jetzt noch drei Dateien.
Services.wsdl, types.xsd und messages.xsd
Alle drei runter zu laden vom Exchange Server:
https://exchange.example.com/EWS/types.xsd
https://exchange.example.com/EWS/messages.xsd
https://exchange.example.com/EWS/Services.wsdl
Bei Services.wsdl noch das nächste Textblock VOR der letzten Zeile hinzufügen:
<wsdl:service name="ExchangeServices">
<wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
<soap:address location="https://exchange.example.com/EWS/Exchange.asmx"/>
</wsdl:port>
</wsdl:service>
Der PHP Quellcode ist folgender: (Achtung:2x Mailadresse ändern)
<?
/*
*******************************
IP-SYMCON Event Scripting
*******************************
File : calendar_pb.ips.php
Trigger :
Interval :
*/
class NTLMSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
$headers = array(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "'.$action.'"',
);
$this->__last_request_headers = $headers;
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
return $response;
}
function __getLastRequestHeaders() {
return implode("n", $this->__last_request_headers)."n";
}
}
class ExchangeNTLMSoapClient extends NTLMSoapClient {
protected $user = 'deine@mail.adresse'; // evtl. 'Domäne\\User'
protected $password = 'kennwort';
}
class NTLMStream {
private $path;
private $mode;
private $options;
private $opened_path;
private $buffer;
private $pos;
public function stream_open($path, $mode, $options, $opened_path) {
echo "[NTLMStream::stream_open] $path , mode=$mode n";
$this->path = $path;
$this->mode = $mode;
$this->options = $options;
$this->opened_path = $opened_path;
$this->createBuffer($path);
return true;
}
public function stream_close() {
echo "[NTLMStream::stream_close] n";
curl_close($this->ch);
}
public function stream_read($count) {
echo "[NTLMStream::stream_read] $count n";
if(strlen($this->buffer) == 0) {
return false;
}
$read = substr($this->buffer,$this->pos, $count);
$this->pos += $count;
return $read;
}
public function stream_write($data) {
echo "[NTLMStream::stream_write] n";
if(strlen($this->buffer) == 0) {
return false;
}
return true;
}
public function stream_eof() {
echo "[NTLMStream::stream_eof] ";
if($this->pos > strlen($this->buffer)) {
echo "true n";
return true;
}
echo "false n";
return false;
}
/* return the position of the current read pointer */
public function stream_tell() {
echo "[NTLMStream::stream_tell] n";
return $this->pos;
}
public function stream_flush() {
echo "[NTLMStream::stream_flush] n";
$this->buffer = null;
$this->pos = null;
}
public function stream_stat() {
echo "[NTLMStream::stream_stat] n";
$this->createBuffer($this->path);
$stat = array(
'size' => strlen($this->buffer),
);
return $stat;
}
public function url_stat($path, $flags) {
echo "[NTLMStream::url_stat] n";
$this->createBuffer($path);
$stat = array(
'size' => strlen($this->buffer),
);
return $stat;
}
/* Create the buffer by requesting the url through cURL */
private function createBuffer($path) {
if($this->buffer) {
return;
}
echo "[NTLMStream::createBuffer] create buffer from : $pathn";
$this->ch = curl_init($path);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($this->ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
echo $this->buffer = curl_exec($this->ch);
echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytesn";
$this->pos = 0;
}
}
class ExchangeNTLMStream extends NTLMStream {
protected $user = 'deine@mail.adresse'; // evtl. 'Domäne\\User'
protected $password = 'kennwort';
}
//verändert: erst wenn https registriert ist, unregistrieren
$existed = in_array("https", stream_get_wrappers());
if ($existed) {
stream_wrapper_unregister("https");
stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol");
$wsdl = "services.wsdl";
$client = new ExchangeNTLMSoapClient($wsdl);
/* Do something with the web service connection */
stream_wrapper_restore('https');
}
else {
stream_wrapper_register('https', 'ExchangeNTLMStream') or die("Failed to register protocol");
$wsdl = "services.wsdl";
$client = new ExchangeNTLMSoapClient($wsdl);
}
print_r($client->__getFunctions());
?>
Es ist mir schon gelungen einen Termineintrag zu erstellen.
$CreateItem->SendMeetingInvitations = "SendToNone";
$CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "calendar";
$CreateItem->Items->CalendarItem = array();
for($i = 0; $i < 1; $i++) {
$CreateItem->Items->CalendarItem[$i]->Subject = "Hello from PHP";
$CreateItem->Items->CalendarItem[$i]->Start = "2010-01-01T16:00:00Z"; # ISO date format. Z denotes UTC time
$CreateItem->Items->CalendarItem[$i]->End = "2010-01-01T17:00:00Z";
$CreateItem->Items->CalendarItem[$i]->IsAllDayEvent = false;
$CreateItem->Items->CalendarItem[$i]->LegacyFreeBusyStatus = "Busy";
$CreateItem->Items->CalendarItem[$i]->Location = "Bahamas";
$CreateItem->Items->CalendarItem[$i]->Categories->String = "MyCategory";
}
$result = $client->CreateItem($CreateItem);
print_r($result);
Leider klappt es nicht eine Suche zu starten… (Quellcode: )
$FindItem->Traversal = "Shallow";
$FindItem->ItemShape->BaseShape = "AllProperties";
$FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
$FindItem->CalendarView->StartDate = "2008-12-01T00:00:00Z";
$FindItem->CalendarView->EndDate = "2008-12-31T00:00:00Z";
$result = $client->FindItem($FindItem);
$calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
foreach($calendaritems as $item) {
echo $item->Subject."n";
}
Output:
<br />
<b>Fatal error</b>: Uncaught SoapFault exception: [soap11:Client] The request failed schema validation:
The element 'FindItem' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has
incomplete content. List of possible elements expected: 'GroupBy, DistinguishedGroupBy, Restriction, SortOrder,
ParentFolderIds' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'. in
C:\Program Files\IP-SYMCON\scripts\.currentscript:192
Stack trace:
#0 [internal function]: SoapClient->__call('FindItem', Array)
#1 C:\Program Files\IP-SYMCON\scripts\.currentscript(192): ExchangeNTLMSoapClient->FindItem(Object(stdClass))
#2 {main}
thrown in <b>C:\Program Files\IP-SYMCON\scripts\.currentscript</b> on line <b>192</b><br />
oder
$FindFolder->Traversal = "Shallow";
$FindFolder->FolderShape->BaseShape = "Default";
$FindFolder->ParentFolderIds->DistinguishedFolderId->Id = "root";
$result = $client->FindFolder($FindFolder);
$folders = $result->ResponseMessages->FindFolderResponseMessage->RootFolder->Folders->Folder;
foreach($folders as $folder) {
echo $folder->DisplayName."n";
}
Output:
<br />
<b>Fatal error</b>: Uncaught SoapFault exception: [soap11:Client] The request failed schema validation:
The element 'FindFolder' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'
has incomplete content. List of possible elements expected: 'IndexedPageFolderView, FractionalPageFolderView,
Restriction, ParentFolderIds' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'.
in C:\Program Files\IP-SYMCON\scripts\.currentscript:179
Stack trace:
#0 [internal function]: SoapClient->__call('FindFolder', Array)
#1 C:\Program Files\IP-SYMCON\scripts\.currentscript(179): ExchangeNTLMSoapClient->FindFolder(Object(stdClass))
#2 {main}
thrown in <b>C:\Program Files\IP-SYMCON\scripts\.currentscript</b> on line <b>179</b><br />
Wer von euch kann mir helfen dieses Problem zu lösen?
danke
oortmanp