]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/scripts/fixup-shadow.php
OStatus: reject attempts to create a remote profile for a local user or group.
[quix0rs-gnu-social.git] / plugins / OStatus / scripts / fixup-shadow.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 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
22
23 $longoptions = array('dry-run');
24
25 $helptext = <<<END_OF_USERROLE_HELP
26 fixup_shadow.php [options]
27 Patches up stray ostatus_profile entries with corrupted shadow entries
28 for local users and groups.
29
30      --dry-run  look but don't touch
31
32 END_OF_USERROLE_HELP;
33
34 require_once INSTALLDIR.'/scripts/commandline.inc';
35
36 $dry = have_option('dry-run');
37
38 $oprofile = new Ostatus_profile();
39
40 $marker = mt_rand(31337, 31337000);
41
42 $profileTemplate = common_local_url('userbyid', array('id' => $marker));
43 $encProfile = $oprofile->escape($profileTemplate, true);
44 $encProfile = str_replace($marker, '%', $encProfile);
45
46 $groupTemplate = common_local_url('groupbyid', array('id' => $marker));
47 $encGroup = $oprofile->escape($groupTemplate, true);
48 $encGroup = str_replace($marker, '%', $encGroup);
49
50 $sql = "SELECT * FROM ostatus_profile WHERE uri LIKE '%s' OR uri LIKE '%s'";
51 $oprofile->query(sprintf($sql, $encProfile, $encGroup));
52
53 echo "Found $oprofile->N bogus ostatus_profile entries:\n";
54
55 while ($oprofile->fetch()) {
56     echo "$oprofile->uri";
57
58     if ($dry) {
59         echo " (unchanged)\n";
60     } else {
61         echo " deleting...";
62         $evil = clone($oprofile);
63         $evil->delete();
64         echo "  ok\n";
65     }
66 }
67
68 echo "done.\n";
69