summaryrefslogtreecommitdiff
path: root/plugins/OStatus/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/OStatus/scripts')
-rw-r--r--plugins/OStatus/scripts/fixup-shadow.php96
-rw-r--r--plugins/OStatus/scripts/resub-feed.php74
-rw-r--r--plugins/OStatus/scripts/testfeed.php89
-rw-r--r--plugins/OStatus/scripts/update-profile.php147
-rw-r--r--plugins/OStatus/scripts/updateostatus.php14
5 files changed, 415 insertions, 5 deletions
diff --git a/plugins/OStatus/scripts/fixup-shadow.php b/plugins/OStatus/scripts/fixup-shadow.php
new file mode 100644
index 000000000..6522ca240
--- /dev/null
+++ b/plugins/OStatus/scripts/fixup-shadow.php
@@ -0,0 +1,96 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010 StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$longoptions = array('dry-run');
+
+$helptext = <<<END_OF_USERROLE_HELP
+fixup_shadow.php [options]
+Patches up stray ostatus_profile entries with corrupted shadow entries
+for local users and groups.
+
+ --dry-run look but don't touch
+
+END_OF_USERROLE_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+$dry = have_option('dry-run');
+
+$oprofile = new Ostatus_profile();
+
+$marker = mt_rand(31337, 31337000);
+
+$profileTemplate = common_local_url('userbyid', array('id' => $marker));
+$encProfile = $oprofile->escape($profileTemplate, true);
+$encProfile = str_replace($marker, '%', $encProfile);
+
+$groupTemplate = common_local_url('groupbyid', array('id' => $marker));
+$encGroup = $oprofile->escape($groupTemplate, true);
+$encGroup = str_replace($marker, '%', $encGroup);
+
+$sql = "SELECT * FROM ostatus_profile WHERE uri LIKE '%s' OR uri LIKE '%s'";
+$oprofile->query(sprintf($sql, $encProfile, $encGroup));
+
+$count = $oprofile->N;
+echo "Found $count bogus ostatus_profile entries shadowing local users and groups:\n";
+
+while ($oprofile->fetch()) {
+ $uri = $oprofile->uri;
+ if (preg_match('!/group/(\d+)/id!', $oprofile->uri, $matches)) {
+ $id = intval($matches[1]);
+ $group = Local_group::staticGet('group_id', $id);
+ if ($group) {
+ $nick = $group->nickname;
+ } else {
+ $nick = '<deleted>';
+ }
+ echo "group $id ($nick) hidden by $uri";
+ } else if (preg_match('!/user/(\d+)!', $uri, $matches)) {
+ $id = intval($matches[1]);
+ $user = User::staticGet('id', $id);
+ if ($user) {
+ $nick = $user->nickname;
+ } else {
+ $nick = '<deleted>';
+ }
+ echo "user $id ($nick) hidden by $uri";
+ } else {
+ echo "$uri matched query, but we don't recognize it.\n";
+ continue;
+ }
+
+ if ($dry) {
+ echo " - skipping\n";
+ } else {
+ echo " - removing bogus ostatus_profile entry...";
+ $evil = clone($oprofile);
+ $evil->delete();
+ echo " ok\n";
+ }
+}
+
+if ($count && $dry) {
+ echo "NO CHANGES MADE -- To delete the bogus entries, run again without --dry-run option.\n";
+} else {
+ echo "done.\n";
+}
+
diff --git a/plugins/OStatus/scripts/resub-feed.php b/plugins/OStatus/scripts/resub-feed.php
new file mode 100644
index 000000000..121d12109
--- /dev/null
+++ b/plugins/OStatus/scripts/resub-feed.php
@@ -0,0 +1,74 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$helptext = <<<END_OF_HELP
+resub-feed.php [options] http://example.com/atom-feed-url
+Reinitialize the PuSH subscription for the given feed. This may help get
+things restarted if we and the hub have gotten our states out of sync.
+
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (empty($args[0]) || !Validate::uri($args[0])) {
+ print "$helptext";
+ exit(1);
+}
+
+$feedurl = $args[0];
+
+
+$sub = FeedSub::staticGet('topic', $feedurl);
+if (!$sub) {
+ print "Feed $feedurl is not subscribed.\n";
+ exit(1);
+}
+
+print "Old state:\n";
+showSub($sub);
+
+print "\n";
+print "Pinging hub $sub->huburi with new subscription for $sub->uri\n";
+$ok = $sub->subscribe();
+
+if ($ok) {
+ print "ok\n";
+} else {
+ print "Could not confirm.\n";
+}
+
+$sub2 = FeedSub::staticGet('topic', $feedurl);
+
+print "\n";
+print "New state:\n";
+showSub($sub2);
+
+function showSub($sub)
+{
+ print " Subscription state: $sub->sub_state\n";
+ print " Verify token: $sub->verify_token\n";
+ print " Signature secret: $sub->secret\n";
+ print " Sub start date: $sub->sub_start\n";
+ print " Record created: $sub->created\n";
+ print " Record modified: $sub->modified\n";
+}
diff --git a/plugins/OStatus/scripts/testfeed.php b/plugins/OStatus/scripts/testfeed.php
new file mode 100644
index 000000000..5e3ccd433
--- /dev/null
+++ b/plugins/OStatus/scripts/testfeed.php
@@ -0,0 +1,89 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$longoptions = array('skip=', 'count=');
+
+$helptext = <<<END_OF_HELP
+testfeed.php [options] http://example.com/atom-feed-url
+Pull an Atom feed and run items in it as though they were live PuSH updates.
+Mainly intended for testing funky feed formats.
+
+ --skip=N Ignore the first N items in the feed.
+ --count=N Only process up to N items from the feed, after skipping.
+
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (empty($args[0]) || !Validate::uri($args[0])) {
+ print "$helptext";
+ exit(1);
+}
+
+$feedurl = $args[0];
+$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
+$count = have_option('count') ? intval(get_option_value('count')) : 0;
+
+
+$sub = FeedSub::staticGet('topic', $feedurl);
+if (!$sub) {
+ print "Feed $feedurl is not subscribed.\n";
+ exit(1);
+}
+
+$xml = file_get_contents($feedurl);
+if ($xml === false) {
+ print "Bad fetch.\n";
+ exit(1);
+}
+
+$feed = new DOMDocument();
+if (!$feed->loadXML($xml)) {
+ print "Bad XML.\n";
+ exit(1);
+}
+
+if ($skip || $count) {
+ $entries = $feed->getElementsByTagNameNS(ActivityUtils::ATOM, 'entry');
+ $remove = array();
+ for ($i = 0; $i < $skip && $i < $entries->length; $i++) {
+ $item = $entries->item($i);
+ if ($item) {
+ $remove[] = $item;
+ }
+ }
+ if ($count) {
+ for ($i = $skip + $count; $i < $entries->length; $i++) {
+ $item = $entries->item($i);
+ if ($item) {
+ $remove[] = $item;
+ }
+ }
+ }
+ foreach ($remove as $item) {
+ $item->parentNode->removeChild($item);
+ }
+}
+
+Event::handle('StartFeedSubReceive', array($sub, $feed));
+
diff --git a/plugins/OStatus/scripts/update-profile.php b/plugins/OStatus/scripts/update-profile.php
new file mode 100644
index 000000000..d06de4f90
--- /dev/null
+++ b/plugins/OStatus/scripts/update-profile.php
@@ -0,0 +1,147 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$helptext = <<<END_OF_HELP
+update-profile.php [options] http://example.com/profile/url
+
+Rerun profile and feed info discovery for the given OStatus remote profile,
+and reinitialize its PuSH subscription for the given feed. This may help get
+things restarted if the hub or feed URLs have changed for the profile.
+
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (empty($args[0]) || !Validate::uri($args[0])) {
+ print "$helptext";
+ exit(1);
+}
+
+$uri = $args[0];
+
+
+$oprofile = Ostatus_profile::staticGet('uri', $uri);
+
+if (!$oprofile) {
+ print "No OStatus remote profile known for URI $uri\n";
+ exit(1);
+}
+
+print "Old profile state for $oprofile->uri\n";
+showProfile($oprofile);
+
+print "\n";
+print "Re-running feed discovery for profile URL $oprofile->uri\n";
+// @fixme will bork where the URI isn't the profile URL for now
+$discover = new FeedDiscovery();
+$feedurl = $discover->discoverFromURL($oprofile->uri);
+$huburi = $discover->getAtomLink('hub');
+$salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
+
+print " Feed URL: $feedurl\n";
+print " Hub URL: $huburi\n";
+print " Salmon URL: $salmonuri\n";
+
+if ($feedurl != $oprofile->feeduri || $salmonuri != $oprofile->salmonuri) {
+ print "\n";
+ print "Updating...\n";
+ // @fixme update keys :P
+ #$orig = clone($oprofile);
+ #$oprofile->feeduri = $feedurl;
+ #$oprofile->salmonuri = $salmonuri;
+ #$ok = $oprofile->update($orig);
+ $ok = $oprofile->query('UPDATE ostatus_profile SET ' .
+ 'feeduri=\'' . $oprofile->escape($feedurl) . '\',' .
+ 'salmonuri=\'' . $oprofile->escape($salmonuri) . '\' ' .
+ 'WHERE uri=\'' . $oprofile->escape($uri) . '\'');
+
+ if (!$ok) {
+ print "Failed to update profile record...\n";
+ exit(1);
+ }
+
+ $oprofile->decache();
+} else {
+ print "\n";
+ print "Ok, ostatus_profile record unchanged.\n\n";
+}
+
+$sub = FeedSub::ensureFeed($feedurl);
+
+if ($huburi != $sub->huburi) {
+ print "\n";
+ print "Updating hub record for feed; was $sub->huburi\n";
+ $orig = clone($sub);
+ $sub->huburi = $huburi;
+ $ok = $sub->update($orig);
+
+ if (!$ok) {
+ print "Failed to update sub record...\n";
+ exit(1);
+ }
+} else {
+ print "\n";
+ print "Feed record ok, not changing.\n\n";
+}
+
+print "\n";
+print "Pinging hub $sub->huburi with new subscription for $sub->uri\n";
+$ok = $sub->subscribe();
+
+if ($ok) {
+ print "ok\n";
+} else {
+ print "Could not confirm.\n";
+}
+
+$o2 = Ostatus_profile::staticGet('uri', $uri);
+
+print "\n";
+print "New profile state:\n";
+showProfile($o2);
+
+print "\n";
+print "New feed state:\n";
+$sub2 = FeedSub::ensureFeed($feedurl);
+showSub($sub2);
+
+function showProfile($oprofile)
+{
+ print " Feed URL: $oprofile->feeduri\n";
+ print " Salmon URL: $oprofile->salmonuri\n";
+ print " Avatar URL: $oprofile->avatar\n";
+ print " Profile ID: $oprofile->profile_id\n";
+ print " Group ID: $oprofile->group_id\n";
+ print " Record created: $oprofile->created\n";
+ print " Record modified: $oprofile->modified\n";
+}
+
+function showSub($sub)
+{
+ print " Subscription state: $sub->sub_state\n";
+ print " Verify token: $sub->verify_token\n";
+ print " Signature secret: $sub->secret\n";
+ print " Sub start date: $sub->sub_start\n";
+ print " Record created: $sub->created\n";
+ print " Record modified: $sub->modified\n";
+}
diff --git a/plugins/OStatus/scripts/updateostatus.php b/plugins/OStatus/scripts/updateostatus.php
index d553a7d62..622ded56a 100644
--- a/plugins/OStatus/scripts/updateostatus.php
+++ b/plugins/OStatus/scripts/updateostatus.php
@@ -56,7 +56,12 @@ try {
$user = new User();
if ($user->find()) {
while ($user->fetch()) {
- updateOStatus($user);
+ try {
+ updateOStatus($user);
+ } catch (Exception $e) {
+ common_log(LOG_NOTICE, "Couldn't convert OMB subscriptions ".
+ "for {$user->nickname} to OStatus: " . $e->getMessage());
+ }
}
}
} else {
@@ -98,7 +103,7 @@ function updateOStatus($user)
echo "Checking {$rp->nickname}...";
}
- $op = Ostatus_profile::ensureProfile($rp->profileurl);
+ $op = Ostatus_profile::ensureProfileURL($rp->profileurl);
if (empty($op)) {
echo "can't convert.\n";
@@ -107,8 +112,8 @@ function updateOStatus($user)
if (!have_option('q', 'quiet')) {
echo "Converting...";
}
- Subscription::cancel($up, $rp);
Subscription::start($up, $op->localProfile());
+ Subscription::cancel($up, $rp);
if (!have_option('q', 'quiet')) {
echo "done.\n";
}
@@ -118,8 +123,7 @@ function updateOStatus($user)
if (!have_option('q', 'quiet')) {
echo "fail.\n";
}
- continue;
- common_log(LOG_WARNING, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname .
+ common_log(LOG_NOTICE, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname .
") to OStatus: " . $e->getMessage());
continue;
}