Make list of languages installed discoverable at runtime.

Stop hardcoding Russian in webadmin.
Limit the setting in controlpanel to the known languages, because
untrusted language code might lead to some interesting vulnerabilities.
This commit is contained in:
Alexey Sokolov
2017-08-19 18:05:47 +01:00
parent 328461faf1
commit f885699d1a
6 changed files with 65 additions and 8 deletions
+19 -3
View File
@@ -276,7 +276,9 @@ class CAdminMod : public CModule {
PutModule("StatusPrefix = " + pUser->GetStatusPrefix());
#ifdef HAVE_I18N
else if (sVar == "language")
PutModule("Language = " + pUser->GetLanguage());
PutModule("Language = " + (pUser->GetLanguage().empty()
? "en"
: pUser->GetLanguage()));
#endif
#ifdef HAVE_ICU
else if (sVar == "clientencoding")
@@ -453,8 +455,22 @@ class CAdminMod : public CModule {
}
#ifdef HAVE_I18N
else if (sVar == "language") {
pUser->SetLanguage(sValue);
PutModule("Language = " + pUser->GetLanguage());
auto mTranslations = CTranslationInfo::GetTranslations();
// TODO: maybe stop special-casing English
if (sValue == "en") {
pUser->SetLanguage("");
PutModule("Language is set to English");
} else if (mTranslations.count(sValue)) {
pUser->SetLanguage(sValue);
PutModule("Language = " + sValue);
} else {
VCString vsCodes = {"en"};
for (const auto it : mTranslations) {
vsCodes.push_back(it.first);
}
PutModule("Supported languages: " +
CString(", ").Join(vsCodes.begin(), vsCodes.end()));
}
}
#endif
#ifdef HAVE_ICU