]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/scripts/rm_bad_feedsubs.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / OStatus / scripts / rm_bad_feedsubs.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2010 StatusNet, Inc.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 /* 
22  *  Run this from INSTALLDIR/plugins/OStatus/scripts
23  */
24
25 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
26
27
28 $shortoptions = 'd';
29 $longoptions = array('dry-run');
30
31 $helptext = <<<END_OF_HELP
32 rm_bad_feedsubs.php [options]
33 Deletes feedsub records that are in the inconsistent state of "subscribe"
34 and are older than one hour. If the hub hasn't answered back in an hour
35 the hub is probably either broken or doesn't exist.'
36
37       Options:
38
39     -d --dry-run look but don't mess with it
40
41
42 END_OF_HELP;
43
44 require_once INSTALLDIR . '/scripts/commandline.inc';
45
46 $dry = false;
47
48 if (have_option('d') || have_option('dry-run')) {
49     $dry = true;
50 }
51
52 echo "Looking for feed subscriptions with dirty no good huburis...\n";
53
54 $feedsub = new FeedSub();
55 $feedsub->sub_state = 'subscribe';
56 $feedsub->whereAdd('created < DATE_SUB(NOW(), INTERVAL 1 HOUR)');
57 $feedsub->find();
58 $cnt = 0;
59
60 while ($feedsub->fetch()) {
61     echo "----------------------------------------------------------------------------------------\n";
62     echo  '           feed: '
63         . $feedsub->uri . "\n"
64         . '        hub uri: '
65         . $feedsub->huburi ."\n"
66         . ' subscribe date: '
67         . date('r', strtotime($feedsub->created)) . "\n";
68
69     if (!$dry) {
70         $feedsub->delete();
71         echo "                 (DELETED)\n";
72     } else {
73         echo "                 (WOULD BE DELETED)\n";
74     }
75     echo "----------------------------------------------------------------------------------------\n";
76     $cnt++;
77 }
78 if ($cnt == 0) {
79     echo "None found.\n";
80 } else {
81     echo "Deleted $cnt bogus hub URIs.\n";
82 }
83 echo "Done.\n";