diff --git a/api-client/tests/version2_test.py b/api-client/tests/version2_test.py index f2f5acd7b..421f87cb3 100644 --- a/api-client/tests/version2_test.py +++ b/api-client/tests/version2_test.py @@ -11,10 +11,8 @@ def config_filepath(tmp_path: Path): filepath.write_text( """ [general] +public_url = http://localhost/test api_key = TEST_KEY -base_dir = /test -base_port = 80 -base_url = localhost """ ) return filepath diff --git a/api/libretime_api/settings/testing.py b/api/libretime_api/settings/testing.py index b25b433da..d884a3a7f 100644 --- a/api/libretime_api/settings/testing.py +++ b/api/libretime_api/settings/testing.py @@ -1,6 +1,7 @@ import os os.environ.setdefault("LIBRETIME_DEBUG", "true") +os.environ.setdefault("LIBRETIME_GENERAL_PUBLIC_URL", "http://localhost") os.environ.setdefault("LIBRETIME_GENERAL_API_KEY", "testing") # pylint: disable=wrong-import-position,unused-import diff --git a/docs/admin-manual/setup/configuration.md b/docs/admin-manual/setup/configuration.md index 5cb5c78b2..a4b2d6723 100644 --- a/docs/admin-manual/setup/configuration.md +++ b/docs/admin-manual/setup/configuration.md @@ -11,21 +11,11 @@ The `general` section configure anything related to the legacy and API services. ```ini [general] -# The internal API authentication key, this field is required +# The public url. This field is REQUIRED +public_url = https://example.com +# The internal API authentication key, this field is REQUIRED api_key = some_random_generated_secret! -# The public url scheme -# Mutually exclusive with force_ssl -protocol = -# The public url hostname, default is localhost -base_url = localhost -# The public url port -base_port = -# The public url base path, default is / -base_dir = / -# Force https for generated urls, default is false -force_ssl = false - # How many hours ahead Playout should cache scheduled media files, default is 1 cache_ahead_hours = 1 diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index a1b6acd87..4a8e82642 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -46,6 +46,14 @@ sudo apt purge \ uwsgi-plugin-python3 ``` +### New configuration schema + +The configuration schema was updated. + +The `general` section has been changed: + +- theĀ `general.protocol`, `general.base_url`, `general.base_port`, `general.base_dir` and `general.force_ssl` entries were replaced with a single `general.public_url` entry, be sure to use a valid url with the new configuration entry. + ## :warning: Known issues The following issues may need a workaround for the time being. Please search the [issues](https://github.com/libretime/libretime/issues) before reporting problems not listed below. diff --git a/legacy/application/common/HTTPHelper.php b/legacy/application/common/HTTPHelper.php index 3120fe57e..28483845d 100644 --- a/legacy/application/common/HTTPHelper.php +++ b/legacy/application/common/HTTPHelper.php @@ -1,5 +1,7 @@ $CC_CONFIG['protocol'], + 'host' => $CC_CONFIG['baseUrl'], + 'port' => $CC_CONFIG['basePort'], + 'path' => $CC_CONFIG['baseDir'], + ] + ); + if (empty($baseDir)) { $baseDir = '/'; } @@ -45,26 +52,7 @@ class Application_Common_HTTPHelper $baseDir = $baseDir . '/'; } - // Set in reverse order of preference. ForceSSL configuration takes absolute preference, then - // the protocol set in config. If neither are set, the port is used to determine the scheme - $scheme = 'http'; - if ($secured && $basePort == '443') { - $scheme = 'https'; - } - if (!empty($configProtocol)) { - $scheme = $configProtocol; - } - if ($forceSSL) { - $scheme = 'https'; - } - - $portStr = ''; - if (($scheme == 'http' && $basePort !== '80') - || ($scheme == 'https' && $basePort !== '443')) { - $portStr = ":{$basePort}"; - } - - return "{$scheme}://{$baseUrl}{$portStr}{$baseDir}"; + return rtrim($url, '/') . '/'; } /** @@ -114,7 +102,7 @@ class ZendActionHttpException extends Exception Exception $previous = null ) { Logging::error('Error in action ' . $action->getRequest()->getActionName() - . " with status code {$statusCode}: {$message}"); + . " with status code {$statusCode}: {$message}"); $action->getResponse() ->setHttpResponseCode($statusCode) ->appendBody($message); diff --git a/legacy/application/configs/conf.php b/legacy/application/configs/conf.php index 0eb776a7e..5be3b2d3a 100644 --- a/legacy/application/configs/conf.php +++ b/legacy/application/configs/conf.php @@ -1,6 +1,8 @@ getMessage(); + + exit; + } + + $scheme = $public_url->getScheme() ?? 'http'; + $host = $public_url->getHost() ?? 'localhost'; + $port = $public_url->getPort() ?? ($scheme == 'https' ? 443 : 80); + $path = rtrim($public_url->getPath() ?? '', '/') . '/'; // Path requires a trailing slash + + $CC_CONFIG['protocol'] = $scheme; + $CC_CONFIG['baseUrl'] = $host; + $CC_CONFIG['basePort'] = $port; + $CC_CONFIG['baseDir'] = $path; $CC_CONFIG['dev_env'] = $values['general']['dev_env'] ?? 'production'; $CC_CONFIG['auth'] = $values['general']['auth'] ?? 'local'; diff --git a/legacy/build/airtime-setup/forms/general-settings.php b/legacy/build/airtime-setup/forms/general-settings.php index 13b142f40..bee1708f9 100644 --- a/legacy/build/airtime-setup/forms/general-settings.php +++ b/legacy/build/airtime-setup/forms/general-settings.php @@ -3,52 +3,40 @@