public function _handler_csv($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); midcom::get()->disable_limits(); $this->_load_datamanager($this->_load_schemadb($handler_id, $args, $data)); $this->_objects = $this->_load_data($handler_id, $args, $data); if (!isset($args[0]) || empty($args[0])) { //We do not have filename in URL, generate one and redirect $fname = preg_replace('/[^a-z0-9-]/i', '_', strtolower($this->_topic->extra)) . '_' . date('Y-m-d') . '.csv'; if (strpos(midcom_connection::get_url('uri'), '/', strlen(midcom_connection::get_url('uri')) - 2)) { return new midcom_response_relocate(midcom_connection::get_url('uri') . $fname); } else { return new midcom_response_relocate(midcom_connection::get_url('uri') . "/{$fname}"); } } if (!isset($data['filename']) || $data['filename'] == '') { $data['filename'] = str_replace('.csv', '', $args[0]); } $this->_init_csv_variables(); midcom::get()->skip_page_style = true; // FIXME: Use global configuration //midcom::get('cache')->content->content_type($this->_config->get('csv_export_content_type')); midcom::get('cache')->content->content_type('application/csv'); _midcom_header('Content-Disposition: filename=' . $data['filename']); }
private function _generate_http_response() { if ($GLOBALS['midcom_config']['auth_login_form_httpcode'] == 200) { _midcom_header('HTTP/1.0 200 OK'); return; } _midcom_header('HTTP/1.0 403 Forbidden'); }
<?php if (!isset($_POST['org_openpsa_export_csv_data'])) { debug_add('Variable org_openpsa_reports_csv not set in _POST, aborting'); die; } $filename = 'export.csv'; if (isset($_POST['org_openpsa_export_csv_filename'])) { $filename = $_POST['org_openpsa_export_csv_filename']; //some basic sanitation... $filename = str_replace("\n", '', $filename); $filename = str_replace("'", '', $filename); $filename = str_replace('"', '', $filename); $filename = str_replace(' ', '_', $filename); } _midcom_header('Content-type: application/csv; charset=utf-8'); _midcom_header('Content-Disposition: attachment;Filename=' . $filename); echo $_POST['org_openpsa_export_csv_data'];
global $argc, $argv; $session = new midcom_services_session('midcom_helper_datamanager2_widget_captcha'); if (!isset($argv[0])) { throw new midcom_error_notfound("Missing CAPTCHA session key."); } if ($argc == 0 || !$session->exists($argv[0])) { throw new midcom_error('Failed to generate CAPTCHA, the session key passed is invalid.'); } $passphrase = $session->get($argv[0]); if (empty($passphrase)) { throw new midcom_error('Failed to generate CAPTCHA, no passphrase in session.'); } // Set Captcha options (font must exist!) $options = array('width' => 200, 'height' => 80, 'phrase' => $passphrase, 'imageOptions' => array('font_path' => MIDCOM_ROOT . '/midcom/helper/datamanager2/widget/', 'font_file' => 'captcha-font.ttf', 'background_color' => '#000000', 'text_color' => '#FFFFFF')); /* Generate a new Text_CAPTCHA object, Image driver * This is working at least with Text_CAPTCHAS latest alpha version. Older versions * give missing font error */ $captcha = Text_CAPTCHA::factory('Image'); $result = $captcha->init($options); if (PEAR::isError($result)) { throw new midcom_error('Failed to generate CAPTCHA, class init call failed: ' . $result->getMessage()); } // Get Captcha GD Handle $image = $captcha->getCAPTCHA(); if (!is_resource($image)) { throw new midcom_error('Failed to generate CAPTCHA, rendering failed. Reason: ' . $image->getMessage()); } // Render the Captcha _midcom_header('Content-Type: image/png'); imagepng($image);
function cache_control_headers() { // Add Expiration and Cache Control headers $cache_control = false; $pragma = false; $expires = false; // Just to be sure not to mess the headers sent by no_cache in case it was called if (!$this->_no_cache) { // Typecast to make copy in stead of reference $strategy = (string) $this->_headers_strategy; $default_lifetime = (int) $this->_default_lifetime; if (midcom::get('auth')->is_valid_user() || !midcom_connection::get_user()) { // Typecast to make copy in stead of reference $strategy = (string) $this->_headers_strategy_authenticated; $default_lifetime = (int) $this->_default_lifetime_authenticated; } switch ($strategy) { // included in case _headers_strategy_authenticated sets this case 'no-cache': $this->no_cache(); break; case 'revalidate': // Currently, we *force* a cache client to revalidate the copy every time. // I hope that this fixes most of the problems outlined in #297 for the time being. // The timeout of a content cache entry is not affected by this. $cache_control = 'max-age=0 must-revalidate'; $expires = time(); break; case 'private': // Fall-strough intentional // Fall-strough intentional case 'public': if (!is_null($this->_expires)) { $expires = $this->_expires; $max_age = $this->_expires - time(); } else { $expires = time() + $default_lifetime; $max_age = $default_lifetime; } $cache_control = "{$strategy} max-age={$max_age}"; if ($max_age == 0) { $cache_control .= ' must-revalidate'; } $pragma =& $strategy; break; } } if ($cache_control !== false) { $header = "Cache-Control: {$cache_control}"; _midcom_header($header); $this->_sent_headers[] = $header; } if ($pragma !== false) { $header = "Pragma: {$pragma}"; _midcom_header($header); $this->_sent_headers[] = $header; } if ($expires !== false) { $header = "Expires: " . gmdate("D, d M Y H:i:s", $expires) . " GMT"; _midcom_header($header); $this->_sent_headers[] = $header; } }
/** * Show an error page. * * This function is a small helper, that will display a simple HTML Page reporting * the error described by $httpcode and $message. The $httpcode is also used to * send an appropriate HTTP Response. * * The error pages can be customized by creating style elements named midcom_error_$httpcode. * * For a list of the allowed HTTP codes see the MIDCOM_ERR... constants * * <b>Note:</b> This function will call _midcom_stop_request() after it is finished. * * @link http://www.midgard-project.org/documentation/styling-midcom-error-pages/ Styling MidCOM error pages * @param int $httpcode The error code to send. * @param string $message The message to print. */ public function show($httpcode, $message) { if (!$this->_exception) { debug_add("An error has been generated: Code: {$httpcode}, Message: {$message}"); debug_print_function_stack('Stacktrace:'); } // Send error to special log or recipient as per in configuration. $this->send($httpcode, $message); if (_midcom_headers_sent()) { debug_add("Generate-Error was called after sending the HTTP Headers!", MIDCOM_LOG_ERROR); debug_add("Unexpected Error: {$httpcode} - {$message}", MIDCOM_LOG_ERROR); _midcom_stop_request("Unexpected Error, this should display an HTTP {$httpcode} - " . htmlentities($message)); } switch ($httpcode) { case MIDCOM_ERROK: $header = "HTTP/1.0 200 OK"; $title = "OK"; $code = 200; break; case MIDCOM_ERRNOTFOUND: $header = "HTTP/1.0 404 Not Found"; $title = "Not Found"; $code = 404; break; case MIDCOM_ERRFORBIDDEN: // show access denied $this->access_denied($message); $header = "HTTP/1.0 403 Forbidden"; $title = "Forbidden"; $code = 403; break; case MIDCOM_ERRAUTH: $header = "HTTP/1.0 401 Unauthorized"; $title = "Unauthorized"; $code = 401; break; default: debug_add("Unknown Errorcode {$httpcode} encountered, assuming 500"); // Fall-through // Fall-through case MIDCOM_ERRCRIT: $header = "HTTP/1.0 500 Server Error"; $title = "Server Error"; $code = 500; break; } _midcom_header($header); _midcom_header('Content-Type: text/html'); $style = midcom::get('style'); $style->data['error_title'] = $title; $style->data['error_message'] = $message; $style->data['error_code'] = $code; $style->data['error_exception'] = $this->_exception; $style->data['error_handler'] = $this; if (!$style->show_midcom('midcom_error_' . $code)) { $style->show_midcom('midcom_error'); } debug_add("Error Page output finished, exiting now"); midcom::get('cache')->content->no_cache(); if (midcom::get()) { midcom::get()->finish(); } _midcom_stop_request(); }
// IP Address Checks $ips = $GLOBALS['midcom_config']['indexer_reindex_allowed_ips']; $ip_sudo = false; if ($ips && in_array($_SERVER['REMOTE_ADDR'], $ips)) { if (!midcom::get('auth')->request_sudo('midcom.services.indexer')) { throw new midcom_error('Failed to acquire SUDO rights. Aborting.'); } $ip_sudo = true; } else { // Require user to Basic-authenticate for security reasons midcom::get('auth')->require_valid_user('basic'); midcom::get('auth')->require_admin_user(); } midcom::get('cache')->content->enable_live_mode(); _midcom_header('Content-Type: text/plain'); // Ensure cron doesn't timeout @ini_set('max_execution_time', 0); // Determine recurrence $recurrence = MIDCOM_CRON_MINUTE; if (isset($_GET['type'])) { switch ($_GET['type']) { case 'hour': $recurrence = MIDCOM_CRON_HOUR; break; case 'day': $recurrence = MIDCOM_CRON_DAY; break; } } // Instantiate cron service and run
/** * Sends a header out to the client. * * This function is syntactically identical to * the regular PHP header() function, but is integrated into the framework. Every * Header you sent must go through this function or it might be lost later on; * this is especially important with caching. * * @param string $header The header to send. * @param integer $response_code HTTP response code to send with the header */ public function header($header, $response_code = null) { midcom::get('cache')->content->register_sent_header($header); if (!is_null($response_code)) { // Send the HTTP response code as requested _midcom_header($header, true, $response_code); } else { _midcom_header($header); } }