public static function getHKPResponse($uri) { $config = Keyserver::getConfig(); try { return Factory::forward(Keyserver::getRequest())->to('http://' . ($addr = (($primary = $config->hkp_primary_keyserver_addr && (strpos($uri, '/pks/lookup?op=stats') === 0 || strpos($uri, '/pks/hashquery') === 0)) ? $config->hkp_primary_keyserver_addr : $config->hkp_load_balanced_addr) . ':' . (!$primary && $config->hkp_load_balanced_port ? $config->hkp_load_balanced_port : $config->hkp_public_port)) . $uri); } catch (\Exception $e) { return new Response(Log::catchError($e, 'Double-check if the keyserver is up and running at the expected address:port (' . $addr . ').')); } }
public static function indentStrictHtml($content) { $dom = new \DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; libxml_use_internal_errors(true); if (!$dom->loadXML(utf8_encode($content), LIBXML_PARSEHUGE)) { $_error = "Validation of Strict HTML failed:"; foreach (libxml_get_errors() as $error) { $_error .= "\n\t" . $error->message; } return Log::catchError($_error) ?: $content; } return preg_replace('~></(?:area|base(?:font)?|br|col|command|embed|frame|hr|img|input|keygen|link|meta|param|source|track|wbr)>~', '/>', utf8_decode(substr($dom = $dom->saveXML($dom, LIBXML_NOEMPTYTAG), strpos($dom, '?' . '>') + 3))); }
public function importContent($content) { if (substr(trim($content), 0, 1) !== '<') { return '<pre>' . trim(htmlentities($content)) . '</pre>'; } $dom = new \DOMDocument('1.0'); libxml_use_internal_errors(true); if (!$dom->loadHTML(utf8_encode($content), LIBXML_PARSEHUGE)) { $_error = "Validation of Strict HTML in Keyserver's output failed:"; foreach (libxml_get_errors() as $error) { $_error .= "\n\t" . $error->message; } return Log::catchError($_error) ?: preg_replace('/.*<body>(.*)<\\/body>.*$/s', '$1', $content); } $xpath = new \DOMXPath($dom); $body = $xpath->query('/html/body'); $content = preg_replace('/^<body>(.*)<\\/body>$/s', '$1', utf8_decode($dom->saveXml($body->item(0)))); if (Keyserver::getConfig()->repair_hkp_h1_tags) { $content = preg_replace('/<h1>(Public Key Server -- )?(.*?)(( "| \')(.*?)( "|\')?)?<\\/h1>/s', '<h2>$2:' . (Keyserver::getRequest()->query->get('search') ? ' <i>' . Keyserver::getRequest()->query->get('search') . '</i> <small style="float:right;line-height:15px;font-size:14px;">' . (Keyserver::getRequest()->query->get('op') == 'get' || strpos(Keyserver::getRequest()->server->get('ORIGINAL_REQUEST_URI'), '/get/') === 0 || strpos(Keyserver::getRequest()->server->get('ORIGINAL_REQUEST_URI'), '/0x') === 0 ? '<a href="/download/' . Keyserver::getRequest()->query->get('search') . '" title="Download">Download</a>' : NULL) . ((Keyserver::getRequest()->query->get('op') == 'get' || strpos(Keyserver::getRequest()->server->get('ORIGINAL_REQUEST_URI'), '/get/') === 0 || strpos(Keyserver::getRequest()->server->get('ORIGINAL_REQUEST_URI'), '/0x') === 0) && Keyserver::getRequest()->server->get('ORIGINAL_REQUEST_URI') == Keyserver::getRequest()->server->get('REQUEST_URI') ? ' | ' : NULL) . (Keyserver::getRequest()->server->get('ORIGINAL_REQUEST_URI') == Keyserver::getRequest()->server->get('REQUEST_URI') ? '<a href="/' . (Keyserver::getRequest()->query->get('op') != 'get' ? 'search/' : (strpos(Keyserver::getRequest()->query->get('search'), '0x') !== 0 ? 'get/' : NULL)) . str_replace(' ', '+', Keyserver::getRequest()->query->get('search')) . '" title="Permalink">Permalink</a>' : NULL) . '</small>' : NULL) . '</h2>', preg_replace('/<h2>(.*)<\\/h2>/', '<h3>$1</h3>', preg_replace('/<h3>(.*)<\\/h3>/', '<h4>$1</h4>', preg_replace('/<pre> (.*)<\\/pre>/s', '<pre style="font-size:15px;line-height:17px;">$1</pre>', $content)))); } Keyserver::getConfig()->head_title = preg_match('/<h2>(.*)<\\/h2>/', $content, $matches) && isset($matches[1]) ? strtok($matches[1], '<') . Keyserver::getRequest()->query->get('search') : Keyserver::getConfig()->html_title; return $content; }