diff --git a/blocking.py b/blocking.py
index 05f68dd93..3b254d086 100644
--- a/blocking.py
+++ b/blocking.py
@@ -1460,3 +1460,101 @@ def get_cw_list_variable(list_name: str) -> str:
"""Returns the variable associated with a CW list
"""
return 'list' + list_name.replace(' ', '').replace("'", '')
+
+
+def import_blocks(base_dir: str, nickname: str, domain: str,
+ filename: str) -> bool:
+ """Imports blocked domains for a given account
+ """
+ lines = []
+ try:
+ with open(filename, 'r', encoding='utf-8') as fp_blocks:
+ lines = fp_blocks.read().splitlines()
+ except OSError:
+ print('EX: unable to import blocked instances from file ' +
+ filename)
+ if not lines:
+ return False
+ if len(lines) < 2:
+ return False
+ if not lines[0].startswith('#domain,#') or \
+ 'comment' not in lines[0]:
+ return False
+ fieldnames = lines[0].split(',')
+ comment_field_index = 0
+ for field_str in fieldnames:
+ if 'comment' in field_str:
+ break
+ comment_field_index += 1
+ if comment_field_index >= len(fieldnames):
+ return False
+
+ account_directory = acct_dir(base_dir, nickname, domain)
+ blocking_filename = \
+ account_directory + '/blocking.txt'
+ blocking_reasons_filename = \
+ account_directory + '/blocking_reasons.txt'
+
+ existing_lines = []
+ if os.path.isfile(blocking_filename):
+ try:
+ with open(blocking_filename, 'r', encoding='utf-8') as fp_blocks:
+ existing_lines = fp_blocks.read().splitlines()
+ except OSError:
+ print('EX: ' +
+ 'unable to import existing blocked instances from file ' +
+ blocking_filename)
+ existing_reasons = []
+ if os.path.isfile(blocking_reasons_filename):
+ try:
+ with open(blocking_reasons_filename,
+ 'r', encoding='utf-8') as fp_blocks:
+ existing_reasons = fp_blocks.read().splitlines()
+ except OSError:
+ print('EX: ' +
+ 'unable to import existing ' +
+ 'blocked instance reasons from file ' +
+ blocking_reasons_filename)
+
+ append_blocks = []
+ append_reasons = []
+ for line_str in lines:
+ if line_str.startswith('#'):
+ continue
+ block_fields = line_str.split(',')
+ blocked_domain_name = block_fields[0].strip()
+ if ' ' in blocked_domain_name or \
+ '.' not in blocked_domain_name:
+ continue
+ if blocked_domain_name in existing_lines:
+ # already blocked
+ continue
+ append_blocks.append(blocked_domain_name)
+ blocked_comment = block_fields[comment_field_index].strip()
+ if blocked_comment:
+ if blocked_comment not in existing_reasons:
+ append_reasons.append(blocked_domain_name + ' ' +
+ blocked_comment)
+ if not append_blocks:
+ return True
+
+ try:
+ with open(blocking_filename, 'a+', encoding='utf-8') as fp_blocks:
+ for new_block in append_blocks:
+ fp_blocks.write(new_block + '\n')
+ except OSError:
+ print('EX: ' +
+ 'unable to append imported blocks to ' +
+ blocking_filename)
+
+ try:
+ with open(blocking_reasons_filename, 'a+',
+ encoding='utf-8') as fp_blocks:
+ for new_reason in append_reasons:
+ fp_blocks.write(new_reason + '\n')
+ except OSError:
+ print('EX: ' +
+ 'unable to append imported block reasons to ' +
+ blocking_reasons_filename)
+
+ return True
diff --git a/daemon.py b/daemon.py
index 28f715512..5f72edc44 100644
--- a/daemon.py
+++ b/daemon.py
@@ -147,6 +147,7 @@ from media import replace_twitter
from media import attach_media
from media import path_is_video
from media import path_is_audio
+from blocking import import_blocks
from blocking import add_account_blocks
from blocking import get_cw_list_variable
from blocking import load_cw_lists
@@ -6172,6 +6173,7 @@ class PubServer(BaseHTTPRequestHandler):
'instanceLogo',
'left_col_image', 'right_col_image',
'submitImportFollows',
+ 'submitImportBlocks',
'submitImportTheme'
)
profile_media_types_uploaded = {}
@@ -6220,6 +6222,10 @@ class PubServer(BaseHTTPRequestHandler):
filename_base = \
acct_dir(base_dir, nickname, domain) + \
'/import_following.csv'
+ elif m_type == 'submitImportBlocks':
+ filename_base = \
+ acct_dir(base_dir, nickname, domain) + \
+ '/import_blocks.csv'
else:
filename_base = \
acct_dir(base_dir, nickname, domain) + \
@@ -6244,6 +6250,25 @@ class PubServer(BaseHTTPRequestHandler):
nickname)
continue
+ if m_type == 'submitImportBlocks':
+ if os.path.isfile(filename_base):
+ blocks_import_succeeded = False
+ if import_blocks(base_dir, nickname, domain,
+ filename_base):
+ print(nickname + ' imported blocks csv')
+ blocks_import_succeeded = True
+ try:
+ os.remove(filename_base)
+ except OSError:
+ print('EX: ' +
+ 'unable to remove imported blocks file ' +
+ filename_base)
+ if blocks_import_succeeded:
+ continue
+ print('WARN: failed to import blocks from csv for ' +
+ nickname)
+ continue
+
if m_type == 'submitImportTheme':
if nickname == admin_nickname or \
is_artist(base_dir, nickname):
diff --git a/translations/ar.json b/translations/ar.json
index b81b52f08..4ebdfbdd9 100644
--- a/translations/ar.json
+++ b/translations/ar.json
@@ -617,5 +617,7 @@
"Buy link": "رابط شراء",
"Buy links are allowed from the following domains": "روابط الشراء مسموح بها من المجالات التالية",
"Media license": "رخصة وسائل الإعلام",
- "Media creator": "صانع الوسائط"
+ "Media creator": "صانع الوسائط",
+ "Import Blocks": "استيراد مثيلات محظورة",
+ "Export Blocks": "تصدير المثيلات المحظورة"
}
diff --git a/translations/bn.json b/translations/bn.json
index c5032d6cc..633265209 100644
--- a/translations/bn.json
+++ b/translations/bn.json
@@ -617,5 +617,7 @@
"Buy link": "সংযোগ কেনা",
"Buy links are allowed from the following domains": "নিম্নলিখিত ডোমেনগুলি থেকে লিঙ্কগুলি কেনার অনুমতি দেওয়া হয়েছে",
"Media license": "মিডিয়া লাইসেন্স",
- "Media creator": "মিডিয়া নির্মাতা"
+ "Media creator": "মিডিয়া নির্মাতা",
+ "Import Blocks": "অবরুদ্ধ দৃষ্টান্ত আমদানি করুন",
+ "Export Blocks": "অবরুদ্ধ দৃষ্টান্ত রপ্তানি করুন"
}
diff --git a/translations/ca.json b/translations/ca.json
index ad5ed9676..05ebf95ac 100644
--- a/translations/ca.json
+++ b/translations/ca.json
@@ -617,5 +617,7 @@
"Buy link": "Enllaç de compra",
"Buy links are allowed from the following domains": "Els enllaços de compra es permeten des dels dominis següents",
"Media license": "Llicència de mitjans",
- "Media creator": "Creador de mitjans"
+ "Media creator": "Creador de mitjans",
+ "Import Blocks": "Importa instàncies bloquejades",
+ "Export Blocks": "Exporta instàncies bloquejades"
}
diff --git a/translations/cy.json b/translations/cy.json
index 8446a0fc9..a9fa19e6a 100644
--- a/translations/cy.json
+++ b/translations/cy.json
@@ -617,5 +617,7 @@
"Buy link": "Prynu dolen",
"Buy links are allowed from the following domains": "Caniateir dolenni prynu o'r parthau canlynol",
"Media license": "Trwydded cyfryngau",
- "Media creator": "Crëwr cyfryngau"
+ "Media creator": "Crëwr cyfryngau",
+ "Import Blocks": "Mewnforio Achosion wedi'u Rhwystro",
+ "Export Blocks": "Allforio Achosion wedi'u Rhwystro"
}
diff --git a/translations/de.json b/translations/de.json
index e8c010de1..17659190a 100644
--- a/translations/de.json
+++ b/translations/de.json
@@ -617,5 +617,7 @@
"Buy link": "Link kaufen",
"Buy links are allowed from the following domains": "Kauflinks sind von den folgenden Domains erlaubt",
"Media license": "Medienlizenz",
- "Media creator": "Mediengestalter"
+ "Media creator": "Mediengestalter",
+ "Import Blocks": "Blockierte Instanzen importieren",
+ "Export Blocks": "Blockierte Instanzen exportieren"
}
diff --git a/translations/el.json b/translations/el.json
index af95a1f9a..e50e8fa51 100644
--- a/translations/el.json
+++ b/translations/el.json
@@ -617,5 +617,7 @@
"Buy link": "Σύνδεσμος αγοράς",
"Buy links are allowed from the following domains": "Οι σύνδεσμοι αγοράς επιτρέπονται από τους παρακάτω τομείς",
"Media license": "Άδεια ΜΜΕ",
- "Media creator": "Δημιουργός πολυμέσων"
+ "Media creator": "Δημιουργός πολυμέσων",
+ "Import Blocks": "Εισαγωγή αποκλεισμένων παρουσιών",
+ "Export Blocks": "Εξαγωγή αποκλεισμένων παρουσιών"
}
diff --git a/translations/en.json b/translations/en.json
index 278db6e9f..dca7d64b7 100644
--- a/translations/en.json
+++ b/translations/en.json
@@ -617,5 +617,7 @@
"Buy link": "Buy link",
"Buy links are allowed from the following domains": "Buy links are allowed from the following domains",
"Media license": "Media license",
- "Media creator": "Media creator"
+ "Media creator": "Media creator",
+ "Import Blocks": "Import Blocks",
+ "Export Blocks": "Export Blocks"
}
diff --git a/translations/es.json b/translations/es.json
index 6e8a14a62..b30c32413 100644
--- a/translations/es.json
+++ b/translations/es.json
@@ -617,5 +617,7 @@
"Buy link": "Enlace de compra",
"Buy links are allowed from the following domains": "Se permiten enlaces de compra de los siguientes dominios",
"Media license": "Licencia de medios",
- "Media creator": "Creadora de medios"
+ "Media creator": "Creadora de medios",
+ "Import Blocks": "Importar instancias bloqueadas",
+ "Export Blocks": "Exportar instancias bloqueadas"
}
diff --git a/translations/fa.json b/translations/fa.json
index f4895eb61..25f0fe70c 100644
--- a/translations/fa.json
+++ b/translations/fa.json
@@ -617,5 +617,7 @@
"Buy link": "لینک خرید",
"Buy links are allowed from the following domains": "لینک خرید از دامنه های زیر مجاز است",
"Media license": "مجوز رسانه",
- "Media creator": "سازنده رسانه"
+ "Media creator": "سازنده رسانه",
+ "Import Blocks": "وارد کردن موارد مسدود شده",
+ "Export Blocks": "نمونه های مسدود شده را صادر کنید"
}
diff --git a/translations/fr.json b/translations/fr.json
index 4f84280c8..7b3d2bf19 100644
--- a/translations/fr.json
+++ b/translations/fr.json
@@ -617,5 +617,7 @@
"Buy link": "Acheter un lien",
"Buy links are allowed from the following domains": "Les liens d'achat sont autorisés à partir des domaines suivants",
"Media license": "Licence média",
- "Media creator": "Créateur de médias"
+ "Media creator": "Créateur de médias",
+ "Import Blocks": "Importer des instances bloquées",
+ "Export Blocks": "Exporter les instances bloquées"
}
diff --git a/translations/ga.json b/translations/ga.json
index 0e7e7d460..c5383252f 100644
--- a/translations/ga.json
+++ b/translations/ga.json
@@ -617,5 +617,7 @@
"Buy link": "Ceannaigh nasc",
"Buy links are allowed from the following domains": "Ceadaítear naisc cheannaigh ó na fearainn seo a leanas",
"Media license": "Ceadúnas meáin",
- "Media creator": "Cruthaitheoir meáin"
+ "Media creator": "Cruthaitheoir meáin",
+ "Import Blocks": "Iompórtáil Cásanna Blocáilte",
+ "Export Blocks": "Easpórtáil Cásanna Blocáilte"
}
diff --git a/translations/hi.json b/translations/hi.json
index 5b2992dcc..3c8fc236a 100644
--- a/translations/hi.json
+++ b/translations/hi.json
@@ -617,5 +617,7 @@
"Buy link": "लिंक खरीदें",
"Buy links are allowed from the following domains": "निम्नलिखित डोमेन से खरीदें लिंक की अनुमति है",
"Media license": "मीडिया लाइसेंस",
- "Media creator": "मीडिया निर्माता"
+ "Media creator": "मीडिया निर्माता",
+ "Import Blocks": "अवरोधित उदाहरण आयात करें",
+ "Export Blocks": "निर्यात अवरुद्ध उदाहरण"
}
diff --git a/translations/it.json b/translations/it.json
index ab986d350..a0ddb6430 100644
--- a/translations/it.json
+++ b/translations/it.json
@@ -617,5 +617,7 @@
"Buy link": "Link per l'acquisto",
"Buy links are allowed from the following domains": "I link di acquisto sono consentiti dai seguenti domini",
"Media license": "Licenza multimediale",
- "Media creator": "Creatore multimediale"
+ "Media creator": "Creatore multimediale",
+ "Import Blocks": "Importa istanze bloccate",
+ "Export Blocks": "Esporta istanze bloccate"
}
diff --git a/translations/ja.json b/translations/ja.json
index 0c2cb9a78..3d530171e 100644
--- a/translations/ja.json
+++ b/translations/ja.json
@@ -617,5 +617,7 @@
"Buy link": "購入リンク",
"Buy links are allowed from the following domains": "次のドメインからの購入リンクが許可されています",
"Media license": "メディアライセンス",
- "Media creator": "メディアクリエーター"
+ "Media creator": "メディアクリエーター",
+ "Import Blocks": "ブロックされたインスタンスのインポート",
+ "Export Blocks": "ブロックされたインスタンスのエクスポート"
}
diff --git a/translations/ko.json b/translations/ko.json
index dc6d6f577..416e33d76 100644
--- a/translations/ko.json
+++ b/translations/ko.json
@@ -617,5 +617,7 @@
"Buy link": "구매 링크",
"Buy links are allowed from the following domains": "다음 도메인에서 구매 링크가 허용됩니다.",
"Media license": "미디어 라이센스",
- "Media creator": "미디어 크리에이터"
+ "Media creator": "미디어 크리에이터",
+ "Import Blocks": "차단된 인스턴스 가져오기",
+ "Export Blocks": "차단된 인스턴스 내보내기"
}
diff --git a/translations/ku.json b/translations/ku.json
index 385541118..e739010a4 100644
--- a/translations/ku.json
+++ b/translations/ku.json
@@ -617,5 +617,7 @@
"Buy link": "Girêdanê bikirin",
"Buy links are allowed from the following domains": "Zencîreyên kirînê ji domên jêrîn têne destûr kirin",
"Media license": "Lîsansa medyayê",
- "Media creator": "Afirînerê medyayê"
+ "Media creator": "Afirînerê medyayê",
+ "Import Blocks": "Mînakên Astengkirî Import",
+ "Export Blocks": "Mînakên Astengkirî Export"
}
diff --git a/translations/nl.json b/translations/nl.json
index 7c53151d7..98ac9c26f 100644
--- a/translations/nl.json
+++ b/translations/nl.json
@@ -617,5 +617,7 @@
"Buy link": "koop link",
"Buy links are allowed from the following domains": "Kooplinks zijn toegestaan vanaf de volgende domeinen",
"Media license": "Media licentie",
- "Media creator": "Media-maker"
+ "Media creator": "Media-maker",
+ "Import Blocks": "Importeer geblokkeerde instanties",
+ "Export Blocks": "Exporteer geblokkeerde instanties"
}
diff --git a/translations/oc.json b/translations/oc.json
index 45e2bb7de..922848b71 100644
--- a/translations/oc.json
+++ b/translations/oc.json
@@ -613,5 +613,7 @@
"Buy link": "Buy link",
"Buy links are allowed from the following domains": "Buy links are allowed from the following domains",
"Media license": "Media license",
- "Media creator": "Media creator"
+ "Media creator": "Media creator",
+ "Import Blocks": "Import Blocks",
+ "Export Blocks": "Export Blocks"
}
diff --git a/translations/pl.json b/translations/pl.json
index 3858f49fa..866dc0f2f 100644
--- a/translations/pl.json
+++ b/translations/pl.json
@@ -617,5 +617,7 @@
"Buy link": "Kup Link",
"Buy links are allowed from the following domains": "Kupuj linki są dozwolone z następujących domen",
"Media license": "Licencja medialna",
- "Media creator": "Kreator mediów"
+ "Media creator": "Kreator mediów",
+ "Import Blocks": "Importuj zablokowane instancje",
+ "Export Blocks": "Eksportuj zablokowane instancje"
}
diff --git a/translations/pt.json b/translations/pt.json
index 6c11a0d59..1b6c9c7dd 100644
--- a/translations/pt.json
+++ b/translations/pt.json
@@ -617,5 +617,7 @@
"Buy link": "Link de compra",
"Buy links are allowed from the following domains": "Links de compra são permitidos nos seguintes domínios",
"Media license": "Licença de mídia",
- "Media creator": "Criador de mídia"
+ "Media creator": "Criador de mídia",
+ "Import Blocks": "Importar instâncias bloqueadas",
+ "Export Blocks": "Exportar instâncias bloqueadas"
}
diff --git a/translations/ru.json b/translations/ru.json
index f859e1d58..4679f935c 100644
--- a/translations/ru.json
+++ b/translations/ru.json
@@ -617,5 +617,7 @@
"Buy link": "Купить ссылку",
"Buy links are allowed from the following domains": "Ссылки на покупку разрешены со следующих доменов",
"Media license": "Медиа лицензия",
- "Media creator": "Создатель медиа"
+ "Media creator": "Создатель медиа",
+ "Import Blocks": "Импорт заблокированных экземпляров",
+ "Export Blocks": "Экспорт заблокированных экземпляров"
}
diff --git a/translations/sw.json b/translations/sw.json
index f4f04873f..9a1bad0f3 100644
--- a/translations/sw.json
+++ b/translations/sw.json
@@ -617,5 +617,7 @@
"Buy link": "Nunua kiungo",
"Buy links are allowed from the following domains": "Viungo vya kununua vinaruhusiwa kutoka kwa vikoa vifuatavyo",
"Media license": "Leseni ya media",
- "Media creator": "Muundaji wa media"
+ "Media creator": "Muundaji wa media",
+ "Import Blocks": "Ingiza Matukio Yaliyozuiwa",
+ "Export Blocks": "Hamisha Matukio Yaliyozuiwa"
}
diff --git a/translations/tr.json b/translations/tr.json
index b6a480bde..a6e84aab7 100644
--- a/translations/tr.json
+++ b/translations/tr.json
@@ -617,5 +617,7 @@
"Buy link": "Bağlantı satın al",
"Buy links are allowed from the following domains": "Aşağıdaki alanlardan satın alma bağlantılarına izin verilir",
"Media license": "Medya lisansı",
- "Media creator": "Medya yaratıcısı"
+ "Media creator": "Medya yaratıcısı",
+ "Import Blocks": "Engellenen Örnekleri İçe Aktar",
+ "Export Blocks": "Engellenen Örnekleri Dışa Aktar"
}
diff --git a/translations/uk.json b/translations/uk.json
index bbecd07ac..42f0d4ae6 100644
--- a/translations/uk.json
+++ b/translations/uk.json
@@ -617,5 +617,7 @@
"Buy link": "Купити посилання",
"Buy links are allowed from the following domains": "Посилання на купівлю дозволено з таких доменів",
"Media license": "Медіа ліцензія",
- "Media creator": "Творець медіа"
+ "Media creator": "Творець медіа",
+ "Import Blocks": "Імпортувати заблоковані екземпляри",
+ "Export Blocks": "Експортувати заблоковані екземпляри"
}
diff --git a/translations/yi.json b/translations/yi.json
index acf8981ba..b1214f9b1 100644
--- a/translations/yi.json
+++ b/translations/yi.json
@@ -617,5 +617,7 @@
"Buy link": "קויפן לינק",
"Buy links are allowed from the following domains": "קויפן פֿאַרבינדונגען זענען ערלויבט פֿון די פאלגענדע דאָומיינז",
"Media license": "מעדיע דערלויבעניש",
- "Media creator": "מעדיע באשעפער"
+ "Media creator": "מעדיע באשעפער",
+ "Import Blocks": "ימפּאָרט בלאַקט ינסטאַנסיז",
+ "Export Blocks": "עקספּאָרט בלאַקט ינסטאַנסיז"
}
diff --git a/translations/zh.json b/translations/zh.json
index 9a88921a4..df2228367 100644
--- a/translations/zh.json
+++ b/translations/zh.json
@@ -617,5 +617,7 @@
"Buy link": "购买链接",
"Buy links are allowed from the following domains": "允许来自以下域的购买链接",
"Media license": "媒体许可证",
- "Media creator": "媒体创作者"
+ "Media creator": "媒体创作者",
+ "Import Blocks": "导入被阻止的实例",
+ "Export Blocks": "导出被阻止的实例"
}
diff --git a/webapp_profile.py b/webapp_profile.py
index aee6c8bb3..9d85fdc41 100644
--- a/webapp_profile.py
+++ b/webapp_profile.py
@@ -92,6 +92,7 @@ from roles import is_devops
from session import site_is_verified
THEME_FORMATS = '.zip, .gz'
+BLOCKFILE_FORMATS = '.csv'
def _valid_profile_preview_post(post_json_object: {},
@@ -2043,6 +2044,20 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
edit_text_area(translate['Blocked accounts'], None, 'blocked',
blocked_str, 200, '', False)
+ # import and export blocks
+ edit_profile_form += \
+ ' \n'
+ edit_profile_form += ' \n'
+ edit_profile_form += \
+ '
\n'
+ edit_profile_form += \
+ '
\n'
+
idx = 'Direct messages are always allowed from these instances.'
edit_profile_form += \
edit_text_area(translate['Direct Message permitted instances'], None,