mirror of https://gitlab.com/bashrc2/epicyon
Optionally block military tlds
parent
7c7b43a86a
commit
5c4ee4b96c
48
blocking.py
48
blocking.py
|
@ -1753,3 +1753,51 @@ def get_blocks_via_server(session, nickname: str, password: str,
|
|||
print('DEBUG: c2s GET blocked collection success')
|
||||
|
||||
return blocked_json
|
||||
|
||||
|
||||
def load_blocked_military(base_dir: str) -> {}:
|
||||
"""Loads a list of nicknames for accounts which block military instances
|
||||
"""
|
||||
block_military_filename = base_dir + '/accounts/block_military.txt'
|
||||
nicknames_list = []
|
||||
if os.path.isfile(block_military_filename):
|
||||
try:
|
||||
with open(block_military_filename, 'r',
|
||||
encoding='utf-8') as fp_mil:
|
||||
nicknames_list = fp_mil.read()
|
||||
except OSError:
|
||||
print('EX: error while reading block military 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
|
||||
"""
|
||||
nicknames_str = ''
|
||||
for nickname, _ in block_military.items():
|
||||
nicknames_str += nickname + '\n'
|
||||
|
||||
block_military_filename = base_dir + '/accounts/block_military.txt'
|
||||
try:
|
||||
with open(block_military_filename, 'w+',
|
||||
encoding='utf-8') as fp_mil:
|
||||
fp_mil.write(nicknames_str)
|
||||
except OSError:
|
||||
print('EX: error while saving block military file')
|
||||
|
||||
|
||||
def contains_military_domain(message_str: str) -> bool:
|
||||
"""Returns true if the given string contains a military domain
|
||||
"""
|
||||
mil_domains = ('army', 'navy', 'airforce')
|
||||
for tld in mil_domains:
|
||||
if '.' + tld + '"' in message_str or \
|
||||
'.' + tld + '/' in message_str:
|
||||
return True
|
||||
return False
|
||||
|
|
39
daemon.py
39
daemon.py
|
@ -154,6 +154,9 @@ from media import path_is_transcript
|
|||
from media import path_is_audio
|
||||
from cwlists import get_cw_list_variable
|
||||
from cwlists import load_cw_lists
|
||||
from blocking import contains_military_domain
|
||||
from blocking import load_blocked_military
|
||||
from blocking import save_blocked_military
|
||||
from blocking import blocked_timeline_json
|
||||
from blocking import import_blocking_file
|
||||
from blocking import export_blocking_file
|
||||
|
@ -7722,6 +7725,22 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'repliesFromMutualsOnly file ' +
|
||||
show_replies_mutuals_file)
|
||||
|
||||
# block military instances
|
||||
block_mil_instances = False
|
||||
if fields.get('blockMilitary'):
|
||||
if fields['blockMilitary'] == 'on':
|
||||
block_mil_instances = True
|
||||
if block_mil_instances:
|
||||
if not self.server.block_military.get(nickname):
|
||||
self.server.block_military[nickname] = True
|
||||
save_blocked_military(self.server.base_dir,
|
||||
self.server.block_military)
|
||||
else:
|
||||
if self.server.block_military.get(nickname):
|
||||
del self.server.block_military[nickname]
|
||||
save_blocked_military(self.server.base_dir,
|
||||
self.server.block_military)
|
||||
|
||||
# notify about new Likes
|
||||
if on_final_welcome_screen:
|
||||
# default setting from welcome screen
|
||||
|
@ -16741,7 +16760,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.min_images_for_accounts,
|
||||
self.server.max_recent_posts,
|
||||
self.server.reverse_sequence,
|
||||
self.server.buy_sites)
|
||||
self.server.buy_sites,
|
||||
self.server.block_military)
|
||||
if msg:
|
||||
msg = msg.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -23298,11 +23318,23 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.postreq_busy = False
|
||||
return
|
||||
|
||||
if contains_invalid_chars(message_bytes.decode("utf-8")):
|
||||
decoded_message_bytes = message_bytes.decode("utf-8")
|
||||
if contains_invalid_chars(decoded_message_bytes):
|
||||
self._400()
|
||||
self.server.postreq_busy = False
|
||||
return
|
||||
|
||||
if users_in_path:
|
||||
nickname = self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname = nickname.split('/')[0]
|
||||
if self.server.block_military.get(nickname):
|
||||
if contains_military_domain(decoded_message_bytes):
|
||||
self._400()
|
||||
print('BLOCK: military domain blocked')
|
||||
self.server.postreq_busy = False
|
||||
return
|
||||
|
||||
# convert the raw bytes to json
|
||||
message_json = json.loads(message_bytes)
|
||||
|
||||
|
@ -23623,6 +23655,9 @@ def run_daemon(max_hashtags: int,
|
|||
|
||||
httpd.starting_daemon = True
|
||||
|
||||
# load a list of nicknames for accounts blocking military instances
|
||||
httpd.block_military = load_blocked_military(base_dir)
|
||||
|
||||
# scan the theme directory for any svg files containing scripts
|
||||
assert not scan_themes_for_scripts(base_dir)
|
||||
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "سبب",
|
||||
"Chat": "محادثة",
|
||||
"Chat link": "رابط الدردشة",
|
||||
"Clear Cache": "مسح ذاكرة التخزين المؤقت"
|
||||
"Clear Cache": "مسح ذاكرة التخزين المؤقت",
|
||||
"Block military instances": "منع الحالات العسكرية"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "কারণ",
|
||||
"Chat": "চ্যাট",
|
||||
"Chat link": "চ্যাট লিঙ্ক",
|
||||
"Clear Cache": "ক্যাশে সাফ করুন"
|
||||
"Clear Cache": "ক্যাশে সাফ করুন",
|
||||
"Block military instances": "সামরিক দৃষ্টান্ত ব্লক করুন"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Raó",
|
||||
"Chat": "Xatejar",
|
||||
"Chat link": "Enllaç de xat",
|
||||
"Clear Cache": "Netejar memòria cau"
|
||||
"Clear Cache": "Netejar memòria cau",
|
||||
"Block military instances": "Bloquejar instàncies militars"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Rheswm",
|
||||
"Chat": "Sgwrsio",
|
||||
"Chat link": "Dolen sgwrs",
|
||||
"Clear Cache": "Clirio Cache"
|
||||
"Clear Cache": "Clirio Cache",
|
||||
"Block military instances": "Rhwystro achosion milwrol"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Grund",
|
||||
"Chat": "Plaudern",
|
||||
"Chat link": "Chat-Link",
|
||||
"Clear Cache": "Cache leeren"
|
||||
"Clear Cache": "Cache leeren",
|
||||
"Block military instances": "Militärische Instanzen blockieren"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Λόγος",
|
||||
"Chat": "Κουβέντα",
|
||||
"Chat link": "Σύνδεσμος συνομιλίας",
|
||||
"Clear Cache": "Εκκαθάριση προσωρινής μνήμης"
|
||||
"Clear Cache": "Εκκαθάριση προσωρινής μνήμης",
|
||||
"Block military instances": "Αποκλεισμός στρατιωτικών περιπτώσεων"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Reason",
|
||||
"Chat": "Chat",
|
||||
"Chat link": "Chat link",
|
||||
"Clear Cache": "Clear Cache"
|
||||
"Clear Cache": "Clear Cache",
|
||||
"Block military instances": "Block military instances"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Razón",
|
||||
"Chat": "Charlar",
|
||||
"Chat link": "Enlace de chat",
|
||||
"Clear Cache": "Limpiar cache"
|
||||
"Clear Cache": "Limpiar cache",
|
||||
"Block military instances": "Bloquear instancias militares"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "دلیل",
|
||||
"Chat": "چت کنید",
|
||||
"Chat link": "لینک چت",
|
||||
"Clear Cache": "پاک کردن حافظه پنهان"
|
||||
"Clear Cache": "پاک کردن حافظه پنهان",
|
||||
"Block military instances": "موارد نظامی را مسدود کنید"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Raison",
|
||||
"Chat": "Discuter",
|
||||
"Chat link": "Lien de discussion",
|
||||
"Clear Cache": "Vider le cache"
|
||||
"Clear Cache": "Vider le cache",
|
||||
"Block military instances": "Bloquer les instances militaires"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Cúis",
|
||||
"Chat": "Comhrá",
|
||||
"Chat link": "Nasc comhrá",
|
||||
"Clear Cache": "Glan Taisce"
|
||||
"Clear Cache": "Glan Taisce",
|
||||
"Block military instances": "Bloc cásanna míleata"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "कारण",
|
||||
"Chat": "बात करना",
|
||||
"Chat link": "चैट लिंक",
|
||||
"Clear Cache": "कैश को साफ़ करें"
|
||||
"Clear Cache": "कैश को साफ़ करें",
|
||||
"Block military instances": "सैन्य उदाहरणों को ब्लॉक करें"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Motivo",
|
||||
"Chat": "Chiacchierata",
|
||||
"Chat link": "Collegamento alla chat",
|
||||
"Clear Cache": "Cancella cache"
|
||||
"Clear Cache": "Cancella cache",
|
||||
"Block military instances": "Blocca istanze militari"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "理由",
|
||||
"Chat": "チャット",
|
||||
"Chat link": "チャットリンク",
|
||||
"Clear Cache": "キャッシュの消去"
|
||||
"Clear Cache": "キャッシュの消去",
|
||||
"Block military instances": "軍事インスタンスをブロックする"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "이유",
|
||||
"Chat": "채팅",
|
||||
"Chat link": "채팅 링크",
|
||||
"Clear Cache": "캐시 지우기"
|
||||
"Clear Cache": "캐시 지우기",
|
||||
"Block military instances": "군사 인스턴스 차단"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Semed",
|
||||
"Chat": "Galgalkirin",
|
||||
"Chat link": "Lînka chatê",
|
||||
"Clear Cache": "Cache paqij bike"
|
||||
"Clear Cache": "Cache paqij bike",
|
||||
"Block military instances": "Mînakên leşkerî asteng bikin"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Reden",
|
||||
"Chat": "Chatten",
|
||||
"Chat link": "Chat-link",
|
||||
"Clear Cache": "Cache wissen"
|
||||
"Clear Cache": "Cache wissen",
|
||||
"Block military instances": "Blokkeer militaire instanties"
|
||||
}
|
||||
|
|
|
@ -625,5 +625,6 @@
|
|||
"Reason": "Reason",
|
||||
"Chat": "Chat",
|
||||
"Chat link": "Chat link",
|
||||
"Clear Cache": "Clear Cache"
|
||||
"Clear Cache": "Clear Cache",
|
||||
"Block military instances": "Block military instances"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Powód",
|
||||
"Chat": "Czat",
|
||||
"Chat link": "Link do czatu",
|
||||
"Clear Cache": "Wyczyść pamięć podręczną"
|
||||
"Clear Cache": "Wyczyść pamięć podręczną",
|
||||
"Block military instances": "Blokuj instancje wojskowe"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Razão",
|
||||
"Chat": "Bater papo",
|
||||
"Chat link": "Link de bate-papo",
|
||||
"Clear Cache": "Limpar cache"
|
||||
"Clear Cache": "Limpar cache",
|
||||
"Block military instances": "Bloquear instâncias militares"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Причина",
|
||||
"Chat": "Чат",
|
||||
"Chat link": "Ссылка на чат",
|
||||
"Clear Cache": "Очистить кэш"
|
||||
"Clear Cache": "Очистить кэш",
|
||||
"Block military instances": "Блокировать военные инстансы"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Sababu",
|
||||
"Chat": "Soga",
|
||||
"Chat link": "Kiungo cha gumzo",
|
||||
"Clear Cache": "Futa Cache"
|
||||
"Clear Cache": "Futa Cache",
|
||||
"Block military instances": "Zuia matukio ya kijeshi"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Sebep",
|
||||
"Chat": "Sohbet",
|
||||
"Chat link": "Sohbet bağlantısı",
|
||||
"Clear Cache": "Önbelleği Temizle"
|
||||
"Clear Cache": "Önbelleği Temizle",
|
||||
"Block military instances": "Askeri örnekleri engelle"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "Причина",
|
||||
"Chat": "Чат",
|
||||
"Chat link": "Посилання на чат",
|
||||
"Clear Cache": "Очистити кеш"
|
||||
"Clear Cache": "Очистити кеш",
|
||||
"Block military instances": "Блокувати військові інстанції"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "סיבה",
|
||||
"Chat": "שמועסן",
|
||||
"Chat link": "שמועס לינק",
|
||||
"Clear Cache": "קלאָר קאַש"
|
||||
"Clear Cache": "קלאָר קאַש",
|
||||
"Block military instances": "פאַרשפּאַרן מיליטעריש ינסטאַנסיז"
|
||||
}
|
||||
|
|
|
@ -629,5 +629,6 @@
|
|||
"Reason": "原因",
|
||||
"Chat": "聊天",
|
||||
"Chat link": "聊天链接",
|
||||
"Clear Cache": "קלאָר קאַש"
|
||||
"Clear Cache": "קלאָר קאַש",
|
||||
"Block military instances": "阻止军事实例"
|
||||
}
|
||||
|
|
|
@ -2017,7 +2017,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
|
|||
crawlers_allowed: str,
|
||||
translate: {}, reply_interval_hours: int,
|
||||
cw_lists: {}, lists_enabled: str,
|
||||
buy_sites: {}) -> str:
|
||||
buy_sites: {}, block_military: {}) -> str:
|
||||
"""Filtering and blocking section of edit profile screen
|
||||
"""
|
||||
filter_str = ''
|
||||
|
@ -2232,6 +2232,15 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
|
|||
'buySitesStr', buy_domains_list_str,
|
||||
200, '', False)
|
||||
|
||||
idx = 'Block military instances'
|
||||
if translate.get(idx):
|
||||
name = translate[idx]
|
||||
block_mil = False
|
||||
if block_military.get(nickname):
|
||||
block_mil = block_military[nickname]
|
||||
edit_profile_form += \
|
||||
edit_check_box(idx, 'blockMilitary', block_mil)
|
||||
|
||||
cw_lists_str = ''
|
||||
for name, _ in cw_lists.items():
|
||||
variablename = get_cw_list_variable(name)
|
||||
|
@ -2692,7 +2701,8 @@ def html_edit_profile(server, translate: {},
|
|||
min_images_for_accounts: [],
|
||||
max_recent_posts: int,
|
||||
reverse_sequence: [],
|
||||
buy_sites: {}) -> str:
|
||||
buy_sites: {},
|
||||
block_military: {}) -> str:
|
||||
"""Shows the edit profile screen
|
||||
"""
|
||||
path = path.replace('/inbox', '').replace('/outbox', '')
|
||||
|
@ -2952,7 +2962,8 @@ def html_edit_profile(server, translate: {},
|
|||
_html_edit_profile_filtering(base_dir, nickname, domain,
|
||||
user_agents_blocked, crawlers_allowed,
|
||||
translate, reply_interval_hours,
|
||||
cw_lists, lists_enabled, buy_sites)
|
||||
cw_lists, lists_enabled, buy_sites,
|
||||
block_military)
|
||||
|
||||
# git projects section
|
||||
edit_profile_form += \
|
||||
|
|
Loading…
Reference in New Issue