generalise the site black|white allow lists, also add a channel black|white list for future use

This commit is contained in:
redmatrix 2015-11-29 20:26:00 -08:00
parent a2747403f2
commit 650f882265
4 changed files with 63 additions and 26 deletions

View File

@ -40,19 +40,11 @@ function externals_run($argv, $argc){
$url = $r[0]['site_url']; $url = $r[0]['site_url'];
} }
// Note: blacklisted sites must be stored in the config as an array.
// No simple way to turn this into a personal config because we have no identity here.
// For that we probably need a variant of superblock.
$blacklisted = false; $blacklisted = false;
$bl1 = get_config('system','blacklisted_sites');
if(is_array($bl1) && $bl1) { if(! check_siteallowed($url)) {
foreach($bl1 as $bl) { logger('blacklisted site: ' . $url);
if($bl && strpos($url,$bl) !== false) { $blacklisted = true;
$blacklisted = true;
break;
}
}
} }
$attempts ++; $attempts ++;

View File

@ -1813,3 +1813,58 @@ function get_site_info() {
); );
return $data; return $data;
} }
function check_siteallowed($url) {
$retvalue = true;
$bl1 = get_config('system','whitelisted_sites');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
$retvalue = true;
if($bl && strpos($url,$bl) !== false)
return true;
}
}
$bl1 = get_config('system','blacklisted_sites');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
$retvalue = false;
if($bl && strpos($url,$bl) !== false) {
return false;
}
}
}
return $retvalue;
}
function check_channelallowed($hash) {
$retvalue = true;
$bl1 = get_config('system','whitelisted_channels');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
$retvalue = true;
if($bl && strpos($hash,$bl) !== false)
return true;
}
}
$bl1 = get_config('system','blacklisted_channels');
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl1 === '*')
$retvalue = false;
if($bl && strpos($hash,$bl) !== false) {
return false;
}
}
}
return $retvalue;
}

View File

@ -554,18 +554,8 @@ function zot_gethub($arr,$multiple = false) {
if($arr['guid'] && $arr['guid_sig'] && $arr['url'] && $arr['url_sig']) { if($arr['guid'] && $arr['guid_sig'] && $arr['url'] && $arr['url_sig']) {
$blacklisted = false; if(! check_siteallowed($arr['url'])) {
$bl1 = get_config('system','blacklisted_sites'); logger('blacklisted site: ' . $arr['url']);
if(is_array($bl1) && $bl1) {
foreach($bl1 as $bl) {
if($bl && strpos($arr['url'],$bl) !== false) {
$blacklisted = true;
break;
}
}
}
if($blacklisted) {
logger('zot_gethub: blacklisted site: ' . $arr['url']);
return null; return null;
} }

View File

@ -14,7 +14,7 @@ $install_wizard_pass = 1;
* *
* @param[in,out] App &$a * @param[in,out] App &$a
*/ */
function setup_init(&$a){ function setup_init(&$a) {
// Ensure that if somebody hasn't read the install documentation and doesn't have all // Ensure that if somebody hasn't read the install documentation and doesn't have all
// the required modules or has a totally borked shared hosting provider and they can't // the required modules or has a totally borked shared hosting provider and they can't