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
This commit is contained in:
psychon
2008-10-20 13:00:54 +00:00
parent fa2a9819d0
commit ce31b29b68
2 changed files with 92 additions and 2 deletions

View File

@@ -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 <VHost>");
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 <VHost>");
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", "<vhost (ip preferred)>");
Table.SetCell("Description", "Adds a VHost for normal users to use");
Table.AddRow();
Table.SetCell("Command", "RemVHost");
Table.SetCell("Arguments", "<vhost>");
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", "<vhost (ip preferred)>");