Index: svnroot/munin-node/src/plugins/external/ExternalMuninNodePlugin.cpp =================================================================== --- svnroot/munin-node/src/plugins/external/ExternalMuninNodePlugin.cpp (revision 11) +++ svnroot/munin-node/src/plugins/external/ExternalMuninNodePlugin.cpp (working copy) @@ -19,13 +19,37 @@ #include "StdAfx.h" #include "ExternalMuninNodePlugin.h" +#include "../../core/Service.h" + + +void removeAllNL (std::string &str) +{ + std::string temp; + for (unsigned int i = 0; i < str.length(); i++) + if ((str[i] != '\r') && (str[i] != '\n')) temp += str[i]; + str = temp; +} + +void removeAllLF (std::string &str) +{ + std::string temp; + for (unsigned int i = 0; i < str.length(); i++) + if ((str[i] != '\r')) temp += str[i]; + str = temp; +} + + + ExternalMuninNodePlugin::ExternalMuninNodePlugin(const std::string &externalPlugin) : m_ExternalPlugin(externalPlugin) { m_Name = Run("name"); + removeAllNL(m_Name); // Check that the name is valid - if (m_Name.find(" ") != m_Name.npos) - m_Name = ""; + if (m_Name.find(" ") != m_Name.npos) { + _Module.LogError("Failed to load External plugin: %s", m_Name.c_str()); + m_Name = ""; + } } ExternalMuninNodePlugin::~ExternalMuninNodePlugin() @@ -47,7 +71,8 @@ { std::string output = Run(""); if (output.length() > 0) { - strncpy(buffer, output.c_str(), len); + removeAllLF(output); + strncpy(buffer, output.c_str(), len); return 0; } return -1; @@ -63,7 +88,7 @@ if (pipe.Execute(A2TConvert(cmdLine).c_str()) == CPEXEC_OK) { // Wait for the command to complete while (pipe.IsChildRunning()) - Sleep(0); + Sleep(100); // don't do a very tight loop -- that reduces CPU usage return T2AConvert(pipe.GetOutput()); } // Command failed, empty string Index: svnroot/munin-node/src/core/MuninPluginManager.cpp =================================================================== --- svnroot/munin-node/src/core/MuninPluginManager.cpp (revision 11) +++ svnroot/munin-node/src/core/MuninPluginManager.cpp (working copy) @@ -90,7 +90,7 @@ if (plugin->IsLoaded()) { AddPlugin(plugin); } else { - _Module.LogEvent("Failed to load External plugin: %s", filename.c_str()); + _Module.LogError("Failed to load External plugin: %s", filename.c_str()); delete plugin; } } Index: svnroot/munin-node/src/core/Service.cpp =================================================================== --- svnroot/munin-node/src/core/Service.cpp (revision 11) +++ svnroot/munin-node/src/core/Service.cpp (working copy) @@ -139,7 +139,8 @@ //LogEvent("Updating INI File"); // Save any changes to the INI file - g_Config.WriteFile(); + // NAAAAH, never ever modify my settings + // g_Config.WriteFile(); if (m_bService) { @@ -204,7 +205,7 @@ // Adding firewall rule if (FAILED(AddApplicationToExceptionList(szFilePath, m_szServiceName))) { - ShowMessage(_T("Couldn't add firewall excception rule")); + ShowMessage(_T("Couldn't add firewall exception rule")); } if (dwStartupType == SERVICE_AUTO_START) @@ -266,7 +267,7 @@ // Remove firewall rule if (FAILED(RemoveApplicationFromExceptionList(szFilePath))) { - ShowMessage(_T("Couldn't remove firewall excception rule")); + ShowMessage(_T("Couldn't remove firewall exception rule")); } if (!m_EventLog.UnRegisterSource()) @@ -334,3 +335,25 @@ printf("\n"); } } + +void CService::LogError(LPCSTR pFormat, ...) +{ + char chMsg[512]; + va_list pArg; + va_start(pArg, pFormat); + _vsnprintf(chMsg, 512, pFormat, pArg); + va_end(pArg); + chMsg[511] = 0; + + if (m_bService) + { + m_EventLog.Write(EVENTLOG_ERROR_TYPE, A2TConvert(chMsg).c_str()); + } + else + { + // As we don't have an event log handle, just write the error to the console. + printf("ERROR:"); + printf(chMsg); + printf("\n"); + } +} Index: svnroot/munin-node/src/core/Service.h =================================================================== --- svnroot/munin-node/src/core/Service.h (revision 11) +++ svnroot/munin-node/src/core/Service.h (working copy) @@ -26,6 +26,7 @@ BOOL Install(); BOOL Uninstall(DWORD dwTimeout = 10000); void LogEvent(LPCSTR pszFormat, ...); + void LogError(LPCSTR pszFormat, ...); void SetServiceStatus(DWORD dwState); void SetQuiet(bool bQuiet) { m_bQuiet = bQuiet; }; void ShowMessage(LPCTSTR szMessage); Index: svnroot/munin-node/src/core/MuninNodeServer.cpp =================================================================== --- svnroot/munin-node/src/core/MuninNodeServer.cpp (revision 11) +++ svnroot/munin-node/src/core/MuninNodeServer.cpp (working copy) @@ -18,6 +18,7 @@ #include "StdAfx.h" #include "MuninNodeServer.h" +#include "MuninNodeSettings.h" #include "Service.h" void MuninNodeServer::Stop() @@ -29,7 +30,11 @@ void *MuninNodeServer::Entry() { - //the socket function creates our SOCKET + int portNumber = g_Config.GetValueI("MuninNode", "PortNumber", 4949); + bool logConnections = g_Config.GetValueB("MuninNode", "LogConnections", true); + std::string masterAddress = g_Config.GetValue("MuninNode", "MasterAddress", "*"); + + //the socket function creates our SOCKET if (!m_ServerSocket.Create()) { return 0; } @@ -38,7 +43,7 @@ //structure. Basically it connects the socket with //the local address and a specified port. //If it returns non-zero quit, as this indicates error - if (!m_ServerSocket.Bind(4949)) { + if (!m_ServerSocket.Bind(portNumber)) { return 0; } @@ -56,10 +61,16 @@ if (m_ServerSocket.Accept(client)) { // TODO: Add ip address matching, http://stackoverflow.com/questions/594112/matching-an-ip-to-a-cidr-mask-in-php5 const char *ipAddress = inet_ntoa(client->m_Address.sin_addr); - _Module.LogEvent("Connection from %s", ipAddress); - // Start child thread to process client socket - MuninNodeClient *clientThread = new MuninNodeClient(client, this, &m_PluginManager); - clientThread->Run(); + if (masterAddress == "*" || ipAddress == masterAddress) { + if(logConnections){ + _Module.LogEvent("Connection from %s", ipAddress); + } + // Start child thread to process client socket + MuninNodeClient *clientThread = new MuninNodeClient(client, this, &m_PluginManager); + clientThread->Run(); + } else { + _Module.LogError("Rejecting connection from %s", ipAddress); + } } else { delete client; break; Index: svnroot/munin-node/munin-node.rc =================================================================== --- svnroot/munin-node/munin-node.rc (revision 11) +++ svnroot/munin-node/munin-node.rc (working copy) @@ -7,7 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // -#include "afxres.h" +#include "windows.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -34,7 +34,7 @@ 2 TEXTINCLUDE BEGIN - "#include ""afxres.h""\r\n" + "#include ""windows.h""\r\n" "\0" END