Logon($auth_user, $auth_domain, $auth_pw) == false) { header("HTTP/1.1 401 Unauthorized"); header("WWW-Authenticate: Basic realm=\"ZPush\""); print("Access denied. Username or password incorrect."); debugLog("Access denied: backend logon failed."); debugLog("end"); debugLog("--------"); return; } // $user is usually the same as the PHP_AUTH_USER. This allows you to sync the 'john' account if you // have sufficient privileges as user 'joe'. if($backend->Setup($user, $devid, $protocolversion) == false) { header("HTTP/1.1 401 Unauthorized"); header("WWW-Authenticate: Basic realm=\"ZPush\""); print("Access denied or user '$user' unknown."); debugLog("Access denied: backend setup failed."); debugLog("end"); debugLog("--------"); return; } // check policy header if (PROVISIONING === true && $_SERVER["REQUEST_METHOD"] != 'OPTIONS' && $cmd != 'Ping' && $cmd != 'Provision' && $backend->CheckPolicy($policykey, $devid) != SYNC_PROVISION_STATUS_SUCCESS && (LOOSE_PROVISIONING === false || (LOOSE_PROVISIONING === true && isset($requestheaders["X-MS-PolicyKey"])))) { header("HTTP/1.1 449 Retry after sending a PROVISION command"); header("MS-Server-ActiveSync: 6.5.7638.1"); header("MS-ASProtocolVersions: 1.0,2.0,2.1,2.5"); header("MS-ASProtocolCommands: Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Provision,ResolveRecipients,ValidateCert,Search,Ping"); header("Cache-Control: private"); debugLog("POST cmd $cmd denied: Retry after sending a PROVISION command"); debugLog("end"); debugLog("--------"); return; } // Do the actual request switch($_SERVER["REQUEST_METHOD"]) { case 'OPTIONS': header("MS-Server-ActiveSync: 6.5.7638.1"); header("MS-ASProtocolVersions: 1.0,2.0,2.1,2.5"); header("MS-ASProtocolCommands: Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,ResolveRecipients,ValidateCert,Provision,Search,Ping"); debugLog("Options request"); break; case 'POST': header("MS-Server-ActiveSync: 6.5.7638.1"); debugLog("POST cmd: $cmd"); // Do the actual request if(!HandleRequest($backend, $cmd, $devid, $protocolversion)) { // Request failed. Try to output some kind of error information. We can only do this if // output had not started yet. If it has started already, we can't show the user the error, and // the device will give its own (useless) error message. if(!headers_sent()) { header("Content-type: text/html"); print("
\n"); print("\n"); print("There was a problem processing the $cmd command from your PDA.\n"); print("
Here is the debug output:
\n"); print(getDebugInfo()); print("\n"); print("\n"); } } break; case 'GET': header("Content-type: text/html"); print("\n"); print("
\n"); print("This is the z-push location and can only be accessed by Microsoft ActiveSync-capable devices."); print("\n"); break; } $len = ob_get_length(); $data = ob_get_contents(); ob_end_clean(); // Unfortunately, even though zpush can stream the data to the client // with a chunked encoding, using chunked encoding also breaks the progress bar // on the PDA. So we de-chunk here and just output a content-length header and // send it as a 'normal' packet. If the output packet exceeds 1MB (see ob_start) // then it will be sent as a chunked packet anyway because PHP will have to flush // the buffer. header("Content-Length: $len"); print $data; // destruct backend after all data is on the stream $backend->Logoff(); debugLog("end"); debugLog("--------"); ?>