From 4c227938509a547f00f715a1d6651bd3ab91bcaa Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 13 May 2022 16:18:34 -0700 Subject: [PATCH] Embed default template in service --- service/OneService.cpp | 115 +++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/service/OneService.cpp b/service/OneService.cpp index f1bbcff55..a276ec073 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -151,43 +151,54 @@ size_t curlResponseWrite(void *ptr, size_t size, size_t nmemb, std::string *data namespace ZeroTier { -const char *ssoResponseTemplate = "\ -\ -\ -\ -\ -





\ -
\ -
\ -
%s
\ -
\ -\ -"; +std::string ssoResponseTemplate = R"""( + + + + + + Network SSO Login {{ networkId }} + + + + + +
+
+
{{ messageText }}
+
+ + +)"""; // Configured networks class NetworkState @@ -287,16 +298,9 @@ public: } 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)); - // fprintf(stderr, "ssoEnabled: %s, ssoVersion: %d\n", - // _config.ssoEnabled ? "true" : "false", _config.ssoVersion); if (_config.ssoEnabled && _config.ssoVersion == 1) { - // fprintf(stderr, "ssoEnabled for %s\n", nwid); #if ZT_SSO_ENABLED if (_idc == nullptr) { @@ -304,10 +308,6 @@ public: assert(_config.ssoClientID != 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( _config.issuerURL, _config.ssoClientID, @@ -319,8 +319,6 @@ public: fprintf(stderr, "idc is null\n"); return; } - - // fprintf(stderr, "idc created (%s, %s, %s)\n", _config.issuerURL, _config.ssoClientID, _config.centralAuthURL); } zeroidc::zeroidc_set_nonce_and_csrf( @@ -335,7 +333,6 @@ public: zeroidc::free_cstr(url); if (zeroidc::zeroidc_is_running(_idc) && nwc->status == ZT_NETWORK_STATUS_AUTHENTICATION_REQUIRED) { - // TODO: kick the refresh thread zeroidc::zeroidc_kick_refresh_thread(_idc); } #endif @@ -1704,29 +1701,33 @@ public: std::string htmlTemplatePath = _homePath + ZT_PATH_SEPARATOR + "sso-auth.template.html"; std::string htmlTemplate; if (!OSUtils::readFile(htmlTemplatePath.c_str(), htmlTemplate)) { - fprintf(stderr, "ERROR: unable to read sso result template"); - exit(1); + htmlTemplate = ssoResponseTemplate; } - responseContentType = "text/html"; 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) { - 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; json data; outData["messageText"] = (std::string("ERROR ") + error + std::string(": ") + desc); responseBody = inja::render(htmlTemplate, outData); + + zeroidc::free_cstr(desc); + zeroidc::free_cstr(error); + return scode; } // SSO redirect handling char* state = zeroidc::zeroidc_get_url_param_value("state", path.c_str()); char* nwid = zeroidc::zeroidc_network_id_from_state(state); - + + outData["networkId"] = std::string(nwid); + const uint64_t id = Utils::hexStrToU64(nwid); zeroidc::free_cstr(nwid);