Option to block nostr bridges

merge-requests/30/head
Bob Mottram 2024-12-29 14:17:06 +00:00
parent 73dcad7b88
commit a8b5ae487a
37 changed files with 172 additions and 35 deletions

View File

@ -1965,6 +1965,27 @@ def load_blocked_bluesky(base_dir: str) -> {}:
return nicknames_dict
def load_blocked_nostr(base_dir: str) -> {}:
"""Loads a list of nicknames for accounts which block nostr bridges
"""
block_nostr_filename = data_dir(base_dir) + '/block_nostr.txt'
nicknames_list: list[str] = []
if os.path.isfile(block_nostr_filename):
try:
with open(block_nostr_filename, 'r',
encoding='utf-8') as fp_nostr:
nicknames_list = fp_nostr.read()
except OSError:
print('EX: error while reading block nostr file')
if not nicknames_list:
return {}
nicknames_list = nicknames_list.split('\n')
nicknames_dict = {}
for nickname in nicknames_list:
nicknames_dict[nickname] = True
return nicknames_dict
def save_blocked_military(base_dir: str, block_military: {}) -> None:
"""Saves a list of nicknames for accounts which block military instances
"""
@ -2013,6 +2034,22 @@ def save_blocked_bluesky(base_dir: str, block_bluesky: {}) -> None:
print('EX: error while saving block bluesky file')
def save_blocked_nostr(base_dir: str, block_nostr: {}) -> None:
"""Saves a list of nicknames for accounts which block nostr bridges
"""
nicknames_str = ''
for nickname, _ in block_nostr.items():
nicknames_str += nickname + '\n'
block_nostr_filename = data_dir(base_dir) + '/block_nostr.txt'
try:
with open(block_nostr_filename, 'w+',
encoding='utf-8') as fp_nostr:
fp_nostr.write(nicknames_str)
except OSError:
print('EX: error while saving block nostr file')
def get_mil_domains_list() -> []:
"""returns a list of military domains
"""
@ -2032,6 +2069,12 @@ def get_bsky_domains_list() -> []:
return ['brid.gy']
def get_nostr_domains_list() -> []:
"""returns a list of nostr bridges
"""
return ['mostr.pub']
def contains_military_domain(message_str: str) -> bool:
"""Returns true if the given string contains a military domain
"""
@ -2073,6 +2116,20 @@ def contains_bluesky_domain(message_str: str) -> bool:
return False
def contains_nostr_domain(message_str: str) -> bool:
"""Returns true if the given string contains a nostr bridge domain
"""
if '.nostr.' in message_str or \
'/nostr.' in message_str:
return True
nostr_domains = get_nostr_domains_list()
for domain_str in nostr_domains:
if domain_str + '"' in message_str or \
domain_str + '/' in message_str:
return True
return False
def load_federated_blocks_endpoints(base_dir: str) -> []:
"""Loads endpoint urls for federated blocklists
"""

View File

@ -16,6 +16,7 @@ from utils import remove_eol
from blocking import get_mil_domains_list
from blocking import get_gov_domains_list
from blocking import get_bsky_domains_list
from blocking import get_nostr_domains_list
from blocking import update_blocked_cache
from blocking import is_blocked_domain
@ -114,7 +115,8 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
known_bots: [], path: str,
block_military: {},
block_government: {},
block_bluesky: {}):
block_bluesky: {},
block_nostr: {}):
"""Should a GET or POST be blocked based upon its user agent?
"""
if not agent_str:
@ -232,7 +234,8 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
block_dicts = {
"military": block_military,
"government": block_government,
"bluesky": block_bluesky
"bluesky": block_bluesky,
"nostr": block_nostr
}
for block_type, block_dict in block_dicts.items():
if blocked_ua or not block_dict:
@ -250,6 +253,8 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
blk_domains = get_mil_domains_list()
elif block_type == "government":
blk_domains = get_gov_domains_list()
elif block_type == "nostr":
blk_domains = get_nostr_domains_list()
else:
blk_domains = get_bsky_domains_list()
for domain_str in blk_domains:

View File

