/** * Handles the download the calendar data as iCalendar for the * user identified by $key. * * * @global Seminar_User $user * @global Seminar_Perm $perm * @param string $key * @param string $type type of export */ function index_action($key = '') { if (strlen($key)) { $user_id = IcalExport::getUserIdByKey($key); } else { $username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (isset($username) && isset($password)) { $result = StudipAuthAbstract::CheckAuthentication($username, $password); } if (isset($result) && $result['uid'] !== false) { $user_id = $result['uid']; } else { $this->response->add_header('WWW-Authenticate', 'Basic realm="Stud.IP Login"'); $this->set_status(401); $this->render_text('authentication failed'); return; } } if ($user_id) { $GLOBALS['user'] = new Seminar_User($user_id); $GLOBALS['perm'] = new Seminar_Perm(); $extype = 'ALL_EVENTS'; $export = new CalendarExport(new CalendarWriterICalendar()); $export->exportFromDatabase($user_id, strtotime('-4 week'), 2114377200, 'ALL_EVENTS'); if ($GLOBALS['_calendar_error']->getMaxStatus(ErrorHandler::ERROR_CRITICAL)) { $this->set_status(500); $this->render_nothing(); return; } $content = join($export->getExport()); if (stripos($_SERVER['HTTP_USER_AGENT'], 'google-calendar') !== false) { $content = str_replace(array('CLASS:PRIVATE', 'CLASS:CONFIDENTIAL'), 'CLASS:PUBLIC', $content); } $this->response->add_header('Content-Type', 'text/calendar;charset=utf-8'); $this->response->add_header('Content-Disposition', 'attachment; filename="studip.ics"'); $this->response->add_header('Content-Transfer-Encoding', 'binary'); $this->response->add_header('Pragma', 'public'); $this->response->add_header('Cache-Control', 'private'); $this->response->add_header('Content-Length', strlen($content)); $this->render_text($content); } else { // delayed response to prevent brute force attacks ??? $this->set_status(400); $this->render_nothing(); } }
/** * Sets the lentgh of the key * * @param int $length */ public static function setKeyLength($length) { self::$id_length = $length; }
public function share_action($range_id = null) { $this->range_id = $range_id ?: $this->range_id; $this->calendar = new SingleCalendar($this->range_id); $this->short_id = null; if ($this->calendar->havePermission(Calendar::PERMISSION_OWN)) { if (Request::submitted('delete_id')) { CSRFProtection::verifySecurityToken(); IcalExport::deleteKey($GLOBALS['user']->id); PageLayout::postMessage(MessageBox::success(_('Die Adresse, unter der Ihre Termine abrufbar sind, wurde gelöscht'))); } if (Request::submitted('new_id')) { CSRFProtection::verifySecurityToken(); $this->short_id = IcalExport::setKey($GLOBALS['user']->id); PageLayout::postMessage(MessageBox::success(_('Eine Adresse, unter der Ihre Termine abrufbar sind, wurde erstellt.'))); } else { $this->short_id = IcalExport::getKeyByUser($GLOBALS['user']->id); } if (Request::submitted('submit_email')) { $email_reg_exp = '/^([-.0-9=?A-Z_a-z{|}~])+@([-.0-9=?A-Z_a-z{|}~])+\\.[a-zA-Z]{2,6}$/i'; if (preg_match($email_reg_exp, Request::get('email')) !== 0) { $subject = '[' . get_config('UNI_NAME_CLEAN') . ']' . _('Exportadresse für Ihre Termine'); $text .= _("Diese Email wurde vom Stud.IP-System verschickt. Sie können\n auf diese Nachricht nicht antworten.") . "\n\n"; $text .= _('Über diese Adresse erreichen Sie den Export für Ihre Termine:') . "\n\n"; $text .= $GLOBALS['ABSOLUTE_URI_STUDIP'] . 'dispatch.php/ical/index/' . IcalExport::getKeyByUser($GLOBALS['user']->id); StudipMail::sendMessage(Request::get('email'), $subject, $text); PageLayout::postMessage(MessageBox::success(_('Die Adresse wurde verschickt!'))); } else { PageLayout::postMessage(MessageBox::error(_('Bitte geben Sie eine gültige Email-Adresse an.'))); } $this->short_id = IcalExport::getKeyByUser($GLOBALS['user']->id); } } PageLayout::setTitle($this->getTitle($this->calendar, _('Kalender teilen oder einbetten'))); $this->createSidebar('share', $this->calendar); $this->createSidebarFilter(); }