Merge pull request #1034 from jpnurmi/bindhost

Remove flawed Add/Del/List/BindHost(s) (close #983)
This commit is contained in:
Alexey Sokolov
2015-08-17 23:50:44 +01:00
8 changed files with 28 additions and 314 deletions
+8 -4
View File
@@ -67,9 +67,12 @@ public:
static CString GetTag(bool bIncludeVersion = true, bool bHTML = false);
static CString GetCompileOptionsString();
CString GetUptime() const;
void ClearBindHosts();
bool AddBindHost(const CString& sHost);
bool RemBindHost(const CString& sHost);
/** @deprecated Since 1.7.0. List of allowed bind hosts was a flawed design. */
void ClearBindHosts() { }
/** @deprecated Since 1.7.0. List of allowed bind hosts was a flawed design. */
bool AddBindHost(const CString& sHost) { return false; }
/** @deprecated Since 1.7.0. List of allowed bind hosts was a flawed design. */
bool RemBindHost(const CString& sHost) { return false; }
void ClearTrustedProxies();
bool AddTrustedProxy(const CString& sHost);
bool RemTrustedProxy(const CString& sHost);
@@ -125,6 +128,7 @@ public:
CString GetPemLocation() const;
const CString& GetConfigFile() const { return m_sConfigFile; }
bool WritePemFile();
/** @deprecated Since 1.7.0. List of allowed bind hosts was a flawed design. */
const VCString& GetBindHosts() const { return m_vsBindHosts; }
const VCString& GetTrustedProxies() const { return m_vsTrustedProxies; }
const std::vector<CListener*>& GetListeners() const { return m_vpListeners; }
@@ -229,7 +233,7 @@ protected:
CString m_sSSLCertFile;
CString m_sSSLCiphers;
CString m_sSSLProtocols;
VCString m_vsBindHosts;
VCString m_vsBindHosts; // TODO: remove (deprecated in 1.7.0)
VCString m_vsTrustedProxies;
VCString m_vsMotd;
CFile* m_pLockFile;
-35
View File
@@ -290,23 +290,6 @@ class CAdminMod : public CModule {
return;
}
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (!GetUser()->IsAdmin() && !vsHosts.empty()) {
bool bFound = false;
for (const CString& sHost : vsHosts) {
if (sValue.Equals(sHost)) {
bFound = true;
break;
}
}
if (!bFound) {
PutModule("You may not use this bind host. See /msg " + GetUser()->GetStatusPrefix() + "status ListBindHosts for a list");
return;
}
}
pUser->SetBindHost(sValue);
PutModule("BindHost = " + sValue);
} else {
@@ -563,24 +546,6 @@ class CAdminMod : public CModule {
return;
}
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (!GetUser()->IsAdmin() && !vsHosts.empty()) {
VCString::const_iterator it;
bool bFound = false;
for (const CString& sHost : vsHosts) {
if (sValue.Equals(sHost)) {
bFound = true;
break;
}
}
if (!bFound) {
PutModule("You may not use this bind host. See /msg " + GetUser()->GetStatusPrefix() + "status ListBindHosts for a list");
return;
}
}
pNetwork->SetBindHost(sValue);
PutModule("BindHost = " + sValue);
} else {
@@ -48,14 +48,7 @@
<? IF BindHostEdit ?>
<div class="subsection">
<div class="inputlabel">BindHost:</div>
<? IF BindHostLoop ?>
<select name="bindhost">
<option value="">- Default -</option>
<? LOOP BindHostLoop ?><option value="<? VAR BindHost ?>"<? IF Checked ?> selected="selected"<? ENDIF ?>><? VAR BindHost ?></option><? ENDLOOP ?>
</select>
<? ELSE ?>
<input type="text" name="bindhost" value="<? VAR BindHost ?>"/>
<? ENDIF ?>
<input type="text" name="bindhost" value="<? VAR BindHost ?>"/>
</div>
<div style="clear: both;"></div>
<? ENDIF ?>
+2 -16
View File
@@ -87,27 +87,13 @@
<? IF BindHostEdit ?>
<div class="subsection">
<div class="inputlabel">BindHost:</div>
<? IF BindHostLoop ?>
<select name="bindhost">
<option value="">- Default -</option>
<? LOOP BindHostLoop ?><option value="<? VAR BindHost ?>"<? IF Checked ?> selected="selected"<? ENDIF ?>><? VAR BindHost ?></option><? ENDLOOP ?>
</select>
<? ELSE ?>
<input type="text" name="bindhost" value="<? VAR BindHost ?>"/>
<? ENDIF ?>
<input type="text" name="bindhost" value="<? VAR BindHost ?>"/>
</div>
<div style="clear: both;"></div>
<div class="subsection">
<div class="inputlabel">DCCBindHost:</div>
<? IF DCCBindHostLoop ?>
<select name="dccbindhost">
<option value="">- Default -</option>
<? LOOP DCCBindHostLoop ?><option value="<? VAR BindHost ?>"<? IF Checked ?> selected="selected"<? ENDIF ?>><? VAR BindHost ?></option><? ENDLOOP ?>
</select>
<? ELSE ?>
<input type="text" name="dccbindhost" value="<? VAR DCCBindHost ?>"/>
<? ENDIF ?>
<input type="text" name="dccbindhost" value="<? VAR DCCBindHost ?>"/>
</div>
<div style="clear: both;"></div>
<? ENDIF ?>
-8
View File
@@ -155,14 +155,6 @@
<br /><span class="info">"Message of the Day", sent to all ZNC users on connect.</span>
</div>
<div class="subsection twothird">
<div class="inputlabel">BindHosts:</div>
<textarea name="bindhosts" cols="70" rows="8"><? LOOP BindHostLoop ?><? VAR BindHost ?>
<? ENDLOOP ?>
</textarea>
<br /><span class="info">One host name or IP entry per line.</span>
</div>
</div>
</div>
</div>
+6 -117
View File
@@ -230,28 +230,6 @@ public:
if (!sArg2.empty()) {
pNewUser->SetDCCBindHost(sArg2);
}
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (!spSession->IsAdmin() && !vsHosts.empty()) {
bool bFound = false;
bool bFoundDCC = false;
for (const CString& sHost : vsHosts) {
if (sArg.Equals(sHost)) {
bFound = true;
}
if (sArg2.Equals(sHost)) {
bFoundDCC = true;
}
}
if (!bFound) {
pNewUser->SetBindHost(pUser ? pUser->GetBindHost() : "");
}
if (!bFoundDCC) {
pNewUser->SetDCCBindHost(pUser ? pUser->GetDCCBindHost() : "");
}
}
} else if (pUser){
pNewUser->SetBindHost(pUser->GetBindHost());
pNewUser->SetDCCBindHost(pUser->GetDCCBindHost());
@@ -810,31 +788,8 @@ public:
// To change BindHosts be admin or don't have DenySetBindHost
if (spSession->IsAdmin() || !spSession->GetUser()->DenySetBindHost()) {
Tmpl["BindHostEdit"] = "true";
const VCString& vsBindHosts = CZNC::Get().GetBindHosts();
if (vsBindHosts.empty()) {
if (pNetwork) {
Tmpl["BindHost"] = pNetwork->GetBindHost();
}
} else {
bool bFoundBindHost = false;
for (const CString& sBindHost : vsBindHosts) {
CTemplate& l = Tmpl.AddRow("BindHostLoop");
l["BindHost"] = sBindHost;
if (pNetwork && pNetwork->GetBindHost() == sBindHost) {
l["Checked"] = "true";
bFoundBindHost = true;
}
}
// If our current bindhost is not in the global list...
if (pNetwork && !bFoundBindHost && !pNetwork->GetBindHost().empty()) {
CTemplate& l = Tmpl.AddRow("BindHostLoop");
l["BindHost"] = pNetwork->GetBindHost();
l["Checked"] = "true";
}
if (pNetwork) {
Tmpl["BindHost"] = pNetwork->GetBindHost();
}
}
@@ -990,23 +945,7 @@ public:
sArg = WebSock.GetParam("bindhost");
// To change BindHosts be admin or don't have DenySetBindHost
if (spSession->IsAdmin() || !spSession->GetUser()->DenySetBindHost()) {
CString sHost = WebSock.GetParam("bindhost");
const VCString& vsHosts = CZNC::Get().GetBindHosts();
if (!spSession->IsAdmin() && !vsHosts.empty()) {
bool bFound = false;
for (const CString& s : vsHosts) {
if (sHost.Equals(s)) {
bFound = true;
break;
}
}
if (!bFound) {
sHost = pNetwork->GetBindHost();
}
}
pNetwork->SetBindHost(sHost);
pNetwork->SetBindHost(WebSock.GetParam("bindhost"));
}
if (WebSock.GetParam("floodprotection").ToBool()) {
@@ -1281,46 +1220,9 @@ public:
// To change BindHosts be admin or don't have DenySetBindHost
if (spSession->IsAdmin() || !spSession->GetUser()->DenySetBindHost()) {
Tmpl["BindHostEdit"] = "true";
const VCString& vsBindHosts = CZNC::Get().GetBindHosts();
if (vsBindHosts.empty()) {
if (pUser) {
Tmpl["BindHost"] = pUser->GetBindHost();
Tmpl["DCCBindHost"] = pUser->GetDCCBindHost();
}
} else {
bool bFoundBindHost = false;
bool bFoundDCCBindHost = false;
for (const CString& sBindHost : vsBindHosts) {
CTemplate& l = Tmpl.AddRow("BindHostLoop");
CTemplate& k = Tmpl.AddRow("DCCBindHostLoop");
l["BindHost"] = sBindHost;
k["BindHost"] = sBindHost;
if (pUser && pUser->GetBindHost() == sBindHost) {
l["Checked"] = "true";
bFoundBindHost = true;
}
if (pUser && pUser->GetDCCBindHost() == sBindHost) {
k["Checked"] = "true";
bFoundDCCBindHost = true;
}
}
// If our current bindhost is not in the global list...
if (pUser && !bFoundBindHost && !pUser->GetBindHost().empty()) {
CTemplate& l = Tmpl.AddRow("BindHostLoop");
l["BindHost"] = pUser->GetBindHost();
l["Checked"] = "true";
}
if (pUser && !bFoundDCCBindHost && !pUser->GetDCCBindHost().empty()) {
CTemplate& l = Tmpl.AddRow("DCCBindHostLoop");
l["BindHost"] = pUser->GetDCCBindHost();
l["Checked"] = "true";
}
if (pUser) {
Tmpl["BindHost"] = pUser->GetBindHost();
Tmpl["DCCBindHost"] = pUser->GetDCCBindHost();
}
}
@@ -1696,12 +1598,6 @@ public:
Tmpl["ProtectWebSessions"] = CString(CZNC::Get().GetProtectWebSessions());
Tmpl["HideVersion"] = CString(CZNC::Get().GetHideVersion());
const VCString& vsBindHosts = CZNC::Get().GetBindHosts();
for (const CString& sHost : vsBindHosts) {
CTemplate& l = Tmpl.AddRow("BindHostLoop");
l["BindHost"] = sHost;
}
const VCString& vsMotd = CZNC::Get().GetMotd();
for (const CString& sMotd : vsMotd) {
CTemplate& l = Tmpl.AddRow("MOTDLoop");
@@ -1834,13 +1730,6 @@ public:
CZNC::Get().AddMotd(sMotd.TrimRight_n());
}
WebSock.GetRawParam("bindhosts").Split("\n", vsArgs);
CZNC::Get().ClearBindHosts();
for (const CString& sHost : vsArgs) {
CZNC::Get().AddBindHost(sHost.Trim_n());
}
CZNC::Get().SetSkinName(WebSock.GetParam("skin"));
set<CString> ssArgs;
-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();
}