Skip to content

Commit

Permalink
core: Move default bridges to whitelist.default.txt
Browse files Browse the repository at this point in the history
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
  • Loading branch information
logmanoriginal committed Jun 6, 2019
1 parent b0a780a commit d4e867f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
19 changes: 0 additions & 19 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
25 changes: 14 additions & 11 deletions lib/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

}

}
Expand Down
4 changes: 0 additions & 4 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '!');

}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/rssbridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/');

Expand Down
15 changes: 15 additions & 0 deletions whitelist.default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Bandcamp
Cryptome
DansTonChat
DuckDuckGo
Facebook
Flickr
GoogleSearch
Identica
Instagram
OpenClassrooms
Pinterest
Scmb
Twitter
Wikipedia
Youtube

0 comments on commit d4e867f

Please sign in to comment.