FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
iTop/application/loginbasic.class.inc.php at develop · Combodo/iTop · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Combodo
/
iTop
Public
Notifications
You must be signed in to change notification settings
Fork
297
Star
1.2k
Code
Issues
8
Pull requests
54
Actions
Security and quality
92
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
iTop
/
application
/
loginbasic.class.inc.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
123 lines (112 loc) · 4.03 KB
Breadcrumbs
iTop
/
application
/
loginbasic.class.inc.php
Copy path
File metadata and controls
123 lines (112 loc) · 4.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
use
Combodo
\
iTop
\
Application
\
Helper
\
Session
;
/**
* Class LoginBasic
*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
class
LoginBasic
extends
AbstractLoginFSMExtension
{
/**
* Return the list of supported login modes for this plugin
*
* @return array of supported login modes
*/
public
function
ListSupportedLoginModes
()
{
return
[
'
basic
'
];
}
protected
function
OnModeDetection
(&
$
iErrorCode
)
{
if
(!Session::
IsSet
(
'
login_mode
'
)) {
if
(
isset
(
$
_SERVER
[
'
HTTP_AUTHORIZATION
'
]) && !
empty
(
$
_SERVER
[
'
HTTP_AUTHORIZATION
'
])) {
Session::
Set
(
'
login_mode
'
,
'
basic
'
);
}
elseif
(
isset
(
$
_SERVER
[
'
REDIRECT_HTTP_AUTHORIZATION
'
]) && !
empty
(
$
_SERVER
[
'
REDIRECT_HTTP_AUTHORIZATION
'
])) {
Session::
Set
(
'
login_mode
'
,
'
basic
'
);
}
elseif
(
isset
(
$
_SERVER
[
'
PHP_AUTH_USER
'
])) {
Session::
Set
(
'
login_mode
'
,
'
basic
'
);
}
}
return
LoginWebPage::
LOGIN_FSM_CONTINUE
;
}
protected
function
OnReadCredentials
(&
$
iErrorCode
)
{
if
(!Session::
IsSet
(
'
login_mode
'
) || Session::
Get
(
'
login_mode
'
) ==
'
basic
'
) {
list
(
$
sAuthUser
) =
$
this
->
GetAuthUserAndPassword
();
Session::
Set
(
'
login_temp_auth_user
'
,
$
sAuthUser
);
}
return
LoginWebPage::
LOGIN_FSM_CONTINUE
;
}
protected
function
OnCheckCredentials
(&
$
iErrorCode
)
{
if
(Session::
Get
(
'
login_mode
'
) ==
'
basic
'
) {
list
(
$
sAuthUser
,
$
sAuthPwd
) =
$
this
->
GetAuthUserAndPassword
();
if
(!UserRights::
CheckCredentials
(
$
sAuthUser
,
$
sAuthPwd
, Session::
Get
(
'
login_mode
'
),
'
internal
'
)) {
$
iErrorCode
= LoginWebPage::
EXIT_CODE_WRONGCREDENTIALS
;
return
LoginWebPage::
LOGIN_FSM_ERROR
;
}
Session::
Set
(
'
auth_user
'
,
$
sAuthUser
);
}
return
LoginWebPage::
LOGIN_FSM_CONTINUE
;
}
protected
function
OnCredentialsOK
(&
$
iErrorCode
)
{
if
(Session::
Get
(
'
login_mode
'
) ==
'
basic
'
) {
LoginWebPage::
OnLoginSuccess
(Session::
Get
(
'
auth_user
'
),
'
internal
'
, Session::
Get
(
'
login_mode
'
));
}
return
LoginWebPage::
LOGIN_FSM_CONTINUE
;
}
protected
function
OnError
(&
$
iErrorCode
)
{
if
(Session::
Get
(
'
login_mode
'
) ==
'
basic
'
) {
$
iOnExit
= LoginWebPage::
getIOnExit
();
if
(
$
iOnExit
=== LoginWebPage::
EXIT_RETURN
) {
return
LoginWebPage::
LOGIN_FSM_RETURN
;
// Error, exit FSM
}
LoginWebPage::
HTTP401Error
();
}
return
LoginWebPage::
LOGIN_FSM_CONTINUE
;
}
protected
function
OnConnected
(&
$
iErrorCode
)
{
if
(Session::
Get
(
'
login_mode
'
) ==
'
basic
'
) {
Session::
Set
(
'
can_logoff
'
,
true
);
return
LoginWebPage::
CheckLoggedUser
(
$
iErrorCode
);
}
return
LoginWebPage::
LOGIN_FSM_CONTINUE
;
}
private
function
GetAuthUserAndPassword
()
{
$
sAuthUser
=
''
;
$
sAuthPwd
=
null
;
$
sAuthorization
=
''
;
if
(
isset
(
$
_SERVER
[
'
HTTP_AUTHORIZATION
'
]) && !
empty
(
$
_SERVER
[
'
HTTP_AUTHORIZATION
'
])) {
$
sAuthorization
=
$
_SERVER
[
'
HTTP_AUTHORIZATION
'
];
}
elseif
(
isset
(
$
_SERVER
[
'
REDIRECT_HTTP_AUTHORIZATION
'
]) && !
empty
(
$
_SERVER
[
'
REDIRECT_HTTP_AUTHORIZATION
'
])) {
$
sAuthorization
=
$
_SERVER
[
'
REDIRECT_HTTP_AUTHORIZATION
'
];
}
if
(!
empty
(
$
sAuthorization
)) {
list
(
$
sAuthUser
,
$
sAuthPwd
) =
explode
(
'
:
'
,
base64_decode
(
substr
(
$
sAuthorization
,
6
)));
}
else
{
if
(
isset
(
$
_SERVER
[
'
PHP_AUTH_USER
'
])) {
$
sAuthUser
=
$
_SERVER
[
'
PHP_AUTH_USER
'
];
// Unfortunately, the RFC is not clear about the encoding...
// IE and FF supply the user and password encoded in ISO-8859-1 whereas Chrome provides them encoded in UTF-8
// So let's try to guess if it's an UTF-8 string or not... fortunately all encodings share the same ASCII base
if
(!LoginWebPage::
LooksLikeUTF8
(
$
sAuthUser
)) {
// Does not look like and UTF-8 string, try to convert it from iso-8859-1 to UTF-8
// Supposed to be harmless in case of a plain ASCII string...
$
sAuthUser
=
iconv
(
'
iso-8859-1
'
,
'
utf-8
'
,
$
sAuthUser
);
}
$
sAuthPwd
=
$
_SERVER
[
'
PHP_AUTH_PW
'
];
if
(!LoginWebPage::
LooksLikeUTF8
(
$
sAuthPwd
)) {
// Does not look like and UTF-8 string, try to convert it from iso-8859-1 to UTF-8
// Supposed to be harmless in case of a plain ASCII string...
$
sAuthPwd
=
iconv
(
'
iso-8859-1
'
,
'
utf-8
'
,
$
sAuthPwd
);
}
}
}
return
[
$
sAuthUser
,
$
sAuthPwd
];
}
}
Back
|
FazBrowse Home
|
New Git URL