Option to block bluesky bridges

main
Bob Mottram 2024-12-14 18:02:43 +00:00
parent bb0717ae27
commit a355d2c5b7
36 changed files with 199 additions and 34 deletions

View File

@ -1922,6 +1922,27 @@ def load_blocked_military(base_dir: str) -> {}:
return nicknames_dict
def load_blocked_bluesky(base_dir: str) -> {}:
"""Loads a list of nicknames for accounts which block bluesky bridges
"""
block_bluesky_filename = data_dir(base_dir) + '/block_bluesky.txt'
nicknames_list = []
if os.path.isfile(block_bluesky_filename):
try:
with open(block_bluesky_filename, 'r',
encoding='utf-8') as fp_mil:
nicknames_list = fp_mil.read()
except OSError:
print('EX: error while reading block bluesky 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
"""
@ -1938,6 +1959,22 @@ def save_blocked_military(base_dir: str, block_military: {}) -> None:
print('EX: error while saving block military file')
def save_blocked_bluesky(base_dir: str, block_bluesky: {}) -> None:
"""Saves a list of nicknames for accounts which block bluesky bridges
"""
nicknames_str = ''
for nickname, _ in block_bluesky.items():
nicknames_str += nickname + '\n'
block_bluesky_filename = data_dir(base_dir) + '/block_bluesky.txt'
try:
with open(block_bluesky_filename, 'w+',
encoding='utf-8') as fp_mil:
fp_mil.write(nicknames_str)
except OSError:
print('EX: error while saving block bluesky file')
def get_mil_domains_list() -> []:
"""returns a list of military domains
"""
@ -1945,6 +1982,12 @@ def get_mil_domains_list() -> []:
'sncorp.com', 'sierranevadacorp.us', 'ncontext.com')
def get_bsky_domains_list() -> []:
"""returns a list of bluesky bridges
"""
return ('bsky.brid.gy', 'fed.brid.gy')
def contains_military_domain(message_str: str) -> bool:
"""Returns true if the given string contains a military domain
"""
@ -1962,6 +2005,23 @@ def contains_military_domain(message_str: str) -> bool:
return False
def contains_bluesky_domain(message_str: str) -> bool:
"""Returns true if the given string contains a bluesky bridge domain
"""
bsky_domains = get_bsky_domains_list()
for domain_str in bsky_domains:
if '.' not in domain_str:
tld = domain_str
if '.' + tld + '"' in message_str or \
'.' + tld + '/' in message_str:
return True
else:
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

@ -14,6 +14,7 @@ from utils import save_json
from utils import user_agent_domain
from utils import remove_eol
from blocking import get_mil_domains_list
from blocking import get_bsky_domains_list
from blocking import update_blocked_cache
from blocking import is_blocked_domain
@ -110,7 +111,8 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
blocked_cache_update_secs: int,
crawlers_allowed: [],
known_bots: [], path: str,
block_military: {}):
block_military: {},
block_bluesky: {}):
"""Should a GET or POST be blocked based upon its user agent?
"""
if not agent_str:
@ -250,4 +252,29 @@ def blocked_user_agent(calling_domain: str, agent_str: str,
agent_domain)
break
# optionally block bluesky bridges on a per account basis
if not blocked_ua and block_bluesky:
if '/users/' in path:
# which accounts is this?
nickname = path.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
# does this account block bluesky bridges?
if block_bluesky.get(nickname):
bsky_domains = get_bsky_domains_list()
for domain_str in bsky_domains:
if '.' not in domain_str:
tld = domain_str
if agent_domain.endswith('.' + tld):
blocked_ua = True
print('BLOCK: Blocked bluesky tld user agent: ' +
agent_domain)
break
else:
if agent_domain.endswith(domain_str):
blocked_ua = True
print('BLOCK: Blocked bluesky user agent: ' +
agent_domain)
break
return blocked_ua, blocked_cache_last_updated, False

View File

@ -32,6 +32,7 @@ from cwlists import load_cw_lists
from blocking import run_federated_blocks_daemon
from blocking import load_federated_blocks_endpoints
from blocking import load_blocked_military
from blocking import load_blocked_bluesky
from blocking import update_blocked_cache
from blocking import set_broch_mode
from blocking import get_domain_blocklist
@ -305,7 +306,8 @@ class EpicyonServer(ThreadingHTTPServer):
auto_cw_cache = {}
sites_unavailable = None
max_shares_on_profile = 0
block_military = []
block_military = {}
block_bluesky = {}
followers_synchronization = False
followers_sync_cache = {}
buy_sites = None
@ -783,6 +785,9 @@ def run_daemon(accounts_data_dir: str,
# load a list of nicknames for accounts blocking military instances
httpd.block_military = load_blocked_military(base_dir)
# load a list of nicknames for accounts blocking bluesky bridges
httpd.block_bluesky = load_blocked_bluesky(base_dir)
# scan the theme directory for any svg files containing scripts
assert not scan_themes_for_scripts(base_dir)

View File

@ -358,7 +358,8 @@ def daemon_http_get(self) -> None:
self.server.blocked_cache_update_secs,
self.server.crawlers_allowed,
self.server.known_bots,
self.path, self.server.block_military)
self.path, self.server.block_military,
self.server.block_bluesky)
if block:
if llm:
# check if LLM is too frequent
@ -4341,6 +4342,7 @@ def daemon_http_get(self) -> None:
self.server.reverse_sequence,
self.server.buy_sites,
self.server.block_military,
self.server.block_bluesky,
self.server.block_federated_endpoints):
self.server.getreq_busy = False
return

View File

@ -533,7 +533,8 @@ def edit_profile2(self, calling_domain: str, path: str,
max_recent_posts: int,
reverse_sequence: bool,
buy_sites: [],
block_military: bool,
block_military: {},
block_bluesky: {},
block_federated_endpoints: []) -> bool:
"""Show the edit profile screen
"""
@ -562,6 +563,7 @@ def edit_profile2(self, calling_domain: str, path: str,
reverse_sequence,
buy_sites,
block_military,
block_bluesky,
block_federated_endpoints)
if msg:
msg = msg.encode('utf-8')

View File

@ -22,6 +22,7 @@ from utils import contains_invalid_chars
from utils import remove_id_ending
from utils import check_bad_path
from blocking import contains_military_domain
from blocking import contains_bluesky_domain
from crawlers import blocked_user_agent
from session import get_session_for_domain
from session import establish_session
@ -181,7 +182,8 @@ def daemon_http_post(self) -> None:
self.server.blocked_cache_update_secs,
self.server.crawlers_allowed,
self.server.known_bots,
self.path, self.server.block_military)
self.path, self.server.block_military,
self.server.block_bluesky)
if block:
http_400(self)
self.server.postreq_busy = False
@ -1119,6 +1121,12 @@ def daemon_http_post(self) -> None:
print('BLOCK: blocked military domain')
self.server.postreq_busy = False
return
if self.server.block_bluesky.get(nickname):
if contains_bluesky_domain(decoded_message_bytes):
http_400(self)
print('BLOCK: blocked bluesky domain')
self.server.postreq_busy = False
return
# convert the raw bytes to json
try:

View File

@ -12,6 +12,7 @@ import errno
from webfinger import webfinger_update
from socket import error as SocketError
from blocking import save_blocked_military
from blocking import save_blocked_bluesky
from httpheaders import redirect_headers
from httpheaders import clear_login_details
from flags import is_artist
@ -853,6 +854,25 @@ def _profile_post_block_military(nickname: str, fields: {}, self) -> None:
self.server.block_military)
def _profile_post_block_bluesky(nickname: str, fields: {}, self) -> None:
""" HTTP POST block bluesky bridges
"""
block_bsky_instances = False
if fields.get('blockBlueSky'):
if fields['blockBlueSky'] == 'on':
block_bsky_instances = True
if block_bsky_instances:
if not self.server.block_bluesky.get(nickname):
self.server.block_bluesky[nickname] = True
save_blocked_bluesky(self.server.base_dir,
self.server.block_bluesky)
else:
if self.server.block_bluesky.get(nickname):
del self.server.block_bluesky[nickname]
save_blocked_bluesky(self.server.base_dir,
self.server.block_bluesky)
def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str,
fields: {}) -> bool:
""" HTTP POST disallow boosts of replies in inbox
@ -3239,6 +3259,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
actor_json, fields, self,
actor_changed, premium)
_profile_post_block_military(nickname, fields, self)
_profile_post_block_bluesky(nickname, fields, self)
_profile_post_no_reply_boosts(base_dir, nickname, domain,
fields)
_profile_post_no_seen_posts(base_dir, nickname, domain,

View File

@ -703,5 +703,6 @@
"Reply Controls": "عناصر التحكم في الرد",
"Searchable by": "قابلة للبحث بواسطة",
"Yourself": "نفسك",
"Epicyon Instances": "حالات Epicyon"
"Epicyon Instances": "حالات Epicyon",
"Block BlueSky bridges": "حجب جسور بلو سكاي"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "উত্তর নিয়ন্ত্রণ",
"Searchable by": "দ্বারা অনুসন্ধানযোগ্য",
"Yourself": "নিজেকে",
"Epicyon Instances": "এপিসিয়ন দৃষ্টান্ত"
"Epicyon Instances": "এপিসিয়ন দৃষ্টান্ত",
"Block BlueSky bridges": "ব্লুস্কাই ব্রিজ ব্লক করুন"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Controls de resposta",
"Searchable by": "Cercable per",
"Yourself": "Tu mateix",
"Epicyon Instances": "Instàncies d'Epicyon"
"Epicyon Instances": "Instàncies d'Epicyon",
"Block BlueSky bridges": "Bloqueja els ponts BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Rheolaethau Ymateb",
"Searchable by": "Chwiliadwy gan",
"Yourself": "Eich Hun",
"Epicyon Instances": "Enghreifftiau Epicyon"
"Epicyon Instances": "Enghreifftiau Epicyon",
"Block BlueSky bridges": "Rhwystro pontydd BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Antwortsteuerung",
"Searchable by": "Durchsuchbar nach",
"Yourself": "Selbst",
"Epicyon Instances": "Epicyon-Instanzen"
"Epicyon Instances": "Epicyon-Instanzen",
"Block BlueSky bridges": "Blockieren Sie BlueSky-Brücken"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Στοιχεία ελέγχου απάντησης",
"Searchable by": "Δυνατότητα αναζήτησης από",
"Yourself": "Σύ ο ίδιος",
"Epicyon Instances": "Περιπτώσεις Epicyon"
"Epicyon Instances": "Περιπτώσεις Epicyon",
"Block BlueSky bridges": "Αποκλείστε τις γέφυρες BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Reply Controls",
"Searchable by": "Searchable by",
"Yourself": "Yourself",
"Epicyon Instances": "Epicyon Instances"
"Epicyon Instances": "Epicyon Instances",
"Block BlueSky bridges": "Block BlueSky bridges"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Controles de respuesta",
"Searchable by": "Buscable por",
"Yourself": "Tú mismo",
"Epicyon Instances": "Instancias de Epicyon"
"Epicyon Instances": "Instancias de Epicyon",
"Block BlueSky bridges": "Bloquear puentes BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "کنترل های پاسخ",
"Searchable by": "قابل جستجو توسط",
"Yourself": "خودت",
"Epicyon Instances": "موارد Epicyon"
"Epicyon Instances": "موارد Epicyon",
"Block BlueSky bridges": "پل های BlueSky را مسدود کنید"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Vastausohjaimet",
"Searchable by": "Haettavissa",
"Yourself": "itseäsi",
"Epicyon Instances": "Epicyonin esiintymät"
"Epicyon Instances": "Epicyonin esiintymät",
"Block BlueSky bridges": "Estä BlueSky-sillat"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Contrôles de réponse",
"Searchable by": "Recherchable par",
"Yourself": "Toi-même",
"Epicyon Instances": "Instances d'Epicyon"
"Epicyon Instances": "Instances d'Epicyon",
"Block BlueSky bridges": "Bloquer les ponts BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Rialuithe Freagra",
"Searchable by": "Inchuardaithe ag",
"Yourself": "Tú féin",
"Epicyon Instances": "Cásanna Epicyon"
"Epicyon Instances": "Cásanna Epicyon",
"Block BlueSky bridges": "Bloc droichid BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "פקדי תגובה",
"Searchable by": "ניתן לחיפוש לפי",
"Yourself": "עַצמְךָ",
"Epicyon Instances": "מופעי Epicyon"
"Epicyon Instances": "מופעי Epicyon",
"Block BlueSky bridges": "חסום גשרי BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "उत्तर नियंत्रण",
"Searchable by": "द्वारा खोजा जा सकता है",
"Yourself": "अपने आप को",
"Epicyon Instances": "एपिक्योन इंस्टेंसेस"
"Epicyon Instances": "एपिक्योन इंस्टेंसेस",
"Block BlueSky bridges": "ब्लूस्काई पुलों को ब्लॉक करें"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Controlli di risposta",
"Searchable by": "Ricercabile per",
"Yourself": "Te stesso",
"Epicyon Instances": "Istanze di Epicyon"
"Epicyon Instances": "Istanze di Epicyon",
"Block BlueSky bridges": "Blocca i ponti BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "返信コントロール",
"Searchable by": "検索可能",
"Yourself": "あなた自身",
"Epicyon Instances": "エピキオンインスタンス"
"Epicyon Instances": "エピキオンインスタンス",
"Block BlueSky bridges": "ブルースカイ橋をブロックする"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "답변 제어",
"Searchable by": "검색 가능",
"Yourself": "당신 자신",
"Epicyon Instances": "에피시온 인스턴스"
"Epicyon Instances": "에피시온 인스턴스",
"Block BlueSky bridges": "블루스카이 다리 차단"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Reply Controls",
"Searchable by": "Lêgerîn ji hêla",
"Yourself": "Xwe",
"Epicyon Instances": "Mînakên Epicyon"
"Epicyon Instances": "Mînakên Epicyon",
"Block BlueSky bridges": "Pirên BlueSky asteng bikin"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Antwoordbedieningen",
"Searchable by": "Doorzoekbaar op",
"Yourself": "Jezelf",
"Epicyon Instances": "Epicyon-instanties"
"Epicyon Instances": "Epicyon-instanties",
"Block BlueSky bridges": "Blokkeer BlueSky-bruggen"
}