@ -34,6 +34,7 @@ from blocking import load_federated_blocks_endpoints
from blocking import load_blocked_military
from blocking import load_blocked_government
from blocking import load_blocked_bluesky
from blocking import load_blocked_nostr
from blocking import update_blocked_cache
from blocking import set_broch_mode
from blocking import get_domain_blocklist
@ -311,6 +312,7 @@ class EpicyonServer(ThreadingHTTPServer):
block_military = {}
block_government = {}
block_bluesky = {}
block_nostr = {}
followers_synchronization = False
followers_sync_cache = {}
buy_sites = None
@ -798,6 +800,9 @@ def run_daemon(accounts_data_dir: str,
# load a list of nicknames for accounts blocking bluesky bridges
httpd.block_bluesky = load_blocked_bluesky(base_dir)
# load a list of nicknames for accounts blocking nostr bridges
httpd.block_nostr = load_blocked_nostr(base_dir)
# scan the theme directory for any svg files containing scripts
assert not scan_themes_for_scripts(base_dir)

View File

@ -361,7 +361,8 @@ def daemon_http_get(self) -> None:
self.server.known_bots,
self.path, self.server.block_military,
self.server.block_government,
self.server.block_bluesky)
self.server.block_bluesky,
self.server.block_nostr)
if block:
if llm:
# check if LLM is too frequent
@ -4366,6 +4367,7 @@ def daemon_http_get(self) -> None:
self.server.block_military,
self.server.block_government,
self.server.block_bluesky,
self.server.block_nostr,
self.server.block_federated_endpoints):
self.server.getreq_busy = False
return

View File

@ -542,6 +542,7 @@ def edit_profile2(self, calling_domain: str, path: str,
block_military: {},
block_government: {},
block_bluesky: {},
block_nostr: {},
block_federated_endpoints: []) -> bool:
"""Show the edit profile screen
"""
@ -572,6 +573,7 @@ def edit_profile2(self, calling_domain: str, path: str,
block_military,
block_government,
block_bluesky,
block_nostr,
block_federated_endpoints)
if msg:
msg = msg.encode('utf-8')

View File

@ -25,6 +25,7 @@ from utils import detect_mitm
from blocking import contains_military_domain
from blocking import contains_government_domain
from blocking import contains_bluesky_domain
from blocking import contains_nostr_domain
from crawlers import blocked_user_agent
from session import get_session_for_domain
from session import establish_session
@ -190,7 +191,8 @@ def daemon_http_post(self) -> None:
self.server.known_bots,
self.path, self.server.block_military,
self.server.block_government,
self.server.block_bluesky)
self.server.block_bluesky,
self.server.block_nostr)
if block:
http_400(self)
self.server.postreq_busy = False
@ -1146,6 +1148,12 @@ def daemon_http_post(self) -> None:
print('BLOCK: blocked bluesky domain')
self.server.postreq_busy = False
return
if self.server.block_nostr.get(nickname):
if contains_nostr_domain(decoded_message_bytes):
http_400(self)
print('BLOCK: blocked nostr domain')
self.server.postreq_busy = False
return
# convert the raw bytes to json
try:

View File

