Log: add ShowSettings command, rework Set command, #601

Make more strings translateable, #1354
This commit is contained in:
Alexey Sokolov
2017-09-07 23:35:18 +01:00
parent 408e6e9f01
commit d51159a330
11 changed files with 173 additions and 113 deletions
+7 -6
View File
@@ -1,13 +1,14 @@
<? I18N znc-lastseen ?>
<? INC Header.tmpl ?>
<div class="toptable">
<table class="data">
<thead>
<tr>
<th>User</th>
<th>Last Seen</th>
<th>Info</th>
<? IF WebAdminLoaded ?><td>Action</td><? ENDIF ?>
<th><? FORMAT "User" ?></th>
<th><? FORMAT "Last Seen" ?></th>
<th><? FORMAT "Info" ?></th>
<? IF WebAdminLoaded ?><td><? FORMAT "Action" ?></td><? ENDIF ?>
</tr>
</thead>
<tbody>
@@ -17,8 +18,8 @@
<td><? VAR LastSeen DEFAULT="- unknown -" ?></td>
<td><? VAR Info ?></td>
<? IF WebAdminLoaded TOP ?><td><span class="nowrap">
[<a href="<? VAR URIPrefix TOP ?>/mods/global/webadmin/edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
<? IF !IsSelf ?>[<a href="<? VAR URIPrefix TOP ?>/mods/global/webadmin/deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
[<a href="<? VAR URIPrefix TOP ?>/mods/global/webadmin/edituser?user=<?VAR Username ESC=URL?>"><? FORMAT "Edit" ?></a>]
<? IF !IsSelf ?>[<a href="<? VAR URIPrefix TOP ?>/mods/global/webadmin/deluser?user=<?VAR Username ESC=URL?>"><? FORMAT "Delete" ?></a>]<? ENDIF ?>
</span></td><? ENDIF ?>
</tr>
<? ENDLOOP ?>
@@ -1,7 +1,9 @@
<? I18N znc-lastseen ?>
<div class="sectionbg">
<div class="sectionbody">
<div class="subsection">
<label id="last_login">Last login time:</label>
<label id="last_login"><? FORMAT "Last login time:" ?></label>
<span id="lastseen"><? VAR LastSeen DEFAULT="- unknown -" ?></span>
</div>
</div>
+9 -8
View File
@@ -1,16 +1,17 @@
<? I18N znc-listsockets ?>
<? INC Header.tmpl ?>
<table class="data">
<thead>
<tr>
<th>Name</th>
<th>Created</th>
<th>State</th>
<th>SSL</th>
<th>Local</th>
<th>Remote</th>
<th>Data In</th>
<th>Data Out</th>
<th><? FORMAT "Name" ?></th>
<th><? FORMAT "Created" ?></th>
<th><? FORMAT "State" ?></th>
<th><? FORMAT "SSL" ?></th>
<th><? FORMAT "Local" ?></th>
<th><? FORMAT "Remote" ?></th>
<th><? FORMAT "Data In" ?></th>
<th><? FORMAT "Data Out" ?></th>
</tr>
</thead>
<tbody>
+3 -3
View File
@@ -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;
}
+6 -3
View File
@@ -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("[<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);});
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 {}
+2 -1
View File
@@ -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;
}
}
+12 -11
View File
@@ -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<CModCommand::ModCmdFunc>(
&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<CLastSeenMod>(CModInfo& Info) {
}
GLOBALMODULEDEFS(CLastSeenMod,
"Collects data about when a user last logged in.")
t_s("Collects data about when a user last logged in."))
+35 -31
View File
@@ -59,17 +59,15 @@ class CListSockets : public CModule {
public:
MODCONSTRUCTOR(CListSockets) {
AddHelpCommand();
AddCommand(
"List",
static_cast<CModCommand::ModCmdFunc>(&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<CSocketSorter> 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<CListSockets>(CModInfo& Info) {
Info.SetWikiPage("listsockets");
}
USERMODULEDEFS(CListSockets, "List active sockets")
USERMODULEDEFS(CListSockets, t_s("Lists active sockets"))
+92 -46
View File
@@ -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<CModCommand::ModCmdFunc>(&CLogMod::SetRulesCmd),
"<rules>",
"Set logging rules, use !#chan or !query to negate and * "
"for wildcards");
AddCommand("ClearRules", static_cast<CModCommand::ModCmdFunc>(
&CLogMod::ClearRulesCmd),
"", "Clear all logging rules");
AddCommand("ListRules",
static_cast<CModCommand::ModCmdFunc>(&CLogMod::ListRulesCmd),
"", "List all logging rules");
AddCommand(
"Set", static_cast<CModCommand::ModCmdFunc>(&CLogMod::Set),
"boolean",
"Set one of the following booleans, joins, quits, nickchanges");
"SetRules", t_d("<rules>"),
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("<var> 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 <rules>");
PutModule("Wildcards are allowed");
PutModule(t_s("Usage: SetRules <rules>"));
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 <var> true|false, where <var> is one of: joins, "
"quits, nickchanges"));
return;
}
bool b = sLine.Token(2).ToBool();
const std::unordered_map<CString, std::pair<CString, CString>>
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<CChan*>& 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<CChan*>& 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<CLogMod>(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."))
+3 -2
View File
@@ -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<CMissingMotd>(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"))
+1 -1
View File
@@ -114,4 +114,4 @@ void TModInfo<CFOModule>(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\"."))