FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/server/ServerLoginPages.cpp at main · ssh352/rstudio · GitHub
ssh352
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
server
/
ServerLoginPages.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
169 lines (145 loc) · 6.15 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
server
/
ServerLoginPages.cpp
Copy path
File metadata and controls
169 lines (145 loc) · 6.15 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
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
/*
* ServerLoginPages.cpp
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
"
ServerLoginPages.hpp
"
#
include
<
boost/format.hpp
>
#
include
<
shared_core/SafeConvert.hpp
>
#
include
<
shared_core/FilePath.hpp
>
#
include
<
core/http/URL.hpp
>
#
include
<
core/http/Request.hpp
>
#
include
<
core/http/Response.hpp
>
#
include
<
core/text/TemplateFilter.hpp
>
#
include
<
server/ServerOptions.hpp
>
#
include
<
server/auth/ServerAuthHandler.hpp
>
#
include
<
server/auth/ServerAuthHandlerOverlay.hpp
>
const
char
*
const
kStaySignedInDisplay
=
"
staySignedInDisplay
"
;
const
char
*
const
kAuthTimeoutMinutes
=
"
authTimeoutMinutes
"
;
const
char
*
const
kAuthTimeoutMinutesDisplay
=
"
authTimeoutMinutesDisplay
"
;
const
char
*
const
kIsRStudioProDesktop
=
"
isRdp
"
;
const
char
*
const
kLogoHtml
=
"
logoHtml
"
;
namespace
rstudio
{
namespace
server
{
std::string
loginErrorMessage
(ErrorType error)
{
switch
(error)
{
case
kErrorNone
:
return
"
"
;
case
kErrorInvalidLogin
:
return
"
Incorrect or invalid username/password
"
;
case
kErrorServer
:
return
"
Temporary server error, please try again
"
;
case
kErrorUserUnauthorized
:
return
"
Unauthorized user.
"
;
case
kErrorUserLicenseLimitReached
:
return
"
The user limit for this license has been reached, or you are not allowed access.
"
;
case
kErrorUserLicenseSystemUnavailable
:
return
"
The user licensing system is temporarily unavailable. Please try again later.
"
;
}
return
"
"
;
}
void
fillLoginFields
(
const
core::http::Request& request,
const
std::string& formAction,
std::map<std::string, std::string>& variables)
{
variables[
"
action
"
] =
core::http::URL::uncomplete
(request.
uri
(), formAction);
//
fill stay signed in
variables[
kStaySignedInDisplay
] =
auth::handler::overlay::canStaySignedIn
() ?
"
block
"
:
"
none
"
;
int
timeoutMinutes =
server::options
().
authTimeoutMinutes
();
variables[
kAuthTimeoutMinutesDisplay
] = timeoutMinutes >
0
?
"
block
"
:
"
none
"
;
variables[
kAuthTimeoutMinutes
] =
core::safe_convert::numberToString
(timeoutMinutes);
//
fill error
std::string error = request.
queryParamValue
(
kErrorParam
);
variables[
kErrorMessage
] =
loginErrorMessage
(
static_cast
<ErrorType>(
core::safe_convert::stringTo<
unsigned
>(error,
kErrorNone
)));
variables[
kErrorDisplay
] = error.
empty
() ?
"
none
"
:
"
block
"
;
//
get the application uri the user was on the way to (default to
//
root location if it isn't specified)
variables[
kAppUri
] = request.
queryParamValue
(
kAppUri
);
//
include custom login page html
bool
isRdp = request.
queryParamValue
(
kIsRStudioProDesktop
) ==
"
1
"
;
boost::format
logoImgHtmlFormat
(
R"DELIM(
<picture>
<source
srcset="images/Posit-ProductLogo_rst-server-reverse.svg"
media="(prefers-color-scheme: dark)"/>
<img src="images/Posit-ProductLogo_rst-server-full-color.svg" height="27" alt="%1%"/>
</picture>
)DELIM"
);
if
(!isRdp)
{
variables[
kLoginPageHtml
] =
server::options
().
authLoginPageHtml
();
//
render logo with links
std::string logoImgHtml =
boost::str
(logoImgHtmlFormat %
"
Posit Software PBC (goes to external site)
"
);
variables[
kLogoHtml
] =
R"DELIM(
<a href="https://posit.co/">
)DELIM"
+ logoImgHtml +
"
</a>
"
;
}
else
{
variables[
kLoginPageHtml
] =
server::options
().
authRdpLoginPageHtml
();
//
render logo without links - user should not be able
//
to freely navigate in RDP
std::string logoImgHtml =
boost::str
(logoImgHtmlFormat %
"
RStudio Logo
"
);
variables[
kLogoHtml
] = logoImgHtml;
}
}
void
loadLoginPage
(
const
core::http::Request& request,
core::http::Response* pResponse,
const
std::string& templatePath,
const
std::string& formAction,
std::map<std::string,std::string> variables)
{
//
setup template variables
fillLoginFields
(request, formAction, variables);
//
get the path to the template file
Options& options =
server::options
();
core::FilePath
wwwPath
(options.
wwwLocalPath
());
core::FilePath signInFilePath = wwwPath.
completePath
(templatePath);
core::text::TemplateFilter
templateFilter
(variables);
//
don't allow sign-in page to be framed by other domains (clickjacking
//
defense)
pResponse->
setFrameOptionHeaders
(options.
wwwFrameOrigin
());
//
return login (processing template)
pResponse->
setNoCacheHeaders
();
pResponse->
setFile
(signInFilePath, request, templateFilter);
pResponse->
setContentType
(
"
text/html
"
);
}
std::string
generateLoginPath
(
const
core::http::Request& request,
const
std::string& appUri,
ErrorType error
/*
= kErrorNone
*/
)
{
//
build fields
core::http::Fields fields;
fields.
push_back
(
std::make_pair
(
kAppUri
, appUri));
if
(error !=
kErrorNone
)
fields.
push_back
(
std::make_pair
(
kErrorParam
,
core::safe_convert::numberToString
(error)));
//
build query string
std::string queryString;
if
(!fields.
empty
())
core::http::util::buildQueryString
(fields, &queryString);
//
generate url
std::string signInPath =
core::http::URL::uncomplete
(request.
baseUri
(), auth::handler::
kSignIn
);
if
(!queryString.
empty
())
signInPath += (
"
?
"
+ queryString);
return
signInPath;
}
void
redirectToLoginPage
(
const
core::http::Request& request,
core::http::Response* pResponse,
const
std::string& appUri,
ErrorType error
/*
= kErrorNone
*/
)
{
pResponse->
setMovedTemporarily
(
request,
generateLoginPath
(request, appUri, error));
}
}
//
namespace server
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL