forked from TestLinkOpenSourceTRMS/testlink-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (142 loc) · 4.75 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* TestLink Open Source Project - http://testlink.sourceforge.net/
* This script is distributed under the GNU General Public License 2 or later.
*
* @filesource index.php
* @package TestLink
* @copyright 2006-2019, TestLink community
* @link http://www.testlink.org
*
*
**/
require_once('config.inc.php');
require_once('common.php');
require_once('configCheck.php');
checkConfiguration();
doSessionStart();
// will be very interesting understand why we do this
unset($_SESSION['basehref']);
setPaths();
$args = initArgs();
// verify the session during a work
$redir2login = true;
if( isset($_SESSION['currentUser']) ) {
// Session exists we need to do other checks.
// we use/copy Mantisbt approach
$securityCookie = tlUser::auth_get_current_user_cookie();
$redir2login = is_null($securityCookie);
if(!$redir2login) {
doDBConnect($db,database::ONERROREXIT);
$user = new tlUser();
$user->dbID = $_SESSION['currentUser']->dbID;
$user->readFromDB($db);
$dbSecurityCookie = $user->getSecurityCookie();
$redir2login = ( $securityCookie != $dbSecurityCookie );
}
}
if($redir2login) {
// destroy user in session as security measure
unset($_SESSION['currentUser']);
// If session does not exists I think is better in order to
// manage other type of authentication method/schemas
// to understand that this is a sort of FIRST Access.
//
// When TL undertand that session exists but has expired
// is OK to call login with expired indication, but is not this case
//
// Dev Notes:
// may be we are going to login.php and it will call us again!
$urlo = TL_BASE_HREF . "login.php" . ($args->ssodisable ? '?ssodisable' : '');
redirect($urlo);
exit;
}
// We arrive to these lines only if we are logged in
//
// Calling testlinkInitPage() I'm doing what we do on navBar.php
// navBar.php is called via main.tpl
// testlinkInitPage($db,('initProject' == 'initProject'));
$gui = initGui($db,$args);
$tplEngine = new TLSmarty();
$tplEngine->assign('gui', $gui);
$tplEngine->display('../dashio/main.tpl');
/**
*
*/
function initArgs() {
$iParams = array(
"reqURI" => array(tlInputParameter::STRING_N,0,4000),
"action" => array(tlInputParameter::STRING_N,1,15),
"activeMenu" => array(tlInputParameter::STRING_N,6,20),
"projectView" => array(tlInputParameter::INT_N));
//:q!dump($_REQUEST);
$args = new stdClass();
R_PARAMS($iParams,$args);
$args->user = $_SESSION['currentUser'];
$args->ssodisable = getSSODisable();
// CWE-79:
// Improper Neutralization of Input
// During Web Page Generation ('Cross-site Scripting')
//
// https://cxsecurity.com/issue/WLB-2019110139
if ($args->reqURI != '') {
// some sanity checks
// strpos ( string $haystack , mixed $needle
if (stripos($args->reqURI,'javascript') !== false) {
$args->reqURI = null;
}
}
if (null == $args->reqURI) {
$args->reqURI = 'lib/general/mainPage.php';
}
$args->reqURI = $_SESSION['basehref'] . $args->reqURI;
$k2l = array('tproject_id','current_tproject_id','tplan_id');
foreach($k2l as $pp) {
$args->$pp = isset($_REQUEST[$pp]) ? intval($_REQUEST[$pp]) : 0;
}
// active menu needs to be validated using white list
$items = getFirstLevelMenuStructure();
$args->activeMenu = trim($args->activeMenu);
if (!isset($args->activeMenu) ) {
$args->activeMenu = '';
}
$args->projectView = ($args->projectView > 0) ? 1 : 0;
return $args;
}
/**
*
*
*/
function initGui(&$dbH,&$argsObj) {
list($add2args,$gui,$tprojMgr) = initUserEnv($dbH,$argsObj);
$gui->action = $argsObj->action;
$gui->title = lang_get('main_page_title');
$gui->navbar_height = config_get('navbar_height');
$sso = ($argsObj->ssodisable ? '&ssodisable' : '');
$gui->logout = 'logout.php?viewer=' . $sso;
$gui->current_tproject_id = $argsObj->current_tproject_id;
if( $argsObj->current_tproject_id == 0 ) {
$gui->current_tproject_id = $argsObj->tproject_id;
}
$gui->tproject_id = $argsObj->tproject_id;
$gui->tplan_id = $argsObj->tplan_id;
$gui->titleframe = "lib/general/navBar.php?" .
"tproject_id={$gui->tproject_id}&" .
"tplan_id={$gui->tplan_id}&" .
"updateMainPage=1" . $sso;
$gui->mainframe = $argsObj->reqURI;
if( strpos($gui->mainframe,'?') !== FALSE ) {
$gui->mainframe .= "&";
} else {
$gui->mainframe .= "?";
}
// 20201022
$activateMenu = "";
if ($argsObj->activeMenu != "") {
$activateMenu = "&activeMenu=$argsObj->activeMenu";
}
$projView = "&projectView=$argsObj->projectView";
$gui->mainframe .= "tproject_id={$gui->tproject_id}&" .
"tplan_id={$gui->tplan_id}{$activateMenu}{$projView}";
return $gui;
}