/*
- * Copyright (C) 2004-2011 See the AUTHORS file for details.
+ * Copyright (C) 2004-2013 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
*
* Quiet Away and message logger
* Author: imaginos <imaginos@imaginos.net>
+ *
+ * I originally wrote this module for when I had multiple clients connected to ZNC. I would leave work and forget to close my client, arriving at home
+ * and re-attaching there someone may have messaged me in commute and I wouldn't know it until I would arrive back at work the next day. I wrote it such that
+ * my xchat client would monitor desktop activity and ping the module to let it know I was active. Within a few minutes of inactivity the pinging stops and
+ * the away module sets the user as away and logging commences.
*/
#define REQUIRESSL
-#include "Client.h"
-#include "User.h"
-#include "FileUtils.h"
+#include <znc/Client.h>
+#include <znc/User.h>
+#include <znc/IRCNetwork.h>
+#include <znc/FileUtils.h>
#include <sys/stat.h>
+using std::vector;
+using std::map;
+
#define CRYPT_VERIFICATION_TOKEN "::__:AWAY:__::"
class CAway;
void AddMessage(time_t iTime, const CNick & Nick, CString & sMessage)
{
- if (m_pUser && Nick.GetNick() == m_pUser->GetIRCNick().GetNick())
+ if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick())
return; // ignore messages from self
AddMessage(CString(iTime) + ":" + Nick.GetNickMask() + ":" + sMessage);
}
}
}
-MODULEDEFS(CAway, "You don't need this module, ZNC works ok without it")
+template<> void TModInfo<CAway>(CModInfo& Info) {
+ Info.SetWikiPage("awaystore");
+ Info.SetHasArgs(true);
+ Info.SetArgsHelpText("[ -notimer | -timer N ] passw0rd . N is number of seconds, 600 by default.");
+}
+
+NETWORKMODULEDEFS(CAway, "Adds auto-away with logging, useful when you use ZNC from different locations");
using std::vector;
-#define MESSAGE "Your account has been disabled. Contact your administrator."
+#define MESSAGE "Your account has been disabled: "
class CBlockUser : public CModule {
public:
// Load saved settings
for (it2 = BeginNV(); it2 != EndNV(); ++it2) {
// Ignore errors
- Block(it2->first);
+ Block(it2->first, it2->second);
}
// Parse arguments, each argument is a user name to block
sArgs.Split(" ", vArgs, false);
for (it = vArgs.begin(); it != vArgs.end(); ++it) {
- if (!Block(*it)) {
+ if (!Block(*it, "no reason")) {
sMessage = "Could not block [" + *it + "]";
return false;
}
MCString::iterator it;
Table.AddColumn("Blocked user");
+ Table.AddColumn("Reason");
for (it = BeginNV(); it != EndNV(); ++it) {
Table.AddRow();
Table.SetCell("Blocked user", it->first);
+ Table.SetCell("Reason", it->second);
}
if (PutModule(Table) == 0)
return;
}
- if (Block(sUser))
+ if (Block(sUser, sCommand.Token(2, true)))
PutModule("Blocked [" + sUser + "]");
else
PutModule("Could not block [" + sUser + "] (misspelled?)");
}
}
+#if 0
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) {
CString sAction = Tmpl["WebadminAction"];
}
return false;
}
+#endif
private:
bool IsBlocked(const CString& sUser) {
return false;
}
- bool Block(const CString& sUser) {
+ bool Block(const CString& sUser, const CString &reason) {
CUser *pUser = CZNC::Get().FindUser(sUser);
- if (!pUser)
+ if (!pUser || reason.empty())
return false;
// Disconnect all clients
vector<CClient*> vpClients = pUser->GetAllClients();
vector<CClient*>::iterator it;
for (it = vpClients.begin(); it != vpClients.end(); ++it) {
- (*it)->PutStatusNotice(MESSAGE);
+ (*it)->PutStatusNotice(MESSAGE + reason);
(*it)->Close(Csock::CLT_AFTERWRITE);
}
(*it2)->SetIRCConnectEnabled(false);
}
- SetNV(pUser->GetUserName(), "");
+ SetNV(pUser->GetUserName(), reason);
return true;
}
};