Block user agents from edit profile screen

main
Bob Mottram 2021-07-02 21:57:21 +01:00
parent 5d38503baa
commit ba126be369
19 changed files with 81 additions and 35 deletions

View File

@ -5084,8 +5084,7 @@ class PubServer(BaseHTTPRequestHandler):
actorChanged = True
# grayscale theme
if path.startswith('/users/' +
adminNickname + '/') or \
if path.startswith('/users/' + adminNickname + '/') or \
isArtist(baseDir, nickname):
grayscale = False
if fields.get('grayscale'):
@ -5181,15 +5180,30 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(allowedInstancesFilename):
os.remove(allowedInstancesFilename)
# save peertube instances list
peertubeInstancesFile = \
baseDir + '/accounts/peertube.txt'
if fields.get('ptInstances'):
adminNickname = \
getConfigParam(baseDir, 'admin')
if adminNickname and \
path.startswith('/users/' +
adminNickname + '/'):
# save blocked user agents
# This is admin lebel and global to the instance
if path.startswith('/users/' + adminNickname + '/'):
userAgentsBlocked = ''
if fields.get('userAgentsBlockedStr'):
userAgentsBlockedStr = \
fields['userAgentsBlockedStr']
userAgentsBlockedList = \
userAgentsBlockedStr.split('\n')
for ua in userAgentsBlockedList:
if userAgentsBlocked:
userAgentsBlocked += ','
userAgentsBlocked += ua.strip()
else:
userAgentsBlocked = ''
if self.server.userAgentsBlocked != userAgentsBlocked:
self.server.userAgentsBlocked = userAgentsBlocked
setConfigParam(baseDir, 'userAgentsBlocked',
userAgentsBlocked)
# save peertube instances list
peertubeInstancesFile = \
baseDir + '/accounts/peertube.txt'
if fields.get('ptInstances'):
self.server.peertubeInstances.clear()
with open(peertubeInstancesFile, 'w+') as aFile:
aFile.write(fields['ptInstances'])
@ -5203,10 +5217,10 @@ class PubServer(BaseHTTPRequestHandler):
if url in self.server.peertubeInstances:
continue
self.server.peertubeInstances.append(url)
else:
if os.path.isfile(peertubeInstancesFile):
os.remove(peertubeInstancesFile)
self.server.peertubeInstances.clear()
else:
if os.path.isfile(peertubeInstancesFile):
os.remove(peertubeInstancesFile)
self.server.peertubeInstances.clear()
# save git project names list
gitProjectsFilename = \
@ -10328,7 +10342,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.themeName,
peertubeInstances,
self.server.textModeBanner,
city, accessKeys).encode('utf-8')
city,
self.server.userAgentsBlocked,
accessKeys).encode('utf-8')
if msg:
msglen = len(msg)
self._set_headers('text/html', msglen,

View File

@ -448,5 +448,6 @@
"Graphic Design": "التصميم الجرافيكي",
"Import Theme": "استيراد الموضوع",
"Export Theme": "موضوع التصدير",
"Custom post submit button text": "عرف نشر إرسال نص زر"
"Custom post submit button text": "عرف نشر إرسال نص زر",
"Blocked User Agents": "عوامل المستخدم المحظورة"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Disseny gràfic",
"Import Theme": "Importació temàtica",
"Export Theme": "Tema d'exportació",
"Custom post submit button text": "Text de botó d'enviament de publicacions personalitzades"
"Custom post submit button text": "Text de botó d'enviament de publicacions personalitzades",
"Blocked User Agents": "Agents d'usuari bloquejats"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Dylunio Graffig",
"Import Theme": "Thema Mewnforio",
"Export Theme": "Thema Allforio",
"Custom post submit button text": "Testun Post Post Post"
"Custom post submit button text": "Testun Post Post Post",
"Blocked User Agents": "Asiantau defnyddwyr wedi'u blocio"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Grafikdesign",
"Import Theme": "Theme importieren",
"Export Theme": "Theme exportieren",
"Custom post submit button text": "Benutzerdefinierte Post-Senden Schaltfläche Text"
"Custom post submit button text": "Benutzerdefinierte Post-Senden Schaltfläche Text",
"Blocked User Agents": "Blockierte Benutzeragenten"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Graphic Design",
"Import Theme": "Import Theme",
"Export Theme": "Export Theme",
"Custom post submit button text": "Custom post submit button text"
"Custom post submit button text": "Custom post submit button text",
"Blocked User Agents": "Blocked User Agents"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Diseño gráfico",
"Import Theme": "Tema de importación",
"Export Theme": "Tema de exportación",
"Custom post submit button text": "POST POST PERSONALIZADO Botón Texto"
"Custom post submit button text": "POST POST PERSONALIZADO Botón Texto",
"Blocked User Agents": "Agentes de usuario bloqueados"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Conception graphique",
"Import Theme": "Import thème",
"Export Theme": "Thème d'exportation",
"Custom post submit button text": "Texte de bouton d'envoi postal personnalisé"
"Custom post submit button text": "Texte de bouton d'envoi postal personnalisé",
"Blocked User Agents": "Agents d'utilisateur bloqués"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Dearadh grafach",
"Import Theme": "Téama Iompórtáil",
"Export Theme": "Téama Easpórtála",
"Custom post submit button text": "Post saincheaptha Cuir isteach an cnaipe Téacs"
"Custom post submit button text": "Post saincheaptha Cuir isteach an cnaipe Téacs",
"Blocked User Agents": "Gníomhairí úsáideora blocáilte"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "ग्राफ़िक डिज़ाइन",
"Import Theme": "आयात विषय",
"Export Theme": "निर्यात विषय",
"Custom post submit button text": "कस्टम पोस्ट सबमिट बटन टेक्स्ट"
"Custom post submit button text": "कस्टम पोस्ट सबमिट बटन टेक्स्ट",
"Blocked User Agents": "अवरुद्ध उपयोगकर्ता एजेंट"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Graphic design",
"Import Theme": "Tema dell'importazione",
"Export Theme": "Esportare tema",
"Custom post submit button text": "Pulsante di invio del post personalizzato"
"Custom post submit button text": "Pulsante di invio del post personalizzato",
"Blocked User Agents": "Agenti utente bloccati"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "グラフィックデザイン",
"Import Theme": "輸入テーマ",
"Export Theme": "テーマをエクスポートします",
"Custom post submit button text": "カスタムポスト送信ボタンテキスト"
"Custom post submit button text": "カスタムポスト送信ボタンテキスト",
"Blocked User Agents": "ブロックされたユーザーエージェント"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Sêwirana grafîkî",
"Import Theme": "Mijara Import",
"Export Theme": "Mijara Export",
"Custom post submit button text": "Nivîsa bişkojka paşîn a paşîn"
"Custom post submit button text": "Nivîsa bişkojka paşîn a paşîn",
"Blocked User Agents": "Karmendên bikarhêner asteng kirin"
}

