*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_TWOFACTOR_PLUGIN_IMAGES')) define('DOKU_TWOFACTOR_PLUGIN_IMAGES',DOKU_BASE.'lib/plugins/twofactor/images/');
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
*/
class admin_plugin_twofactor extends DokuWiki_Admin_Plugin {
protected $_auth = null; // auth object
protected $_user_list = array(); // number of users with attributes
protected $_filter = array(); // user selection filter(s)
protected $_start = 0; // index of first user to be displayed
protected $_last = 0; // index of the last user to be displayed
protected $_pagesize = 20; // number of users to list on one page
protected $_disabled = ''; // if disabled set to explanatory string
protected $_lastdisabled = false; // set to true if last user is unknown and last button is hence buggy
/**
* Constructor
*/
public function __construct(){
global $auth;
if (!isset($auth)) {
$this->_disabled = $this->lang['noauth'];
} else if (!$auth->canDo('getUsers')) {
$this->_disabled = $this->lang['nosupport'];
} else {
// we're good to go
$this->_auth = & $auth;
}
$this->setupLocale();
$requireAttribute = $this->getConf("enable") === 1;
$this->attribute = $requireAttribute ? $this->loadHelper('attribute', 'TwoFactor depends on the Attribute plugin, but the Attribute plugin is not installed!') : null;
$available = Twofactor_Auth_Module::_listModules();
$allmodules = Twofactor_Auth_Module::_loadModules($available);
$failed = array_diff($available, array_keys($allmodules));
if (count($failed) > 0) {
msg('At least one loaded module did not have a properly named class.' . ' ' . implode(', ', $failed), -1);
}
$this->modules = &$allmodules;
$this->_getUsers();
}
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Mike Wilmes',
'email' => 'mwilmes@wilminator.com',
'date' => '2018-06-26',
'name' => 'TwoFactor Plugin',
'desc' => 'This plugin provides for two factor authentication using either Google Authenticator or one time passwords sent by email or SMS appliance.',
'url' => 'http://www.dokuwiki.org/plugin:twofactor',
);
}
protected function _getUsers() {
if ($this->getConf("enable") === 1) {
if (!is_null($this->attribute)) {
$attr = $this->attribute;
$this->_user_list = $this->attribute->enumerateUsers('twofactor');
}
else {
msg($this->lang['no_purpose'], -1);
}
}
}
/**
* Return prompt for admin menu
*
* @param string $language
* @return string
*/
public function getMenuText($language) {
global $INFO;
if (!$INFO['isadmin'])
return parent::getMenuText($language);
return $this->getLang('menu').' '.$this->_disabled;
}
/**
* return sort order for position in admin menu
*
* @return int
*/
public function getMenuSort() {
return 2;
}
/**
* @return int current start value for pageination
*/
public function getStart() {
return $this->_start;
}
/**
* @return int number of users per page
*/
public function getPagesize() {
return $this->_pagesize;
}
/**
* @param boolean $lastdisabled
*/
public function setLastdisabled($lastdisabled) {
$this->_lastdisabled = $lastdisabled;
}
/**
* Handle user request
*
* @return bool
*/
public function handle() {
global $INPUT, $INFO;
if (!$INFO['isadmin']) return false;
if ($this->_disabled) {
// If disabled, don't process anything.
return true;
}
// 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 "reset" : $this->_resetUser(); break;
case "search" : $this->_setFilter($param);
$this->_start = 0;
break;
}
$this->_user_total = count($this->_user_list) > 0 ? $this->_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;
}
/**
* Output appropriate html
*
* @return bool
*/
public function html() {
global $ID, $INFO;
if(!$INFO['isadmin']) {
print $this->lang['badauth'];
return false;
}
if ($this->disabled !== '') {
msg($this->_disabled, -1);
return true;
}
$user_list = $this->_retrieveUsers($this->_start, $this->_pagesize, $this->_filter);
$page_buttons = $this->_pagination();
print $this->locale_xhtml('intro');
print $this->locale_xhtml('list');
ptln("