diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index 06b46babef..7dfce32982 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -106,6 +106,19 @@ public: /// The key that stores the switch for enabling/disabling the rendering on a master /// computer static const std::string KeyRenderingMethod; + /// The key that stores the http proxy settings for the downloadmanager + static const std::string KeyHttpProxy; + /// The key that stores the address of the http proxy + static const std::string ConfigurationManager::PartHttpProxyAddress; + /// The key that stores the port of the http proxy + static const std::string ConfigurationManager::PartHttpProxyPort; + /// The key that stores the authentication method of the http proxy + static const std::string ConfigurationManager::PartHttpProxyAuthentication; + /// The key that stores the username to use for authentication to access the http proxy + static const std::string ConfigurationManager::PartHttpProxyUser; + /// The key that stores the password to use for authentication to access the http proxy + static const std::string ConfigurationManager::PartHttpProxyPassword; + /** * Iteratively walks the directory structure starting with \p filename to find the diff --git a/modules/globebrowsing/tile/tiledataset.cpp b/modules/globebrowsing/tile/tiledataset.cpp index 4c2d0bc781..f877595b8f 100644 --- a/modules/globebrowsing/tile/tiledataset.cpp +++ b/modules/globebrowsing/tile/tiledataset.cpp @@ -41,8 +41,8 @@ #include #include - - +#include +#include namespace { @@ -170,10 +170,55 @@ namespace openspace { if (!GdalHasBeenInitialized) { GDALAllRegister(); CPLSetConfigOption("GDAL_DATA", absPath("${MODULE_GLOBEBROWSING}/gdal_data").c_str()); + setGdalProxyConfiguration(); GdalHasBeenInitialized = true; } } + void TileDataset::setGdalProxyConfiguration() { + ghoul::Dictionary proxySettings; + bool proxyEnabled = OsEng.configurationManager().getValue(ConfigurationManager::KeyHttpProxy, proxySettings); + if (proxyEnabled) { + std::string proxyAddress, proxyPort, proxyUser, proxyPassword, proxyAuth; + + bool success = proxySettings.getValue(ConfigurationManager::PartHttpProxyAddress, proxyAddress); + success &= proxySettings.getValue(ConfigurationManager::PartHttpProxyPort, proxyPort); + proxySettings.getValue(ConfigurationManager::PartHttpProxyAuthentication, proxyAuth); + + std::string proxyAuthString = "BASIC"; + if (proxyAuth == "basic" || proxyAuth == "") { + proxyAuthString = "BASIC"; + } else if (proxyAuth == "ntlm") { + proxyAuthString = "NTLM"; + } else if (proxyAuth == "digest") { + proxyAuthString = "DIGEST"; + } else if (proxyAuth == "any") { + proxyAuthString = "ANY"; + } else { + success = false; + } + + bool userAndPassword = proxySettings.getValue(ConfigurationManager::PartHttpProxyUser, proxyUser); + userAndPassword &= proxySettings.getValue(ConfigurationManager::PartHttpProxyPassword, proxyPassword); + + if (success) { + std::string proxy = proxyAddress + ":" + proxyPort; + CPLSetConfigOption("GDAL_HTTP_PROXY", proxy.c_str()); + LDEBUG("Using proxy server " << proxy); + if (userAndPassword) { + std::string proxyUserPwd = proxyUser + ":" + proxyPassword; + CPLSetConfigOption("GDAL_HTTP_PROXYUSERPWD", proxyUserPwd.c_str()); + CPLSetConfigOption("GDAL_HTTP_PROXYAUTH", proxyAuthString.c_str()); + LDEBUG("Using authentication method: " << proxyAuthString); + } + } else { + LERROR("Invalid proxy settings for GDAL"); + } + } else { + LDEBUG("Setting up GDAL without proxy server"); + } + } + GDALDataset* TileDataset::gdalDataset(const std::string& gdalDatasetDesc) { GDALDataset* dataset = (GDALDataset *)GDALOpen(gdalDatasetDesc.c_str(), GA_ReadOnly); if (!dataset) { diff --git a/modules/globebrowsing/tile/tiledataset.h b/modules/globebrowsing/tile/tiledataset.h index 303c32a13b..fb226ee117 100644 --- a/modules/globebrowsing/tile/tiledataset.h +++ b/modules/globebrowsing/tile/tiledataset.h @@ -136,6 +136,7 @@ namespace openspace { ////////////////////////////////////////////////////////////////////////////////// void gdalEnsureInitialized(); + void setGdalProxyConfiguration(); GDALDataset* gdalDataset(const std::string& gdalDatasetDesc); bool gdalHasOverviews() const; int gdalOverview(const PixelRange& baseRegionSize) const; diff --git a/src/engine/configurationmanager.cpp b/src/engine/configurationmanager.cpp index fb0972d471..881a8dfcb2 100644 --- a/src/engine/configurationmanager.cpp +++ b/src/engine/configurationmanager.cpp @@ -72,6 +72,13 @@ const string ConfigurationManager::KeyDisableMasterRendering = "DisableRendering const string ConfigurationManager::KeyDownloadRequestURL = "DownloadRequestURL"; const string ConfigurationManager::KeyRenderingMethod = "RenderingMethod"; +const string ConfigurationManager::KeyHttpProxy = "HttpProxy"; +const string ConfigurationManager::PartHttpProxyAddress = "Address"; +const string ConfigurationManager::PartHttpProxyPort = "Port"; +const string ConfigurationManager::PartHttpProxyAuthentication = "Authentication"; +const string ConfigurationManager::PartHttpProxyUser = "User"; +const string ConfigurationManager::PartHttpProxyPassword = "Password"; + string ConfigurationManager::findConfiguration(const string& filename) { using ghoul::filesystem::Directory; diff --git a/src/engine/configurationmanager_doc.inl b/src/engine/configurationmanager_doc.inl index fc796a5bb8..f260d37f79 100644 --- a/src/engine/configurationmanager_doc.inl +++ b/src/engine/configurationmanager_doc.inl @@ -325,7 +325,45 @@ Documentation ConfigurationManager::Documentation() { "or just managing the state of the network. This is desired in cases where " "the master computer does not have the resources to render a scene.", Optional::Yes - } + }, + { + ConfigurationManager::KeyHttpProxy, + new TableVerifier({ + { + ConfigurationManager::PartHttpProxyAddress, + new StringVerifier, + "The address of the http proxy" + }, + { + ConfigurationManager::PartHttpProxyPort, + new StringVerifier, + "The port of the http proxy" + }, + { + ConfigurationManager::PartHttpProxyAuthentication, + new StringInListVerifier( + { "basic", "ntlm", "digest", "any" } + ), + "The authentication method of the http proxy", + Optional::Yes + }, + { + ConfigurationManager::PartHttpProxyUser, + new StringVerifier, + "The user of the http proxy", + Optional::Yes + }, + { + ConfigurationManager::PartHttpProxyPassword, + new StringVerifier, + "The password of the http proxy", + Optional::Yes + } + }), + "This defines the use for a proxy when fetching data over http." + "No proxy will be used if this is left out.", + Optional::Yes + } } }; };