Ejemplo n.º 1
0
 protected function getConfig($key)
 {
     if (!property_exists($config = Keyserver::getConfig(), $key)) {
         throw new \Exception('Unknown config: "' . $key . '".');
     }
     return $config->{$key};
 }
Ejemplo n.º 2
0
 public static function getInstance()
 {
     if (self::$instance === NULL) {
         self::$instance = new self(Keyserver::getRequest());
     }
     return self::$instance;
 }
Ejemplo n.º 3
0
 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 . ').'));
     }
 }
Ejemplo n.º 4
0
    private function importHead($content)
    {
        $content = preg_replace('/<title>(.*)<\\/title>/', '<title>' . (preg_match('/<title>(.*)<\\/title>/', $content, $matches) && isset($matches[1]) && strip_tags($matches[1]) ? Keyserver::getConfig()->html_title . ' | ' . strip_tags($matches[1]) : (preg_match('/<h2>(.*)<\\/h2>/', $content, $matches) && isset($matches[1]) ? Keyserver::getConfig()->html_title . ' | ' . strip_tags($matches[1]) : Keyserver::getConfig()->html_title)) . '</title>', $content);
        $hkp_styles = <<<CSS
<style type="text/css">
      .uid { color: green; text-decoration: underline; }
      .warn { color: red; font-weight: bold; }
    </style>
CSS;
        return preg_replace('/(<\\/head>)/s', $hkp_styles . '$1', $content);
    }
Ejemplo n.º 5
0
 private function getState($host)
 {
     $fp = fsockopen($host, (int) Keyserver::getConfig()->boinc_machines_port, $errno, $errstr, 30);
     if (!$fp) {
         return 'Server down.';
     }
     $request = sprintf("<boinc_gui_rpc_request>\n%s\n</boinc_gui_rpc_request>\n", '<get_state/>');
     fputs($fp, $request);
     $res = NULL;
     while (!feof($fp)) {
         $char = fgetc($fp);
         if ($char === false || $char == "") {
             break;
         }
         $res .= $char;
     }
     fclose($fp);
     try {
         $xml = new \SimpleXMLElement($res);
     } catch (\Exception $ex) {
         return 'Service down.';
     }
     $host = $xml->xpath('/boinc_gui_rpc_reply/client_state/host_info');
     $return = '<h4>' . $host[0]->p_ncpus . 'x ' . $host[0]->p_model . ':</h4>';
     $result = $xml->xpath('/boinc_gui_rpc_reply/client_state/result');
     while (list(, $node) = each($result)) {
         $class = 'state-done';
         if ($node->active_task) {
             if ($node->active_task->active_task_state == '1') {
                 $class = 'state-active';
             } else {
                 $class = 'state-pause';
             }
         } else {
             if ($node->state == 2) {
                 $class = 'state-queue';
             }
         }
         $return .= '<table style="margin:0px auto;" class=' . $class . '>' . '<tr><td width="150">Project: </td><td width="450">' . current(array_slice(explode('/', $node->project_url), 2, 1)) . '</td></tr>' . '<tr><td width="150">Task: </td><td width="450">' . $node->name . '</td></tr>' . '<tr><td>State: </td><td>' . strtr($node->state, array('1' => 'Completed, transferring..', '5' => 'Completed, waiting for validation', '2' => $node->active_task ? $node->active_task->active_task_state == '1' ? 'In progress' : 'Paused' : 'Queued')) . '</td></tr>' . '<tr><td>Received: </td><td>' . $this->timestampToStr($node->received_time) . '</td></tr>' . '<tr><td>Deadline: </td><td>' . $this->timestampToStr($node->report_deadline) . '</td></tr>';
         if ($node->active_task) {
             $return .= '<tr><td>CPU time remaining: </td><td>' . $this->secToStr($node->estimated_cpu_time_remaining) . '</td></tr>' . '<tr><td>Elapsed CPU time: </td><td>' . $this->secToStr($node->active_task->current_cpu_time) . '</td></tr>' . '<tr><td>Slot: </td><td>' . $node->active_task->slot . '</td></tr>' . '<tr><td>Fraction done: </td><td>' . number_format(floatval($node->active_task->fraction_done) * 100, 1) . '%' . '</td></tr>';
         } else {
             if (!in_array($node->state, array(1, 2))) {
                 $return .= '<tr><td>Complete: </td><td>' . $this->timestampToStr($node->completed_time) . '</td></tr>' . '<tr><td>Final CPU time: </td><td>' . $this->secToStr($node->final_cpu_time) . '</td></tr>' . '<tr><td>Total elapsed time: </td><td>' . $this->secToStr($node->final_elapsed_time) . '</td></tr>';
             }
         }
         $return .= '</table><br />';
     }
     return $return;
 }
