]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpenID/actions/openidtrust.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / OpenID / actions / openidtrust.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, 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 if (!defined('STATUSNET')) {
21     exit(1);
22 }
23
24 require_once INSTALLDIR.'/plugins/OpenID/openid.php';
25
26 class OpenidtrustAction extends Action
27 {
28     var $trust_root;
29     var $allowUrl;
30     var $denyUrl;
31     var $user;
32
33     /**
34      * Is this a read-only action?
35      *
36      * @return boolean false
37      */
38     function isReadOnly($args)
39     {
40         return false;
41     }
42
43     /**
44      * Title of the page
45      *
46      * @return string title of the page
47      */
48     function title()
49     {
50         // TRANS: Title for identity verification page.
51         return _m('OpenID Identity Verification');
52     }
53
54     function prepare($args)
55     {
56         parent::prepare($args);
57         common_ensure_session();
58         $this->user = common_current_user();
59         if(empty($this->user)){
60             /* Go log in, and then come back. */
61             common_set_returnto($_SERVER['REQUEST_URI']);
62             common_redirect(common_local_url('login'));
63         }
64         $this->trust_root = $_SESSION['openid_trust_root'];
65         $this->allowUrl = $_SESSION['openid_allow_url'];
66         $this->denyUrl = $_SESSION['openid_deny_url'];
67         if(empty($this->trust_root) || empty($this->allowUrl) || empty($this->denyUrl)){
68             // TRANS: Client error when visiting page directly.
69             $this->clientError(_m('This page should only be reached during OpenID processing, not directly.'));
70         }
71         return true;
72     }
73
74     function handle($args)
75     {
76         parent::handle($args);
77         if($_SERVER['REQUEST_METHOD'] == 'POST'){
78             $this->handleSubmit();
79         }else{
80             $this->showPage();
81         }
82     }
83
84     function handleSubmit()
85     {
86         global $_PEAR;
87
88         unset($_SESSION['openid_trust_root']);
89         unset($_SESSION['openid_allow_url']);
90         unset($_SESSION['openid_deny_url']);
91         if($this->arg('allow'))
92         {
93             //save to database
94             $user_openid_trustroot = new User_openid_trustroot();
95             $user_openid_trustroot->user_id = $this->user->id;
96             $user_openid_trustroot->trustroot = $this->trust_root;
97             $user_openid_trustroot->created = common_sql_now();
98             if (!$user_openid_trustroot->insert()) {
99                 $err = &$_PEAR->getStaticProperty('DB_DataObject','lastError');
100             }
101             common_redirect($this->allowUrl, $code=302);
102         }else{
103             common_redirect($this->denyUrl, $code=302);
104         }
105     }
106
107     /**
108      * Show page notice
109      *
110      * Display a notice for how to use the page, or the
111      * error if it exists.
112      *
113      * @return void
114      */
115     function showPageNotice()
116     {
117         // TRANS: Page notice. %s is a trustroot name.
118         $this->element('p',null,sprintf(_m('%s has asked to verify your identity. Click Continue to verify your identity and login without creating a new password.'),$this->trust_root));
119     }
120
121     /**
122      * Core of the display code
123      *
124      * Shows the login form.
125      *
126      * @return void
127      */
128     function showContent()
129     {
130         $this->elementStart('form', array('method' => 'post',
131                                    'id' => 'form_openidtrust',
132                                    'class' => 'form_settings',
133                                    'action' => common_local_url('openidtrust')));
134         $this->elementStart('fieldset');
135         // TRANS: Button text to continue OpenID identity verification.
136         $this->submit('allow', _m('BUTTON','Continue'));
137         // TRANS: Button text to cancel OpenID identity verification.
138         $this->submit('deny', _m('BUTTON','Cancel'));
139
140         $this->elementEnd('fieldset');
141         $this->elementEnd('form');
142     }
143 }