Completed
Push — development ( a4b5b1...dcab98 )
by Nils
07:16
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 *
4
 * @file          index.php
5
 * @author        Nils Laumaillé
6
 * @version       2.1.27
7
 * @copyright     (c) 2009-2017 Nils Laumaillé
8
 * @licensing     GNU AFFERO GPL 3.0
9
 * @link          http://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-Option: 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_destroy();
47
session_id();
48
// initialize session
49
$_SESSION['CPM'] = 1;
50 View Code Duplication
if (!isset($_SESSION['settings']['cpassman_dir']) || $_SESSION['settings']['cpassman_dir'] === "") {
51
    $_SESSION['settings']['cpassman_dir'] = ".";
52
    $_SESSION['settings']['cpassman_url'] = $_SERVER["REQUEST_URI"];
53
}
54
55
// Include files
56
require_once $_SESSION['settings']['cpassman_dir'].'/includes/config/settings.php';
57
require_once $_SESSION['settings']['cpassman_dir'].'/includes/config/include.php';
58
require_once $_SESSION['settings']['cpassman_dir'].'/sources/SplClassLoader.php';
59
60
// connect to the server
61
require_once './includes/libraries/Database/Meekrodb/db.class.php';
62
DB::$host = $server;
63
DB::$user = $user;
64
DB::$password = $pass;
65
DB::$dbName = $database;
66
DB::$port = $port;
67
DB::$encoding = $encoding;
68
DB::$error_handler = 'db_error_handler';
0 ignored issues
show
Documentation Bug introduced by
The property $error_handler was declared of type boolean, but 'db_error_handler' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
69
$link = mysqli_connect($server, $user, $pass, $database, $port);
70
$link->set_charset($encoding);
71
72
73
//load main functions needed
74
require_once 'sources/main.functions.php';
75
// Load CORE
76
require_once $_SESSION['settings']['cpassman_dir'].'/sources/core.php';
77
78
/* DEFINE WHAT LANGUAGE TO USE */
79
if (isset($_GET['language'])) {
80
    // case of user has change language in the login page
81
    $dataLanguage = DB::queryFirstRow(
82
        "SELECT flag, name
83
        FROM ".prefix_table("languages")."
84
        WHERE name = %s",
85
        filter_var($_GET['language'], FILTER_SANITIZE_STRING)
86
    );
87
    $_SESSION['user_language'] = $dataLanguage['name'];
88
    $_SESSION['user_language_flag'] = $dataLanguage['flag'];
89
} elseif (!isset($_SESSION['user_id']) && !isset($_POST['language']) && !isset($_SESSION['user_language'])) {
90
    //get default language
91
    $dataLanguage = DB::queryFirstRow(
92
        "SELECT m.valeur AS valeur, l.flag AS flag
93
        FROM ".prefix_table("misc")." AS m
94
        INNER JOIN ".prefix_table("languages")." AS l ON (m.valeur = l.name)
95
        WHERE m.type=%s_type AND m.intitule=%s_intitule",
96
        array(
97
            'type' => "admin",
98
            'intitule' => "default_language"
99
        )
100
    );
101
    if (empty($dataLanguage['valeur'])) {
102
        $_SESSION['user_language'] = "english";
103
        $_SESSION['user_language_flag'] = "us.png";
104
    } else {
105
        $_SESSION['user_language'] = $dataLanguage['valeur'];
106
        $_SESSION['user_language_flag'] = $dataLanguage['flag'];
107
    }
108 View Code Duplication
} elseif (isset($_SESSION['settings']['default_language']) && !isset($_SESSION['user_language'])) {
109
    $_SESSION['user_language'] = $_SESSION['settings']['default_language'];
110
} elseif (isset($_POST['language'])) {
111
    $_SESSION['user_language'] = filter_var($_POST['language'], FILTER_SANITIZE_STRING);
112
} elseif (!isset($_SESSION['user_language']) || empty($_SESSION['user_language'])) {
113
    if (isset($_POST['language'])) {
114
        $_SESSION['user_language'] = filter_var($_POST['language'], FILTER_SANITIZE_STRING);
115 View Code Duplication
    } elseif (isset($_SESSION['settings']['default_language'])) {
116
        $_SESSION['user_language'] = $_SESSION['settings']['default_language'];
117
    }
118
} elseif ($_SESSION['user_language'] === "0") {
119
    $_SESSION['user_language'] = $_SESSION['settings']['default_language'];
120
}
121
122
// Load user languages files
123
if (in_array($_SESSION['user_language'], $languagesList)) {
124
    @require_once $_SESSION['settings']['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'.php';
125
    if (isset($_GET['page']) && filter_var($_GET['page'], FILTER_SANITIZE_STRING) === "kb") {
126
        require_once $_SESSION['settings']['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'_kb.php';
127
    }
128
} else {
129
    $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
130
    include $_SESSION['settings']['cpassman_dir'].'/error.php';
131
}
132
133
// load 2FA Google
134 View Code Duplication
if (isset($_SESSION['settings']['google_authentication']) && $_SESSION['settings']['google_authentication'] === "1") {
135
    include_once($_SESSION['settings']['cpassman_dir']."/includes/libraries/Authentication/TwoFactorAuth/TwoFactorAuth.php");
136
}
137
138
// Load links, css and javascripts
139
if (isset($_SESSION['CPM'])) {
140
    @require_once $_SESSION['settings']['cpassman_dir'].'/load.php';
141
}
142
143
?>
144
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
145
146
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
147
<head>
148
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
149
<title>Teampass</title>
150
<script type="text/javascript">
151
    //<![CDATA[
152
    if (window.location.href.indexOf("page=") === -1 && (window.location.href.indexOf("otv=") === -1 && window.location.href.indexOf("action=") === -1)) {
153
        if (window.location.href.indexOf("session_over=true") == -1) {
154
            location.replace("./index.php?page=items");
155
        } else {
156
            location.replace("./logout.php");
157
        }
158
    }
159
    //]]>
160
</script>
161
<?php
162
163
// load HEADERS
164
if (isset($_SESSION['CPM'])) {
165
    echo $htmlHeaders;
166
}
167
?>
168
    </head>
169
170
<body>
171
    <?php
172
173
/* HEADER */
174
echo '
175
    <div id="top">
176
        <div id="logo"><img src="includes/images/canevas/logo.png" alt="" /></div>';
177
// Display menu
178
if (isset($_SESSION['login'])) {
179
    // welcome message
180
    echo '
181
        <div style="float:right; margin:-10px 5px 0 0; color:#FFF;">'.$LANG['index_welcome'].'&nbsp;<b>'.$_SESSION['name'].'&nbsp;'.$_SESSION['lastname'].'&nbsp;['.$_SESSION['login'].']</b>&nbsp;-&nbsp;', $_SESSION['user_admin'] == 1 ? $LANG['god'] : ($_SESSION['user_manager'] == 1 ? $LANG['gestionnaire'] : ($_SESSION['user_read_only'] == 1 ? $LANG['read_only_account'] : $LANG['user'])), '&nbsp;'.strtolower($LANG['index_login']).'</div>';
182
183
    echo '
184
        <div id="menu_top">
185
            <div style="margin-left:20px; margin-top:2px;width:710px;" id="main_menu">';
186
    if ($_SESSION['user_admin'] == 0 || $k['admin_full_right'] == 0) {
187
        echo '
188
                <a class="btn btn-default" href="#"',
189
                (isset($_SESSION['nb_folders']) && $_SESSION['nb_folders'] == 0)
190
                || (isset($_SESSION['nb_roles']) && $_SESSION['nb_roles'] == 0) ? '' : ' onclick="MenuAction(\'items\')"',
191
                '>
192
                    <i class="fa fa-key fa-2x tip" title="'.$LANG['pw'].'"></i>
193
                </a>
194
195
                <a class="btn btn-default" href="#"',
196
                (isset($_SESSION['nb_folders']) && $_SESSION['nb_folders'] == 0)
197
                || (isset($_SESSION['nb_roles']) && $_SESSION['nb_roles'] == 0) ? '' : ' onclick="MenuAction(\'find\')"',
198
                '>
199
                    <i class="fa fa-binoculars fa-2x tip" title="'.$LANG['find'].'"></i>
200
                </a>';
201
    }
202
203
    // Favourites menu
204 View Code Duplication
    if (
205
        isset($_SESSION['settings']['enable_favourites'])
206
        && $_SESSION['settings']['enable_favourites'] == 1
207
        &&
208
        ($_SESSION['user_admin'] == 0 || ($_SESSION['user_admin'] == 1 && $k['admin_full_right'] == false))
209
    ) {
210
        echo '
211
                <a class="btn btn-default" href="#" onclick="MenuAction(\'favourites\')">
212
                    <i class="fa fa-star fa-2x tip" title="'.$LANG['my_favourites'].'"></i>
213
                </a>';
214
    }
215
    // KB menu
216 View Code Duplication
    if (isset($_SESSION['settings']['enable_kb']) && $_SESSION['settings']['enable_kb'] == 1) {
217
        echo '
218
                <a class="btn btn-default" href="#" onclick="MenuAction(\'kb\')">
219
                    <i class="fa fa-map-signs fa-2x tip" title="'.$LANG['kb_menu'].'"></i>
220
                </a>';
221
    }
222
    echo '
223
    <span id="menu_suggestion_position">';
224
    // SUGGESTION menu
225 View Code Duplication
    if (
226
        isset($_SESSION['settings']['enable_suggestion']) && $_SESSION['settings']['enable_suggestion'] == 1
227
        && ($_SESSION['user_read_only'] == 1 || $_SESSION['user_admin'] == 1 || $_SESSION['user_manager'] == 1)
228
    ) {
229
        echo '
230
                <a class="btn btn-default" href="#" onclick="MenuAction(\'suggestion\')">
231
                    <i class="fa fa-lightbulb-o fa-2x tip" id="menu_icon_suggestions" title="'.$LANG['suggestion_menu'].'"></i>
232
                </a>';
233
    }
234
    echo '
235
    </span>';
236
    // Admin menu
237
    if ($_SESSION['user_admin'] == 1) {
238
        echo '
239
                &nbsp;
240
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_main\')">
241
                    <i class="fa fa-info fa-2x tip" title="'.$LANG['admin_main'].'"></i>
242
                </a>
243
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_settings\')">
244
                    <i class="fa fa-wrench fa-2x tip" title="'.$LANG['admin_settings'].'"></i>
245
                </a>';
246
    }
247
248
    if ($_SESSION['user_admin'] == 1 || $_SESSION['user_manager'] == 1) {
249
        echo '
250
                &nbsp;
251
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_folders\')">
252
                    <i class="fa fa-folder-open fa-2x tip" title="'.$LANG['admin_groups'].'"></i>
253
                </a>
254
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_roles\')">
255
                    <i class="fa fa-graduation-cap fa-2x tip" title="'.$LANG['admin_functions'].'"></i>
256
                </a>
257
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_users\')">
258
                    <i class="fa fa-users fa-2x tip" title="'.$LANG['admin_users'].'"></i>
259
                </a>
260
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_views\')">
261
                    <i class="fa fa-cubes fa-2x tip" title="'.$LANG['admin_views'].'"></i>
262
                </a>';
263
    }
264
265
    echo '
266
                <div style="float:right;">
267
                    <ul class="menu" style="">
268
                        <li class="" style="padding:4px;width:40px; text-align:center;"><i class="fa fa-dashboard fa-fw"></i>&nbsp;
269
                            <ul class="menu_200" style="text-align:left;">',
270
                                ($_SESSION['user_admin'] == 1 && $k['admin_full_right'] == true) ? '' : isset($_SESSION['settings']['enable_pf_feature']) && $_SESSION['settings']['enable_pf_feature'] == 1 ? '
271
                                <li onclick="$(\'#div_set_personal_saltkey\').dialog(\'open\')">
272
                                    <i class="fa fa-key fa-fw"></i> &nbsp;'.$LANG['home_personal_saltkey_button'].'
273
                                </li>' : '', '
274
                                <li onclick="$(\'#div_increase_session_time\').dialog(\'open\')">
275
                                    <i class="fa fa-clock-o fa-fw"></i> &nbsp;'.$LANG['index_add_one_hour'].'
276
                                </li>
277
                                <li onclick="loadProfileDialog()">
278
                                    <i class="fa fa-user fa-fw"></i> &nbsp;'.$LANG['my_profile'].'
279
                                </li>
280
                                <li onclick="MenuAction(\'deconnexion\', \''.$_SESSION['user_id'].'\')">
281
                                    <i class="fa fa-sign-out fa-fw"></i> &nbsp;'.$LANG['disconnect'].'
282
                                </li>
283
                            </ul>
284
                        </li>
285
                    </ul>
286
                </div>';
287
288
    if ($_SESSION['user_admin'] != 1 || ($_SESSION['user_admin'] == 1 && $k['admin_full_right'] == false)) {
289
        echo '
290
                <div style="float:right; margin-right:10px;">
291
                    <ul class="menu" id="menu_last_seen_items">
292
                        <li class="" style="padding:4px;width:40px; text-align:center;"><i class="fa fa-map fa-fw"></i>&nbsp;&nbsp;
293
                            <ul class="menu_200" id="last_seen_items_list" style="text-align:left;">
294
                                <li>'.$LANG['please_wait'].'</li>
295
                            </ul>
296
                        </li>
297
                    </ul>
298
                </div>';
299
    }
300
301
    // show avatar
302 View Code Duplication
    if (isset($_SESSION['user_avatar_thumb']) && !empty($_SESSION['user_avatar_thumb'])) {
303
        if (file_exists('includes/avatars/'.$_SESSION['user_avatar_thumb'])) {
304
            $avatar = $_SESSION['settings']['cpassman_url'].'/includes/avatars/'.$_SESSION['user_avatar_thumb'];
305
        } else {
306
            $avatar = $_SESSION['settings']['cpassman_url'].'/includes/images/photo.jpg';
307
        }
308
    } else {
309
        $avatar = $_SESSION['settings']['cpassman_url'].'/includes/images/photo.jpg';
310
    }
311
    echo '
312
                <div style="float:right; margin-right:10px;">
313
                    <img src="'.$avatar.'" style="border-radius:10px; height:28px; cursor:pointer;" onclick="loadProfileDialog()" alt="photo" id="user_avatar_thumb" />
314
                </div>';
315
316
    echo '
317
            </div>';
318
319
    echo '
320
        </div>';
321
}
322
323
echo '
324
    </div>';
325
326
    echo '
327
<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">
328
    <div id="main_info_box_text" style="text-align:center;margin-top:10px;"></div>
329
</div>';
330
331
/* MAIN PAGE */
332
echo '
333
        <input type="hidden" id="temps_restant" value="', isset($_SESSION['fin_session']) ? $_SESSION['fin_session'] : '', '" />
334
        <input type="hidden" name="language" id="language" value="" />
335
        <input type="hidden" name="user_pw_complexity" id="user_pw_complexity" value="'.@$_SESSION['user_pw_complexity'].'" />
336
        <input type="hidden" name="user_session" id="user_session" value=""/>
337
        <input type="hidden" name="encryptClientServer" id="encryptClientServer" value="', isset($_SESSION['settings']['encryptClientServer']) ? $_SESSION['settings']['encryptClientServer'] : '1', '" />
338
        <input type="hidden" name="please_login" id="please_login" value="" />
339
        <input type="hidden" name="disabled_action_on_going" id="disabled_action_on_going" value="" />
340
        <input type="hidden" id="duo_sig_response" value="'.@$_POST['sig_response'].'" />';
341
342
// SENDING STATISTICS?
343
if (
344
    isset($_SESSION['settings']['send_stats']) && $_SESSION['settings']['send_stats'] == 1
345
    && (!isset($_SESSION['temporary']['send_stats_done']) || $_SESSION['temporary']['send_stats_done'] !== "1")
346
) {
347
    echo '
348
        <input type="hidden" name="send_statistics" id="send_statistics" value="1" />';
349
} else {
350
    echo '
351
    <input type="hidden" name="send_statistics" id="send_statistics" value="0" />';
352
}
353
354
echo '
355
    <div id="', (isset($_GET['page']) && filter_var($_GET['page'], FILTER_SANITIZE_STRING) === "items" && isset($_SESSION['user_id'])) ? "main_simple" : "main", '">';
356
// MESSAGE BOX
357
echo '
358
        <div style="" class="div_center">
359
            <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>
360
        </div>';
361
// Main page
362
if (isset($_SESSION['autoriser']) && $_SESSION['autoriser'] == true) {
363
    // Show menu
364
    echo '
365
        <form method="post" name="main_form" action="">
366
            <input type="hidden" name="menu_action" id="menu_action" value="" />
367
            <input type="hidden" name="changer_pw" id="changer_pw" value="" />
368
            <input type="hidden" name="form_user_id" id="form_user_id" value="', isset($_SESSION['user_id']) ? $_SESSION['user_id'] : '', '" />
369
            <input type="hidden" name="is_admin" id="is_admin" value="', isset($_SESSION['is_admin']) ? $_SESSION['is_admin'] : '', '" />
370
            <input type="hidden" name="personal_saltkey_set" id="personal_saltkey_set" value="', isset($_SESSION['my_sk']) ? true : false, '" />
371
        </form>';
372
}
373
// ---------
374
// Display a help to admin
375
$errorAdmin = "";
376
// error nb folders
377
if (isset($_SESSION['nb_folders']) && $_SESSION['nb_folders'] == 0) {
378
    $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_folders'].'<br />';
379
}
380
// error nb roles
381
if (isset($_SESSION['nb_roles']) && $_SESSION['nb_roles'] == 0) {
382
    if (empty($errorAdmin)) {
383
        $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_roles'];
384
    } else {
385
        $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_roles'];
386
    }
387
}
388
/*
389
// error Salt key
390
if (isset($_SESSION['error']['salt']) && $_SESSION['error']['salt'] == 1) {
391
    if (empty($errorAdmin)) {
392
        $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_salt'];
393
    } else {
394
        $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_salt'];
395
    }
396
}
397
*/
398
399
if (isset($_SESSION['validite_pw']) && $_SESSION['validite_pw']) {
400
    // error cpassman dir
401 View Code Duplication
    if (isset($_SESSION['settings']['cpassman_dir']) && empty($_SESSION['settings']['cpassman_dir']) || !isset($_SESSION['settings']['cpassman_dir'])) {
402
        if (empty($errorAdmin)) {
403
            $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_dir'];
404
        } else {
405
            $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_dir'];
406
        }
407
    }
408
    // error cpassman url
409 View Code Duplication
    if (isset($_SESSION['validite_pw']) && (isset($_SESSION['settings']['cpassman_url']) && empty($_SESSION['settings']['cpassman_url']) || !isset($_SESSION['settings']['cpassman_url']))) {
410
        if (empty($errorAdmin)) {
411
            $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_url'];
412
        } else {
413
            $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_url'];
414
        }
415
    }
416
}
417
// Display help
418
if (!empty($errorAdmin)) {
419
    echo '
420
            <div style="margin:10px;padding:10px;" class="ui-state-error ui-corner-all">
421
            '.$errorAdmin.'
422
            </div>';
423
}
424
// -----------
425
// Display Maintenance mode information
426
if (
427
    isset($_SESSION['settings']['maintenance_mode']) && $_SESSION['settings']['maintenance_mode'] == 1
428
        && isset($_SESSION['user_admin']) && $_SESSION['user_admin'] == 1
429
    ) {
430
    echo '
431
        <div style="text-align:center;margin-bottom:5px;padding:10px;" class="ui-state-highlight ui-corner-all">
432
            <b>'.$LANG['index_maintenance_mode_admin'].'</b>
433
        </div>';
434
}
435
// Display UPDATE NEEDED information
436
if (
437
    isset($_SESSION['settings']['update_needed']) && $_SESSION['settings']['update_needed'] == true
438
        && isset($_SESSION['user_admin']) && $_SESSION['user_admin'] == 1
439
        && ((isset($_SESSION['hide_maintenance']) && $_SESSION['hide_maintenance'] == 0)
440
        || !isset($_SESSION['hide_maintenance']))
441
    ) {
442
    echo '
443
        <div style="text-align:center;margin-bottom:5px;padding:10px;"
444
            class="ui-state-highlight ui-corner-all" id="div_maintenance">
445
            <b>'.$LANG['update_needed_mode_admin'].'</b>
446
            <span style="float:right;cursor:pointer;">
447
                <span class="fa fa-close mi-red" onclick="toggleDiv(\'div_maintenance\')"></span>
448
            </span>
449
        </div>';
450
}
451
452
// display an item in the context of OTV link
453
    if ((!isset($_SESSION['validite_pw']) || empty($_SESSION['validite_pw']) || empty($_SESSION['user_id'])) && isset($_GET['otv']) && filter_var($_GET['otv'], FILTER_SANITIZE_STRING) === "true") {
454
        // case where one-shot viewer
455
        if (
456
            isset($_GET['code']) && !empty($_GET['code'])
457
            && isset($_GET['stamp']) && !empty($_GET['stamp'])
458
        ) {
459
            include 'otv.php';
460
        } else {
461
            $_SESSION['error']['code'] = ERR_VALID_SESSION;
462
            $_SESSION['initial_url'] = filter_var(substr($_SERVER["REQUEST_URI"], strpos($_SERVER["REQUEST_URI"], "index.php?")), FILTER_SANITIZE_URL);
463
            include $_SESSION['settings']['cpassman_dir'].'/error.php';
464
        }
465
    }
466
// ask the user to change his password
467
    else if ((!isset($_SESSION['validite_pw']) || $_SESSION['validite_pw'] === false) && !empty($_SESSION['user_id'])) {
468
        //Check if password is valid
469
        echo '
470
        <div style="margin:auto; padding:20px; width:500px;" class="ui-state-focus ui-corner-all">
471
            <h3>'.$LANG['index_change_pw'].'</h3>
472
            <div style="height:20px;text-align:center;margin:2px;display:none;" id="change_pwd_error" class=""></div>
473
            <div style="text-align:center;margin:5px;padding:3px;" id="change_pwd_complexPw" class="ui-widget ui-state-active ui-corner-all">'.
474
            $LANG['complex_asked'].' : '.$_SESSION['settings']['pwComplexity'][$_SESSION['user_pw_complexity']][1].
475
            '</div>
476
            <div id="pw_strength" style="margin:0 0 10px 140px;"></div>
477
            <table>
478
                <tr>
479
                    <td>'.$LANG['index_new_pw'].' :</td><td><input type="password" size="15" name="new_pw" id="new_pw"/></td>
480
                </tr>
481
                <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>
482
            </table>
483
            <input type="hidden" id="pw_strength_value" />
484
            <div style="width:420px; text-align:center; margin:15px 0 10px 0;">
485
                <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'].'" />
486
            </div>
487
        </div>
488
        <script type="text/javascript">
489
            $("#new_pw").focus();
490
        </script>';
491
    }
492
// Display pages
493
    elseif (isset($_SESSION['validite_pw']) && $_SESSION['validite_pw'] == true && !empty($_GET['page']) && !empty($_SESSION['user_id'])) {
494
        if (!extension_loaded('mcrypt')) {
495
            $_SESSION['error']['code'] = ERR_NO_MCRYPT;
496
            include $_SESSION['settings']['cpassman_dir'].'/error.php';
497
        } elseif (isset($_SESSION['initial_url']) && !empty($_SESSION['initial_url'])) {
498
            include $_SESSION['initial_url'];
499 View Code Duplication
        } elseif ($_GET['page'] == "items") {
500
            // SHow page with Items
501
            if (
502
                ($_SESSION['user_admin'] != 1)
503
                ||
504
                ($_SESSION['user_admin'] == 1 && $k['admin_full_right'] == false)
505
            ) {
506
                include 'items.php';
507
            } else {
508
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
509
                include $_SESSION['settings']['cpassman_dir'].'/error.php';
510
            }
511
        } elseif ($_GET['page'] == "find") {
512
            // Show page for items findind
513
            include 'find.php';
514
        } elseif ($_GET['page'] == "favourites") {
515
            // Show page for user favourites
516
            include 'favorites.php';
517 View Code Duplication
        } elseif ($_GET['page'] == "kb") {
518
            // Show page KB
519
            if (isset($_SESSION['settings']['enable_kb']) && $_SESSION['settings']['enable_kb'] == 1) {
520
                include 'kb.php';
521
            } else {
522
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
523
                include $_SESSION['settings']['cpassman_dir'].'/error.php';
524
            }
525
        } elseif ($_GET['page'] == "suggestion") {
526
            // Show page KB
527
            if (isset($_SESSION['settings']['enable_suggestion']) && $_SESSION['settings']['enable_suggestion'] == 1) {
528
                include 'suggestion.php';
529
            } else {
530
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
531
                include $_SESSION['settings']['cpassman_dir'].'/error.php';
532
            }
533
        } elseif (in_array($_GET['page'], array_keys($mngPages))) {
534
            // Define if user is allowed to see management pages
535
            if ($_SESSION['user_admin'] == 1) {
536
                include($mngPages[$_GET['page']]);
537
            } elseif ($_SESSION['user_manager'] == 1) {
538
                if (($_GET['page'] != "manage_main" && $_GET['page'] != "manage_settings")) {
539
                    include($mngPages[$_GET['page']]);
540
                } else {
541
                    $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
542
                    include $_SESSION['settings']['cpassman_dir'].'/error.php';
543
                }
544
            } else {
545
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
546
                include $_SESSION['settings']['cpassman_dir'].'/error.php';
547
            }
548 View Code Duplication
        } else {
549
            $_SESSION['error']['code'] = ERR_NOT_EXIST; //page doesn't exist
550
            include $_SESSION['settings']['cpassman_dir'].'/error.php';
551
        }
552
    }
553
// case of password recovery
554
    elseif (empty($_SESSION['user_id']) && isset($_GET['action']) && $_GET['action'] == "password_recovery") {
555
        // Case where user has asked new PW
556
        echo '
557
            <div style="width:400px;margin:50px auto 50px auto;padding:25px;" class="ui-state-highlight ui-corner-all">
558
                <div style="text-align:center;font-weight:bold;margin-bottom:20px;">
559
                    '.$LANG['pw_recovery_asked'].'
560
                </div>
561
                <div id="generate_new_pw_error" style="color:red;display:none;text-align:center;margin:5px;"></div>
562
                <div style="margin-bottom:3px;">
563
                    '.$LANG['pw_recovery_info'].'
564
                </div>
565
                <div style="margin:15px; text-align:center;">
566
                    <input type="button" id="but_generate_new_password" onclick="GenerateNewPassword(\''.htmlspecialchars($_GET['key'], ENT_QUOTES).'\',\''.htmlspecialchars($_GET['login'], ENT_QUOTES).'\')" style="padding:3px;cursor:pointer;" class="ui-state-default ui-corner-all" value="'.$LANG['pw_recovery_button'].'" />
567
                    <br /><br />
568
                    <div id="ajax_loader_send_mail" style="display:none; margin: 20px;"><span class="fa fa-cog fa-spin fa-2x"></span></div>
569
                </div>
570
                <div style="margin-top:30px; text-align:center;">
571
                    <a href="index.php" class="tip" title="'.$LANG['home'].'"><span class="fa fa-home fa-lg"></span></a>
572
                </div>
573
            </div>';
574
    } elseif (!empty($_SESSION['user_id']) && isset($_SESSION['user_id'])) {
575
        // Page doesn't exist
576
        $_SESSION['error']['code'] = ERR_NOT_EXIST;
577
        include $_SESSION['settings']['cpassman_dir'].'/error.php';
578
        // When user is not identified
579
    } else {
580
        // Automatic redirection
581 View Code Duplication
        if (strpos($_SERVER["REQUEST_URI"], "?") > 0) {
582
            $nextUrl = filter_var(substr($_SERVER["REQUEST_URI"], strpos($_SERVER["REQUEST_URI"], "?")), FILTER_SANITIZE_URL);
583
        } else {
584
            $nextUrl = "";
585
        }
586
        // MAINTENANCE MODE
587
        if (isset($_SESSION['settings']['maintenance_mode']) && $_SESSION['settings']['maintenance_mode'] == 1) {
588
            echo '
589
                <div style="text-align:center;margin-top:30px;margin-bottom:20px;padding:10px;"
590
                    class="ui-state-error ui-corner-all">
591
                    <b>'.$LANG['index_maintenance_mode'].'</b>
592
                </div>';
593
        } else if (isset($_GET['session_over']) && $_GET['session_over'] == "true") {
594
            // SESSION FINISHED => RECONNECTION ASKED
595
            echo '
596
                    <div style="text-align:center;margin-top:30px;margin-bottom:20px;padding:10px;"
597
                        class="ui-state-error ui-corner-all">
598
                        <b>'.$LANG['index_session_expired'].'</b>
599
                    </div>';
600
        }
601
602
        // case where user not logged and can't access a direct link
603 View Code Duplication
        if (!empty($_GET['page'])) {
604
            $_SESSION['initial_url'] = filter_var(substr($_SERVER["REQUEST_URI"], strpos($_SERVER["REQUEST_URI"], "index.php?")), FILTER_SANITIZE_URL);
605
        } else {
606
            $_SESSION['initial_url'] = "";
607
        }
608
609
        // CONNECTION FORM
610
        echo '
611
                <form method="post" name="form_identify" id="form_identify" action="">
612
                    <div style="width:480px;margin:10px auto 10px auto;padding:25px;" class="ui-state-highlight ui-corner-all">
613
                        <div style="text-align:center;font-weight:bold;margin-bottom:20px;">',
614
        isset($_SESSION['settings']['custom_logo']) && !empty($_SESSION['settings']['custom_logo']) ? '<img src="'.$_SESSION['settings']['custom_logo'].'" alt="" style="margin-bottom:40px;" />' : '', '<br />
615
                            '.$LANG['index_get_identified'].'
616
                            <span id="ajax_loader_connexion" style="display:none;margin-left:10px;"><span class="fa fa-cog fa-spin fa-1x"></span></span>
617
                        </div>
618
                        <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>';
619
        echo '
620
                        <div style="margin-bottom:3px;">
621
                            <label for="login" class="form_label">', isset($_SESSION['settings']['custom_login_text']) && !empty($_SESSION['settings']['custom_login_text']) ? $_SESSION['settings']['custom_login_text'] : $LANG['index_login'], '</label>
622
                            <input type="text" size="10" id="login" name="login" class="input_text text ui-widget-content ui-corner-all" />
623
                            <span id="login_check_wait" style="display:none; float:right;"><i class="fa fa-cog fa-spin fa-1x"></i></span>
624
                        </div>';
625
626
        // AGSES
627 View Code Duplication
        if (isset($_SESSION['settings']['agses_authentication_enabled']) && $_SESSION['settings']['agses_authentication_enabled'] == 1) {
628
            echo '
629
                        <div id="agses_cardid_div" style="text-align:center; display:none; padding:5px; width:454px; margin-bottom:5px;" class="ui-state-active ui-corner-all">
630
                            '.$LANG['user_profile_agses_card_id'].': &nbsp;
631
                            <input type="text" size="12" id="agses_cardid">
632
                        </div>
633
                        <div id="agses_flickercode_div" style="text-align:center; display:none;">
634
                            <canvas id="axs_canvas"></canvas>
635
                        </div>';
636
        }
637
638
                        echo '
639
                        <div id="connect_pw" style="margin-bottom:3px;">
640
                            <label for="pw" class="form_label" id="user_pwd">'.$LANG['index_password'].'</label>
641
                            <input type="password" size="10" id="pw" name="pw" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($_SESSION['settings']['duo']) && $_SESSION['settings']['duo'] == 1 ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($_SESSION['settings']['google_authentication']) && $_SESSION['settings']['google_authentication'] == 1 ? 1 : '', '\')" class="input_text text ui-widget-content ui-corner-all" />
642
                        </div>';
643
644
        // Personal salt key
645
        if (isset($_SESSION['settings']['psk_authentication']) && $_SESSION['settings']['psk_authentication'] == 1) {
646
            echo '
647
                        <div id="connect_psk" style="margin-bottom:3px;">
648
                            <label for="personal_psk" class="form_label">'.$LANG['home_personal_saltkey'].'</label>
649
                            <input type="password" size="10" id="psk" name="psk" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($_SESSION['settings']['duo']) && $_SESSION['settings']['duo'] == 1 ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($_SESSION['settings']['psk_authentication']) && $_SESSION['settings']['psk_authentication'] == 1 ? 1 : '', '\')" class="input_text text ui-widget-content ui-corner-all" />
650
                        </div>
651
                        <div id="connect_psk_confirm" style="margin-bottom:3px; display:none;">
652
                            <label for="psk_confirm" class="form_label">'.$LANG['home_personal_saltkey_confirm'].'</label>
653
                            <input type="password" size="10" id="psk_confirm" name="psk_confirm" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($_SESSION['settings']['duo']) && $_SESSION['settings']['duo'] == 1 ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($_SESSION['settings']['psk_authentication']) && $_SESSION['settings']['psk_authentication'] == 1 ? 1 : '', '\')" class="input_text text ui-widget-content ui-corner-all" />
654
                        </div>';
655
        }
656
657
        // Google Authenticator code
658
        if (isset($_SESSION['settings']['google_authentication']) && $_SESSION['settings']['google_authentication'] === "1") {
659
            echo '
660
                        <div id="ga_code_div" style="margin-bottom:10px;">
661
                            '.$LANG['ga_identification_code'].'
662
                            <input type="text" size="4" id="ga_code" name="ga_code" style="margin:0px;" class="input_text text ui-widget-content ui-corner-all numeric_only" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($_SESSION['settings']['duo']) && $_SESSION['settings']['duo'] == 1 ? 1 : '', '\', \''.$nextUrl.'\')" />
663
                        <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>
664
                        <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>
665
                        </div>';
666
        }
667
        echo '
668
                        <div style="margin-bottom:3px;">
669
                            <label for="duree_session" class="">'.$LANG['index_session_duration'].'&nbsp;('.$LANG['minutes'].') </label>
670
                            <input type="text" size="4" id="duree_session" name="duree_session" value="', isset($_SESSION['settings']['default_session_expiration_time']) ? $_SESSION['settings']['default_session_expiration_time'] : "60", '" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($_SESSION['settings']['duo']) && $_SESSION['settings']['duo'] == 1 ? 1 : '', '\', \''.$nextUrl.'\')" class="input_text text ui-widget-content ui-corner-all numeric_only" />
671
                        </div>
672
673
                        <div style="text-align:center;margin-top:5px;font-size:10pt;">
674
                            <span onclick="OpenDialog(\'div_forgot_pw\')" style="padding:3px;cursor:pointer;">'.$LANG['forgot_my_pw'].'</span>
675
                        </div>
676
                        <div style="text-align:center;margin-top:15px;">
677
                            <input type="button" id="but_identify_user" onclick="launchIdentify(\'', isset($_SESSION['settings']['duo']) && $_SESSION['settings']['duo'] == 1 ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($_SESSION['settings']['psk_authentication']) && $_SESSION['settings']['psk_authentication'] == 1 ? 1 : '', '\')" style="padding:3px;cursor:pointer;" class="ui-state-default ui-corner-all" value="'.$LANG['index_identify_button'].'" />
678
                        </div>
679
                    </div>
680
                </form>
681
                <script type="text/javascript">
682
                    $("#login").focus();
683
                </script>';
684
        // DIV for forgotten password
685
        echo '
686
                <div id="div_forgot_pw" style="display:none;">
687
                    <div style="margin:5px auto 5px auto;" id="div_forgot_pw_alert"></div>
688
                    <div style="margin:5px auto 5px auto;">'.$LANG['forgot_my_pw_text'].'</div>
689
                    <label for="forgot_pw_email">'.$LANG['email'].'</label>
690
                    <input type="text" size="40" name="forgot_pw_email" id="forgot_pw_email" />
691
                    <br />
692
                    <label for="forgot_pw_login">'.$LANG['login'].'</label>
693
                    <input type="text" size="20" name="forgot_pw_login" id="forgot_pw_login" />
694
                    <div id="div_forgot_pw_status" style="text-align:center;margin-top:15px;display:none; padding:5px;" class="ui-corner-all"><
695
                        <i class="fa fa-cog fa-spin fa-2x"></i>&nbsp;<b>'.$LANG['please_wait'].'</b>
696
                    </div>
697
                </div>';
698
    }
699
echo '
700
    </div>';
701
// FOOTER
702
/* DON'T MODIFY THE FOOTER ... MANY THANKS TO YOU */
703
echo '
704
    <div id="footer">
705
        <div style="float:left;width:32%;">
706
            <a href="http://teampass.net/about" target="_blank" style="color:#F0F0F0;">'.$k['tool_name'].'&nbsp;'.$k['version'].'&nbsp;<i class="fa fa-copyright"></i>&nbsp;'.$k['copyright'].'</a>
707
            &nbsp;|&nbsp;
708
            <a href="http://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>
709
            &nbsp;
710
            <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>
711
        </div>
712
        <div style="float:left;width:32%;text-align:center;">
713
            ', (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) ? '<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>' : '', '
714
        </div><div id="countdown2"></div>
715
        <div style="float:right;text-align:right;">
716
            <i class="fa fa-clock-o"></i>&nbsp;'. $LANG['server_time']." : ".@date($_SESSION['settings']['date_format'], $_SERVER['REQUEST_TIME'])." - ".@date($_SESSION['settings']['time_format'], $_SERVER['REQUEST_TIME']).'
717
        </div>
718
    </div>';
719
// PAGE LOADING
720
echo '
721
    <div id="div_loading" style="display:none;">
722
        <div style="padding:5px; z-index:9999999;" class="ui-widget-content ui-state-focus ui-corner-all">
723
            <i class="fa fa-cog fa-spin fa-2x"></i>
724
        </div>
725
    </div>';
726
// Alert BOX
727
echo '
728
    <div id="div_dialog_message" style="display:none;">
729
        <div id="div_dialog_message_text"></div>
730
    </div>';
731
732
// WARNING FOR QUERY ERROR
733
echo '
734
    <div id="div_mysql_error" style="display:none;">
735
        <div style="padding:10px;text-align:center;" id="mysql_error_warning"></div>
736
    </div>';
737
738
739
//Personnal SALTKEY
740
if (
741
    isset($_SESSION['settings']['enable_pf_feature']) && $_SESSION['settings']['enable_pf_feature'] == 1
742
    //&& (!isset($_SESSION['settings']['psk_authentication']) || $_SESSION['settings']['psk_authentication'] == 0)
743
) {
744
    echo '
745
        <div id="div_set_personal_saltkey" style="display:none;padding:4px;">
746
            <i class="fa fa-key"></i> <b>'.$LANG['home_personal_saltkey'].'</b>
747
            <input type="password" name="input_personal_saltkey" id="input_personal_saltkey" style="width:200px;padding:5px;margin-left:30px;" class="text ui-widget-content ui-corner-all text_without_symbols tip" value="', isset($_SESSION['my_sk']) ? $_SESSION['my_sk'] : '', '" title="<i class=\'fa fa-bullhorn\'></i>&nbsp;'.$LANG['text_without_symbols'].'" />
748
            <span id="set_personal_saltkey_last_letter" style="font-weight:bold;font-size:20px;"></span>
749
            <div style="display:none;margin-top:5px;text-align:center;padding:4px;" id="set_personal_saltkey_warning" class="ui-widget-content ui-state-error ui-corner-all"></div>
750
        </div>';
751
}
752
753
// user profile
754
echo '
755
<div id="dialog_user_profil" style="display:none;padding:4px;">
756
    <div id="div_user_profil">
757
        <i class="fa fa-cog fa-spin fa-2x"></i>&nbsp;<b>'.$LANG['please_wait'].'</b>
758
    </div>
759
</div>';
760
761
// DUO box
762
echo '
763
<div id="dialog_duo" style="display:none;padding:4px;">
764
    <div id="div_duo"></div>
765
    '.$LANG['duo_loading_iframe'].'
766
    <form method="post" id="duo_form" action="#">
767
        <input type="hidden" id="duo_login" name="duo_login" value="'.@$_POST['duo_login'].'" />
768
        <input type="hidden" id="duo_data" name="duo_data" value=\''.@$_POST['duo_data'].'\' />
769
    </form>
770
</div>';
771
772
// INCREASE session time
773
echo '
774
<div id="div_increase_session_time" style="display:none;padding:4px;">
775
    <b>'.$LANG['index_session_duration'].':</b>
776
    <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']) ? $_SESSION['user_settings']['session_duration'] / 60 : 60, '" />
777
    <b>'.$LANG['minutes'].'</b>
778
    <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>
779
</div>';
780
781
closelog();
782
783
?>
784
<script type="text/javascript">NProgress.start();</script>
785
    </body>
786
</html>