diff --git a/modules/data/lastseen/tmpl/index.tmpl b/modules/data/lastseen/tmpl/index.tmpl index 950b4fe6..1fe98086 100644 --- a/modules/data/lastseen/tmpl/index.tmpl +++ b/modules/data/lastseen/tmpl/index.tmpl @@ -1,13 +1,14 @@ +
- - - - + + + + @@ -17,8 +18,8 @@ diff --git a/modules/data/lastseen/tmpl/lastseen_WebadminUser.tmpl b/modules/data/lastseen/tmpl/lastseen_WebadminUser.tmpl index e8617543..4f9d50bd 100644 --- a/modules/data/lastseen/tmpl/lastseen_WebadminUser.tmpl +++ b/modules/data/lastseen/tmpl/lastseen_WebadminUser.tmpl @@ -1,7 +1,9 @@ + +
- +
diff --git a/modules/data/listsockets/tmpl/index.tmpl b/modules/data/listsockets/tmpl/index.tmpl index e33316c2..8e9503c7 100644 --- a/modules/data/listsockets/tmpl/index.tmpl +++ b/modules/data/listsockets/tmpl/index.tmpl @@ -1,16 +1,17 @@ +
UserLast SeenInfoAction
- [Edit] - [Delete] + [] + []
- - - - - - - - + + + + + + + + diff --git a/modules/fail2ban.cpp b/modules/fail2ban.cpp index 37dfa5f5..afc3a2f2 100644 --- a/modules/fail2ban.cpp +++ b/modules/fail2ban.cpp @@ -52,9 +52,9 @@ class CFailToBanMod : public CModule { } else if (timeout == 0 || m_uiAllowedFailed == 0 || !sArgs.Token(2, true).empty()) { sMessage = - "Invalid argument, must be the number of minutes " - "IPs are blocked after a failed login and can be " - "followed by number of allowed failed login attempts"; + t_s("Invalid argument, must be the number of minutes IPs are " + "blocked after a failed login and can be followed by " + "number of allowed failed login attempts"); return false; } diff --git a/modules/flooddetach.cpp b/modules/flooddetach.cpp index dfb949f8..85d07b9a 100644 --- a/modules/flooddetach.cpp +++ b/modules/flooddetach.cpp @@ -27,12 +27,15 @@ class CFloodDetachMod : public CModule { m_iThresholdMsgs = 0; AddHelpCommand(); - AddCommand("Show","",t_d("Show current limits"),[=](const CString& sLine){ShowCommand(sLine);}); + AddCommand("Show", "", t_d("Show current limits"), + [=](const CString& sLine) { ShowCommand(sLine); }); AddCommand("Secs", t_d("[]"), t_d("Show or set number of seconds in the time interval"), [=](const CString& sLine) { SecsCommand(sLine); }); - AddCommand("Lines",t_d("[]"),t_d("blahblah: description"),[=](const CString& sLine){LinesCommand(sLine);}); - AddCommand("Silent",t_d("[yes|no]"),t_d("blahblah: description"),[=](const CString& sLine){SilentCommand(sLine);}); + AddCommand("Lines", t_d("[]"), 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 {} diff --git a/modules/kickrejoin.cpp b/modules/kickrejoin.cpp index baec6aa4..a6c3ed8c 100644 --- a/modules/kickrejoin.cpp +++ b/modules/kickrejoin.cpp @@ -73,7 +73,8 @@ class CRejoinMod : public CModule { if ((i == 0 && sArgs == "0") || i > 0) delay = i; else { - sErrorMsg = "Illegal argument, must be a positive number or 0"; + sErrorMsg = + t_s("Illegal argument, must be a positive number or 0"); return false; } } diff --git a/modules/lastseen.cpp b/modules/lastseen.cpp index 1cdcd132..35a57503 100644 --- a/modules/lastseen.cpp +++ b/modules/lastseen.cpp @@ -50,7 +50,7 @@ class CLastSeenMod : public CModule { // Shows all users as well as the time they were last seen online void ShowCommand(const CString& sLine) { if (!GetUser()->IsAdmin()) { - PutModule("Access denied"); + PutModule(t_s("Access denied")); return; } @@ -58,13 +58,14 @@ class CLastSeenMod : public CModule { MUsers::const_iterator it; CTable Table; - Table.AddColumn("User"); - Table.AddColumn("Last Seen"); + Table.AddColumn(t_s("User", "show")); + Table.AddColumn(t_s("Last Seen", "show")); for (it = mUsers.begin(); it != mUsers.end(); ++it) { Table.AddRow(); - Table.SetCell("User", it->first); - Table.SetCell("Last Seen", FormatLastSeen(it->second, "never")); + Table.SetCell(t_s("User", "show"), it->first); + Table.SetCell(t_s("Last Seen", "show"), + FormatLastSeen(it->second, t_s("never"))); } PutModule(Table); @@ -73,9 +74,9 @@ class CLastSeenMod : public CModule { public: MODCONSTRUCTOR(CLastSeenMod) { AddHelpCommand(); - AddCommand("Show", static_cast( - &CLastSeenMod::ShowCommand), - "", "Shows list of users and when they last logged in"); + AddCommand("Show", "", + t_d("Shows list of users and when they last logged in"), + [=](const CString& sLine) { ShowCommand(sLine); }); } ~CLastSeenMod() override {} @@ -94,7 +95,7 @@ class CLastSeenMod : public CModule { // Web stuff: bool WebRequiresAdmin() override { return true; } - CString GetWebMenuTitle() override { return "Last Seen"; } + CString GetWebMenuTitle() override { return t_s("Last Seen"); } bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) override { @@ -120,7 +121,7 @@ class CLastSeenMod : public CModule { Row["Username"] = pUser->GetUserName(); Row["IsSelf"] = CString(pUser == WebSock.GetSession()->GetUser()); - Row["LastSeen"] = FormatLastSeen(pUser, "never"); + Row["LastSeen"] = FormatLastSeen(pUser, t_s("never")); } return true; @@ -149,4 +150,4 @@ void TModInfo(CModInfo& Info) { } GLOBALMODULEDEFS(CLastSeenMod, - "Collects data about when a user last logged in.") + t_s("Collects data about when a user last logged in.")) diff --git a/modules/listsockets.cpp b/modules/listsockets.cpp index 3cba6e03..7e2bddc2 100644 --- a/modules/listsockets.cpp +++ b/modules/listsockets.cpp @@ -59,17 +59,15 @@ class CListSockets : public CModule { public: MODCONSTRUCTOR(CListSockets) { AddHelpCommand(); - AddCommand( - "List", - static_cast(&CListSockets::OnListCommand), - "[-n]", - "Show the list of active sockets. Pass -n to show IP addresses"); + AddCommand("List", t_d("[-n]"), t_d("Shows the list of active sockets. " + "Pass -n to show IP addresses"), + [=](const CString& sLine) { OnListCommand(sLine); }); } bool OnLoad(const CString& sArgs, CString& sMessage) override { #ifndef MOD_LISTSOCKETS_ALLOW_EVERYONE if (!GetUser()->IsAdmin()) { - sMessage = "You must be admin to use this module"; + sMessage = t_s("You must be admin to use this module"); return false; } #endif @@ -95,7 +93,7 @@ class CListSockets : public CModule { } bool WebRequiresAdmin() override { return true; } - CString GetWebMenuTitle() override { return "List sockets"; } + CString GetWebMenuTitle() override { return t_s("List sockets"); } bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) override { @@ -114,7 +112,8 @@ class CListSockets : public CModule { Row["Name"] = pSocket->GetSockName(); Row["Created"] = GetCreatedTime(pSocket); Row["State"] = GetSocketState(pSocket); - Row["SSL"] = pSocket->GetSSL() ? "Yes" : "No"; + Row["SSL"] = + pSocket->GetSSL() ? t_s("Yes", "ssl") : t_s("No", "ssl"); Row["Local"] = GetLocalHost(pSocket, true); Row["Remote"] = GetRemoteHost(pSocket, true); Row["In"] = CString::ToByteStr(pSocket->GetBytesRead()); @@ -140,17 +139,17 @@ class CListSockets : public CModule { CString GetSocketState(Csock* pSocket) { switch (pSocket->GetType()) { case Csock::LISTENER: - return "Listener"; + return t_s("Listener"); case Csock::INBOUND: - return "Inbound"; + return t_s("Inbound"); case Csock::OUTBOUND: if (pSocket->IsConnected()) - return "Outbound"; + return t_s("Outbound"); else - return "Connecting"; + return t_s("Connecting"); } - return "UNKNOWN"; + return t_s("UNKNOWN"); } CString GetCreatedTime(Csock* pSocket) { @@ -203,41 +202,46 @@ class CListSockets : public CModule { void ShowSocks(bool bShowHosts) { if (CZNC::Get().GetManager().empty()) { - PutStatus("You have no open sockets."); + PutStatus(t_s("You have no open sockets.")); return; } std::priority_queue socks = GetSockets(); CTable Table; - Table.AddColumn("Name"); - Table.AddColumn("Created"); - Table.AddColumn("State"); + Table.AddColumn(t_s("Name"); + Table.AddColumn(t_s("Created"); + Table.AddColumn(t_s("State"); #ifdef HAVE_LIBSSL - Table.AddColumn("SSL"); + Table.AddColumn(t_s("SSL"); #endif - Table.AddColumn("Local"); - Table.AddColumn("Remote"); - Table.AddColumn("In"); - Table.AddColumn("Out"); + Table.AddColumn(t_s("Local"); + Table.AddColumn(t_s("Remote"); + Table.AddColumn(t_s("In"); + Table.AddColumn(t_s("Out"); while (!socks.empty()) { Csock* pSocket = socks.top().GetSock(); socks.pop(); Table.AddRow(); - Table.SetCell("Name", pSocket->GetSockName()); - Table.SetCell("Created", GetCreatedTime(pSocket)); - Table.SetCell("State", GetSocketState(pSocket)); + Table.SetCell(t_s("Name", pSocket->GetSockName()); + Table.SetCell(t_s("Created", GetCreatedTime(pSocket)); + Table.SetCell(t_s("State", GetSocketState(pSocket)); #ifdef HAVE_LIBSSL - Table.SetCell("SSL", pSocket->GetSSL() ? "Yes" : "No"); + Table.SetCell(t_s("SSL", pSocket->GetSSL() + ? t_s("Yes", "ssl") + : t_s("No", "ssl")); #endif - Table.SetCell("Local", GetLocalHost(pSocket, bShowHosts)); - Table.SetCell("Remote", GetRemoteHost(pSocket, bShowHosts)); - Table.SetCell("In", CString::ToByteStr(pSocket->GetBytesRead())); - Table.SetCell("Out", + Table.SetCell(t_s("Local", + GetLocalHost(pSocket, bShowHosts)); + Table.SetCell(t_s("Remote", + GetRemoteHost(pSocket, bShowHosts)); + Table.SetCell(t_s("In", + CString::ToByteStr(pSocket->GetBytesRead())); + Table.SetCell(t_s("Out", CString::ToByteStr(pSocket->GetBytesWritten())); } @@ -253,4 +257,4 @@ void TModInfo(CModInfo& Info) { Info.SetWikiPage("listsockets"); } -USERMODULEDEFS(CListSockets, "List active sockets") +USERMODULEDEFS(CListSockets, t_s("Lists active sockets")) diff --git a/modules/log.cpp b/modules/log.cpp index 8fd2ba7b..b9232c72 100644 --- a/modules/log.cpp +++ b/modules/log.cpp @@ -51,41 +51,33 @@ class CLogRule { }; class CLogMod : public CModule { - void Set(const CString& sLine) { - const CString sVar = sLine.Token(1).AsLower(); - bool b = sLine.Token(2).ToBool(); - - if (sVar == "joins" || sVar == "quits" || sVar == "nickchanges") { - SetNV(sVar, CString(b)); - PutModule("Set " + sVar + " to " + CString(b)); - } else - PutModule(sVar + " is invalid."); - } - public: MODCONSTRUCTOR(CLogMod) { m_bSanitize = false; AddHelpCommand(); - AddCommand("SetRules", - static_cast(&CLogMod::SetRulesCmd), - "", - "Set logging rules, use !#chan or !query to negate and * " - "for wildcards"); - AddCommand("ClearRules", static_cast( - &CLogMod::ClearRulesCmd), - "", "Clear all logging rules"); - AddCommand("ListRules", - static_cast(&CLogMod::ListRulesCmd), - "", "List all logging rules"); AddCommand( - "Set", static_cast(&CLogMod::Set), - "boolean", - "Set one of the following booleans, joins, quits, nickchanges"); + "SetRules", t_d(""), + t_d("Set logging rules, use !#chan or !query to negate and * "), + [=](const CString& sLine) { SetRulesCmd(sLine); }); + AddCommand("ClearRules", "", t_d("Clear all logging rules"), + [=](const CString& sLine) { ClearRulesCmd(sLine); }); + AddCommand("ListRules", "", t_d("List all logging rules"), + [=](const CString& sLine) { ListRulesCmd(sLine); }); + AddCommand( + "Set", t_d(" true|false"), + t_d("Set one of the following options: joins, quits, nickchanges"), + [=](const CString& sLine) { SetCmd(sLine); }); + AddCommand("ShowSettings", "", + t_d("Show current settings set by Set command"), + [=](const CString& sLine) { ShowSettingsCmd(sLine); }); } void SetRulesCmd(const CString& sLine); void ClearRulesCmd(const CString& sLine); void ListRulesCmd(const CString& sLine = ""); + void SetCmd(const CString& sLine); + void ShowSettingsCmd(const CString& sLine); + void SetRules(const VCString& vsRules); VCString SplitRules(const CString& sRules) const; CString JoinRules(const CString& sSeparator) const; @@ -134,6 +126,10 @@ class CLogMod : public CModule { EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) override; private: + bool NeedJoins() const; + bool NeedQuits() const; + bool NeedNickChanges() const; + CString m_sLogPath; CString m_sTimestamp; bool m_bSanitize; @@ -144,8 +140,8 @@ void CLogMod::SetRulesCmd(const CString& sLine) { VCString vsRules = SplitRules(sLine.Token(1, true)); if (vsRules.empty()) { - PutModule("Usage: SetRules "); - PutModule("Wildcards are allowed"); + PutModule(t_s("Usage: SetRules ")); + PutModule(t_s("Wildcards are allowed")); } else { SetRules(vsRules); SetNV("rules", JoinRules(",")); @@ -157,33 +153,79 @@ void CLogMod::ClearRulesCmd(const CString& sLine) { size_t uCount = m_vRules.size(); if (uCount == 0) { - PutModule("No logging rules. Everything is logged."); + PutModule(t_s("No logging rules. Everything is logged.")); } else { CString sRules = JoinRules(" "); SetRules(VCString()); DelNV("rules"); - PutModule(CString(uCount) + " rule(s) removed: " + sRules); + PutModule(t_p("1 rule removed: {2}", "{1} rules removed: {2}", uCount)( + uCount, sRules)); } } void CLogMod::ListRulesCmd(const CString& sLine) { CTable Table; - Table.AddColumn("Rule"); - Table.AddColumn("Logging enabled"); + Table.AddColumn(t_s("Rule", "listrules")); + Table.AddColumn(t_s("Logging enabled", "listrules")); for (const CLogRule& Rule : m_vRules) { Table.AddRow(); - Table.SetCell("Rule", Rule.GetRule()); - Table.SetCell("Logging enabled", CString(Rule.IsEnabled())); + Table.SetCell(t_s("Rule", "listrules"), Rule.GetRule()); + Table.SetCell(t_s("Logging enabled", "listrules"), CString(Rule.IsEnabled())); } if (Table.empty()) { - PutModule("No logging rules. Everything is logged."); + PutModule(t_s("No logging rules. Everything is logged.")); } else { PutModule(Table); } } +void CLogMod::SetCmd(const CString& sLine) { + const CString sVar = sLine.Token(1).AsLower(); + const CString sValue = sLine.Token(2); + if (sValue.empty()) { + PutModule( + t_s("Usage: Set true|false, where is one of: joins, " + "quits, nickchanges")); + return; + } + bool b = sLine.Token(2).ToBool(); + const std::unordered_map> + mssResponses = { + {"joins", {t_s("Will log joins"), t_s("Will not log joins")}}, + {"quits", {t_s("Will log quits"), t_s("Will not log quits")}}, + {"nickchanges", + {t_s("Will log nick changes"), t_s("Will not log nick changes")}}}; + auto it = mssResponses.find(sVar); + if (it == mssResponses.end()) { + PutModule(t_s( + "Unknown variable. Known variables: joins, quits, nickchanges")); + return; + } + SetNV(sVar, CString(b)); + PutModule(b ? it->second.first : it->second.second); +} + +void CLogMod::ShowSettingsCmd(const CString& sLine) { + PutModule(NeedJoins() ? t_s("Logging joins") : t_s("Not logging joins")); + PutModule(NeedQuits() ? t_s("Logging quits") : t_s("Not logging quits")); + PutModule(NeedNickChanges() ? t_s("Logging nick changes") + : t_s("Not logging nick changes")); +} + +bool CLogMod::NeedJoins() const { + return !HasNV("joins") || GetNV("joins").ToBool(); +} + +bool CLogMod::NeedQuits() const { + return !HasNV("quits") || GetNV("quits").ToBool(); +} + +bool CLogMod::NeedNickChanges() const { + return !HasNV("nickchanges") || GetNV("nickchanges").ToBool(); +} + void CLogMod::SetRules(const VCString& vsRules) { m_vRules.clear(); @@ -281,7 +323,7 @@ CString CLogMod::GetServer() { CServer* pServer = GetNetwork()->GetCurrentServer(); CString sSSL; - if (!pServer) return "(no server)"; + if (!pServer) return ("(no server)"; if (pServer->IsSSL()) sSSL = "+"; return pServer->GetName() + " " + sSSL + CString(pServer->GetPort()); @@ -305,9 +347,9 @@ bool CLogMod::OnLoad(const CString& sArgs, CString& sMessage) { } else { // Only one arg may be LogPath if (bHaveLogPath) { - sMessage = "Invalid args [" + sArgs + - "]. Only one log path allowed. Check that there " - "are no spaces in the path."; + sMessage = + t_f("Invalid args [{1}]. Only one log path allowed. Check " + "that there are no spaces in the path.")(sArgs); return false; } m_sLogPath = sArg; @@ -356,15 +398,17 @@ bool CLogMod::OnLoad(const CString& sArgs, CString& sMessage) { // Check if it's allowed to write in this path in general m_sLogPath = CDir::CheckPathPrefix(GetSavePath(), m_sLogPath); if (m_sLogPath.empty()) { - sMessage = "Invalid log path [" + m_sLogPath + "]."; + sMessage = t_f("Invalid log path [{1}]")(m_sLogPath); return false; } else { - sMessage = "Logging to [" + m_sLogPath + "]. Using timestamp format '" + - m_sTimestamp + "'"; + sMessage = t_f("Logging to [{1}]. Using timestamp format '{2}'")( + m_sLogPath, m_sTimestamp); return true; } } +// TODO consider writing translated strings to log. Currently user language +// affects only UI. void CLogMod::OnIRCConnected() { PutLog("Connected to IRC (" + GetServer() + ")"); } @@ -393,7 +437,7 @@ void CLogMod::OnKick(const CNick& OpNick, const CString& sKickedNick, void CLogMod::OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { - if (!HasNV("quits") || GetNV("quits").ToBool()) { + if (NeedQuits()) { for (CChan* pChan : vChans) PutLog("*** Quits: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ") (" + sMessage + ")", @@ -413,10 +457,11 @@ CModule::EModRet CLogMod::OnSendToIRCMessage(CMessage& Message) { } void CLogMod::OnJoin(const CNick& Nick, CChan& Channel) { - if (!HasNV("joins") || GetNV("joins").ToBool()) + if (NeedJoins()) { PutLog("*** Joins: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ")", Channel); + } } void CLogMod::OnPart(const CNick& Nick, CChan& Channel, @@ -428,7 +473,7 @@ void CLogMod::OnPart(const CNick& Nick, CChan& Channel, void CLogMod::OnNick(const CNick& OldNick, const CString& sNewNick, const vector& vChans) { - if (!HasNV("nickchanges") || GetNV("nickchanges").ToBool()) { + if (NeedNickChanges()) { for (CChan* pChan : vChans) PutLog("*** " + OldNick.GetNick() + " is now known as " + sNewNick, *pChan); @@ -510,8 +555,9 @@ void TModInfo(CModInfo& Info) { Info.AddType(CModInfo::NetworkModule); Info.AddType(CModInfo::GlobalModule); Info.SetHasArgs(true); - Info.SetArgsHelpText("[-sanitize] Optional path where to store logs."); + Info.SetArgsHelpText( + Info.t_s("[-sanitize] Optional path where to store logs.")); Info.SetWikiPage("log"); } -USERMODULEDEFS(CLogMod, "Write IRC logs.") +USERMODULEDEFS(CLogMod, t_s("Writes IRC logs.")) diff --git a/modules/missingmotd.cpp b/modules/missingmotd.cpp index 6dd0ad6b..3210e88a 100644 --- a/modules/missingmotd.cpp +++ b/modules/missingmotd.cpp @@ -22,7 +22,8 @@ class CMissingMotd : public CModule { MODCONSTRUCTOR(CMissingMotd) {} void OnClientLogin() override { - PutUser(":irc.znc.in 422 " + GetClient()->GetNick() + " :MOTD File is missing"); + PutUser(":irc.znc.in 422 " + GetClient()->GetNick() + + " :MOTD File is missing"); } }; @@ -32,4 +33,4 @@ void TModInfo(CModInfo& Info) { Info.SetHasArgs(false); } -USERMODULEDEFS(CMissingMotd, "Sends 422 to clients when they login") +USERMODULEDEFS(CMissingMotd, t_s("Sends 422 to clients when they login")) diff --git a/modules/modules_online.cpp b/modules/modules_online.cpp index dc015db0..8a6fb217 100644 --- a/modules/modules_online.cpp +++ b/modules/modules_online.cpp @@ -114,4 +114,4 @@ void TModInfo(CModInfo& Info) { Info.SetWikiPage("modules_online"); } -NETWORKMODULEDEFS(CFOModule, "Make ZNC's *modules to be \"online\".") +NETWORKMODULEDEFS(CFOModule, t_s("Makes ZNC's *modules to be \"online\"."))
NameCreatedStateSSLLocalRemoteData InData Out