From 5370a5401294bdd9414b8015083952ba96db00f4 Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 18 Jan 2008 22:18:36 +0000 Subject: [PATCH] Add DenySetVHost patch from Veit Wahlich aka cru git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@925 726aef4b-f618-498e-8847-2d620e286838 --- AUTHORS | 3 +++ Client.cpp | 12 +++++++----- User.cpp | 5 +++++ User.h | 3 +++ modules/webadmin.cpp | 32 +++++++++++++++++++++++++------- znc.cpp | 3 +++ 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/AUTHORS b/AUTHORS index 774d6aea..7802777f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -40,3 +40,6 @@ Zack3000 - BetaTester, ShellProvider d4n13L - WebDesigner Contributed graphiX webadmin skin + +Veit "Cru" Wahlich - Patches + Implementation of "Deny SetVHost" capabilities in znc and webadmin diff --git a/Client.cpp b/Client.cpp index 87ab28e1..d02e2874 100644 --- a/Client.cpp +++ b/Client.cpp @@ -1304,7 +1304,7 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Unable to unload [" + sMod + "] Modules are not enabled."); #endif return; - } else if (sCommand.CaseCmp("SETVHOST") == 0) { + } else if (sCommand.CaseCmp("SETVHOST") == 0 && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { CString sVHost = sLine.Token(1); if (sVHost.empty()) { @@ -1540,10 +1540,12 @@ void CClient::HelpUser() { Table.SetCell("Arguments", "<#chan> [linecount]"); Table.SetCell("Description", "Set the buffer count for a channel"); - Table.AddRow(); - Table.SetCell("Command", "SetVHost"); - Table.SetCell("Arguments", ""); - Table.SetCell("Description", "Set the VHost for this connection"); + if (m_pUser->IsAdmin() || !m_pUser->DenySetVHost()) { + Table.AddRow(); + Table.SetCell("Command", "SetVHost"); + Table.SetCell("Arguments", ""); + Table.SetCell("Description", "Set the VHost for this connection"); + } Table.AddRow(); Table.SetCell("Command", "Jump"); diff --git a/User.cpp b/User.cpp index cc33e720..bb7262a6 100644 --- a/User.cpp +++ b/User.cpp @@ -37,6 +37,7 @@ CUser::CUser(const CString& sUserName) { m_bKeepNick = false; m_bDenyLoadMod = false; m_bAdmin= false; + m_bDenySetVHost= false; m_sStatusPrefix = "*"; m_sChanPrefixes = "#&"; m_uBufferCount = 50; @@ -399,6 +400,7 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet) { SetUseClientIP(User.UseClientIP()); SetDenyLoadMod(User.DenyLoadMod()); SetAdmin(User.IsAdmin()); + SetDenySetVHost(User.DenySetVHost()); SetTimestampAppend(User.GetTimestampAppend()); SetTimestampPrepend(User.GetTimestampPrepend()); SetTimestampFormat(User.GetTimestampFormat()); @@ -544,6 +546,7 @@ bool CUser::WriteConfig(CFile& File) { PrintLine(File, "AutoCycle", CString((AutoCycle()) ? "true" : "false")); PrintLine(File, "DenyLoadMod", CString((DenyLoadMod()) ? "true" : "false")); PrintLine(File, "Admin", CString((IsAdmin()) ? "true" : "false")); + PrintLine(File, "DenySetVHost", CString((DenySetVHost()) ? "true" : "false")); PrintLine(File, "DCCLookupMethod", CString((UseClientIP()) ? "client" : "default")); PrintLine(File, "TimestampFormat", GetTimestampFormat()); PrintLine(File, "AppendTimestamp", CString((GetTimestampAppend()) ? "true" : "false")); @@ -983,6 +986,7 @@ void CUser::SetUseClientIP(bool b) { m_bUseClientIP = b; } void CUser::SetKeepNick(bool b) { m_bKeepNick = b; } void CUser::SetDenyLoadMod(bool b) { m_bDenyLoadMod = b; } void CUser::SetAdmin(bool b) { m_bAdmin = b; } +void CUser::SetDenySetVHost(bool b) { m_bDenySetVHost = b; } void CUser::SetDefaultChanModes(const CString& s) { m_sDefaultChanModes = s; } void CUser::SetIRCServer(const CString& s) { m_sIRCServer = s; m_bIRCConnected = true; } void CUser::SetQuitMsg(const CString& s) { m_sQuitMsg = s; } @@ -1053,6 +1057,7 @@ bool CUser::UseClientIP() const { return m_bUseClientIP; } bool CUser::GetKeepNick() const { return m_bKeepNick; } bool CUser::DenyLoadMod() const { return m_bDenyLoadMod; } bool CUser::IsAdmin() const { return m_bAdmin; } +bool CUser::DenySetVHost() const { return m_bDenySetVHost; } bool CUser::MultiClients() const { return m_bMultiClients; } bool CUser::BounceDCCs() const { return m_bBounceDCCs; } const CString& CUser::GetStatusPrefix() const { return m_sStatusPrefix; } diff --git a/User.h b/User.h index bad94ef9..925598ce 100644 --- a/User.h +++ b/User.h @@ -125,6 +125,7 @@ public: void SetKeepNick(bool b); void SetDenyLoadMod(bool b); void SetAdmin(bool b); + void SetDenySetVHost(bool b); bool SetStatusPrefix(const CString& s); void SetDefaultChanModes(const CString& s); void SetIRCNick(const CNick& n); @@ -173,6 +174,7 @@ public: bool GetKeepNick() const; bool DenyLoadMod() const; bool IsAdmin() const; + bool DenySetVHost() const; bool BounceDCCs() const; bool MultiClients() const; const CString& GetStatusPrefix() const; @@ -230,6 +232,7 @@ protected: bool m_bKeepNick; bool m_bDenyLoadMod; bool m_bAdmin; + bool m_bDenySetVHost; bool m_bKeepBuffer; bool m_bAutoCycle; bool m_bBeingDeleted; diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index 1e5c5976..80031ade 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -855,15 +855,18 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) { m_Template["StatusPrefix"] = "*"; } + // To change VHosts be admin or don't have DenySetVHost const VCString& vsVHosts = CZNC::Get().GetVHosts(); - for (unsigned int b = 0; b < vsVHosts.size(); b++) { - const CString& sVHost = vsVHosts[b]; - CTemplate& l = m_Template.AddRow("VHostLoop"); + if (IsAdmin() || !m_pSessionUser->DenySetVHost()) { + for (unsigned int b = 0; b < vsVHosts.size(); b++) { + const CString& sVHost = vsVHosts[b]; + CTemplate& l = m_Template.AddRow("VHostLoop"); - l["VHost"] = sVHost; + l["VHost"] = sVHost; - if (pUser && pUser->GetVHost() == sVHost) { - l["Checked"] = "true"; + if (pUser && pUser->GetVHost() == sVHost) { + l["Checked"] = "true"; + } } } @@ -938,6 +941,11 @@ bool CWebAdminSock::UserPage(CString& sPageRet, CUser* pUser) { o10["DisplayName"] = "Admin"; if (pUser && pUser->IsAdmin()) { o10["Checked"] = "true"; } if (pUser && pUser == CZNC::Get().FindUser(GetUser())) { o10["Disabled"] = "true"; } + + CTemplate& o11 = m_Template.AddRow("OptionLoop"); + o11["Name"] = "denysetvhost"; + o11["DisplayName"] = "Deny SetVHost"; + if (pUser && pUser->DenySetVHost()) { o11["Checked"] = "true"; } } PrintPage(sPageRet, "UserPage.tmpl"); @@ -1087,11 +1095,19 @@ CUser* CWebAdminSock::GetNewUser(CString& sPageRet, CUser* pUser) { sArg = GetParam("statusprefix"); if (!sArg.empty()) { pNewUser->SetStatusPrefix(sArg); } sArg = GetParam("ident"); if (!sArg.empty()) { pNewUser->SetIdent(sArg); } sArg = GetParam("realname"); if (!sArg.empty()) { pNewUser->SetRealName(sArg); } - sArg = GetParam("vhost"); if (!sArg.empty()) { pNewUser->SetVHost(sArg); } sArg = GetParam("quitmsg"); if (!sArg.empty()) { pNewUser->SetQuitMsg(sArg); } sArg = GetParam("chanmodes"); if (!sArg.empty()) { pNewUser->SetDefaultChanModes(sArg); } sArg = GetParam("timestampformat"); if (!sArg.empty()) { pNewUser->SetTimestampFormat(sArg); } + sArg = GetParam("vhost"); + // To change VHosts be admin or don't have DenySetVHost + if (IsAdmin() || !m_pSessionUser->DenySetVHost()) { + if (!sArg.empty()) + pNewUser->SetVHost(sArg); + } else if (pUser){ + pNewUser->SetVHost(pUser->GetVHost()); + } + pNewUser->SetBufferCount(GetParam("bufsize").ToUInt()); pNewUser->SetKeepBuffer(GetParam("keepbuffer").ToBool()); pNewUser->SetMultiClients(GetParam("multiclients").ToBool()); @@ -1104,8 +1120,10 @@ CUser* CWebAdminSock::GetNewUser(CString& sPageRet, CUser* pUser) { if (IsAdmin()) { pNewUser->SetDenyLoadMod(GetParam("denyloadmod").ToBool()); + pNewUser->SetDenySetVHost(GetParam("denysetvhost").ToBool()); } else if (pUser) { pNewUser->SetDenyLoadMod(pUser->DenyLoadMod()); + pNewUser->SetDenySetVHost(pUser->DenySetVHost()); } if (pUser && pUser != CZNC::Get().FindUser(GetUser())) { diff --git a/znc.cpp b/znc.cpp index 556d5e29..8e554e5d 100644 --- a/znc.cpp +++ b/znc.cpp @@ -982,6 +982,9 @@ bool CZNC::ParseConfig(const CString& sConfig) { } else if (sName.CaseCmp("Admin") == 0) { pUser->SetAdmin((sValue.CaseCmp("TRUE") == 0)); continue; + } else if (sName.CaseCmp("DenySetVHost") == 0) { + pUser->SetDenySetVHost((sValue.CaseCmp("TRUE") == 0)); + continue; } else if (sName.CaseCmp("StatusPrefix") == 0) { if (!pUser->SetStatusPrefix(sValue)) { CUtils::PrintError("Invalid StatusPrefix [" + sValue + "] Must be 1-5 chars, no spaces.");