View File

@ -699,5 +699,6 @@
"Reply Controls": "Reply Controls",
"Searchable by": "Searchable by",
"Yourself": "Yourself",
"Epicyon Instances": "Epicyon Instances"
"Epicyon Instances": "Epicyon Instances",
"Block BlueSky bridges": "Block BlueSky bridges"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Kontrola odpowiedzi",
"Searchable by": "Można wyszukiwać według",
"Yourself": "Się",
"Epicyon Instances": "Instancje Epicyon"
"Epicyon Instances": "Instancje Epicyon",
"Block BlueSky bridges": "Zablokuj mosty BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Controles de resposta",
"Searchable by": "Pesquisável por",
"Yourself": "Tu próprio",
"Epicyon Instances": "Instâncias Epicyon"
"Epicyon Instances": "Instâncias Epicyon",
"Block BlueSky bridges": "Bloquear pontes BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Ответить Элементы управления",
"Searchable by": "Поиск по",
"Yourself": "Сам",
"Epicyon Instances": "Эпиционные экземпляры"
"Epicyon Instances": "Эпиционные экземпляры",
"Block BlueSky bridges": "Блокировать мосты BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Vidhibiti vya Kujibu",
"Searchable by": "Inaweza kutafutwa na",
"Yourself": "Mwenyewe",
"Epicyon Instances": "Matukio ya Epicyon"
"Epicyon Instances": "Matukio ya Epicyon",
"Block BlueSky bridges": "Zuia madaraja ya BlueSky"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Cevap Kontrolleri",
"Searchable by": "Aranabilir",
"Yourself": "Kendin",
"Epicyon Instances": "Epikyon Örnekleri"
"Epicyon Instances": "Epikyon Örnekleri",
"Block BlueSky bridges": "BlueSky köprülerini engelle"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "Елементи керування відповідями",
"Searchable by": "Можливість пошуку за",
"Yourself": "себе",
"Epicyon Instances": "Примірники Epicyon"
"Epicyon Instances": "Примірники Epicyon",
"Block BlueSky bridges": "Блок BlueSky bridges"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "ענטפער קאָנטראָלס",
"Searchable by": "זוך דורך",
"Yourself": "זיך",
"Epicyon Instances": "Epicyon ינסטאַנסיז"
"Epicyon Instances": "Epicyon ינסטאַנסיז",
"Block BlueSky bridges": "פאַרשפּאַרן בלוסקי בריקן"
}

