GetProperty('C_ConfigPath').'autodiscover.dat'); if ($sdata) { $xml_config=text_to_xml($sdata); foreach($xml_config->children() as $field) $autodiscover_settings[$field->get_name()]=strtolower($xml_config->get_data($field->get_name())); } $loaded=true; } // Get setting $result=$autodiscover_settings[$service]; // Get from the API if (!$result) $result=$api->GetProperty('C_Mail_SMTP_General_HostName'); // Return return $result; } // 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'; //$schema='http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a'; // 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'); // Scheme type $is_license=$schema=='http://icewarp.com/ns/license'; $is_outlook=$schema=='http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a'; //$is_activesync=(($schema=='http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006')||(strpos($_SERVER['HTTP_USER_AGENT'],'iPhone'))); $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'); // MobileSync if ($account->GetProperty('U_ActiveSyncSupport')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'MobileSync'); $server->new_child_data('Server',NULL,$api->GetProperty('C_ActiveSync_URL')); $server->new_child_data('Name',NULL,$api->GetProperty('C_ActiveSync_URL')); $server->new_child_data('LoginName',NULL,$email); } // SyncML (OMA DS) if ($account->GetProperty('U_SyncMLSupport')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'SyncML'); $server->new_child_data('Server',NULL,$api->GetProperty('C_SyncML_URL')); $server->new_child_data('LoginName',NULL,$email); } // XMPP if ($account->GetProperty('U_IMSupport')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'XMPP'); $server->new_child_data('Server',NULL,get_server('XMPP')); $server->new_child_data('Port',NULL,$api->GetProperty('C_System_Services_IM_Port')); $server->new_child_data('LoginName',NULL,$email); } // SIP if ($account->GetProperty('U_SIPSupport')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'SIP'); $server->new_child_data('Server',NULL,get_server('SIP')); $server->new_child_data('Port',NULL,$api->GetProperty('C_System_Services_SIP_Port')); $server->new_child_data('LoginName',NULL,$email); } // SMTP if ($account->GetProperty('U_SMTP')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'SMTP'); $server->new_child_data('Server',NULL,get_server('SMTP')); $server->new_child_data('Port',NULL,$api->GetProperty('C_System_Services_SMTP_Port')); $server->new_child_data('LoginName',NULL,$username); $server->new_child_data('SSL',NULL,'off'); } // POP3 / IMAP if ($account->GetProperty('U_POP3IMAP')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'IMAP'); $server->new_child_data('Server',NULL,get_server('IMAP')); $server->new_child_data('Port',NULL,$api->GetProperty('C_System_Services_IMAP_Port')); $server->new_child_data('LoginName',NULL,$username); $server->new_child_data('SSL',NULL,'off'); $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'POP3'); $server->new_child_data('Server',NULL,get_server('POP3')); $server->new_child_data('Port',NULL,$api->GetProperty('C_System_Services_POP3_Port')); $server->new_child_data('LoginName',NULL,$username); $server->new_child_data('SSL',NULL,'off'); } // WebDAV if ($account->GetProperty('U_WebDAVSupport')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'DAV'); $server->new_child_data('Server',NULL,$api->GetProperty('C_WebDAV_URL')); $server->new_child_data('LoginName',NULL,$email); } // X-ICEWARP-WEBCLIENT if ($account->GetProperty('U_WebMail')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'X-ICEWARP-WEBCLIENT'); $server->new_child_data('Server',NULL,$api->GetProperty('C_WebMail_URL')); $server->new_child_data('LoginName',NULL,$email); } // X-ICEWARP-SMS if ($account->GetProperty('U_SMSSupport')) { $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'X-ICEWARP-SMS'); $server->new_child_data('Server',NULL,$api->GetProperty('C_SMSService_URL')); $server->new_child_data('LoginName',NULL,$username); } // X-ICEWARP-LICENSE $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'X-ICEWARP-LICENSE'); $server->new_child_data('Server',NULL,($_SERVER['HTTPS']=='ON'?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); $server->new_child_data('LoginName',NULL,$email); // X-ICEWARP-DOWNLOAD $server=&$account_xml->new_child('Protocol',NULL); $server->new_child_data('Type',NULL,'X-ICEWARP-DOWNLOAD'); $server->new_child_data('Server',NULL,$api->GetProperty('C_Install_URL')); $server->new_child_data('LoginName',NULL,$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; ?>