mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
clang-format: switch tabs to spaces
I like tabs, but I have to admit that spaces make source code more consistent, because every editor/viewer tends to render tabs differently :(
This commit is contained in:
@@ -23,192 +23,192 @@ using std::vector;
|
||||
|
||||
class CBlockUser : public CModule {
|
||||
public:
|
||||
MODCONSTRUCTOR(CBlockUser) {
|
||||
AddHelpCommand();
|
||||
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CBlockUser::OnListCommand),
|
||||
"", "List blocked users");
|
||||
AddCommand("Block", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CBlockUser::OnBlockCommand),
|
||||
"<user>", "Block a user");
|
||||
AddCommand("Unblock", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CBlockUser::OnUnblockCommand),
|
||||
"<user>", "Unblock a user");
|
||||
}
|
||||
MODCONSTRUCTOR(CBlockUser) {
|
||||
AddHelpCommand();
|
||||
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CBlockUser::OnListCommand),
|
||||
"", "List blocked users");
|
||||
AddCommand("Block", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CBlockUser::OnBlockCommand),
|
||||
"<user>", "Block a user");
|
||||
AddCommand("Unblock", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CBlockUser::OnUnblockCommand),
|
||||
"<user>", "Unblock a user");
|
||||
}
|
||||
|
||||
virtual ~CBlockUser() {}
|
||||
virtual ~CBlockUser() {}
|
||||
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
VCString vArgs;
|
||||
VCString::iterator it;
|
||||
MCString::iterator it2;
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
VCString vArgs;
|
||||
VCString::iterator it;
|
||||
MCString::iterator it2;
|
||||
|
||||
// Load saved settings
|
||||
for (it2 = BeginNV(); it2 != EndNV(); ++it2) {
|
||||
// Ignore errors
|
||||
Block(it2->first);
|
||||
}
|
||||
// Load saved settings
|
||||
for (it2 = BeginNV(); it2 != EndNV(); ++it2) {
|
||||
// Ignore errors
|
||||
Block(it2->first);
|
||||
}
|
||||
|
||||
// Parse arguments, each argument is a user name to block
|
||||
sArgs.Split(" ", vArgs, false);
|
||||
// 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)) {
|
||||
sMessage = "Could not block [" + *it + "]";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (it = vArgs.begin(); it != vArgs.end(); ++it) {
|
||||
if (!Block(*it)) {
|
||||
sMessage = "Could not block [" + *it + "]";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) override {
|
||||
if (IsBlocked(Auth->GetUsername())) {
|
||||
Auth->RefuseLogin(MESSAGE);
|
||||
return HALT;
|
||||
}
|
||||
EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) override {
|
||||
if (IsBlocked(Auth->GetUsername())) {
|
||||
Auth->RefuseLogin(MESSAGE);
|
||||
return HALT;
|
||||
}
|
||||
|
||||
return CONTINUE;
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) override {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
} else {
|
||||
HandleCommand(sCommand);
|
||||
}
|
||||
}
|
||||
void OnModCommand(const CString& sCommand) override {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Access denied");
|
||||
} else {
|
||||
HandleCommand(sCommand);
|
||||
}
|
||||
}
|
||||
|
||||
void OnListCommand(const CString& sCommand) {
|
||||
CTable Table;
|
||||
MCString::iterator it;
|
||||
void OnListCommand(const CString& sCommand) {
|
||||
CTable Table;
|
||||
MCString::iterator it;
|
||||
|
||||
Table.AddColumn("Blocked user");
|
||||
Table.AddColumn("Blocked user");
|
||||
|
||||
for (it = BeginNV(); it != EndNV(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Blocked user", it->first);
|
||||
}
|
||||
for (it = BeginNV(); it != EndNV(); ++it) {
|
||||
Table.AddRow();
|
||||
Table.SetCell("Blocked user", it->first);
|
||||
}
|
||||
|
||||
if (PutModule(Table) == 0) PutModule("No users blocked");
|
||||
}
|
||||
if (PutModule(Table) == 0) PutModule("No users blocked");
|
||||
}
|
||||
|
||||
void OnBlockCommand(const CString& sCommand) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
void OnBlockCommand(const CString& sCommand) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: Block <user>");
|
||||
return;
|
||||
}
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: Block <user>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetUser()->GetUserName().Equals(sUser)) {
|
||||
PutModule("You can't block yourself");
|
||||
return;
|
||||
}
|
||||
if (GetUser()->GetUserName().Equals(sUser)) {
|
||||
PutModule("You can't block yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Block(sUser))
|
||||
PutModule("Blocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("Could not block [" + sUser + "] (misspelled?)");
|
||||
}
|
||||
if (Block(sUser))
|
||||
PutModule("Blocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("Could not block [" + sUser + "] (misspelled?)");
|
||||
}
|
||||
|
||||
void OnUnblockCommand(const CString& sCommand) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
void OnUnblockCommand(const CString& sCommand) {
|
||||
CString sUser = sCommand.Token(1, true);
|
||||
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: Unblock <user>");
|
||||
return;
|
||||
}
|
||||
if (sUser.empty()) {
|
||||
PutModule("Usage: Unblock <user>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (DelNV(sUser))
|
||||
PutModule("Unblocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("This user is not blocked");
|
||||
}
|
||||
if (DelNV(sUser))
|
||||
PutModule("Unblocked [" + sUser + "]");
|
||||
else
|
||||
PutModule("This user is not blocked");
|
||||
}
|
||||
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName,
|
||||
CTemplate& Tmpl) override {
|
||||
if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) {
|
||||
CString sAction = Tmpl["WebadminAction"];
|
||||
if (sAction == "display") {
|
||||
Tmpl["Blocked"] = CString(IsBlocked(Tmpl["Username"]));
|
||||
Tmpl["Self"] = CString(Tmpl["Username"].Equals(
|
||||
WebSock.GetSession()->GetUser()->GetUserName()));
|
||||
return true;
|
||||
}
|
||||
if (sAction == "change" &&
|
||||
WebSock.GetParam("embed_blockuser_presented").ToBool()) {
|
||||
if (Tmpl["Username"].Equals(
|
||||
WebSock.GetSession()->GetUser()->GetUserName()) &&
|
||||
WebSock.GetParam("embed_blockuser_block").ToBool()) {
|
||||
WebSock.GetSession()->AddError("You can't block yourself");
|
||||
} else if (WebSock.GetParam("embed_blockuser_block").ToBool()) {
|
||||
if (!WebSock.GetParam("embed_blockuser_old").ToBool()) {
|
||||
if (Block(Tmpl["Username"])) {
|
||||
WebSock.GetSession()->AddSuccess(
|
||||
"Blocked [" + Tmpl["Username"] + "]");
|
||||
} else {
|
||||
WebSock.GetSession()->AddError(
|
||||
"Couldn't block [" + Tmpl["Username"] + "]");
|
||||
}
|
||||
}
|
||||
} else if (WebSock.GetParam("embed_blockuser_old").ToBool()) {
|
||||
if (DelNV(Tmpl["Username"])) {
|
||||
WebSock.GetSession()->AddSuccess(
|
||||
"Unblocked [" + Tmpl["Username"] + "]");
|
||||
} else {
|
||||
WebSock.GetSession()->AddError(
|
||||
"User [" + Tmpl["Username"] + "is not blocked");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName,
|
||||
CTemplate& Tmpl) override {
|
||||
if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) {
|
||||
CString sAction = Tmpl["WebadminAction"];
|
||||
if (sAction == "display") {
|
||||
Tmpl["Blocked"] = CString(IsBlocked(Tmpl["Username"]));
|
||||
Tmpl["Self"] = CString(Tmpl["Username"].Equals(
|
||||
WebSock.GetSession()->GetUser()->GetUserName()));
|
||||
return true;
|
||||
}
|
||||
if (sAction == "change" &&
|
||||
WebSock.GetParam("embed_blockuser_presented").ToBool()) {
|
||||
if (Tmpl["Username"].Equals(
|
||||
WebSock.GetSession()->GetUser()->GetUserName()) &&
|
||||
WebSock.GetParam("embed_blockuser_block").ToBool()) {
|
||||
WebSock.GetSession()->AddError("You can't block yourself");
|
||||
} else if (WebSock.GetParam("embed_blockuser_block").ToBool()) {
|
||||
if (!WebSock.GetParam("embed_blockuser_old").ToBool()) {
|
||||
if (Block(Tmpl["Username"])) {
|
||||
WebSock.GetSession()->AddSuccess(
|
||||
"Blocked [" + Tmpl["Username"] + "]");
|
||||
} else {
|
||||
WebSock.GetSession()->AddError(
|
||||
"Couldn't block [" + Tmpl["Username"] + "]");
|
||||
}
|
||||
}
|
||||
} else if (WebSock.GetParam("embed_blockuser_old").ToBool()) {
|
||||
if (DelNV(Tmpl["Username"])) {
|
||||
WebSock.GetSession()->AddSuccess(
|
||||
"Unblocked [" + Tmpl["Username"] + "]");
|
||||
} else {
|
||||
WebSock.GetSession()->AddError(
|
||||
"User [" + Tmpl["Username"] + "is not blocked");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool IsBlocked(const CString& sUser) {
|
||||
MCString::iterator it;
|
||||
for (it = BeginNV(); it != EndNV(); ++it) {
|
||||
if (sUser == it->first) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool IsBlocked(const CString& sUser) {
|
||||
MCString::iterator it;
|
||||
for (it = BeginNV(); it != EndNV(); ++it) {
|
||||
if (sUser == it->first) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Block(const CString& sUser) {
|
||||
CUser* pUser = CZNC::Get().FindUser(sUser);
|
||||
bool Block(const CString& sUser) {
|
||||
CUser* pUser = CZNC::Get().FindUser(sUser);
|
||||
|
||||
if (!pUser) return false;
|
||||
if (!pUser) 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)->Close(Csock::CLT_AFTERWRITE);
|
||||
}
|
||||
// Disconnect all clients
|
||||
vector<CClient*> vpClients = pUser->GetAllClients();
|
||||
vector<CClient*>::iterator it;
|
||||
for (it = vpClients.begin(); it != vpClients.end(); ++it) {
|
||||
(*it)->PutStatusNotice(MESSAGE);
|
||||
(*it)->Close(Csock::CLT_AFTERWRITE);
|
||||
}
|
||||
|
||||
// Disconnect all networks from irc
|
||||
vector<CIRCNetwork*> vNetworks = pUser->GetNetworks();
|
||||
for (vector<CIRCNetwork*>::iterator it2 = vNetworks.begin();
|
||||
it2 != vNetworks.end(); ++it2) {
|
||||
(*it2)->SetIRCConnectEnabled(false);
|
||||
}
|
||||
// Disconnect all networks from irc
|
||||
vector<CIRCNetwork*> vNetworks = pUser->GetNetworks();
|
||||
for (vector<CIRCNetwork*>::iterator it2 = vNetworks.begin();
|
||||
it2 != vNetworks.end(); ++it2) {
|
||||
(*it2)->SetIRCConnectEnabled(false);
|
||||
}
|
||||
|
||||
SetNV(pUser->GetUserName(), "");
|
||||
return true;
|
||||
}
|
||||
SetNV(pUser->GetUserName(), "");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
void TModInfo<CBlockUser>(CModInfo& Info) {
|
||||
Info.SetWikiPage("blockuser");
|
||||
Info.SetHasArgs(true);
|
||||
Info.SetArgsHelpText(
|
||||
"Enter one or more user names. Separate them by spaces.");
|
||||
Info.SetWikiPage("blockuser");
|
||||
Info.SetHasArgs(true);
|
||||
Info.SetArgsHelpText(
|
||||
"Enter one or more user names. Separate them by spaces.");
|
||||
}
|
||||
|
||||
GLOBALMODULEDEFS(CBlockUser, "Block certain users from logging in.")
|
||||
|
||||
Reference in New Issue
Block a user