public function render() { $headers = array(); $response = ''; if (count($this->route_matches) > 1) { $site = $this->route_matches[1]; if (!preg_match('@^https?://@i', $site)) { $site = 'http://' . $site; } $headers = @get_headers($site); if (!$headers) { error400('Headers could not be retrieved for that domain.'); return; } foreach ($headers as $header) { $response .= htmlspecialchars($header . "\n"); } } else { $headers = getallheaders(); foreach ($headers as $key => $value) { if (server_or_default('HTTP_X_DAGD_PROXY') == "1") { if (strpos($key, 'X-Forwarded-') === 0 || $key == 'X-DaGd-Proxy') { continue; } } $response .= htmlspecialchars($key . ': ' . $value . "\n"); } } return $response; }
public function render() { $query = $this->route_matches[1]; // Default to english (en). $language = request_or_default('lang', 'en'); if (!preg_match('@^[a-z]+$@i', $language)) { error400('`lang` should only contain letters.'); return; } $wmprojects = array("wikipedia", "wiktionary", "wikisource", "wikiversity", "wikibooks", "wikiquote", "wikinews"); // Default to wikipedia.org. $project = request_or_default('proj', 'wikipedia'); if (!in_array($project, $wmprojects)) { error400('`proj` needs to be a valid Wikimedia project.'); return; } if (!count(dns_get_record($language . '.' . $project . '.org'))) { error400($language . '.' . $project . '.org is not a valid wikipedia subdomain.'); return; } $counts = file_get_contents('http://' . $language . '.' . $project . '.org/w/api.php?action=query&list=users' . '&usprop=editcount&format=json&ususers=' . urlencode($query)); $json_counts = json_decode($counts, true); $json_counts = $json_counts['query']['users']; $total_edits = 0; foreach ($json_counts as $user) { $total_edits += (int) $user['editcount']; } return $total_edits; }
public function render() { $environment = DaGdConfig::get('general.environment'); if ($environment != 'development') { error400('This page is disabled in the production environment.'); return false; } else { throw new Exception('This is a test exception.'); } }
public function render() { $code = $this->route_matches[1]; if (!is_numeric($code)) { error400('You should give a numeric HTTP status code.'); return; } if ((int) $code > 999) { error400('The given HTTP status code must be under 1000.'); return; } if (count($this->route_matches) == 2) { header('HTTP/1.1 ' . $code . ' da.gd header test'); return; } else { $text = $this->route_matches[2]; header('HTTP/1.1 ' . $code . ' ' . $text); return; } }
public function render() { if (server_or_default('REQUEST_METHOD') == 'POST') { error400('This service has been deprecated, no new pastes are being accepted.'); return; } else { // Trying to access one? if (count($this->route_matches) > 1) { // Yes $this->paste_id = $this->route_matches[1]; $this->fetch_paste(); if ($this->paste_text) { // NEVER EVER EVER EVER EVER EVER EVER remove this header() without // changing the lines below it. XSS is bad. :) header('Content-type: text/plain; charset=utf-8'); header('X-Content-Type-Options: nosniff'); $this->wrap_pre = false; $this->escape = false; $this->text_html_strip = false; $this->text_content_type = false; return $this->paste_text; } else { error404(); return; } } else { if (!is_html_useragent()) { // No use in showing a form for text UAs. Rather, show help text. return help('DaGdPastebinController'); } $content = ' ***da.gd Pastebin*** This feature is being deprecated and no new pastes are being accepted. '; $markup = new DaGdMarkup($content); $markup = $markup->render(); echo $markup; return; } } }
if (strlen($type) == 0) { return error400($host . '/' . $plugin . (strlen($pinst) ? '-' . $pinst : '') . '/?', "Type name may not be blank"); } } } $tinst = read_var('c_type_instance', $vars, ''); $graph_identifier = $host . '/' . $plugin . (strlen($pinst) ? '-' . $pinst : '') . '/' . $type . (strlen($tinst) ? '-' . $tinst : '-*'); $timespan = read_var('timespan', $vars, $config['timespan'][0]['name']); $timespan_ok = false; foreach ($config['timespan'] as &$ts) { if ($ts['name'] == $timespan) { $timespan_ok = true; } } if (!$timespan_ok) { return error400($graph_identifier, "Unknown timespan requested"); } $logscale = (bool) read_var('logarithmic', $vars, false); $tinylegend = (bool) read_var('tinylegend', $vars, false); // Check that at least 1 RRD exists for the specified request $all_tinst = collectd_list_tinsts($host, $plugin, $pinst, $type); if (count($all_tinst) == 0) { return error404($graph_identifier, "No rrd file found for graphing"); } // Now that we are read, do the bulk work load_graph_definitions($logscale, $tinylegend); $pinst = strlen($pinst) == 0 ? null : $pinst; $tinst = strlen($tinst) == 0 ? null : $tinst; $opts = array(); $opts['timespan'] = $timespan; if ($logscale) {
public function render() { if ($this->route_matches[1] == 'store') { // We are storing a command. Do some sanity checks. $valid_char_pattern = '@^[\\d\\w-_]+$@i'; if (!preg_match($valid_char_pattern, $this->route_matches[2])) { error400('Invalid command. Alphanumeric only, please.'); return false; } // TODO: might be better to use a unique constraint here, and not check // ourselves. That way we only make one query and just report the error // back. $this->getURL($this->route_matches[2]); if ($this->url !== null) { error400('That command has already been defined. Try using a new name.'); return false; } if ($this->addCommand()) { return 'Success.'; } else { error400('Something failed :( ... Try again later.'); return false; } } elseif (count($this->route_matches) <= 2) { $rows = $this->getAllCommands(); if (end($this->route_matches) == 'json') { $commands = array(); foreach ($rows as $row) { $commands[$row['command']] = $row['url']; } header('Content-Type: application/json'); $this->escape = false; $this->wrap_pre = false; return json_encode($commands); } else { $return = "***Enabled Commands***<dl>\n"; foreach ($rows as $row) { $return .= '<dt>' . htmlspecialchars($row['command']) . "</dt>\n"; $return .= '<dd> Redirect: ' . htmlspecialchars($row['url']) . "</dd>\n"; $return .= '<dd> Added: ' . htmlspecialchars($row['creation_dt']) . "</dd>\n"; } $return .= '</dl>'; $markup = new DaGdMarkup($return); $markup->nl2br = false; $this->escape = false; $this->wrap_pre = false; return $markup->render(); } } else { // Accessing a command? $this->getURL($this->route_matches[1]); if ($this->url === null) { error400('That command was not found.'); return false; } else { $url = str_replace('$PARAMETERS', $this->route_matches[2], $this->url); header('Location: ' . $url); return true; } } }
public function render() { $max_width = DaGdConfig::get('image.max_width'); $max_height = DaGdConfig::get('image.max_height'); $default_filetype = DaGdConfig::get('image.default_filetype'); $imagetypes = DaGdConfig::get('image.imagetypes'); $fontpath = DaGdConfig::get('image.fontpath'); $bg_color_rgb = DaGdConfig::get('image.default_bg_rgb'); $text_color_rgb = DaGdConfig::get('image.default_text_rgb'); $split = preg_split('@(?:x|\\*)@', $this->route_matches[1]); if (count($split) !== 2) { error400('You must separate width and height with either * or x'); return false; } else { $this->width = $split[0]; $this->height = $split[1]; } if ($this->width > $max_width || $this->height > $max_height) { error400('The generated image should be less than ' . $max_width . 'x' . $max_height . '.'); return false; } if (count($this->route_matches) === 3) { if (in_array($this->route_matches[2], array_keys($imagetypes))) { $this->filetype = $this->route_matches[2]; } else { error400('The image type you specified is not supported.'); return false; } } else { $this->filetype = $default_filetype; } $r = $bg_color_rgb[0]; $g = $bg_color_rgb[1]; $b = $bg_color_rgb[2]; if ($bgcolor = request_or_default('bgcolor')) { if (strlen($bgcolor) == 6) { $r = $bgcolor[0] . $bgcolor[1]; $g = $bgcolor[2] . $bgcolor[3]; $b = $bgcolor[4] . $bgcolor[5]; } elseif (strlen($bgcolor) == 3) { $r = $bgcolor[0] . $bgcolor[0]; $g = $bgcolor[1] . $bgcolor[1]; $b = $bgcolor[2] . $bgcolor[2]; } } $this->bgcolor = array(hexdec($r), hexdec($g), hexdec($b)); $this->escape = false; $this->wrap_pre = false; $this->text_html_strip = false; $this->text_content_type = false; // Generate the image. header('Content-Type: ' . $imagetypes[$this->filetype]['contenttype']); $image = imagecreate($this->width, $this->height); imagecolorallocate($image, $this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]); $text = request_or_default('text', $this->width . 'x' . $this->height); if ($text == 'off') { $text = ''; } $positions = imagettfbbox(30, 0, $fontpath, $text); $center_x = ceil(($this->width - $positions[2]) / 2); $center_y = ceil(($this->height - $positions[5]) / 2); $color = imagecolorallocate($image, $text_color_rgb[0], $text_color_rgb[1], $text_color_rgb[2]); imagettftext($image, 30, 0, $center_x, $center_y, $color, $fontpath, $text); call_user_func($imagetypes[$this->filetype]['phpfunction'], $image); imagedestroy($image); }
function error400($error = 'Invalid formula') { header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); include '400.php'; } //ignore_user_abort(); ini_set('max_execution_time', 10); header('X-Powered-By: S2 Latex Service'); $templater = new Templater(TPL_DIR); $renderer = new Renderer($templater, TMP_DIR, LATEX_COMMAND, DVISVG_COMMAND, DVIPNG_COMMAND); if (defined('LOG_DIR')) { $renderer->setLogDir(LOG_DIR); } $renderer->setDebug($isDebug); $processor = new Processor($renderer, CACHE_SUCCESS_DIR, CACHE_FAIL_DIR); $processor->addSVGCommand(SVGO); $processor->addSVGCommand(GZIP); try { $processor->parseURI(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); } catch (Exception $e) { error400($isDebug ? $e->getMessage() : 'Invalid formula'); die; } if ($processor->prepareContent()) { $processor->echoContent(); } else { error400($isDebug ? $processor->getError() : 'Invalid formula'); } if (!$isDebug) { $processor->saveContent(); }
public function set_longurl_or_400() { if ($_REQUEST['url'] == '') { // If url was there but is an empty string, say so. error400('Error: Cannot create something out of nothing.'); return false; } if ($long_url = request_or_default('url')) { // Something has at least been submitted. Is it valid? if (preg_match('@^https?://@', $long_url) && !$this->blacklisted($long_url)) { // Good enough for now...probably needs some better checks. $this->long_url = $long_url; return true; } else { error400('Malformed or blacklisted original URL. Try again (http or https ' . 'protocols only, please.).'); return false; } } else { return false; } }
if (strlen($type) == 0) { return error400($host . '/' . $plugin . (strlen($pinst) ? '-' . $pinst : '') . '/?', "类型名称不可以空白"); } } } $tinst = read_var('c_type_instance', $vars, ''); $graph_identifier = $host . '/' . $plugin . (strlen($pinst) ? '-' . $pinst : '') . '/' . $type . (strlen($tinst) ? '-' . $tinst : '-*'); $timespan = read_var('timespan', $vars, $config['timespan'][0]['name']); $timespan_ok = false; foreach ($config['timespan'] as &$ts) { if ($ts['name'] == $timespan) { $timespan_ok = true; } } if (!$timespan_ok) { return error400($graph_identifier, "未知的时间要求"); } $logscale = (bool) read_var('logarithmic', $vars, false); $tinylegend = (bool) read_var('tinylegend', $vars, false); // Check that at least 1 RRD exists for the specified request $all_tinst = collectd_list_tinsts($host, $plugin, $pinst, $type); if (count($all_tinst) == 0) { return error404($graph_identifier, "没有RRD文件发现图形"); } // Now that we are read, do the bulk work load_graph_definitions($logscale, $tinylegend); $pinst = strlen($pinst) == 0 ? null : $pinst; $tinst = strlen($tinst) == 0 ? null : $tinst; $opts = array(); $opts['timespan'] = $timespan; if ($logscale) {