-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
119 lines (100 loc) · 3.53 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* DokuWiki Plugin authyubikey (Action Component)
* Plaintext authentication backend combined with Yubico's OTP
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Dirk Scheer <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
/**
* Class action_plugin_authyubikey
*/
class action_plugin_authyubikey extends DokuWiki_Action_Plugin {
/**
* Registring
*
* Registers a callback function for a given event
*
* @author Dirk Scheer <[email protected]>
* @param Doku_Event_Handler
*
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_loginform');
$controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'BEFORE', $this, 'handle_updateprofileform');
}
/**
* Hook for the login form
*
* Shows a one-time password field in the login form
*
* @author Dirk Scheer <[email protected]>
* @param Doku_Event $event
* @param array $param
*/
public function handle_loginform(Doku_Event &$event, $param) {
global $auth;
/* Check for activated authyubikey plugin */
if(!is_a($auth, 'auth_plugin_authyubikey')) return;
/** Get a reference to $form */
$form =& $event->data;
// add select box
$element = form_makeTextField('otp', '', $this->getLang('otp'), '', 'block');
$pos = $form->findElementByAttribute('name', 'p');
$form->insertElement($pos + 1, $element);
}
/**
* Hook for the profile form
*
* Shows Yubikey ID fields in the personal profile form
*
* @author Dirk Scheer <[email protected]>
* @param Doku_Event $event
* @param array $param
*/
public function handle_updateprofileform(Doku_Event &$event, $param) {
global $INPUT;
global $auth;
global $conf;
/* Check for activated authyubikey plugin */
if(!is_a($auth, 'auth_plugin_authyubikey')) return;
/** Get a reference to $form */
$form =& $event->data;
$pos = $form->findElementByAttribute('name', 'login');
$elem =& $form->getElementAt($pos);
$user = $elem['value'];
$yubi = array();
if($user !== '') {
$userinfo = $auth->getUserData($user);
if($userinfo === false) return false;
$yubi = $userinfo['yubi'];
}
// add textboxes for entering the Yubikey ID's
$maxkeys = $this->getConf('yubico_maxkeys');
for($i=0 ; $i<$maxkeys ; $i++) {
/* Building the label - if the user can enter
* enter only one ID, then the ID's are not
* numbered.
*/
if($maxkeys == 1) {
$label = $this->getLang('yubikeyid');
}
else {
$label = $this->getLang('yubikeyid') . ' #' . ($i+1);
}
/* Is there a value already defined in the $_POST environment?
* If not, then we will use the value stored value.
*/
$value = $INPUT->str('yubikeyid'.$i);
if($value === '') {
$value = $yubi[$i];
}
$element = form_makeTextField('yubikeyid'.$i, $value, $label, '', 'block', array('maxlength'=>'44'));
$pos = $form->findElementByAttribute('name', 'email');
$form->insertElement($pos + $i + 1, $element);
}
}
}
// vim:ts=4:sw=4:et: