From 8ac8e08abf25ac43b660e7e3c0b7485f4f6628d7 Mon Sep 17 00:00:00 2001 From: LogMANOriginal Date: Tue, 29 May 2018 11:52:17 +0200 Subject: [PATCH] Add user config (#653) Uses the parse_ini_file function to load default settings from the default configuration file 'config.default.ini.php'. Optionally loads custom settings from 'config.ini.php' to replace the default values. --- .gitignore | 1 + config.default.ini.php | 27 ++++++++++++++++++++++++ index.php | 48 +++++++++++++++++++++++++++++++++--------- 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 config.default.ini.php diff --git a/.gitignore b/.gitignore index c9ad203..a848b5f 100644 --- a/.gitignore +++ b/.gitignore @@ -227,6 +227,7 @@ pip-log.txt /cache /whitelist.txt DEBUG +config.ini.php ###################### ## VisualStudioCode ## diff --git a/config.default.ini.php b/config.default.ini.php new file mode 100644 index 0000000..d27ead1 --- /dev/null +++ b/config.default.ini.php @@ -0,0 +1,27 @@ +; DO NOT REMOVE THIS LINE + +; This file contains the default settings for RSS-Bridge. Do not change this +; file, it will be replaced on the next update of RSS-Bridge! You can specify +; your own configuration in 'config.ini.php' (copy this file). + +[cache] + +; Allow users to specify custom timeout for specific requests. +; true = enabled +; false = disabled (default) +custom_timeout = false + +[proxy] + +; Sets the proxy url (i.e. "tcp://192.168.0.0:32") +; "" = Proxy disabled (default) +url = "" + +; Sets the proxy name that is shown on the bridge instead of the proxy url. +; "" = Show proxy url +name = "Hidden proxy name" + +; Allow users to disable proxy usage for specific requests. +; true = enabled +; false = disabled (default) +by_bridge = false \ No newline at end of file diff --git a/index.php b/index.php index e0cc548..5642583 100644 --- a/index.php +++ b/index.php @@ -10,19 +10,47 @@ TODO : - implement header('X-Cached-Version: '.date(DATE_ATOM, filemtime($cachefile))); */ +if(!file_exists('config.default.ini.php')) + die('The default configuration file "config.default.ini.php" is missing!'); + +$config = parse_ini_file('config.default.ini.php', true, INI_SCANNER_TYPED); + +if(file_exists('config.ini.php')) { + // Replace default configuration with custom settings + foreach(parse_ini_file('config.ini.php', true, INI_SCANNER_TYPED) as $header => $section) { + foreach($section as $key => $value) { + // Skip unknown sections and keys + if(array_key_exists($header, $config) && array_key_exists($key, $config[$header])) { + $config[$header][$key] = $value; + } + } + } +} + +if(!is_string($config['proxy']['url'])) + die('Parameter [proxy] => "url" is not a valid string! Please check "config.ini.php"!'); + +if(!empty($config['proxy']['url'])) + define('PROXY_URL', $config['proxy']['url']); + +if(!is_bool($config['proxy']['by_bridge'])) + die('Parameter [proxy] => "by_bridge" is not a valid Boolean! Please check "config.ini.php"!'); + +define('PROXY_BYBRIDGE', $config['proxy']['by_bridge']); + +if(!is_string($config['proxy']['name'])) + die('Parameter [proxy] => "name" is not a valid string! Please check "config.ini.php"!'); + +define('PROXY_NAME', $config['proxy']['name']); + +if(!is_bool($config['cache']['custom_timeout'])) + die('Parameter [cache] => "custom_timeout" is not a valid Boolean! Please check "config.ini.php"!'); + +define('CUSTOM_CACHE_TIMEOUT', $config['cache']['custom_timeout']); + // Defines the minimum required PHP version for RSS-Bridge define('PHP_VERSION_REQUIRED', '5.6.0'); -//define('PROXY_URL', 'tcp://192.168.0.0:28'); -// Set to true if you allow users to disable proxy usage for specific bridges -define('PROXY_BYBRIDGE', false); -// Comment this line or keep PROXY_NAME empty to display PROXY_URL instead -define('PROXY_NAME', 'Hidden Proxy Name'); - -// Allows the operator to specify custom cache timeouts via '&_cache_timeout=3600' -// true: enabled, false: disabled (default) -define('CUSTOM_CACHE_TIMEOUT', false); - date_default_timezone_set('UTC'); error_reporting(0);