4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2010, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
23 $longoptions = array('verify', 'slap=', 'notice=');
25 $helptext = <<<END_OF_HELP
28 Test generation and sending of magic envelopes for Salmon slaps.
30 --notice=N generate entry for this notice number
31 --verify send signed magic envelope to Tuomas Koski's test service
32 --slap=<url> send signed Salmon slap to the destination endpoint
37 require_once INSTALLDIR.'/scripts/commandline.inc';
39 if (!have_option('--notice')) {
44 $notice_id = get_option_value('--notice');
46 $notice = Notice::getKV('id', $notice_id);
47 $profile = $notice->getProfile();
48 $entry = $notice->asAtomEntry(true);
50 echo "== Original entry ==\n\n";
54 $magic_env = MagicEnvelope::signAsUser($entry, $profile->getUser());
55 $envxml = $magic_env->toXML();
57 echo "== Signed envelope ==\n\n";
61 echo "== Testing local verification ==\n\n";
62 $magic_env = new MagicEnvelope($envxml);
63 $activity = new Activity($magic_env->getPayload()->documentElement);
64 $actprofile = Profile::fromUri($activity->actor->id);
65 $ok = $magic_env->verify($actprofile);
72 if (have_option('--verify')) {
73 $url = 'http://www.madebymonsieur.com/ostatus_discovery/magic_env/validate/';
74 echo "== Testing remote verification ==\n\n";
75 print "Sending for verification to $url ...\n";
77 $client = new HTTPClient();
79 $response = $client->post($url, array(), array('magic_env' => $envxml));
81 print $response->getStatus() . "\n\n";
82 print $response->getBody() . "\n\n";
83 } catch (NoHttpResponseException $e) {
84 print 'Failed POST to URL '.var_export($url, true).': '.$e->getMessage();
88 if (have_option('--slap')) {
89 $url = get_option_value('--slap');
90 echo "== Remote salmon slap ==\n\n";
91 print "Sending signed Salmon slap to $url ...\n";
93 $ok = Salmon::post($url, $entry, $profile->getUser());