*/
/**
* Copyright (C) 2012 Iain Hallam, Andreas Gohr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_ssocas extends DokuWiki_Action_Plugin {
function getInfo() {
return array (
'author' => 'Iain Hallam',
'email' => 'iain@nineworlds.net',
'date' => '2012-06-16',
'name' => 'SSO CAS Plugin',
'desc' => 'Authenticate DokuWiki users via CAS',
'url' => 'http://www.dokuwiki.org/plugin:ssocas',
);
}
function register (&$controller) {
if ($this->getConf('server') != '') {
$controller->register_hook ('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_login_form');
$controller->register_hook ('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action');
$controller->register_hook ('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'handle_template');
}
}
function _self () {
global $ID;
return wl($ID, '', true, '');
}
function _selfdo ($do) {
global $ID;
return wl($ID, 'do=' . $do, true, '&');
}
function _redirect ($url) {
header ('Location: ' . $url);
exit;
}
// Log function copied from Andreas Gohr's loglog plugin
function _log ($msg) {
global $conf;
$t = time();
$log = $t."\t".strftime($conf['dformat'],$t)."\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REMOTE_USER']."\t".$msg;
io_saveFile($conf['cachedir'].'/ssocas.log',"$log\n",true);
}
function handle_login_form (&$event, $param) {
global $auth;
global $conf;
global $lang;
global $ID;
// Remove the register and resendpwd links, if they exist.
for ($formPosition = 0; $formPosition < count($event->data->_content); $formPosition++) {
$formElement = $event->data->getElementAt($formPosition);
if ((! is_array($formElement)) and (substr($formElement, 0, 2) == '