@@ -60,5 +60,5 @@ |
||
| 60 | 60 | |
| 61 | 61 | // Tell the PHP extension which exception class to instantiate |
| 62 | 62 | if (function_exists('mapi_enable_exceptions')) { |
| 63 | - //mapi_enable_exceptions("mapiexception"); |
|
| 63 | + //mapi_enable_exceptions("mapiexception"); |
|
| 64 | 64 | } |
@@ -22,10 +22,10 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | public function getDisplayMessage() |
| 24 | 24 | { |
| 25 | - if(!empty($this->displayMessage)) |
|
| 25 | + if (!empty($this->displayMessage)) |
|
| 26 | 26 | return $this->displayMessage; |
| 27 | 27 | |
| 28 | - switch($this->getCode()) |
|
| 28 | + switch ($this->getCode()) |
|
| 29 | 29 | { |
| 30 | 30 | case MAPI_E_NO_ACCESS: |
| 31 | 31 | return _("You have insufficient privileges to open this object."); |
@@ -22,8 +22,9 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | public function getDisplayMessage() |
| 24 | 24 | { |
| 25 | - if(!empty($this->displayMessage)) |
|
| 26 | - return $this->displayMessage; |
|
| 25 | + if(!empty($this->displayMessage)) { |
|
| 26 | + return $this->displayMessage; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | switch($this->getCode()) |
| 29 | 30 | { |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | // assign display message |
| 59 | 59 | $this->displayMessage = $displayMessage; |
| 60 | 60 | |
| 61 | - parent::__construct($errorMessage, (int) $code, $previous); |
|
| 61 | + parent::__construct($errorMessage, (int)$code, $previous); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function getFileLine() |
| 68 | 68 | { |
| 69 | - return $this->getBaseFile() . ':' . $this->getLine(); |
|
| 69 | + return $this->getBaseFile().':'.$this->getLine(); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function getDisplayMessage() |
| 76 | 76 | { |
| 77 | - if(!is_null($this->displayMessage)) { |
|
| 77 | + if (!is_null($this->displayMessage)) { |
|
| 78 | 78 | return $this->displayMessage; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function getBaseFile() |
| 127 | 127 | { |
| 128 | - if(is_null($this->baseFile)) { |
|
| 128 | + if (is_null($this->baseFile)) { |
|
| 129 | 129 | $this->baseFile = basename(parent::getFile()); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | function setRecurrence(&$recur) |
| 75 | 75 | { |
| 76 | 76 | $this->recur = $recur; |
| 77 | - $this->action =& $recur; |
|
| 77 | + $this->action = & $recur; |
|
| 78 | 78 | |
| 79 | - if(!isset($this->recur["changed_occurences"])) |
|
| 79 | + if (!isset($this->recur["changed_occurences"])) |
|
| 80 | 80 | $this->recur["changed_occurences"] = Array(); |
| 81 | 81 | |
| 82 | - if(!isset($this->recur["deleted_occurences"])) |
|
| 82 | + if (!isset($this->recur["deleted_occurences"])) |
|
| 83 | 83 | $this->recur["deleted_occurences"] = Array(); |
| 84 | 84 | |
| 85 | 85 | if (!isset($this->recur['startocc'])) $this->recur['startocc'] = 0; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | // Update $this->recur with proper startrecurrdate and endrecurrdate updated after saving recurrence |
| 92 | 92 | $msgProps = mapi_getprops($this->message, array($this->proptags['recurring_data'])); |
| 93 | 93 | $recurring_data = $this->parseRecurrence($msgProps[$this->proptags['recurring_data']]); |
| 94 | - foreach($recurring_data as $key => $value) { |
|
| 94 | + foreach ($recurring_data as $key => $value) { |
|
| 95 | 95 | $this->recur[$key] = $value; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | function setFirstOccurrence() |
| 108 | 108 | { |
| 109 | 109 | // Check if it is already the first occurrence |
| 110 | - if($this->action['start'] == $this->recur["start"]){ |
|
| 110 | + if ($this->action['start'] == $this->recur["start"]) { |
|
| 111 | 111 | return; |
| 112 | - }else{ |
|
| 112 | + } else { |
|
| 113 | 113 | $items = $this->getNextOccurrence(); |
| 114 | 114 | |
| 115 | 115 | $props = array(); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * then we create first two occurrence separately and for first occurrence recurrence has ended. |
| 141 | 141 | */ |
| 142 | 142 | if ((empty($this->action['startdate']) && empty($this->action['duedate'])) |
| 143 | - || ($this->action['complete'] == 1) || (isset($this->action['deleteOccurrence']) && $this->action['deleteOccurrence'])){ |
|
| 143 | + || ($this->action['complete'] == 1) || (isset($this->action['deleteOccurrence']) && $this->action['deleteOccurrence'])) { |
|
| 144 | 144 | |
| 145 | 145 | $nextOccurrence = $this->getNextOccurrence(); |
| 146 | 146 | $result = mapi_getprops($this->message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
@@ -265,18 +265,18 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | $copy_to_recipientTable = mapi_message_getrecipienttable($newMessage); |
| 267 | 267 | $copy_to_recipientRows = mapi_table_queryallrows($copy_to_recipientTable, array(PR_ROWID)); |
| 268 | - foreach($copy_to_recipientRows as $recipient) { |
|
| 268 | + foreach ($copy_to_recipientRows as $recipient) { |
|
| 269 | 269 | mapi_message_modifyrecipients($newMessage, MODRECIP_REMOVE, array($recipient)); |
| 270 | 270 | } |
| 271 | 271 | mapi_message_modifyrecipients($newMessage, MODRECIP_ADD, $recipients); |
| 272 | 272 | |
| 273 | 273 | // Copy attachments |
| 274 | 274 | $attachmentTable = mapi_message_getattachmenttable($this->message); |
| 275 | - if($attachmentTable) { |
|
| 275 | + if ($attachmentTable) { |
|
| 276 | 276 | $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD)); |
| 277 | 277 | |
| 278 | - foreach($attachments as $attach_props){ |
|
| 279 | - $attach_old = mapi_message_openattach($this->message, (int) $attach_props[PR_ATTACH_NUM]); |
|
| 278 | + foreach ($attachments as $attach_props) { |
|
| 279 | + $attach_old = mapi_message_openattach($this->message, (int)$attach_props[PR_ATTACH_NUM]); |
|
| 280 | 280 | $attach_newResourceMsg = mapi_message_createattach($newMessage); |
| 281 | 281 | |
| 282 | 282 | mapi_copyto($attach_old, array(), array(), $attach_newResourceMsg, 0); |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | $separator = "------------\r\n"; |
| 294 | 294 | |
| 295 | 295 | if (!empty($msgbody) && strrpos($msgbody, $separator) === false) { |
| 296 | - $msgbody = $separator . $msgbody; |
|
| 296 | + $msgbody = $separator.$msgbody; |
|
| 297 | 297 | $stream = mapi_openproperty($this->message, PR_BODY, IID_IStream, STGM_TRANSACTED, 0); |
| 298 | 298 | mapi_stream_setsize($stream, strlen($msgbody)); |
| 299 | 299 | mapi_stream_write($stream, $msgbody); |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | { |
| 339 | 339 | // Fix timezone object |
| 340 | 340 | $this->tz = false; |
| 341 | - $this->action =& $recur; |
|
| 341 | + $this->action = & $recur; |
|
| 342 | 342 | $dead_occurrence = isset($this->messageprops[$this->proptags['dead_occurrence']]) ? $this->messageprops[$this->proptags['dead_occurrence']] : false; |
| 343 | 343 | |
| 344 | 344 | if (!$dead_occurrence) { |
@@ -76,14 +76,20 @@ discard block |
||
| 76 | 76 | $this->recur = $recur; |
| 77 | 77 | $this->action =& $recur; |
| 78 | 78 | |
| 79 | - if(!isset($this->recur["changed_occurences"])) |
|
| 80 | - $this->recur["changed_occurences"] = Array(); |
|
| 79 | + if(!isset($this->recur["changed_occurences"])) { |
|
| 80 | + $this->recur["changed_occurences"] = Array(); |
|
| 81 | + } |
|
| 81 | 82 | |
| 82 | - if(!isset($this->recur["deleted_occurences"])) |
|
| 83 | - $this->recur["deleted_occurences"] = Array(); |
|
| 83 | + if(!isset($this->recur["deleted_occurences"])) { |
|
| 84 | + $this->recur["deleted_occurences"] = Array(); |
|
| 85 | + } |
|
| 84 | 86 | |
| 85 | - if (!isset($this->recur['startocc'])) $this->recur['startocc'] = 0; |
|
| 86 | - if (!isset($this->recur['endocc'])) $this->recur['endocc'] = 0; |
|
| 87 | + if (!isset($this->recur['startocc'])) { |
|
| 88 | + $this->recur['startocc'] = 0; |
|
| 89 | + } |
|
| 90 | + if (!isset($this->recur['endocc'])) { |
|
| 91 | + $this->recur['endocc'] = 0; |
|
| 92 | + } |
|
| 87 | 93 | |
| 88 | 94 | // Save recurrence because we need proper startrecurrdate and endrecurrdate |
| 89 | 95 | $this->saveRecurrence(); |
@@ -109,7 +115,7 @@ discard block |
||
| 109 | 115 | // Check if it is already the first occurrence |
| 110 | 116 | if($this->action['start'] == $this->recur["start"]){ |
| 111 | 117 | return; |
| 112 | - }else{ |
|
| 118 | + } else{ |
|
| 113 | 119 | $items = $this->getNextOccurrence(); |
| 114 | 120 | |
| 115 | 121 | $props = array(); |
@@ -171,8 +177,9 @@ discard block |
||
| 171 | 177 | |
| 172 | 178 | $props[$this->proptags["dead_occurrence"]] = false; |
| 173 | 179 | } else { |
| 174 | - if (isset($this->action['deleteOccurrence']) && $this->action['deleteOccurrence']) |
|
| 175 | - return false; |
|
| 180 | + if (isset($this->action['deleteOccurrence']) && $this->action['deleteOccurrence']) { |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 176 | 183 | |
| 177 | 184 | // Didn't get next occurrence, probably this is the last one, so recurrence ends here |
| 178 | 185 | $props[$this->proptags["dead_occurrence"]] = true; |
@@ -224,8 +231,12 @@ discard block |
||
| 224 | 231 | // Get all properties |
| 225 | 232 | $taskItemProps = mapi_getprops($this->message); |
| 226 | 233 | |
| 227 | - if (isset($this->action["subject"])) $taskItemProps[$this->proptags["subject"]] = $this->action["subject"]; |
|
| 228 | - if (isset($this->action["importance"])) $taskItemProps[$this->proptags["importance"]] = $this->action["importance"]; |
|
| 234 | + if (isset($this->action["subject"])) { |
|
| 235 | + $taskItemProps[$this->proptags["subject"]] = $this->action["subject"]; |
|
| 236 | + } |
|
| 237 | + if (isset($this->action["importance"])) { |
|
| 238 | + $taskItemProps[$this->proptags["importance"]] = $this->action["importance"]; |
|
| 239 | + } |
|
| 229 | 240 | if (isset($this->action["startdate"])) { |
| 230 | 241 | $taskItemProps[$this->proptags["startdate"]] = $this->action["startdate"]; |
| 231 | 242 | $taskItemProps[$this->proptags["commonstart"]] = $this->action["startdate"]; |
@@ -380,8 +391,9 @@ discard block |
||
| 380 | 391 | $props[$this->proptags['reset_reminder']] = false; |
| 381 | 392 | } |
| 382 | 393 | |
| 383 | - if (!empty($props)) |
|
| 384 | - mapi_setprops($this->message, $props); |
|
| 394 | + if (!empty($props)) { |
|
| 395 | + mapi_setprops($this->message, $props); |
|
| 396 | + } |
|
| 385 | 397 | } |
| 386 | 398 | |
| 387 | 399 | /** |
@@ -27,13 +27,13 @@ discard block |
||
| 27 | 27 | Request::Initialize(); |
| 28 | 28 | ZLog::Initialize(); |
| 29 | 29 | |
| 30 | - ZLog::Write(LOGLEVEL_DEBUG,"-------- Start"); |
|
| 30 | + ZLog::Write(LOGLEVEL_DEBUG, "-------- Start"); |
|
| 31 | 31 | ZLog::Write(LOGLEVEL_DEBUG, |
| 32 | 32 | sprintf("cmd='%s' devType='%s' devId='%s' getUser='%s' from='%s' version='%s' method='%s'", |
| 33 | - Request::GetCommand(), Request::GetDeviceType(), Request::GetDeviceID(), Request::GetGETUser(), Request::GetRemoteAddr(), @constant('GROMMUNIOSYNC_VERSION'), Request::GetMethod() )); |
|
| 33 | + Request::GetCommand(), Request::GetDeviceType(), Request::GetDeviceID(), Request::GetGETUser(), Request::GetRemoteAddr(), @constant('GROMMUNIOSYNC_VERSION'), Request::GetMethod())); |
|
| 34 | 34 | |
| 35 | 35 | // always request the authorization header |
| 36 | - if (! Request::HasAuthenticationInfo() || !Request::GetGETUser()) |
|
| 36 | + if (!Request::HasAuthenticationInfo() || !Request::GetGETUser()) |
|
| 37 | 37 | throw new AuthenticationRequiredException("Access denied. Please send authorisation information"); |
| 38 | 38 | |
| 39 | 39 | ZPush::CheckAdvancedConfig(); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Check required GET parameters |
| 51 | - if(Request::IsMethodPOST() && (Request::GetCommandCode() === false || !Request::GetDeviceID() || !Request::GetDeviceType())) |
|
| 51 | + if (Request::IsMethodPOST() && (Request::GetCommandCode() === false || !Request::GetDeviceID() || !Request::GetDeviceType())) |
|
| 52 | 52 | throw new FatalException("Requested the grommunio-sync URL without the required GET parameters"); |
| 53 | 53 | |
| 54 | 54 | // Load the backend |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | header(ZPush::GetServerHeader()); |
| 75 | 75 | |
| 76 | 76 | if (RequestProcessor::isUserAuthenticated()) { |
| 77 | - header("X-Grommunio-Sync-Version: ". @constant('GROMMUNIOSYNC_VERSION')); |
|
| 77 | + header("X-Grommunio-Sync-Version: ".@constant('GROMMUNIOSYNC_VERSION')); |
|
| 78 | 78 | |
| 79 | 79 | // announce the supported AS versions (if not already sent to device) |
| 80 | 80 | if (ZPush::GetDeviceManager()->AnnounceASVersion()) { |
| 81 | 81 | $versions = ZPush::GetSupportedProtocolVersions(true); |
| 82 | 82 | ZLog::Write(LOGLEVEL_INFO, sprintf("Announcing latest AS version to device: %s", $versions)); |
| 83 | - header("X-MS-RP: ". $versions); |
|
| 83 | + header("X-MS-RP: ".$versions); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | // data send as a 'normal' packet. If the output packet exceeds 1MB (see ob_start) |
| 111 | 111 | // then it will be sent as a chunked packet anyway because PHP will have to flush |
| 112 | 112 | // the buffer. |
| 113 | - if(!headers_sent()) |
|
| 113 | + if (!headers_sent()) |
|
| 114 | 114 | header("Content-Length: $len"); |
| 115 | 115 | |
| 116 | 116 | // send vnd.ms-sync.wbxml content type header if there is no content |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | // Extract any previous exception message for logging purpose. |
| 144 | 144 | $exclass = get_class($ex); |
| 145 | 145 | $exception_message = $ex->getMessage(); |
| 146 | - if($ex->getPrevious()){ |
|
| 146 | + if ($ex->getPrevious()) { |
|
| 147 | 147 | do { |
| 148 | 148 | $current_exception = $ex->getPrevious(); |
| 149 | - $exception_message .= ' -> ' . $current_exception->getMessage(); |
|
| 150 | - } while($current_exception->getPrevious()); |
|
| 149 | + $exception_message .= ' -> '.$current_exception->getMessage(); |
|
| 150 | + } while ($current_exception->getPrevious()); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (Request::GetUserAgent()) |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | ZLog::Write(LOGLEVEL_FATAL, sprintf('Exception: (%s) - %s', $exclass, $exception_message)); |
| 157 | 157 | |
| 158 | - if(!headers_sent()) { |
|
| 158 | + if (!headers_sent()) { |
|
| 159 | 159 | if ($ex instanceof ZPushException) { |
| 160 | - header('HTTP/1.1 '. $ex->getHTTPCodeString()); |
|
| 160 | + header('HTTP/1.1 '.$ex->getHTTPCodeString()); |
|
| 161 | 161 | foreach ($ex->getHTTPHeaders() as $h) |
| 162 | 162 | header($h); |
| 163 | 163 | } |
@@ -171,12 +171,12 @@ discard block |
||
| 171 | 171 | // some devices send unauthorized OPTIONS requests |
| 172 | 172 | // and don't expect anything in the response body |
| 173 | 173 | if (Request::IsMethodGET()) { |
| 174 | - ZPush::PrintGrommunioSyncLegal($exclass, sprintf('<pre>%s</pre>',$ex->getMessage())); |
|
| 174 | + ZPush::PrintGrommunioSyncLegal($exclass, sprintf('<pre>%s</pre>', $ex->getMessage())); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // log the failed login attempt e.g. for fail2ban |
| 178 | 178 | if (defined('LOGAUTHFAIL') && LOGAUTHFAIL != false) |
| 179 | - ZLog::Write(LOGLEVEL_WARN, sprintf("IP: %s failed to authenticate user '%s'", Request::GetRemoteAddr(), Request::GetAuthUser()? Request::GetAuthUser(): Request::GetGETUser() )); |
|
| 179 | + ZLog::Write(LOGLEVEL_WARN, sprintf("IP: %s failed to authenticate user '%s'", Request::GetRemoteAddr(), Request::GetAuthUser() ? Request::GetAuthUser() : Request::GetGETUser())); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // This could be a WBXML problem.. try to get the complete request |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | // the output had not started yet. If it has started already, we can't show the user the error, and |
| 189 | 189 | // the device will give its own (useless) error message. |
| 190 | 190 | else if (!($ex instanceof ZPushException) || $ex->showLegalNotice()) { |
| 191 | - $cmdinfo = (Request::GetCommand())? sprintf(" processing command <i>%s</i>", Request::GetCommand()): ""; |
|
| 191 | + $cmdinfo = (Request::GetCommand()) ? sprintf(" processing command <i>%s</i>", Request::GetCommand()) : ""; |
|
| 192 | 192 | $extrace = $ex->getTrace(); |
| 193 | - $trace = (!empty($extrace))? "\n\nTrace:\n". print_r($extrace,1):""; |
|
| 194 | - ZPush::PrintGrommunioSyncLegal($exclass . $cmdinfo, sprintf('<pre>%s</pre>',$ex->getMessage() . $trace)); |
|
| 193 | + $trace = (!empty($extrace)) ? "\n\nTrace:\n".print_r($extrace, 1) : ""; |
|
| 194 | + ZPush::PrintGrommunioSyncLegal($exclass.$cmdinfo, sprintf('<pre>%s</pre>', $ex->getMessage().$trace)); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Announce exception to process loop detection |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | Request::GetCommand(), Utils::FormatBytes(memory_get_peak_usage(false)), Utils::FormatBytes(memory_get_peak_usage(true)), |
| 213 | 213 | number_format(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"], 2), |
| 214 | 214 | Request::GetDeviceType(), Request::GetDeviceID(), Request::GetGETUser(), Request::GetRemoteAddr(), |
| 215 | - RequestProcessor::GetWaitTime(), @constant('GROMMUNIOSYNC_VERSION'), Request::GetMethod(), http_response_code() )); |
|
| 215 | + RequestProcessor::GetWaitTime(), @constant('GROMMUNIOSYNC_VERSION'), Request::GetMethod(), http_response_code())); |
|
| 216 | 216 | |
| 217 | 217 | ZLog::Write(LOGLEVEL_DEBUG, "-------- End"); |
| 218 | 218 | |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | require_once 'vendor/autoload.php'; |
| 16 | 16 | |
| 17 | -if (!defined('ZPUSH_CONFIG')) define('ZPUSH_CONFIG', 'config.php'); |
|
| 17 | +if (!defined('ZPUSH_CONFIG')) { |
|
| 18 | + define('ZPUSH_CONFIG', 'config.php'); |
|
| 19 | +} |
|
| 18 | 20 | include_once(ZPUSH_CONFIG); |
| 19 | 21 | |
| 20 | 22 | // Attempt to set maximum execution time |
@@ -33,8 +35,9 @@ discard block |
||
| 33 | 35 | Request::GetCommand(), Request::GetDeviceType(), Request::GetDeviceID(), Request::GetGETUser(), Request::GetRemoteAddr(), @constant('GROMMUNIOSYNC_VERSION'), Request::GetMethod() )); |
| 34 | 36 | |
| 35 | 37 | // always request the authorization header |
| 36 | - if (! Request::HasAuthenticationInfo() || !Request::GetGETUser()) |
|
| 37 | - throw new AuthenticationRequiredException("Access denied. Please send authorisation information"); |
|
| 38 | + if (! Request::HasAuthenticationInfo() || !Request::GetGETUser()) { |
|
| 39 | + throw new AuthenticationRequiredException("Access denied. Please send authorisation information"); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | 42 | ZPush::CheckAdvancedConfig(); |
| 40 | 43 | |
@@ -48,8 +51,9 @@ discard block |
||
| 48 | 51 | } |
| 49 | 52 | |
| 50 | 53 | // Check required GET parameters |
| 51 | - if(Request::IsMethodPOST() && (Request::GetCommandCode() === false || !Request::GetDeviceID() || !Request::GetDeviceType())) |
|
| 52 | - throw new FatalException("Requested the grommunio-sync URL without the required GET parameters"); |
|
| 54 | + if(Request::IsMethodPOST() && (Request::GetCommandCode() === false || !Request::GetDeviceID() || !Request::GetDeviceType())) { |
|
| 55 | + throw new FatalException("Requested the grommunio-sync URL without the required GET parameters"); |
|
| 56 | + } |
|
| 53 | 57 | |
| 54 | 58 | // Load the backend |
| 55 | 59 | $backend = ZPush::GetBackend(); |
@@ -58,17 +62,20 @@ discard block |
||
| 58 | 62 | if (PROVISIONING === true && Request::IsMethodPOST() && ZPush::CommandNeedsProvisioning(Request::GetCommandCode()) && |
| 59 | 63 | ((Request::WasPolicyKeySent() && Request::GetPolicyKey() == 0) || ZPush::GetProvisioningManager()->ProvisioningRequired(Request::GetPolicyKey())) && |
| 60 | 64 | (LOOSE_PROVISIONING === false || |
| 61 | - (LOOSE_PROVISIONING === true && Request::WasPolicyKeySent()))) |
|
| 62 | - //TODO for AS 14 send a wbxml response |
|
| 65 | + (LOOSE_PROVISIONING === true && Request::WasPolicyKeySent()))) { |
|
| 66 | + //TODO for AS 14 send a wbxml response |
|
| 63 | 67 | throw new ProvisioningRequiredException(); |
| 68 | + } |
|
| 64 | 69 | |
| 65 | 70 | // most commands require an authenticated user |
| 66 | - if (ZPush::CommandNeedsAuthentication(Request::GetCommandCode())) |
|
| 67 | - RequestProcessor::Authenticate(); |
|
| 71 | + if (ZPush::CommandNeedsAuthentication(Request::GetCommandCode())) { |
|
| 72 | + RequestProcessor::Authenticate(); |
|
| 73 | + } |
|
| 68 | 74 | |
| 69 | 75 | // Do the actual processing of the request |
| 70 | - if (Request::IsMethodGET()) |
|
| 71 | - throw new NoPostRequestException("This is the grommunio-sync location and can only be accessed by Microsoft ActiveSync-capable devices", NoPostRequestException::GET_REQUEST); |
|
| 76 | + if (Request::IsMethodGET()) { |
|
| 77 | + throw new NoPostRequestException("This is the grommunio-sync location and can only be accessed by Microsoft ActiveSync-capable devices", NoPostRequestException::GET_REQUEST); |
|
| 78 | + } |
|
| 72 | 79 | |
| 73 | 80 | // Do the actual request |
| 74 | 81 | header(ZPush::GetServerHeader()); |
@@ -110,36 +117,35 @@ discard block |
||
| 110 | 117 | // data send as a 'normal' packet. If the output packet exceeds 1MB (see ob_start) |
| 111 | 118 | // then it will be sent as a chunked packet anyway because PHP will have to flush |
| 112 | 119 | // the buffer. |
| 113 | - if(!headers_sent()) |
|
| 114 | - header("Content-Length: $len"); |
|
| 120 | + if(!headers_sent()) { |
|
| 121 | + header("Content-Length: $len"); |
|
| 122 | + } |
|
| 115 | 123 | |
| 116 | 124 | // send vnd.ms-sync.wbxml content type header if there is no content |
| 117 | 125 | // otherwise text/html content type is added which might break some devices |
| 118 | - if (!headers_sent() && $len == 0) |
|
| 119 | - header("Content-Type: application/vnd.ms-sync.wbxml"); |
|
| 126 | + if (!headers_sent() && $len == 0) { |
|
| 127 | + header("Content-Type: application/vnd.ms-sync.wbxml"); |
|
| 128 | + } |
|
| 120 | 129 | |
| 121 | 130 | print $data; |
| 122 | 131 | |
| 123 | 132 | // destruct backend after all data is on the stream |
| 124 | 133 | $backend->Logoff(); |
| 125 | - } |
|
| 126 | - |
|
| 127 | - catch (NoPostRequestException $nopostex) { |
|
| 134 | + } catch (NoPostRequestException $nopostex) { |
|
| 128 | 135 | if ($nopostex->getCode() == NoPostRequestException::OPTIONS_REQUEST) { |
| 129 | 136 | header(ZPush::GetServerHeader()); |
| 130 | 137 | header(ZPush::GetSupportedProtocolVersions()); |
| 131 | 138 | header(ZPush::GetSupportedCommands()); |
| 132 | 139 | ZLog::Write(LOGLEVEL_INFO, $nopostex->getMessage()); |
| 140 | + } else if ($nopostex->getCode() == NoPostRequestException::GET_REQUEST) { |
|
| 141 | + if (Request::GetUserAgent()) { |
|
| 142 | + ZLog::Write(LOGLEVEL_INFO, sprintf("User-agent: '%s'", Request::GetUserAgent())); |
|
| 143 | + } |
|
| 144 | + if (!headers_sent() && $nopostex->showLegalNotice()) { |
|
| 145 | + ZPush::PrintGrommunioSyncLegal('GET not supported', $nopostex->getMessage()); |
|
| 146 | + } |
|
| 133 | 147 | } |
| 134 | - else if ($nopostex->getCode() == NoPostRequestException::GET_REQUEST) { |
|
| 135 | - if (Request::GetUserAgent()) |
|
| 136 | - ZLog::Write(LOGLEVEL_INFO, sprintf("User-agent: '%s'", Request::GetUserAgent())); |
|
| 137 | - if (!headers_sent() && $nopostex->showLegalNotice()) |
|
| 138 | - ZPush::PrintGrommunioSyncLegal('GET not supported', $nopostex->getMessage()); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - catch (Exception $ex) { |
|
| 148 | + } catch (Exception $ex) { |
|
| 143 | 149 | // Extract any previous exception message for logging purpose. |
| 144 | 150 | $exclass = get_class($ex); |
| 145 | 151 | $exception_message = $ex->getMessage(); |
@@ -150,20 +156,23 @@ discard block |
||
| 150 | 156 | } while($current_exception->getPrevious()); |
| 151 | 157 | } |
| 152 | 158 | |
| 153 | - if (Request::GetUserAgent()) |
|
| 154 | - ZLog::Write(LOGLEVEL_INFO, sprintf("User-agent: '%s'", Request::GetUserAgent())); |
|
| 159 | + if (Request::GetUserAgent()) { |
|
| 160 | + ZLog::Write(LOGLEVEL_INFO, sprintf("User-agent: '%s'", Request::GetUserAgent())); |
|
| 161 | + } |
|
| 155 | 162 | |
| 156 | 163 | ZLog::Write(LOGLEVEL_FATAL, sprintf('Exception: (%s) - %s', $exclass, $exception_message)); |
| 157 | 164 | |
| 158 | 165 | if(!headers_sent()) { |
| 159 | 166 | if ($ex instanceof ZPushException) { |
| 160 | 167 | header('HTTP/1.1 '. $ex->getHTTPCodeString()); |
| 161 | - foreach ($ex->getHTTPHeaders() as $h) |
|
| 162 | - header($h); |
|
| 168 | + foreach ($ex->getHTTPHeaders() as $h) { |
|
| 169 | + header($h); |
|
| 170 | + } |
|
| 163 | 171 | } |
| 164 | 172 | // something really unexpected happened! |
| 165 | - else |
|
| 166 | - header('HTTP/1.1 500 Internal Server Error'); |
|
| 173 | + else { |
|
| 174 | + header('HTTP/1.1 500 Internal Server Error'); |
|
| 175 | + } |
|
| 167 | 176 | } |
| 168 | 177 | |
| 169 | 178 | if ($ex instanceof AuthenticationRequiredException) { |
@@ -175,8 +184,9 @@ discard block |
||
| 175 | 184 | } |
| 176 | 185 | |
| 177 | 186 | // log the failed login attempt e.g. for fail2ban |
| 178 | - if (defined('LOGAUTHFAIL') && LOGAUTHFAIL != false) |
|
| 179 | - ZLog::Write(LOGLEVEL_WARN, sprintf("IP: %s failed to authenticate user '%s'", Request::GetRemoteAddr(), Request::GetAuthUser()? Request::GetAuthUser(): Request::GetGETUser() )); |
|
| 187 | + if (defined('LOGAUTHFAIL') && LOGAUTHFAIL != false) { |
|
| 188 | + ZLog::Write(LOGLEVEL_WARN, sprintf("IP: %s failed to authenticate user '%s'", Request::GetRemoteAddr(), Request::GetAuthUser()? Request::GetAuthUser(): Request::GetGETUser() )); |
|
| 189 | + } |
|
| 180 | 190 | } |
| 181 | 191 | |
| 182 | 192 | // This could be a WBXML problem.. try to get the complete request |
@@ -195,16 +205,18 @@ discard block |
||
| 195 | 205 | } |
| 196 | 206 | |
| 197 | 207 | // Announce exception to process loop detection |
| 198 | - if (ZPush::GetDeviceManager(false)) |
|
| 199 | - ZPush::GetDeviceManager()->AnnounceProcessException($ex); |
|
| 208 | + if (ZPush::GetDeviceManager(false)) { |
|
| 209 | + ZPush::GetDeviceManager()->AnnounceProcessException($ex); |
|
| 210 | + } |
|
| 200 | 211 | |
| 201 | 212 | // Announce exception if the TopCollector if available |
| 202 | 213 | ZPush::GetTopCollector()->AnnounceInformation(get_class($ex), true); |
| 203 | 214 | } |
| 204 | 215 | |
| 205 | 216 | // save device data if the DeviceManager is available |
| 206 | - if (ZPush::GetDeviceManager(false)) |
|
| 207 | - ZPush::GetDeviceManager()->Save(); |
|
| 217 | + if (ZPush::GetDeviceManager(false)) { |
|
| 218 | + ZPush::GetDeviceManager()->Save(); |
|
| 219 | + } |
|
| 208 | 220 | |
| 209 | 221 | // end gracefully |
| 210 | 222 | ZLog::Write(LOGLEVEL_INFO, |