]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/actions/ostatustag.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / OStatus / actions / ostatustag.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * @package OStatusPlugin
22  * @maintainer James Walker <james@status.net>
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
26
27
28 class OStatusTagAction extends OStatusInitAction
29 {
30     var $nickname;
31     var $profile;
32     var $err;
33
34     function prepare($args)
35     {
36         parent::prepare($args);
37
38         if (common_logged_in()) {
39             // TRANS: Client error displayed when trying to list a local object as if it is remote.
40             $this->clientError(_m('You can use the local list functionality!'));
41         }
42
43         $this->nickname = $this->trimmed('nickname');
44
45         // Webfinger or profile URL of the remote user
46         $this->profile = $this->trimmed('profile');
47
48         return true;
49     }
50
51     function showContent()
52     {
53         // TRANS: Header for listing a remote object. %s is a remote object's name.
54         $header = sprintf(_m('List %s'), $this->nickname);
55         // TRANS: Button text to list a remote object.
56         $submit = _m('BUTTON','Go');
57         $this->elementStart('form', array('id' => 'form_ostatus_connect',
58                                           'method' => 'post',
59                                           'class' => 'form_settings',
60                                           'action' => common_local_url('ostatustag')));
61         $this->elementStart('fieldset');
62         $this->element('legend', null,  $header);
63         $this->hidden('token', common_session_token());
64
65         $this->elementStart('ul', 'form_data');
66         $this->elementStart('li', array('id' => 'ostatus_nickname'));
67         // TRANS: Field label.
68         $this->input('nickname', _m('User nickname'), $this->nickname,
69                      // TRANS: Field title.
70                      _m('Nickname of the user you want to list.'));
71         $this->elementEnd('li');
72         $this->elementStart('li', array('id' => 'ostatus_profile'));
73         // TRANS: Field label.
74         $this->input('profile', _m('Profile Account'), $this->profile,
75                      // TRANS: Field title.
76                      _m('Your account id (for example user@example.com).'));
77         $this->elementEnd('li');
78         $this->elementEnd('ul');
79         $this->submit('submit', $submit);
80         $this->elementEnd('fieldset');
81         $this->elementEnd('form');
82     }
83
84     function connectWebfinger($acct)
85     {
86         $target_profile = $this->targetProfile();
87
88         $disco = new Discovery;
89         $xrd = $disco->lookup($acct);
90
91         $link = $xrd->get('http://ostatus.org/schema/1.0/tag');
92         if (!is_null($link)) {
93             // We found a URL - let's redirect!
94             if (!empty($link->template)) {
95                 $url = Discovery::applyTemplate($link->template, $target_profile);
96             } else {
97                 $url = $link->href;
98             }
99             common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
100             common_redirect($url, 303);
101         }
102         // TRANS: Client error displayed when remote profile address could not be confirmed.
103         $this->clientError(_m('Could not confirm remote profile address.'));
104     }
105
106     function connectProfile($subscriber_profile)
107     {
108         $target_profile = $this->targetProfile();
109
110         // @fixme hack hack! We should look up the remote sub URL from XRDS
111         $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/tagprofile', $subscriber_profile);
112         $suburl .= '?uri=' . urlencode($target_profile);
113
114         common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl");
115         common_redirect($suburl, 303);
116     }
117
118     function title()
119     {
120       // TRANS: Title for an OStatus list.
121       return _m('OStatus list');  
122     }
123 }