View File

@ -703,5 +703,6 @@
"Reply Controls": "回复控制",
"Searchable by": "可搜索",
"Yourself": "你自己",
"Epicyon Instances": "史诗副本"
"Epicyon Instances": "史诗副本",
"Block BlueSky bridges": "封锁蓝天桥梁"
}

View File

@ -2408,6 +2408,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
translate: {}, reply_interval_hours: int,
cw_lists: {}, lists_enabled: str,
buy_sites: {}, block_military: {},
block_bluesky: {},
block_federated_endpoints: []) -> str:
"""Filtering and blocking section of edit profile screen
"""
@ -2685,6 +2686,15 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
edit_profile_form += \
edit_check_box(idx, 'blockMilitary', block_mil)
idx = 'Block BlueSky bridges'
if translate.get(idx):
name = translate[idx]
block_bsky = False
if block_bluesky.get(nickname):
block_bsky = block_bluesky[nickname]
edit_profile_form += \
edit_check_box(idx, 'blockBlueSky', block_bsky)
cw_lists_str = ''
for name, _ in cw_lists.items():
variablename = get_cw_list_variable(name)
@ -3265,6 +3275,7 @@ def html_edit_profile(server, translate: {},
reverse_sequence: [],
buy_sites: {},
block_military: {},
block_bluesky: {},
block_federated_endpoints: []) -> str:
"""Shows the edit profile screen
"""
@ -3589,7 +3600,8 @@ def html_edit_profile(server, translate: {},
user_agents_blocked, crawlers_allowed,
translate, reply_interval_hours,
cw_lists, lists_enabled, buy_sites,
block_military, block_federated_endpoints)
block_military, block_bluesky,
block_federated_endpoints)
# git projects section
edit_profile_form += \