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; }
function handle($data) { assert(is_array($data)); assert(is_string($data['salmonuri'])); assert(is_string($data['entry'])); $actor = Profile::staticGet($data['actor']); $salmon = new Salmon(); $salmon->post($data['salmonuri'], $data['entry'], $actor); // @fixme detect failure and attempt to resend return true; }
function handle($data) { assert(is_array($data)); assert(is_string($data['salmonuri'])); assert(is_string($data['entry'])); $actor = Profile::getKV($data['actor']); Salmon::post($data['salmonuri'], $data['entry'], $actor->getUser()); // @fixme detect failure and attempt to resend return true; }
function handle($data) { assert(is_array($data)); assert(is_string($data['salmonuri'])); assert(is_string($data['entry'])); $actor = Profile::getKV($data['actor']); $target = array_key_exists('target', $data) ? Profile::getKV($data['target']) : null; Salmon::post($data['salmonuri'], $data['entry'], $actor, $target); // @fixme detect failure and attempt to resend return true; }
/** * Send a Salmon notification ping immediately, and confirm that we got * an acceptable response from the remote site. * * @param mixed $entry XML string, Notice, or Activity * @param Profile $actor * @return boolean success */ public function notifyActivity($entry, Profile $actor) { if ($this->salmonuri) { return Salmon::post($this->salmonuri, $this->notifyPrepXml($entry), $actor, $this->localProfile()); } common_debug(__CLASS__ . ' error: No salmonuri for Ostatus_profile uri: ' . $this->uri); return false; }
print "\n\n"; echo "== Testing local verification ==\n\n"; $magic_env = new MagicEnvelope($envxml); $activity = new Activity($magic_env->getPayload()->documentElement); $actprofile = Profile::fromUri($activity->actor->id); $ok = $magic_env->verify($actprofile); if ($ok) { print "OK\n\n"; } else { print "FAIL\n\n"; } if (have_option('--verify')) { $url = 'http://www.madebymonsieur.com/ostatus_discovery/magic_env/validate/'; echo "== Testing remote verification ==\n\n"; print "Sending for verification to {$url} ...\n"; $client = new HTTPClient(); $response = $client->post($url, array(), array('magic_env' => $envxml)); print $response->getStatus() . "\n\n"; print $response->getBody() . "\n\n"; } if (have_option('--slap')) { $url = get_option_value('--slap'); echo "== Remote salmon slap ==\n\n"; print "Sending signed Salmon slap to {$url} ...\n"; $ok = Salmon::post($url, $entry, $profile->getUser()); if ($ok) { print "OK\n\n"; } else { print "FAIL\n\n"; } }
/** * Send a Salmon notification ping immediately, and confirm that we got * an acceptable response from the remote site. * * @param mixed $entry XML string, Notice, or Activity * @param Profile $actor * @return boolean success */ public function notifyActivity($entry, $actor) { if ($this->salmonuri) { $salmon = new Salmon(); return $salmon->post($this->salmonuri, $this->notifyPrepXml($entry), $actor); } return false; }
END_OF_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; if (!have_option('--notice')) { print "{$helptext}"; exit(1); } $notice_id = get_option_value('--notice'); $notice = Notice::staticGet('id', $notice_id); $profile = $notice->getProfile(); $entry = $notice->asAtomEntry(true); echo "== Original entry ==\n\n"; print $entry; print "\n\n"; $salmon = new Salmon(); $envelope = $salmon->createMagicEnv($entry, $profile); echo "== Signed envelope ==\n\n"; print $envelope; print "\n\n"; echo "== Testing local verification ==\n\n"; $ok = $salmon->verifyMagicEnv($envelope); if ($ok) { print "OK\n\n"; } else { print "FAIL\n\n"; } if (have_option('--verify')) { $url = 'http://www.madebymonsieur.com/ostatus_discovery/magic_env/validate/'; echo "== Testing remote verification ==\n\n"; print "Sending for verification to {$url} ...\n";