Completed
Push — development ( 351bb8...cf7e58 )
by Nils
08:11
created

index.php (3 issues)

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-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')) {
50
    require_once '../includes/config/tp.config.php';
51
} elseif (file_exists('./includes/config/tp.config.php')) {
52
    require_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
64
// initialize session
65
$_SESSION['CPM'] = 1;
66 View Code Duplication
if (isset($SETTINGS['cpassman_dir']) === false || $SETTINGS['cpassman_dir'] === "") {
67
    $SETTINGS['cpassman_dir'] = ".";
68
    $SETTINGS['cpassman_url'] = $superGlobal->get("REQUEST_URI", "SERVER");
69
}
70
71
// Include files
72
require_once $SETTINGS['cpassman_dir'].'/sources/SplClassLoader.php';
73
require_once $SETTINGS['cpassman_dir'].'/sources/main.functions.php';
74
75
76
// Open MYSQL database connection
77
require_once './includes/libraries/Database/Meekrodb/db.class.php';
78
$pass = defuse_return_decrypted($pass);
79
DB::$host = $server;
80
DB::$user = $user;
81
DB::$password = $pass;
82
DB::$dbName = $database;
83
DB::$port = $port;
84
DB::$encoding = $encoding;
85
DB::$error_handler = true;
86
$link = mysqli_connect($server, $user, $pass, $database, $port);
87
$link->set_charset($encoding);
88
89
90
// Load Core library
91
require_once $SETTINGS['cpassman_dir'].'/sources/core.php';
92
93
// Prepare POST variables
94
$post_language =        filter_input(INPUT_POST, 'language', FILTER_SANITIZE_STRING);
95
$post_sig_response =    filter_input(INPUT_POST, 'sig_response', FILTER_SANITIZE_STRING);
96
$post_duo_login =       filter_input(INPUT_POST, 'duo_login', FILTER_SANITIZE_STRING);
97
$post_duo_data =        filter_input(INPUT_POST, 'duo_data', FILTER_SANITIZE_STRING);
98
$post_login =           filter_input(INPUT_POST, 'login', FILTER_SANITIZE_STRING);
99
$post_pw =              filter_input(INPUT_POST, 'pw', FILTER_SANITIZE_STRING);
100
101
// Prepare superGlobal variables
102
$session_user_language =        $superGlobal->get("user_language", "SESSION");
103
$session_user_id =              $superGlobal->get("user_id", "SESSION");
104
$session_user_flag =            $superGlobal->get("user_language_flag", "SESSION");
105
$session_user_admin =           $superGlobal->get("user_admin", "SESSION");
106
$session_user_human_resources = $superGlobal->get("user_can_manage_all_users", "SESSION");
107
$session_user_avatar_thumb =    $superGlobal->get("user_avatar_thumb", "SESSION");
108
$session_name =                 $superGlobal->get("name", "SESSION");
109
$session_lastname =             $superGlobal->get("lastname", "SESSION");
110
$session_user_manager =         $superGlobal->get("user_manager", "SESSION");
111
$session_user_read_only =       $superGlobal->get("user_read_only", "SESSION");
112
$session_is_admin =             $superGlobal->get("is_admin", "SESSION");
113
$session_login =                $superGlobal->get("login", "SESSION");
114
$session_validite_pw =          $superGlobal->get("validite_pw", "SESSION");
115
$session_nb_folders =           $superGlobal->get("nb_folders", "SESSION");
116
$session_nb_roles =             $superGlobal->get("nb_roles", "SESSION");
117
$session_autoriser =            $superGlobal->get("autoriser", "SESSION");
118
$session_hide_maintenance =     $superGlobal->get("hide_maintenance", "SESSION");
119
$session_initial_url =          $superGlobal->get("initial_url", "SESSION");
120
$server_request_uri =           $superGlobal->get("REQUEST_URI", "SERVER");
121
$session_nb_users_online =      $superGlobal->get("nb_users_online", "SESSION");
122
123
124
/* DEFINE WHAT LANGUAGE TO USE */
125
if (isset($_GET['language']) === true) {
126
    // case of user has change language in the login page
127
    $dataLanguage = DB::queryFirstRow(
128
        "SELECT flag, name
129
        FROM ".prefix_table("languages")."
130
        WHERE name = %s",
131
        filter_var($_GET['language'], FILTER_SANITIZE_STRING)
132
    );
133
    $superGlobal->put("user_language", $dataLanguage['name'], "SESSION");
134
    $superGlobal->put("user_language_flag", $dataLanguage['flag'], "SESSION");
135
} elseif ($session_user_id === null && null === $post_language && $session_user_language === null) {
136
    //get default language
137
    $dataLanguage = DB::queryFirstRow(
138
        "SELECT m.valeur AS valeur, l.flag AS flag
139
        FROM ".prefix_table("misc")." AS m
140
        INNER JOIN ".prefix_table("languages")." AS l ON (m.valeur = l.name)
141
        WHERE m.type=%s_type AND m.intitule=%s_intitule",
142
        array(
143
            'type' => "admin",
144
            'intitule' => "default_language"
145
        )
146
    );
147
    if (empty($dataLanguage['valeur'])) {
148
        $superGlobal->put("user_language", "english", "SESSION");
149
        $superGlobal->put("user_language_flag", "us.png", "SESSION");
150
        $session_user_language = "english";
151
    } else {
152
        $superGlobal->put("user_language", $dataLanguage['valeur'], "SESSION");
153
        $superGlobal->put("user_language_flag", $dataLanguage['flag'], "SESSION");
154
        $session_user_language = $dataLanguage['valeur'];
155
    }
156
} elseif (isset($SETTINGS['default_language']) === true && $session_user_language === null) {
157
    $superGlobal->put("user_language", $SETTINGS['default_language'], "SESSION");
158
    $session_user_language = $SETTINGS['default_language'];
159
} elseif (null !== $post_language) {
160
    $superGlobal->put("user_language", $post_language, "SESSION");
161
    $session_user_language = $post_language;
162
} elseif ($session_user_language === null || empty($session_user_language) === true) {
163
    if (null !== $post_language) {
164
        $superGlobal->put("user_language", $post_language, "SESSION");
165
        $session_user_language = $post_language;
166 View Code Duplication
    } elseif ($session_user_language !== null) {
167
        $superGlobal->put("user_language", $SETTINGS['default_language'], "SESSION");
168
        $session_user_language = $SETTINGS['default_language'];
169
    }
170 View Code Duplication
} elseif ($session_user_language === '0') {
171
    $superGlobal->put("user_language", $SETTINGS['default_language'], "SESSION");
172
    $session_user_language = $SETTINGS['default_language'];
173
}
174
175 View Code Duplication
if (isset($SETTINGS['cpassman_dir']) === false || $SETTINGS['cpassman_dir'] === "") {
176
    $SETTINGS['cpassman_dir'] = ".";
177
    $SETTINGS['cpassman_url'] = (string) $server_request_uri;
178
}
179
180
// Load user languages files
181
if (in_array($session_user_language, $languagesList) === true) {
182 View Code Duplication
    if (file_exists($SETTINGS['cpassman_dir'].'/includes/language/'.$session_user_language.'.php') === true) {
183
        require_once $SETTINGS['cpassman_dir'].'/includes/language/'.$session_user_language.'.php';
184
    }
185
} else {
186
    $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
187
    include $SETTINGS['cpassman_dir'].'/error.php';
188
}
189
190
// load 2FA Google
191
if (isset($SETTINGS['google_authentication']) === true && $SETTINGS['google_authentication'] === "1") {
192
    include_once($SETTINGS['cpassman_dir']."/includes/libraries/Authentication/TwoFactorAuth/TwoFactorAuth.php");
193
}
194
195
// Load links, css and javascripts
196
if (isset($_SESSION['CPM']) === true && isset($SETTINGS['cpassman_dir']) === true) {
197
    require_once $SETTINGS['cpassman_dir'].'/load.php';
198
}
199
200
?>
201
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
202
203
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
204
<head>
205
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
206
<meta http-equiv="X-UA-Compatible" content="IE=edge">
207
<title>Teampass</title>
208
<script type="text/javascript">
209
    //<![CDATA[
210
    if (window.location.href.indexOf("page=") == -1 && (window.location.href.indexOf("otv=") == -1 && window.location.href.indexOf("action=") == -1)) {
211
        if (window.location.href.indexOf("session_over=true") == -1) {
212
            //location.replace("./index.php?page=items");
213
        } else {
214
            location.replace("./logout.php");
215
        }
216
    }
217
    //]]>
218
</script>
219
<?php
220
221
// load HEADERS
222
if (isset($_SESSION['CPM'])) {
223
    echo $htmlHeaders;
224
}
225
?>
226
    </head>
227
228
<body>
229
    <?php
230
231
/* HEADER */
232
    echo '
233
    <div id="top">
234
        <div id="logo"><img src="includes/images/canevas/logo.png" alt="" /></div>';
235
    // Display menu
236
    if (empty($session_login) === false) {
237
        // welcome message
238
        echo '
239
        <div style="float:right; margin:-10px 5px 0 0; color:#FFF;">'
240
            .$LANG['index_welcome'].'&nbsp;<b>'.$session_name.'&nbsp;'.$session_lastname
241
            .'&nbsp;['.$session_login.']</b>&nbsp;-&nbsp;'
242
            , $session_user_admin === '1' ? $LANG['god'] :
243
                ($session_user_manager === '1' ? $LANG['gestionnaire'] :
244
                    ($session_user_read_only === '1' ? $LANG['read_only_account'] :
245
                        ($session_user_human_resources === '1' ? $LANG['human_resources'] :$LANG['user'])
246
                    )
247
                ), '&nbsp;'.strtolower($LANG['index_login']).'</div>';
248
249
        echo '
250
        <div id="menu_top">
251
            <div style="margin-left:20px; margin-top:2px;width:710px;" id="main_menu">';
252
        if ($session_user_admin === '0' || $SETTINGS_EXT['admin_full_right'] == 0) {
253
            echo '
254
                <a class="btn btn-default" href="#"',
255
                ($session_nb_folders !== null && intval($session_nb_folders) === 0)
256
                || ($session_nb_roles !== null && intval($session_nb_roles) === 0) ? '' : ' onclick="MenuAction(\'items\')"',
257
                '>
258
                    <i class="fa fa-key fa-2x tip" title="'.$LANG['pw'].'"></i>
259
                </a>
260
261
                <a class="btn btn-default" href="#"',
262
                ($session_nb_folders !== null && intval($session_nb_folders) === 0)
263
                || ($session_nb_roles !== null && intval($session_nb_roles) === 0) ? '' : ' onclick="MenuAction(\'find\')"',
264
                '>
265
                    <i class="fa fa-binoculars fa-2x tip" title="'.$LANG['find'].'"></i>
266
                </a>';
267
        }
268
269
        // Favourites menu
270
        if (isset($SETTINGS['enable_favourites'])
271
            && $SETTINGS['enable_favourites'] == 1
272
            &&
273
            ($session_user_admin === '0' || ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === false))
274
        ) {
275
            echo '
276
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'favourites\')">
277
                        <i class="fa fa-star fa-2x tip" title="'.$LANG['my_favourites'].'"></i>
278
                    </a>';
279
        }
280
        // KB menu
281 View Code Duplication
        if (isset($SETTINGS['enable_kb']) && $SETTINGS['enable_kb'] == 1) {
282
            echo '
283
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'kb\')">
284
                        <i class="fa fa-map-signs fa-2x tip" title="'.$LANG['kb_menu'].'"></i>
285
                    </a>';
286
        }
287
        echo '
288
        <span id="menu_suggestion_position">';
289
        // SUGGESTION menu
290
        if (isset($SETTINGS['enable_suggestion']) && $SETTINGS['enable_suggestion'] === '1'
291
            && ($session_user_read_only === '1' || $session_user_admin === '1' || $session_user_manager === '1')
292
        ) {
293
            echo '
294
                <a class="btn btn-default" href="#" onclick="MenuAction(\'suggestion\')">
295
                    <i class="fa fa-lightbulb-o fa-2x tip" id="menu_icon_suggestions" title="'.$LANG['suggestion_menu'].'"></i>
296
                </a>';
297
        }
298
        echo '
299
        </span>';
300
        // Admin menu
301
        if ($session_user_admin === '1') {
302
            echo '
303
                    &nbsp;
304
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_main\')">
305
                        <i class="fa fa-info fa-2x tip" title="'.$LANG['admin_main'].'"></i>
306
                    </a>
307
                    <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_settings\')">
308
                        <i class="fa fa-wrench fa-2x tip" title="'.$LANG['admin_settings'].'"></i>
309
                    </a>';
310
        }
311
312
        if ($session_user_admin === '1' || $session_user_manager === '1' || $session_user_human_resources === '1') {
313
            echo '
314
                &nbsp;
315
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_folders\')">
316
                    <i class="fa fa-folder-open fa-2x tip" title="'.$LANG['admin_groups'].'"></i>
317
                </a>
318
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_roles\')">
319
                    <i class="fa fa-graduation-cap fa-2x tip" title="'.$LANG['admin_functions'].'"></i>
320
                </a>
321
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_users\')">
322
                    <i class="fa fa-users fa-2x tip" title="'.$LANG['admin_users'].'"></i>
323
                </a>
324
                <a class="btn btn-default" href="#" onclick="MenuAction(\'manage_views\')">
325
                    <i class="fa fa-cubes fa-2x tip" title="'.$LANG['admin_views'].'"></i>
326
                </a>';
327
        }
328
329
        echo '
330
                <div style="float:right;">
331
                    <ul class="menu" style="">
332
                        <li class="" style="padding:4px;width:40px; text-align:center;"><i class="fa fa-dashboard fa-fw"></i>&nbsp;
333
                            <ul class="menu_200" style="text-align:left;">',
334
                                ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === true) ? '' : isset($SETTINGS['enable_pf_feature']) === true && $SETTINGS['enable_pf_feature'] == 1 ? '
