added safe harbor for domains

One can now add a [safe harbor] section to the config file with an entry
"domains" that has a comma separated list of domains that shall never end
on the block list.
This commit is contained in:
Tobias Diekershoff 2023-01-07 22:20:50 +01:00
commit bca141a120
3 changed files with 38 additions and 16 deletions

View file

@ -80,6 +80,18 @@ trust = 30
trust = -50 trust = -50
``` ```
You can also add a list of protected nodes to the config file. To do so add a
section `[safe harbor]` to the config file. This section has only one entry
called `domains` and the value of this entry is a comma separated list of domains
that should never get on your blocklist.
For example
```
[safe harbor]
domain = friendica.example.com
```
### Running the script ### Running the script
You have to supply the file name of the configuration file on the command You have to supply the file name of the configuration file on the command

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "brewserverblocklist" name = "brewserverblocklist"
version = "1.0.0" version = "1.0.1"
description = "A python script to collect the server-wide blocklists from Friendica nodes to build a collection from trusted admin choice" description = "A python script to collect the server-wide blocklists from Friendica nodes to build a collection from trusted admin choice"
authors = ["Tobias Diekershoff"] authors = ["Tobias Diekershoff"]
license = "GNU General Public License v3.0" license = "GNU General Public License v3.0"

View file

@ -31,11 +31,20 @@ class BrewBlocklist():
self.sources = [] self.sources = []
self.auto_accept = auto_accept self.auto_accept = auto_accept
self.auto_accept_direction = auto_accept_direction self.auto_accept_direction = auto_accept_direction
self.safe_harbor = []
config = configparser.RawConfigParser() config = configparser.RawConfigParser()
config.read(configfile) config.read(configfile)
for section in config.sections(): for section in config.sections():
section_values = dict(config.items(section)) section_values = dict(config.items(section))
self.sources.append({'url': section, 'trust': int(section_values['trust'])}) if not section == 'safe harbor':
self.sources.append({
'url': section,
'trust': int(section_values['trust']),
})
else:
for item in section_values['domains'].split(','):
print(item)
self.safe_harbor.append(item)
self.outputfile = outputfile self.outputfile = outputfile
self.confidence = confidence self.confidence = confidence
self.blocklist = {} self.blocklist = {}
@ -71,21 +80,22 @@ class BrewBlocklist():
c_blocklist = {} c_blocklist = {}
c_reasons = {} c_reasons = {}
for key, value in self.blocklist.items(): for key, value in self.blocklist.items():
if value < self.confidence: if not key in self.safe_harbor:
if not self.auto_accept: if value < self.confidence:
print('Domain: {} [total trust {}]'.format(key, value)) if not self.auto_accept:
print('Reason: {}'.format(self.reasons[key])) print('Domain: {} [total trust {}]'.format(key, value))
keep = input('Keep that entry? [Y/n] > ') print('Reason: {}'.format(self.reasons[key]))
if keep not in ['n', 'N']: keep = input('Keep that entry? [Y/n] > ')
c_blocklist[key] = value if keep not in ['n', 'N']:
c_reasons[key] = self.reasons[key] c_blocklist[key] = value
c_reasons[key] = self.reasons[key]
else:
if self.auto_accept_direction:
c_blocklist[key] = value
c_reasons[key] = self.reasons[key]
else: else:
if self.auto_accept_direction: c_blocklist[key] = value
c_blocklist[key] = value c_reasons[key] = self.reasons[key]
c_reasons[key] = self.reasons[key]
else:
c_blocklist[key] = value
c_reasons[key] = self.reasons[key]
self.blocklist = c_blocklist self.blocklist = c_blocklist
self.reasons = c_reasons self.reasons = c_reasons