grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026vcal_focus = new iCal(); $this->user_focus = new User(); } /** * Serve a webdav request * * @access public * @param string */ public function ServeICalRequest($base = false) { global $sugar_config; global $current_language; global $log; if (empty($_REQUEST['type'])) { $_REQUEST['type'] = 'ics'; } if (empty($_REQUEST['encoding'])) { $this->cal_encoding = 'utf-8'; } else { $this->cal_encoding = $_REQUEST['encoding']; } if (empty($_REQUEST['cal_charset'])) { $this->cal_charset = 'utf-8'; } else { $this->cal_charset = $_REQUEST['cal_charset']; } if (empty($_REQUEST['http_spec'])) { $this->http_spec = '1.1'; } else { $this->http_spec = $_REQUEST['http_spec']; } // check the HTTP auth headers for a user if (empty($_REQUEST['user_name']) && !empty($_SERVER['PHP_AUTH_USER'])) { $_REQUEST['user_name'] = $_SERVER['PHP_AUTH_USER']; $_REQUEST['password'] = $_SERVER['PHP_AUTH_PW']; } if (!empty($sugar_config['session_dir'])) { session_save_path($sugar_config['session_dir']); } session_start(); $query_arr = array(); // set path if (empty($_SERVER["PATH_INFO"])) { $this->path = "/"; if (strtolower($_SERVER["REQUEST_METHOD"]) == 'get') { $query_arr = $_REQUEST; } else { parse_str($_REQUEST['parms'], $query_arr); } } else { $this->path = $this->_urldecode($_SERVER["PATH_INFO"]); if (ini_get("magic_quotes_gpc")) { $this->path = stripslashes($this->path); } $query_str = preg_replace('/^\//', '', $this->path); $query_arr = array(); parse_str($query_str, $query_arr); } if (!empty($query_arr['type'])) { $this->vcal_type = $query_arr['type']; } else { $this->vcal_type = 'vfb'; } if (!empty($query_arr['source'])) { $this->source = $query_arr['source']; } else { $this->source = 'outlook'; } if (!empty($query_arr['key'])) { $this->publish_key = $query_arr['key']; } // select user by email if (!empty($query_arr['user_id'])) { $this->user_focus->retrieve(clean_string($query_arr['user_id'])); $this->user_focus->loadPreferences(); } else { if (isset($query_arr['password'])) { $user = $this->user_focus; $user->retrieve_by_string_fields(['user_name' => $query_arr['user_name']]); if ($user->id === null && !$user::findUserPassword($user->user_name, md5($query_arr['password'])) ) { $this->http_status("401 not authorized"); echo 'Invalid username or password'; return; } $this->user_focus->authenticated = true; } elseif (!empty($query_arr['email'])) { // clean the string! $query_arr['email'] = clean_string($query_arr['email']); //get user info $this->user_focus->retrieve_by_email_address($query_arr['email']); } else { if (!empty($query_arr['user_name'])) { // clean the string! $query_arr['user_name'] = clean_string($query_arr['user_name']); //get user info $arr = array('user_name' => $query_arr['user_name']); $this->user_focus->retrieve_by_string_fields($arr); } else { $errorMessage = 'iCal Server - Invalid request.'; $log->warning($errorMessage); print $errorMessage; } } } parent::ServeRequest(); } public function GET() { return true; } /** * GET method handler * * @param void * @returns void */ public function http_GET() { if ($this->vcal_type == 'vfb') { $this->http_status("200 OK"); ob_end_clean(); echo $this->vcal_focus->get_vcal_freebusy($this->user_focus); } else { if ($this->vcal_type == 'ics') { // DO HTTP AUTHORIZATION for iCal: if (isset($this->publish_key) && $this->publish_key === $this->user_focus->getPreference('calendar_publish_key') || $this->user_focus->is_authenticated() ) { $this->http_status("200 OK"); header('Content-Type: text/calendar; charset="' . $this->cal_charset . '"'); $result = mb_convert_encoding(html_entity_decode($this->vcal_focus->getVcalIcal( $this->user_focus, $_REQUEST['num_months'] ), ENT_QUOTES, $this->cal_charset), $this->cal_encoding); ob_end_clean(); echo $result; return; } $this->http_status("401 not authorized"); header('WWW-Authenticate: Basic realm="SugarCRM iCal"'); echo 'Authorization required'; } else { $this->http_status("404 Not Found"); ob_end_clean(); } } } /** * set HTTP return status and mirror it in a private header * * @param string status code and message * @return void */ public function http_status($status) { // simplified success case if ($status === true) { $status = "200 OK"; } // remember status $this->_http_status = $status; // generate HTTP status response header("HTTP/$this->http_spec $status"); header("X-WebDAV-Status: $status", true); } }