- Timestamp:
- 04/19/05 00:50:16 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- d656933
- Parents:
- aaa9a22
- Location:
- modules
- Files:
-
- 10 added
- 17 edited
-
CheckDisk/CheckDisk.cpp (modified) (4 diffs)
-
CheckDisk/CheckDisk.h (modified) (1 diff)
-
CheckDisk/CheckDisk.vcproj (modified) (6 diffs)
-
CheckSystem/CheckSystem.cpp (added)
-
CheckSystem/CheckSystem.def (added)
-
CheckSystem/CheckSystem.h (added)
-
CheckSystem/CheckSystem.vcproj (added)
-
CheckSystem/PDHCollector.cpp (added)
-
CheckSystem/PDHCollector.h (added)
-
CheckSystem/stdafx.cpp (added)
-
CheckSystem/stdafx.h (added)
-
FileLogger/FileLogger.cpp (modified) (2 diffs)
-
FileLogger/FileLogger.vcproj (modified) (1 diff)
-
FileLogger/stdafx.h (modified) (1 diff)
-
NRPEListener/NRPEListener.cpp (modified) (6 diffs)
-
NRPEListener/NRPEListener.h (modified) (2 diffs)
-
NRPEListener/NRPEListener.vcproj (modified) (8 diffs)
-
NRPEListener/NRPEPacket.cpp (added)
-
NRPEListener/NRPEPacket.h (added)
-
NRPEListener/NRPESocket.cpp (modified) (1 diff)
-
NRPEListener/NRPESocket.h (modified) (2 diffs)
-
NRPEListener/stdafx.h (modified) (1 diff)
-
NSClientCompat/NSClientCompat.vcproj (modified) (1 diff)
-
NSClientListener/NSClientListener.cpp (modified) (4 diffs)
-
NSClientListener/NSClientListener.h (modified) (2 diffs)
-
NSClientListener/NSClientListener.vcproj (modified) (3 diffs)
-
SysTray/SysTray.vcproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
modules/CheckDisk/CheckDisk.cpp
r1a5449e rcea178b 6 6 #include <strEx.h> 7 7 #include <time.h> 8 #include <utils.h> 8 9 9 10 CheckDisk gCheckDisk; … … 82 83 } 83 84 84 NSCAPI::nagiosReturn CheckDisk::Check FileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) {85 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 85 86 // CheckFileSize 86 // request: CheckFileSize &<option>&<option>...87 // request: CheckFileSize <option> <option>... 87 88 // <option> MaxWarn=<size gmkb> 88 89 // MaxCrit=<size gmkb> … … 100 101 // Examples: 101 102 // <return string> <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit> 102 // test: CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.* 103 // test: CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.* 104 // CheckFileSize 105 // 106 // check_nscp -H <ip> -p <port> -s <passwd> -c <commandstring> 107 // 108 // ./check_nscp -H 192.168.0.167 -p 1234 -s pwd -c 'CheckFileSize&ShowAll&MaxWarn=1024M&MaxCrit=4096M&File:WIN=c:\WINDOWS\*.*' 109 // WIN: 1G (2110962363B)|WIN:2110962363:1073741824:4294967296 110 NSC_DEBUG_MSG("CheckDriveSize"); 111 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 112 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 113 if (args.empty()) { 114 message = "Missing argument(s)."; 115 return NSCAPI::returnCRIT; 116 } 117 118 checkHolders::SizeMaxMin warn; 119 checkHolders::SizeMaxMin crit; 120 bool bShowAll = false; 121 bool bNSClient = false; 122 std::list<std::string> drives; 123 124 std::list<std::string>::const_iterator cit; 125 for (cit=args.begin();cit!=args.end();++cit) { 126 std::string arg = *cit; 127 std::pair<std::string,std::string> p = strEx::split(arg,"="); 128 if (p.first == "Drive") { 129 drives.push_back(p.second); 130 } else if (p.first == "MaxWarn") { 131 warn.max.set(p.second); 132 } else if (p.first == "MinWarn") { 133 warn.min.set(p.second); 134 } else if (p.first == "MaxCrit") { 135 crit.max.set(p.second); 136 } else if (p.first == "MinCrit") { 137 crit.min.set(p.second); 138 } else if (p.first == "ShowAll") { 139 bShowAll = true; 140 } else if (p.first == "nsclient") { 141 bNSClient = true; 142 } else { 143 drives.push_back(p.first); 144 } 145 } 146 147 NSC_DEBUG_MSG_STD("Bounds: critical " + crit.min.toString() + " > size > " + crit.max.toString()); 148 NSC_DEBUG_MSG_STD("Bounds: warning " + warn.min.toString() + " > size > " + warn.max.toString()); 149 NSC_DEBUG_MSG_STD("Showall: " + ((bShowAll)?"yeap":"noop")); 150 NSC_DEBUG_MSG_STD("nsclient: " + ((bNSClient)?"yeap":"noop")); 151 152 for (std::list<std::string>::iterator it = drives.begin();it!=drives.end();it++) { 153 std::string drive = (*it); 154 if (drive.length() == 1) 155 drive += ":"; 156 if (GetDriveType(drive.c_str()) != DRIVE_FIXED){ 157 message = "ERROR: Drive is not a fixed drive: " + drive; 158 return NSCAPI::returnUNKNOWN; 159 } 160 ULARGE_INTEGER freeBytesAvailableToCaller; 161 ULARGE_INTEGER totalNumberOfBytes; 162 ULARGE_INTEGER totalNumberOfFreeBytes; 163 if (!GetDiskFreeSpaceEx(drive.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 164 message = "ERROR: Could not get free space for" + drive; 165 return NSCAPI::returnUNKNOWN; 166 } 167 168 if (bNSClient) { 169 message += strEx::itos(totalNumberOfFreeBytes.QuadPart) + "&"; 170 message += strEx::itos(totalNumberOfBytes.QuadPart) + "&"; 171 } else { 172 std::string tStr; 173 long long usedSpace = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 174 long long totalSpace = totalNumberOfBytes.QuadPart; 175 if (crit.max.hasBounds() && crit.max.checkMAX(usedSpace, totalSpace)) { 176 message += crit.max.prettyPrint(drive, usedSpace, totalSpace); 177 NSCHelper::escalteReturnCodeToCRIT(returnCode); 178 } else if (crit.min.hasBounds() && crit.min.checkMIN(usedSpace, totalSpace)) { 179 tStr = crit.min.prettyPrint(drive, usedSpace, totalSpace); 180 NSCHelper::escalteReturnCodeToCRIT(returnCode); 181 } else if (warn.max.hasBounds() && warn.max.checkMAX(usedSpace, totalSpace)) { 182 tStr = warn.max.prettyPrint(drive, usedSpace, totalSpace); 183 NSCHelper::escalteReturnCodeToWARN(returnCode); 184 } else if (warn.min.hasBounds() && warn.min.checkMIN(usedSpace, totalSpace)) { 185 tStr = warn.min.prettyPrint(drive, usedSpace, totalSpace); 186 NSCHelper::escalteReturnCodeToWARN(returnCode); 187 } else if (bShowAll) { 188 tStr = drive + ": " + strEx::itos_as_BKMG(usedSpace); 189 } 190 perf += checkHolders::SizeMaxMin::printPerf(drive, usedSpace, totalSpace, warn, crit); 191 if (!message.empty() && !tStr.empty()) 192 message += ", "; 193 if (!tStr.empty()) 194 message += tStr; 195 } 196 } 197 if (message.empty()) 198 message = "All drive sizes are within bounds."; 199 return returnCode; 200 } 201 202 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 203 // CheckFileSize 204 // request: CheckFileSize <option> <option>... 205 // <option> MaxWarn=<size gmkb> 206 // MaxCrit=<size gmkb> 207 // MinWarn=<size gmkb> 208 // MinCrit=<size gmkb> 209 // ShowAll 210 // File=<path> 211 // File:<shortname>=<path> 212 // 213 // Return: <return state>&<return string>... 214 // <return state> 0 - No errors 215 // 1 - Unknown 216 // 2 - Errors 217 // <size gmkb> is a size with a possible modifier letter (such as G for gigabyte, M for Megabyte, K for kilobyte etc) 218 // Examples: 219 // <return string> <directory> <size gmkb> ... |<shortname>=<size>:<warn>:<crit> 220 // test: CheckFileSize ShowAll MaxWarn=1024M MaxCrit=4096M File:WIN=c:\WINDOWS\*.* 103 221 // CheckFileSize 104 222 // … … 196 314 if (command == "CheckFileSize") { 197 315 return CheckFileSize(argLen, char_args, msg, perf); 316 } else if (command == "CheckDriveSize") { 317 return CheckDriveSize(argLen, char_args, msg, perf); 318 198 319 // } else if (command == "CheckFileDate") { 199 320 } -
modules/CheckDisk/CheckDisk.h
r1eef1ee rcea178b 18 18 // Check commands 19 19 NSCAPI::nagiosReturn CheckFileSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 20 NSCAPI::nagiosReturn CheckDriveSize(const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 20 21 }; -
modules/CheckDisk/CheckDisk.vcproj
r452fd41 rcea178b 21 21 Optimization="0" 22 22 AdditionalIncludeDirectories="../include;../../include" 23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_ STATIC_LIB;_STLP_USE_NEWALLOC"23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1" 24 24 MinimalRebuild="TRUE" 25 25 BasicRuntimeChecks="3" 26 RuntimeLibrary=" 1"26 RuntimeLibrary="3" 27 27 UsePrecompiledHeader="3" 28 28 WarningLevel="3" … … 71 71 Name="VCCLCompilerTool" 72 72 AdditionalIncludeDirectories="../include;../../include" 73 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS ;_STLP_USE_STATIC_LIB;SYSTRAY_EXPORTS"74 RuntimeLibrary=" 0"73 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 74 RuntimeLibrary="2" 75 75 UsePrecompiledHeader="3" 76 76 WarningLevel="3" … … 112 112 </Configuration> 113 113 <Configuration 114 Name="Dynamic Linkage|Win32"115 OutputDirectory="$(ConfigurationName)"116 IntermediateDirectory="$(ConfigurationName)"117 ConfigurationType="2"118 CharacterSet="2">119 <Tool120 Name="VCCLCompilerTool"121 AdditionalIncludeDirectories="../include;../../include"122 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"123 RuntimeLibrary="2"124 UsePrecompiledHeader="3"125 WarningLevel="3"126 Detect64BitPortabilityProblems="TRUE"127 DebugInformationFormat="3"/>128 <Tool129 Name="VCCustomBuildTool"/>130 <Tool131 Name="VCLinkerTool"132 OutputFile="../../Release/modules/$(ProjectName).dll"133 LinkIncremental="1"134 ModuleDefinitionFile="CheckDisk.def"135 GenerateDebugInformation="TRUE"136 SubSystem="2"137 OptimizeReferences="2"138 EnableCOMDATFolding="2"139 ImportLibrary="$(OutDir)/CheckDisk.lib"140 TargetMachine="1"/>141 <Tool142 Name="VCMIDLTool"/>143 <Tool144 Name="VCPostBuildEventTool"/>145 <Tool146 Name="VCPreBuildEventTool"/>147 <Tool148 Name="VCPreLinkEventTool"/>149 <Tool150 Name="VCResourceCompilerTool"/>151 <Tool152 Name="VCWebServiceProxyGeneratorTool"/>153 <Tool154 Name="VCXMLDataGeneratorTool"/>155 <Tool156 Name="VCWebDeploymentTool"/>157 <Tool158 Name="VCManagedWrapperGeneratorTool"/>159 <Tool160 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>161 </Configuration>162 <Configuration163 Name="Debug Dynamic Linkage|Win32"164 OutputDirectory="$(ConfigurationName)"165 IntermediateDirectory="$(ConfigurationName)"166 ConfigurationType="2"167 CharacterSet="2">168 <Tool169 Name="VCCLCompilerTool"170 Optimization="0"171 AdditionalIncludeDirectories="../include;../../include"172 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1"173 MinimalRebuild="TRUE"174 BasicRuntimeChecks="3"175 RuntimeLibrary="3"176 UsePrecompiledHeader="3"177 WarningLevel="3"178 Detect64BitPortabilityProblems="TRUE"179 DebugInformationFormat="4"/>180 <Tool181 Name="VCCustomBuildTool"/>182 <Tool183 Name="VCLinkerTool"184 OutputFile="../../Debug/modules/$(ProjectName).dll"185 LinkIncremental="2"186 ModuleDefinitionFile="CheckDisk.def"187 GenerateDebugInformation="TRUE"188 ProgramDatabaseFile="$(OutDir)/CheckDisk.pdb"189 SubSystem="2"190 ImportLibrary="$(OutDir)/CheckDisk.lib"191 TargetMachine="1"/>192 <Tool193 Name="VCMIDLTool"/>194 <Tool195 Name="VCPostBuildEventTool"/>196 <Tool197 Name="VCPreBuildEventTool"/>198 <Tool199 Name="VCPreLinkEventTool"/>200 <Tool201 Name="VCResourceCompilerTool"/>202 <Tool203 Name="VCWebServiceProxyGeneratorTool"/>204 <Tool205 Name="VCXMLDataGeneratorTool"/>206 <Tool207 Name="VCWebDeploymentTool"/>208 <Tool209 Name="VCManagedWrapperGeneratorTool"/>210 <Tool211 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>212 </Configuration>213 <Configuration214 114 Name="Distribution|Win32" 215 115 OutputDirectory="$(ConfigurationName)" … … 292 192 </FileConfiguration> 293 193 <FileConfiguration 294 Name="D ynamic Linkage|Win32">194 Name="Distribution|Win32"> 295 195 <Tool 296 196 Name="VCCLCompilerTool" 297 197 UsePrecompiledHeader="1"/> 298 198 </FileConfiguration> 299 <FileConfiguration 300 Name="Debug Dynamic Linkage|Win32"> 301 <Tool 302 Name="VCCLCompilerTool" 303 UsePrecompiledHeader="1"/> 199 </File> 200 <File 201 RelativePath="..\..\include\utils.cpp"> 202 <FileConfiguration 203 Name="Debug|Win32"> 204 <Tool 205 Name="VCCLCompilerTool" 206 UsePrecompiledHeader="0"/> 207 </FileConfiguration> 208 <FileConfiguration 209 Name="Release|Win32"> 210 <Tool 211 Name="VCCLCompilerTool" 212 UsePrecompiledHeader="0"/> 304 213 </FileConfiguration> 305 214 <FileConfiguration … … 307 216 <Tool 308 217 Name="VCCLCompilerTool" 309 UsePrecompiledHeader=" 1"/>218 UsePrecompiledHeader="0"/> 310 219 </FileConfiguration> 311 220 </File> … … 323 232 <File 324 233 RelativePath=".\stdafx.h"> 234 </File> 235 <File 236 RelativePath="..\..\include\utils.h"> 325 237 </File> 326 238 </Filter> -
modules/FileLogger/FileLogger.cpp
r452fd41 rcea178b 19 19 20 20 bool FileLogger::loadModule() { 21 file_ = NSCModuleHelper::getSettingsString( "log", "file", "nsclient.log");21 file_ = NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT); 22 22 return true; 23 23 } … … 26 26 } 27 27 std::string FileLogger::getModuleName() { 28 return "File logger: " + NSCModuleHelper::getSettingsString( "log", "file", "nsclient.log");28 return "File logger: " + NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT); 29 29 } 30 30 NSCModuleWrapper::module_version FileLogger::getModuleVersion() { -
modules/FileLogger/FileLogger.vcproj
r452fd41 rcea178b 204 204 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> 205 205 <File 206 RelativePath="..\..\include\config.h"> 207 </File> 208 <File 206 209 RelativePath=".\FileLogger.h"> 207 210 </File> -
modules/FileLogger/stdafx.h
ra0528c4 rcea178b 16 16 #include <fstream> 17 17 18 #include <config.h> 19 18 20 19 21 // TODO: reference additional headers your program requires here -
modules/NRPEListener/NRPEListener.cpp
r452fd41 rcea178b 7 7 #include <time.h> 8 8 #include <config.h> 9 #include "NRPEPacket.h" 9 10 10 11 NRPEListener gNRPEListener; … … 24 25 25 26 bool NRPEListener::loadModule() { 26 timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,60); 27 bUseSSL_ = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_USE_SSL ,NRPE_SETTINGS_USE_SSL_DEFAULT)==1; 28 timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,NRPE_SETTINGS_TIMEOUT_DEFAULT); 27 29 std::list<std::string> commands = NSCModuleHelper::getSettingsSection(NRPE_HANDLER_SECTION_TITLE); 28 30 std::list<std::string>::iterator it; … … 40 42 } 41 43 42 socket.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOWED, ""), ","));44 allowedHosts.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOWED, NRPE_SETTINGS_ALLOWED_DEFAULT), ",")); 43 45 try { 44 socket.StartListen(NSCModuleHelper::getSettingsInt("NSClient", NRPE_SETTINGS_PORT, DEFAULT_NRPE_PORT)); 46 if (bUseSSL_) { 47 socket_ssl_.setHandler(this); 48 socket_ssl_.StartListener(NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT)); 49 } else { 50 socket_.setHandler(this); 51 socket_.StartListener(NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT)); 52 } 45 53 } catch (simpleSocket::SocketException e) { 46 54 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 47 55 return false; 48 } 56 } catch (simpleSSL::SSLException e) { 57 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 58 return false; 59 } 60 49 61 return true; 50 62 } 51 63 bool NRPEListener::unloadModule() { 52 64 try { 53 socket.close(); 65 if (bUseSSL_) { 66 socket_ssl_.removeHandler(this); 67 socket_ssl_.StopListener(); 68 } else { 69 socket_.removeHandler(this); 70 socket_.StopListener(); 71 } 54 72 } catch (simpleSocket::SocketException e) { 73 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 74 return false; 75 } catch (simpleSSL::SSLException e) { 55 76 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); 56 77 return false; … … 81 102 82 103 std::string str = (*it).second; 83 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, 0) == 1) {104 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, NRPE_SETTINGS_ALLOW_ARGUMENTS_DEFAULT) == 1) { 84 105 arrayBuffer::arrayList arr = arrayBuffer::arrayBuffer2list(argLen, char_args); 85 106 arrayBuffer::arrayList::const_iterator cit = arr.begin(); … … 87 108 88 109 for (;cit!=arr.end();cit++,i++) { 89 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, 0) == 0) {110 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, NRPE_SETTINGS_ALLOW_NASTY_META_DEFAULT) == 0) { 90 111 if ((*cit).find_first_of(NASTY_METACHARS) != std::string::npos) { 91 112 NSC_LOG_ERROR("Request string contained illegal metachars!"); … … 199 220 return result; 200 221 } 201 222 void NRPEListener::onClose() 223 {} 224 225 void NRPEListener::onAccept(simpleSocket::Socket &client) 226 { 227 if (!allowedHosts.inAllowedHosts(client.getAddrString())) { 228 NSC_LOG_ERROR("Unothorized access from: " + client.getAddrString()); 229 client.close(); 230 return; 231 } 232 try { 233 simpleSocket::DataBuffer block; 234 235 for (int i=0;i<100;i++) { 236 client.readAll(block); 237 if (block.getLength() >= NRPEPacket::getBufferLength()) 238 break; 239 Sleep(100); 240 } 241 if (i == 100) { 242 NSC_LOG_ERROR_STD("Could not retrieve NRPE packet."); 243 client.close(); 244 return; 245 } 246 247 if (block.getLength() == NRPEPacket::getBufferLength()) { 248 try { 249 NRPEPacket out = handlePacket(NRPEPacket(block.getBuffer(), block.getLength())); 250 block.copyFrom(out.getBuffer(), out.getBufferLength()); 251 } catch (NRPEPacket::NRPEPacketException e) { 252 NSC_LOG_ERROR_STD("NRPESocketException: " + e.getMessage()); 253 client.close(); 254 return; 255 } 256 client.send(block); 257 } 258 } catch (simpleSocket::SocketException e) { 259 NSC_LOG_ERROR_STD("SocketException: " + e.getMessage()); 260 } catch (NRPEException e) { 261 NSC_LOG_ERROR_STD("NRPEException: " + e.getMessage()); 262 } 263 client.close(); 264 } 265 266 NRPEPacket NRPEListener::handlePacket(NRPEPacket p) { 267 if (p.getType() != NRPEPacket::queryPacket) { 268 NSC_LOG_ERROR("Request is not a query."); 269 throw NRPEException("Invalid query type"); 270 } 271 if (p.getVersion() != NRPEPacket::version2) { 272 NSC_LOG_ERROR("Request had unsupported version."); 273 throw NRPEException("Invalid version"); 274 } 275 if (!p.verifyCRC()) { 276 NSC_LOG_ERROR("Request had invalid checksum."); 277 throw NRPEException("Invalid checksum"); 278 } 279 strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 280 std::string msg, perf; 281 NSC_DEBUG_MSG_STD("Command: " + cmd.first); 282 NSC_DEBUG_MSG_STD("Arguments: " + cmd.second); 283 284 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, NRPE_SETTINGS_ALLOW_ARGUMENTS_DEFAULT) == 0) { 285 if (!cmd.second.empty()) { 286 NSC_LOG_ERROR("Request contained arguments (not currently allowed)."); 287 throw NRPEException("Request contained arguments (not currently allowed)."); 288 } 289 } 290 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, NRPE_SETTINGS_ALLOW_NASTY_META_DEFAULT) == 0) { 291 if (cmd.first.find_first_of(NASTY_METACHARS) != std::string::npos) { 292 NSC_LOG_ERROR("Request command contained illegal metachars!"); 293 throw NRPEException("Request command contained illegal metachars!"); 294 } 295 if (cmd.second.find_first_of(NASTY_METACHARS) != std::string::npos) { 296 NSC_LOG_ERROR("Request arguments contained illegal metachars!"); 297 throw NRPEException("Request command contained illegal metachars!"); 298 } 299 } 300 301 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 302 if (perf.empty()) { 303 return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg); 304 } else { 305 return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg + "|" + perf); 306 } 307 } 202 308 203 309 NSC_WRAPPERS_MAIN_DEF(gNRPEListener); -
modules/NRPEListener/NRPEListener.h
r1a5449e rcea178b 1 1 NSC_WRAPPERS_MAIN(); 2 #include <Socket.h> 3 #include <SSLSocket.h> 4 #include <map> 5 #include "NRPEPacket.h" 2 6 3 4 #include "NRPESocket.h" 5 #include <Socket.h> 6 #include <map> 7 8 class NRPEListener { 7 class NRPEListener : public simpleSocket::ListenerHandler { 9 8 private: 10 NRPESocket socket; 9 bool bUseSSL_; 10 simpleSSL::Listener socket_ssl_; 11 simpleSocket::Listener<> socket_; 11 12 typedef std::map<std::string, std::string> commandList; 12 13 commandList commands; 13 14 unsigned int timeout; 15 socketHelpers::allowedHosts allowedHosts; 14 16 15 17 public: … … 26 28 27 29 private: 30 class NRPEException { 31 std::string error_; 32 public: 33 /* NRPESocketException(simpleSSL::SSLException e) { 34 error_ = e.getMessage(); 35 } 36 NRPEException(NRPEPacket::NRPEPacketException e) { 37 error_ = e.getMessage(); 38 } 39 */ 40 NRPEException(std::string s) { 41 error_ = s; 42 } 43 std::string getMessage() { 44 return error_; 45 } 46 }; 47 48 49 private: 50 void onAccept(simpleSocket::Socket &client); 51 void onClose(); 52 53 54 NRPEPacket handlePacket(NRPEPacket p); 28 55 int executeNRPECommand(std::string command, std::string &msg, std::string &perf); 29 56 void addCommand(std::string key, std::string args) { 30 57 commands[key] = args; 31 58 } 59 32 60 }; 33 61 -
modules/NRPEListener/NRPEListener.vcproj
r452fd41 rcea178b 33 33 <Tool 34 34 Name="VCLinkerTool" 35 AdditionalDependencies="ws2_32.lib "35 AdditionalDependencies="ws2_32.lib ssleay32.lib libeay32.lib" 36 36 OutputFile="../../Debug/modules/$(ProjectName).dll" 37 37 LinkIncremental="2" 38 AdditionalLibraryDirectories=""C:\Source\openssl-0.9.7f\out32dll.dbg"" 38 39 ModuleDefinitionFile="NRPEListener.def" 39 40 GenerateDebugInformation="TRUE" … … 82 83 <Tool 83 84 Name="VCLinkerTool" 84 AdditionalDependencies="ws2_32.lib "85 AdditionalDependencies="ws2_32.lib ssleay32.lib libeay32.lib" 85 86 OutputFile="../../Release/modules/$(ProjectName).dll" 86 87 LinkIncremental="1" 88 AdditionalLibraryDirectories=""C:\Source\openssl-0.9.7f\out32dll"" 87 89 ModuleDefinitionFile="NRPEListener.def" 88 90 GenerateDebugInformation="TRUE" … … 132 134 <Tool 133 135 Name="VCLinkerTool" 134 AdditionalDependencies="ws2_32.lib "136 AdditionalDependencies="ws2_32.lib ssleay32.lib libeay32.lib" 135 137 OutputFile="../../Dist/modules/$(ProjectName).dll" 136 138 LinkIncremental="1" … … 181 183 </File> 182 184 <File 183 RelativePath=".\NRPE Socket.cpp">185 RelativePath=".\NRPEPacket.cpp"> 184 186 </File> 185 187 <File … … 190 192 </File> 191 193 <File 194 RelativePath="..\..\include\SSLSocket.cpp"> 195 </File> 196 <File 192 197 RelativePath=".\stdafx.cpp"> 193 198 <FileConfiguration … … 208 213 Name="VCCLCompilerTool" 209 214 UsePrecompiledHeader="1"/> 215 </FileConfiguration> 216 </File> 217 <File 218 RelativePath="..\..\include\utils.cpp"> 219 <FileConfiguration 220 Name="Debug|Win32"> 221 <Tool 222 Name="VCCLCompilerTool" 223 UsePrecompiledHeader="0"/> 224 </FileConfiguration> 225 <FileConfiguration 226 Name="Release|Win32"> 227 <Tool 228 Name="VCCLCompilerTool" 229 UsePrecompiledHeader="0"/> 230 </FileConfiguration> 231 <FileConfiguration 232 Name="Distribution|Win32"> 233 <Tool 234 Name="VCCLCompilerTool" 235 UsePrecompiledHeader="0"/> 210 236 </FileConfiguration> 211 237 </File> … … 219 245 </File> 220 246 <File 247 RelativePath="..\..\include\config.h"> 248 </File> 249 <File 221 250 RelativePath=".\NRPEListener.h"> 222 251 </File> 223 252 <File 224 RelativePath=".\NRPESocket.h">225 </File>226 <File227 253 RelativePath="..\..\include\NSCHelper.h"> 228 254 </File> … … 231 257 </File> 232 258 <File 259 RelativePath="..\..\include\SSLSocket.h"> 260 </File> 261 <File 233 262 RelativePath=".\stdafx.h"> 234 263 </File> 235 264 <File 236 265 RelativePath="..\..\include\thread.h"> 266 </File> 267 <File 268 RelativePath="..\..\include\utils.h"> 237 269 </File> 238 270 </Filter> -
modules/NRPEListener/NRPESocket.cpp
r452fd41 rcea178b 3 3 #include "NRPESocket.h" 4 4 5 /**6 * Default c-tor7 */8 NRPESocket::NRPESocket() {9 }10 11 NRPESocket::~NRPESocket() {12 }13 5 14 6 15 7 16 typedef short int16_t;17 typedef unsigned long u_int32_t;18 8 19 static unsigned long crc32_table[256]; 20 static bool hascrc32 = false; 21 void generate_crc32_table(void){ 22 unsigned long crc, poly; 23 int i, j; 24 poly=0xEDB88320L; 25 for(i=0;i<256;i++){ 26 crc=i; 27 for(j=8;j>0;j--){ 28 if(crc & 1) 29 crc=(crc>>1)^poly; 30 else 31 crc>>=1; 32 } 33 crc32_table[i]=crc; 34 } 35 hascrc32 = true; 36 } 37 unsigned long calculate_crc32(const char *buffer, int buffer_size){ 38 if (!hascrc32) 39 generate_crc32_table(); 40 register unsigned long crc; 41 int this_char; 42 int current_index; 43 44 crc=0xFFFFFFFF; 45 46 for(current_index=0;current_index<buffer_size;current_index++){ 47 this_char=(int)buffer[current_index]; 48 crc=((crc>>8) & 0x00FFFFFF) ^ crc32_table[(crc ^ this_char) & 0xFF]; 49 } 50 51 return (crc ^ 0xFFFFFFFF); 9 const char* NRPEPacket::getBuffer() { 10 delete [] tmpBuffer; 11 tmpBuffer = new char[getBufferLength()]; 12 packet *p = reinterpret_cast<packet*>(tmpBuffer); 13 p->result_code = htons(NSCHelper::nagios2int(result_)); 14 p->packet_type = htons(type_); 15 p->packet_version = htons(version_); 16 p->crc32_value = 0; 17 strncpy(p->buffer, payload_.c_str(), 1023); 18 p->buffer[1024] = 0; 19 p->crc32_value = htonl(calculate_crc32(tmpBuffer, getBufferLength())); 20 return tmpBuffer; 52 21 } 53 22 54 55 class NRPEPacket {56 public:57 static const short queryPacket = 1;58 static const short responsePacket = 2;59 static const short version2 = 2;60 private:61 typedef struct packet {62 int16_t packet_version;63 int16_t packet_type;64 u_int32_t crc32_value;65 int16_t result_code;66 char buffer[1024];67 } packet;68 std::string payload_;69 short type_;70 short version_;71 NSCAPI::nagiosReturn result_;72 unsigned int crc32_;73 unsigned int calculatedCRC32_;74 char *tmpBuffer;75 public:76 NRPEPacket(const char *buffer) : tmpBuffer(NULL) {77 const packet *p = reinterpret_cast<const packet*>(buffer);78 type_ = ntohs(p->packet_type);79 assert( (type_ == queryPacket)||(type_ == responsePacket));80 version_ = ntohs(p->packet_version);81 assert(version_ == version2);82 crc32_ = ntohl(p->crc32_value);83 // Verify CRC3284 // @todo Fix this, currently we need a const buffer so we cannot change the crc to 0.85 char * tb = new char[getBufferLength()];86 memcpy(tb, buffer, getBufferLength());87 packet *p2 = reinterpret_cast<packet*>(tb);88 p2->crc32_value = 0;89 calculatedCRC32_ = calculate_crc32(tb, getBufferLength());90 delete [] tb;91 // Verify CRC32 end92 result_ = NSCHelper::int2nagios(ntohs(p->result_code));93 payload_ = std::string(p->buffer);94 }95 NRPEPacket(short type, short version, NSCAPI::nagiosReturn result, std::string payLoad)96 : tmpBuffer(NULL)97 ,type_(type)98 ,version_(version)99 ,result_(result)100 ,payload_(payLoad)101 {102 }103 ~NRPEPacket() {104 delete [] tmpBuffer;105 }106 unsigned short getVersion() const { return version_; }107 unsigned short getType() const { return type_; }108 unsigned short getResult() const { return result_; }109 std::string getPayload() const { return payload_; }110 const char* getBuffer() {111 delete [] tmpBuffer;112 tmpBuffer = new char[getBufferLength()];113 packet *p = reinterpret_cast<packet*>(tmpBuffer);114 p->result_code = htons(NSCHelper::nagios2int(result_));115 p->packet_type = htons(type_);116 p->packet_version = htons(version_);117 p->crc32_value = 0;118 strncpy(p->buffer, payload_.c_str(), 1023);119 p->buffer[1024] = 0;120 p->crc32_value = htonl(calculate_crc32(tmpBuffer, getBufferLength()));121 return tmpBuffer;122 }123 bool verifyCRC() {124 return calculatedCRC32_ == crc32_;125 }126 const unsigned int getBufferLength() const {127 return sizeof(packet);128 }129 };130 131 void NRPESocket::onAccept(simpleSocket::Socket client) {132 if (!inAllowedHosts(client.getAddrString())) {133 NSC_LOG_ERROR("Unothorized access from: " + client.getAddrString());134 client.close();135 return;136 }137 simpleSocket::DataBuffer block;138 client.readAll(block);139 NRPEPacket p(block.getBuffer());140 if (p.getType() != NRPEPacket::queryPacket) {141 NSC_LOG_ERROR("Request is not a query.");142 client.close();143 return;144 }145 if (p.getVersion() != NRPEPacket::version2) {146 NSC_LOG_ERROR("Request had unsupported version.");147 client.close();148 return;149 }150 if (!p.verifyCRC()) {151 NSC_LOG_ERROR("Request had invalid checksum.");152 client.close();153 return;154 }155 strEx::token cmd = strEx::getToken(p.getPayload(), '!');156 std::string msg, perf;157 NSC_DEBUG_MSG_STD("Command: " + cmd.first);158 NSC_DEBUG_MSG_STD("Arguments: " + cmd.second);159 160 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, 0) == 0) {161 if (!cmd.second.empty()) {162 NSC_LOG_ERROR("Request contained arguments (not currently allowed).");163 client.close();164 return;165 }166 }167 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, 0) == 0) {168 if (cmd.first.find_first_of(NASTY_METACHARS) != std::string::npos) {169 NSC_LOG_ERROR("Request command contained illegal metachars!");170 client.close();171 return;172 }173 if (cmd.second.find_first_of(NASTY_METACHARS) != std::string::npos) {174 NSC_LOG_ERROR("Request arguments contained illegal metachars!");175 client.close();176 return;177 }178 }179 180 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf);181 if (perf.empty()) {182 NRPEPacket p2(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg);183 client.send(p2.getBuffer(), p2.getBufferLength(), 0);184 } else {185 NRPEPacket p2(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg + "|" + perf);186 client.send(p2.getBuffer(), p2.getBufferLength(), 0);187 }188 client.close();189 }190 -
modules/NRPEListener/NRPESocket.h
r452fd41 rcea178b 2 2 #include "resource.h" 3 3 #include <Socket.h> 4 #include <SSLSocket.h> 5 4 6 /** 5 7 * @ingroup NSClient++ … … 30 32 #define NASTY_METACHARS "|`&><'\"\\[]{}" /* This may need to be modified for windows directory seperator */ 31 33 32 class NRPESocket : public simpleSocket::Listener { 34 typedef short int16_t; 35 typedef unsigned long u_int32_t; 36 37 38 template <class TBase> 39 class NRPESocket : public TBase { 33 40 private: 34 41 strEx::splitList allowedHosts_; 35 42 43 class NRPESocketException { 44 std::string error_; 45 public: 46 NRPESocketException(simpleSSL::SSLException e) { 47 error_ = e.getMessage(); 48 } 49 NRPESocketException(NRPEPacket::NRPEPacketException e) { 50 error_ = e.getMessage(); 51 } 52 NRPESocketException(std::string s) { 53 error_ = s; 54 } 55 std::string getMessage() { 56 return error_; 57 } 58 }; 59 60 36 61 public: 37 NRPESocket(); 38 virtual ~NRPESocket(); 39 40 void setAllowedHosts(strEx::splitList allowedHosts) { 41 allowedHosts_ = allowedHosts; 62 NRPESocket() { 42 63 } 43 bool inAllowedHosts(std::string s) { 44 if (allowedHosts_.empty()) 45 return true; 46 strEx::splitList::const_iterator cit; 47 for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) { 48 if ( (*cit) == s) 49 return true; 50 } 51 return false; 64 virtual ~NRPESocket() { 52 65 } 53 66 67 54 68 private: 55 virtual void onAccept(simpleSocket::Socket client); 69 NRPEPacket handlePacket(NRPEPacket p) { 70 if (p.getType() != NRPEPacket::queryPacket) { 71 NSC_LOG_ERROR("Request is not a query."); 72 throw NRPESocketException("Invalid query type"); 73 } 74 if (p.getVersion() != NRPEPacket::version2) { 75 NSC_LOG_ERROR("Request had unsupported version."); 76 throw NRPESocketException("Invalid version"); 77 } 78 if (!p.verifyCRC()) { 79 NSC_LOG_ERROR("Request had invalid checksum."); 80 throw NRPESocketException("Invalid checksum"); 81 } 82 strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 83 std::string msg, perf; 84 NSC_DEBUG_MSG_STD("Command: " + cmd.first); 85 NSC_DEBUG_MSG_STD("Arguments: " + cmd.second); 86 87 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS, NRPE_SETTINGS_ALLOW_ARGUMENTS_DEFAULT) == 0) { 88 if (!cmd.second.empty()) { 89 NSC_LOG_ERROR("Request contained arguments (not currently allowed)."); 90 throw NRPESocketException("Request contained arguments (not currently allowed)."); 91 } 92 } 93 if (NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META, NRPE_SETTINGS_ALLOW_NASTY_META_DEFAULT) == 0) { 94 if (cmd.first.find_first_of(NASTY_METACHARS) != std::string::npos) { 95 NSC_LOG_ERROR("Request command contained illegal metachars!"); 96 throw NRPESocketException("Request command contained illegal metachars!"); 97 } 98 if (cmd.second.find_first_of(NASTY_METACHARS) != std::string::npos) { 99 NSC_LOG_ERROR("Request arguments contained illegal metachars!"); 100 throw NRPESocketException("Request command contained illegal metachars!"); 101 } 102 } 103 104 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 105 if (perf.empty()) { 106 return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg); 107 } else { 108 return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg + "|" + perf); 109 } 110 } 111 void setupDH(simpleSSL::DH &dh); 56 112 }; 57 58 59 60 -
modules/NRPEListener/stdafx.h
r452fd41 rcea178b 15 15 16 16 #include <config.h> 17 #include <utils.h> 17 18 18 19 #include <NSCAPI.h> -
modules/NSClientCompat/NSClientCompat.vcproj
r452fd41 rcea178b 254 254 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> 255 255 </Filter> 256 <File257 RelativePath=".\ReadMe.txt">258 </File>259 256 </Files> 260 257 <Globals> -
modules/NSClientListener/NSClientListener.cpp
r452fd41 rcea178b 9 9 10 10 NSClientListener gNSClientListener; 11 12 13 #define REQ_CLIENTVERSION 1 // Works fine! 14 #define REQ_CPULOAD 2 // Quirks 15 #define REQ_UPTIME 3 // Works fine! 16 #define REQ_USEDDISKSPACE 4 // Works fine! 17 #define REQ_SERVICESTATE 5 // Works fine! 18 #define REQ_PROCSTATE 6 // Works fine! 19 #define REQ_MEMUSE 7 // Works fine! 20 //#define REQ_COUNTER 8 // ! - not implemented Have to look at this, if anyone has a sample let me know... 21 //#define REQ_FILEAGE 9 // ! - not implemented Dont know how to use 22 //#define REQ_INSTANCES 10 // ! - not implemented Dont know how to use 11 23 12 24 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) … … 22 34 23 35 bool NSClientListener::loadModule() { 24 socket.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString("NRPE", "allowed_hosts", ""), ","));36 allowedHosts.setAllowedHosts(strEx::splitEx(NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_ALLOWED, NSCLIENT_SETTINGS_ALLOWED_DEFAULT), ",")); 25 37 try { 26 socket.StartListen(NSCModuleHelper::getSettingsInt("NSClient", "port", DEFAULT_NSCLIENT_PORT)); 38 socket.setHandler(this); 39 socket.StartListener(NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT)); 27 40 } catch (simpleSocket::SocketException e) { 28 41 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); … … 33 46 bool NSClientListener::unloadModule() { 34 47 try { 35 socket.close(); 48 socket.removeHandler(this); 49 socket.StopListener(); 36 50 } catch (simpleSocket::SocketException e) { 37 51 NSC_LOG_ERROR_STD("Exception caught: " + e.getMessage()); … … 49 63 } 50 64 65 66 std::string NSClientListener::parseRequest(std::string buffer) { 67 strEx::token pwd = strEx::getToken(buffer, '&'); 68 NSC_DEBUG_MSG("Password: " + pwd.first); 69 if ( (pwd.first.empty()) || (pwd.first != NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PWD, NSCLIENT_SETTINGS_PWD_DEFAULT)) ) 70 return "ERROR: Invalid password."; 71 if (pwd.second.empty()) 72 return "ERRRO: No command specified."; 73 strEx::token cmd = strEx::getToken(pwd.second, '&'); 74 if (cmd.first.empty()) 75 return "ERRRO: No command specified."; 76 NSC_DEBUG_MSG("Command: " + cmd.first); 77 78 int c = atoi(cmd.first.c_str()); 79 80 // prefix various commands 81 switch (c) { 82 case REQ_CPULOAD: 83 cmd.first = "checkCPU"; 84 cmd.second += "&nsclient"; 85 break; 86 case REQ_UPTIME: 87 cmd.first = "checkUpTime"; 88 cmd.second = "nsclient"; 89 break; 90 case REQ_USEDDISKSPACE: 91 cmd.first = "CheckDriveSize"; 92 cmd.second += "&nsclient"; 93 break; 94 case REQ_CLIENTVERSION: 95 { 96 std::string v = NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern"); 97 if (v == "modern") 98 return NSCModuleHelper::getApplicationName() + " " + NSCModuleHelper::getApplicationVersionString(); 99 return NSCModuleHelper::getSettingsString("nsclient compat", "version", "modern"); 100 } 101 case REQ_SERVICESTATE: 102 cmd.first = "checkServiceState"; 103 break; 104 case REQ_PROCSTATE: 105 cmd.first = "checkProcState"; 106 break; 107 case REQ_MEMUSE: 108 cmd.first = "checkMem"; 109 cmd.second = "nsclient"; 110 break; 111 } 112 113 114 std::string message, perf; 115 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second.c_str(), '&', message, perf); 116 if (!NSCHelper::isNagiosReturnCode(ret)) { 117 if (message.empty()) 118 return "ERROR: Could not complete the request check log file for more information."; 119 return "ERROR: " + message; 120 } 121 switch (c) { 122 case REQ_UPTIME: // Some check_nt commands has no return code syntax 123 case REQ_MEMUSE: 124 case REQ_CPULOAD: 125 case REQ_CLIENTVERSION: 126 case REQ_USEDDISKSPACE: 127 return message; 128 129 case REQ_SERVICESTATE: // Some check_nt commands return the return code (coded as a string) 130 case REQ_PROCSTATE: 131 return NSCHelper::translateReturn(ret) + "&" + message; 132 133 default: // "New" check_nscp also returns performance data 134 if (perf.empty()) 135 return NSCHelper::translateReturn(ret) + "&" + message; 136 return NSCHelper::translateReturn(ret) + "&" + message + "|" + perf; 137 } 138 } 139 140 void NSClientListener::onClose() 141 {} 142 143 void NSClientListener::onAccept(simpleSocket::Socket &client) { 144 if (!allowedHosts.inAllowedHosts(client.getAddrString())) { 145 NSC_LOG_ERROR("Unothorized access from: " + client.getAddrString()); 146 client.close(); 147 return; 148 } 149 simpleSocket::DataBuffer db; 150 client.readAll(db); 151 if (db.getLength() > 0) { 152 std::string incoming(db.getBuffer(), db.getLength()); 153 NSC_DEBUG_MSG_STD("Incoming data: " + incoming); 154 std::string response = parseRequest(incoming); 155 NSC_DEBUG_MSG("Outgoing data: " + response); 156 client.send(response.c_str(), static_cast<int>(response.length()), 0); 157 } 158 client.close(); 159 } 160 51 161 NSC_WRAPPERS_MAIN_DEF(gNSClientListener); 52 162 NSC_WRAPPERS_IGNORE_MSG_DEF(); -
modules/NSClientListener/NSClientListener.h
r1a5449e rcea178b 1 #include "NSClientSocket.h" 1 #include <Socket.h> 2 #include <string> 3 #include <utils.h> 2 4 3 5 NSC_WRAPPERS_MAIN(); 4 6 5 class NSClientListener {7 class NSClientListener : public simpleSocket::ListenerHandler { 6 8 private: 7 NSClientSocket socket; 9 simpleSocket::Listener<> socket; 10 socketHelpers::allowedHosts allowedHosts; 8 11 9 12 public: … … 15 18 std::string getModuleName(); 16 19 NSCModuleWrapper::module_version getModuleVersion(); 20 std::string parseRequest(std::string buffer); 21 22 // simpleSocket::ListenerHandler implementation 23 void onAccept(simpleSocket::Socket &client); 24 void onClose(); 25 17 26 }; -
modules/NSClientListener/NSClientListener.vcproj
r452fd41 rcea178b 122 122 Name="VCCLCompilerTool" 123 123 AdditionalIncludeDirectories="../include;../../include" 124 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS ;_USRDLL;NSCLIENTLISTENER_EXPORTS"124 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" 125 125 RuntimeLibrary="2" 126 126 UsePrecompiledHeader="3" … … 179 179 <File 180 180 RelativePath=".\NSClientListener.cpp"> 181 </File>182 <File183 RelativePath=".\NSClientSocket.cpp">184 181 </File> 185 182 <File … … 219 216 </File> 220 217 <File 218 RelativePath="..\..\include\config.h"> 219 </File> 220 <File 221 221 RelativePath=".\NSClientListener.h"> 222 </File>223 <File224 RelativePath=".\NSClientSocket.h">225 222 </File> 226 223 <File -
modules/SysTray/SysTray.vcproj
r452fd41 rcea178b 207 207 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> 208 208 <File 209 RelativePath="..\..\include\config.h"> 210 </File> 211 <File 209 212 RelativePath="..\..\include\NSCHelper.h"> 210 213 </File>
Note: See TracChangeset
for help on using the changeset viewer.








