diff --git a/index.php b/index.php index 771e3379..0bc63625 100644 --- a/index.php +++ b/index.php @@ -29,27 +29,8 @@ define('USER_AGENT', 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 9e5750a7..dc42e79b 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -192,7 +192,8 @@ class Bridge { /** * 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 @@ class Bridge { 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 be9315c8..cf2fd7c8 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -106,10 +106,6 @@ final class Configuration { 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 5a523588..168c91ca 100644 --- a/lib/rssbridge.php +++ b/lib/rssbridge.php @@ -38,6 +38,9 @@ define('PATH_CACHE', __DIR__ . '/../cache/'); /** 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 00000000..6530c324 --- /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