Hi,
I've been playing around with few bits of code and have managed to mash them together so I can access MS exchange contacts (mine) with a push of a button. The main file that does the talking to Exchange relies on "Exchange Server name", "Username" and "Password" being stored in the file. Can anyone suggests of a way of encrypting the information and stored some where other then at the head of the php page?
<?
#####################################################################
# Asterisk Directory for Exchange
#####################################################################
// Modify the paths to these class files as needed.
require_once("class_http.php");
require_once("class_xml.php");
// Change these values for your Exchange Server.
$exchange_server = "http://xxxx";
$exchange_username = "xxxx";
$exchange_password = "xxxx";
// We use Troy's http class object to send the XML-formatted WebDAV request
// to the Exchange Server and to receive the response from the Exchange Server.
// The response is also XML-formatted.
$h = new http();
$h->headers["Content-Type"] = 'text/xml;charset="UTF-8"';
$h->headers["Depth"] = "0";
$h->headers["Translate"] = "f";
// Find all the contacts for a specific company in a specific folder.
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2...
$h->xmlrequest = '<?xml version="1.0"?>';
$h->xmlrequest .= <<
SELECT "a:href"
,"urn:schemas:contacts:o"
,"urn:schemas:contacts:cn"
,"urn:schemas:contacts:fileas"
,"urn:schemas:contacts:title"
,"urn:schemas:contacts:email1"
,"urn:schemas:contacts:telephoneNumber"
FROM "$exchange_server/exchange/xxxx/contacts/"
ORDER BY "urn:schemas:contacts:cn"
END;
// 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'.
if (!$h->fetch($exchange_server."/exchange/xxxx/contacts/", 0, null, $exchange_username, $exchange_password, "SEARCH")) {
echo "There is a problem with the http request!";
echo $h->log;
exit();
}
// The assumption now is that we've got an XML result back from the Exchange
// Server, so let's parse the XML into an object we can more easily access.
// For this task, we'll use Troy's xml class object.
$x = new xml();
if (!$x->fetch($h->body)) {
$output = "There was a problem parsing your XML!";
$output .="".$h->log."\n";
$output .="".$h->header."\n";
$output .="".$h->body."\n";
$output .="".$x->log."\n";
echo $output;
exit();
}
foreach($x->data->A_MULTISTATUS[0]->A_RESPONSE as $idx=>$contact) {
$directory[] = "".$contact->A_PROPSTAT[0]->A_PROP[0]->E_CN[0]->_text."\n"."Dial:".$contact->A_PROPSTAT[0]->A_PROP[0]->E_TELEPHONENUMBER[0]->_text."\n";
#$directory[] = "".$callerid."\n";
}
# Display Page
$output ="";
$output .= "Directory ($page/$last)\n";
foreach ($directory as $v)
{
$output .= "\n";
$output .= $v;
$output .= "\n";
}
# Dial button
$output .= "\n";
$output .= "Dial\n";
$output .= "SoftKey:Select\n";
$output .= "\n";
# End of the object
$output .= "\n";
# HTTP header and output
header("Content-Type: text/xml");
header("Content-Length: ".strlen($output));
echo $output;
?>

Member Since:
2007-08-10