From ef9d9b217a3826fe9aad33a4562089e2e2da1a47 Mon Sep 17 00:00:00 2001 From: prozacx Date: Tue, 27 Dec 2005 19:19:05 +0000 Subject: [PATCH] Added ListenHost for binding to a specific ip instead of inaddr_any git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@588 726aef4b-f618-498e-8847-2d620e286838 --- modules/webadmin.cpp | 7 +++++-- znc.cpp | 44 ++++++++++++++++++++++++++++++++++++-------- znc.h | 2 ++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index ca81c1bd..93abbb8f 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -123,7 +123,10 @@ public: #endif } - m_uPort = sPort.ToUInt(); + if (!sPort.empty()) { + m_uPort = sPort.ToUInt(); + } + CWebAdminSock* pListenSock = new CWebAdminSock(this); #ifdef HAVE_LIBSSL @@ -132,7 +135,7 @@ public: } #endif - return m_pManager->ListenAll(m_uPort, "WebAdmin::Listener", bSSL, SOMAXCONN, pListenSock); + return m_pManager->ListenHost(m_uPort, "WebAdmin::Listener", CZNC::Get().GetListenHost(), bSSL, SOMAXCONN, pListenSock); } void AddSock(CWebAdminSock* pSock) { diff --git a/znc.cpp b/znc.cpp index 666e034e..f3a50cbd 100644 --- a/znc.cpp +++ b/znc.cpp @@ -267,7 +267,8 @@ bool CZNC::Listen() { pClient->SetPemLocation(GetPemLocation()); } #endif - return m_Manager.ListenAll(m_uListenPort, "_LISTENER", bSSL, SOMAXCONN, pClient); + + return m_Manager.ListenHost(m_uListenPort, "_LISTENER", m_sListenHost, bSSL, SOMAXCONN, pClient); } bool CZNC::IsHostAllowed(const CString& sHostMask) { @@ -338,7 +339,13 @@ bool CZNC::WriteConfig() { return false; } - File.Write("ListenPort = " + CString((m_bSSL) ? "+" : "") + CString::ToString(m_uListenPort) + "\r\n"); + CString sHostPortion; + if (!m_sListenHost.empty()) { + sHostPortion = m_sListenHost + ":"; + } + + File.Write("Listen = " + sHostPortion + CString((m_bSSL) ? "+" : "") + CString::ToString(m_uListenPort) + "\r\n"); + if (!m_sISpoofFile.empty()) { File.Write("ISpoofFile = " + m_sISpoofFile + "\r\n"); if (!m_sISpoofFormat.empty()) { File.Write("ISpoofFormat = " + m_sISpoofFormat + "\r\n"); } @@ -413,15 +420,22 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { CUtils::PrintMessage("First lets start with some global settings..."); CUtils::PrintMessage(""); - // ListenPort + // Listen unsigned int uPort = 0; while(!CUtils::GetNumInput("What port would you like ZNC to listen on?", uPort, 1, 65535)); #ifdef HAVE_LIBSSL bAnswer = CUtils::GetBoolInput("Would you like ZNC to listen using SSL?", false); #endif - vsLines.push_back("ListenPort = " + CString((bAnswer) ? "+" : "") + CString::ToString(uPort)); - // !ListenPort + CString sListenHost; + CUtils::GetInput("Listen Host", sListenHost, "", "Blank for all ips"); + + if (!sListenHost.empty()) { + sListenHost += ":"; + } + + vsLines.push_back("Listen = " + sListenHost + CString((bAnswer) ? "+" : "") + CString::ToString(uPort)); + // !Listen #ifdef _MODULES set ssGlobalMods; @@ -942,16 +956,30 @@ bool CZNC::ParseConfig(const CString& sConfig) { } } } else { - if (sName.CaseCmp("ListenPort") == 0) { + if (sName.CaseCmp("Listen") == 0 || sName.CaseCmp("ListenPort") == 0) { m_bSSL = false; - CString sPort = sValue; + CString sPort; + + if (sValue.find(":") != CString::npos) { + m_sListenHost = sValue.Token(0, false, ":"); + sPort = sValue.Token(1, true, ":"); + } else { + sPort = sValue; + } + if (sPort.Left(1) == "+") { sPort.LeftChomp(); m_bSSL = true; } + CString sHostComment; + + if (!m_sListenHost.empty()) { + sHostComment = " on host [" + m_sListenHost + "]"; + } + m_uListenPort = strtol(sPort.c_str(), NULL, 10); - CUtils::PrintAction("Binding to port [" + CString((m_bSSL) ? "+" : "") + CString::ToString(m_uListenPort) + "]"); + CUtils::PrintAction("Binding to port [" + CString((m_bSSL) ? "+" : "") + CString::ToString(m_uListenPort) + "]" + sHostComment); #ifndef HAVE_LIBSSL if (m_bSSL) { diff --git a/znc.h b/znc.h index 1bf8186b..8a0da96d 100644 --- a/znc.h +++ b/znc.h @@ -52,6 +52,7 @@ public: CGlobalModules& GetModules() { return *m_pModules; } #endif unsigned short GetListenPort() const { return m_uListenPort; } + const CString& GetListenHost() const { return m_sListenHost; } const CString& GetStatusPrefix() const { return m_sStatusPrefix; } const CString& GetCurPath() const { if (!CFile::Exists(m_sCurPath)) { CUtils::MakeDir(m_sCurPath); } return m_sCurPath; } const CString& GetModPath() const { if (!CFile::Exists(m_sModPath)) { CUtils::MakeDir(m_sModPath); } return m_sModPath; } @@ -95,6 +96,7 @@ public: private: protected: unsigned short m_uListenPort; + CString m_sListenHost; map m_msUsers; set m_ssDelUsers; TSocketManager m_Manager;