From ce31b29b68b62386292ea49cf60736fcb19a452a Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 20 Oct 2008 13:00:54 +0000 Subject: [PATCH] Some changes to the vhost interface from *status This adds AddVHost, RemVHost and ListVHosts. If this vhost list (which is the same webadmin uses for displaying drop-down lists) is none-empty, then users can only set one of these vhosts via SetVHost. If the list is empty, everything is allowed. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1256 726aef4b-f618-498e-8847-2d620e286838 --- ClientCommand.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++ znc.cpp | 11 +++++-- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/ClientCommand.cpp b/ClientCommand.cpp index f3f753ae..621600cb 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -749,6 +749,49 @@ void CClient::UserCommand(const CString& sLine) { PutStatus("Unable to unload [" + sMod + "] Modules are not enabled."); #endif return; + } else if (sCommand.Equals("ADDVHOST") && m_pUser->IsAdmin()) { + CString sVHost = sLine.Token(1); + + if (sVHost.empty()) { + PutStatus("Usage: AddVHost "); + return; + } + + if (CZNC::Get().AddVHost(sVHost)) { + PutStatus("Done"); + } else { + PutStatus("The VHost [" + sVHost + "] is already in the list"); + } + } else if ((sCommand.Equals("REMVHOST") || sCommand.Equals("DELVHOST")) && m_pUser->IsAdmin()) { + CString sVHost = sLine.Token(1); + + if (sVHost.empty()) { + PutStatus("Usage: RemVHost "); + return; + } + + if (CZNC::Get().RemVHost(sVHost)) { + PutStatus("Done"); + } else { + PutStatus("The VHost [" + sVHost + "] is not in the list"); + } + } else if (sCommand.Equals("LISTVHOSTS") && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { + const VCString& vsVHosts = CZNC::Get().GetVHosts(); + + if (vsVHosts.empty()) { + PutStatus("No VHosts configured"); + return; + } + + CTable Table; + Table.AddColumn("VHost"); + + VCString::const_iterator it; + for (it = vsVHosts.begin(); it != vsVHosts.end(); it++) { + Table.AddRow(); + Table.SetCell("VHost", *it); + } + PutStatus(Table); } else if (sCommand.Equals("SETVHOST") && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { CString sVHost = sLine.Token(1); @@ -757,6 +800,29 @@ void CClient::UserCommand(const CString& sLine) { return; } + if (sVHost.Equals(m_pUser->GetVHost())) { + PutStatus("You already have this VHost!"); + return; + } + + const VCString& vsVHosts = CZNC::Get().GetVHosts(); + if (!m_pUser->IsAdmin() && !vsVHosts.empty()) { + VCString::const_iterator it; + bool bFound = false; + + for (it = vsVHosts.begin(); it != vsVHosts.end(); it++) { + if (sVHost.Equals(*it)) { + bFound = true; + break; + } + } + + if (!bFound) { + PutStatus("You may not use this VHost. See [ListVHosts] for a list"); + return; + } + } + m_pUser->SetVHost(sVHost); PutStatus("Set VHost to [" + m_pUser->GetVHost() + "]"); } else if (sCommand.Equals("CLEARVHOST") && (m_pUser->IsAdmin() || !m_pUser->DenySetVHost())) { @@ -986,7 +1052,24 @@ void CClient::HelpUser() { Table.SetCell("Arguments", "<#chan> [linecount]"); Table.SetCell("Description", "Set the buffer count for a channel"); + if (m_pUser->IsAdmin()) { + Table.AddRow(); + Table.SetCell("Command", "AddVHost"); + Table.SetCell("Arguments", ""); + Table.SetCell("Description", "Adds a VHost for normal users to use"); + + Table.AddRow(); + Table.SetCell("Command", "RemVHost"); + Table.SetCell("Arguments", ""); + Table.SetCell("Description", "Removes a VHost from the list"); + } + if (m_pUser->IsAdmin() || !m_pUser->DenySetVHost()) { + Table.AddRow(); + Table.SetCell("Command", "ListVHosts"); + Table.SetCell("Arguments", ""); + Table.SetCell("Description", "Shows the configured list of vhosts"); + Table.AddRow(); Table.SetCell("Command", "SetVHost"); Table.SetCell("Arguments", ""); diff --git a/znc.cpp b/znc.cpp index da5c8d21..93b7a58e 100644 --- a/znc.cpp +++ b/znc.cpp @@ -1593,8 +1593,15 @@ bool CZNC::AddVHost(const CString& sHost) { } bool CZNC::RemVHost(const CString& sHost) { - // @todo - return true; + VCString::iterator it; + for (it = m_vsVHosts.begin(); it != m_vsVHosts.end(); it++) { + if (sHost.Equals(*it)) { + m_vsVHosts.erase(it); + return true; + } + } + + return false; } void CZNC::Broadcast(const CString& sMessage, bool bAdminOnly,