@ -14,6 +14,7 @@ from socket import error as SocketError
from blocking import save_blocked_military
from blocking import save_blocked_government
from blocking import save_blocked_bluesky
from blocking import save_blocked_nostr
from httpheaders import redirect_headers
from httpheaders import clear_login_details
from flags import is_artist
@ -893,6 +894,25 @@ def _profile_post_block_bluesky(nickname: str, fields: {}, self) -> None:
self.server.block_bluesky)
def _profile_post_block_nostr(nickname: str, fields: {}, self) -> None:
""" HTTP POST block nostr bridges
"""
block_nostr_instances = False
if fields.get('blockNostr'):
if fields['blockNostr'] == 'on':
block_nostr_instances = True
if block_nostr_instances:
if not self.server.block_nostr.get(nickname):
self.server.block_nostr[nickname] = True
save_blocked_nostr(self.server.base_dir,
self.server.block_nostr)
else:
if self.server.block_nostr.get(nickname):
del self.server.block_nostr[nickname]
save_blocked_nostr(self.server.base_dir,
self.server.block_nostr)
def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str,
fields: {}) -> bool:
""" HTTP POST disallow boosts of replies in inbox
@ -3285,6 +3305,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
_profile_post_block_military(nickname, fields, self)
_profile_post_block_government(nickname, fields, self)
_profile_post_block_bluesky(nickname, fields, self)
_profile_post_block_nostr(nickname, fields, self)
_profile_post_no_reply_boosts(base_dir, nickname, domain,
fields)
_profile_post_no_seen_posts(base_dir, nickname, domain,

View File

@ -9172,8 +9172,6 @@ def run_all_tests():
base_dir = os.getcwd()
data_dir_testing(base_dir)
print('Running tests...')
_test_functions()
return
update_default_themes_list(os.getcwd())
_test_source_contains_no_tabs()
_translate_ontology(base_dir)

View File

@ -705,5 +705,6 @@
"Yourself": "نفسك",
"Epicyon Instances": "حالات Epicyon",
"Block BlueSky bridges": "حجب جسور بلو سكاي",
"Block government instances": "حظر حالات الحكومة"
"Block government instances": "حظر حالات الحكومة",
"Block Nostr bridges": "سد جسور نوستر"
}

View File

@ -705,5 +705,6 @@
"Yourself": "নিজেকে",
"Epicyon Instances": "এপিসিয়ন দৃষ্টান্ত",
"Block BlueSky bridges": "ব্লুস্কাই ব্রিজ ব্লক করুন",
"Block government instances": "সরকারী দৃষ্টান্ত ব্লক করুন"
"Block government instances": "সরকারী দৃষ্টান্ত ব্লক করুন",
"Block Nostr bridges": "ব্লক নস্ট্র ব্রিজ"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Tu mateix",
"Epicyon Instances": "Instàncies d'Epicyon",
"Block BlueSky bridges": "Bloqueja els ponts BlueSky",
"Block government instances": "Bloquejar instàncies governamentals"
"Block government instances": "Bloquejar instàncies governamentals",
"Block Nostr bridges": "Bloc Nostr ponts"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Eich Hun",
"Epicyon Instances": "Enghreifftiau Epicyon",
"Block BlueSky bridges": "Rhwystro pontydd BlueSky",
"Block government instances": "Rhwystro achosion llywodraeth"
"Block government instances": "Rhwystro achosion llywodraeth",
"Block Nostr bridges": "Rhwystro pontydd Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Selbst",
"Epicyon Instances": "Epicyon-Instanzen",
"Block BlueSky bridges": "Blockieren Sie BlueSky-Brücken",
"Block government instances": "Blockieren von Regierungsinstanzen"
"Block government instances": "Blockieren von Regierungsinstanzen",
"Block Nostr bridges": "Block Nostr-Brücken"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Σύ ο ίδιος",
"Epicyon Instances": "Περιπτώσεις Epicyon",
"Block BlueSky bridges": "Αποκλείστε τις γέφυρες BlueSky",
"Block government instances": "Αποκλεισμός κρατικών περιπτώσεων"
"Block government instances": "Αποκλεισμός κρατικών περιπτώσεων",
"Block Nostr bridges": "Αποκλείστε τις γέφυρες Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Yourself",
"Epicyon Instances": "Epicyon Instances",
"Block BlueSky bridges": "Block BlueSky bridges",
"Block government instances": "Block government instances"
"Block government instances": "Block government instances",
"Block Nostr bridges": "Block Nostr bridges"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Tú mismo",
"Epicyon Instances": "Instancias de Epicyon",
"Block BlueSky bridges": "Bloquear puentes BlueSky",
"Block government instances": "Bloquear instancias gubernamentales"
"Block government instances": "Bloquear instancias gubernamentales",
"Block Nostr bridges": "Puentes Block Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "خودت",
"Epicyon Instances": "موارد Epicyon",
"Block BlueSky bridges": "پل های BlueSky را مسدود کنید",
"Block government instances": "موارد دولتی را مسدود کنید"
"Block government instances": "موارد دولتی را مسدود کنید",
"Block Nostr bridges": "پل های نوستر را مسدود کنید"
}

View File

@ -705,5 +705,6 @@
"Yourself": "itseäsi",
"Epicyon Instances": "Epicyonin esiintymät",
"Block BlueSky bridges": "Estä BlueSky-sillat",
"Block government instances": "Estä hallituksen esiintymät"
"Block government instances": "Estä hallituksen esiintymät",
"Block Nostr bridges": "Estä Nostrin sillat"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Toi-même",
"Epicyon Instances": "Instances d'Epicyon",
"Block BlueSky bridges": "Bloquer les ponts BlueSky",
"Block government instances": "Bloquer les instances gouvernementales"
"Block government instances": "Bloquer les instances gouvernementales",
"Block Nostr bridges": "Bloc Nostr ponts"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Tú féin",
"Epicyon Instances": "Cásanna Epicyon",
"Block BlueSky bridges": "Bloc droichid BlueSky",
"Block government instances": "Cuir bac ar chásanna rialtais"
"Block government instances": "Cuir bac ar chásanna rialtais",
"Block Nostr bridges": "Bloc droichid Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "עַצמְךָ",
"Epicyon Instances": "מופעי Epicyon",
"Block BlueSky bridges": "חסום גשרי BlueSky",
"Block government instances": "חסום מקרים ממשלתיים"
"Block government instances": "חסום מקרים ממשלתיים",
"Block Nostr bridges": "חסום גשרי Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "अपने आप को",
"Epicyon Instances": "एपिक्योन इंस्टेंसेस",
"Block BlueSky bridges": "ब्लूस्काई पुलों को ब्लॉक करें",
"Block government instances": "सरकारी इंस्टेंस ब्लॉक करें"
"Block government instances": "सरकारी इंस्टेंस ब्लॉक करें",
"Block Nostr bridges": "ब्लॉक नोस्ट्र पुल"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Te stesso",
"Epicyon Instances": "Istanze di Epicyon",
"Block BlueSky bridges": "Blocca i ponti BlueSky",
"Block government instances": "Bloccare le istanze governative"
"Block government instances": "Bloccare le istanze governative",
"Block Nostr bridges": "Ponti Block Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "あなた自身",
"Epicyon Instances": "エピキオンインスタンス",
"Block BlueSky bridges": "ブルースカイ橋をブロックする",
"Block government instances": "政府インスタンスをブロックする"
"Block government instances": "政府インスタンスをブロックする",
"Block Nostr bridges": "ノストル橋をブロック"
}

View File

@ -705,5 +705,6 @@
"Yourself": "당신 자신",
"Epicyon Instances": "에피시온 인스턴스",
"Block BlueSky bridges": "블루스카이 다리 차단",
"Block government instances": "정부 인스턴스 차단"
"Block government instances": "정부 인스턴스 차단",
"Block Nostr bridges": "블록 노스트르 다리"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Xwe",
"Epicyon Instances": "Mînakên Epicyon",
"Block BlueSky bridges": "Pirên BlueSky asteng bikin",
"Block government instances": "Bûyerên hikûmetê asteng bikin"
"Block government instances": "Bûyerên hikûmetê asteng bikin",
"Block Nostr bridges": "Pirên Nostrê asteng bikin"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Jezelf",
"Epicyon Instances": "Epicyon-instanties",
"Block BlueSky bridges": "Blokkeer BlueSky-bruggen",
"Block government instances": "Overheidsinstanties blokkeren"
"Block government instances": "Overheidsinstanties blokkeren",
"Block Nostr bridges": "Blok Nostr-bruggen"
}

View File

@ -701,5 +701,6 @@
"Yourself": "Yourself",
"Epicyon Instances": "Epicyon Instances",
"Block BlueSky bridges": "Block BlueSky bridges",
"Block government instances": "Block government instances"
"Block government instances": "Block government instances",
"Block Nostr bridges": "Block Nostr bridges"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Się",
"Epicyon Instances": "Instancje Epicyon",
"Block BlueSky bridges": "Zablokuj mosty BlueSky",
"Block government instances": "Zablokuj wystąpienia rządowe"
"Block government instances": "Zablokuj wystąpienia rządowe",
"Block Nostr bridges": "Mosty Bloku Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Tu próprio",
"Epicyon Instances": "Instâncias Epicyon",
"Block BlueSky bridges": "Bloquear pontes BlueSky",
"Block government instances": "Bloquear instâncias governamentais"
"Block government instances": "Bloquear instâncias governamentais",
"Block Nostr bridges": "Bloquear pontes Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Сам",
"Epicyon Instances": "Эпиционные экземпляры",
"Block BlueSky bridges": "Блокировать мосты BlueSky",
"Block government instances": "Блокировать правительственные инстанции"
"Block government instances": "Блокировать правительственные инстанции",
"Block Nostr bridges": "Блок Ностр мосты"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Mwenyewe",
"Epicyon Instances": "Matukio ya Epicyon",
"Block BlueSky bridges": "Zuia madaraja ya BlueSky",
"Block government instances": "Zuia matukio ya serikali"
"Block government instances": "Zuia matukio ya serikali",
"Block Nostr bridges": "Zuia madaraja ya Nostr"
}

View File

@ -705,5 +705,6 @@
"Yourself": "Kendin",
"Epicyon Instances": "Epikyon Örnekleri",
"Block BlueSky bridges": "BlueSky köprülerini engelle",
"Block government instances": "Hükümet örneklerini engelle"
"Block government instances": "Hükümet örneklerini engelle",
"Block Nostr bridges": "Nostr köprülerini engelle"
}

View File

@ -705,5 +705,6 @@
"Yourself": "себе",
"Epicyon Instances": "Примірники Epicyon",
"Block BlueSky bridges": "Блок BlueSky bridges",
"Block government instances": "Блокувати державні інстанції"
"Block government instances": "Блокувати державні інстанції",
"Block Nostr bridges": "Блок Nostr bridges"
}

View File

@ -705,5 +705,6 @@
"Yourself": "זיך",
"Epicyon Instances": "Epicyon ינסטאַנסיז",
"Block BlueSky bridges": "פאַרשפּאַרן בלוסקי בריקן",
"Block government instances": "פאַרשפּאַרן רעגירונג ינסטאַנסיז"
"Block government instances": "פאַרשפּאַרן רעגירונג ינסטאַנסיז",
"Block Nostr bridges": "פאַרשפּאַרן נאָסטר בריקן"
}

View File

@ -705,5 +705,6 @@
"Yourself": "你自己",
"Epicyon Instances": "史诗副本",
"Block BlueSky bridges": "封锁蓝天桥梁",
"Block government instances": "阻止政府实例"
"Block government instances": "阻止政府实例",
"Block Nostr bridges": "布洛克诺斯特桥"
}

View File

@ -2434,6 +2434,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
buy_sites: {}, block_military: {},
block_government: {},
block_bluesky: {},
block_nostr: {},
block_federated_endpoints: []) -> str:
"""Filtering and blocking section of edit profile screen
"""
@ -2729,6 +2730,15 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
edit_profile_form += \
edit_check_box(idx, 'blockBlueSky', block_bsky)
idx = 'Block Nostr bridges'
if translate.get(idx):
name = translate[idx]
blocknostr = False
if block_nostr.get(nickname):
blocknostr = block_nostr[nickname]
edit_profile_form += \
edit_check_box(idx, 'blockNostr', blocknostr)
cw_lists_str = ''
for name, _ in cw_lists.items():
variablename = get_cw_list_variable(name)
@ -3311,6 +3321,7 @@ def html_edit_profile(server, translate: {},
block_military: {},
block_government: {},
block_bluesky: {},
block_nostr: {},
block_federated_endpoints: []) -> str:
"""Shows the edit profile screen
"""
@ -3636,7 +3647,7 @@ def html_edit_profile(server, translate: {},
translate, reply_interval_hours,
cw_lists, lists_enabled, buy_sites,
block_military, block_government,
block_bluesky,
block_bluesky, block_nostr,
block_federated_endpoints)
# git projects section