335
                                <li onclick="$(\'#div_set_personal_saltkey\').dialog(\'open\')">
336
                                    <i class="fa fa-key fa-fw"></i> &nbsp;'.$LANG['home_personal_saltkey_button'].'
337
                                </li>' : '', '
338
                                <li onclick="$(\'#div_increase_session_time\').dialog(\'open\')">
339
                                    <i class="fa fa-clock-o fa-fw"></i> &nbsp;'.$LANG['index_add_one_hour'].'
340
                                </li>
341
                                <li onclick="loadProfileDialog()">
342
                                    <i class="fa fa-user fa-fw"></i> &nbsp;'.$LANG['my_profile'].'
343
                                </li>
344
                                <li onclick="MenuAction(\'deconnexion\', \''.$session_user_id.'\')">
345
                                    <i class="fa fa-sign-out fa-fw"></i> &nbsp;'.$LANG['disconnect'].'
346
                                </li>
347
                            </ul>
348
                        </li>
349
                    </ul>
350
                </div>';
351
352
        if ($session_user_admin !== '1' || ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === false)) {
353
            echo '
354
                <div style="float:right; margin-right:10px;">
355
                    <ul class="menu" id="menu_last_seen_items">
356
                        <li class="" style="padding:4px;width:40px; text-align:center;"><i class="fa fa-map fa-fw"></i>&nbsp;&nbsp;
357
                            <ul class="menu_200" id="last_seen_items_list" style="text-align:left;">
358
                                <li>'.$LANG['please_wait'].'</li>
359
                            </ul>
360
                        </li>
361
                    </ul>
362
                </div>';
363
        }
