Button on moderator screen to clear actor cache

main
Bob Mottram 2023-07-11 10:25:43 +01:00
parent 5160005509
commit 1825b058a8
29 changed files with 91 additions and 26 deletions

View File

@ -32,6 +32,31 @@ def _remove_person_from_cache(base_dir: str, person_url: str,
del person_cache[person_url]
def clear_actor_cache(base_dir: str, person_cache: {},
clear_domain: str) -> None:
"""Clears the actor cache for the given domain
This is useful if you know that a given instance has rotated their
signing keys after a security incident
"""
if not clear_domain:
return
if '.' not in clear_domain:
return
actor_cache_dir = base_dir + '/cache/actors'
for subdir, _, files in os.walk(actor_cache_dir):
for fname in files:
filename = os.path.join(subdir, fname)
if not filename.endswith('.json'):
continue
if clear_domain not in fname:
continue
person_url = fname.replace('#', '/').replace('.json', '')
_remove_person_from_cache(base_dir, person_url,
person_cache)
break
def check_for_changed_actor(session, base_dir: str,
http_prefix: str, domain_full: str,
person_url: str, avatar_url: str, person_cache: {},

View File

@ -378,6 +378,7 @@ from content import add_html_tags
from content import extract_media_in_form_post
from content import save_media_in_form_post
from content import extract_text_fields_in_post
from cache import clear_actor_cache
from cache import get_actor_public_key_from_id
from cache import check_for_changed_actor
from cache import store_person_in_cache
@ -2697,6 +2698,8 @@ class PubServer(BaseHTTPRequestHandler):
moderation_button = 'filter'
elif moderation_str.startswith('submitUnfilter'):
moderation_button = 'unfilter'
elif moderation_str.startswith('submitClearCache'):
moderation_button = 'clearcache'
elif moderation_str.startswith('submitSuspend'):
moderation_button = 'suspend'
elif moderation_str.startswith('submitUnsuspend'):
@ -2723,6 +2726,10 @@ class PubServer(BaseHTTPRequestHandler):
add_global_filter(base_dir, moderation_text)
if moderation_button == 'unfilter':
remove_global_filter(base_dir, moderation_text)
if moderation_button == 'clearcache':
clear_actor_cache(base_dir,
self.server.person_cache,
moderation_text)
if moderation_button == 'block':
full_block_domain = None
moderation_text = moderation_text.strip()

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "السماح فقط بالردود من المتبادلين",
"Reason": "سبب",
"Chat": "محادثة",
"Chat link": "رابط الدردشة"
"Chat link": "رابط الدردشة",
"Clear Cache": "مسح ذاكرة التخزين المؤقت"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "শুধুমাত্র মিউচুয়াল থেকে উত্তরের অনুমতি দিন",
"Reason": "কারণ",
"Chat": "চ্যাট",
"Chat link": "চ্যাট লিঙ্ক"
"Chat link": "চ্যাট লিঙ্ক",
"Clear Cache": "ক্যাশে সাফ করুন"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Només permet respostes de mútues",
"Reason": "Raó",
"Chat": "Xatejar",
"Chat link": "Enllaç de xat"
"Chat link": "Enllaç de xat",
"Clear Cache": "Netejar memòria cau"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Caniatewch atebion gan gwmnïau cydfuddiannol yn unig",
"Reason": "Rheswm",
"Chat": "Sgwrsio",
"Chat link": "Dolen sgwrs"
"Chat link": "Dolen sgwrs",
"Clear Cache": "Clirio Cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Erlauben Sie nur Antworten von Gegenseitigkeitsgesellschaften",
"Reason": "Grund",
"Chat": "Plaudern",
"Chat link": "Chat-Link"
"Chat link": "Chat-Link",
"Clear Cache": "Cache leeren"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Επιτρέπονται μόνο απαντήσεις από αμοιβαία μέλη",
"Reason": "Λόγος",
"Chat": "Κουβέντα",
"Chat link": "Σύνδεσμος συνομιλίας"
"Chat link": "Σύνδεσμος συνομιλίας",
"Clear Cache": "Εκκαθάριση προσωρινής μνήμης"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Only allow replies from mutuals",
"Reason": "Reason",
"Chat": "Chat",
"Chat link": "Chat link"
"Chat link": "Chat link",
"Clear Cache": "Clear Cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Permitir solo respuestas de mutuas",
"Reason": "Razón",
"Chat": "Charlar",
"Chat link": "Enlace de chat"
"Chat link": "Enlace de chat",
"Clear Cache": "Limpiar cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "فقط اجازه پاسخ از طرف متقابل را بدهید",
"Reason": "دلیل",
"Chat": "چت کنید",
"Chat link": "لینک چت"
"Chat link": "لینک چت",
"Clear Cache": "پاک کردن حافظه پنهان"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Autoriser uniquement les réponses des mutuelles",
"Reason": "Raison",
"Chat": "Discuter",
"Chat link": "Lien de discussion"
"Chat link": "Lien de discussion",
"Clear Cache": "Vider le cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Ná ceadaigh ach freagraí ó chomhlachtaí frithpháirteacha",
"Reason": "Cúis",
"Chat": "Comhrá",
"Chat link": "Nasc comhrá"
"Chat link": "Nasc comhrá",
"Clear Cache": "Glan Taisce"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "केवल पारस्परिक उत्तरों की अनुमति दें",
"Reason": "कारण",
"Chat": "बात करना",
"Chat link": "चैट लिंक"
"Chat link": "चैट लिंक",
"Clear Cache": "कैश को साफ़ करें"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Consenti solo risposte da mutue",
"Reason": "Motivo",
"Chat": "Chiacchierata",
"Chat link": "Collegamento alla chat"
"Chat link": "Collegamento alla chat",
"Clear Cache": "Cancella cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "相互からの返信のみを許可する",
"Reason": "理由",
"Chat": "チャット",
"Chat link": "チャットリンク"
"Chat link": "チャットリンク",
"Clear Cache": "キャッシュの消去"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "상호 간의 답장만 허용",
"Reason": "이유",
"Chat": "채팅",
"Chat link": "채팅 링크"
"Chat link": "채팅 링크",
"Clear Cache": "캐시 지우기"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Tenê destûr bidin bersivên ji hevdu",
"Reason": "Semed",
"Chat": "Galgalkirin",
"Chat link": "Lînka chatê"
"Chat link": "Lînka chatê",
"Clear Cache": "Cache paqij bike"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Sta alleen reacties van onderlinge maatschappijen toe",
"Reason": "Reden",
"Chat": "Chatten",
"Chat link": "Chat-link"
"Chat link": "Chat-link",
"Clear Cache": "Cache wissen"
}

View File

@ -624,5 +624,6 @@
"Only allow replies from mutuals": "Only allow replies from mutuals",
"Reason": "Reason",
"Chat": "Chat",
"Chat link": "Chat link"
"Chat link": "Chat link",
"Clear Cache": "Clear Cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Zezwalaj tylko na odpowiedzi od towarzystw wzajemnych",
"Reason": "Powód",
"Chat": "Czat",
"Chat link": "Link do czatu"
"Chat link": "Link do czatu",
"Clear Cache": "Wyczyść pamięć podręczną"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Permitir apenas respostas de mútuos",
"Reason": "Razão",
"Chat": "Bater papo",
"Chat link": "Link de bate-papo"
"Chat link": "Link de bate-papo",
"Clear Cache": "Limpar cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Разрешить ответы только от взаимных",
"Reason": "Причина",
"Chat": "Чат",
"Chat link": "Ссылка на чат"
"Chat link": "Ссылка на чат",
"Clear Cache": "Очистить кэш"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Ruhusu tu majibu kutoka kwa pande zote mbili",
"Reason": "Sababu",
"Chat": "Soga",
"Chat link": "Kiungo cha gumzo"
"Chat link": "Kiungo cha gumzo",
"Clear Cache": "Futa Cache"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Yalnızca ortaklardan gelen yanıtlara izin ver",
"Reason": "Sebep",
"Chat": "Sohbet",
"Chat link": "Sohbet bağlantısı"
"Chat link": "Sohbet bağlantısı",
"Clear Cache": "Önbelleği Temizle"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "Дозволити відповіді лише від взаємних клієнтів",
"Reason": "Причина",
"Chat": "Чат",
"Chat link": "Посилання на чат"
"Chat link": "Посилання на чат",
"Clear Cache": "Очистити кеш"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "לאָזן בלויז ענטפֿערס פון מיוטשואַלז",
"Reason": "סיבה",
"Chat": "שמועסן",
"Chat link": "שמועס לינק"
"Chat link": "שמועס לינק",
"Clear Cache": "קלאָר קאַש"
}

View File

@ -628,5 +628,6 @@
"Only allow replies from mutuals": "只允许来自相互的回复",
"Reason": "原因",
"Chat": "聊天",
"Chat link": "聊天链接"
"Chat link": "聊天链接",
"Clear Cache": "קלאָר קאַש"
}

View File

@ -294,6 +294,13 @@ def _html_timeline_moderation_buttons(moderator: bool, box_name: str,
'alt="' + \
translate['Unfilter words'] + ' | " ' + \
'name="submitUnfilter" value="' + translate['Unfilter'] + '">\n'
tl_str += \
' <input type="submit" title="' + \
translate['Clear Cache'] + '" ' + \
'alt="' + \
translate['Clear Cache'] + ' | " ' + \
'name="submitClearCache" value="' + \
translate['Clear Cache'] + '">\n'
tl_str += '</div>\n</form>\n'
return tl_str