Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_2fa/kolab_2fa.php
Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | public function auth_form($attrib = array()) | ||||
if (empty($attrib['form'])) { | if (empty($attrib['form'])) { | ||||
$out = $this->api->output->form_tag(array('name' => $form_name, 'method' => 'post'), $out); | $out = $this->api->output->form_tag(array('name' => $form_name, 'method' => 'post'), $out); | ||||
} | } | ||||
return $out; | return $out; | ||||
} | } | ||||
/** | /** | ||||
* Load driver class for the given method | * Load driver class for the given authentication factor | ||||
* | |||||
* @param string $factor Factor identifier (<method>:<id>) | |||||
* @return Kolab2FA\Driver\Base | |||||
*/ | */ | ||||
public function get_driver($method) | public function get_driver($factor) | ||||
{ | { | ||||
list($method) = explode(':', $factor, 2); | |||||
$rcmail = rcmail::get_instance(); | $rcmail = rcmail::get_instance(); | ||||
if ($this->drivers[$method]) { | if ($this->drivers[$factor]) { | ||||
return $this->drivers[$method]; | return $this->drivers[$factor]; | ||||
} | } | ||||
$config = $rcmail->config->get('kolab_2fa_' . $method, array()); | $config = $rcmail->config->get('kolab_2fa_' . $method, array()); | ||||
// use product name as "issuer"" | // use product name as "issuer"" | ||||
if (empty($config['issuer'])) { | if (empty($config['issuer'])) { | ||||
$config['issuer'] = $rcmail->config->get('product_name'); | $config['issuer'] = $rcmail->config->get('product_name'); | ||||
} | } | ||||
try { | try { | ||||
// TODO: use external auth service if configured | // TODO: use external auth service if configured | ||||
$driver = \Kolab2FA\Driver\Base::factory($method, $config); | $driver = \Kolab2FA\Driver\Base::factory($factor, $config); | ||||
// attach storage | // attach storage | ||||
$driver->storage = $this->get_storage(); | $driver->storage = $this->get_storage(); | ||||
if ($rcmail->user->ID) { | if ($rcmail->user->ID) { | ||||
$driver->username = $rcmail->get_user_name(); | $driver->username = $rcmail->get_user_name(); | ||||
} | } | ||||
$this->drivers[$method] = $driver; | $this->drivers[$factor] = $driver; | ||||
return $driver; | return $driver; | ||||
} | } | ||||
catch (Exception $e) { | catch (Exception $e) { | ||||
$error = strval($e); | $error = strval($e); | ||||
} | } | ||||
rcube::raise_error(array( | rcube::raise_error(array( | ||||
'code' => 600, | 'code' => 600, | ||||
▲ Show 20 Lines • Show All 428 Lines • ▼ Show 20 Lines | class kolab_2fa extends rcube_plugin | ||||
*/ | */ | ||||
protected function check_secure_mode() | protected function check_secure_mode() | ||||
{ | { | ||||
$valid = ($_SESSION['kolab_2fa_secure_mode'] && $_SESSION['kolab_2fa_secure_mode'] > time() - 180); | $valid = ($_SESSION['kolab_2fa_secure_mode'] && $_SESSION['kolab_2fa_secure_mode'] > time() - 180); | ||||
return $valid; | return $valid; | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |