diff --git a/action.php b/action.php
--- a/action.php
+++ b/action.php
@@ -1,113 +1,113 @@
getConf("g2fa_enable");
if($enable===1) {
$controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'two_fa_login_form', array());
$controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'AFTER', $this, 'handle_profile_form', array());
}
}
/**
* Handles the login form rendering.
*/
function two_fa_login_form(&$event, $param) {
global $conf;
// Show login form above submit button (and above remember me option, if enabled)
$pos = $event->data->findElementByAttribute('type', 'submit');
if($conf["rememberme"])
$pos = $pos-1;
$event->data->insertElement($pos, form_makePasswordField('t', $this->getLang('g2fa'), '', 'block'));
}
function handle_profile_form(&$event, $param) {
global $ID;
global $INPUT;
$fn = $INPUT->param('fn');
if(is_array($fn)) {
$cmd = key($fn);
$param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null;
} else {
$cmd = $fn;
$param = null;
}
$th = new TokenHelper();
$secret = $th->getSecret($_SERVER['REMOTE_USER']);
$form = new Doku_Form($ID);
$form->startFieldset($this->getLang('g2fa_fieldset'));
$form->addHidden('do', 'profile');
$form->addHidden('g2fa', '1');
$reveal = false;
switch($cmd) {
case "gensecret" :
if($th->createTokenForUser($_SERVER['REMOTE_USER'])) {
msg($this->getLang('g2fa_created'));
$secret = $th->getSecret($_SERVER['REMOTE_USER']);
}
break;
case "update":
if($INPUT->param('secret') == "********")
{
msg($this->getLang('g2fa_notchanged'));
break;
}
if($th->saveToken($_SERVER['REMOTE_USER'], $INPUT->param('secret')))
msg($this->getLang('g2fa_updated'));
else
msg($this->getLang('g2fa_notchanged'));
$secret = $th->getSecret($_SERVER['REMOTE_USER']);
break;
case "showqr" :
if($secret != '') {
$ga = new PHPGangsta_GoogleAuthenticator();
- $url = $ga->getQRCodeGoogleUrl('DokuWiki for '.$_SERVER['REMOTE_USER'], $secret);
+ $url = $ga->getQRCodeGoogleUrl(urlencode('DokuWiki:'.$_SERVER['REMOTE_USER']), $secret);
$form->addElement(form_makeTag('img', array('src' => $url, 'alt' => 'Google 2FA QR Image')));
$form->addElement(form_makeTag('br'));
$reveal = true;
}
break;
case "delsecret" :
if($th->deleteTokenForUser($_SERVER['REMOTE_USER'])) {
msg($this->getLang('g2fa_removed'));
$secret = '';
}
break;
}
if($reveal) {
$form->addElement(form_makeTextField('secret', $secret, $this->getLang('secret'), '', 'block', array('size'=>'50')));
} else {
$form->addElement(form_makeTextField('secret', '********', $this->getLang('secret'), '', 'block', array('size'=>'50')));
}
$form->addElement(form_makeButton('submit', '', $this->getLang('showqr'), array('name' => 'fn[showqr]', 'disabled' => $secret == '' ? 'disabled' : '')));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeButton('submit', '', $this->getLang('generate'), array('name' => 'fn[gensecret]')));
$form->addElement(form_makeButton('submit', '', $this->getLang('update'), array('name' => 'fn[update]')));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeButton('submit', '', $this->getLang('delete'), array('name' => 'fn[delsecret]', 'disabled' => $secret == '' ? 'disabled' : '' )));
$form->endFieldset();
html_form('g2fa', $form);
}
}
?>
diff --git a/admin.php b/admin.php
--- a/admin.php
+++ b/admin.php
@@ -1,239 +1,239 @@
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
require_once(dirname(__FILE__).'/GoogleAuthenticator.php');
require_once(dirname(__FILE__).'/TokenHelper.php');
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
*/
class admin_plugin_authg2fa extends DokuWiki_Admin_Plugin {
protected $_auth = null;
protected $_tokens = array();
protected $_start = 0;
protected $_pagesize = 20;
protected $_filter = array();
protected $_disabled = "";
protected $_user_total = 0;
protected $_tokenHelper = null;
protected $_unhide = "";
/**
* Constructor
*/
public function admin_plugin_authg2fa() {
/** @var DokuWiki_Auth_Plugin $auth */
global $auth;
$this->setupLocale();
if (!isset($auth)) {
return;
//$this->_disabled = $this->lang['noauth'];
} else if (!$auth->canDo('getUsers')) {
return;
//$this->_disabled = $this->lang['nosupport'];
} else {
// we're good to go
$this->_auth = & $auth;
}
$this->_tokenHelper = new TokenHelper();
$this->_tokens = $this->_tokenHelper->getTokens();
}
public function handle() {
global $INPUT;
if(is_null($this->_auth)) return false;
if(!isset($_REQUEST['fn']) || !checkSecurityToken()) return;
// extract the command and any specific parameters
// submit button name is of the form - fn[cmd][param(s)]
$fn = $INPUT->param('fn');
if (is_array($fn)) {
$cmd = key($fn);
$param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null;
} else {
$cmd = $fn;
$param = null;
}
if ($cmd != "search") {
$this->_start = $INPUT->int('start', 0);
$this->_filter = $this->_retrieveFilter();
}
switch($cmd) {
case "csecret" : $this->_tokenHelper->createTokenForUser($param); $this->_tokens = $this->_tokenHelper->getTokens(); break;
case "nsecret" : $this->_createTokenForAllUsers(); break;
case "dsecret" : $this->_tokenHelper->deleteTokenForUser($param); $this->_tokens = $this->_tokenHelper->getTokens(); break;
case "ssecret" : $this->_unhide = $param; break;
}
$this->_user_total = $this->_auth->canDo('getUserCount') ? $this->_auth->getUserCount($this->_filter) : -1;
// page handling
switch($cmd){
case 'start' : $this->_start = 0; break;
case 'prev' : $this->_start -= $this->_pagesize; break;
case 'next' : $this->_start += $this->_pagesize; break;
case 'last' : $this->_start = $this->_user_total; break;
}
$this->_validatePagination();
return true;
}
public function html() {
global $ID;
$user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter);
$page_buttons = $this->_pagination();
if($this->_unhide != "")
{
if(isset($this->_tokens[$this->_unhide])) {
$ga = new PHPGangsta_GoogleAuthenticator();
- $url = $ga->getQRCodeGoogleUrl('DokuWiki for '.$this->_unhide, $this->_tokens[$this->_unhide]);
+ $url = $ga->getQRCodeGoogleUrl(urlencode('DokuWiki:'.$this->_unhide), $this->_tokens[$this->_unhide]);
ptln('Showing QR Code for user '.$this->_unhide.':
');
ptln('
');
}
}
ptln("