]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/allsites.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / scripts / allsites.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - the distributed open-source microblogging tool
5  * Copyright (C) 2009, 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 // Abort if called from a web server
22
23 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
24
25 $shortoptions = 't:w:';
26 $longoptions = array('tagged=', 'not-tagged=');
27
28 $helptext = <<<ENDOFHELP
29 allsites.php - list all sites configured for multi-site use
30 USAGE: allsites.php [OPTIONS]
31
32 -t --tagged=tagname  List only sites with this tag
33 -w --not-tagged=tagname List only sites without this tag
34
35 ENDOFHELP;
36
37 require_once INSTALLDIR.'/scripts/commandline.inc';
38
39 function print_all_sites() {
40
41     $sn = new Status_network();
42
43     if ($sn->find()) {
44         while ($sn->fetch()) {
45             print "$sn->nickname\n";
46         }
47     }
48     return;
49 }
50
51 function print_tagged_sites($tag) {
52
53     $sn = new Status_network();
54
55     $sn->query('select status_network.nickname '.
56                'from status_network join status_network_tag '.
57                'on status_network.site_id = status_network_tag.site_id '.
58                'where status_network_tag.tag = "' . $tag . '"');
59
60     while ($sn->fetch()) {
61         print "$sn->nickname\n";
62     }
63
64     return;
65 }
66
67 function print_untagged_sites($tag) {
68
69     $sn = new Status_network();
70
71     $sn->query('select status_network.nickname '.
72                'from status_network '.
73                'where not exists '.
74                '(select tag from status_network_tag '.
75                'where site_id = status_network.site_id '.
76                'and tag = "'.$tag.'")');
77
78     while ($sn->fetch()) {
79         print "$sn->nickname\n";
80     }
81
82     return;
83 }
84
85 if (have_option('t', 'tagged')) {
86     $tag = get_option_value('t', 'tagged');
87     print_tagged_sites($tag);
88 } else if (have_option('w', 'not-tagged')) {
89     $tag = get_option_value('w', 'not-tagged');
90     print_untagged_sites($tag);
91 } else {
92     print_all_sites();
93 }