Passed
Push — development ( fb8b55...b814ca )
by Nils
08:04
created
Severity
1
<?php
2
/**
3
 *
4
 * @package       index.php
5
 * @author        Nils Laumaillé <[email protected]>
6
 * @version       2.1.27
7
 * @copyright     2009-2018 Nils Laumaillé
8
 * @license       GNU GPL-3.0
9
 * @link          https://www.teampass.net
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
16
header("X-XSS-Protection: 1; mode=block");
17
header("X-Frame-Options: SameOrigin");
18
19
// **PREVENTING SESSION HIJACKING**
20
// Prevents javascript XSS attacks aimed to steal the session ID
21
ini_set('session.cookie_httponly', 1);
22
23
// **PREVENTING SESSION FIXATION**
24
// Session ID cannot be passed through URLs
25
ini_set('session.use_only_cookies', 1);
26
27
// Uses a secure connection (HTTPS) if possible
28
ini_set('session.cookie_secure', 0);
29
30
// Before we start processing, we should abort no install is present
31
if (!file_exists('includes/config/settings.php')) {
32
    // This should never happen, but in case it does
33
    // this means if headers are sent, redirect will fallback to JS
34
    if (headers_sent()) {
35
        echo '<script language="javascript" type="text/javascript">document.location.replace("install/install.php");</script>';
36
    } else {
37
        header('Location: install/install.php');
38
    }
39
    // Now either way, we should stop processing further
40
    exit();
41
}
42
43
// initialise CSRFGuard library
44
require_once './includes/libraries/csrfp/libs/csrf/csrfprotector.php';
45
csrfProtector::init();
46
session_id();
47
48
// Load config
49
if (file_exists('../includes/config/tp.config.php') === true) {
50
    include_once '../includes/config/tp.config.php';
51
} elseif (file_exists('./includes/config/tp.config.php') === true) {
52
    include_once './includes/config/tp.config.php';
53
} else {
54
    throw new Exception("Error file '/includes/config/tp.config.php' not exists", 1);
55
}
56
57
// Include files
58
require_once $SETTINGS['cpassman_dir'].'/includes/config/settings.php';
59
require_once $SETTINGS['cpassman_dir'].'/includes/config/include.php';
60
require_once $SETTINGS['cpassman_dir'].'/includes/libraries/protect/SuperGlobal/SuperGlobal.php';
61
$superGlobal = new protect\SuperGlobal\SuperGlobal();
62
63
// initialize session
64
$_SESSION['CPM'] = 1;
65
if (isset($SETTINGS['cpassman_dir']) === false || $SETTINGS['cpassman_dir'] === "") {
66
    $SETTINGS['cpassman_dir'] = ".";
67
    $SETTINGS['cpassman_url'] = $superGlobal->get("REQUEST_URI", "SERVER");
68
}
69
70
// Include files
71
require_once $SETTINGS['cpassman_dir'].'/sources/SplClassLoader.php';
72
require_once $SETTINGS['cpassman_dir'].'/sources/main.functions.php';
73
74
// Open MYSQL database connection
75
require_once './includes/libraries/Database/Meekrodb/db.class.php';
76
$pass = defuse_return_decrypted($pass);
77
DB::$host = $server;
78
DB::$user = $user;
79
DB::$password = $pass;
80
DB::$dbName = $database;
81
DB::$port = $port;
82
DB::$encoding = $encoding;
83
DB::$error_handler = true;
84
$link = mysqli_connect($server, $user, $pass, $database, $port);
85
$link->set_charset($encoding);
86
87
// Load Core library
88
require_once $SETTINGS['cpassman_dir'].'/sources/core.php';
89
90
// Prepare POST variables
91
$post_language = filter_input(INPUT_POST, 'language', FILTER_SANITIZE_STRING);
92
$post_sig_response = filter_input(INPUT_POST, 'sig_response', FILTER_SANITIZE_STRING);
93
$post_duo_login = filter_input(INPUT_POST, 'duo_login', FILTER_SANITIZE_STRING);
94
$post_duo_pwd = filter_input(INPUT_POST, 'duo_pwd', FILTER_SANITIZE_STRING);
95
$post_duo_data = filter_input(INPUT_POST, 'duo_data', FILTER_SANITIZE_STRING);
96
$post_login = filter_input(INPUT_POST, 'login', FILTER_SANITIZE_STRING);
97
$post_pw = filter_input(INPUT_POST, 'pw', FILTER_SANITIZE_STRING);
98
99
// Prepare superGlobal variables
100
$session_user_language = $superGlobal->get("user_language", "SESSION");
101
$session_user_id = $superGlobal->get("user_id", "SESSION");
102
$session_user_flag = $superGlobal->get("user_language_flag", "SESSION");
103
$session_user_admin = $superGlobal->get("user_admin", "SESSION");
104
$session_user_human_resources = $superGlobal->get("user_can_manage_all_users", "SESSION");
105
$session_user_avatar_thumb = $superGlobal->get("user_avatar_thumb", "SESSION");
106
$session_name = $superGlobal->get("name", "SESSION");
107
$session_lastname = $superGlobal->get("lastname", "SESSION");
108
$session_user_manager = $superGlobal->get("user_manager", "SESSION");
109
$session_user_read_only = $superGlobal->get("user_read_only", "SESSION");
110
$session_is_admin = $superGlobal->get("is_admin", "SESSION");
111
$session_login = $superGlobal->get("login", "SESSION");
112
$session_validite_pw = $superGlobal->get("validite_pw", "SESSION");
113
$session_nb_folders = $superGlobal->get("nb_folders", "SESSION");
114
$session_nb_roles = $superGlobal->get("nb_roles", "SESSION");
115
$session_autoriser = $superGlobal->get("autoriser", "SESSION");
116
$session_hide_maintenance = $superGlobal->get("hide_maintenance", "SESSION");
117
$session_initial_url = $superGlobal->get("initial_url", "SESSION");
118
$server_request_uri = $superGlobal->get("REQUEST_URI", "SERVER");
119
$session_nb_users_online = $superGlobal->get("nb_users_online", "SESSION");
120
121
/* DEFINE WHAT LANGUAGE TO USE */
122
if (isset($_GET['language']) === true) {
123
    // case of user has change language in the login page
124
    $dataLanguage = DB::queryFirstRow(
125
        "SELECT flag, name
126
        FROM " . prefix_table("languages")."
127
        WHERE name = %s",
128
        filter_var($_GET['language'], FILTER_SANITIZE_STRING)
129
    );
130
    $superGlobal->put("user_language", $dataLanguage['name'], "SESSION");
131
    $superGlobal->put("user_language_flag", $dataLanguage['flag'], "SESSION");
132
} elseif ($session_user_id === null && null === $post_language && $session_user_language === null) {
133
    //get default language
134
    $dataLanguage = DB::queryFirstRow(
135
        "SELECT m.valeur AS valeur, l.flag AS flag
136
        FROM " . prefix_table("misc")." AS m
137
        INNER JOIN " . prefix_table("languages")." AS l ON (m.valeur = l.name)
138
        WHERE m.type=%s_type AND m.intitule=%s_intitule",
139
        array(
140
            'type' => "admin",
141
            'intitule' => "default_language",
142
        )
143
    );
144
    if (empty($dataLanguage['valeur'])) {
145
        $superGlobal->put("user_language", "english", "SESSION");
146
        $superGlobal->put("user_language_flag", "us.png", "SESSION");
147
        $session_user_language = "english";
148
    } else {
149
        $superGlobal->put("user_language", $dataLanguage['valeur'], "SESSION");
150
        $superGlobal->put("user_language_flag", $dataLanguage['flag'], "SESSION");
151
        $session_user_language = $dataLanguage['valeur'];
152
    }
153
} elseif (isset($SETTINGS['default_language']) === true && $session_user_language === null) {
154
    $superGlobal->put("user_language", $SETTINGS['default_language'], "SESSION");
155
    $session_user_language = $SETTINGS['default_language'];
156
} elseif (null !== $post_language) {
157
    $superGlobal->put("user_language", $post_language, "SESSION");
158
    $session_user_language = $post_language;
159
} elseif ($session_user_language === null || empty($session_user_language) === true) {
160
    if (null !== $post_language) {
161
        $superGlobal->put("user_language", $post_language, "SESSION");
162
        $session_user_language = $post_language;
163
    } elseif ($session_user_language !== null) {
164
        $superGlobal->put("user_language", $SETTINGS['default_language'], "SESSION");
165
        $session_user_language = $SETTINGS['default_language'];
166
    }
167
} elseif ($session_user_language === '0') {
168
    $superGlobal->put("user_language", $SETTINGS['default_language'], "SESSION");
169
    $session_user_language = $SETTINGS['default_language'];
170
}
171
172
if (isset($SETTINGS['cpassman_dir']) === false || $SETTINGS['cpassman_dir'] === "") {
173
    $SETTINGS['cpassman_dir'] = ".";
174
    $SETTINGS['cpassman_url'] = (string) $server_request_uri;
175
}
176
177
// Load user languages files
178
if (in_array($session_user_language, $languagesList) === true) {
179
    if (file_exists($SETTINGS['cpassman_dir'].'/includes/language/'.$session_user_language.'.php') === true) {
180
        include_once $SETTINGS['cpassman_dir'].'/includes/language/'.$session_user_language.'.php';
181
    }
182
} else {
183
    $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
184
    include $SETTINGS['cpassman_dir'].'/error.php';
185
}
186
187
// load 2FA Google
188
if (isset($SETTINGS['google_authentication']) === true && $SETTINGS['google_authentication'] === "1") {
189
    include_once $SETTINGS['cpassman_dir']."/includes/libraries/Authentication/TwoFactorAuth/TwoFactorAuth.php";
190
}
191
192
// load 2FA Yubico
193
if (isset($SETTINGS['yubico_authentication']) === true && $SETTINGS['yubico_authentication'] === "1") {
194
    include_once $SETTINGS['cpassman_dir']."/includes/libraries/Authentication/Yubico/Yubico.php";
195
}
196
197
// Load links, css and javascripts
198
if (isset($_SESSION['CPM']) === true && isset($SETTINGS['cpassman_dir']) === true) {
199
    include_once $SETTINGS['cpassman_dir'].'/load.php';
200
}
201
202
?>
203
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
204
205
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
206
<head>
207
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
208
<meta http-equiv="X-UA-Compatible" content="IE=edge">
209
<title>Teampass</title>
210
<script type="text/javascript">
211
    //<![CDATA[