364
365
        // show avatar
366
        if ($session_user_avatar_thumb !== null && empty($session_user_avatar_thumb) === false) {
367
            if (file_exists('includes/avatars/'.$session_user_avatar_thumb)) {
368
                $avatar = $SETTINGS['cpassman_url'].'/includes/avatars/'.$session_user_avatar_thumb;
369
            } else {
370
                $avatar = $SETTINGS['cpassman_url'].'/includes/images/photo.jpg';
371
            }
372
        } else {
373
            $avatar = $SETTINGS['cpassman_url'].'/includes/images/photo.jpg';
374
        }
375
        echo '
376
                <div style="float:right; margin-right:10px;">
377
                    <img src="'.$avatar.'" style="border-radius:10px; height:28px; cursor:pointer;" onclick="loadProfileDialog()" alt="photo" id="user_avatar_thumb" />
378
                </div>';
379
380
        echo '
381
            </div>';
382
383
        echo '
384
        </div>';
385
    }
386
387
    echo '
388
    </div>';
389
390
    echo '
391
<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">
392
    <span class="closeButton" onclick="$(\'#main_info_box\').hide()">&#10006</span>
393
    <div id="main_info_box_text" style="text-align:center;margin-top:10px;"></div>
394
</div>';
395
396
/* MAIN PAGE */
397
    echo '
398
        <input type="hidden" id="temps_restant" value="', isset($_SESSION['fin_session']) ? $_SESSION['fin_session'] : '', '" />
399
        <input type="hidden" name="language" id="language" value="" />
400
        <input type="hidden" name="user_pw_complexity" id="user_pw_complexity" value="', isset($_SESSION['user_pw_complexity']) ? $_SESSION['user_pw_complexity'] : '', '" />
401
        <input type="hidden" name="user_session" id="user_session" value=""/>
402
        <input type="hidden" name="encryptClientServer" id="encryptClientServer" value="', isset($SETTINGS['encryptClientServer']) ? $SETTINGS['encryptClientServer'] : '1', '" />
403
        <input type="hidden" name="please_login" id="please_login" value="" />
