diff --git a/administrator/components/com_config/model/application.php b/administrator/components/com_config/model/application.php index c546cbba44390..ba9d509739d88 100644 --- a/administrator/components/com_config/model/application.php +++ b/administrator/components/com_config/model/application.php @@ -118,6 +118,36 @@ public function save($data) return false; } + // Check if we can set the Force SSL option + if ((int) $data['force_ssl'] !== 0 && (int) $data['force_ssl'] !== (int) JFactory::getConfig()->get('force_ssl', '0')) + { + try + { + // Make an HTTPS request to check if the site is available in HTTPS. + $host = JUri::getInstance()->getHost(); + $options = new \Joomla\Registry\Registry; + $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0'); + $options->set('transport.curl', array(CURLOPT_SSL_VERIFYPEER => false)); + $response = JHttpFactory::getHttp($options)->get('https://' . $host . JUri::root(true) . '/', array('Host' => $host), 10); + + // If available in HTTPS check also the status code. + if (!in_array($response->code, array(200, 503, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310), true)) + { + throw new RuntimeException('HTTPS version of the site returned an invalid HTTP status code.'); + } + } + catch (RuntimeException $e) + { + $data['force_ssl'] = 0; + + // Also update the user state + $app->setUserState('com_config.config.global.data.force_ssl', 0); + + // Inform the user + $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_SSL_NOT_AVAILABLE'), 'warning'); + } + } + // Save the rules if (isset($data['rules'])) { diff --git a/administrator/language/en-GB/en-GB.com_config.ini b/administrator/language/en-GB/en-GB.com_config.ini index 0bdc95f6c96b4..c0ef21098215e 100644 --- a/administrator/language/en-GB/en-GB.com_config.ini +++ b/administrator/language/en-GB/en-GB.com_config.ini @@ -28,6 +28,7 @@ COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE="Could not make configuration.php COM_CONFIG_ERROR_HELPREFRESH_ERROR_STORE="The new Help Sites list could not be saved." COM_CONFIG_ERROR_HELPREFRESH_FETCH="The current Help Sites list could not be fetched from the remote server." COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND="The asset for global configuration could not be found. Permissions have not been saved." +COM_CONFIG_ERROR_SSL_NOT_AVAILABLE="HTTPS has not been enabled as it is not available on this server." COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN="You can't remove your own Super User permissions." COM_CONFIG_ERROR_WRITE_FAILED="Could not write to the configuration file" COM_CONFIG_FIELD_CACHE_HANDLER_DESC="Choose cache handler to enable caching. Native caching mechanism is file-based. Please make sure the cache folders are writable."