212
    if (window.location.href.indexOf("page=") == -1 && (window.location.href.indexOf("otv=") == -1 && window.location.href.indexOf("action=") == -1)) {
213
        if (window.location.href.indexOf("session_over=true") == -1) {
214
            //location.replace("./index.php?page=items");
215
        } else {
216
            location.replace("./logout.php");
217
        }
218
    }
219
    //]]>
220
</script>
221
<?php
222
223
// load HEADERS
224
if (isset($_SESSION['CPM']) === true) {
225
    echo $htmlHeaders;
226
}
227
?>
228
    </head>
229
230
<body>
231
    <?php
232
    
233
/* HEADER */
234
echo '
235
    <div id="top">
236
        <div id="logo"><img src="includes/images/canevas/logo.png" alt="" /></div>';
237
// Display menu
238
if (empty($session_login) === false) {
239
    // welcome message
240
    echo '
241
        <div style="float:right; margin:-10px 5px 0 0; color:#FFF;">'
242
    . $LANG['index_welcome'].'&nbsp;<b>'.$session_name.'&nbsp;'.$session_lastname
243
    . '&nbsp;['.$session_login.']</b>&nbsp;-&nbsp;'
244
    , $session_user_admin === '1' ? $LANG['god'] : (
245
        $session_user_manager === '1' ? $LANG['gestionnaire'] : (
246
            $session_user_read_only === '1' ? $LANG['read_only_account'] : ($session_user_human_resources === '1' ? $LANG['human_resources'] : $LANG['user'])
247
        )
248
    ), '&nbsp;'.strtolower($LANG['index_login']).'</div>';
249
250
    echo '
251
        <div id="menu_top">
252
            <div style="margin-left:20px; margin-top:2px;width:710px;" id="main_menu">';
253
    if ($session_user_admin === '0' || $SETTINGS_EXT['admin_full_right'] == 0) {
254
        echo '
255
                <a class="btn btn-default" href="#"',
256
        ($session_nb_folders !== null && intval($session_nb_folders) === 0)
257
        || ($session_nb_roles !== null && intval($session_nb_roles) === 0) ? '' : ' onclick="MenuAction(\'items\')"',
258
        '>
259
                    <i class="fa fa-key fa-2x tip" title="' . $LANG['pw'].'"></i>
260
                </a>
261
262
                <a class="btn btn-default" href="#"',
263
        ($session_nb_folders !== null && intval($session_nb_folders) === 0)
264
        || ($session_nb_roles !== null && intval($session_nb_roles) === 0) ? '' : ' onclick="MenuAction(\'find\')"',
265
            '>
266
                    <i class="fa fa-binoculars fa-2x tip" title="' . $LANG['find'].'"></i>
267
                </a>';
268
    }
269
270
    // Favourites menu
271
    if (isset($SETTINGS['enable_favourites'])
272
        && $SETTINGS['enable_favourites'] == 1
273
        &&
274
        ($session_user_admin === '0' || ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === false))
275
    ) {
276
        echo '
277
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'favourites\')">
278
                        <i class="fa fa-star fa-2x tip" title="' . $LANG['my_favourites'].'"></i>
279
                    </a>';
280
    }
281
    // KB menu
282
    if (isset($SETTINGS['enable_kb']) && $SETTINGS['enable_kb'] == 1) {
283
        echo '
284
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'kb\')">
285
                        <i class="fa fa-map-signs fa-2x tip" title="' . $LANG['kb_menu'].'"></i>
286
                    </a>';
287
    }
288
    echo '
289
        <span id="menu_suggestion_position">';
290
    // SUGGESTION menu
291
    if (isset($SETTINGS['enable_suggestion']) === true && $SETTINGS['enable_suggestion'] === '1'
292
        && ($session_user_admin === '1' || $session_user_manager === '1')
293
        // Removed this condition in previous $session_user_read_only === '1' || 
294
    ) {
295
        echo '
296
                <a class="btn btn-default" href="#" onclick="MenuAction(\'suggestion\')">
297
                    <i class="fa fa-lightbulb-o fa-2x tip" id="menu_icon_suggestions" title="' . $LANG['suggestion_menu'].'"></i>
298
                </a>';
299
    }
300
    echo '
301
        </span>';
302
    // Admin menu
