Remove flawed Add/Del/List/BindHost(s) (close #983)

This commit is contained in:
J-P Nurmi
2015-08-17 15:22:20 +02:00
parent 6bfe7d840f
commit d19a040f2d
8 changed files with 28 additions and 314 deletions
-82
View File
@@ -1207,48 +1207,6 @@ void CClient::UserCommand(CString& sLine) {
} else {
PutStatus("Done, but there were errors, [" + sMod + "] could not be loaded everywhere.");
}
} else if ((sCommand.Equals("ADDBINDHOST") || sCommand.Equals("ADDVHOST")) && m_pUser->IsAdmin()) {
CString sHost = sLine.Token(1);
if (sHost.empty()) {
PutStatus("Usage: AddBindHost <host>");
return;
}
if (CZNC::Get().AddBindHost(sHost)) {
PutStatus("Done");
} else {
PutStatus("The host [" + sHost + "] is already in the list");
}
} else if ((sCommand.Equals("REMBINDHOST") || sCommand.Equals("DELBINDHOST") || sCommand.Equals("REMVHOST") || sCommand.Equals("DELVHOST")) && m_pUser->IsAdmin()) {
CString sHost = sLine.Token(1);
if (sHost.empty()) {
PutStatus("Usage: DelBindHost <host>");
return;
}
if (CZNC::Get().RemBindHost(sHost)) {
PutStatus("Done");
} else {
PutStatus("The host [" + sHost + "] is not in the list");
}
} else if ((sCommand.Equals("LISTBINDHOSTS") || sCommand.Equals("LISTVHOSTS")) && (m_pUser->IsAdmin() || !m_pUser->DenySetBindHost())) {
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (vsHosts.empty()) {
PutStatus("No bind hosts configured");
return;
}
CTable Table;
Table.AddColumn("Host");
for (const CString& sHost : vsHosts) {
Table.AddRow();
Table.SetCell("Host", sHost);
}
PutStatus(Table);
} else if ((sCommand.Equals("SETBINDHOST") || sCommand.Equals("SETVHOST")) && (m_pUser->IsAdmin() || !m_pUser->DenySetBindHost())) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command. Try SetUserBindHost instead");
@@ -1266,23 +1224,6 @@ void CClient::UserCommand(CString& sLine) {
return;
}
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (!m_pUser->IsAdmin() && !vsHosts.empty()) {
bool bFound = false;
for (const CString& sHost : vsHosts) {
if (sArg.Equals(sHost)) {
bFound = true;
break;
}
}
if (!bFound) {
PutStatus("You may not use this bind host. See [ListBindHosts] for a list");
return;
}
}
m_pNetwork->SetBindHost(sArg);
PutStatus("Set bind host for network [" + m_pNetwork->GetName() + "] to [" + m_pNetwork->GetBindHost() + "]");
} else if (sCommand.Equals("SETUSERBINDHOST") && (m_pUser->IsAdmin() || !m_pUser->DenySetBindHost())) {
@@ -1298,23 +1239,6 @@ void CClient::UserCommand(CString& sLine) {
return;
}
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (!m_pUser->IsAdmin() && !vsHosts.empty()) {
bool bFound = false;
for (const CString& sHost : vsHosts) {
if (sArg.Equals(sHost)) {
bFound = true;
break;
}
}
if (!bFound) {
PutStatus("You may not use this bind host. See [ListBindHosts] for a list");
return;
}
}
m_pUser->SetBindHost(sArg);
PutStatus("Set bind host to [" + m_pUser->GetBindHost() + "]");
} else if ((sCommand.Equals("CLEARBINDHOST") || sCommand.Equals("CLEARVHOST")) && (m_pUser->IsAdmin() || !m_pUser->DenySetBindHost())) {
@@ -1682,13 +1606,7 @@ void CClient::HelpUser(const CString& sFilter) {
AddCommandHelp(Table, "ClearAllQueryBuffers", "", "Clear the query buffers", sFilter);
AddCommandHelp(Table, "SetBuffer", "<#chan|query> [linecount]", "Set the buffer count", sFilter);
if (m_pUser->IsAdmin()) {
AddCommandHelp(Table, "AddBindHost", "<host (IP preferred)>", "Adds a bind host for normal users to use", sFilter);
AddCommandHelp(Table, "DelBindHost", "<host>", "Removes a bind host from the list", sFilter);
}
if (m_pUser->IsAdmin() || !m_pUser->DenySetBindHost()) {
AddCommandHelp(Table, "ListBindHosts", "", "Shows the configured list of bind hosts", sFilter);
AddCommandHelp(Table, "SetBindHost", "<host (IP preferred)>", "Set the bind host for this connection", sFilter);
AddCommandHelp(Table, "SetUserBindHost", "<host (IP preferred)>", "Set the default bind host for this user", sFilter);
AddCommandHelp(Table, "ClearBindHost", "", "Clear the bind host for this connection", sFilter);
+11 -44
View File
@@ -510,10 +510,6 @@ bool CZNC::WriteConfig() {
config.AddKeyValuePair("Motd", sLine.FirstLine());
}
for (const CString& sHost : m_vsBindHosts) {
config.AddKeyValuePair("BindHost", sHost.FirstLine());
}
for (const CString& sProxy : m_vsTrustedProxies) {
config.AddKeyValuePair("TrustedProxy", sProxy.FirstLine());
}
@@ -1059,10 +1055,17 @@ bool CZNC::LoadGlobal(CConfig& config, CString& sError) {
AddMotd(sMotd);
}
m_vsBindHosts.clear();
config.FindStringVector("bindhost", vsList);
for (const CString& sHost : vsList) {
AddBindHost(sHost);
if (config.FindStringVector("bindhost", vsList)) {
CUtils::PrintStatus(false, "WARNING: the global BindHost list is deprecated. Ignoring the following lines:");
for (const CString& sHost : vsList) {
CUtils::PrintStatus(false, "BindHost = " + sHost);
}
}
if (config.FindStringVector("vhost", vsList)) {
CUtils::PrintStatus(false, "WARNING: the global vHost list is deprecated. Ignoring the following lines:");
for (const CString& sHost : vsList) {
CUtils::PrintStatus(false, "vHost = " + sHost);
}
}
m_vsTrustedProxies.clear();
@@ -1071,11 +1074,6 @@ bool CZNC::LoadGlobal(CConfig& config, CString& sError) {
AddTrustedProxy(sProxy);
}
config.FindStringVector("vhost", vsList);
for (const CString& sHost : vsList) {
AddBindHost(sHost);
}
CString sVal;
if (config.FindStringEntry("pidfile", sVal))
m_sPidFile = sVal;
@@ -1277,37 +1275,6 @@ void CZNC::DumpConfig(const CConfig* pConfig) {
}
}
void CZNC::ClearBindHosts() {
m_vsBindHosts.clear();
}
bool CZNC::AddBindHost(const CString& sHost) {
if (sHost.empty()) {
return false;
}
for (const CString& sBindHost : m_vsBindHosts) {
if (sBindHost.Equals(sHost)) {
return false;
}
}
m_vsBindHosts.push_back(sHost);
return true;
}
bool CZNC::RemBindHost(const CString& sHost) {
VCString::iterator it;
for (it = m_vsBindHosts.begin(); it != m_vsBindHosts.end(); ++it) {
if (sHost.Equals(*it)) {
m_vsBindHosts.erase(it);
return true;
}
}
return false;
}
void CZNC::ClearTrustedProxies() {
m_vsTrustedProxies.clear();
}