]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/CasAuthenticationPlugin.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / CasAuthentication / CasAuthenticationPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to enable Single Sign On via CAS (Central Authentication Service)
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Craig Andrews <candrews@integralblue.com>
25  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 // We bundle the phpCAS library...
35 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/CAS');
36
37 class CasAuthenticationPlugin extends AuthenticationPlugin
38 {
39     public $server;
40     public $port = 443;
41     public $path = '';
42     public $takeOverLogin = false;
43
44     function checkPassword($username, $password)
45     {
46         global $casTempPassword;
47         return ($casTempPassword == $password);
48     }
49
50     function onAutoload($cls)
51     {
52         switch ($cls)
53         {
54          case 'phpCAS':
55             require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
56             return false;
57         }
58
59         // if it's not our exception, try standard places
60         return parent::onAutoload($cls);
61     }
62
63     function onArgsInitialize(&$args)
64     {
65         if($this->takeOverLogin && $args['action'] == 'login')
66         {
67             $args['action'] = 'caslogin';
68         }
69     }
70
71     function onStartInitializeRouter($m)
72     {
73         $m->connect('main/cas', array('action' => 'caslogin'));
74         return true;
75     }
76
77     function onEndLoginGroupNav($action)
78     {
79         $action_name = $action->trimmed('action');
80
81         $action->menuItem(common_local_url('caslogin'),
82                           // TRANS: Menu item. CAS is Central Authentication Service.
83                           _m('CAS'),
84                           // TRANS: Tooltip for menu item. CAS is Central Authentication Service.
85                           _m('Login or register with CAS.'),
86                           $action_name === 'caslogin');
87
88         return true;
89     }
90
91     function onEndShowPageNotice($action)
92     {
93         $name = $action->trimmed('action');
94
95         switch ($name)
96         {
97          case 'login':
98             // TRANS: Invitation to users with a CAS account to log in using the service.
99             // TRANS: "[CAS login]" is a link description. (%%action.caslogin%%) is the URL.
100             // TRANS: These two elements may not be separated.
101             $instr = _m('(Have an account with CAS? ' .
102               'Try our [CAS login](%%action.caslogin%%)!)');
103             break;
104          default:
105             return true;
106         }
107
108         $output = common_markup_to_html($instr);
109         $action->raw($output);
110         return true;
111     }
112
113     function onLoginAction($action, &$login)
114     {
115         switch ($action)
116         {
117          case 'caslogin':
118             $login = true;
119             return false;
120          default:
121             return true;
122         }
123     }
124
125     function onInitializePlugin(){
126         parent::onInitializePlugin();
127         if(!isset($this->server)){
128             // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
129             throw new Exception(_m("Specifying a server is required."));
130         }
131         if(!isset($this->port)){
132             // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
133             throw new Exception(_m("Specifying a port is required."));
134         }
135         if(!isset($this->path)){
136             // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
137             throw new Exception(_m("Specifying a path is required."));
138         }
139         //These values need to be accessible to a action object
140         //I can't think of any other way than global variables
141         //to allow the action instance to be able to see values :-(
142         global $casSettings;
143         $casSettings = array();
144         $casSettings['server']=$this->server;
145         $casSettings['port']=$this->port;
146         $casSettings['path']=$this->path;
147         $casSettings['takeOverLogin']=$this->takeOverLogin;
148     }
149
150     function onPluginVersion(array &$versions)
151     {
152         $versions[] = array('name' => 'CAS Authentication',
153                             'version' => GNUSOCIAL_VERSION,
154                             'author' => 'Craig Andrews',
155                             'homepage' => 'http://status.net/wiki/Plugin:CasAuthentication',
156                             // TRANS: Plugin description. CAS is Central Authentication Service.
157                             'rawdescription' => _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));
158         return true;
159     }
160 }