diff --git a/README.md b/README.md index 7e155db7..05042630 100644 --- a/README.md +++ b/README.md @@ -369,14 +369,6 @@ enabled_bridges[] = TwitchBridge enabled_bridges[] = GettrBridge ``` -### How to enable debug mode - -The -[debug mode](https://rss-bridge.github.io/rss-bridge/For_Developers/Debug_mode.html) -disables the majority of caching operations. - - enable_debug_mode = true - ### How to switch to memcached as cache backend ``` diff --git a/actions/ConnectivityAction.php b/actions/ConnectivityAction.php index e4e1e7c2..458a06af 100644 --- a/actions/ConnectivityAction.php +++ b/actions/ConnectivityAction.php @@ -22,8 +22,8 @@ class ConnectivityAction implements ActionInterface public function __invoke(Request $request): Response { - if (!Debug::isEnabled()) { - return new Response('This action is only available in debug mode!', 403); + if (Configuration::getConfig('system', 'env') !== 'dev') { + return new Response('This action is only available in dev environment!', 403); } $bridgeName = $request->get('bridge'); diff --git a/bridges/BlueskyBridge.php b/bridges/BlueskyBridge.php index bf5053be..ada24128 100644 --- a/bridges/BlueskyBridge.php +++ b/bridges/BlueskyBridge.php @@ -178,10 +178,8 @@ class BlueskyBridge extends BridgeAbstract $postDisplayName = e($postDisplayName); $postUri = $item['uri']; - if (Debug::isEnabled()) { - $url = explode('/', $post['post']['uri']); - $this->logger->debug('https://bsky.app/profile/' . $url[2] . '/post/' . $url[4]); - } + $url = explode('/', $post['post']['uri']); + $this->logger->debug('https://bsky.app/profile/' . $url[2] . '/post/' . $url[4]); $description = ''; $description .= '

'; @@ -612,9 +610,9 @@ class BlueskyBridge extends BridgeAbstract private function getAuthorFeed($did, $filter) { $uri = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=' . urlencode($did) . '&filter=' . urlencode($filter) . '&limit=30'; - if (Debug::isEnabled()) { - $this->logger->debug($uri); - } + + $this->logger->debug($uri); + $response = json_decode(getContents($uri), true); return $response; } diff --git a/config.default.ini.php b/config.default.ini.php index ae8b23b7..39329a2a 100644 --- a/config.default.ini.php +++ b/config.default.ini.php @@ -6,6 +6,9 @@ [system] +; System environment: "dev" or "prod" +env = "prod" + ; Only these bridges are available for feed production ; How to enable all bridges: enabled_bridges[] = * ;enabled_bridges[] = CssSelectorBridge @@ -31,13 +34,6 @@ timezone = "UTC" ; Display a system message to users. ;message = "Hello world" -; Whether to enable debug mode. -enable_debug_mode = false - -; Enable debug mode only for these permitted ip addresses -; debug_mode_whitelist[] = 127.0.0.1 -; debug_mode_whitelist[] = 192.168.1.10 - ; Whether to enable maintenance mode. If enabled, feed requests receive 503 Service Unavailable enable_maintenance_mode = false diff --git a/docs/04_For_Developers/05_Debug_mode.md b/docs/04_For_Developers/05_Debug_mode.md index 7d503acd..cccf2768 100644 --- a/docs/04_For_Developers/05_Debug_mode.md +++ b/docs/04_For_Developers/05_Debug_mode.md @@ -1,23 +1,28 @@ -

Warning!

+Debug mode has been removed. -Enabling debug mode on a public server may result in malicious clients retrieving sensitive data about your server and possibly gaining access to it. -Do not enable debug mode on a public server, unless you understand the implications of your doing! +If you want to disable caching you can set cache type to array (in-memory cache): -*** +```ini +[cache] -Debug mode enables error reporting and prevents loading data from the cache (data is still written to the cache). -To enable debug mode, set in `config.ini.php`: +; Cache type: file, sqlite, memcached, array, null +type = "array" +``` - enable_debug_mode = true +Alternatively, you can comment out the cache middleware in `lib/RssBridge.php`: -Allow only explicit ip addresses: +```diff +diff --git a/lib/RssBridge.php b/lib/RssBridge.php +index d16f1d89..da3df8be 100644 +--- a/lib/RssBridge.php ++++ b/lib/RssBridge.php +@@ -24,7 +24,7 @@ final class RssBridge - debug_mode_whitelist[] = 127.0.0.1 - debug_mode_whitelist[] = 192.168.1.10 - -_Notice_: - -* An empty file enables debug mode for anyone! -* The bridge whitelist still applies! (debug mode does **not** enable all bridges) - -RSS-Bridge will give you a visual feedback when debug mode is enabled. + $middlewares = [ + new BasicAuthMiddleware(), +- new CacheMiddleware($this->container['cache']), ++ //new CacheMiddleware($this->container['cache']), + new ExceptionMiddleware($this->container['logger']), + new SecurityMiddleware(), + new MaintenanceMiddleware(), +``` \ No newline at end of file diff --git a/docs/04_For_Developers/index.md b/docs/04_For_Developers/index.md index 97bbb854..31e513a5 100644 --- a/docs/04_For_Developers/index.md +++ b/docs/04_For_Developers/index.md @@ -6,7 +6,6 @@ If you are new to **RSS-Bridge** you should make yourself familiar with some gen - [Coding style policy](./01_Coding_style_policy.md) - [Folder structure](./03_Folder_structure.md) - - [Debug mode](./05_Debug_mode.md) - [Bridge API](../05_Bridge_API/index.md) - [Cache API](../07_Cache_API/index.md) - [Technical recommendations](../09_Technical_recommendations/index.md) diff --git a/index.php b/index.php index 02ea9a3d..79403e11 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,7 @@ set_error_handler(function ($code, $message, $file, $line) use ($logger) { // Deprecation messages and other masked errors are typically ignored here return false; } - if (Debug::isEnabled()) { + if (Configuration::getConfig('system', 'env') === 'dev') { // This might be annoying, but it's for the greater good throw new \ErrorException($message, 0, $code, $file, $line); } diff --git a/lib/Configuration.php b/lib/Configuration.php index 37368894..d8f64d21 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -36,11 +36,10 @@ final class Configuration } if (file_exists(__DIR__ . '/../DEBUG')) { - // The debug mode has been moved to config. Preserve existing installs which has this DEBUG file. - self::setConfig('system', 'enable_debug_mode', true); $debug = trim(file_get_contents(__DIR__ . '/../DEBUG')); - if ($debug) { - self::setConfig('system', 'debug_mode_whitelist', explode("\n", str_replace("\r", '', $debug))); + if ($debug === '') { + self::setConfig('system', 'env', 'dev'); + self::setConfig('cache', 'type', 'array'); } } @@ -82,8 +81,8 @@ final class Configuration } } - if (Debug::isEnabled()) { - self::setConfig('cache', 'type', 'array'); + if (!in_array(self::getConfig('system', 'env'), ['dev', 'prod'])) { + self::throwConfigError('system', 'env', 'Must be dev or prod'); } if (!is_array(self::getConfig('system', 'enabled_bridges'))) { @@ -97,13 +96,6 @@ final class Configuration self::throwConfigError('system', 'timezone'); } - if (!is_bool(self::getConfig('system', 'enable_debug_mode'))) { - self::throwConfigError('system', 'enable_debug_mode', 'Is not a valid Boolean'); - } - if (!is_array(self::getConfig('system', 'debug_mode_whitelist') ?: [])) { - self::throwConfigError('system', 'debug_mode_whitelist', 'Is not a valid array'); - } - if (!is_string(self::getConfig('proxy', 'url'))) { self::throwConfigError('proxy', 'url', 'Is not a valid string'); } @@ -199,6 +191,8 @@ final class Configuration private static function throwConfigError($section, $key, $message = '') { - throw new \Exception("Config [$section] => [$key] is invalid. $message"); + http_response_code(500); + print ("Config [$section] => [$key] is invalid. $message"); + exit(1); } } diff --git a/lib/Debug.php b/lib/Debug.php deleted file mode 100644 index 630fd8ec..00000000 --- a/lib/Debug.php +++ /dev/null @@ -1,18 +0,0 @@ -addHandler(new ErrorLogHandler(Logger::DEBUG)); } else { $logger->addHandler(new ErrorLogHandler(Logger::INFO)); } // Uncomment this for info logging to fs - // $logger->addHandler(new StreamHandler('/tmp/rss-bridge.txt', Logger::INFO)); + // $logger->addHandler(new StreamHandler('/tmp/rss-bridge.log', Logger::INFO)); // Uncomment this for debug logging to fs - // $logger->addHandler(new StreamHandler('/tmp/rss-bridge-debug.txt', Logger::DEBUG)); + // $logger->addHandler(new StreamHandler('/tmp/rss-bridge-debug.log', Logger::DEBUG)); return $logger; }; diff --git a/lib/html.php b/lib/html.php index 71a3a29e..dd756979 100644 --- a/lib/html.php +++ b/lib/html.php @@ -15,19 +15,15 @@ function render(string $template, array $context = []): string 'level' => 'info', ]; } - if (Debug::isEnabled()) { - $debugModeWhitelist = Configuration::getConfig('system', 'debug_mode_whitelist') ?: []; - if ($debugModeWhitelist === []) { - $context['messages'][] = [ - 'body' => 'Warning : Debug mode is active from any location, make sure only you can access RSS-Bridge.', - 'level' => 'error' - ]; - } else { - $context['messages'][] = [ - 'body' => 'Warning : Debug mode is active from your IP address, your requests will bypass the cache.', - 'level' => 'warning' - ]; - } + if (Configuration::getConfig('system', 'env') === 'dev') { + $context['messages'][] = [ + 'body' => 'System environment: dev', + 'level' => 'error' + ]; + $context['messages'][] = [ + 'body' => sprintf('Cache type: %s', Configuration::getConfig('cache', 'type')), + 'level' => 'info' + ]; } $context['page'] = render_template($template, $context); return render_template('base.html.php', $context); diff --git a/lib/http.php b/lib/http.php index b89e3c05..8f0a1638 100644 --- a/lib/http.php +++ b/lib/http.php @@ -23,12 +23,10 @@ class HttpException extends \Exception public static function fromResponse(Response $response, string $url): HttpException { $message = sprintf( - '%s resulted in %s %s %s', + '%s resulted in %s %s', $url, $response->getCode(), - $response->getStatusLine(), - // If debug, include a part of the response body in the exception message - Debug::isEnabled() ? mb_substr($response->getBody(), 0, 500) : '', + $response->getStatusLine() ); if (CloudFlareException::isCloudFlareResponse($response)) { return new CloudFlareException($message, $response->getCode(), $response);