]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/updateurls.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / scripts / updateurls.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2008-2011, 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 $shortoptions = '';
24 $longoptions = array();
25
26 $helptext = <<<END_OF_UPDATEURLS_HELP
27 updateurls.php [options]
28 update stored URLs in the system
29
30 END_OF_UPDATEURLS_HELP;
31
32 require_once INSTALLDIR.'/scripts/commandline.inc';
33
34 function main()
35 {
36     updateUserUrls();
37     updateGroupUrls();
38 }
39
40 function updateUserUrls()
41 {
42     printfnq("Updating user URLs...\n");
43
44     // XXX: only update user URLs where out-of-date
45
46     $user = new User();
47     if ($user->find()) {
48         while ($user->fetch()) {
49             printfv("Updating user {$user->nickname}...");
50             try {
51                 $profile = $user->getProfile();
52
53                 updateProfileUrl($profile);
54                 updateAvatarUrls($profile);
55             } catch (Exception $e) {
56                 echo "Error updating URLs: " . $e->getMessage();
57             }
58             printfv("DONE.");
59         }
60     }
61 }
62
63 function updateProfileUrl($profile)
64 {
65     $orig = clone($profile);
66     $profile->profileurl = common_profile_url($profile->nickname);
67     $profile->update($orig);
68 }
69
70 function updateAvatarUrls($profile)
71 {
72     $avatar = new Avatar();
73
74     $avatar->profile_id = $profile->id;
75     if ($avatar->find()) {
76         while ($avatar->fetch()) {
77             $orig_url = $avatar->url;
78             $avatar->url = Avatar::url($avatar->filename);
79             if ($avatar->url != $orig_url) {
80                 $sql =
81                   "UPDATE avatar SET url = '" . $avatar->url . "' ".
82                   "WHERE profile_id = " . $avatar->profile_id . " ".
83                   "AND width = " . $avatar->width . " " .
84                   "AND height = " . $avatar->height . " ";
85
86                 if ($avatar->original) {
87                     $sql .= "AND original = 1 ";
88                 }
89
90                 if (!$avatar->query($sql)) {
91                     throw new Exception("Can't update avatar for user " . $profile->nickname . ".");
92                 } else {
93                     $touched = true;
94                 }
95             }
96         }
97     }
98 }
99
100 function updateGroupUrls()
101 {
102     printfnq("Updating group URLs...\n");
103
104     $group = new User_group();
105
106     if ($group->find()) {
107         while ($group->fetch()) {
108             try {
109                 printfv("Updating group {$group->nickname}...");
110                 $orig = User_group::getKV('id', $group->id);
111                 if (!empty($group->original_logo)) {
112                     $group->original_logo = Avatar::url(basename($group->original_logo));
113                     $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
114                     $group->stream_logo = Avatar::url(basename($group->stream_logo));
115                     $group->mini_logo = Avatar::url(basename($group->mini_logo));
116                 }
117                 // XXX: this is a hack to see if a group is local or not
118                 $localUri = common_local_url('groupbyid',
119                                              array('id' => $group->id));
120                 if ($group->getUri() != $localUri) {
121                     $group->mainpage = common_local_url('showgroup',
122                                                         array('nickname' => $group->nickname));
123                 }
124                 $group->update($orig);
125                 printfv("DONE.");
126             } catch (Exception $e) {
127                 echo "Can't update avatars for group " . $group->nickname . ": ". $e->getMessage();
128             }
129         }
130     }
131 }
132
133 main();