mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-19 04:57:53 +00:00
Embed default template in service
This commit is contained in:
parent
da74b9651c
commit
4c22793850
@ -151,43 +151,54 @@ size_t curlResponseWrite(void *ptr, size_t size, size_t nmemb, std::string *data
|
|||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
const char *ssoResponseTemplate = "<html>\
|
std::string ssoResponseTemplate = R"""(
|
||||||
<head>\
|
<!doctype html>
|
||||||
<style type=\"text/css\">\
|
<html class="no-js" lang="">
|
||||||
html,body {\
|
<head>
|
||||||
background: #eeeeee;\
|
<meta charset="utf-8">
|
||||||
margin: 0;\
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
padding: 0;\
|
<title>Network SSO Login {{ networkId }}</title>
|
||||||
font-family: \"Helvetica\";\
|
<meta name="description" content="">
|
||||||
font-weight: bold;\
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
font-size: 12pt;\
|
<style type=\"text/css\">
|
||||||
height: 100%;\
|
html,body {
|
||||||
width: 100%;\
|
background: #eeeeee;
|
||||||
}\
|
margin: 0;
|
||||||
div.icon {\
|
padding: 0;
|
||||||
background: #ffb354;\
|
font-family: "Helvetica";
|
||||||
color: #000000;\
|
font-weight: bold;
|
||||||
font-size: 120pt;\
|
font-size: 12pt;
|
||||||
border-radius: 2.5rem;\
|
height: 100%;
|
||||||
display: inline-block;\
|
width: 100%;
|
||||||
width: 1.3em;\
|
}
|
||||||
height: 1.3em;\
|
div.icon {
|
||||||
padding: 0;\
|
background: #ffb354;
|
||||||
margin: 15;\
|
color: #000000;
|
||||||
line-height: 1.4em;\
|
font-size: 120pt;
|
||||||
vertical-align: middle;\
|
border-radius: 2.5rem;
|
||||||
text-align: center;\
|
display: inline-block;
|
||||||
}\
|
width: 1.3em;
|
||||||
</style>\
|
height: 1.3em;
|
||||||
</head>\
|
padding: 0;
|
||||||
<body>\
|
margin: 15;
|
||||||
<br><br><br><br><br><br>\
|
line-height: 1.4em;
|
||||||
<center>\
|
vertical-align: middle;
|
||||||
<div class=\"icon\">⏁</div>\
|
text-align: center;
|
||||||
<div class=\"text\">%s</div>\
|
}
|
||||||
</center>\
|
.container {
|
||||||
</body>\
|
vertical-align: center;
|
||||||
</html>";
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="icon">⏁</div>
|
||||||
|
<div class="text">{{ messageText }}</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)""";
|
||||||
|
|
||||||
// Configured networks
|
// Configured networks
|
||||||
class NetworkState
|
class NetworkState
|
||||||
@ -287,16 +298,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setConfig(const ZT_VirtualNetworkConfig *nwc) {
|
void setConfig(const ZT_VirtualNetworkConfig *nwc) {
|
||||||
char nwbuf[17] = {};
|
|
||||||
const char* nwid = Utils::hex(nwc->nwid, nwbuf);
|
|
||||||
// fprintf(stderr, "NetworkState::setConfig(%s)\n", nwid);
|
|
||||||
|
|
||||||
memcpy(&_config, nwc, sizeof(ZT_VirtualNetworkConfig));
|
memcpy(&_config, nwc, sizeof(ZT_VirtualNetworkConfig));
|
||||||
// fprintf(stderr, "ssoEnabled: %s, ssoVersion: %d\n",
|
|
||||||
// _config.ssoEnabled ? "true" : "false", _config.ssoVersion);
|
|
||||||
|
|
||||||
if (_config.ssoEnabled && _config.ssoVersion == 1) {
|
if (_config.ssoEnabled && _config.ssoVersion == 1) {
|
||||||
// fprintf(stderr, "ssoEnabled for %s\n", nwid);
|
|
||||||
#if ZT_SSO_ENABLED
|
#if ZT_SSO_ENABLED
|
||||||
if (_idc == nullptr)
|
if (_idc == nullptr)
|
||||||
{
|
{
|
||||||
@ -304,10 +308,6 @@ public:
|
|||||||
assert(_config.ssoClientID != nullptr);
|
assert(_config.ssoClientID != nullptr);
|
||||||
assert(_config.centralAuthURL != nullptr);
|
assert(_config.centralAuthURL != nullptr);
|
||||||
|
|
||||||
// fprintf(stderr, "Issuer URL: %s\n", _config.issuerURL);
|
|
||||||
// fprintf(stderr, "Client ID: %s\n", _config.ssoClientID);
|
|
||||||
// fprintf(stderr, "Central Auth URL: %s\n", _config.centralAuthURL);
|
|
||||||
|
|
||||||
_idc = zeroidc::zeroidc_new(
|
_idc = zeroidc::zeroidc_new(
|
||||||
_config.issuerURL,
|
_config.issuerURL,
|
||||||
_config.ssoClientID,
|
_config.ssoClientID,
|
||||||
@ -319,8 +319,6 @@ public:
|
|||||||
fprintf(stderr, "idc is null\n");
|
fprintf(stderr, "idc is null\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fprintf(stderr, "idc created (%s, %s, %s)\n", _config.issuerURL, _config.ssoClientID, _config.centralAuthURL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zeroidc::zeroidc_set_nonce_and_csrf(
|
zeroidc::zeroidc_set_nonce_and_csrf(
|
||||||
@ -335,7 +333,6 @@ public:
|
|||||||
zeroidc::free_cstr(url);
|
zeroidc::free_cstr(url);
|
||||||
|
|
||||||
if (zeroidc::zeroidc_is_running(_idc) && nwc->status == ZT_NETWORK_STATUS_AUTHENTICATION_REQUIRED) {
|
if (zeroidc::zeroidc_is_running(_idc) && nwc->status == ZT_NETWORK_STATUS_AUTHENTICATION_REQUIRED) {
|
||||||
// TODO: kick the refresh thread
|
|
||||||
zeroidc::zeroidc_kick_refresh_thread(_idc);
|
zeroidc::zeroidc_kick_refresh_thread(_idc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1704,29 +1701,33 @@ public:
|
|||||||
std::string htmlTemplatePath = _homePath + ZT_PATH_SEPARATOR + "sso-auth.template.html";
|
std::string htmlTemplatePath = _homePath + ZT_PATH_SEPARATOR + "sso-auth.template.html";
|
||||||
std::string htmlTemplate;
|
std::string htmlTemplate;
|
||||||
if (!OSUtils::readFile(htmlTemplatePath.c_str(), htmlTemplate)) {
|
if (!OSUtils::readFile(htmlTemplatePath.c_str(), htmlTemplate)) {
|
||||||
fprintf(stderr, "ERROR: unable to read sso result template");
|
htmlTemplate = ssoResponseTemplate;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
responseContentType = "text/html";
|
responseContentType = "text/html";
|
||||||
json outData;
|
json outData;
|
||||||
|
|
||||||
const char *error = zeroidc::zeroidc_get_url_param_value("error", path.c_str());
|
char *error = zeroidc::zeroidc_get_url_param_value("error", path.c_str());
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
const char *desc = zeroidc::zeroidc_get_url_param_value("error_description", path.c_str());
|
char *desc = zeroidc::zeroidc_get_url_param_value("error_description", path.c_str());
|
||||||
scode = 500;
|
scode = 500;
|
||||||
|
|
||||||
json data;
|
json data;
|
||||||
outData["messageText"] = (std::string("ERROR ") + error + std::string(": ") + desc);
|
outData["messageText"] = (std::string("ERROR ") + error + std::string(": ") + desc);
|
||||||
responseBody = inja::render(htmlTemplate, outData);
|
responseBody = inja::render(htmlTemplate, outData);
|
||||||
|
|
||||||
|
zeroidc::free_cstr(desc);
|
||||||
|
zeroidc::free_cstr(error);
|
||||||
|
|
||||||
return scode;
|
return scode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSO redirect handling
|
// SSO redirect handling
|
||||||
char* state = zeroidc::zeroidc_get_url_param_value("state", path.c_str());
|
char* state = zeroidc::zeroidc_get_url_param_value("state", path.c_str());
|
||||||
char* nwid = zeroidc::zeroidc_network_id_from_state(state);
|
char* nwid = zeroidc::zeroidc_network_id_from_state(state);
|
||||||
|
|
||||||
|
outData["networkId"] = std::string(nwid);
|
||||||
|
|
||||||
const uint64_t id = Utils::hexStrToU64(nwid);
|
const uint64_t id = Utils::hexStrToU64(nwid);
|
||||||
|
|
||||||
zeroidc::free_cstr(nwid);
|
zeroidc::free_cstr(nwid);
|
||||||
|
Loading…
Reference in New Issue
Block a user