303
    if ($session_user_admin === '1') {
304
        echo '
305
                    &nbsp;
306
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_main\')">
307
                        <i class="fa fa-info fa-2x tip" title="' . $LANG['admin_main'].'"></i>
308
                    </a>
309
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_settings\')">
310
                        <i class="fa fa-wrench fa-2x tip" title="' . $LANG['admin_settings'].'"></i>
311
                    </a>';
312
    }
313
314
    if ($session_user_admin === '1' || $session_user_manager === '1' || $session_user_human_resources === '1') {
315
        echo '
316
                &nbsp;
317
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_folders\')">
318
                    <i class="fa fa-folder-open fa-2x tip" title="' . $LANG['admin_groups'].'"></i>
319
                </a>
320
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_roles\')">
321
                    <i class="fa fa-graduation-cap fa-2x tip" title="' . $LANG['admin_functions'].'"></i>
322
                </a>
323
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_users\')">
324
                    <i class="fa fa-users fa-2x tip" title="' . $LANG['admin_users'].'"></i>
325
                </a>
326
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_views\')">
327
                    <i class="fa fa-cubes fa-2x tip" title="' . $LANG['admin_views'].'"></i>
328
                </a>';
329
    }
330
331
    echo '
332
                <div style="float:right;">
333
                    <ul class="menu" style="">
334
                        <li class="" style="padding:4px;width:40px; text-align:center;"><i class="fa fa-dashboard fa-fw"></i>&nbsp;
335
                            <ul class="menu_200" style="text-align:left;">',
336
    ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === true) ? '' : isset($SETTINGS['enable_pf_feature']) === true && $SETTINGS['enable_pf_feature'] == 1 ? '
337
                                <li onclick="$(\'#div_set_personal_saltkey\').dialog(\'open\')">
338
                                    <i class="fa fa-key fa-fw"></i> &nbsp;' . $LANG['home_personal_saltkey_button'].'
339
                                </li>' : '', '
340
                                <li onclick="$(\'#div_increase_session_time\').dialog(\'open\')">
341
                                    <i class="fa fa-clock-o fa-fw"></i> &nbsp;' . $LANG['index_add_one_hour'].'
342
                                </li>
343
                                <li onclick="loadProfileDialog()">
344
                                    <i class="fa fa-user fa-fw"></i> &nbsp;' . $LANG['my_profile'].'
345
                                </li>
346
                                <li onclick="MenuAction(\'deconnexion\', \'' . $session_user_id.'\')">
347
                                    <i class="fa fa-sign-out fa-fw"></i> &nbsp;' . $LANG['disconnect'].'
348
                                </li>
349
                            </ul>
350
                        </li>
351
                    </ul>
352
                </div>';
353
354
    if ($session_user_admin !== '1' || ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === false)) {
355
        echo '
356
                <div style="float:right; margin-right:10px;">
357
                    <ul class="menu" id="menu_last_seen_items">
358
                        <li class="" style="padding:4px;width:40px; text-align:center;"><i class="fa fa-map fa-fw"></i>&nbsp;&nbsp;
359
                            <ul class="menu_200" id="last_seen_items_list" style="text-align:left;">
360
                                <li>' . $LANG['please_wait'].'</li>
361
                            </ul>
362
                        </li>
363
                    </ul>
364
                </div>';
365
    }
366
367
    // show avatar
368
    if ($session_user_avatar_thumb !== null && empty($session_user_avatar_thumb) === false) {
369
        if (file_exists('includes/avatars/'.$session_user_avatar_thumb)) {
370
            $avatar = $SETTINGS['cpassman_url'].'/includes/avatars/'.$session_user_avatar_thumb;
371
        } else {
372
            $avatar = $SETTINGS['cpassman_url'].'/includes/images/photo.jpg';
373
        }
374
    } else {
375
        $avatar = $SETTINGS['cpassman_url'].'/includes/images/photo.jpg';
376
    }
377
    echo '
378
                <div style="float:right; margin-right:10px;">
379
                    <img src="' . $avatar.'" style="border-radius:10px; height:28px; cursor:pointer;" onclick="loadProfileDialog()" alt="photo" id="user_avatar_thumb" />
380
                </div>';
381
382
    echo '
383
            </div>';
384
385
    echo '
386
        </div>';
387
}
388
389
echo '
390
    </div>';
391
392
echo '
393
<div id="main_info_box" style="display:none; z-index:99999; position:absolute; width:400px; height:40px;" class="ui-widget ui-state-active ui-color">
394
    <span class="closeButton" onclick="$(\'#main_info_box\').hide()">&#10006</span>
395
    <div id="main_info_box_text" style="text-align:center;margin-top:10px;"></div>
396
</div>';
397
398
/* MAIN PAGE */
399
echo '
400
        <input type="hidden" id="temps_restant" value="', isset($_SESSION['fin_session']) ? $_SESSION['fin_session'] : '', '" />
401
        <input type="hidden" name="language" id="language" value="" />
402
        <input type="hidden" name="user_pw_complexity" id="user_pw_complexity" value="', isset($_SESSION['user_pw_complexity']) ? $_SESSION['user_pw_complexity'] : '', '" />
403
        <input type="hidden" name="user_session" id="user_session" value=""/>
404
        <input type="hidden" name="encryptClientServer" id="encryptClientServer" value="', isset($SETTINGS['encryptClientServer']) ? $SETTINGS['encryptClientServer'] : '1', '" />
405
        <input type="hidden" name="please_login" id="please_login" value="" />
406
        <input type="hidden" name="disabled_action_on_going" id="disabled_action_on_going" value="" />
407
        <input type="hidden" id="duo_sig_response" value="', null !== $post_sig_response ? $post_sig_response : '', '" />';
408
409
// SENDING STATISTICS?
410
if (isset($SETTINGS['send_stats']) && $SETTINGS['send_stats'] === "1"
411
    && (!isset($_SESSION['temporary']['send_stats_done']) || $_SESSION['temporary']['send_stats_done'] !== "1")
412
) {
413
    echo '
414
            <input type="hidden" name="send_statistics" id="send_statistics" value="1" />';
415
} else {
416
    echo '
417
        <input type="hidden" name="send_statistics" id="send_statistics" value="0" />';
418
}
419
420
echo '
421
    <div id="', (isset($_GET['page']) && filter_var($_GET['page'], FILTER_SANITIZE_STRING) === "items" && $session_user_id !== null) ? "main_simple" : "main", '">';
422
// MESSAGE BOX
423
echo '
424
            <div style="" class="div_center">
425
                <div id="message_box" style="display:none;width:200px;padding:5px;text-align:center; z-index:999999;" class="ui-widget-content ui-state-error ui-corner-all"></div>
426
            </div>';
427
// Main page
428
if ($session_autoriser !== null && $session_autoriser === true) {
429
    // Show menu
430
    echo '
431
            <form method="post" name="main_form" action="">
432
                <input type="hidden" name="menu_action" id="menu_action" value="" />
433
                <input type="hidden" name="changer_pw" id="changer_pw" value="" />
434
                <input type="hidden" name="form_user_id" id="form_user_id" value="', $session_user_id !== null ? $session_user_id : '', '" />
435
                <input type="hidden" name="is_admin" id="is_admin" value="', $session_is_admin !== null ? $session_is_admin : '', '" />
436
                <input type="hidden" name="personal_saltkey_set" id="personal_saltkey_set" value="', isset($_SESSION['user_settings']['clear_psk']) ? true : false, '" />
437
            </form>';
438
}
439
// ---------
440
// Display a help to admin
441
$errorAdmin = $nextUrl = "";
442
443
// error nb folders
444
if ($session_nb_folders !== null && intval($session_nb_folders) === 0) {
445
    $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_folders'].'<br />';
446
}
447
// error nb roles
448
if ($session_nb_roles !== null && intval($session_nb_roles) === 0) {
449
    if (empty($errorAdmin)) {
450
        $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_roles'];
451
    } else {
452
        $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_roles'];
453
    }
454
}
455
456
if ($session_validite_pw !== null && empty($session_validite_pw) === false) {
457
    // error cpassman dir
458
    if (isset($SETTINGS['cpassman_dir']) && empty($SETTINGS['cpassman_dir']) || !isset($SETTINGS['cpassman_dir'])) {
0 ignored issues
show
Consider adding parentheses for clarity. Current Interpretation: (IssetNode && empty($SET..._dir'])) || ! IssetNode, Probably Intended Meaning: IssetNode && (empty($SET..._dir']) || ! IssetNode)
Loading history...
459
        if (empty($errorAdmin)) {
460
            $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_dir'];
461
        } else {
462
            $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_dir'];
463
        }
464
    }
465
    // error cpassman url
466
    if ($session_validite_pw !== null && (isset($SETTINGS['cpassman_url']) && empty($SETTINGS['cpassman_url']) || !isset($SETTINGS['cpassman_url']))) {
467
        if (empty($errorAdmin)) {
468
            $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_url'];
469
        } else {
470
            $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_url'];
471
        }
472
    }
473
}
474
// Display help
475
if (!empty($errorAdmin)) {
476
    echo '
477
                <div style="margin:10px;padding:10px;" class="ui-state-error ui-corner-all">
478
                ' . $errorAdmin.'
479
                </div>';
480
}
481
// -----------
482
// Display Maintenance mode information
483
if (isset($SETTINGS['maintenance_mode']) === true && $SETTINGS['maintenance_mode'] === '1'
484
    && $session_user_admin !== null && $session_user_admin === '1'
485
) {
486
    echo '
487
            <div style="text-align:center;margin-bottom:5px;padding:10px;" class="ui-state-highlight ui-corner-all">
488
                <b>' . $LANG['index_maintenance_mode_admin'].'</b>
489
            </div>';
490
}
491
// Display UPDATE NEEDED information
492
if (isset($SETTINGS['update_needed']) && $SETTINGS['update_needed'] === true
493
    && $session_user_admin !== null && $session_user_admin === '1'
494
    && (($session_hide_maintenance !== null && $session_hide_maintenance === '0')
495
    || $session_hide_maintenance === null)
496
) {
497
    echo '
498
            <div style="text-align:center;margin-bottom:5px;padding:10px;"
499
                class="ui-state-highlight ui-corner-all" id="div_maintenance">
500
                <b>' . $LANG['update_needed_mode_admin'].'</b>
501
                <span style="float:right;cursor:pointer;">
502
                    <span class="fa fa-close mi-red" onclick="toggleDiv(\'div_maintenance\')"></span>
503
                </span>
504
            </div>';
505
}
506
507
// display an item in the context of OTV link
508
if (($session_validite_pw === null || empty($session_validite_pw) === true || empty($session_user_id) === true) &&
509
    isset($_GET['otv']) && filter_var($_GET['otv'], FILTER_SANITIZE_STRING) === 'true'
510
) {
511
    // case where one-shot viewer
512
    if (isset($_GET['code']) && !empty($_GET['code'])
513
        && isset($_GET['stamp']) && !empty($_GET['stamp'])
514
    ) {
515
        include 'otv.php';
516
    } else {
517
        $_SESSION['error']['code'] = ERR_VALID_SESSION;
518
        $superGlobal->put(
519
            "initial_url",
520
            filter_var(
521
                substr($server_request_uri, strpos($server_request_uri, "index.php?")),
522
                FILTER_SANITIZE_URL
523
            ),
524
            "SESSION"
525
        );
526
        include $SETTINGS['cpassman_dir'].'/error.php';
527
    }
528
    // Ask the user to change his password
529
} elseif (($session_validite_pw === null || $session_validite_pw === false)
530
    && empty($session_user_id) === false
531
) {
532
    //Check if password is valid
533
    echo '
534
        <div style="margin:auto; padding:20px; width:500px;" class="ui-state-focus ui-corner-all">
535
            <h3>' . $LANG['index_change_pw'].'</h3>
536
            <div style="height:20px;text-align:center;margin:2px;display:none;" id="change_pwd_error" class=""></div>
537
            <div style="text-align:center;margin:5px;padding:3px;" id="change_pwd_complexPw" class="ui-widget ui-state-active ui-corner-all">' .
538
        $LANG['complex_asked'].' : '.$SETTINGS_EXT['pwComplexity'][$_SESSION['user_pw_complexity']][1].
539
        '</div>
540
            <div id="pw_strength" style="margin:0 0 10px 140px;"></div>
541
            <table>
542
                <tr>
543
                    <td>' . $LANG['index_new_pw'].' :</td><td><input type="password" size="15" name="new_pw" id="new_pw"/></td>
544
                </tr>
545
                <tr><td>' . $LANG['index_change_pw_confirmation'].' :</td><td><input type="password" size="15" name="new_pw2" id="new_pw2" onkeypress="if (event.keyCode == 13) ChangeMyPass();" /></td></tr>
546
            </table>
547
            <input type="hidden" id="pw_strength_value" />
548
            <div style="width:420px; text-align:center; margin:15px 0 10px 0;">
549
                <input type="button" onClick="ChangeMyPass()" onkeypress="if (event.keyCode == 13) ChangeMyPass();" class="ui-state-default ui-corner-all" style="padding:4px;width:150px;margin:10px 0 0 80px;" value="' . $LANG['index_change_pw_button'].'" />
550
            </div>
551
        </div>
552
        <script type="text/javascript">
553
            $("#new_pw").focus();
554
        </script>';
555
// Display pages
556
} elseif ($session_validite_pw !== null
557
    && $session_validite_pw === true
558
    && empty($_GET['page']) === false
559
    && empty($session_user_id) === false
560
) {
561
    if ($session_initial_url !== null && empty($session_initial_url) === false) {
562
        include $session_initial_url;
563
    } elseif ($_GET['page'] == "items") {
564
        // SHow page with Items
565
        if (($session_user_admin !== '1')
566
            ||
567
            ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === false)
568
        ) {
569
            include 'items.php';
570
        } else {
571
            $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
572
            include $SETTINGS['cpassman_dir'].'/error.php';
573
        }
574
    } elseif ($_GET['page'] == "find") {
575
        // Show page for items findind
576
        include 'find.php';
577
    } elseif ($_GET['page'] == "favourites") {
578
        // Show page for user favourites
579
        include 'favorites.php';
580
    } elseif ($_GET['page'] == "kb") {
581
        // Show page KB
582
        if (isset($SETTINGS['enable_kb']) && $SETTINGS['enable_kb'] == 1) {
583
            include 'kb.php';
584
        } else {
585
            $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
586
            include $SETTINGS['cpassman_dir'].'/error.php';
587
        }
588
    } elseif ($_GET['page'] == "suggestion") {
589
        // Show page KB
590
        if (isset($SETTINGS['enable_suggestion']) && $SETTINGS['enable_suggestion'] == 1) {
591
            include 'suggestion.php';
592
        } else {
593
            $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
594
            include $SETTINGS['cpassman_dir'].'/error.php';
595
        }
596
    } elseif (in_array($_GET['page'], array_keys($mngPages))) {
597
        // Define if user is allowed to see management pages
598
        if ($session_user_admin === '1') {
599
            include $mngPages[$_GET['page']];
600
        } elseif ($session_user_manager === '1' || $session_user_human_resources == '1') {
601
            if (($_GET['page'] != "manage_main" && $_GET['page'] != "manage_settings")) {
602
                include $mngPages[$_GET['page']];
603
            } else {
604
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
605
                include $SETTINGS['cpassman_dir'].'/error.php';
606
            }
607
        } else {
608
            $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
609
            include $SETTINGS['cpassman_dir'].'/error.php';
610
        }
611
    } else {
612
        $_SESSION['error']['code'] = ERR_NOT_EXIST; //page doesn't exist
613
        include $SETTINGS['cpassman_dir'].'/error.php';
614
    }
