From d4e867f2403c6224c93d8588fadbde600aec4444 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 6 Jun 2019 20:53:44 +0200 Subject: [PATCH] core: Move default bridges to whitelist.default.txt Default bridges are currently statically defined in index.php, which is not the right place if we want to keep responsibilities separated. This commit introduces a new file whitelist.default.txt that holds the default bridges and which is loaded automatically, if whitelist.txt doesn't exist. Due to this it is also no longer necessary to have write permission for the root directory. References #1001 --- index.php | 19 ------------------- lib/Bridge.php | 25 ++++++++++++++----------- lib/Configuration.php | 4 ---- lib/rssbridge.php | 3 +++ whitelist.default.txt | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 whitelist.default.txt diff --git a/index.php b/index.php index 771e3379ad8..0bc63625de6 100644 --- a/index.php +++ b/index.php @@ -29,27 +29,8 @@ ini_set('user_agent', USER_AGENT); -// default whitelist -$whitelist_default = array( - 'BandcampBridge', - 'CryptomeBridge', - 'DansTonChatBridge', - 'DuckDuckGoBridge', - 'FacebookBridge', - 'FlickrBridge', - 'GoogleSearchBridge', - 'IdenticaBridge', - 'InstagramBridge', - 'OpenClassroomsBridge', - 'PinterestBridge', - 'ScmbBridge', - 'TwitterBridge', - 'WikipediaBridge', - 'YoutubeBridge'); - try { - Bridge::setWhitelist($whitelist_default); $actionFac = new \ActionFactory(); $actionFac->setWorkingDir(PATH_LIB_ACTIONS); diff --git a/lib/Bridge.php b/lib/Bridge.php index 9e5750a7f9f..dc42e79b01f 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -192,7 +192,8 @@ public static function isWhitelisted($name){ /** * Returns the whitelist. * - * On first call this function reads the whitelist from {@see WHITELIST}. + * On first call this function reads the whitelist from {@see WHITELIST} if + * the file exists, {@see WHITELIST_DEFAULT} otherwise. * * Each line in the file specifies one bridge on the whitelist. * * An empty file disables all bridges. * * If the file only only contains `*`, all bridges are whitelisted. @@ -210,19 +211,21 @@ public static function getWhitelist() { if($firstCall) { - // Create initial whitelist or load from disk - if (!file_exists(WHITELIST) && !empty(self::$whitelist)) { - file_put_contents(WHITELIST, implode("\n", self::$whitelist)); - } elseif(file_exists(WHITELIST)) { - + if(file_exists(WHITELIST)) { $contents = trim(file_get_contents(WHITELIST)); + } elseif(file_exists(WHITELIST_DEFAULT)) { + $contents = trim(file_get_contents(WHITELIST_DEFAULT)); + } else { + $contents = ''; + } - if($contents === '*') { // Whitelist all bridges - self::$whitelist = self::getBridgeNames(); - } else { - self::$whitelist = array_map('self::sanitizeBridgeName', explode("\n", $contents)); + if($contents === '*') { // Whitelist all bridges + self::$whitelist = self::getBridgeNames(); + } else { + //self::$whitelist = array_map('self::sanitizeBridgeName', explode("\n", $contents)); + foreach(explode("\n", $contents) as $bridgeName) { + self::$whitelist[] = self::sanitizeBridgeName($bridgeName); } - } } diff --git a/lib/Configuration.php b/lib/Configuration.php index be9315c8caf..cf2fd7c8ceb 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -106,10 +106,6 @@ public static function verifyInstallation() { if(!is_writable(PATH_CACHE)) die('RSS-Bridge does not have write permissions for ' . PATH_CACHE . '!'); - // Check whitelist file permissions - if(!file_exists(WHITELIST) && !is_writable(dirname(WHITELIST))) - die('RSS-Bridge does not have write permissions for ' . WHITELIST . '!'); - } /** diff --git a/lib/rssbridge.php b/lib/rssbridge.php index 5a52358861f..168c91ca921 100644 --- a/lib/rssbridge.php +++ b/lib/rssbridge.php @@ -38,6 +38,9 @@ /** Path to the whitelist file */ define('WHITELIST', __DIR__ . '/../whitelist.txt'); +/** Path to the default whitelist file */ +define('WHITELIST_DEFAULT', __DIR__ . '/../whitelist.default.txt'); + /** URL to the RSS-Bridge repository */ define('REPOSITORY', 'https://github.com/RSS-Bridge/rss-bridge/'); diff --git a/whitelist.default.txt b/whitelist.default.txt new file mode 100644 index 00000000000..6530c3245b7 --- /dev/null +++ b/whitelist.default.txt @@ -0,0 +1,15 @@ +Bandcamp +Cryptome +DansTonChat +DuckDuckGo +Facebook +Flickr +GoogleSearch +Identica +Instagram +OpenClassrooms +Pinterest +Scmb +Twitter +Wikipedia +Youtube