Ejemplo n.º 6
0
 public static function catchError($e, $hint = NULL)
 {
     if (!is_string($e)) {
         $e = $e->getMessage() . PHP_EOL . $e->getTraceAsString();
     }
     if ($hint) {
         $e = 'Hint! ' . $hint . PHP_EOL . $e;
     }
     if (!(bool) (int) Keyserver::getConfig()->display_exceptions) {
         self::getLog()->addEmergency($e);
         return "An error ocurred. Please, read the logs or contact the keyserver administrator.";
     }
     return '<pre>' . $e . '</pre>';
 }
Ejemplo n.º 7
0
 public static function parseContent(Response $response, $content = FALSE)
 {
     $response->headers->set('Via', '1.1 ' . Keyserver::getConfig()->hostname . ':' . Keyserver::getConfig()->hkp_public_port . ' (' . (Keyserver::getConfig()->expose_keyserver ? $response->headers->get('Server') : 'php-proxy-keyserver') . ')');
     if (strpos($response->headers->get('Content-Disposition'), 'attachment') === 0 || !Keyserver::getRequest()->server->get('HTTP_USER_AGENT') || Keyserver::getRequest()->server->get('SERVER_PORT') === Keyserver::getConfig()->hkp_public_port && !Keyserver::getConfig()->layout_hkp_request && strpos(Keyserver::getRequest()->server->get('REQUEST_URI'), '/pks/') === 0) {
         return $response;
     }
     if (!$content) {
         $content = self::isPhtml() ? (string) new Phtml(FALSE, $response->getContent()) : $response->getContent();
     }
     if (self::isPhtml() && Keyserver::getConfig()->indent_strict_html) {
         $content = self::indentStrictHtml($content);
     }
     $response->headers->set('Content-Type', 'text/html;charset=UTF-8');
     $response->headers->set('Content-Length', strlen($content));
     return $response->setContent($content);
 }
Ejemplo n.º 8
0
echo date('Y-m-d');
?>
</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>
  <url>
    <loc>http<?php 
if ($SERVER_PORT_443) {
    ?>
s<?php 
}
?>
://<?php 
echo Keyserver::getConfig()->hostname;
if ($SERVER_PORT_HKP) {
    ?>
:<?php 
    echo Keyserver::getConfig()->hkp_public_port;
}
?>
/faq</loc>
    <lastmod><?php 
echo date('Y-m-d');
?>
</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.5</priority>
  </url>
</urlset>
<?php

use ctubio\HKPProxy\Keyserver;
ini_set('display_errors', TRUE);
ini_set('error_reporting', E_ALL);
require '../vendor/autoload.php';
Keyserver::getResponse()->send();
Ejemplo n.º 10
0
 public static function warn($scope, $msg = NULL, $subject = NULL)
 {
     return '</small><br /><span class="warn">' . strtr($scope, array('contact' => 'Your membership line is correct, but after checking your stats page, ' . $subject . ' (or the page was unreachable).', 'format' => 'Membership line mal-formed, ', 'exists' => 'Your membership line was already added to ' . Keyserver::getConfig()->hostname . '.</span><br /><br />', 'admin' => 'Your membership line is correct, and ' . Keyserver::getConfig()->hostname . ' was found as a Gossip Peer in the stats page of ' . $subject . ', but an error occurred while saving your membership line, please send an email to <a href="mailto:' . Keyserver::getConfig()->bugs_contact_mail . '">&lt;' . Keyserver::getConfig()->bugs_contact_mail . '&gt;</a> as usual.', 'server' => 'Your membership line is correct, but after checking the stats page of ' . $subject . ', ' . Keyserver::getConfig()->hostname . ' was not found as a Gossip Peer.</span><br /><br /><span class="uid" style="text-decoration:none;">Please, add the following line to your membership file and wait until it is refreshed before continue:</span><br /><br /><input style="width:100%;padding:5px;;text-align:center;font-weight:600;" value="' . htmlentities(Keyserver::getConfig()->membership_line) . '" />')) . $msg . '</span><br />';
 }
 public function testSilentUnreachable()
 {
     $request = Request::createFromGlobals();
     $request->server->set('REQUEST_URI', '/pks/lookup?op=stats');
     $request->server->set('HTTP_USER_AGENT', __METHOD__);
     Keyserver::$request_instance = $request;
     Keyserver::getConfig()->display_exceptions = FALSE;
     $response = Keyserver::getResponse();
     $this->assertTrue($response instanceof Response);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('text/html;charset=UTF-8', $response->headers->get('content-type'));
     $this->assertStringStartsWith('<!DOCTYPE html>', $response->getContent());
     $this->assertStringEndsWith('</html>' . PHP_EOL, $response->getContent());
     $this->assertSame(FALSE, strpos($response->getContent(), '<pre>Hint! Double-check'));
     $this->assertGreaterThan(21, strpos($response->getContent(), 'An error ocurred. Please'));
 }