From 1452b747402928edf4ddd84431429ade859ebe82 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 1 Aug 2021 23:52:27 +0200 Subject: [PATCH] [welcome] Load potentially a list of URLs to check --- .../welcome/checker/GeneralRequirements.cpp | 76 +++++++++++++++------- src/modules/welcome/welcome.conf | 15 +++++ 2 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/modules/welcome/checker/GeneralRequirements.cpp b/src/modules/welcome/checker/GeneralRequirements.cpp index 07c352946..2528cbd9f 100644 --- a/src/modules/welcome/checker/GeneralRequirements.cpp +++ b/src/modules/welcome/checker/GeneralRequirements.cpp @@ -215,6 +215,57 @@ GeneralRequirements::checkRequirements() return checkEntries; } +/** @brief Loads the check-internel URLs + * + * There may be zero or one or more URLs specified; returns + * @c true if the configuration is incomplete or damaged in some way. + */ +static bool +getCheckInternetUrls( const QVariantMap& configurationMap ) +{ + const QString exampleUrl = QStringLiteral( "http://example.com" ); + + bool incomplete = false; + QStringList checkInternetSetting = CalamaresUtils::getStringList( configurationMap, "internetCheckUrl" ); + if ( !checkInternetSetting.isEmpty() ) + { + QVector< QUrl > urls; + for ( const auto& urlString : qAsConst( checkInternetSetting ) ) + { + QUrl url( urlString.trimmed() ); + if ( url.isValid() ) + { + urls.append( url ); + } + else + { + cWarning() << "GeneralRequirements entry 'internetCheckUrl' in welcome.conf contains invalid" + << urlString; + } + } + + if ( urls.empty() ) + { + cWarning() << "GeneralRequirements entry 'internetCheckUrl' contains no valid URLs," + << "reverting to default (http://example.com)."; + CalamaresUtils::Network::Manager::instance().setCheckHasInternetUrl( QUrl( exampleUrl ) ); + incomplete = true; + } + else + { + CalamaresUtils::Network::Manager::instance().setCheckHasInternetUrl( urls ); + } + } + else + { + cWarning() << "GeneralRequirements entry 'internetCheckUrl' is undefined in welcome.conf," + "reverting to default (http://example.com)."; + CalamaresUtils::Network::Manager::instance().setCheckHasInternetUrl( QUrl( exampleUrl ) ); + incomplete = true; + } + return incomplete; +} + void GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap ) @@ -302,30 +353,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap ) incompleteConfiguration = true; } - QUrl checkInternetUrl; - QString checkInternetSetting = CalamaresUtils::getString( configurationMap, "internetCheckUrl" ); - if ( !checkInternetSetting.isEmpty() ) - { - checkInternetUrl = QUrl( checkInternetSetting.trimmed() ); - if ( !checkInternetUrl.isValid() ) - { - cWarning() << "GeneralRequirements entry 'internetCheckUrl' is invalid in welcome.conf" - << checkInternetSetting << "reverting to default (http://example.com)."; - checkInternetUrl = QUrl( "http://example.com" ); - incompleteConfiguration = true; - } - } - else - { - cWarning() << "GeneralRequirements entry 'internetCheckUrl' is undefined in welcome.conf," - "reverting to default (http://example.com)."; - checkInternetUrl = "http://example.com"; - incompleteConfiguration = true; - } - if ( checkInternetUrl.isValid() ) - { - CalamaresUtils::Network::Manager::instance().setCheckHasInternetUrl( checkInternetUrl ); - } + incompleteConfiguration |= getCheckInternetUrls( configurationMap ); if ( incompleteConfiguration ) { diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index b3da8d366..6e11817bf 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -43,6 +43,21 @@ requirements: # # The URL is only used if "internet" is in the *check* list below. internetCheckUrl: http://example.com + # + # This may be a single URL, or a list or URLs, in which case the + # URLs will be checked one-by-one; if any of them returns data, + # internet is assumed to be OK. This can be used to check via + # a number of places, where some domains may be down or blocked. + # + # To use a list of URLs, just use YAML list syntax (e.g. + # + # internetCheckUrl: + # - http://www.kde.org + # - http://www.freebsd.org + # + # or short-form + # + # internetCheckUrl: [ http://www.kde.org, http://www.freebsd.org ] # List conditions to check. Each listed condition will be # probed in some way, and yields true or false according to -- 2.11.0