View File

@ -444,5 +444,6 @@
"Graphic Design": "Graphic Design",
"Import Theme": "Import Theme",
"Export Theme": "Export Theme",
"Custom post submit button text": "Custom post submit button text"
"Custom post submit button text": "Custom post submit button text",
"Blocked User Agents": "Blocked User Agents"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Design gráfico",
"Import Theme": "Importar tema",
"Export Theme": "Exportar tema",
"Custom post submit button text": "Texto de botão de envio de post personalizado"
"Custom post submit button text": "Texto de botão de envio de post personalizado",
"Blocked User Agents": "Agentes de usuário bloqueados"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Графический дизайн",
"Import Theme": "Импортировать тему",
"Export Theme": "Экспортная тема",
"Custom post submit button text": "Пользовательский пост Отправить кнопку текста"
"Custom post submit button text": "Пользовательский пост Отправить кнопку текста",
"Blocked User Agents": "Заблокированные пользовательские агенты"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "Graphic design",
"Import Theme": "Ingiza mandhari",
"Export Theme": "Tuma mandhari",
"Custom post submit button text": "Ujumbe wa Desturi Wasilisha Nakala ya kifungo"
"Custom post submit button text": "Ujumbe wa Desturi Wasilisha Nakala ya kifungo",
"Blocked User Agents": "Wakala wa watumiaji waliozuiwa"
}

View File

@ -448,5 +448,6 @@
"Graphic Design": "平面设计",
"Import Theme": "进口主题",
"Export Theme": "出口主题",
"Custom post submit button text": "自定义发布提交按钮文本"
"Custom post submit button text": "自定义发布提交按钮文本",
"Blocked User Agents": "阻止用户代理商"
}

View File

@ -1414,7 +1414,7 @@ def _htmlEditProfileGitProjects(baseDir: str, nickname: str, domain: str,
def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str,
translate: {}) -> str:
userAgentsBlocked: str, translate: {}) -> str:
"""Filtering and blocking section of edit profile screen
"""
filterStr = ''
@ -1581,6 +1581,17 @@ def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str,
'style="height:200px" spellcheck="false">' + \
allowedInstancesStr + '</textarea>\n'
userAgentsBlockedStr = ''
if userAgentsBlocked:
userAgentsBlockedStr = userAgentsBlocked.replace(',', '\n')
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Blocked User Agents'] + '</label></b>\n'
editProfileForm += \
' <textarea id="message" name="userAgentsBlockedStr" ' + \
'style="height:200px" spellcheck="false">' + \
userAgentsBlockedStr + '</textarea>\n'
editProfileForm += ' </div></details>\n'
return editProfileForm
@ -1880,6 +1891,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
defaultTimeline: str, theme: str,
peertubeInstances: [],
textModeBanner: str, city: str,
userAgentsBlocked: str,
accessKeys: {}) -> str:
"""Shows the edit profile screen
"""
@ -2056,7 +2068,8 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
# Filtering and blocking section
editProfileForm += \
_htmlEditProfileFiltering(baseDir, nickname, domain, translate)
_htmlEditProfileFiltering(baseDir, nickname, domain,
userAgentsBlocked, translate)
# git projects section
editProfileForm += \