Exemplo n.º 1
0
 function prepare($args)
 {
     StatusNet::setApi(true);
     // Send smaller error pages
     parent::prepare($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_m('This method requires a POST.'));
     }
     if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') {
         $this->clientError(_m('Salmon requires application/magic-envelope+xml'));
     }
     $xml = file_get_contents('php://input');
     // Check the signature
     $salmon = new Salmon();
     if (!$salmon->verifyMagicEnv($xml)) {
         common_log(LOG_DEBUG, "Salmon signature verification failed.");
         $this->clientError(_m('Salmon signature verification failed.'));
     } else {
         $magic_env = new MagicEnvelope();
         $env = $magic_env->parse($xml);
         $xml = $magic_env->unfold($env);
     }
     $dom = DOMDocument::loadXML($xml);
     if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') {
         common_log(LOG_DEBUG, "Got invalid Salmon post: {$xml}");
         $this->clientError(_m('Salmon post must be an Atom entry.'));
     }
     $this->act = new Activity($dom->documentElement);
     return true;
 }
Exemplo n.º 2
0
 public function verifyMagicEnv($text)
 {
     $magic_env = new MagicEnvelope();
     $env = $magic_env->parse($text);
     return $magic_env->verify($env);
 }