resub-feed.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @package GNUsocial
  19. * @copyright 2010 StatusNet, Inc.
  20. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  21. */
  22. define('INSTALLDIR', dirname(__DIR__, 3));
  23. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  24. $longoptions = array('unsub');
  25. $shortoptions = 'u';
  26. $helptext = <<<END_OF_HELP
  27. resub-feed.php [options] http://example.com/atom-feed-url
  28. Reinitialize the WebSub subscription for the given feed. This may help get
  29. things restarted if we and the hub have gotten our states out of sync.
  30. Options:
  31. -u --unsub Unsubscribe instead of subscribing.
  32. END_OF_HELP;
  33. require_once INSTALLDIR.'/scripts/commandline.inc';
  34. $validate = new Validate();
  35. if (empty($args[0]) || !$validate->uri($args[0])) {
  36. print "$helptext";
  37. exit(1);
  38. }
  39. $feedurl = $args[0];
  40. $sub = FeedSub::getKV('uri', $feedurl);
  41. if (!$sub) {
  42. print "Feed $feedurl is not subscribed.\n";
  43. exit(1);
  44. }
  45. print "Old state:\n";
  46. showSub($sub);
  47. try {
  48. echo "\n";
  49. if (have_option('u') || have_option('--unsub')) {
  50. echo "Pinging hub {$sub->huburi} with unsubscription for {$sub->uri}\n";
  51. $sub->unsubscribe();
  52. } else {
  53. echo "Pinging hub {$sub->huburi} with new subscription for {$sub->uri}\n";
  54. $sub->subscribe();
  55. }
  56. echo "ok\n";
  57. } catch (Exception $e) {
  58. echo 'Could not confirm. '.get_class($e).': '.$e->getMessage()."\n";
  59. }
  60. $sub2 = FeedSub::getKV('uri', $feedurl);
  61. print "\n";
  62. print "New state:\n";
  63. showSub($sub2);
  64. function showSub($sub)
  65. {
  66. print " Subscription state: $sub->sub_state\n";
  67. print " Signature secret: $sub->secret\n";
  68. print " Sub start date: $sub->sub_start\n";
  69. print " Sub end date: $sub->sub_end\n";
  70. print " Sub lease remaining: {$sub->getLeaseRemaining()}\n";
  71. print " Record created: $sub->created\n";
  72. print " Record modified: $sub->modified\n";
  73. }