Ik heb een mooi stuke PHP code gevonden welke goed werkt:
PHP Code:
// OWA Login Check
// Written by Scott Milliken
// Permission granted to use under the GPL
//
$username = "user";
$password = "pass";
// You can just use the base URL for your default mailbox
// or you can add on to it to specify a group mailbox
// $mailboxURL = "https://email.mydomain.com" for default
// or for a shared NOC mailbox in the IT department...
$mailboxURL = "https://domain.com/Exchange/boardroom/Agenda/";
$authURL = "https://domain.com/exchweb/bin/auth/owaauth.dll";
// First go to the URL that a user would use so that you can get your session cookie set
$pg = curl_init();
curl_setopt( $pg, CURLOPT_URL, $mailboxURL );
curl_setopt( $pg, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
curl_setopt( $pg, CURLOPT_FOLLOWLOCATION, true );
// You need to define a cookie jar to store and retrieve
// the session cookies or this won't work
curl_setopt( $pg, CURLOPT_COOKIEJAR, "cookies.txt" );
curl_setopt( $pg, CURLOPT_COOKIEFILE, "cookies.txt" );
curl_setopt( $pg, CURLOPT_HEADER, false );
curl_setopt( $pg, CURLOPT_RETURNTRANSFER, true );
// Setting these to false is handy for checking multiple
// frontends that may share the same SSL cert, such as
// ones in a round robin DNS scheme, but you address
// them by the "real name" of the host
curl_setopt( $pg, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $pg, CURLOPT_SSL_VERIFYHOST, false );
// Set this to true for debugging
curl_setopt( $pg, CURLOPT_VERBOSE, false );
$response = curl_exec( $pg );
$info = curl_getinfo( $pg );
// Set the form data for posting the login information
$postData = array();
$postData["url"] = $mailboxURL;
$postData["reason"] = "0";
$postData["destination"] = $mailboxURL;
$postData["flags"] = "0";
$postData["username"] = $username;
$postData["password"] = $password;
$postData["SubmitCreds"] = "Log On";
$postText = "";
foreach( $postData as $key => $value ) {
$postText .= $key . "=" . $value . "&";
}
curl_setopt( $pg, CURLOPT_REFERER, $info["url"] );
curl_setopt( $pg, CURLOPT_URL, $authURL );
curl_setopt( $pg, CURLOPT_POST, true );
curl_setopt( $pg, CURLOPT_POSTFIELDS, $postText );
$response = curl_exec( $pg );
// At this point you can either print the following
// status to show the result of logging in, or you
// can make another call to the web server for the
// individual frames, such as
// $mailboxURL . "/Inbox/?Cmd=contents" will give you
// the listing of inbox headers (if you call curl again)
$info = curl_getinfo( $pg );
$needle = "close all browser windows when you finish using Outlook Web Access";
//echo $response;
//exit;
if ( strpos( $response, $needle ) )
{
printf( "Logon to OWA successful.\n" );
}
else
{
printf( "Logon to OWA failed.\n" );
}
Alleen nu wil ik deze query erop los laten:
Code:
<a:searchrequest xmlns:a="DAV:" xmlns:s="http://schemas.microsoft.com/exchange/security/">
<a:sql>
SELECT "DAV:displayname"
,"urn:schemas:httpmail:subject"
,"urn:schemas:calendar:location"
,"urn:schemas:calendar:dtstart"
,"urn:schemas:calendar:duration"
,"urn:schemas:calendar:dtend"
,"urn:schemas:httpmail:textdescription"
,"urn:schemas:calendar:busystatus"
FROM "$mailboxURL"
WHERE "urn:schemas:calendar:dtend" >= '$date'
ORDER BY "urn:schemas:calendar:dtstart" ASC
</a:sql>
</a:searchrequest>
Hoe kan ik dit doen?
ik krijg steeds een 409 error met een conflict als ik het zo doe:
PHP Code:
$date = gmdate("Y-m-d H:i:s", gmmktime(gmdate('H'),gmdate('i'),gmdate('s'),gmdate('m'),gmdate('d'),gmdate('Y')));
$putString = '<?xml version="1.0"?>';
$putString .= <<<END
<a:searchrequest xmlns:a="DAV:" xmlns:s="http://schemas.microsoft.com/exchange/security/">
<a:sql>
SELECT "DAV:displayname"
,"urn:schemas:httpmail:subject"
,"urn:schemas:calendar:location"
,"urn:schemas:calendar:dtstart"
,"urn:schemas:calendar:duration"
,"urn:schemas:calendar:dtend"
,"urn:schemas:httpmail:textdescription"
,"urn:schemas:calendar:busystatus"
FROM "$mailboxURL"
WHERE "urn:schemas:calendar:dtend" >= '$date'
ORDER BY "urn:schemas:calendar:dtstart" ASC
</a:sql>
</a:searchrequest>
END;
//echo $putString;
// IMPORTANT -- The END line above must be completely left-aligned. No white-space.
// The 'fetch' method does the work of sending and receiving the request.
// NOTICE the last parameter passed--'SEARCH' in this example. That is the
// HTTP verb that you must correctly set according to the type of WebDAV request
// you are making. The examples on this page use either 'PROPFIND' or 'SEARCH'.
$headers = array();
//$headers[] = 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.9.0.1) Gecko/2008072820 Firefox/3.0.1';
//$headers[] = 'Authorization: Basic '.base64_encode($exchange_username.":".$exchange_password);
$headers[] = 'Content-Type: text/xml; charset="UTF-8"';
$headers[] = 'Depth: 0';
$headers[] = 'Translate: f';
//$headers[] = 'Content-Length: '.strlen($h->xmlrequest);
//$putString = $h->xmlrequest;
$putData = tmpfile();
fwrite($putData, $putString);
fseek($putData, 0);
$pg = curl_init();
curl_setopt( $pg, CURLOPT_URL, $mailboxURL. "" );
curl_setopt( $pg, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
curl_setopt( $pg, CURLOPT_FOLLOWLOCATION, true );
// You need to define a cookie jar to store and retrieve
// the session cookies or this won't work
curl_setopt( $pg, CURLOPT_COOKIEJAR, "cookies.txt" );
curl_setopt( $pg, CURLOPT_COOKIEFILE, "cookies.txt" );
curl_setopt($pg, CURLOPT_HTTPHEADER, $headers);
//curl_setopt( $pg, CURLOPT_HEADER, false );
curl_setopt( $pg, CURLOPT_RETURNTRANSFER, true );
// Setting these to false is handy for checking multiple
// frontends that may share the same SSL cert, such as
// ones in a round robin DNS scheme, but you address
// them by the "real name" of the host
curl_setopt( $pg, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $pg, CURLOPT_SSL_VERIFYHOST, false );
// Set this to true for debugging
curl_setopt( $pg, CURLOPT_VERBOSE, false );
curl_setopt($pg, CURLOPT_PUT, true);
curl_setopt($pg, CURLOPT_INFILE, $putData);
curl_setopt($pg, CURLOPT_INFILESIZE, strlen($putString));
$content = curl_exec ($pg);
curl_close ($pg);
Iemand een idee?