]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/FacebookBridge/actions/facebookdeauthorize.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / FacebookBridge / actions / facebookdeauthorize.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010-2011, StatusNet, Inc.
5  *
6  * An action that handles deauthorize callbacks from Facebook
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Plugin
24  * @package   StatusNet
25  * @author    Zach Copley <zach@status.net>
26  * @copyright 2010-2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /*
36  * Action class for handling deauthorize callbacks from Facebook. If the user
37  * doesn't have a password let her know she'll need to contact the site
38  * admin to get back into her account (if possible).
39  */
40 class FacebookdeauthorizeAction extends Action
41 {
42     private $facebook;
43
44     /**
45      * For initializing members of the class.
46      *
47      * @param array $args misc. arguments
48      *
49      * @return boolean true
50      */
51     function prepare($args)
52     {
53         $this->facebook = Facebookclient::getFacebook();
54
55         return true;
56     }
57
58     /**
59      * Handler method
60      *
61      * @param array $args is ignored since it's now passed in in prepare()
62      */
63     function handle($args)
64     {
65         parent::handle($args);
66
67         $data = $this->facebook->getSignedRequest();
68
69         if (isset($data['user_id'])) {
70
71             $fbuid = $data['user_id'];
72
73             $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
74             $user = $flink->getUser();
75
76             // Remove the link to Facebook
77             $result = $flink->delete();
78
79             if (!$result) {
80                 common_log_db_error($flink, 'DELETE', __FILE__);
81                 common_log(
82                     LOG_WARNING,
83                     sprintf(
84                         'Unable to delete Facebook foreign link '
85                             . 'for %s (%d), fbuid %d',
86                         $user->nickname,
87                         $user->id,
88                         $fbuid
89                     ),
90                     __FILE__
91                 );
92                 return;
93             }
94
95             common_log(
96                 LOG_INFO,
97                 sprintf(
98                     'Facebook callback: %s (%d), fbuid %d has deauthorized '
99                         . 'the Facebook application.',
100                     $user->nickname,
101                     $user->id,
102                     $fbuid
103                 ),
104                 __FILE__
105             );
106
107             // Warn the user about being locked out of their account
108             // if we can.
109             if (empty($user->password) && !empty($user->email)) {
110                 Facebookclient::emailWarn($user);
111             } else {
112                 common_log(
113                     LOG_WARNING,
114                     sprintf(
115                         '%s (%d), fbuid %d has deauthorized his/her Facebook '
116                         . 'connection but hasn\'t set a password so s/he '
117                         . 'is locked out.',
118                         $user->nickname,
119                         $user->id,
120                         $fbuid
121                     ),
122                     __FILE__
123                 );
124             }
125
126         } else {
127             if (!empty($data)) {
128                 common_log(
129                     LOG_WARNING,
130                     sprintf(
131                         'Facebook called the deauthorize callback '
132                         . ' but didn\'t provide a user ID.'
133                     ),
134                     __FILE__
135                 );
136             } else {
137                 // It probably wasn't Facebook that hit this action,
138                 // so redirect to the public timeline
139                 common_redirect(common_local_url('public'), 303);
140             }
141         }
142     }
143 }