404
        <input type="hidden" name="disabled_action_on_going" id="disabled_action_on_going" value="" />
405
        <input type="hidden" id="duo_sig_response" value="', null !== $post_sig_response ? $post_sig_response : '', '" />';
406
407
// SENDING STATISTICS?
408
    if (isset($SETTINGS['send_stats']) && $SETTINGS['send_stats'] === "1"
409
        && (!isset($_SESSION['temporary']['send_stats_done']) || $_SESSION['temporary']['send_stats_done'] !== "1")
410
    ) {
411
        echo '
412
            <input type="hidden" name="send_statistics" id="send_statistics" value="1" />';
413
    } else {
414
        echo '
415
        <input type="hidden" name="send_statistics" id="send_statistics" value="0" />';
416
    }
417
418
    echo '
419
    <div id="', (isset($_GET['page']) && filter_var($_GET['page'], FILTER_SANITIZE_STRING) === "items" && $session_user_id !== null) ? "main_simple" : "main", '">';
420
// MESSAGE BOX
421
    echo '
422
            <div style="" class="div_center">
423
                <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>
424
            </div>';
425
    // Main page
426
    if ($session_autoriser !== null && $session_autoriser === true) {
427
        // Show menu
428
        echo '
429
            <form method="post" name="main_form" action="">
430
                <input type="hidden" name="menu_action" id="menu_action" value="" />
431
                <input type="hidden" name="changer_pw" id="changer_pw" value="" />
432
                <input type="hidden" name="form_user_id" id="form_user_id" value="', $session_user_id !== null ? $session_user_id : '', '" />
433
                <input type="hidden" name="is_admin" id="is_admin" value="', $session_is_admin !== null ? $session_is_admin : '', '" />
434
                <input type="hidden" name="personal_saltkey_set" id="personal_saltkey_set" value="', isset($_SESSION['user_settings']['clear_psk']) ? true : false, '" />
435
            </form>';
436
    }
437
// ---------
438
// Display a help to admin
439
    $errorAdmin = "";
440
441
// error nb folders
442
    if ($session_nb_folders !== null && intval($session_nb_folders) === 0) {
443
        $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_folders'].'<br />';
444
    }
445
// error nb roles
446
    if ($session_nb_roles !== null && intval($session_nb_roles) === 0) {
447
        if (empty($errorAdmin)) {
448
            $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_roles'];
449
        } else {
450
            $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_no_roles'];
451
        }
452
    }
453
454
    if ($session_validite_pw !== null && empty($session_validite_pw) === false) {
455
        // error cpassman dir
456 View Code Duplication
        if (isset($SETTINGS['cpassman_dir']) && empty($SETTINGS['cpassman_dir']) || !isset($SETTINGS['cpassman_dir'])) {
457
            if (empty($errorAdmin)) {
458
                $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_dir'];
459
            } else {
460
                $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_dir'];
461
            }
462
        }
463
        // error cpassman url
464 View Code Duplication
        if ($session_validite_pw !== null && (isset($SETTINGS['cpassman_url']) && empty($SETTINGS['cpassman_url']) || !isset($SETTINGS['cpassman_url']))) {
465
            if (empty($errorAdmin)) {
466
                $errorAdmin = '<span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_url'];
467
            } else {
468
                $errorAdmin .= '<br /><span class="ui-icon ui-icon-lightbulb" style="float: left; margin-right: .3em;">&nbsp;</span>'.$LANG['error_cpassman_url'];
469
            }
470
        }
471
    }
472
// Display help
473
    if (!empty($errorAdmin)) {
474
        echo '
475
                <div style="margin:10px;padding:10px;" class="ui-state-error ui-corner-all">
476
                '.$errorAdmin.'
477
                </div>';
478
    }
479
// -----------
480
// Display Maintenance mode information
481
    if (isset($SETTINGS['maintenance_mode']) === true && $SETTINGS['maintenance_mode'] === '1'
482
            && $session_user_admin !== null && $session_user_admin === '1'
483
        ) {
484
        echo '
485
            <div style="text-align:center;margin-bottom:5px;padding:10px;" class="ui-state-highlight ui-corner-all">
486
                <b>'.$LANG['index_maintenance_mode_admin'].'</b>
487
            </div>';
488
    }
489
// Display UPDATE NEEDED information
490
    if (isset($SETTINGS['update_needed']) && $SETTINGS['update_needed'] === true
491
            && $session_user_admin !== null && $session_user_admin === '1'
492
            && (($session_hide_maintenance !== null && $session_hide_maintenance === '0')
493
            || $session_hide_maintenance === null)
494
        ) {
495
        echo '
496
            <div style="text-align:center;margin-bottom:5px;padding:10px;"
497
                class="ui-state-highlight ui-corner-all" id="div_maintenance">
498
                <b>'.$LANG['update_needed_mode_admin'].'</b>
499
                <span style="float:right;cursor:pointer;">
500
                    <span class="fa fa-close mi-red" onclick="toggleDiv(\'div_maintenance\')"></span>
501
                </span>
502
            </div>';
503
    }
