From 91a083ea34cddab1c085c1971879acb654e1b2ac Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 26 Jun 2022 23:10:23 +0100 Subject: [PATCH] Edit ActivityPub specification --- daemon.py | 54 ++++++++++++++ .../activitypub.md | 0 .../tutorial-1.png | Bin .../tutorial-2.png | Bin .../tutorial-3.png | Bin .../tutorial-4.png | Bin .../tutorial-5.png | Bin translations/ar.json | 3 +- translations/bn.json | 3 +- translations/ca.json | 3 +- translations/cy.json | 3 +- translations/de.json | 3 +- translations/el.json | 3 +- translations/en.json | 3 +- translations/es.json | 3 +- translations/fr.json | 3 +- translations/ga.json | 3 +- translations/hi.json | 3 +- translations/it.json | 3 +- translations/ja.json | 3 +- translations/ko.json | 3 +- translations/ku.json | 3 +- translations/nl.json | 3 +- translations/oc.json | 3 +- translations/pl.json | 3 +- translations/pt.json | 3 +- translations/ru.json | 3 +- translations/sw.json | 3 +- translations/tr.json | 3 +- translations/uk.json | 3 +- translations/yi.json | 3 +- translations/zh.json | 3 +- webapp_column_left.py | 22 +++++- webapp_specification.py | 67 ++++++++++++++++++ 34 files changed, 192 insertions(+), 26 deletions(-) rename {specifications => specification}/activitypub.md (100%) rename {specifications => specification}/tutorial-1.png (100%) rename {specifications => specification}/tutorial-2.png (100%) rename {specifications => specification}/tutorial-3.png (100%) rename {specifications => specification}/tutorial-4.png (100%) rename {specifications => specification}/tutorial-5.png (100%) create mode 100644 webapp_specification.py diff --git a/daemon.py b/daemon.py index 3cbe6d185..d07691d3c 100644 --- a/daemon.py +++ b/daemon.py @@ -174,6 +174,7 @@ from webapp_utils import get_pwa_theme_colors from webapp_calendar import html_calendar_delete_confirm from webapp_calendar import html_calendar from webapp_about import html_about +from webapp_specification import html_specification from webapp_accesskeys import html_access_keys from webapp_accesskeys import load_access_keys_for_accounts from webapp_confirm import html_confirm_delete @@ -4782,6 +4783,7 @@ class PubServer(BaseHTTPRequestHandler): links_filename = base_dir + '/accounts/links.txt' about_filename = base_dir + '/accounts/about.md' tos_filename = base_dir + '/accounts/tos.md' + specification_filename = base_dir + '/accounts/activitypub.md' # extract all of the text fields into a dict fields = \ @@ -4860,6 +4862,25 @@ class PubServer(BaseHTTPRequestHandler): print('EX: _links_update unable to delete ' + tos_filename) + if fields.get('editedSpecification'): + specification_str = fields['editedSpecification'] + if not dangerous_markup(specification_str, + allow_local_network_access): + try: + with open(specification_filename, 'w+', + encoding='utf-8') as specificationfile: + specificationfile.write(specification_str) + except OSError: + print('EX: unable to write specification ' + + specification_filename) + else: + if os.path.isfile(specification_filename): + try: + os.remove(specification_filename) + except OSError: + print('EX: _links_update unable to delete ' + + specification_filename) + # redirect back to the default timeline self._redirect_headers(actor_str + '/' + default_timeline, cookie, calling_domain) @@ -16274,6 +16295,39 @@ class PubServer(BaseHTTPRequestHandler): self.server.debug) return + if self.path in ('/specification', '/protocol', '/activitypub'): + if calling_domain.endswith('.onion'): + msg = \ + html_specification(self.server.css_cache, + self.server.base_dir, 'http', + self.server.onion_domain, + None, self.server.translate, + self.server.system_language) + elif calling_domain.endswith('.i2p'): + msg = \ + html_specification(self.server.css_cache, + self.server.base_dir, 'http', + self.server.i2p_domain, + None, self.server.translate, + self.server.system_language) + else: + msg = \ + html_specification(self.server.css_cache, + self.server.base_dir, + self.server.http_prefix, + self.server.domain_full, + self.server.onion_domain, + self.server.translate, + self.server.system_language) + msg = msg.encode('utf-8') + msglen = len(msg) + self._login_headers('text/html', msglen, calling_domain) + self._write(msg) + fitness_performance(getreq_start_time, self.server.fitness, + '_GET', 'show specification screen', + self.server.debug) + return + if html_getreq and users_in_path and authorized and \ self.path.endswith('/accesskeys'): nickname = self.path.split('/users/')[1] diff --git a/specifications/activitypub.md b/specification/activitypub.md similarity index 100% rename from specifications/activitypub.md rename to specification/activitypub.md diff --git a/specifications/tutorial-1.png b/specification/tutorial-1.png similarity index 100% rename from specifications/tutorial-1.png rename to specification/tutorial-1.png diff --git a/specifications/tutorial-2.png b/specification/tutorial-2.png similarity index 100% rename from specifications/tutorial-2.png rename to specification/tutorial-2.png diff --git a/specifications/tutorial-3.png b/specification/tutorial-3.png similarity index 100% rename from specifications/tutorial-3.png rename to specification/tutorial-3.png diff --git a/specifications/tutorial-4.png b/specification/tutorial-4.png similarity index 100% rename from specifications/tutorial-4.png rename to specification/tutorial-4.png diff --git a/specifications/tutorial-5.png b/specification/tutorial-5.png similarity index 100% rename from specifications/tutorial-5.png rename to specification/tutorial-5.png diff --git a/translations/ar.json b/translations/ar.json index 2627fa355..5340cc17b 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -564,5 +564,6 @@ "Save": "يحفظ", "Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال", "Minimize attached images": "تصغير الصور المرفقة", - "SHOW MEDIA": "عرض الوسائط" + "SHOW MEDIA": "عرض الوسائط", + "ActivityPub Specification": "مواصفات ActivityPub" } diff --git a/translations/bn.json b/translations/bn.json index f572a1d96..553d29482 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -564,5 +564,6 @@ "Save": "সংরক্ষণ", "Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন", "Minimize attached images": "সংযুক্ত ছবি ছোট করুন", - "SHOW MEDIA": "মিডিয়া দেখান" + "SHOW MEDIA": "মিডিয়া দেখান", + "ActivityPub Specification": "ActivityPub স্পেসিফিকেশন" } diff --git a/translations/ca.json b/translations/ca.json index eddad3773..67933223f 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -564,5 +564,6 @@ "Save": "Desa", "Switch to moderation view": "Canvia a la visualització de moderació", "Minimize attached images": "Minimitzar les imatges adjuntes", - "SHOW MEDIA": "MOSTRA ELS MITJANS" + "SHOW MEDIA": "MOSTRA ELS MITJANS", + "ActivityPub Specification": "Especificació d'ActivityPub" } diff --git a/translations/cy.json b/translations/cy.json index d35db8933..7247eee33 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -564,5 +564,6 @@ "Save": "Arbed", "Switch to moderation view": "Newid i wedd safoni", "Minimize attached images": "Lleihau delweddau sydd ynghlwm", - "SHOW MEDIA": "DANGOS CYFRYNGAU" + "SHOW MEDIA": "DANGOS CYFRYNGAU", + "ActivityPub Specification": "Manyleb GweithgareddPub" } diff --git a/translations/de.json b/translations/de.json index 2e92b79fd..f19a7411d 100644 --- a/translations/de.json +++ b/translations/de.json @@ -564,5 +564,6 @@ "Save": "Speichern", "Switch to moderation view": "Wechseln Sie zur Moderationsansicht", "Minimize attached images": "Angehängte Bilder minimieren", - "SHOW MEDIA": "MEDIEN ZEIGEN" + "SHOW MEDIA": "MEDIEN ZEIGEN", + "ActivityPub Specification": "ActivityPub-Spezifikation" } diff --git a/translations/el.json b/translations/el.json index fc46705aa..ea496a1fc 100644 --- a/translations/el.json +++ b/translations/el.json @@ -564,5 +564,6 @@ "Save": "Αποθηκεύσετε", "Switch to moderation view": "Μετάβαση σε προβολή εποπτείας", "Minimize attached images": "Ελαχιστοποιήστε τις συνημμένες εικόνες", - "SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ" + "SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ", + "ActivityPub Specification": "Προδιαγραφές ActivityPub" } diff --git a/translations/en.json b/translations/en.json index a8be883de..d283394d6 100644 --- a/translations/en.json +++ b/translations/en.json @@ -564,5 +564,6 @@ "Save": "Save", "Switch to moderation view": "Switch to moderation view", "Minimize attached images": "Minimize attached images", - "SHOW MEDIA": "SHOW MEDIA" + "SHOW MEDIA": "SHOW MEDIA", + "ActivityPub Specification": "ActivityPub Specification" } diff --git a/translations/es.json b/translations/es.json index e494d714a..c021c76a8 100644 --- a/translations/es.json +++ b/translations/es.json @@ -564,5 +564,6 @@ "Save": "Ahorrar", "Switch to moderation view": "Cambiar a la vista de moderación", "Minimize attached images": "Minimizar imágenes adjuntas", - "SHOW MEDIA": "MOSTRAR MEDIOS" + "SHOW MEDIA": "MOSTRAR MEDIOS", + "ActivityPub Specification": "Especificación de ActivityPub" } diff --git a/translations/fr.json b/translations/fr.json index c4aa74344..02adc075e 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -564,5 +564,6 @@ "Save": "Sauvegarder", "Switch to moderation view": "Passer en mode modération", "Minimize attached images": "Réduire les images jointes", - "SHOW MEDIA": "AFFICHER LES MÉDIAS" + "SHOW MEDIA": "AFFICHER LES MÉDIAS", + "ActivityPub Specification": "Spécification ActivityPub" } diff --git a/translations/ga.json b/translations/ga.json index f56c56c60..89e4839e1 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -564,5 +564,6 @@ "Save": "Sábháil", "Switch to moderation view": "Athraigh go dtí an t-amharc modhnóireachta", "Minimize attached images": "Íoslaghdaigh íomhánna ceangailte", - "SHOW MEDIA": "Taispeáin MEÁIN" + "SHOW MEDIA": "Taispeáin MEÁIN", + "ActivityPub Specification": "Sonraíocht ActivityPub" } diff --git a/translations/hi.json b/translations/hi.json index c7766c1f4..25da4a044 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -564,5 +564,6 @@ "Save": "बचाना", "Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें", "Minimize attached images": "संलग्न छवियों को छोटा करें", - "SHOW MEDIA": "मीडिया दिखाएं" + "SHOW MEDIA": "मीडिया दिखाएं", + "ActivityPub Specification": "गतिविधिपब विशिष्टता" } diff --git a/translations/it.json b/translations/it.json index 52f0c0e1b..b120d93ea 100644 --- a/translations/it.json +++ b/translations/it.json @@ -564,5 +564,6 @@ "Save": "Salva", "Switch to moderation view": "Passa alla visualizzazione moderazione", "Minimize attached images": "Riduci al minimo le immagini allegate", - "SHOW MEDIA": "MOSTRA MEDIA" + "SHOW MEDIA": "MOSTRA MEDIA", + "ActivityPub Specification": "Specifica ActivityPub" } diff --git a/translations/ja.json b/translations/ja.json index f751136be..2ecea1bcb 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -564,5 +564,6 @@ "Save": "保存", "Switch to moderation view": "モデレートビューに切り替えます", "Minimize attached images": "添付画像を最小限に抑える", - "SHOW MEDIA": "メディアを表示" + "SHOW MEDIA": "メディアを表示", + "ActivityPub Specification": "ActivityPubの仕様" } diff --git a/translations/ko.json b/translations/ko.json index 503175277..8dbfbb256 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -564,5 +564,6 @@ "Save": "구하다", "Switch to moderation view": "검토 보기로 전환", "Minimize attached images": "첨부된 이미지 최소화", - "SHOW MEDIA": "미디어 표시" + "SHOW MEDIA": "미디어 표시", + "ActivityPub Specification": "ActivityPub 사양" } diff --git a/translations/ku.json b/translations/ku.json index 9e5b086e6..fbbe26b22 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -564,5 +564,6 @@ "Save": "Rizgarkirin", "Switch to moderation view": "Biguherîne bo dîtina moderatoriyê", "Minimize attached images": "Wêneyên pêvekirî kêm bikin", - "SHOW MEDIA": "MEDYA NÎŞAN DE" + "SHOW MEDIA": "MEDYA NÎŞAN DE", + "ActivityPub Specification": "Specification ActivityPub" } diff --git a/translations/nl.json b/translations/nl.json index 3cd5a13e2..775c8d284 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -564,5 +564,6 @@ "Save": "Opslaan", "Switch to moderation view": "Overschakelen naar moderatieweergave", "Minimize attached images": "Bijgevoegde afbeeldingen minimaliseren", - "SHOW MEDIA": "TOON MEDIA" + "SHOW MEDIA": "TOON MEDIA", + "ActivityPub Specification": "ActivityPub-specificatie" } diff --git a/translations/oc.json b/translations/oc.json index 46cdd9ae2..98d73eedc 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -560,5 +560,6 @@ "Save": "Save", "Switch to moderation view": "Switch to moderation view", "Minimize attached images": "Minimize attached images", - "SHOW MEDIA": "SHOW MEDIA" + "SHOW MEDIA": "SHOW MEDIA", + "ActivityPub Specification": "ActivityPub Specification" } diff --git a/translations/pl.json b/translations/pl.json index e8b6f4a9e..feb0e953e 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -564,5 +564,6 @@ "Save": "Ratować", "Switch to moderation view": "Przełącz na widok moderacji", "Minimize attached images": "Zminimalizuj załączone obrazy", - "SHOW MEDIA": "POKAŻ MEDIA" + "SHOW MEDIA": "POKAŻ MEDIA", + "ActivityPub Specification": "Specyfikacja ActivityPub" } diff --git a/translations/pt.json b/translations/pt.json index 69c0d159c..b2725ce50 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -564,5 +564,6 @@ "Save": "Salvar", "Switch to moderation view": "Mudar para a visualização de moderação", "Minimize attached images": "Minimizar imagens anexadas", - "SHOW MEDIA": "MOSTRAR MÍDIA" + "SHOW MEDIA": "MOSTRAR MÍDIA", + "ActivityPub Specification": "Especificação do ActivityPub" } diff --git a/translations/ru.json b/translations/ru.json index 127ce94b9..bf21f25f3 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -564,5 +564,6 @@ "Save": "Сохранять", "Switch to moderation view": "Перейти в режим модерации", "Minimize attached images": "Свернуть прикрепленные изображения", - "SHOW MEDIA": "ПОКАЗАТЬ МЕДИА" + "SHOW MEDIA": "ПОКАЗАТЬ МЕДИА", + "ActivityPub Specification": "Спецификация ActivityPub" } diff --git a/translations/sw.json b/translations/sw.json index 9cde2161a..21d05b2b8 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -564,5 +564,6 @@ "Save": "Hifadhi", "Switch to moderation view": "Badili hadi mwonekano wa udhibiti", "Minimize attached images": "Punguza picha zilizoambatishwa", - "SHOW MEDIA": "ONESHA VYOMBO VYA HABARI" + "SHOW MEDIA": "ONESHA VYOMBO VYA HABARI", + "ActivityPub Specification": "Vipimo vya ActivityPub" } diff --git a/translations/tr.json b/translations/tr.json index ffcabb55e..95b1bba51 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -564,5 +564,6 @@ "Save": "Kaydetmek", "Switch to moderation view": "Denetleme görünümüne geç", "Minimize attached images": "Ekli resimleri simge durumuna küçült", - "SHOW MEDIA": "MEDYA GÖSTER" + "SHOW MEDIA": "MEDYA GÖSTER", + "ActivityPub Specification": "ActivityPub Spesifikasyonu" } diff --git a/translations/uk.json b/translations/uk.json index 9501a4193..86e92abaa 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -564,5 +564,6 @@ "Save": "Зберегти", "Switch to moderation view": "Перейти до режиму модерації", "Minimize attached images": "Мінімізуйте вкладені зображення", - "SHOW MEDIA": "ПОКАЗАТИ ЗМІ" + "SHOW MEDIA": "ПОКАЗАТИ ЗМІ", + "ActivityPub Specification": "Специфікація ActivityPub" } diff --git a/translations/yi.json b/translations/yi.json index 6d6b2d627..1ab354557 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -564,5 +564,6 @@ "Save": "היט", "Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג", "Minimize attached images": "מינאַמייז אַטאַטשט בילדער", - "SHOW MEDIA": "ווייַז מעדיע" + "SHOW MEDIA": "ווייַז מעדיע", + "ActivityPub Specification": "ActivityPub באַשרייַבונג" } diff --git a/translations/zh.json b/translations/zh.json index dc037c3fb..0f1f7d9ae 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -564,5 +564,6 @@ "Save": "节省", "Switch to moderation view": "切换到审核视图", "Minimize attached images": "最小化附加图像", - "SHOW MEDIA": "展示媒体" + "SHOW MEDIA": "展示媒体", + "ActivityPub Specification": "ActivityPub 规范" } diff --git a/webapp_column_left.py b/webapp_column_left.py index 40897ce63..31f8845af 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -505,7 +505,7 @@ def html_edit_links(css_cache: {}, translate: {}, base_dir: str, path: str, edit_links_form += \ '' - # the admin can edit terms of service and about text + # the admin can edit terms of service, about and specification text admin_nickname = get_config_param(base_dir, 'admin') if admin_nickname: if nickname == admin_nickname: @@ -547,5 +547,25 @@ def html_edit_links(css_cache: {}, translate: {}, base_dir: str, path: str, edit_links_form += \ '' + specification_filename = base_dir + '/accounts/activitypub.md' + specification_str = '' + if os.path.isfile(specification_filename): + with open(specification_filename, 'r', + encoding='utf-8') as fp_specification: + specification_str = fp_specification.read() + + edit_links_form += \ + '
' + edit_links_form += \ + ' ' + \ + translate['ActivityPub Specification'] + \ + '
' + edit_links_form += \ + ' ' + edit_links_form += \ + '
' + edit_links_form += html_footer() return edit_links_form diff --git a/webapp_specification.py b/webapp_specification.py new file mode 100644 index 000000000..0dd73da47 --- /dev/null +++ b/webapp_specification.py @@ -0,0 +1,67 @@ +__filename__ = "webapp_about.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.3.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@libreserver.org" +__status__ = "Production" +__module_group__ = "Web Interface" + +import os +from shutil import copyfile +from utils import get_config_param +from webapp_utils import html_header_with_website_markup +from webapp_utils import html_footer +from markdown import markdown_to_html + + +def html_specification(css_cache: {}, base_dir: str, http_prefix: str, + domain_full: str, onion_domain: str, translate: {}, + system_language: str) -> str: + """Show the specification screen + """ + admin_nickname = get_config_param(base_dir, 'admin') + if not os.path.isfile(base_dir + '/accounts/activitypub.md'): + copyfile(base_dir + '/specification/activitypub.md', + base_dir + '/accounts/activitypub.md') + + if os.path.isfile(base_dir + '/accounts/login-background-custom.jpg'): + if not os.path.isfile(base_dir + '/accounts/login-background.jpg'): + copyfile(base_dir + '/accounts/login-background-custom.jpg', + base_dir + '/accounts/login-background.jpg') + + specification_text = 'ActivityPub Protocol Specification.' + if os.path.isfile(base_dir + '/accounts/activitypub.md'): + with open(base_dir + '/accounts/activitypub.md', 'r', + encoding='utf-8') as fp_specification: + specification_text = markdown_to_html(fp_specification.read()) + + specification_form = '' + css_filename = base_dir + '/epicyon-profile.css' + if os.path.isfile(base_dir + '/epicyon.css'): + css_filename = base_dir + '/epicyon.css' + + instance_title = \ + get_config_param(base_dir, 'instanceTitle') + specification_form = \ + html_header_with_website_markup(css_filename, instance_title, + http_prefix, domain_full, + system_language) + specification_form += \ + '
' + specification_text + '
' + if onion_domain: + specification_form += \ + '
\n' + \ + '

' + \ + 'http://' + onion_domain + '

\n
\n' + if admin_nickname: + admin_actor = '/users/' + admin_nickname + specification_form += \ + '
\n' + \ + '

' + \ + translate['Administered by'] + ' ' + admin_nickname + '. ' + \ + translate['Version'] + ' ' + __version__ + \ + '

\n
\n' + specification_form += html_footer() + return specification_form