Function for 401 http code

main
Bob Mottram 2022-08-28 14:48:55 +01:00
parent fb7ed831fd
commit 5e998a648c
27 changed files with 120 additions and 33 deletions

View File

@ -1059,6 +1059,15 @@ class PubServer(BaseHTTPRequestHandler):
'This is nothing less ' +
'than an utter triumph', None)
def _401(self, post_msg: str) -> None:
if self.server.translate:
ok_str = self.server.translate[post_msg]
self._http_return_code(401, self.server.translate['Unauthorized'],
ok_str, None)
else:
self._http_return_code(401, 'Unauthorized',
post_msg, None)
def _201(self, etag: str) -> None:
if self.server.translate:
done_str = self.server.translate['It is done']
@ -2050,12 +2059,12 @@ class PubServer(BaseHTTPRequestHandler):
'epicyon=; SameSite=Strict',
calling_domain)
def _show_login_screen(self, calling_domain: str, cookie: str,
def _post_login_screen(self, calling_domain: str, cookie: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str, port: int,
onion_domain: str, i2p_domain: str,
ua_str: str) -> None:
"""Shows the login screen
"""POST to login screen, containing credentials
"""
# ensure that there is a minimum delay between failed login
# attempts, to mitigate brute force
@ -2068,8 +2077,7 @@ class PubServer(BaseHTTPRequestHandler):
length = int(self.headers['Content-length'])
if length > 512:
print('Login failed - credentials too long')
self.send_response(401)
self.end_headers()
self._401('Credentials are too long')
self.server.postreq_busy = False
return
@ -2096,7 +2104,7 @@ class PubServer(BaseHTTPRequestHandler):
html_get_login_credentials(login_params,
self.server.last_login_time,
domain)
if login_nickname:
if login_nickname and login_password:
if is_system_account(login_nickname):
print('Invalid username login: ' + login_nickname +
' (system account)')
@ -2248,6 +2256,10 @@ class PubServer(BaseHTTPRequestHandler):
cookie_str, calling_domain)
self.server.postreq_busy = False
return
else:
print('WARN: No login credentials presented to /login')
self._401('No login credentials were posted')
self.server.postreq_busy = False
self._200()
self.server.postreq_busy = False
@ -20044,9 +20056,9 @@ class PubServer(BaseHTTPRequestHandler):
'_POST', 'start',
self.server.debug)
# login screen
# POST to login screen, containing credentials
if self.path.startswith('/login'):
self._show_login_screen(calling_domain, cookie,
self._post_login_screen(calling_domain, cookie,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "آخر أسبوعين",
"Last month": "الشهر الماضي",
"Last 6 months": "آخر 6 أشهر",
"Last year": "العام الماضي"
"Last year": "العام الماضي",
"Unauthorized": "غير مصرح",
"No login credentials were posted": "لم يتم نشر بيانات اعتماد تسجيل الدخول",
"Credentials are too long": "أوراق الاعتماد طويلة جدًا"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "গত ২ সপ্তাহ",
"Last month": "গত মাসে",
"Last 6 months": "গত ৬ মাস",
"Last year": "গত বছর"
"Last year": "গত বছর",
"Unauthorized": "অননুমোদিত",
"No login credentials were posted": "কোনো লগইন শংসাপত্র পোস্ট করা হয়নি",
"Credentials are too long": "শংসাপত্রগুলি খুব দীর্ঘ৷"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Últimes 2 setmanes",
"Last month": "El mes passat",
"Last 6 months": "Últims 6 mesos",
"Last year": "L'any passat"
"Last year": "L'any passat",
"Unauthorized": "No autoritzat",
"No login credentials were posted": "No s'ha publicat cap credencial d'inici de sessió",
"Credentials are too long": "Les credencials són massa llargues"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "2 wythnos diwethaf",
"Last month": "Mis diwethaf",
"Last 6 months": "6 mis diwethaf",
"Last year": "Blwyddyn diwethaf"
"Last year": "Blwyddyn diwethaf",
"Unauthorized": "Anawdurdodedig",
"No login credentials were posted": "Ni bostiwyd unrhyw fanylion mewngofnodi",
"Credentials are too long": "Mae manylion yn rhy hir"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Letzte 2 Wochen",
"Last month": "Im vergangenen Monat",
"Last 6 months": "Letzte 6 Monate",
"Last year": "Vergangenes Jahr"
"Last year": "Vergangenes Jahr",
"Unauthorized": "Unbefugt",
"No login credentials were posted": "Es wurden keine Zugangsdaten gepostet",
"Credentials are too long": "Anmeldeinformationen sind zu lang"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Τελευταίες 2 εβδομάδες",
"Last month": "Τον προηγούμενο μήνα",
"Last 6 months": "Τελευταίοι 6 μήνες",
"Last year": "Πέρυσι"
"Last year": "Πέρυσι",
"Unauthorized": "Ανεξουσιοδότητος",
"No login credentials were posted": "Δεν δημοσιεύτηκαν διαπιστευτήρια σύνδεσης",
"Credentials are too long": "Τα διαπιστευτήρια είναι πολύ μεγάλα"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Last 2 weeks",
"Last month": "Last month",
"Last 6 months": "Last 6 months",
"Last year": "Last year"
"Last year": "Last year",
"Unauthorized": "Unauthorized",
"No login credentials were posted": "No login credentials were posted",
"Credentials are too long": "Credentials are too long"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "últimas 2 semanas",
"Last month": "El mes pasado",
"Last 6 months": "últimos 6 meses",
"Last year": "El año pasado"
"Last year": "El año pasado",
"Unauthorized": "No autorizado",
"No login credentials were posted": "No se publicaron credenciales de inicio de sesión",
"Credentials are too long": "Las credenciales son demasiado largas"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "2 dernières semaines",
"Last month": "Le mois dernier",
"Last 6 months": "6 derniers mois",
"Last year": "L'année dernière"
"Last year": "L'année dernière",
"Unauthorized": "Non autorisé",
"No login credentials were posted": "Aucun identifiant de connexion n'a été posté",
"Credentials are too long": "Les identifiants sont trop longs"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "2 sheachtain anuas",
"Last month": "An mhí seo caite",
"Last 6 months": "6 mhí anuas",
"Last year": "Anuraidh"
"Last year": "Anuraidh",
"Unauthorized": "Neamhúdaraithe",
"No login credentials were posted": "Níor postáladh aon dintiúir logáil isteach",
"Credentials are too long": "Tá dintiúir ró-fhada"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "पिछले 2 सप्ताह",
"Last month": "पिछले महीने",
"Last 6 months": "पिछले 6 महीने",
"Last year": "पिछले साल"
"Last year": "पिछले साल",
"Unauthorized": "अनधिकृत",
"No login credentials were posted": "कोई लॉगिन क्रेडेंशियल पोस्ट नहीं किया गया था",
"Credentials are too long": "क्रेडेंशियल बहुत लंबे हैं"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Ultime 2 settimane",
"Last month": "Lo scorso mese",
"Last 6 months": "Ultimi 6 mesi",
"Last year": "L'anno scorso"
"Last year": "L'anno scorso",
"Unauthorized": "Non autorizzato",
"No login credentials were posted": "Non sono state pubblicate credenziali di accesso",
"Credentials are too long": "Le credenziali sono troppo lunghe"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "過去 2 週間",
"Last month": "先月",
"Last 6 months": "過去 6 か月",
"Last year": "去年"
"Last year": "去年",
"Unauthorized": "無許可",
"No login credentials were posted": "ログイン認証情報が投稿されていません",
"Credentials are too long": "資格情報が長すぎます"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "지난 2주",
"Last month": "지난 달",
"Last 6 months": "지난 6개월",
"Last year": "작년"
"Last year": "작년",
"Unauthorized": "무단",
"No login credentials were posted": "게시된 로그인 자격 증명이 없습니다.",
"Credentials are too long": "자격 증명이 너무 깁니다."
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "2 hefteyên dawî",
"Last month": "meha borî",
"Last 6 months": "6 mehên dawî",
"Last year": "Sala borî"
"Last year": "Sala borî",
"Unauthorized": "Bêmaf",
"No login credentials were posted": "Tu pêbaweriyên têketinê nehatin şandin",
"Credentials are too long": "Bawernameyên pir dirêj in"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Afgelopen 2 weken",
"Last month": "Vorige maand",
"Last 6 months": "Afgelopen 6 maanden",
"Last year": "Afgelopen jaar"
"Last year": "Afgelopen jaar",
"Unauthorized": "Ongeautoriseerd",
"No login credentials were posted": "Er zijn geen inloggegevens gepost",
"Credentials are too long": "Inloggegevens zijn te lang"
}

View File

@ -583,5 +583,8 @@
"Last 2 weeks": "Last 2 weeks",
"Last month": "Last month",
"Last 6 months": "Last 6 months",
"Last year": "Last year"
"Last year": "Last year",
"Unauthorized": "Unauthorized",
"No login credentials were posted": "No login credentials were posted",
"Credentials are too long": "Credentials are too long"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Ostatnie 2 tygodnie",
"Last month": "W zeszłym miesiącu",
"Last 6 months": "Ostatnie 6 miesięcy",
"Last year": "Ostatni rok"
"Last year": "Ostatni rok",
"Unauthorized": "Nieautoryzowany",
"No login credentials were posted": "Nie opublikowano danych logowania",
"Credentials are too long": "Poświadczenia są za długie"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Últimas 2 semanas",
"Last month": "Mês passado",
"Last 6 months": "Últimos 6 meses",
"Last year": "Ano passado"
"Last year": "Ano passado",
"Unauthorized": "Não autorizado",
"No login credentials were posted": "Nenhuma credencial de login foi postada",
"Credentials are too long": "As credenciais são muito longas"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Последние 2 недели",
"Last month": "Прошлый месяц",
"Last 6 months": "Последние 6 месяцев",
"Last year": "Прошедший год"
"Last year": "Прошедший год",
"Unauthorized": "Неавторизованный",
"No login credentials were posted": "Учетные данные для входа не были отправлены",
"Credentials are too long": "Учетные данные слишком длинные"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Wiki 2 zilizopita",
"Last month": "Mwezi uliopita",
"Last 6 months": "Miezi 6 iliyopita",
"Last year": "Mwaka jana"
"Last year": "Mwaka jana",
"Unauthorized": "Haijaidhinishwa",
"No login credentials were posted": "Hakuna kitambulisho cha kuingia kilichochapishwa",
"Credentials are too long": "Kitambulisho ni kirefu sana"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Son 2 hafta",
"Last month": "Geçen ay",
"Last 6 months": "Son 6 ay",
"Last year": "Geçen yıl"
"Last year": "Geçen yıl",
"Unauthorized": "Yetkisiz",
"No login credentials were posted": "Giriş bilgileri gönderilmedi",
"Credentials are too long": "Kimlik bilgileri çok uzun"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "Останні 2 тижні",
"Last month": "Минулого місяця",
"Last 6 months": "Останні 6 місяців",
"Last year": "Минулого року"
"Last year": "Минулого року",
"Unauthorized": "Несанкціонований",
"No login credentials were posted": "Облікові дані для входу не опубліковано",
"Credentials are too long": "Облікові дані задовгі"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "לעצטע 2 וואָכן",
"Last month": "לעצטע מאנאט",
"Last 6 months": "לעצטע 6 חדשים",
"Last year": "לעצטע יאר"
"Last year": "לעצטע יאר",
"Unauthorized": "אַנאָטערייזד",
"No login credentials were posted": "קיין לאָגין קראַדענטשאַלז זענען אַרייַנגעשיקט",
"Credentials are too long": "קראַדענטשאַלז זענען צו לאַנג"
}

View File

@ -587,5 +587,8 @@
"Last 2 weeks": "过去 2 周",
"Last month": "上个月",
"Last 6 months": "过去 6 个月",
"Last year": "去年"
"Last year": "去年",
"Unauthorized": "未经授权",
"No login credentials were posted": "未发布登录凭据",
"Credentials are too long": "凭据太长"
}

View File

@ -30,7 +30,7 @@ def html_get_login_credentials(loginParams: str,
return None, None, None
# minimum time between login attempts
curr_time = int(time.time())
if curr_time < last_login_time+10:
if curr_time < last_login_time + 10:
return None, None, None
if '&' not in loginParams:
return None, None, None