504
505
// display an item in the context of OTV link
506
    if (($session_validite_pw === null || empty($session_validite_pw) === true || empty($session_user_id) === true) &&
507
        isset($_GET['otv']) && filter_var($_GET['otv'], FILTER_SANITIZE_STRING) === 'true'
508
    ) {
509
        // case where one-shot viewer
510
        if (isset($_GET['code']) && !empty($_GET['code'])
511
            && isset($_GET['stamp']) && !empty($_GET['stamp'])
512
        ) {
513
            include 'otv.php';
514
        } else {
515
            $_SESSION['error']['code'] = ERR_VALID_SESSION;
516
            $superGlobal->put(
517
                "initial_url",
518
                filter_var(
519
                    substr($server_request_uri, strpos($server_request_uri, "index.php?")),
520
                    FILTER_SANITIZE_URL
521
                ),
522
                "SESSION"
523
            );
524
            include $SETTINGS['cpassman_dir'].'/error.php';
525
        }
526
    // Ask the user to change his password
527
    } elseif (($session_validite_pw === null || $session_validite_pw === false)
528
        && empty($session_user_id) === false
529
    ) {
530
        //Check if password is valid
531
        echo '
532
        <div style="margin:auto; padding:20px; width:500px;" class="ui-state-focus ui-corner-all">
533
            <h3>'.$LANG['index_change_pw'].'</h3>
534
            <div style="height:20px;text-align:center;margin:2px;display:none;" id="change_pwd_error" class=""></div>
535
            <div style="text-align:center;margin:5px;padding:3px;" id="change_pwd_complexPw" class="ui-widget ui-state-active ui-corner-all">'.
536
            $LANG['complex_asked'].' : '.$SETTINGS_EXT['pwComplexity'][$_SESSION['user_pw_complexity']][1].
537
            '</div>
538
            <div id="pw_strength" style="margin:0 0 10px 140px;"></div>
539
            <table>
540
                <tr>
541
                    <td>'.$LANG['index_new_pw'].' :</td><td><input type="password" size="15" name="new_pw" id="new_pw"/></td>
542
                </tr>
543
                <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>
544
            </table>
545
            <input type="hidden" id="pw_strength_value" />
546
            <div style="width:420px; text-align:center; margin:15px 0 10px 0;">
547
                <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'].'" />
548
            </div>
549
        </div>
550
        <script type="text/javascript">
551
            $("#new_pw").focus();
552
        </script>';
553
    // Display pages
554
    } elseif ($session_validite_pw !== null
555
        && $session_validite_pw === true
556
        && empty($_GET['page']) === false
557
        && empty($session_user_id) === false
558
    ) {
559
        if ($session_initial_url !== null && empty($session_initial_url) === false) {
560
            include $session_initial_url;
561
        } elseif ($_GET['page'] == "items") {
562
            // SHow page with Items
563
            if (($session_user_admin !== '1')
564
                ||
565
                ($session_user_admin === '1' && $SETTINGS_EXT['admin_full_right'] === false)
566
            ) {
567
                include 'items.php';
568
            } else {
569
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
570
                include $SETTINGS['cpassman_dir'].'/error.php';
571
            }
572
        } elseif ($_GET['page'] == "find") {
573
            // Show page for items findind
574
            include 'find.php';
575
        } elseif ($_GET['page'] == "favourites") {
576
            // Show page for user favourites
577
            include 'favorites.php';
578 View Code Duplication
        } elseif ($_GET['page'] == "kb") {
579
            // Show page KB
580
            if (isset($SETTINGS['enable_kb']) && $SETTINGS['enable_kb'] == 1) {
581
                include 'kb.php';
582
            } else {
583
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
584
                include $SETTINGS['cpassman_dir'].'/error.php';
585
            }
586
        } elseif ($_GET['page'] == "suggestion") {
587
            // Show page KB
588 View Code Duplication
            if (isset($SETTINGS['enable_suggestion']) && $SETTINGS['enable_suggestion'] == 1) {
589
                include 'suggestion.php';
590
            } else {
591
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
592
                include $SETTINGS['cpassman_dir'].'/error.php';
593
            }
594
        } elseif (in_array($_GET['page'], array_keys($mngPages))) {
595
            // Define if user is allowed to see management pages
596
            if ($session_user_admin === '1') {
597
                include($mngPages[$_GET['page']]);
598
            } elseif ($session_user_manager === '1' || $session_user_human_resources == '1') {
599
                if (($_GET['page'] != "manage_main" && $_GET['page'] != "manage_settings")) {
600
                    include($mngPages[$_GET['page']]);
601
                } else {
602
                    $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
603
                    include $SETTINGS['cpassman_dir'].'/error.php';
604
                }
605
            } else {
606
                $_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
607
                include $SETTINGS['cpassman_dir'].'/error.php';
608
            }
609
        } else {
610
            $_SESSION['error']['code'] = ERR_NOT_EXIST; //page doesn't exist
611
            include $SETTINGS['cpassman_dir'].'/error.php';
612
        }
613
    // Case of password recovery
614
    } elseif (isset($_GET['action']) && $_GET['action'] === "password_recovery") {
615
        // Case where user has asked new PW
616
        echo '
617
            <div style="width:400px;margin:50px auto 50px auto;padding:25px;" class="ui-state-highlight ui-corner-all">
618
                <div style="text-align:center;font-weight:bold;margin-bottom:20px;">
619
                    '.$LANG['pw_recovery_asked'].'
620
                </div>
621
                <div id="generate_new_pw_error" style="color:red;display:none;text-align:center;margin:5px;"></div>
622
                <div style="margin-bottom:3px;">
623
                    '.$LANG['pw_recovery_info'].'
624
                </div>
625
                <div style="margin:15px; text-align:center;">
626
                    <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'].'" />
627
                    <br /><br />
628
                    <div id="ajax_loader_send_mail" style="display:none; margin: 20px;"><span class="fa fa-cog fa-spin fa-2x"></span></div>
629
                </div>
630
                <div style="margin-top:30px; text-align:center;">
631
                    <a href="index.php" class="tip" title="'.$LANG['home'].'"><span class="fa fa-home fa-lg"></span></a>
632
                </div>
633
            </div>';
634
    } elseif (empty($session_user_id) === false && $session_user_id !== null) {
635
        // Page doesn't exist
636
        $_SESSION['error']['code'] = ERR_NOT_EXIST;
637
        include $SETTINGS['cpassman_dir'].'/error.php';
638
        // When user is not identified
639
    } else {
640
        // Automatic redirection
641
        if (strpos($server_request_uri, "?") > 0) {
642
            $nextUrl = filter_var(substr($server_request_uri, strpos($server_request_uri, "?")), FILTER_SANITIZE_URL);
643
        } else {
644
            $nextUrl = "";
645
        }
646
        // MAINTENANCE MODE
647
        if (isset($SETTINGS['maintenance_mode']) === true && $SETTINGS['maintenance_mode'] === '1') {
648
            echo '
649
                <div style="text-align:center;margin-top:30px;margin-bottom:20px;padding:10px;"
650
                    class="ui-state-error ui-corner-all">
651
                    <b>'.addslashes($LANG['index_maintenance_mode']).'</b>
652
                </div>';
653
        } elseif (isset($_GET['session_over']) && $_GET['session_over'] === 'true') {
654
            // SESSION FINISHED => RECONNECTION ASKED
655
            echo '
656
                    <div style="text-align:center;margin-top:30px;margin-bottom:20px;padding:10px;"
657
                        class="ui-state-error ui-corner-all">
658
                        <b>'.addslashes($LANG['index_session_expired']).'</b>
659
                    </div>';
660
        }
661
662
        // case where user not logged and can't access a direct link
663
        if (empty($_GET['page']) === false) {
664
            $superGlobal->put(
665
                "initial_url",
666
                filter_var(
667
                    substr($server_request_uri, strpos($server_request_uri, "index.php?")),
668
                    FILTER_SANITIZE_URL
669
                ),
670
                "SESSION"
671
            );
672
            // REDIRECTION PAGE ERREUR
673
            echo '
674
            <script language="javascript" type="text/javascript">
675
            <!--
676
                sessionStorage.clear();
677
                window.location.href = "index.php";
678
            -->
679
            </script>';
680
            exit;
681
        } else {
682
            $superGlobal->put("initial_url", '', "SESSION");
683
        }
684
685
        // CONNECTION FORM
686
        echo '
687
                <form method="post" name="form_identify" id="form_identify" action="">
688
                    <div style="width:480px;margin:10px auto 10px auto;padding:25px;" class="ui-state-highlight ui-corner-all">
689
                        <div style="text-align:center;font-weight:bold;margin-bottom:20px;">',
690
        isset($SETTINGS['custom_logo']) && !empty($SETTINGS['custom_logo']) ? '<img src="'.(string) $SETTINGS['custom_logo'].'" alt="" style="margin-bottom:40px;" />' : '', '<br />
691
                            '.$LANG['index_get_identified'].'
692
                            <span id="ajax_loader_connexion" style="display:none;margin-left:10px;"><span class="fa fa-cog fa-spin fa-1x"></span></span>
693
                        </div>
694
                        <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>';
695
696
        if (isset($SETTINGS['enable_http_request_login']) === true
697
            && $SETTINGS['enable_http_request_login'] === '1'
698
            && isset($_SERVER['PHP_AUTH_USER']) === true
699
            && !(isset($SETTINGS['maintenance_mode']) === true
700
            && $SETTINGS['maintenance_mode'] === '1')
701
        ) {
702 View Code Duplication
            if (strpos($_SERVER['PHP_AUTH_USER'], '@') !== false) {
703
				$username = explode("@", $_SERVER['PHP_AUTH_USER'])[0];
704
			} elseif (strpos($_SERVER['PHP_AUTH_USER'], '\\') !== false) {
705
				$username = explode("\\", $_SERVER['PHP_AUTH_USER'])[1];
706
			} else {
707
				$username = $_SERVER['PHP_AUTH_USER'];
708
			}
709
			echo '
710
        				<div style="margin-bottom:3px;">
711
        			        <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>
0 ignored issues
show
Security Cross-Site Scripting introduced by
isset($SETTINGS['custom_... : $LANG['index_login'] can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_GET
    in includes/libraries/protect/SuperGlobal/SuperGlobal.php on line 45
  2. SuperGlobal::get() returns tainted data, and $SETTINGS is assigned
    in index.php on line 68

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
712
        		            <input type="text" size="10" id="login" name="login" class="input_text text ui-widget-content ui-corner-all" value="' , $username , '" readonly />
0 ignored issues
show
Security Cross-Site Scripting introduced by
$username can contain request data and is used in output context(s) leading to a potential security vulnerability.

3 paths for user data to reach this point

  1. Path: Fetching key PHP_AUTH_USER from $_SERVER, and $_SERVER['PHP_AUTH_USER'] is passed through explode(), and $username is assigned in index.php on line 703
  1. Fetching key PHP_AUTH_USER from $_SERVER, and $_SERVER['PHP_AUTH_USER'] is passed through explode(), and $username is assigned
    in index.php on line 703
  2. Path: Fetching key PHP_AUTH_USER from $_SERVER, and $_SERVER['PHP_AUTH_USER'] is passed through explode(), and $username is assigned in index.php on line 705
  1. Fetching key PHP_AUTH_USER from $_SERVER, and $_SERVER['PHP_AUTH_USER'] is passed through explode(), and $username is assigned
    in index.php on line 705
  3. Path: Fetching key PHP_AUTH_USER from $_SERVER, and $username is assigned in index.php on line 707
  1. Fetching key PHP_AUTH_USER from $_SERVER, and $username is assigned
    in index.php on line 707

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
713
        		            <span id="login_check_wait" style="display:none; float:right;"><i class="fa fa-cog fa-spin fa-1x"></i></span>
714
                        </div>';
715
		} else {
716
        	echo '
717
                    	    <div style="margin-bottom:3px;">
718
                    	        <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>
719
                                <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 : '', '" />
720
                                <span id="login_check_wait" style="display:none; float:right;"><i class="fa fa-cog fa-spin fa-1x"></i></span>
721
                           </div>';
722
        }
723
724
        // AGSES
725
        if (isset($SETTINGS['agses_authentication_enabled']) && $SETTINGS['agses_authentication_enabled'] == 1) {
726
            echo '
727
                        <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">
728
                            '.$LANG['user_profile_agses_card_id'].': &nbsp;
729
                            <input type="text" size="12" id="agses_cardid">
730
                        </div>
731
                        <div id="agses_flickercode_div" style="text-align:center; display:none;">
732
                            <canvas id="axs_canvas"></canvas>
733
                        </div>';
734
        }
735
736
        if (!(isset($SETTINGS['enable_http_request_login']) === true && $SETTINGS['enable_http_request_login'] === '1' && isset($_SERVER['PHP_AUTH_USER']) === true   && !(isset($SETTINGS['maintenance_mode']) === true && $SETTINGS['maintenance_mode'] === '1')) ) {
737
            echo '
738
                        <div id="connect_pw" style="margin-bottom:3px;">
739
                            <label for="pw" class="form_label" id="user_pwd">'.$LANG['index_password'].'</label>
740
                            <input type="password" size="10" id="pw" name="pw" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($SETTINGS['google_authentication']) && $SETTINGS['google_authentication'] === "1" ? 1 : '', '\')" class="input_text text ui-widget-content ui-corner-all" value="', empty($post_pw) === false ? $post_pw : '', '" />
741
                        </div>';
742
        }
743
744
        // Personal salt key
745
        if (isset($SETTINGS['psk_authentication']) && $SETTINGS['psk_authentication'] === "1") {
746
            echo '
747
                        <div id="connect_psk" style="margin-bottom:3px;">
748
                            <label for="personal_psk" class="form_label">'.$LANG['home_personal_saltkey'].'</label>
749
                            <input type="password" size="10" id="psk" name="psk" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($SETTINGS['psk_authentication']) && $SETTINGS['psk_authentication'] === "1" ? 1 : '', '\')" class="input_text text ui-widget-content ui-corner-all" />
750
                        </div>
751
                        <div id="connect_psk_confirm" style="margin-bottom:3px; display:none;">
752
                            <label for="psk_confirm" class="form_label">'.$LANG['home_personal_saltkey_confirm'].'</label>
753
                            <input type="password" size="10" id="psk_confirm" name="psk_confirm" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($SETTINGS['psk_authentication']) && $SETTINGS['psk_authentication'] === "1" ? 1 : '', '\')" class="input_text text ui-widget-content ui-corner-all" />
754
                        </div>';
755
        }
756
757
        // Google Authenticator code
758
        if (isset($SETTINGS['google_authentication']) === true && $SETTINGS['google_authentication'] === "1") {
759
            echo '
760
                        <div id="ga_code_div" style="margin-bottom:10px;">
761
                            '.$LANG['ga_identification_code'].'
762
                            <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($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\')" />
763
                        <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>
764
                        <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>
765
                        </div>';
766
        }
767
        echo '
768
                        <div style="margin-bottom:3px;">
769
                            <label for="duree_session" class="">'.$LANG['index_session_duration'].'&nbsp;('.$LANG['minutes'].') </label>
770
                            <input type="text" size="4" id="duree_session" name="duree_session" value="', isset($SETTINGS['default_session_expiration_time']) ? $SETTINGS['default_session_expiration_time'] : "60", '" onkeypress="if (event.keyCode == 13) launchIdentify(\'', isset($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\')" class="input_text text ui-widget-content ui-corner-all numeric_only" />
771
                        </div>';
772
773
        // Google Authenticator code
774
        if (isset($SETTINGS['disable_show_forgot_pwd_link']) === true && $SETTINGS['google_authentication'] !== "1") {
775
            echo '
776
                        <div style="text-align:center;margin-top:5px;font-size:10pt;">
777
                            <span onclick="OpenDialog(\'div_forgot_pw\')" style="padding:3px;cursor:pointer;">'.$LANG['forgot_my_pw'].'</span>
778
                        </div>';
779
        }
780
781
        if (isset($SETTINGS['enable_http_request_login']) === true
782
            && $SETTINGS['enable_http_request_login'] === '1'
783
            && isset($_SERVER['PHP_AUTH_USER']) === true
784
            && !(isset($SETTINGS['maintenance_mode']) === true
785
            && $SETTINGS['maintenance_mode'] === '1')
786
        ) {
787
        echo	'
788
        	<script>
789
        		var seconds = 3;
790
        		function updateLogonButton(timeToGo){
791
				    document.getElementById("but_identify_user").value = "' . $LANG['duration_login_attempt'] . ' " + timeToGo;
792
				}
793
				$( window ).on( "load", function() {
794
				    updateLogonButton(seconds);
795
				    setInterval(function(){
796
						if(seconds > 0){
797
							seconds--;
798
						}else if(seconds == 0){
799
							launchIdentify(\'', isset($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($SETTINGS['psk_authentication']) && $SETTINGS['psk_authentication'] === "1" ? 1 : '', '\');
0 ignored issues
show
Security Cross-Site Scripting introduced by
'\', \'' . $nextUrl . '\', \'' can contain request data and is used in output context(s) leading to a potential security vulnerability.

1 path for user data to reach this point

  1. Read from $_GET
    in includes/libraries/protect/SuperGlobal/SuperGlobal.php on line 45
  2. SuperGlobal::get() returns tainted data, and $server_request_uri is assigned
    in index.php on line 120
  3. $server_request_uri is passed through substr(), and substr($server_request_uri, strpos($server_request_uri, '?')) is passed through filter_var(), and $nextUrl is assigned
    in index.php on line 642

Preventing Cross-Site-Scripting Attacks

Cross-Site-Scripting allows an attacker to inject malicious code into your website - in particular Javascript code, and have that code executed with the privileges of a visiting user. This can be used to obtain data, or perform actions on behalf of that visiting user.

In order to prevent this, make sure to escape all user-provided data:

// for HTML
$sanitized = htmlentities($tainted, ENT_QUOTES);

// for URLs
$sanitized = urlencode($tainted);

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
800
						}
801
						updateLogonButton(seconds);
802
					}, 1000);
803
				});
804
    		</script>';
805
        }
806
807
        echo '
808
                        <div style="text-align:center;margin-top:15px;">
809
                            <input type="button" id="but_identify_user" onclick="launchIdentify(\'', isset($SETTINGS['duo']) && $SETTINGS['duo'] === "1" ? 1 : '', '\', \''.$nextUrl.'\', \'', isset($SETTINGS['psk_authentication']) && $SETTINGS['psk_authentication'] === "1" ? 1 : '', '\')" style="padding:3px;cursor:pointer;" class="ui-state-default ui-corner-all" value="'.$LANG['index_identify_button'].'" />
810
                        </div>
811
                    </div>
812
                </form>
813
                <script type="text/javascript">
814
                    $("#login").focus();
815
                </script>';
816
        // DIV for forgotten password
817
        echo '
818
                <div id="div_forgot_pw" style="display:none;">
819
                    <div style="margin:5px auto 5px auto;" id="div_forgot_pw_alert"></div>
820
                    <div style="margin:5px auto 5px auto;">'.$LANG['forgot_my_pw_text'].'</div>
821
                    <label for="forgot_pw_email">'.$LANG['email'].'</label>
822
                    <input type="text" size="40" name="forgot_pw_email" id="forgot_pw_email" />
823
                    <br />
824
                    <label for="forgot_pw_login">'.$LANG['login'].'</label>
825
                    <input type="text" size="20" name="forgot_pw_login" id="forgot_pw_login" />
826
                    <div id="div_forgot_pw_status" style="text-align:center;margin-top:15px;display:none; padding:5px;" class="ui-corner-all">
827
                        <i class="fa fa-cog fa-spin fa-2x"></i>&nbsp;<b>'.$LANG['please_wait'].'</b>
828
                    </div>
829
                </div>';
830
    }
831
    echo '
832
    </div>';
833
// FOOTER
834
/* DON'T MODIFY THE FOOTER ... MANY THANKS TO YOU */
835
    echo '
836
    <div id="footer">
837
        <div style="float:left;width:32%;">
838
            <a href="http://teampass.net" target="_blank" style="color:#F0F0F0;">'.$SETTINGS_EXT['tool_name'].'&nbsp;'.$SETTINGS_EXT['version'].'&nbsp;<i class="fa fa-copyright"></i>&nbsp;'.$SETTINGS_EXT['copyright'].'</a>
839
            &nbsp;|&nbsp;
840
            <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>
841
            &nbsp;
842
            <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>
843
            &nbsp;
844
            ', ($session_user_id !== null && empty($session_user_id) === false) ? '
845
            <a href="#" style="color:#F0F0F0;" class="tip" title="'.addslashes($LANG['bugs_page']).'" onclick="generateBugReport()"><i class="fa fa-bug"></i></a>' : '' ,'
846
        </div>
847
        <div style="float:left;width:32%;text-align:center;">
848
            ', ($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>' : '', '
849
        </div><div id="countdown2"></div>
850
        <div style="float:right;text-align:right;">
851
            <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']).'
852
        </div>
853
    </div>';
854
// PAGE LOADING
855
    echo '
856
    <div id="div_loading" class="hidden">
857
        <div style="padding:5px; z-index:9999999;" class="ui-widget-content ui-state-focus ui-corner-all">
858
            <i class="fa fa-cog fa-spin fa-2x"></i>
859
        </div>
860
    </div>';
861
// Alert BOX
862
    echo '
863
    <div id="div_dialog_message" style="display:none;">
864
        <div id="div_dialog_message_text" style="text-align:center; padding:4px; font-size:12px; margin-top:10px;"></div>
865
    </div>';
866
867
// WARNING FOR QUERY ERROR
868
    echo '
869
    <div id="div_mysql_error" style="display:none;">
870
        <div style="padding:10px;text-align:center;" id="mysql_error_warning"></div>
871
    </div>';
872
873
874
//Personnal SALTKEY
875
    if (isset($SETTINGS['enable_pf_feature']) && $SETTINGS['enable_pf_feature'] === "1") {
876
        echo '
877
        <div id="div_set_personal_saltkey" style="display:none;padding:4px;">
878
            <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 ? $LANG['complex_asked']." : ".$SETTINGS_EXT['pwComplexity'][$SETTINGS['personal_saltkey_security_level']][1] : '', '</div>
879
            <table border="0">
880
                <tr>
881
                    <td>
882
                        <i class="fa fa-key"></i> <b>'.$LANG['home_personal_saltkey'].'</b>
883
                    </td>
884
                    <td>
885
                        <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'].'" />
886
                        <span id="set_personal_saltkey_last_letter" style="font-weight:bold;font-size:20px;"></span>
887
                    </td>
888
                </tr>
889
                <tr>
890
                    <td></td>
891
                    <td>
892
                        <div id="psk_strength" style="margin:3px 0 0 10px;"></div>
893
                        <input type="hidden" id="psk_strength_value" />
894
                    </td>
895
                </tr>
896
            </table>
897
            <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>
898
        </div>';
899
    }
900
901
// user profile
902
    echo '
903
<div id="dialog_user_profil" style="display:none;padding:4px;">
904
    <div id="div_user_profil">
905
        <i class="fa fa-cog fa-spin fa-2x"></i>&nbsp;<b>'.$LANG['please_wait'].'</b>
906
    </div>
907
</div>';
908
909
// DUO box
910
    echo '
911
<div id="dialog_duo" style="display:none;padding:4px;">
912
    <div id="div_duo"></div>
913
    '.$LANG['duo_loading_iframe'].'
914
    <form method="post" id="duo_form" action="">
915
        <input type="hidden" id="duo_login" name="duo_login" value="', null !== $post_duo_login ? $post_duo_login : '', '" />
916
        <input type="hidden" id="duo_data" name="duo_data" value="', null !== $post_duo_data ? htmlentities(base64_decode($post_duo_data)) : '', '" />
917
    </form>
918
</div>';
919
920
// INCREASE session time
921
    echo '
922
<div id="div_increase_session_time" style="display:none;padding:4px;">
923
    <b>'.$LANG['index_session_duration'].':</b>
924
    <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, '" />
925
    <b>'.$LANG['minutes'].'</b>
926
    <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>
927
</div>';
928
929
    closelog();
930
931
?>
932
<script type="text/javascript">NProgress.start();</script>
933
    </body>
934
</html>
935