GetProperty('C_ConfigPath').'autodiscover.dat'); if ($sdata) $xml_config=text_to_xml($sdata); $loaded=true; } // Get setting if (is_object($xml_config)) $result=$xml_config->get_data($service); // Get from the API if (!$result && $host) $result=$api->GetProperty('C_Mail_SMTP_General_HostName'); // Return return $result; } function add_protocol($account_xml, $protocol, $serverid, $loginname, $array=NULL) { // Add protocol $server=&$account_xml->new_child('Protocol',NULL); // Add tags $server->new_child_data('Type',NULL,$protocol); $server->new_child_data('Server',NULL,$serverid); $server->new_child_data('LoginName',NULL,$loginname); // Array keys if (is_array($array)) foreach ($array as $key => $value) $server->new_child_data($key,NULL,$value); return $server; }; // Email if ($request) $email=$request->get_data('Request/EMailAddress'); else $email=$_SERVER['PHP_AUTH_USER']; if ($account->AuthenticateUserHash($email,$_SERVER['PHP_AUTH_PW'],$SERVER_NAME,'',true)) { // Get username if ($api->GetProperty('C_Accounts_Policies_Login_LoginSettings')) $username=$account->EmailAddress; else $username=$account->GetProperty('U_Mailbox'); // Name $name=$account->GetProperty('U_Name'); } else $message='Incorrect user or password!'; // Request scheme if ($request) $schema=$request->get_data('Request/AcceptableResponseSchema'); else $schema='http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006'; // Scheme type $is_license=$schema=='http://icewarp.com/ns/license' || $_REQUEST['is_license']; $is_outlook=$schema=='http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a' || $_REQUEST['is_outlook']; // Create response $response=new xml_tree_node('Autodiscover',array('xmlns'=>'http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006')); $response_tag=&$response->new_child('Response',array('xmlns'=>$schema)); $response_tag->new_child_data('Culture', NULL, 'en:en'); $user=&$response_tag->new_child('User',NULL); if ($name) $user->new_child_data('DisplayName',NULL,$name); $user->new_child_data('EMailAddress',NULL,$email); // Create proper nodes if (!$message) { // License if ($is_license) { $settings_xml=&$response_tag->new_child('License',NULL); // Desktop Client if ($key=$account->GetProperty('U_ActivationKey_Desktop')) { $product=&$settings_xml->new_child('Product',NULL); $product->new_child_data('Id',NULL,'Desktop Client'); $product->new_child_data('Key',NULL,$key); } // Outlook Connector if ($key=$account->GetProperty('U_ActivationKey_OutConn')) { $product=&$settings_xml->new_child('Product',NULL); $product->new_child_data('Id',NULL,'Outlook-Connector'); $product->new_child_data('Key',NULL,$key); } } else // Outlook if ($is_outlook) { $account_xml=&$response_tag->new_child('Account',NULL); $account_xml->new_child_data('AccountType',NULL,'email'); $account_xml->new_child_data('Action',NULL,'settings'); // SMTP if ($account->GetProperty('U_SMTP')) { $type=get_tag('SMTPType'); if (!$type) add_protocol(&$account_xml, 'SMTP', get_tag('SMTP', true), $username, array('Port'=>$api->GetProperty('C_System_Services_SMTP_Port'), 'SSL'=>'off')); else add_protocol(&$account_xml, 'SMTP', get_tag('SMTP', true), $username, array('Port'=>$api->GetProperty('C_System_Services_SMTP_SSLPort'), 'SSL'=>'on')); } // POP3 / IMAP if ($account->GetProperty('U_POP3IMAP')) { // IMAP $type=get_tag('IMAPType'); if (!$type) add_protocol(&$account_xml, 'IMAP', get_tag('IMAP', true), $username, array('Port'=>$api->GetProperty('C_System_Services_IMAP_Port'), 'SSL'=>'off')); else add_protocol(&$account_xml, 'IMAP', get_tag('IMAP', true), $username, array('Port'=>$api->GetProperty('C_System_Services_IMAP_SSLPort'), 'SSL'=>'on')); // POP3 $type=get_tag('POP3Type'); if (!$type) add_protocol(&$account_xml, 'POP3', get_tag('POP3', true), $username, array('Port'=>$api->GetProperty('C_System_Services_POP3_Port'), 'SSL'=>'off')); else add_protocol(&$account_xml, 'POP3', get_tag('POP3', true), $username, array('Port'=>$api->GetProperty('C_System_Services_POP3_SSLPort'), 'SSL'=>'on')); } // XMPP if ($account->GetProperty('U_IMSupport')) { $type=get_tag('XMPPType'); if (!$type) add_protocol(&$account_xml, 'XMPP', get_tag('XMPP', true), $email, array('Port'=>$api->GetProperty('C_System_Services_IM_Port'), 'SSL'=>'off')); else add_protocol(&$account_xml, 'XMPP', get_tag('XMPP', true), $email, array('Port'=>$api->GetProperty('C_System_Services_IM_SSLPort'), 'SSL'=>'on')); } // SIP if ($account->GetProperty('U_SIPSupport')) { $type=get_tag('SIPType'); if (!$type) add_protocol(&$account_xml, 'SIP', get_tag('SIP', true), $email, array('Port'=>$api->GetProperty('C_System_Services_SIP_Port'), 'SSL'=>'off')); else add_protocol(&$account_xml, 'SIP', get_tag('SIP', true), $email, array('Port'=>$api->GetProperty('C_System_Services_SIP_SSLPort'), 'SSL'=>'on')); } // WebDAV if ($account->GetProperty('U_WebDAVSupport')) add_protocol(&$account_xml, 'DAV', $api->GetProperty('C_WebDAV_URL'), $email); // MobileSync if ($account->GetProperty('U_ActiveSyncSupport')) add_protocol(&$account_xml, 'MobileSync', $api->GetProperty('C_ActiveSync_URL'), $email); // SyncML (OMA DS) if ($account->GetProperty('U_SyncMLSupport')) add_protocol(&$account_xml, 'SyncML', $api->GetProperty('C_SyncML_URL'), $email); // X-ICEWARP-WEBCLIENT if ($account->GetProperty('U_WebMail')) add_protocol(&$account_xml, 'X-ICEWARP-WEBCLIENT', $api->GetProperty('C_WebMail_URL'), $username); // X-ICEWARP-SMS if ($account->GetProperty('U_SMSSupport')) add_protocol(&$account_xml, 'X-ICEWARP-SMS', $api->GetProperty('C_SMSService_URL'), $username); // X-ICEWARP-LICENSE add_protocol(&$account_xml, 'X-ICEWARP-LICENSE', ($_SERVER['HTTPS']=='ON'?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $email); // X-ICEWARP-DOWNLOAD add_protocol(&$account_xml, 'X-ICEWARP-DOWNLOAD', $api->GetProperty('C_Install_URL'), $email); } else { // ActiveSync $action_xml=&$response_tag->new_child('Action',NULL); $settings_xml=&$action_xml->new_child('Settings',NULL); // MobileSync if ($account->GetProperty('U_ActiveSyncSupport')) { $server=&$settings_xml->new_child('Server',NULL); $server->new_child_data('Type',NULL,'MobileSync'); $server->new_child_data('Url',NULL,$api->GetProperty('C_ActiveSync_URL')); $server->new_child_data('Name',NULL,$api->GetProperty('C_ActiveSync_URL')); } } } else { if ($is_license||$is_outlook) $error=&$response_tag->new_child('Error',NULL); else { $action_xml=&$response_tag->new_child('Action',NULL); $error=&$action_xml->new_child('Error',NULL); } $error->new_child_data('Status',NULL,1); $error->new_child_data('Message',NULL,$message); } } // The script must always be called with authorisation info if (!isset($_SERVER['PHP_AUTH_USER'])) { header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Basic realm="Autodiscover"'); exit; } // Read requested data $request=file_get_contents('php://input'); // Save requested data to memory reprezentation of XML structure if ($request) $request=text_to_xml($request); // Handle requested command and create response handle_autodiscover($request,&$xml_response); $response=''."\r\n".$xml_response->print_node(0,false); // Output response header('Content-Type: text/xml'); header('Content-Length: '.strlen($response)); echo $response; ?>