mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-09 18:16:36 +02:00
fix: introduce system env var, remove debug mode (#4658)
* fix: introduce system env var * docs * docs
This commit is contained in:
@@ -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
|
||||
|
||||
```
|
||||
|
@@ -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');
|
||||
|
@@ -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 .= '<p>';
|
||||
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -1,23 +1,28 @@
|
||||
<h1 align="center">Warning!</h1>
|
||||
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(),
|
||||
```
|
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Debug
|
||||
{
|
||||
/**
|
||||
* Convenience function for Configuration::getConfig('system', 'enable_debug_mode')
|
||||
*/
|
||||
public static function isEnabled(): bool
|
||||
{
|
||||
$ip = $_SERVER['REMOTE_ADDR'] ?? 'x.y.z.1';
|
||||
$enableDebugMode = Configuration::getConfig('system', 'enable_debug_mode');
|
||||
$debugModeWhitelist = Configuration::getConfig('system', 'debug_mode_whitelist') ?: [];
|
||||
if ($enableDebugMode && ($debugModeWhitelist === [] || in_array($ip, $debugModeWhitelist))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -47,16 +47,16 @@ $container['cache_factory'] = function ($c) {
|
||||
|
||||
$container['logger'] = function () {
|
||||
$logger = new SimpleLogger('rssbridge');
|
||||
if (Debug::isEnabled()) {
|
||||
if (Configuration::getConfig('system', 'env') === 'dev') {
|
||||
$logger->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;
|
||||
};
|
||||
|
||||
|
22
lib/html.php
22
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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user