Translateable more, #1354

This commit is contained in:
Alexey Sokolov
2017-09-05 23:44:47 +01:00
parent 3b6d4ac687
commit 7e9acdf085
2 changed files with 61 additions and 73 deletions
+37 -41
View File
@@ -22,22 +22,18 @@ class CFailToBanMod : public CModule {
MODCONSTRUCTOR(CFailToBanMod) {
AddHelpCommand();
AddCommand(
"Timeout", static_cast<CModCommand::ModCmdFunc>(
&CFailToBanMod::OnTimeoutCommand),
"[minutes]",
"The number of minutes IPs are blocked after a failed login.");
AddCommand("Attempts", static_cast<CModCommand::ModCmdFunc>(
&CFailToBanMod::OnAttemptsCommand),
"[count]", "The number of allowed failed login attempts.");
AddCommand("Ban", static_cast<CModCommand::ModCmdFunc>(
&CFailToBanMod::OnBanCommand),
"<hosts>", "Ban the specified hosts.");
AddCommand("Unban", static_cast<CModCommand::ModCmdFunc>(
&CFailToBanMod::OnUnbanCommand),
"<hosts>", "Unban the specified hosts.");
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(
&CFailToBanMod::OnListCommand),
"", "List banned hosts.");
"Timeout", t_d("[minutes]"),
t_d("The number of minutes IPs are blocked after a failed login."),
[=](const CString& sLine) { OnTimeoutCommand(sLine); });
AddCommand("Attempts", t_d("[count]"),
t_d("The number of allowed failed login attempts."),
[=](const CString& sLine) { OnAttemptsCommand(sLine); });
AddCommand("Ban", t_d("<hosts>"), t_d("Ban the specified hosts."),
[=](const CString& sLine) { OnBanCommand(sLine); });
AddCommand("Unban", t_d("<hosts>"), t_d("Unban the specified hosts."),
[=](const CString& sLine) { OnUnbanCommand(sLine); });
AddCommand("List", "", t_d("List banned hosts."),
[=](const CString& sLine) { OnListCommand(sLine); });
}
~CFailToBanMod() override {}
@@ -78,7 +74,7 @@ class CFailToBanMod : public CModule {
void OnTimeoutCommand(const CString& sCommand) {
if (!GetUser()->IsAdmin()) {
PutModule("Access denied");
PutModule(t_s("Access denied"));
return;
}
@@ -87,22 +83,21 @@ class CFailToBanMod : public CModule {
if (!sArg.empty()) {
unsigned int uTimeout = sArg.ToUInt();
if (uTimeout == 0) {
PutModule("Usage: Timeout [minutes]");
PutModule(t_s("Usage: Timeout [minutes]"));
} else {
m_Cache.SetTTL(uTimeout * 60 * 1000);
SetArgs(CString(m_Cache.GetTTL() / 60 / 1000) + " " +
CString(m_uiAllowedFailed));
PutModule("Timeout: " + CString(uTimeout) + " min");
PutModule(t_f("Timeout: {1} min")(uTimeout));
}
} else {
PutModule("Timeout: " + CString(m_Cache.GetTTL() / 60 / 1000) +
" min");
PutModule(t_f("Timeout: {1} min")(m_Cache.GetTTL() / 60 / 1000));
}
}
void OnAttemptsCommand(const CString& sCommand) {
if (!GetUser()->IsAdmin()) {
PutModule("Access denied");
PutModule(t_s("Access denied"));
return;
}
@@ -111,28 +106,28 @@ class CFailToBanMod : public CModule {
if (!sArg.empty()) {
unsigned int uiAttempts = sArg.ToUInt();
if (uiAttempts == 0) {
PutModule("Usage: Attempts [count]");
PutModule(t_s("Usage: Attempts [count]"));
} else {
m_uiAllowedFailed = uiAttempts;
SetArgs(CString(m_Cache.GetTTL() / 60 / 1000) + " " +
CString(m_uiAllowedFailed));
PutModule("Attempts: " + CString(uiAttempts));
PutModule(t_f("Attempts: {1}")(uiAttempts));
}
} else {
PutModule("Attempts: " + CString(m_uiAllowedFailed));
PutModule(t_f("Attempts: {1}")(m_uiAllowedFailed));
}
}
void OnBanCommand(const CString& sCommand) {
if (!GetUser()->IsAdmin()) {
PutModule("Access denied");
PutModule(t_s("Access denied"));
return;
}
CString sHosts = sCommand.Token(1, true);
if (sHosts.empty()) {
PutStatus("Usage: Ban <hosts>");
PutStatus(t_s("Usage: Ban <hosts>"));
return;
}
@@ -142,20 +137,20 @@ class CFailToBanMod : public CModule {
for (const CString& sHost : vsHosts) {
Add(sHost, 0);
PutModule("Banned: " + sHost);
PutModule(t_f("Banned: {1}")(sHost));
}
}
void OnUnbanCommand(const CString& sCommand) {
if (!GetUser()->IsAdmin()) {
PutModule("Access denied");
PutModule(t_s("Access denied"));
return;
}
CString sHosts = sCommand.Token(1, true);
if (sHosts.empty()) {
PutStatus("Usage: Unban <hosts>");
PutStatus(t_s("Usage: Unban <hosts>"));
return;
}
@@ -165,31 +160,31 @@ class CFailToBanMod : public CModule {
for (const CString& sHost : vsHosts) {
if (Remove(sHost)) {
PutModule("Unbanned: " + sHost);
PutModule(t_f("Unbanned: {1}")(sHost));
} else {
PutModule("Ignored: " + sHost);
PutModule(t_f("Ignored: {1}")(sHost));
}
}
}
void OnListCommand(const CString& sCommand) {
if (!GetUser()->IsAdmin()) {
PutModule("Access denied");
PutModule(t_s("Access denied"));
return;
}
CTable Table;
Table.AddColumn("Host");
Table.AddColumn("Attempts");
Table.AddColumn(t_s("Host", "list"));
Table.AddColumn(t_s("Attempts", "list"));
for (const auto& it : m_Cache.GetItems()) {
Table.AddRow();
Table.SetCell("Host", it.first);
Table.SetCell("Attempts", CString(it.second));
Table.SetCell(t_s("Host", "list"), it.first);
Table.SetCell(t_s("Attempts", "list"), CString(it.second));
}
if (Table.empty()) {
PutModule("No bans");
PutModule(t_s("No bans", "list"));
} else {
PutModule(Table);
}
@@ -246,8 +241,9 @@ void TModInfo<CFailToBanMod>(CModInfo& Info) {
Info.SetWikiPage("fail2ban");
Info.SetHasArgs(true);
Info.SetArgsHelpText(
"You might enter the time in minutes for the IP banning and the number "
"of failed logins before any action is taken.");
Info.t_s("You might enter the time in minutes for the IP banning and "
"the number of failed logins before any action is taken."));
}
GLOBALMODULEDEFS(CFailToBanMod, "Block IPs for some time after a failed login.")
GLOBALMODULEDEFS(CFailToBanMod,
t_s("Block IPs for some time after a failed login."))
+24 -32
View File
@@ -27,18 +27,12 @@ class CFloodDetachMod : public CModule {
m_iThresholdMsgs = 0;
AddHelpCommand();
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
&CFloodDetachMod::ShowCommand),
"");
AddCommand("Secs", static_cast<CModCommand::ModCmdFunc>(
&CFloodDetachMod::SecsCommand),
"[<limit>]");
AddCommand("Lines", static_cast<CModCommand::ModCmdFunc>(
&CFloodDetachMod::LinesCommand),
"[<limit>]");
AddCommand("Silent", static_cast<CModCommand::ModCmdFunc>(
&CFloodDetachMod::SilentCommand),
"[yes|no]");
AddCommand("Show","",t_d("Show current limits"),[=](const CString& sLine){ShowCommand(sLine);});
AddCommand("Secs", t_d("[<limit>]"),
t_d("Show or set number of seconds in the time interval"),
[=](const CString& sLine) { SecsCommand(sLine); });
AddCommand("Lines",t_d("[<limit>]"),t_d("blahblah: description"),[=](const CString& sLine){LinesCommand(sLine);});
AddCommand("Silent",t_d("[yes|no]"),t_d("blahblah: description"),[=](const CString& sLine){SilentCommand(sLine);});
}
~CFloodDetachMod() override {}
@@ -90,9 +84,8 @@ class CFloodDetachMod : public CModule {
// we detached because of a flood.
if (!GetNV("silent").ToBool()) {
PutModule("Flood in [" + pChan->GetName() +
"] is over, "
"re-attaching...");
PutModule(t_f("Flood in {1} is over, reattaching...")(
pChan->GetName()));
}
// No buffer playback, makes sense, doesn't it?
pChan->ClearBuffer();
@@ -148,9 +141,8 @@ class CFloodDetachMod : public CModule {
Channel.DetachUser();
if (!GetNV("silent").ToBool()) {
PutModule("Channel [" + Channel.GetName() +
"] was "
"flooded, you've been detached");
PutModule(t_f("Channel {1} was flooded, you've been detached")(
Channel.GetName()));
}
}
@@ -185,23 +177,23 @@ class CFloodDetachMod : public CModule {
}
void ShowCommand(const CString& sLine) {
PutModule("Current limit is " + CString(m_iThresholdMsgs) +
" lines "
"in " +
CString(m_iThresholdSecs) + " secs.");
CString sLines =
t_p("1 line", "{1} lines", m_iThresholdMsgs)(m_iThresholdMsgs);
CString sSeconds = t_p("every second", "every {1} seconds",
m_iThresholdSecs)(m_iThresholdSecs);
PutModule(t_f("Current limit is {1} {2}")(sLines, sSeconds));
}
void SecsCommand(const CString& sLine) {
const CString sArg = sLine.Token(1, true);
if (sArg.empty()) {
PutModule("Seconds limit is [" + CString(m_iThresholdSecs) + "]");
PutModule(t_f("Seconds limit is {1}")(m_iThresholdSecs));
} else {
m_iThresholdSecs = sArg.ToUInt();
if (m_iThresholdSecs == 0) m_iThresholdSecs = 1;
PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) +
"]");
PutModule(t_f("Set seconds limit to {1}")(m_iThresholdSecs));
Save();
}
}
@@ -210,12 +202,12 @@ class CFloodDetachMod : public CModule {
const CString sArg = sLine.Token(1, true);
if (sArg.empty()) {
PutModule("Lines limit is [" + CString(m_iThresholdMsgs) + "]");
PutModule(t_f("Lines limit is {1}")(m_iThresholdMsgs));
} else {
m_iThresholdMsgs = sArg.ToUInt();
if (m_iThresholdMsgs == 0) m_iThresholdMsgs = 2;
PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]");
PutModule(t_f("Set lines limit to {1}")(m_iThresholdMsgs));
Save();
}
}
@@ -228,9 +220,9 @@ class CFloodDetachMod : public CModule {
}
if (GetNV("silent").ToBool()) {
PutModule("Module messages are disabled");
PutModule(t_s("Module messages are disabled"));
} else {
PutModule("Module messages are enabled");
PutModule(t_s("Module messages are enabled"));
}
}
@@ -246,8 +238,8 @@ void TModInfo<CFloodDetachMod>(CModInfo& Info) {
Info.SetWikiPage("flooddetach");
Info.SetHasArgs(true);
Info.SetArgsHelpText(
"This user module takes up to two arguments. Arguments are msgs and "
"secs numbers.");
Info.t_s("This user module takes up to two arguments. Arguments are "
"numbers of messages and seconds."));
}
USERMODULEDEFS(CFloodDetachMod, "Detach channels when flooded")
USERMODULEDEFS(CFloodDetachMod, t_s("Detach channels when flooded"))