615
    // Case of password recovery
616
} elseif (isset($_GET['action']) === true && $_GET['action'] === "password_recovery"
617
    && isset($_GET['key']) === true
618
    && isset($_GET['login']) === true
619
) {
620
    // Case where user has asked new PW
621
    echo '
622
            <div style="width:400px;margin:50px auto 50px auto;padding:25px;" class="ui-state-highlight ui-corner-all">
623
                <div style="text-align:center;font-weight:bold;margin-bottom:20px;">
624
                    ' . $LANG['pw_recovery_asked'].'
625
                </div>
626
                <div id="generate_new_pw_error" style="color:red;display:none;text-align:center;margin:5px;"></div>
627
                <div style="margin-bottom:3px;">
628
                    ' . $LANG['pw_recovery_info'].'
629
                </div>
630
                <div style="margin:15px; text-align:center;">
631
                    <input type="button" id="but_generate_new_password" style="padding:3px;cursor:pointer;" class="ui-state-default ui-corner-all" value="'.$LANG['pw_recovery_button'].'" />
632
                    <br /><br />
633
                    <div id="ajax_loader_send_mail" style="display:none; margin: 20px;"><span class="fa fa-cog fa-spin fa-2x"></span></div>
634
                </div>
635
                <div style="margin-top:30px; text-align:center;">
636
                    <a href="index.php" class="tip" title="' . $LANG['home'].'"><span class="fa fa-home fa-lg"></span></a>
637
                </div>
638
            </div>';
639
} elseif (empty($session_user_id) === false && $session_user_id !== null) {
640
    // Page doesn't exist
641
    $_SESSION['error']['code'] = ERR_NOT_EXIST;
642
    include $SETTINGS['cpassman_dir'].'/error.php';
643
// When user is not identified
644
} else {
645
    // Automatic redirection
646
    if (strpos($server_request_uri, "?") > 0) {
647
        $nextUrl = filter_var(substr($server_request_uri, strpos($server_request_uri, "?")), FILTER_SANITIZE_URL);
648
    }
649
    // MAINTENANCE MODE
650
    if (isset($SETTINGS['maintenance_mode']) === true && $SETTINGS['maintenance_mode'] === '1') {
651
        echo '
652
                <div style="text-align:center;margin-top:30px;margin-bottom:20px;padding:10px;"
653
                    class="ui-state-error ui-corner-all">
654
                    <b>' . addslashes($LANG['index_maintenance_mode']).'</b>
655
                </div>';
656
    } elseif (isset($_GET['session_over']) && $_GET['session_over'] === 'true') {
657
        // SESSION FINISHED => RECONNECTION ASKED
658
        echo '
659
                    <div style="text-align:center;margin-top:30px;margin-bottom:20px;padding:10px;"
660
                        class="ui-state-error ui-corner-all">
661
                        <b>' . addslashes($LANG['index_session_expired']).'</b>
662
                    </div>';
663
    }
664
665
    // case where user not logged and can't access a direct link
666
    if (empty($_GET['page']) === false) {
667
        $superGlobal->put(
668
            "initial_url",
669
            filter_var(
670
                substr($server_request_uri, strpos($server_request_uri, "index.php?")),
671
                FILTER_SANITIZE_URL
672
            ),
673
            "SESSION"
674
        );
675
        // REDIRECTION PAGE ERREUR
676
        echo '
677
            <script language="javascript" type="text/javascript">
678
            <!--
679
                sessionStorage.clear();
680
                window.location.href = "index.php";
681
            -->
682
            </script>';
683
        exit;
684
    } else {
685
        $superGlobal->put("initial_url", '', "SESSION");
686
    }
687
688
    // CONNECTION FORM
689
    echo '
690
                <form method="post" name="form_identify" id="form_identify" action="">
691
                    <div style="width:480px;margin:10px auto 10px auto;padding:25px;" class="ui-state-highlight ui-corner-all">
692
                        <div style="text-align:center;font-weight:bold;margin-bottom:20px;">',
693
    isset($SETTINGS['custom_logo']) && !empty($SETTINGS['custom_logo']) ? '<img src="'.(string) $SETTINGS['custom_logo'].'" alt="" style="margin-bottom:40px;" />' : '', '<br />
694
                            ' . $LANG['index_get_identified'].'
695
                            <span id="ajax_loader_connexion" style="display:none;margin-left:10px;"><span class="fa fa-cog fa-spin fa-1x"></span></span>
696
                        </div>
697
                        <div id="connection_error" style="display:none;text-align:center;margin:5px; padding:3px;" class="ui-state-error ui-corner-all">&nbsp;<i class="fa fa-warning"></i>&nbsp;' . $LANG['index_bas_pw'].'</div>';
698
699
    if (isset($SETTINGS['enable_http_request_login']) === true
700
        && $SETTINGS['enable_http_request_login'] === '1'
701
        && isset($_SERVER['PHP_AUTH_USER']) === true
702
        && !(isset($SETTINGS['maintenance_mode']) === true
703
            && $SETTINGS['maintenance_mode'] === '1')
704
    ) {
705
        if (strpos($_SERVER['PHP_AUTH_USER'], '@') !== false) {
706
            $username = explode("@", $_SERVER['PHP_AUTH_USER'])[0];
707
        } elseif (strpos($_SERVER['PHP_AUTH_USER'], '\\') !== false) {
708
            $username = explode("\\", $_SERVER['PHP_AUTH_USER'])[1];
709
        } else {
710
            $username = $_SERVER['PHP_AUTH_USER'];
711
        }
712
        echo '
713
        				<div style="margin-bottom:3px;">
714
        			        <label for="login" class="form_label">', isset($SETTINGS['custom_login_text']) && !empty($SETTINGS['custom_login_text']) ? (string) $SETTINGS['custom_login_text'] : $LANG['index_login'], '</label>
715
        		            <input type="text" size="10" id="login" name="login" class="input_text text ui-widget-content ui-corner-all" value="', filter_var($username, FILTER_SANITIZE_STRING), '" readonly />
716
        		            <span id="login_check_wait" style="display:none; float:right;"><i class="fa fa-cog fa-spin fa-1x"></i></span>
717
                        </div>';
718
    } else {
719
        echo '
720
                    	    <div style="margin-bottom:3px;">
721
                    	        <label for="login" class="form_label">', isset($SETTINGS['custom_login_text']) && !empty($SETTINGS['custom_login_text']) ? (string) $SETTINGS['custom_login_text'] : $LANG['index_login'], '</label>
722
                                <input type="text" size="10" id="login" name="login" class="input_text text ui-widget-content ui-corner-all" value="', empty($post_login) === false ? $post_login : '', '" />
723
                                <span id="login_check_wait" style="display:none; float:right;"><i class="fa fa-cog fa-spin fa-1x"></i></span>
724
                           </div>';
725
    }
726
727
    if (!(isset($SETTINGS['enable_http_request_login']) === true
728
        && $SETTINGS['enable_http_request_login'] === '1'
729
        && isset($_SERVER['PHP_AUTH_USER']) === true
730
        && !(isset($SETTINGS['maintenance_mode']) === true && $SETTINGS['maintenance_mode'] === '1'))
731
    ) {
732
        echo '
733
                        <div id="connect_pw" style="margin-bottom:3px;">
734
                            <label for="pw" class="form_label" id="user_pwd">' . $LANG['index_password'].'</label>
735
                            <input type="password" size="10" id="pw" name="pw" class="input_text text ui-widget-content ui-corner-all submit-button" value="', empty($post_pw) === false ? $post_pw : '', '" />
736
                        </div>';
737
    }
738
739
    echo '
740
                        <div style="margin-bottom:3px;">
741
                            <label for="duree_session" class="">' . $LANG['index_session_duration'].'&nbsp;('.$LANG['minutes'].') </label>
742
                            <input type="text" size="4" id="duree_session" name="duree_session" value="', isset($SETTINGS['default_session_expiration_time']) ? $SETTINGS['default_session_expiration_time'] : "60", '" class="input_text text ui-widget-content ui-corner-all numeric_only submit-button" />
743
                        </div>';
744
745
    // 2FA auth selector
746
    echo '
747
                        <input type="hidden" id="2fa_agses" value="', isset($SETTINGS['agses_authentication_enabled']) === true && $SETTINGS['agses_authentication_enabled'] === '1' ? '1' : '0', '" />
748
                        <input type="hidden" id="2fa_duo" value="', isset($SETTINGS['duo']) === true && $SETTINGS['duo'] === '1' ? '1' : '0', '" />
749
                        <input type="hidden" id="2fa_google" value="', isset($SETTINGS['google_authentication']) === true && $SETTINGS['google_authentication'] === '1' ? '1' : '0', '" />
750
                        <input type="hidden" id="2fa_yubico" value="', isset($SETTINGS['yubico_authentication']) === true && $SETTINGS['yubico_authentication'] === '1' ? '1' : '0', '" />
751
                        <input type="hidden" id="2fa_user_selection" value="', 
752
                            (isset($_GET['post_type']) === true && $_GET['post_type'] === 'duo' ? 'duo' : '')
753
                        , '" />
754
                        <div id="2fa_selector" class="hidden">
755
                            <div>
756
                                <legend>'.addslashes($LANG['2fa_authentication_selector']).'</legend>
757
                                <div id="2fa_methods_selector" class="2fa-methods" style="padding:3px; text-align:center;">
758
                                ', isset($SETTINGS['google_authentication']) === true && $SETTINGS['google_authentication'] === '1' ?
759
                                    '<label for="select2fa-google">Google</label>
760
                                    <input type="radio" class="2fa_selector_select" name="2fa_selector_select" id="select2fa-google">' : '', '
761
                                    ', isset($SETTINGS['agses_authentication_enabled']) === true && $SETTINGS['agses_authentication_enabled'] === '1' ?
762
                                    '<label for="select2fa-agses">Agses</label>
763
                                    <input type="radio" class="2fa_selector_select" name="2fa_selector_select" id="select2fa-agses">' : '', '
764
                                    ', isset($SETTINGS['duo']) === true && $SETTINGS['duo'] === '1' ?
765
                                    '<label for="select2fa-duo">Duo Security</label>
766
                                    <input type="radio" class="2fa_selector_select" name="2fa_selector_select" id="select2fa-duo">' : '', '
767
                                    ', isset($SETTINGS['yubico_authentication']) === true && $SETTINGS['yubico_authentication'] === '1' ?
768
                                    '<label for="select2fa-yubico">Yubico</label>
769
                                    <input type="radio" class="2fa_selector_select" name="2fa_selector_select" id="select2fa-yubico">' : '', '
770
                                </div>
771
                            </div>
772
                            <div>
773
774
                            </div>
775
                        </div>';
776
777
    // AGSES
778
    if (isset($SETTINGS['agses_authentication_enabled']) === true && $SETTINGS['agses_authentication_enabled'] === '1') {
779
        echo '
780
                        <div id="div-2fa-agses" class="div-2fa-method ', isset($_SESSION['2famethod-agses']) === true && $_SESSION['2famethod-agses'] === '1' ? '' : 'hidden', '">
781
                        <div id="agses_cardid_div" style="text-align:center; padding:5px; width:454px; margin:5px 0 5px;" class="ui-state-active ui-corner-all">
782
                            ' . $LANG['user_profile_agses_card_id'].': &nbsp;
783
                            <input type="text" size="12" id="agses_cardid">
784
                        </div>
785
                        <div id="agses_flickercode_div" style="text-align:center; display:none;">
786
                            <canvas id="axs_canvas"></canvas>
787
                        </div>
788
                        <input type="text" id="agses_code" name="agses_code" style="margin-top:15px;" class="input_text text ui-widget-content ui-corner-all hidden submit-button" placeholder="' . addslashes($LANG['index_agses_key']).'" />
789
                        </div>';
790
    }
791
792
    // Google Authenticator code
793
    if (isset($SETTINGS['google_authentication']) === true && $SETTINGS['google_authentication'] === "1") {
794
        echo '
795
                        <div id="div-2fa-google" class="div-2fa-method ', isset($_SESSION['2famethod-google']) === true && $_SESSION['2famethod-google'] === '1' ? '' : 'hidden', '">
796
                        <div id="ga_code_div" style="margin-top:5px; padding:5px; overflow: auto; width:95%;" class="ui-state-default ui-corner-all">
797
                            <div style="width: 18%; float:left; display:block;">
798
                                <img src="includes/images/2fa_google_auth.png">
799
                            </div>
800
801
                            <div style="width: 82%; float:right; display:block;">
802
                                <input type="text" size="4" id="ga_code" name="ga_code" style="margin-top:15px;" class="input_text text ui-widget-content ui-corner-all numeric_only submit-button" placeholder="' . addslashes($LANG['ga_identification_code']).'" />
803
                                <div id="2fa_new_code_div" style="text-align:center; display:none; margin-top:5px; padding:5px;" class="ui-state-default ui-corner-all"></div>
804
                                <div style="margin-top:2px; font-size:10px; text-align:center; cursor:pointer;" onclick="send_user_new_temporary_ga_code()">' . $LANG['i_need_to_generate_new_ga_code'].'</div>
805
                            </div>
806
                        </div>
807
                        </div>';
808
    }
809
810
    // Google Authenticator code
811
    if (isset($SETTINGS['disable_show_forgot_pwd_link']) === true && $SETTINGS['disable_show_forgot_pwd_link'] !== "1") {
812
        echo '
813
                        <div style="text-align:center;margin-top:10px;font-size:10pt;">
814
                            <span onclick="OpenDialog(\'div_forgot_pw\')" style="padding:3px;cursor:pointer;">' . $LANG['forgot_my_pw'].'</span>
815
                        </div>';
816
    }
817
818
    if (isset($SETTINGS['enable_http_request_login']) === true
819
        && $SETTINGS['enable_http_request_login'] === '1'
820
        && isset($_SERVER['PHP_AUTH_USER']) === true
821
        && !(isset($SETTINGS['maintenance_mode']) === true
822
            && $SETTINGS['maintenance_mode'] === '1')
823
    ) {
824
        echo '
825
<script>
826
var seconds = 1;
827
function updateLogonButton(timeToGo){
828
    document.getElementById("but_identify_user").value = "' . $LANG['duration_login_attempt'].' " + timeToGo;
829
}
830
$( window ).on( "load", function() {
831
    updateLogonButton(seconds);
832
    setInterval(function() {
833
        seconds--;
834
        if (seconds >= 0) {
835
            updateLogonButton(seconds);
836
        } else if(seconds === 0) {
837
            launchIdentify(\'\', \''.$nextUrl.'\');
838
        }
839
        updateLogonButton(seconds);
840
    },
841
    1000
842
  );
843
});
844
</script>';
845
    }
846
847
    // Yubico authentication
848
    if (isset($SETTINGS['yubico_authentication']) === true && $SETTINGS['yubico_authentication'] === "1") {
849
        echo '
850
                        <div id="div-2fa-yubico" class="div-2fa-method ', isset($_SESSION['2famethod-yubico']) === true && $_SESSION['2famethod-yubico'] === '1' ? '' : 'hidden', '">
851
                        <div id="yubico_div" style="margin-top:5px; padding:5px; overflow: auto; width:95%;" class="ui-state-default ui-corner-all">
852
                            <div style="width: 18%; float:left; display:block;">
853
                                <img src="includes/images/yubico.png">
854
                            </div>
855
856
                            <div style="width: 82%; float:right; display:block;">
857
                                <div id="yubico_credentials_div" class="hidden">
858
                                    <h4>' . addslashes($LANG['provide_yubico_identifiers']).'</h4>
859
                                    <label for="yubico_user_id">' . $LANG['yubico_user_id'].'</label>
860
                                    <input type="text" size="10" id="yubico_user_id" class="input_text text ui-widget-content ui-corner-all" />
861
862
                                    <label for="yubico_user_key">' . $LANG['yubico_user_key'].'</label>
863
                                    <input type="text" size="10" id="yubico_user_key" class="input_text text ui-widget-content ui-corner-all" />
864
                                </div>
865
                                <input autocomplete="off" type="text" id="yubiko_key" class="input_text text ui-widget-content ui-corner-all" placeholder="'.addslashes($LANG['press_your_yubico_key']).'" style="margin-top:20px;">
866
                                <div id="show_yubico_credentials" class="hidden"><a href="#" id="yubico_link">'.addslashes($LANG['show_yubico_info_form']).'</a></div>
867
                            </div>
868
                        </div>
869
                        </div>';
870
    }
871
    
872
    // LOgin button
873
    echo '
874
                        <div id="div-login-button" class="" style="text-align:center;margin-top:15px;">
875
                            <a href="#" id="but_identify_user" onclick="launchIdentify(\'\', \''.$nextUrl.'\')" style="padding:3px;cursor:pointer;">'.$LANG['log_in'].'</a>
876
                        </div>';
877
878
    echo '
879
                    </div>
880
                </form>
881
                <script type="text/javascript">
882
                    $("#login").focus();
883
                </script>';
884
    // DIV for forgotten password
885
    echo '
886
                <div id="div_forgot_pw" style="display:none;">
887
                    <div style="margin:5px auto 5px auto;" id="div_forgot_pw_alert"></div>
888
                    <div style="margin:5px auto 5px auto;">' . $LANG['forgot_my_pw_text'].'</div>
889
                    <label for="forgot_pw_email">' . $LANG['email'].'</label>
890
                    <input type="text" size="40" name="forgot_pw_email" id="forgot_pw_email" />
891
                    <br />
892
                    <label for="forgot_pw_login">' . $LANG['login'].'</label>
893
                    <input type="text" size="20" name="forgot_pw_login" id="forgot_pw_login" />
894
                    <div id="div_forgot_pw_status" style="text-align:center;margin-top:15px;display:none; padding:5px;" class="ui-corner-all">
895
                        <i class="fa fa-cog fa-spin fa-2x"></i>&nbsp;<b>' . $LANG['please_wait'].'</b>
896
                    </div>
897
                </div>';
898
}
899
echo '
900
    </div>';
901
// FOOTER
902
/* DON'T MODIFY THE FOOTER ... MANY THANKS TO YOU */
903
echo '
904
    <div id="footer">
905
        <div style="float:left;width:32%;">
906
            <a href="https://teampass.net" target="_blank" style="color:#F0F0F0;">' . $SETTINGS_EXT['tool_name'].'&nbsp;'.$SETTINGS_EXT['version_full'].'&nbsp;<i class="fa fa-copyright"></i>&nbsp;'.$SETTINGS_EXT['copyright'].'</a>
907
            &nbsp;|&nbsp;
908
            <a href="https://teampass.readthedocs.io/en/latest/" target="_blank" style="color:#F0F0F0;" class="tip" title="' . addslashes($LANG['documentation_canal']).' ReadTheDocs"><i class="fa fa-book"></i></a>
909
            &nbsp;
910
            <a href="https://www.reddit.com/r/TeamPass/" target="_blank" style="color:#F0F0F0;" class="tip" title="' . addslashes($LANG['admin_help']).'"><i class="fa fa-reddit-alien"></i></a>
911
            &nbsp;
912
            ', ($session_user_id !== null && empty($session_user_id) === false) ? '
913
            <a href="#" style="color:#F0F0F0;" class="tip" title="' . addslashes($LANG['bugs_page']).'" onclick="generateBugReport()"><i class="fa fa-bug"></i></a>' : '', '
914
        </div>
915
        <div style="float:left;width:32%;text-align:center;">
916
            ', ($session_user_id !== null && empty($session_user_id) === false) ? '<i class="fa fa-users"></i>&nbsp;'.$session_nb_users_online.'&nbsp;'.$LANG['users_online'].'&nbsp;|&nbsp;<i class="fa fa-hourglass-end"></i>&nbsp;'.$LANG['index_expiration_in'].'&nbsp;<div style="display:inline;" id="countdown"></div>' : '', '
917
        </div><div id="countdown2"></div>
918
        <div style="float:right;text-align:right;">
919
            <i class="fa fa-clock-o"></i>&nbsp;' . $LANG['server_time']." : ".@date($SETTINGS['date_format'], (string) $_SERVER['REQUEST_TIME'])." - ".@date($SETTINGS['time_format'], (string) $_SERVER['REQUEST_TIME']).'
920
        </div>
921
    </div>';
922
// PAGE LOADING
923
echo '
924
    <div id="div_loading" class="hidden">
925
        <div style="padding:5px; z-index:9999999;" class="ui-widget-content ui-state-focus ui-corner-all">
926
            <i class="fa fa-cog fa-spin fa-2x"></i>
927
        </div>
928
    </div>';
929
// Alert BOX
930
echo '
931
    <div id="div_dialog_message" style="display:none;">
932
        <div id="div_dialog_message_text" style="text-align:center; padding:4px; font-size:12px; margin-top:10px;"></div>
933
    </div>';
934
935
// WARNING FOR QUERY ERROR
936
echo '
937
    <div id="div_mysql_error" style="display:none;">
938
        <div style="padding:10px;text-align:center;" id="mysql_error_warning"></div>
939
    </div>';
940
941
//Personnal SALTKEY
942
if (isset($SETTINGS['enable_pf_feature']) && $SETTINGS['enable_pf_feature'] === "1") {
943
    echo '
944
        <div id="div_set_personal_saltkey" style="display:none;padding:4px;">
945
            <div style="text-align:center;margin:5px;padding:3px;" id="expected_psk_complexPw" class="ui-widget ui-state-active ui-corner-all hidden">', isset($SETTINGS['personal_saltkey_security_level']) === true && empty($SETTINGS['personal_saltkey_security_level']) === false && isset($SETTINGS_EXT['pwComplexity']) === true ? $LANG['complex_asked']." : ".$SETTINGS_EXT['pwComplexity'][$SETTINGS['personal_saltkey_security_level']][1] : '', '</div>
946
            <table border="0">
947
                <tr>
948
                    <td>
949
                        <i class="fa fa-key"></i> <b>' . $LANG['home_personal_saltkey'].'</b>
950
                    </td>
951
                    <td>
952
                        <input type="password" name="input_personal_saltkey" id="input_personal_saltkey" style="width:200px;padding:5px;margin-left:10px;" class="text ui-widget-content ui-corner-all text_without_symbols tip" value="', isset($_SESSION['user_settings']['clear_psk']) ? (string) $_SESSION['user_settings']['clear_psk'] : '', '" title="<i class=\'fa fa-bullhorn\'></i>&nbsp;'.$LANG['text_without_symbols'].'" />
953
                        <span id="set_personal_saltkey_last_letter" style="font-weight:bold;font-size:20px;"></span>
954
                    </td>
955
                </tr>
956
                <tr>
957
                    <td></td>
958
                    <td>
959
                        <div id="psk_strength" style="margin:3px 0 0 10px;"></div>
960
                        <input type="hidden" id="psk_strength_value" />
961
                    </td>
962
                </tr>
963
            </table>
964
            <div style="display:none;margin-top:5px;text-align:center;padding:4px;" id="set_personal_saltkey_warning" class="ui-widget-content ui-corner-all"></div>
965
        </div>';
966
}
967
968
// user profile
969
echo '
970
<div id="dialog_user_profil" style="display:none;padding:4px;">
971
    <div id="div_user_profil">
972
        <i class="fa fa-cog fa-spin fa-2x"></i>&nbsp;<b>' . $LANG['please_wait'].'</b>
973
    </div>
974
    <input type="hidden" id="force_show_dialog" value="',
975
isset($_SESSION['unsuccessfull_login_attempts']) === true
976
&& $_SESSION['unsuccessfull_login_attempts']['nb'] !== 0
977
&& $_SESSION['unsuccessfull_login_attempts']['shown'] === false ?
978
'1' : '0', '" />
979
</div>';
980
981
// DUO box
982
echo '
983
<div id="dialog_duo" style="display:none;padding:4px;">
984
    <div id="div_duo"></div>
985
    ' . $LANG['duo_loading_iframe'].'
986
    <form method="post" id="duo_form" action="">
987
        <input type="hidden" id="duo_login" name="duo_login" value="', null !== $post_duo_login ? $post_duo_login : '', '" />
988
        <input type="hidden" id="duo_pwd" name="duo_pwd" value="', null !== $post_duo_pwd ? $post_duo_pwd : '', '" />
989
        <input type="hidden" id="duo_data" name="duo_data" value="', null !== $post_duo_data ? $post_duo_data : '', '" />
990
    </form>
991
</div>';
992
993
// INCREASE session time
994
echo '
995
<div id="div_increase_session_time" style="display:none;padding:4px;">
996
    <b>' . $LANG['index_session_duration'].':</b>
997
    <input type="text" id="input_session_duration" style="width:50px;padding:5px;margin:0 10px 0 10px;" class="text ui-widget-content ui-corner-all" value="', isset($_SESSION['user_settings']['session_duration']) ? (int) $_SESSION['user_settings']['session_duration'] / 60 : 60, '" />
998
    <b>' . $LANG['minutes'].'</b>
999
    <div style="display:none;margin-top:5px;text-align:center;padding:4px;" id="input_session_duration_warning" class="ui-widget-content ui-state-error ui-corner-all"></div>
1000
</div>';
1001
1002
closelog();
1003
1004
1005
if (isset($_SESSION['user_id']) === false || empty($_SESSION['user_id']) === true) {
1006
    ?>
1007
    <script type="text/javascript">
1008
    var twoFaMethods = parseInt($("#2fa_google").val()) + parseInt($("#2fa_agses").val()) + parseInt($("#2fa_duo").val()) + parseInt($("#2fa_yubico").val());
1009
    if (twoFaMethods > 1) {
1010
        var loginButMethods = ['google', 'agses', 'duo'];
1011
1012
        // Show methods
1013
        $("#2fa_selector").removeClass("hidden");
1014
1015
        // Hide login button
1016
        $('#div-login-button').addClass('hidden');
1017
1018
        // Unselect any method
1019
        $(".2fa_selector_select").prop('checked', false);
1020
1021
        // Prepare buttons
1022
        $('.2fa-methods').radiosforbuttons({
1023
            margin: 20,
1024
            vertical: false,
1025
            group: false,
1026
            autowidth: true
1027
        });
1028
1029
        // Handle click
1030
        $('.radiosforbuttons-2fa_selector_select')
1031
        .click(function() {
1032
            $('.div-2fa-method').addClass('hidden');
1033
            var twofaMethod = $(this).data('id').split('-');
1034
1035
            // Save user choice
1036
            $('#2fa_user_selection').val(twofaMethod[1]);
1037
1038
            // Show 2fa method div
1039
            $('#div-2fa-'+twofaMethod[1]).removeClass('hidden');
1040
1041
            // Show login button if required
1042
            if ($.inArray(twofaMethod[1], loginButMethods) !== -1) {
1043
                $('#div-login-button').removeClass('hidden');
1044
            } else {
1045
                $('#div-login-button').addClass('hidden');
1046
            }
1047
1048
            // Make focus
1049
            if (twofaMethod[1] === 'google') {
1050
                $('#ga_code').focus();
1051
            } else if (twofaMethod[1] === 'yubico') {
1052
                $('#yubiko_key').focus();
1053
            } else if (twofaMethod[1] === 'agses') {
1054
                startAgsesAuth();
1055
            }
1056
        });
1057
    } else if (twoFaMethods === 1) {
1058
        if ($('#2fa_google').val() === '1') {
1059
            $('#div-2fa-google').removeClass('hidden');
1060
        } else if ($('#2fa_yubico').val() === '1') {
1061
            $('#div-2fa-yubico').removeClass('hidden');
1062
        } else if ($('#2fa_agses').val() === '1') {
1063
            $('#div-2fa-agses').removeClass('hidden');
1064
        }
1065
        $('#login').focus();
1066
    }
1067
1068
    $('.submit-button').keypress(function(event){
1069
        if (event.keyCode === 10 || event.keyCode === 13) {
1070
            launchIdentify('', '<?php echo $nextUrl; ?>', '');
1071
            event.preventDefault();
1072
        }
1073
    });
1074
1075
    $('#yubiko_key').change(function(event) {
1076
        launchIdentify('', '<?php echo $nextUrl; ?>', '');
1077
        event.preventDefault();
1078
    });
1079
    </script>
1080
    <?php
1081
}
1082
1083
?>
1084
<script type="text/javascript">
1085
NProgress.start();
1086
</script>
1087
    </body>
1088
</html>
1089