diff --git a/blocking.py b/blocking.py index 6c6939b4e..2a3874b0f 100644 --- a/blocking.py +++ b/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 diff --git a/daemon.py b/daemon.py index 6312782e3..d957871c0 100644 --- a/daemon.py +++ b/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) diff --git a/translations/ar.json b/translations/ar.json index 0f8427599..d89597fc6 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -629,5 +629,6 @@ "Reason": "سبب", "Chat": "محادثة", "Chat link": "رابط الدردشة", - "Clear Cache": "مسح ذاكرة التخزين المؤقت" + "Clear Cache": "مسح ذاكرة التخزين المؤقت", + "Block military instances": "منع الحالات العسكرية" } diff --git a/translations/bn.json b/translations/bn.json index 6f3513051..e64ab4b74 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -629,5 +629,6 @@ "Reason": "কারণ", "Chat": "চ্যাট", "Chat link": "চ্যাট লিঙ্ক", - "Clear Cache": "ক্যাশে সাফ করুন" + "Clear Cache": "ক্যাশে সাফ করুন", + "Block military instances": "সামরিক দৃষ্টান্ত ব্লক করুন" } diff --git a/translations/ca.json b/translations/ca.json index cb420b6dc..be31293ec 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -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" } diff --git a/translations/cy.json b/translations/cy.json index afe2cbbdd..526e786a3 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -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" } diff --git a/translations/de.json b/translations/de.json index 2ca939939..80727088d 100644 --- a/translations/de.json +++ b/translations/de.json @@ -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" } diff --git a/translations/el.json b/translations/el.json index 8ef18b83f..3ed71e946 100644 --- a/translations/el.json +++ b/translations/el.json @@ -629,5 +629,6 @@ "Reason": "Λόγος", "Chat": "Κουβέντα", "Chat link": "Σύνδεσμος συνομιλίας", - "Clear Cache": "Εκκαθάριση προσωρινής μνήμης" + "Clear Cache": "Εκκαθάριση προσωρινής μνήμης", + "Block military instances": "Αποκλεισμός στρατιωτικών περιπτώσεων" } diff --git a/translations/en.json b/translations/en.json index 75e84219e..60d517c26 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" } diff --git a/translations/es.json b/translations/es.json index 119debf67..957571452 100644 --- a/translations/es.json +++ b/translations/es.json @@ -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" } diff --git a/translations/fa.json b/translations/fa.json index fadadafe9..33c7c3cd5 100644 --- a/translations/fa.json +++ b/translations/fa.json @@ -629,5 +629,6 @@ "Reason": "دلیل", "Chat": "چت کنید", "Chat link": "لینک چت", - "Clear Cache": "پاک کردن حافظه پنهان" + "Clear Cache": "پاک کردن حافظه پنهان", + "Block military instances": "موارد نظامی را مسدود کنید" } diff --git a/translations/fr.json b/translations/fr.json index 4c1f49d88..eb1fcadea 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -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" } diff --git a/translations/ga.json b/translations/ga.json index 76ab7e631..70211340e 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -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" } diff --git a/translations/hi.json b/translations/hi.json index 4291e428d..d27980b78 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -629,5 +629,6 @@ "Reason": "कारण", "Chat": "बात करना", "Chat link": "चैट लिंक", - "Clear Cache": "कैश को साफ़ करें" + "Clear Cache": "कैश को साफ़ करें", + "Block military instances": "सैन्य उदाहरणों को ब्लॉक करें" } diff --git a/translations/it.json b/translations/it.json index 686f6d644..6b77c683b 100644 --- a/translations/it.json +++ b/translations/it.json @@ -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" } diff --git a/translations/ja.json b/translations/ja.json index 1b1143d90..327355960 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -629,5 +629,6 @@ "Reason": "理由", "Chat": "チャット", "Chat link": "チャットリンク", - "Clear Cache": "キャッシュの消去" + "Clear Cache": "キャッシュの消去", + "Block military instances": "軍事インスタンスをブロックする" } diff --git a/translations/ko.json b/translations/ko.json index 201d2fbec..66a07e0a6 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -629,5 +629,6 @@ "Reason": "이유", "Chat": "채팅", "Chat link": "채팅 링크", - "Clear Cache": "캐시 지우기" + "Clear Cache": "캐시 지우기", + "Block military instances": "군사 인스턴스 차단" } diff --git a/translations/ku.json b/translations/ku.json index 7f4be96bc..0d971990b 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -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" } diff --git a/translations/nl.json b/translations/nl.json index b4f99cb82..36b2290c5 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -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" } diff --git a/translations/oc.json b/translations/oc.json index 11abdd4fa..9230f5ff9 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -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" } diff --git a/translations/pl.json b/translations/pl.json index bbc9bc372..633e8d05e 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -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" } diff --git a/translations/pt.json b/translations/pt.json index 2934c1f4f..19825a533 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -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" } diff --git a/translations/ru.json b/translations/ru.json index 712044946..84bdbee5f 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -629,5 +629,6 @@ "Reason": "Причина", "Chat": "Чат", "Chat link": "Ссылка на чат", - "Clear Cache": "Очистить кэш" + "Clear Cache": "Очистить кэш", + "Block military instances": "Блокировать военные инстансы" } diff --git a/translations/sw.json b/translations/sw.json index 7823e8c66..fa7ad0d7b 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -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" } diff --git a/translations/tr.json b/translations/tr.json index 4ec4d8d98..e85e7f44e 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -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" } diff --git a/translations/uk.json b/translations/uk.json index 8f7112b57..32e01af1f 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -629,5 +629,6 @@ "Reason": "Причина", "Chat": "Чат", "Chat link": "Посилання на чат", - "Clear Cache": "Очистити кеш" + "Clear Cache": "Очистити кеш", + "Block military instances": "Блокувати військові інстанції" } diff --git a/translations/yi.json b/translations/yi.json index b34c2243e..4296dda43 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -629,5 +629,6 @@ "Reason": "סיבה", "Chat": "שמועסן", "Chat link": "שמועס לינק", - "Clear Cache": "קלאָר קאַש" + "Clear Cache": "קלאָר קאַש", + "Block military instances": "פאַרשפּאַרן מיליטעריש ינסטאַנסיז" } diff --git a/translations/zh.json b/translations/zh.json index 72e7982ab..926591eac 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -629,5 +629,6 @@ "Reason": "原因", "Chat": "聊天", "Chat link": "聊天链接", - "Clear Cache": "קלאָר קאַש" + "Clear Cache": "קלאָר קאַש", + "Block military instances": "阻止军事实例" } diff --git a/webapp_profile.py b/webapp_profile.py index d6b1ff35a..e16a191a2 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -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 += \