Rev 1288 | Rev 1305 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1288 | Rev 1293 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | namespace ViaThinkSoft\OIDplus; |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | // phpcs:disable PSR1.Files.SideEffects |
22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusPagePublicLogin extends OIDplusPagePluginPublic { |
26 | class OIDplusPagePublicLogin extends OIDplusPagePluginPublic { |
27 | 27 | ||
28 | /** |
28 | /** |
29 | * @param string $actionID |
- | |
30 | * @param array $params |
29 | * @param array $params |
31 | * @return array |
30 | * @return array |
32 | * @throws OIDplusException |
31 | * @throws OIDplusException |
33 | */ |
32 | */ |
34 | public function action(string $actionID, array $params): array { |
33 | private function action_RaLogin(array $params): array { |
35 | // === RA LOGIN/LOGOUT === |
- | |
36 | - | ||
37 | if ($actionID == 'ra_login') { |
- | |
38 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
34 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
39 | 35 | ||
40 | _CheckParamExists($params, 'email'); |
36 | _CheckParamExists($params, 'email'); |
41 | _CheckParamExists($params, 'password'); |
37 | _CheckParamExists($params, 'password'); |
42 | 38 | ||
43 | $email = $params['email']; |
39 | $email = $params['email']; |
44 | $ra = new OIDplusRA($email); |
40 | $ra = new OIDplusRA($email); |
45 | 41 | ||
46 | if (empty($email)) { |
42 | if (empty($email)) { |
47 | throw new OIDplusException(_L('Please enter a valid email address')); |
43 | throw new OIDplusException(_L('Please enter a valid email address')); |
48 | } |
44 | } |
49 | 45 | ||
50 | if ($ra->checkPassword($params['password'])) { |
46 | if ($ra->checkPassword($params['password'])) { |
51 | $remember_me = isset($params['remember_me']) && ($params['remember_me']); |
47 | $remember_me = isset($params['remember_me']) && ($params['remember_me']); |
52 | OIDplus::authUtils()->raLoginEx($email, $remember_me, 'Regular login'); |
48 | OIDplus::authUtils()->raLoginEx($email, $remember_me, 'Regular login'); |
53 | 49 | ||
54 | $authInfo = OIDplus::authUtils()->raGeneratePassword($params['password']); |
50 | $authInfo = OIDplus::authUtils()->raGeneratePassword($params['password']); |
55 | 51 | ||
56 | // Rehash, so that we always have the latest default auth plugin and params |
52 | // Rehash, so that we always have the latest default auth plugin and params |
57 | // Note that we do it every time (unlike PHPs recommended password_needs_rehash), |
53 | // Note that we do it every time (unlike PHPs recommended password_needs_rehash), |
58 | // because we are not sure which auth plugin created the hash (there might be multiple |
54 | // because we are not sure which auth plugin created the hash (there might be multiple |
59 | // auth plugins that can verify this hash). So we just rehash on every login! |
55 | // auth plugins that can verify this hash). So we just rehash on every login! |
60 | $new_authkey = $authInfo->getAuthKey(); |
56 | $new_authkey = $authInfo->getAuthKey(); |
61 | 57 | ||
62 | OIDplus::db()->query("UPDATE ###ra set last_login = ".OIDplus::db()->sqlDate().", authkey = ? where email = ?", array($new_authkey, $email)); |
58 | OIDplus::db()->query("UPDATE ###ra set last_login = ".OIDplus::db()->sqlDate().", authkey = ? where email = ?", array($new_authkey, $email)); |
63 | 59 | ||
64 | return array("status" => 0); |
60 | return array("status" => 0); |
65 | } else { |
61 | } else { |
66 | if (OIDplus::config()->getValue('log_failed_ra_logins', false)) { |
62 | if (OIDplus::config()->getValue('log_failed_ra_logins', false)) { |
67 | if ($ra->existing()) { |
63 | if ($ra->existing()) { |
68 | OIDplus::logger()->log("V2:[WARN]A", "Failed login to RA account '%1' (wrong password)", $email); |
64 | OIDplus::logger()->log("V2:[WARN]A", "Failed login to RA account '%1' (wrong password)", $email); |
69 | } else { |
65 | } else { |
70 | OIDplus::logger()->log("V2:[WARN]A", "Failed login to RA account '%1' (RA not existing)", $email); |
66 | OIDplus::logger()->log("V2:[WARN]A", "Failed login to RA account '%1' (RA not existing)", $email); |
71 | } |
67 | } |
72 | } |
68 | } |
73 | throw new OIDplusException(_L('Wrong password or user not registered')); |
69 | throw new OIDplusException(_L('Wrong password or user not registered')); |
74 | } |
70 | } |
- | 71 | } |
|
75 | 72 | ||
- | 73 | /** |
|
- | 74 | * @param array $params |
|
- | 75 | * @return array |
|
76 | } else if ($actionID == 'ra_logout') { |
76 | * @throws OIDplusException |
77 | 77 | */ |
|
- | 78 | private function action_RaLogout(array $params): array { |
|
78 | _CheckParamExists($params, 'email'); |
79 | _CheckParamExists($params, 'email'); |
79 | 80 | ||
80 | $email = $params['email']; |
81 | $email = $params['email']; |
81 | 82 | ||
82 | OIDplus::authUtils()->raLogoutEx($email); |
83 | OIDplus::authUtils()->raLogoutEx($email); |
83 | 84 | ||
84 | return array("status" => 0); |
85 | return array("status" => 0); |
85 | } |
86 | } |
86 | 87 | ||
- | 88 | /** |
|
- | 89 | * @param array $params |
|
- | 90 | * @return array |
|
87 | // === ADMIN LOGIN/LOGOUT === |
91 | * @throws OIDplusException |
88 | 92 | */ |
|
89 | else if ($actionID == 'admin_login') { |
93 | private function action_AdminLogin(array $params): array { |
90 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
94 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
91 | 95 | ||
92 | _CheckParamExists($params, 'password'); |
96 | _CheckParamExists($params, 'password'); |
93 | if (OIDplus::authUtils()->adminCheckPassword($params['password'])) { |
97 | if (OIDplus::authUtils()->adminCheckPassword($params['password'])) { |
94 | $remember_me = isset($params['remember_me']) && ($params['remember_me']); |
98 | $remember_me = isset($params['remember_me']) && ($params['remember_me']); |
95 | OIDplus::authUtils()->adminLoginEx($remember_me, 'Regular login'); |
99 | OIDplus::authUtils()->adminLoginEx($remember_me, 'Regular login'); |
96 | 100 | ||
97 | // TODO: Write a "last login" entry in config table? |
101 | // TODO: Write a "last login" entry in config table? |
98 | 102 | ||
99 | return array("status" => 0); |
103 | return array("status" => 0); |
100 | } else { |
104 | } else { |
101 | if (OIDplus::config()->getValue('log_failed_admin_logins', false)) { |
105 | if (OIDplus::config()->getValue('log_failed_admin_logins', false)) { |
102 | OIDplus::logger()->log("V2:[WARN]A", "Failed login to admin account"); |
106 | OIDplus::logger()->log("V2:[WARN]A", "Failed login to admin account"); |
103 | } |
107 | } |
104 | throw new OIDplusException(_L('Wrong password')); |
108 | throw new OIDplusException(_L('Wrong password')); |
105 | } |
109 | } |
106 | } |
110 | } |
- | 111 | ||
- | 112 | /** |
|
- | 113 | * @param array $params |
|
- | 114 | * @return array |
|
- | 115 | * @throws OIDplusException |
|
- | 116 | */ |
|
107 | else if ($actionID == 'admin_logout') { |
117 | private function action_AdminLogout(array $params): array { |
108 | OIDplus::authUtils()->adminLogoutEx(); |
118 | OIDplus::authUtils()->adminLogoutEx(); |
109 | 119 | ||
110 | return array("status" => 0); |
120 | return array("status" => 0); |
111 | } |
121 | } |
- | 122 | ||
- | 123 | /** |
|
- | 124 | * @param string $actionID |
|
- | 125 | * @param array $params |
|
- | 126 | * @return array |
|
- | 127 | * @throws OIDplusException |
|
- | 128 | */ |
|
- | 129 | public function action(string $actionID, array $params): array { |
|
- | 130 | if ($actionID == 'ra_login') { |
|
- | 131 | return $this->action_RaLogin($params); |
|
- | 132 | } else if ($actionID == 'ra_logout') { |
|
- | 133 | return $this->action_RaLogout($params); |
|
- | 134 | } else if ($actionID == 'admin_login') { |
|
- | 135 | return $this->action_AdminLogin($params); |
|
- | 136 | } else if ($actionID == 'admin_logout') { |
|
- | 137 | return $this->action_AdminLogout($params); |
|
112 | else { |
138 | } else { |
113 | return parent::action($actionID, $params); |
139 | return parent::action($actionID, $params); |
114 | } |
140 | } |
115 | } |
141 | } |
116 | 142 | ||
117 | /** |
143 | /** |
118 | * @param bool $html |
144 | * @param bool $html |
119 | * @return void |
145 | * @return void |
120 | * @throws OIDplusException |
146 | * @throws OIDplusException |
121 | */ |
147 | */ |
122 | public function init(bool $html=true) { |
148 | public function init(bool $html=true) { |
123 | OIDplus::config()->prepareConfigKey('log_failed_ra_logins', 'Log failed RA logins', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
149 | OIDplus::config()->prepareConfigKey('log_failed_ra_logins', 'Log failed RA logins', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
124 | if (!is_numeric($value) || (($value != 0) && (($value != 1)))) { |
150 | if (!is_numeric($value) || (($value != 0) && (($value != 1)))) { |
125 | throw new OIDplusException(_L('Valid values: 0 (off) or 1 (on).')); |
151 | throw new OIDplusException(_L('Valid values: 0 (off) or 1 (on).')); |
126 | } |
152 | } |
127 | }); |
153 | }); |
128 | OIDplus::config()->prepareConfigKey('log_failed_admin_logins', 'Log failed Admin logins', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
154 | OIDplus::config()->prepareConfigKey('log_failed_admin_logins', 'Log failed Admin logins', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
129 | if (!is_numeric($value) || (($value != 0) && (($value != 1)))) { |
155 | if (!is_numeric($value) || (($value != 0) && (($value != 1)))) { |
130 | throw new OIDplusException(_L('Valid values: 0 (off) or 1 (on).')); |
156 | throw new OIDplusException(_L('Valid values: 0 (off) or 1 (on).')); |
131 | } |
157 | } |
132 | }); |
158 | }); |
133 | } |
159 | } |
134 | 160 | ||
135 | /** |
161 | /** |
136 | * @param string $id |
162 | * @param string $id |
137 | * @param array $out |
163 | * @param array $out |
138 | * @param bool $handled |
164 | * @param bool $handled |
139 | * @return void |
165 | * @return void |
140 | * @throws OIDplusException |
166 | * @throws OIDplusException |
141 | */ |
167 | */ |
142 | public function gui(string $id, array &$out, bool &$handled) { |
168 | public function gui(string $id, array &$out, bool &$handled) { |
143 | $ary = explode('$', $id); |
169 | $ary = explode('$', $id); |
144 | $desired_ra = ''; |
170 | $desired_ra = ''; |
145 | if (isset($ary[1])) { |
171 | if (isset($ary[1])) { |
146 | $id = $ary[0]; |
172 | $id = $ary[0]; |
147 | $tab = $ary[1]; |
173 | $tab = $ary[1]; |
148 | if (isset($ary[2])) { |
174 | if (isset($ary[2])) { |
149 | $desired_ra = $ary[2]; |
175 | $desired_ra = $ary[2]; |
150 | } |
176 | } |
151 | } else { |
177 | } else { |
152 | $tab = 'ra'; |
178 | $tab = 'ra'; |
153 | } |
179 | } |
154 | if ($id === 'oidplus:login') { |
180 | if ($id === 'oidplus:login') { |
155 | $handled = true; |
181 | $handled = true; |
156 | $out['title'] = _L('Login'); |
182 | $out['title'] = _L('Login'); |
157 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/login_icon.png'; |
183 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/login_icon.png'; |
158 | 184 | ||
159 | $out['text'] = '<noscript>'; |
185 | $out['text'] = '<noscript>'; |
160 | $out['text'] .= '<p><font color="red">'._L('You need to enable JavaScript to use the login area.').'</font></p>'; |
186 | $out['text'] .= '<p><font color="red">'._L('You need to enable JavaScript to use the login area.').'</font></p>'; |
161 | $out['text'] .= '</noscript>'; |
187 | $out['text'] .= '</noscript>'; |
162 | 188 | ||
163 | $out['text'] .= '<div id="loginArea" style="visibility: hidden"><div id="loginTab" class="container" style="width:100%;">'; |
189 | $out['text'] .= '<div id="loginArea" style="visibility: hidden"><div id="loginTab" class="container" style="width:100%;">'; |
164 | 190 | ||
165 | $out['text'] .= OIDplus::getActiveCaptchaPlugin()->captchaGenerate(_L('Before logging in, please solve the following CAPTCHA')); |
191 | $out['text'] .= OIDplus::getActiveCaptchaPlugin()->captchaGenerate(_L('Before logging in, please solve the following CAPTCHA')); |
166 | $out['text'] .= '<br>'; |
192 | $out['text'] .= '<br>'; |
167 | 193 | ||
168 | // ---------------- Tab control |
194 | // ---------------- Tab control |
169 | $out['text'] .= OIDplus::gui()->tabBarStart(); |
195 | $out['text'] .= OIDplus::gui()->tabBarStart(); |
170 | $out['text'] .= OIDplus::gui()->tabBarElement('ra', _L('Login as RA'), $tab === 'ra'); |
196 | $out['text'] .= OIDplus::gui()->tabBarElement('ra', _L('Login as RA'), $tab === 'ra'); |
171 | $out['text'] .= OIDplus::gui()->tabBarElement('admin', _L('Login as administrator'), $tab === 'admin'); |
197 | $out['text'] .= OIDplus::gui()->tabBarElement('admin', _L('Login as administrator'), $tab === 'admin'); |
172 | $out['text'] .= OIDplus::gui()->tabBarEnd(); |
198 | $out['text'] .= OIDplus::gui()->tabBarEnd(); |
173 | $out['text'] .= OIDplus::gui()->tabContentStart(); |
199 | $out['text'] .= OIDplus::gui()->tabContentStart(); |
174 | // ---------------- "RA" tab |
200 | // ---------------- "RA" tab |
175 | $tabcont = '<h2>'._L('Login as RA').'</h2>'; |
201 | $tabcont = '<h2>'._L('Login as RA').'</h2>'; |
176 | $login_list = OIDplus::authUtils()->loggedInRaList(); |
202 | $login_list = OIDplus::authUtils()->loggedInRaList(); |
177 | if (count($login_list) > 0) { |
203 | if (count($login_list) > 0) { |
178 | foreach ($login_list as $x) { |
204 | foreach ($login_list as $x) { |
179 | $tabcont .= '<p>'._L('You are logged in as %1','<b>'.$x->raEmail().'</b>').' (<a href="#" onclick="return OIDplusPagePublicLogin.raLogout('.js_escape($x->raEmail()).');">'._L('Logout').'</a>)</p>'; |
205 | $tabcont .= '<p>'._L('You are logged in as %1','<b>'.$x->raEmail().'</b>').' (<a href="#" onclick="return OIDplusPagePublicLogin.raLogout('.js_escape($x->raEmail()).');">'._L('Logout').'</a>)</p>'; |
180 | } |
206 | } |
181 | $tabcont .= '<p>'._L('If you have more accounts, you can log in with another account here.').'</p>'; |
207 | $tabcont .= '<p>'._L('If you have more accounts, you can log in with another account here.').'</p>'; |
182 | } else { |
208 | } else { |
183 | $tabcont .= '<p>'._L('Enter your email address and your password to log in as Registration Authority.').'</p>'; |
209 | $tabcont .= '<p>'._L('Enter your email address and your password to log in as Registration Authority.').'</p>'; |
184 | } |
210 | } |
185 | $tabcont .= '<form action="javascript:void(0);" onsubmit="return OIDplusPagePublicLogin.raLoginOnSubmit(this);">'; |
211 | $tabcont .= '<form action="javascript:void(0);" onsubmit="return OIDplusPagePublicLogin.raLoginOnSubmit(this);">'; |
186 | $tabcont .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" name="email" value="'.htmlentities($desired_ra).'" id="raLoginEMail"></div>'; |
212 | $tabcont .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" name="email" value="'.htmlentities($desired_ra).'" id="raLoginEMail"></div>'; |
187 | $tabcont .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" name="password" value="" id="raLoginPassword"></div>'; |
213 | $tabcont .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" name="password" value="" id="raLoginPassword"></div>'; |
188 | if (OIDplus::baseConfig()->getValue('JWT_ALLOW_LOGIN_USER', true)) { |
214 | if (OIDplus::baseConfig()->getValue('JWT_ALLOW_LOGIN_USER', true)) { |
189 | if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreJWT::class)) { |
215 | if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreJWT::class)) { |
190 | if (OIDplus::authUtils()->getExtendedAttribute('oidplus_generator',-1) === OIDplusAuthContentStoreJWT::JWT_GENERATOR_LOGIN) { |
216 | if (OIDplus::authUtils()->getExtendedAttribute('oidplus_generator',-1) === OIDplusAuthContentStoreJWT::JWT_GENERATOR_LOGIN) { |
191 | $att = 'disabled checked'; |
217 | $att = 'disabled checked'; |
192 | } else { |
218 | } else { |
193 | $att = 'disabled'; |
219 | $att = 'disabled'; |
194 | } |
220 | } |
195 | } else if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreSession::class)) { |
221 | } else if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreSession::class)) { |
196 | $att = 'disabled'; |
222 | $att = 'disabled'; |
197 | } else { |
223 | } else { |
198 | $att = ''; |
224 | $att = ''; |
199 | } |
225 | } |
200 | $tabcont .= '<div><input '.$att.' type="checkbox" value="1" id="remember_me_ra" name="remember_me_ra"> <label for="remember_me_ra">'._L('Remember me').'</label></div>'; |
226 | $tabcont .= '<div><input '.$att.' type="checkbox" value="1" id="remember_me_ra" name="remember_me_ra"> <label for="remember_me_ra">'._L('Remember me').'</label></div>'; |
201 | } |
227 | } |
202 | $tabcont .= '<br><input type="submit" value="'._L('Login').'"><br><br>'; |
228 | $tabcont .= '<br><input type="submit" value="'._L('Login').'"><br><br>'; |
203 | $tabcont .= '</form>'; |
229 | $tabcont .= '</form>'; |
204 | $tabcont .= '<p><a '.OIDplus::gui()->link('oidplus:forgot_password').'>'._L('Forgot password?').'</a><br>'; |
230 | $tabcont .= '<p><a '.OIDplus::gui()->link('oidplus:forgot_password').'>'._L('Forgot password?').'</a><br>'; |
205 | 231 | ||
206 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
232 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
207 | if (!is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled')) { |
233 | if (!is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled')) { |
208 | $tabcont .= '<p><b>'._L('How to register?').'</b> '._L('To receive login data, the superior RA needs to send you an invitation. After creating or updating your OID, the system will ask them if they want to send you an invitation. If they accept, you will receive an email with an activation link. Alternatively, the system admin can create your account manually in the administrator control panel.').'</p>'; |
234 | $tabcont .= '<p><b>'._L('How to register?').'</b> '._L('To receive login data, the superior RA needs to send you an invitation. After creating or updating your OID, the system will ask them if they want to send you an invitation. If they accept, you will receive an email with an activation link. Alternatively, the system admin can create your account manually in the administrator control panel.').'</p>'; |
209 | } else { |
235 | } else { |
210 | $tabcont .= '<p><b>'._L('How to register?').'</b> '._L('Since invitations are disabled at this OIDplus system, the system administrator needs to create your account manually in the administrator control panel.').'</p>'; |
236 | $tabcont .= '<p><b>'._L('How to register?').'</b> '._L('Since invitations are disabled at this OIDplus system, the system administrator needs to create your account manually in the administrator control panel.').'</p>'; |
211 | } |
237 | } |
212 | 238 | ||
213 | if ($tab === 'ra') { |
239 | if ($tab === 'ra') { |
214 | $alt_logins_html = array(); |
240 | $alt_logins_html = array(); |
215 | foreach (OIDplus::getAllPlugins() as $plugin) { |
241 | foreach (OIDplus::getAllPlugins() as $plugin) { |
216 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_5) { |
242 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_5) { |
217 | $logins = $plugin->alternativeLoginMethods(); |
243 | $logins = $plugin->alternativeLoginMethods(); |
218 | foreach ($logins as $data) { |
244 | foreach ($logins as $data) { |
219 | if (isset($data[2]) && !empty($data[2])) { |
245 | if (isset($data[2]) && !empty($data[2])) { |
220 | $img = '<img src="'.$data[2].'" alt="'.htmlentities($data[1]).'"> '; |
246 | $img = '<img src="'.$data[2].'" alt="'.htmlentities($data[1]).'"> '; |
221 | } else { |
247 | } else { |
222 | $img = ''; |
248 | $img = ''; |
223 | } |
249 | } |
224 | $alt_logins_html[] = $img.'<a '.OIDplus::gui()->link($data[0]).'>'.htmlentities($data[1]).'</a>'; |
250 | $alt_logins_html[] = $img.'<a '.OIDplus::gui()->link($data[0]).'>'.htmlentities($data[1]).'</a>'; |
225 | } |
251 | } |
226 | } |
252 | } |
227 | } |
253 | } |
228 | if (count($alt_logins_html) > 0) { |
254 | if (count($alt_logins_html) > 0) { |
229 | $tabcont .= '<p>'._L('Alternative login methods').':<br>'; |
255 | $tabcont .= '<p>'._L('Alternative login methods').':<br>'; |
230 | foreach ($alt_logins_html as $alt_login) { |
256 | foreach ($alt_logins_html as $alt_login) { |
231 | $tabcont .= $alt_login.'<br>'; |
257 | $tabcont .= $alt_login.'<br>'; |
232 | } |
258 | } |
233 | $tabcont .= '</p>'; |
259 | $tabcont .= '</p>'; |
234 | } |
260 | } |
235 | } |
261 | } |
236 | 262 | ||
237 | $out['text'] .= OIDplus::gui()->tabContentPage('ra', $tabcont, $tab === 'ra'); |
263 | $out['text'] .= OIDplus::gui()->tabContentPage('ra', $tabcont, $tab === 'ra'); |
238 | // ---------------- "Administrator" tab |
264 | // ---------------- "Administrator" tab |
239 | $tabcont = '<h2>'._L('Login as administrator').'</h2>'; |
265 | $tabcont = '<h2>'._L('Login as administrator').'</h2>'; |
240 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
266 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
241 | $tabcont .= '<p>'._L('You are logged in as administrator.').'</p>'; |
267 | $tabcont .= '<p>'._L('You are logged in as administrator.').'</p>'; |
242 | $tabcont .= '<a href="#" onclick="return OIDplusPagePublicLogin.adminLogout();">'._L('Logout').'</a>'; |
268 | $tabcont .= '<a href="#" onclick="return OIDplusPagePublicLogin.adminLogout();">'._L('Logout').'</a>'; |
243 | } else { |
269 | } else { |
244 | $tabcont .= '<form action="javascript:void(0);" onsubmit="return OIDplusPagePublicLogin.adminLoginOnSubmit(this);">'; |
270 | $tabcont .= '<form action="javascript:void(0);" onsubmit="return OIDplusPagePublicLogin.adminLoginOnSubmit(this);">'; |
245 | $tabcont .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" name="password" value="" id="adminLoginPassword"></div>'; |
271 | $tabcont .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" name="password" value="" id="adminLoginPassword"></div>'; |
246 | if (OIDplus::baseConfig()->getValue('JWT_ALLOW_LOGIN_ADMIN', true)) { |
272 | if (OIDplus::baseConfig()->getValue('JWT_ALLOW_LOGIN_ADMIN', true)) { |
247 | if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreJWT::class)) { |
273 | if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreJWT::class)) { |
248 | if (OIDplus::authUtils()->getExtendedAttribute('oidplus_generator',-1) === OIDplusAuthContentStoreJWT::JWT_GENERATOR_LOGIN) { |
274 | if (OIDplus::authUtils()->getExtendedAttribute('oidplus_generator',-1) === OIDplusAuthContentStoreJWT::JWT_GENERATOR_LOGIN) { |
249 | $att = 'disabled checked'; |
275 | $att = 'disabled checked'; |
250 | } else { |
276 | } else { |
251 | $att = 'disabled'; |
277 | $att = 'disabled'; |
252 | } |
278 | } |
253 | } else if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreSession::class)) { |
279 | } else if ((OIDplus::authUtils()->getAuthMethod() === OIDplusAuthContentStoreSession::class)) { |
254 | $att = 'disabled'; |
280 | $att = 'disabled'; |
255 | } else { |
281 | } else { |
256 | $att = ''; |
282 | $att = ''; |
257 | } |
283 | } |
258 | $tabcont .= '<div><input '.$att.' type="checkbox" value="1" id="remember_me_admin" name="remember_me_admin"> <label for="remember_me_admin">'._L('Remember me').'</label></div>'; |
284 | $tabcont .= '<div><input '.$att.' type="checkbox" value="1" id="remember_me_admin" name="remember_me_admin"> <label for="remember_me_admin">'._L('Remember me').'</label></div>'; |
259 | } |
285 | } |
260 | $tabcont .= '<br><input type="submit" value="'._L('Login').'"><br><br>'; |
286 | $tabcont .= '<br><input type="submit" value="'._L('Login').'"><br><br>'; |
261 | $tabcont .= '</form>'; |
287 | $tabcont .= '</form>'; |
262 | $tabcont .= '<p><a '.OIDplus::gui()->link('oidplus:forgot_password_admin').'>'._L('Forgot password?').'</a><br>'; |
288 | $tabcont .= '<p><a '.OIDplus::gui()->link('oidplus:forgot_password_admin').'>'._L('Forgot password?').'</a><br>'; |
263 | } |
289 | } |
264 | $out['text'] .= OIDplus::gui()->tabContentPage('admin', $tabcont, $tab === 'admin'); |
290 | $out['text'] .= OIDplus::gui()->tabContentPage('admin', $tabcont, $tab === 'admin'); |
265 | $out['text'] .= OIDplus::gui()->tabContentEnd(); |
291 | $out['text'] .= OIDplus::gui()->tabContentEnd(); |
266 | // ---------------- Tab control END |
292 | // ---------------- Tab control END |
267 | 293 | ||
268 | $out['text'] .= '</div><br>'; |
294 | $out['text'] .= '</div><br>'; |
269 | 295 | ||
270 | $mins = ceil(OIDplus::baseConfig()->getValue('SESSION_LIFETIME', 30*60)/60); |
296 | $mins = ceil(OIDplus::baseConfig()->getValue('SESSION_LIFETIME', 30*60)/60); |
271 | $out['text'] .= '<p><font size="-1">'._L('<i>Privacy information</i>: By using the login functionality, you are accepting that a "session cookie" is temporarily stored in your browser. The session cookie is a small text file that is sent to this website every time you visit it, to identify you as an already logged in user. It does not track any of your online activities outside OIDplus. The cookie will be destroyed when you log out or after an inactivity of %1 minutes (except if the "Remember me" option is used).', $mins); |
297 | $out['text'] .= '<p><font size="-1">'._L('<i>Privacy information</i>: By using the login functionality, you are accepting that a "session cookie" is temporarily stored in your browser. The session cookie is a small text file that is sent to this website every time you visit it, to identify you as an already logged in user. It does not track any of your online activities outside OIDplus. The cookie will be destroyed when you log out or after an inactivity of %1 minutes (except if the "Remember me" option is used).', $mins); |
272 | $privacy_document_file = 'OIDplus/privacy_documentation.html'; |
298 | $privacy_document_file = 'OIDplus/privacy_documentation.html'; |
273 | $resourcePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.500'); // OIDplusPagePublicResources |
299 | $resourcePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.500'); // OIDplusPagePublicResources |
274 | if (!is_null($resourcePlugin) && file_exists(OIDplus::localpath().'res/'.$privacy_document_file)) { |
300 | if (!is_null($resourcePlugin) && file_exists(OIDplus::localpath().'res/'.$privacy_document_file)) { |
275 | $out['text'] .= ' <a '.OIDplus::gui()->link('oidplus:resources$'.$privacy_document_file.'#cookies').'>'._L('More information about the cookies used').'</a>'; |
301 | $out['text'] .= ' <a '.OIDplus::gui()->link('oidplus:resources$'.$privacy_document_file.'#cookies').'>'._L('More information about the cookies used').'</a>'; |
276 | } |
302 | } |
277 | $out['text'] .= '</font></p></div>'; |
303 | $out['text'] .= '</font></p></div>'; |
278 | 304 | ||
279 | $out['text'] .= '<script>$("#loginArea")[0].style.visibility = "visible";</script>'; |
305 | $out['text'] .= '<script>$("#loginArea")[0].style.visibility = "visible";</script>'; |
280 | } |
306 | } |
281 | } |
307 | } |
282 | 308 | ||
283 | /** |
309 | /** |
284 | * @param array $out |
310 | * @param array $out |
285 | * @return void |
311 | * @return void |
286 | */ |
312 | */ |
287 | public function publicSitemap(array &$out) { |
313 | public function publicSitemap(array &$out) { |
288 | $out[] = 'oidplus:login'; |
314 | $out[] = 'oidplus:login'; |
289 | } |
315 | } |
290 | 316 | ||
291 | /** |
317 | /** |
292 | * @param array $json |
318 | * @param array $json |
293 | * @param string|null $ra_email |
319 | * @param string|null $ra_email |
294 | * @param bool $nonjs |
320 | * @param bool $nonjs |
295 | * @param string $req_goto |
321 | * @param string $req_goto |
296 | * @return bool |
322 | * @return bool |
297 | * @throws OIDplusConfigInitializationException |
323 | * @throws OIDplusConfigInitializationException |
298 | * @throws OIDplusException |
324 | * @throws OIDplusException |
299 | */ |
325 | */ |
300 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
326 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
301 | $loginChildren = array(); |
327 | $loginChildren = array(); |
302 | 328 | ||
303 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
329 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
304 | $ra_roots = array(); |
330 | $ra_roots = array(); |
305 | 331 | ||
306 | foreach (OIDplus::getPagePlugins() as $plugin) { |
332 | foreach (OIDplus::getPagePlugins() as $plugin) { |
307 | if (is_subclass_of($plugin, OIDplusPagePluginAdmin::class)) { |
333 | if (is_subclass_of($plugin, OIDplusPagePluginAdmin::class)) { |
308 | $plugin->tree($ra_roots); |
334 | $plugin->tree($ra_roots); |
309 | } |
335 | } |
310 | } |
336 | } |
311 | 337 | ||
312 | $ra_roots[] = array( |
338 | $ra_roots[] = array( |
313 | 'id' => 'oidplus:logout$admin', |
339 | 'id' => 'oidplus:logout$admin', |
314 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/logout_icon16.png', |
340 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/logout_icon16.png', |
315 | 'conditionalselect' => 'OIDplusPagePublicLogin.adminLogout(); false;', |
341 | 'conditionalselect' => 'OIDplusPagePublicLogin.adminLogout(); false;', |
316 | 'text' => _L('Log out') |
342 | 'text' => _L('Log out') |
317 | ); |
343 | ); |
318 | $loginChildren[] = array( |
344 | $loginChildren[] = array( |
319 | 'id' => 'oidplus:dummy$'.md5((string)rand()), |
345 | 'id' => 'oidplus:dummy$'.md5((string)rand()), |
320 | 'text' => _L("Logged in as <b>admin</b>"), |
346 | 'text' => _L("Logged in as <b>admin</b>"), |
321 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/admin_icon16.png', |
347 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/admin_icon16.png', |
322 | 'conditionalselect' => 'false', // dummy node that can't be selected |
348 | 'conditionalselect' => 'false', // dummy node that can't be selected |
323 | 'state' => array("opened" => true), |
349 | 'state' => array("opened" => true), |
324 | 'children' => $ra_roots |
350 | 'children' => $ra_roots |
325 | ); |
351 | ); |
326 | } |
352 | } |
327 | 353 | ||
328 | foreach (OIDplus::authUtils()->loggedInRaList() as $ra) { |
354 | foreach (OIDplus::authUtils()->loggedInRaList() as $ra) { |
329 | $ra_email = $ra->raEmail(); |
355 | $ra_email = $ra->raEmail(); |
330 | $ra_roots = array(); |
356 | $ra_roots = array(); |
331 | 357 | ||
332 | foreach (OIDplus::getPagePlugins() as $plugin) { |
358 | foreach (OIDplus::getPagePlugins() as $plugin) { |
333 | if (is_subclass_of($plugin, OIDplusPagePluginRa::class)) { |
359 | if (is_subclass_of($plugin, OIDplusPagePluginRa::class)) { |
334 | $plugin->tree($ra_roots, $ra_email); |
360 | $plugin->tree($ra_roots, $ra_email); |
335 | } |
361 | } |
336 | } |
362 | } |
337 | 363 | ||
338 | $ra_roots[] = array( |
364 | $ra_roots[] = array( |
339 | 'id' => 'oidplus:logout$'.$ra_email, |
365 | 'id' => 'oidplus:logout$'.$ra_email, |
340 | 'conditionalselect' => 'OIDplusPagePublicLogin.raLogout('.js_escape($ra_email).'); false;', |
366 | 'conditionalselect' => 'OIDplusPagePublicLogin.raLogout('.js_escape($ra_email).'); false;', |
341 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/logout_icon16.png', |
367 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/logout_icon16.png', |
342 | 'text' => _L('Log out') |
368 | 'text' => _L('Log out') |
343 | ); |
369 | ); |
344 | foreach (OIDplusObject::getRaRoots($ra_email) as $loc_root) { |
370 | foreach (OIDplusObject::getRaRoots($ra_email) as $loc_root) { |
345 | $ico = $loc_root->getIcon(); |
371 | $ico = $loc_root->getIcon(); |
346 | $ra_roots[] = array( |
372 | $ra_roots[] = array( |
347 | 'id' => 'oidplus:raroot$'.$loc_root->nodeId(), |
373 | 'id' => 'oidplus:raroot$'.$loc_root->nodeId(), |
348 | 'text' => _L('Jump to RA root %1',$loc_root->objectTypeTitleShort().' '.$loc_root->crudShowId(OIDplusObject::parse($loc_root::root()))), |
374 | 'text' => _L('Jump to RA root %1',$loc_root->objectTypeTitleShort().' '.$loc_root->crudShowId(OIDplusObject::parse($loc_root::root()))), |
349 | 'conditionalselect' => 'openOidInPanel('.js_escape($loc_root->nodeId()).', true); false;', |
375 | 'conditionalselect' => 'openOidInPanel('.js_escape($loc_root->nodeId()).', true); false;', |
350 | 'icon' => !is_null($ico) ? $ico : OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/link_icon16.png' |
376 | 'icon' => !is_null($ico) ? $ico : OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/link_icon16.png' |
351 | ); |
377 | ); |
352 | } |
378 | } |
353 | $ra_email_or_name = (new OIDplusRA($ra_email))->raName(); |
379 | $ra_email_or_name = (new OIDplusRA($ra_email))->raName(); |
354 | if ($ra_email_or_name == '') { |
380 | if ($ra_email_or_name == '') { |
355 | $ra_email_html = htmlentities($ra_email); |
381 | $ra_email_html = htmlentities($ra_email); |
356 | $ra_email_or_name = '<b>'.$ra_email_html.'</b>'; |
382 | $ra_email_or_name = '<b>'.$ra_email_html.'</b>'; |
357 | } else { |
383 | } else { |
358 | $ra_email_html = htmlentities($ra_email); |
384 | $ra_email_html = htmlentities($ra_email); |
359 | $ra_email_or_name_html = htmlentities($ra_email_or_name); |
385 | $ra_email_or_name_html = htmlentities($ra_email_or_name); |
360 | $ra_email_or_name = "<b>$ra_email_or_name_html</b> ($ra_email_html)"; |
386 | $ra_email_or_name = "<b>$ra_email_or_name_html</b> ($ra_email_html)"; |
361 | } |
387 | } |
362 | $loginChildren[] = array( |
388 | $loginChildren[] = array( |
363 | 'id' => 'oidplus:dummy$'.md5((string)rand()), |
389 | 'id' => 'oidplus:dummy$'.md5((string)rand()), |
364 | 'text' => _L('Logged in as %1',$ra_email_or_name), |
390 | 'text' => _L('Logged in as %1',$ra_email_or_name), |
365 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/ra_icon16.png', |
391 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/ra_icon16.png', |
366 | 'conditionalselect' => 'false', // dummy node that can't be selected |
392 | 'conditionalselect' => 'false', // dummy node that can't be selected |
367 | 'state' => array("opened" => true), |
393 | 'state' => array("opened" => true), |
368 | 'children' => $ra_roots |
394 | 'children' => $ra_roots |
369 | ); |
395 | ); |
370 | } |
396 | } |
371 | 397 | ||
372 | $json[] = array( |
398 | $json[] = array( |
373 | 'id' => 'oidplus:login', |
399 | 'id' => 'oidplus:login', |
374 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/login_icon16.png', |
400 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/login_icon16.png', |
375 | 'text' => _L('Login'), |
401 | 'text' => _L('Login'), |
376 | 'state' => array("opened" => count($loginChildren)>0), |
402 | 'state' => array("opened" => count($loginChildren)>0), |
377 | 'children' => $loginChildren |
403 | 'children' => $loginChildren |
378 | ); |
404 | ); |
379 | 405 | ||
380 | return true; |
406 | return true; |
381 | } |
407 | } |
382 | 408 | ||
383 | /** |
409 | /** |
384 | * @param string $request |
410 | * @param string $request |
385 | * @return array|false |
411 | * @return array|false |
386 | */ |
412 | */ |
387 | public function tree_search(string $request) { |
413 | public function tree_search(string $request) { |
388 | return false; |
414 | return false; |
389 | } |
415 | } |
390 | } |
416 | } |
391 | 417 |