Changeset 281
- Timestamp:
- 08/19/10 13:36:13 (18 months ago)
- Files:
-
- 20 added
- 57 edited
-
branches/stable/modules/CheckDisk/CMakeLists.txt (added)
-
branches/stable/modules/CheckDisk/CheckDisk.cpp (modified) (15 diffs)
-
branches/stable/modules/CheckDisk/CheckDisk.h (modified) (4 diffs)
-
branches/stable/modules/CheckDisk/module.cmake (added)
-
branches/stable/modules/CheckDisk/stdafx.h (modified) (2 diffs)
-
trunk/CMakeLists.txt (modified) (3 diffs)
-
trunk/include/NSCAPI.h (modified) (2 diffs)
-
trunk/include/config.h.in (modified) (1 diff)
-
trunk/include/file_helpers.hpp (modified) (2 diffs)
-
trunk/include/nrpe/server/handler.hpp (modified) (1 diff)
-
trunk/include/nrpe/server/server.cpp (modified) (4 diffs)
-
trunk/include/nrpe/server/server.hpp (modified) (1 diff)
-
trunk/include/nscapi/macros.hpp (modified) (2 diffs)
-
trunk/include/nscapi/nscapi_core_wrapper.cpp (modified) (2 diffs)
-
trunk/include/nscapi/nscapi_core_wrapper.hpp (modified) (3 diffs)
-
trunk/include/nscapi/nscapi_plugin_wrapper.hpp (modified) (3 diffs)
-
trunk/include/nscapi/plugin.hpp (modified) (1 diff)
-
trunk/include/nscapi/settings.cpp (added)
-
trunk/include/nscapi/settings.hpp (added)
-
trunk/include/settings/Settings.h (modified) (5 diffs)
-
trunk/include/settings/macros.h (modified) (4 diffs)
-
trunk/include/settings/settings_core.hpp (added)
-
trunk/include/settings/settings_core_impl.hpp (added)
-
trunk/include/settings/settings_ini.hpp (modified) (16 diffs)
-
trunk/include/settings/settings_old.hpp (modified) (21 diffs)
-
trunk/include/settings/settings_registry.hpp (modified) (13 diffs)
-
trunk/include/simple_timer.hpp (modified) (1 diff)
-
trunk/include/strEx.h (modified) (3 diffs)
-
trunk/modules/CheckEventLog/CMakeLists.txt (added)
-
trunk/modules/CheckEventLog/CheckEventLog.cpp (modified) (23 diffs)
-
trunk/modules/CheckEventLog/CheckEventLog.cpp.bak (added)
-
trunk/modules/CheckEventLog/CheckEventLog.h (modified) (4 diffs)
-
trunk/modules/CheckEventLog/CheckEventLog.h.bak (added)
-
trunk/modules/CheckEventLog/eventlog_record.hpp (modified) (2 diffs)
-
trunk/modules/CheckEventLog/module.cmake (added)
-
trunk/modules/CheckEventLog/stdafx.h (modified) (1 diff)
-
trunk/modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (6 diffs)
-
trunk/modules/CheckExternalScripts/CheckExternalScripts.def (modified) (1 diff)
-
trunk/modules/CheckExternalScripts/CheckExternalScripts.h (modified) (6 diffs)
-
trunk/modules/CheckExternalScripts/module.cmake (added)
-
trunk/modules/CheckHelpers/CheckHelpers.cpp (modified) (2 diffs)
-
trunk/modules/CheckHelpers/CheckHelpers.h (modified) (2 diffs)
-
trunk/modules/CheckHelpers/module.cmake (added)
-
trunk/modules/CheckSystem/CheckSystem.cpp (modified) (4 diffs)
-
trunk/modules/CheckSystem/CheckSystem.cpp.bak (added)
-
trunk/modules/CheckSystem/CheckSystem.h (modified) (2 diffs)
-
trunk/modules/CheckSystem/module.cmake (added)
-
trunk/modules/FileLogger/FileLogger.cpp (modified) (1 diff)
-
trunk/modules/FileLogger/FileLogger.h (modified) (1 diff)
-
trunk/modules/FileLogger/module.cmake (added)
-
trunk/modules/NRPEClient/NRPEClient.cpp (modified) (3 diffs)
-
trunk/modules/NRPEClient/NRPEClient.h (modified) (2 diffs)
-
trunk/modules/NRPEClient/module.cmake (added)
-
trunk/modules/NRPEServer/NRPEServer.cpp (modified) (3 diffs)
-
trunk/modules/NRPEServer/NRPEServer.def (modified) (1 diff)
-
trunk/modules/NRPEServer/NRPEServer.h (modified) (2 diffs)
-
trunk/modules/NRPEServer/handler_impl.hpp (modified) (2 diffs)
-
trunk/modules/NRPEServer/module.cmake (added)
-
trunk/modules/NSCAAgent/NSCAAgent.cpp (modified) (1 diff)
-
trunk/modules/NSCAAgent/NSCAAgent.h (modified) (1 diff)
-
trunk/modules/NSCAAgent/module.cmake (added)
-
trunk/modules/Scheduler/Scheduler.cpp (modified) (1 diff)
-
trunk/modules/Scheduler/Scheduler.h (modified) (1 diff)
-
trunk/modules/Scheduler/module.cmake (added)
-
trunk/service/CMakeLists.txt (modified) (1 diff)
-
trunk/service/NSCPlugin.cpp (modified) (4 diffs)
-
trunk/service/NSCPlugin.h (modified) (3 diffs)
-
trunk/service/NSClient++.cpp (modified) (26 diffs)
-
trunk/service/NSClient++.h (modified) (3 diffs)
-
trunk/service/cli_parser.hpp (added)
-
trunk/service/core_api.cpp (modified) (10 diffs)
-
trunk/service/core_api.h (modified) (2 diffs)
-
trunk/service/settings_client.hpp (modified) (2 diffs)
-
trunk/service/settings_logger_impl.hpp (modified) (1 diff)
-
trunk/service/settings_manager_impl.cpp (modified) (3 diffs)
-
trunk/service/settings_manager_impl.h (modified) (4 diffs)
-
trunk/service/simple_client.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/modules/CheckDisk/CheckDisk.cpp
r272 r281 30 30 CheckDisk gCheckDisk; 31 31 32 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)33 {34 NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);35 return TRUE;36 }37 38 32 CheckDisk::CheckDisk() : show_errors_(false) { 39 33 } … … 46 40 47 41 bool CheckDisk::loadModule() { 42 return false; 43 } 44 45 bool CheckDisk::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 48 46 try { 49 NSCModuleHelper::registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 50 NSCModuleHelper::registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 51 NSCModuleHelper::registerCommand(_T("CheckFile"), _T("Check various aspects of a file and/or folder.")); 52 53 show_errors_ = NSCModuleHelper::getSettingsInt(CHECK_DISK_SECTION_TITLE, CHECK_DISK_SHOW_ERRORS, CHECK_DISK_SHOW_ERRORS_DEFAULT)==1; 54 } catch (NSCModuleHelper::NSCMHExcpetion &e) { 47 GET_CORE()->registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 48 GET_CORE()->registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 49 GET_CORE()->registerCommand(_T("CheckFile2"), _T("Check various aspects of a file and/or folder.")); 50 51 // TODO 52 SETTINGS_REG_KEY_I(check_disk::SHOW_ERRORS); 53 show_errors_ = SETTINGS_GET_BOOL(check_disk::SHOW_ERRORS); 54 } catch (nscapi::nscapi_exception &e) { 55 55 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 56 56 } catch (...) { … … 162 162 163 163 164 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize( const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {164 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 165 165 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 166 std::list<std::wstring> args = arrayBuffer::arrayBuffer2list(argLen, char_args);167 166 if (args.empty()) { 168 167 message = _T("Missing argument(s)."); … … 344 343 message = _T("OK: All drives within bounds."); 345 344 else if (!bNSClient) 346 message = NSCHelper::translateReturn(returnCode) + _T(": ") + message;345 message = nscapi::plugin_helper::translateReturn(returnCode) + _T(": ") + message; 347 346 return returnCode; 348 347 } … … 416 415 417 416 418 NSCAPI::nagiosReturn CheckDisk::CheckFileSize( const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {417 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 419 418 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 420 std::list<std::wstring> args = arrayBuffer::arrayBuffer2list(argLen, char_args);421 419 bool bPerfData = true; 422 420 bool debug = false; … … 472 470 message = _T("OK all file sizes are within bounds."); 473 471 else 474 message = NSCHelper::translateReturn(returnCode) + _T(": ") + message;472 message = nscapi::plugin_helper::translateReturn(returnCode) + _T(": ") + message; 475 473 return returnCode; 476 474 } … … 985 983 986 984 987 NSCAPI::nagiosReturn CheckDisk::getFileAge( const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {985 NSCAPI::nagiosReturn CheckDisk::getFileAge(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 988 986 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 989 std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);990 987 typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer; 991 if ( stl_args.empty()) {988 if (args.empty()) { 992 989 message = _T("Missing argument(s)."); 993 990 return NSCAPI::returnUNKNOWN; … … 996 993 std::wstring path; 997 994 bool debug = false; 998 MAP_OPTIONS_BEGIN( stl_args)995 MAP_OPTIONS_BEGIN(args) 999 996 MAP_OPTIONS_STR(_T("path"), path) 1000 997 MAP_OPTIONS_STR(_T("date"), format) … … 1024 1021 1025 1022 1026 NSCAPI::nagiosReturn CheckDisk::CheckFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {1027 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK;1028 std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);1029 typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer;1030 if (stl_args.empty()) {1031 message = _T("Missing argument(s).");1032 return NSCAPI::returnUNKNOWN;1033 }1034 file_filter_function finder;1035 PathContainer tmpObject;1036 std::list<std::wstring> paths;1037 unsigned int truncate = 0;1038 CheckFileContainer query;1039 std::wstring syntax = _T("%filename%");1040 std::wstring alias;1041 bool bPerfData = true;1042 unsigned int max_dir_depth = -1;1043 bool debug = false;1044 1045 try {1046 MAP_OPTIONS_BEGIN(stl_args)1047 MAP_OPTIONS_NUMERIC_ALL(query, _T(""))1048 MAP_OPTIONS_STR2INT(_T("truncate"), truncate)1049 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData)1050 MAP_OPTIONS_STR(_T("syntax"), syntax)1051 MAP_OPTIONS_PUSH(_T("path"), paths)1052 MAP_OPTIONS_STR(_T("alias"), alias)1053 MAP_OPTIONS_STR2INT(_T("max-dir-depth"), max_dir_depth)1054 MAP_OPTIONS_PUSH(_T("file"), paths)1055 MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug)1056 MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterIn, _T("in"), _T("out"))1057 MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterAll, _T("all"), _T("any"))1058 MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-size"), size, finder.filter_chain)1059 MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-creation"), creation, finder.filter_chain)1060 MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-written"), written, finder.filter_chain)1061 MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-accessed"), accessed, finder.filter_chain)1062 MAP_OPTIONS_MISSING(message, _T("Unknown argument: "))1063 MAP_OPTIONS_END()1064 } catch (filters::parse_exception e) {1065 message = e.getMessage();1066 return NSCAPI::returnUNKNOWN;1067 } catch (filters::filter_exception e) {1068 message = e.getMessage();1069 return NSCAPI::returnUNKNOWN;1070 }1071 finder.syntax = syntax;1072 NSC_error errors;1073 for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) {1074 pattern_type path = split_pattern(*pit);1075 recursive_scan<file_filter_function>(path.first, path.second, 0, max_dir_depth, finder, &errors, debug);1076 if (errors.has_error()) {1077 if (show_errors_)1078 message = errors.get_error();1079 else1080 message = _T("Check contains error. Check log for details (or enable show_errors in nsc.ini)");1081 return NSCAPI::returnUNKNOWN;1082 }1083 }1084 message = finder.message;1085 if (!alias.empty())1086 query.alias = alias;1087 else1088 query.alias = finder.alias;1089 if (query.alias.empty())1090 query.alias = _T("no files found");1091 query.runCheck(finder.hit_count, returnCode, message, perf);1092 if ((truncate > 0) && (message.length() > (truncate-4)))1093 message = message.substr(0, truncate-4) + _T("...");1094 if (message.empty())1095 message = _T("CheckFile ok");1096 return returnCode;1097 }1098 1023 1099 1024 #define MAP_FILTER(value, obj) \ … … 1105 1030 finder.filter_chain.push_back(filteritem_type(file_filter_function_ex::filter_normal, filter)); } 1106 1031 1107 NSCAPI::nagiosReturn CheckDisk::CheckFile2( const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {1032 NSCAPI::nagiosReturn CheckDisk::CheckFile2(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 1108 1033 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 1109 std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);1110 1034 typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer; 1111 1035 typedef std::pair<int,file_filter> filteritem_type; 1112 1036 typedef std::list<filteritem_type > filterlist_type; 1113 if ( stl_args.empty()) {1037 if (args.empty()) { 1114 1038 message = _T("Missing argument(s)."); 1115 1039 return NSCAPI::returnUNKNOWN; … … 1130 1054 1131 1055 try { 1132 MAP_OPTIONS_BEGIN( stl_args)1056 MAP_OPTIONS_BEGIN(args) 1133 1057 MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 1134 1058 MAP_OPTIONS_STR2INT(_T("truncate"), truncate) … … 1288 1212 1289 1213 1290 NSCAPI::nagiosReturn CheckDisk::CheckSingleFile( const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) {1214 NSCAPI::nagiosReturn CheckDisk::CheckSingleFile(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 1291 1215 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 1292 std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);1293 1216 check_file_multi checker; 1294 1217 typedef std::pair<int,file_filter> filteritem_type; 1295 1218 typedef std::list<filteritem_type > filterlist_type; 1296 if ( stl_args.empty()) {1219 if (args.empty()) { 1297 1220 message = _T("Missing argument(s)."); 1298 1221 return NSCAPI::returnUNKNOWN; … … 1305 1228 1306 1229 try { 1307 MAP_OPTIONS_BEGIN( stl_args)1230 MAP_OPTIONS_BEGIN(args) 1308 1231 //MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 1309 1232 MAP_OPTIONS_STR2INT(_T("truncate"), truncate) … … 1351 1274 return returnCode; 1352 1275 } 1353 NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx:: blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) {1276 NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 1354 1277 if (command == _T("CheckFileSize")) { 1355 return CheckFileSize(arg Len, char_args, msg, perf);1278 return CheckFileSize(arguments, message, perf); 1356 1279 } else if (command == _T("CheckDriveSize")) { 1357 return CheckDriveSize(argLen, char_args, msg, perf); 1358 } else if (command == _T("CheckFile")) { 1359 return CheckFile(argLen, char_args, msg, perf); 1280 return CheckDriveSize(arguments, message, perf); 1360 1281 } else if (command == _T("CheckFile2")) { 1361 return CheckFile2(arg Len, char_args, msg, perf);1282 return CheckFile2(arguments, message, perf); 1362 1283 } else if (command == _T("CheckSingleFile")) { 1363 return CheckSingleFile(arg Len, char_args, msg, perf);1284 return CheckSingleFile(arguments, message, perf); 1364 1285 } else if (command == _T("getFileAge")) { 1365 return getFileAge(arg Len, char_args, msg, perf);1286 return getFileAge(arguments, message, perf); 1366 1287 } 1367 1288 return NSCAPI::returnIgnored; … … 1369 1290 1370 1291 1292 NSC_WRAP_DLL(); 1371 1293 NSC_WRAPPERS_MAIN_DEF(gCheckDisk); 1372 1294 NSC_WRAPPERS_IGNORE_MSG_DEF(); -
branches/stable/modules/CheckDisk/CheckDisk.h
r261 r281 25 25 #include <checkHelpers.hpp> 26 26 27 class CheckDisk {27 class CheckDisk : public nscapi::impl::SimpleCommand { 28 28 private: 29 29 bool show_errors_; … … 34 34 // Module calls 35 35 bool loadModule(); 36 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 36 37 bool unloadModule(); 37 38 … … 42 43 return _T("CheckDisk can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."); 43 44 } 44 NSCModuleWrapper::module_version getModuleVersion() {45 NSCModuleWrapper::module_version version = {0, 0, 1 };45 nscapi::plugin_wrapper::module_version getModuleVersion() { 46 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 46 47 return version; 47 48 } … … 50 51 bool hasMessageHandler(); 51 52 std::wstring get_filter(unsigned int drvType); 52 NSCAPI::nagiosReturn handleCommand(const strEx:: blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf);53 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 53 54 54 55 // Check commands 55 NSCAPI::nagiosReturn CheckFileSize(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 56 NSCAPI::nagiosReturn CheckDriveSize(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 57 NSCAPI::nagiosReturn CheckFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 58 NSCAPI::nagiosReturn CheckFile2(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 59 NSCAPI::nagiosReturn getFileAge(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 60 NSCAPI::nagiosReturn CheckSingleFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 56 NSCAPI::nagiosReturn CheckFileSize(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 57 NSCAPI::nagiosReturn CheckDriveSize(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 58 NSCAPI::nagiosReturn CheckFile2(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 59 NSCAPI::nagiosReturn getFileAge(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 60 NSCAPI::nagiosReturn CheckSingleFile(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 61 61 62 62 private: -
branches/stable/modules/CheckDisk/stdafx.h
r75 r281 21 21 #pragma once 22 22 23 23 24 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 24 25 // Windows Header Files: … … 28 29 #include <functional> 29 30 31 #include <boost/lexical_cast.hpp> 32 33 #include <config.h> 34 #include <unicode_char.hpp> 35 #include <types.hpp> 30 36 #include <NSCAPI.h> 31 #include < NSCHelper.h>37 #include <nscapi/plugin.hpp> 32 38 33 39 #ifdef MEMCHECK -
trunk/CMakeLists.txt
r279 r281 201 201 ${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.cpp 202 202 ${NSCP_INCLUDEDIR}/nscapi/nscapi_core_wrapper.cpp 203 ${NSCP_INCLUDEDIR}/nscapi/settings.cpp 203 204 ) 204 205 … … 208 209 ${NSCP_INCLUDEDIR}/utils.h 209 210 ${NSCP_INCLUDEDIR}/NSCAPI.h 210 ${NSCP_INCLUDEDIR}/nscapi/macros.hpp211 # ${NSCP_INCLUDEDIR}/nscapi/macros.hpp 211 212 ${NSCP_INCLUDEDIR}/nscapi/nscapi_helper.hpp 212 213 ${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.hpp 213 214 ${NSCP_INCLUDEDIR}/nscapi/nscapi_core_wrapper.hpp 215 ${NSCP_INCLUDEDIR}/nscapi/settings.hpp 214 216 ) 215 217 … … 254 256 255 257 SET(ALL_MODULE_NAMES) 256 FILE(GLOB ALL_MODULES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "modules/*/CMakeLists.txt") 258 SET(BUILD_MODULE 0) 259 SET(BUILD_MODULE_SKIP_REASON "") 260 FILE(GLOB ALL_MODULES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "modules/*/module.cmake") 257 261 foreach(CURRENT_MODULE ${ALL_MODULES}) 258 262 get_filename_component(CURRENT_MODULE_PATH ${CURRENT_MODULE} PATH) 259 263 get_filename_component(CURRENT_MODULE_NAME ${CURRENT_MODULE_PATH} NAME) 260 message(STATUS "Adding module: ${CURRENT_MODULE_PATH} (${CURRENT_MODULE_NAME})") 261 ADD_SUBDIRECTORY("${CURRENT_MODULE_PATH}") 262 SET(ALL_MODULE_NAMES ${ALL_MODULE_NAMES} ${CURRENT_MODULE_NAME}) 264 include(${CURRENT_MODULE}) 265 IF(BUILD_MODULE) 266 message(STATUS "+ Module ${CURRENT_MODULE_NAME}: Added") 267 ADD_SUBDIRECTORY("${CURRENT_MODULE_PATH}") 268 SET(ALL_MODULE_NAMES ${ALL_MODULE_NAMES} ${CURRENT_MODULE_NAME}) 269 ELSE(BUILD_MODULE) 270 message(STATUS "- Module ${CURRENT_MODULE_NAME}: Skipped ${BUILD_MODULE_SKIP_REASON}") 271 ENDIF(BUILD_MODULE) 272 273 #ADD_SUBDIRECTORY("${CURRENT_MODULE_PATH}") 274 #SET(ALL_MODULE_NAMES ${ALL_MODULE_NAMES} ${CURRENT_MODULE_NAME}) 263 275 endforeach(CURRENT_MODULE ${ALL_MODULES}) 264 276 -
trunk/include/NSCAPI.h
r257 r281 122 122 typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); 123 123 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int); 124 typedef NSCAPI::errorReturn (*lpNSAPIExpandPath)(const wchar_t*,wchar_t*,unsigned int); 124 125 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); 125 126 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *); … … 154 155 namespace plugin_api { 155 156 typedef int (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 156 typedef int (*lpLoadModule)( int);157 typedef int (*lpLoadModule)(const wchar_t*,int); 157 158 typedef int (*lpGetName)(wchar_t*,unsigned int); 158 159 typedef int (*lpGetDescription)(wchar_t*,unsigned int); -
trunk/include/config.h.in
r217 r281 72 72 73 73 #define DATE_FORMAT _T("%#c") 74 75 76 #define DEFAULT_CONF_LOCATION _T("ini") 77 #define DEFAULT_CONF_OLD_LOCATION _T("old://${exe-path}/nsc.ini") 78 79 /* 80 #;location=old://${exe-path}/nsc.ini 81 #location=ini://${exe-path}/nsclient.ini 82 #;location=ini://${base-path}/nsclient.ini 83 #;location=registry://HKEY_LOCAL_MACHINE/software/NSClient++ 84 */ 85 74 86 75 87 -
trunk/include/file_helpers.hpp
r226 r281 7 7 public: 8 8 static bool is_directory(std::wstring path) { 9 boost::filesystem::is_directory(path);9 return boost::filesystem::is_directory(path); 10 10 } 11 11 // static bool is_directory(DWORD dwAtt) { … … 37 37 }; 38 38 39 class meta { 40 public: 41 static boost::filesystem::wpath get_path(boost::filesystem::wpath path) { 42 return path.branch_path(); 43 } 44 static std::wstring get_filename(boost::filesystem::wpath path) { 45 return path.leaf(); 46 } 47 static std::wstring get_path(std::wstring file) { 48 boost::filesystem::wpath path = file; 49 return path.branch_path().string(); 50 } 51 static std::wstring get_filename(std::wstring file) { 52 boost::filesystem::wpath path = file; 53 return path.leaf(); 54 } 55 }; 56 39 57 class patterns { 40 58 public: -
trunk/include/nrpe/server/handler.hpp
r278 r281 19 19 virtual unsigned int get_payload_length() = 0; 20 20 virtual void set_payload_length(unsigned int payload) = 0; 21 virtual void set_allow_arguments(bool) = 0; 22 virtual void set_allow_nasty_arguments(bool) = 0; 23 virtual void set_perf_data(bool) = 0; 21 24 22 25 }; -
trunk/include/nrpe/server/server.cpp
r280 r281 12 12 13 13 namespace ip = boost::asio::ip; 14 15 16 const int server::connection_info::backlog_default = 0; 14 17 15 18 server::server(connection_info info) … … 27 30 ip::tcp::resolver::iterator endpoint_iterator; 28 31 if (info.address.empty()) { 29 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info. port));32 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_port())); 30 33 } else { 31 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info. address, info.port));34 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_address(), info.port)); 32 35 } 33 36 ip::tcp::resolver::iterator end; … … 39 42 SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 40 43 request_handler_->log_debug(__FILEW__, __LINE__, _T("Using cert: ") + to_wstring(info.certificate)); 41 context_.use_tmp_dh_file( info.certificate);44 context_.use_tmp_dh_file(to_string(info.certificate)); 42 45 context_.set_verify_mode(boost::asio::ssl::context::verify_none); 43 46 } … … 49 52 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 50 53 acceptor_.bind(endpoint); 51 acceptor_.listen(); 54 if (info.back_log == connection_info::backlog_default) 55 acceptor_.listen(); 56 else 57 acceptor_.listen(info.back_log); 52 58 53 59 acceptor_.async_accept(new_connection_->socket(), -
trunk/include/nrpe/server/server.hpp
r280 r281 36 36 public: 37 37 struct connection_info { 38 connection_info(boost::shared_ptr<nrpe::server::handler> request_handler_) : request_handler(request_handler_) {} 38 static const int backlog_default; 39 connection_info(boost::shared_ptr<nrpe::server::handler> request_handler_) : request_handler(request_handler_), back_log(backlog_default) {} 39 40 std::string address; 40 std::string port; 41 std::size_t thread_pool_size; 41 unsigned int port; 42 std::string get_port() { return to_string(port); } 43 std::string get_address() { return to_string(address); } 44 unsigned int thread_pool_size; 45 int back_log; 42 46 bool use_ssl; 47 bool allow_args; 48 bool allow_nasty; 49 unsigned int timeout; 43 50 boost::shared_ptr<nrpe::server::handler> request_handler; 44 std:: string certificate;51 std::wstring certificate; 45 52 std::wstring get_endpoint_str() { 46 53 return to_wstring(address) + _T(":") + to_wstring(port); -
trunk/include/nscapi/macros.hpp
r278 r281 6 6 #define NSC_WRAPPERS_MAIN() \ 7 7 extern "C" int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f); \ 8 extern "C" int NSLoadModule(int mode); \ 8 extern "C" int NSLoadModule(); \ 9 extern "C" int NSLoadModuleEx(const wchar_t alias, int mode); \ 9 10 extern "C" void NSDeleteBuffer(char**buffer); \ 10 11 extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \ … … 63 64 } \ 64 65 } \ 65 extern int NSLoadModule (int mode) { \66 try { \67 return GET_PLUGIN()->wrapLoadModule(toObject.loadModule(mode)); \66 extern int NSLoadModuleEx(wchar_t* alias, int mode) { \ 67 try { \ 68 return GET_PLUGIN()->wrapLoadModule(toObject.loadModuleEx(alias, mode)); \ 68 69 } catch (nscapi::nscapi_exception e) { \ 69 NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 70 return NSCAPI::hasFailed; \ 71 } catch (...) { \ 72 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 73 return NSCAPI::hasFailed; \ 70 NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 71 return NSCAPI::hasFailed; \ 72 } catch (...) { \ 73 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 74 return NSCAPI::hasFailed; \ 75 } \ 76 } \ 77 extern int NSLoadModule() { \ 78 try { \ 79 return GET_PLUGIN()->wrapLoadModule(toObject.loadModule()); \ 80 } catch (nscapi::nscapi_exception e) { \ 81 NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 82 return NSCAPI::hasFailed; \ 83 } catch (...) { \ 84 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 85 return NSCAPI::hasFailed; \ 74 86 } \ 75 87 } \ -
trunk/include/nscapi/nscapi_core_wrapper.cpp
r277 r281 271 271 wchar_t *buffer = new wchar_t[buf_len+1]; 272 272 if (fNSAPIGetSettingsString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, buf_len) != NSCAPI::isSuccess) { 273 delete [] buffer; 274 throw nscapi::nscapi_exception(_T("Settings could not be retrieved.")); 275 } 276 std::wstring ret = buffer; 277 delete [] buffer; 278 return ret; 279 } 280 281 std::wstring nscapi::core_wrapper::expand_path(std::wstring value) { 282 if (!fNSAPIExpandPath) 283 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 284 unsigned int buf_len = getBufferLength(); 285 wchar_t *buffer = new wchar_t[buf_len+1]; 286 if (fNSAPIExpandPath(value.c_str(), buffer, buf_len) != NSCAPI::isSuccess) { 273 287 delete [] buffer; 274 288 throw nscapi::nscapi_exception(_T("Settings could not be retrieved.")); … … 575 589 576 590 fNSAPISettingsSave = (nscapi::core_api::lpNSAPISettingsSave)f(_T("NSAPISettingsSave")); 591 592 fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); 577 593 578 594 return true; -
trunk/include/nscapi/nscapi_core_wrapper.hpp
r258 r281 42 42 nscapi::core_api::lpNSAPIReleaseSettingsSectionBuffer fNSAPIReleaseSettingsSectionBuffer; 43 43 nscapi::core_api::lpNSAPIGetSettingsString fNSAPIGetSettingsString; 44 nscapi::core_api::lpNSAPIExpandPath fNSAPIExpandPath; 44 45 nscapi::core_api::lpNSAPIGetSettingsInt fNSAPIGetSettingsInt; 45 46 nscapi::core_api::lpNSAPIMessage fNSAPIMessage; … … 111 112 , fNSAPIReleasePluginList(NULL) 112 113 , fNSAPISettingsSave(NULL) 114 , fNSAPIExpandPath(NULL) 113 115 , buffer_length_(-1) 114 116 , id_(-1) … … 120 122 std::list<std::wstring> getSettingsSection(std::wstring section); 121 123 std::wstring getSettingsString(std::wstring section, std::wstring key, std::wstring defaultValue); 124 std::wstring expand_path(std::wstring value); 122 125 int getSettingsInt(std::wstring section, std::wstring key, int defaultValue); 123 126 void settings_register_key(std::wstring path, std::wstring key, NSCAPI::settings_type type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced); -
trunk/include/nscapi/nscapi_plugin_wrapper.hpp
r277 r281 170 170 namespace impl { 171 171 172 class simple_plugin { 173 public: 174 nscapi::core_wrapper* get_core() { 175 return nscapi::plugin_singleton->get_core(); 176 } 177 }; 178 172 179 class SimpleNotificationHandler { 173 180 public: … … 220 227 } 221 228 std::wstring msg, perf; 222 NSCAPI::nagiosReturn ret = handleCommand(command , args, msg, perf);229 NSCAPI::nagiosReturn ret = handleCommand(command.c_str(), args, msg, perf); 223 230 224 231 PluginCommand::ResponseMessage response_message; … … 239 246 } 240 247 241 virtual NSCAPI::nagiosReturn handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) = 0;248 virtual NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) = 0; 242 249 }; 243 250 -
trunk/include/nscapi/plugin.hpp
r258 r281 2 2 3 3 #include <nscapi/macros.hpp> 4 #include <nscapi/settings.hpp> 4 5 #include <nscapi/nscapi_helper.hpp> 5 6 #include <nscapi/nscapi_plugin_wrapper.hpp> -
trunk/include/settings/Settings.h
r244 r281 29 29 #include <boost/thread/locks.hpp> 30 30 #include <boost/filesystem/path.hpp> 31 #include <boost/regex.hpp> 31 32 #include <strEx.h> 32 33 #define BUFF_LEN 4096 … … 111 112 ini_file, 112 113 xml_file, 114 lua, 113 115 } settings_type; 114 116 typedef enum { … … 157 159 /// @author mickem 158 160 static settings_type string_to_type(std::wstring key) { 159 if (key == _T("ini")) 161 // detect location here!! 162 boost::wregex old(_T("old://.*nsc\.ini$"), boost::regex::icase); 163 boost::wregex ini(_T("ini://.*\.ini$"), boost::regex::icase); 164 boost::wregex reg(_T("registry://.*/$"), boost::regex::icase); 165 boost::wregex re_lua(_T("lua://.*\.lua$"), boost::regex::icase); 166 if (boost::regex_match(key, ini)) 160 167 return ini_file; 161 if ( key == _T("registry"))168 if (boost::regex_match(key, reg)) 162 169 return registry; 163 if ( key == _T("xml"))164 return xml_file;170 if (boost::regex_match(key, re_lua)) 171 return lua; 165 172 return old_ini_file; 166 173 } … … 1296 1303 path_cache_type path_cache_; 1297 1304 std::wstring context_; 1305 net::url url_; 1298 1306 1299 1307 //SettingsInterfaceImpl() : core_(NULL) {} 1300 SettingsInterfaceImpl(SettingsCore *core, std::wstring context) : core_(core), context_(context) {}1308 SettingsInterfaceImpl(SettingsCore *core, std::wstring context) : core_(core), context_(context), url_(net::parse(context_)) {} 1301 1309 1302 1310 ////////////////////////////////////////////////////////////////////////// … … 1612 1620 return context_; 1613 1621 } 1622 virtual std::wstring get_file_name_from_context() { 1623 return url_.path; 1624 } 1625 virtual std::wstring find_file() { 1626 return core_->find_file(url_.path); 1627 } 1628 1614 1629 ////////////////////////////////////////////////////////////////////////// 1615 1630 /// Set the context. -
trunk/include/settings/macros.h
r278 r281 148 148 namespace nrpe { 149 149 DEFINE_PATH(SECTION, NRPE_SECTION_PROTOCOL); 150 DESCRIBE_SETTING(SECTION, "NRPE SECTION", "Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options.");150 //DESCRIBE_SETTING(SECTION, "NRPE SECTION", "Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options."); 151 151 152 152 … … 158 158 159 159 DEFINE_SETTING_I(PORT, NRPE_SECTION_PROTOCOL, "port", 5666); 160 DESCRIBE_SETTING(PORT, "NSCLIENT PORT NUMBER", "This is the port the NSClientListener.dll will listen to.");160 //DESCRIBE_SETTING(PORT, "NSCLIENT PORT NUMBER", "This is the port the NSClientListener.dll will listen to."); 161 161 162 162 DEFINE_SETTING_S(BINDADDR, NRPE_SECTION_PROTOCOL, GENERIC_KEY_BIND_TO, ""); 163 DESCRIBE_SETTING(BINDADDR, "BIND TO ADDRESS", "Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. Leaving this blank will bind to all avalible IP adresses.");163 //DESCRIBE_SETTING(BINDADDR, "BIND TO ADDRESS", "Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. Leaving this blank will bind to all avalible IP adresses."); 164 164 165 165 DEFINE_SETTING_I(READ_TIMEOUT, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_READ_TIMEOUT, 30); 166 DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out.");166 //DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out."); 167 167 168 168 DEFINE_SETTING_I(LISTENQUE, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_LISTENQUE, 0); 169 DESCRIBE_SETTING_ADVANCED(LISTENQUE, "LISTEN QUEUE", "Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts."); 169 //DESCRIBE_SETTING_ADVANCED(LISTENQUE, "LISTEN QUEUE", "Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts."); 170 171 DEFINE_SETTING_I(THREAD_POOL, NRPE_SECTION_PROTOCOL, "thread pool", 10); 172 //DESCRIBE_SETTING_ADVANCED(THREAD_POOL, "THREAD POOL", ""); 173 174 170 175 171 176 DEFINE_SETTING_B(CACHE_ALLOWED, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_CACHE_ALLOWED, false); … … 173 178 174 179 DEFINE_SETTING_B(KEYUSE_SSL, NRPE_SECTION_PROTOCOL, GENERIC_KEY_USE_SSL, true); 175 DESCRIBE_SETTING(KEYUSE_SSL, "USE SSL SOCKET", "This option controls if SSL should be used on the socket.");180 //DESCRIBE_SETTING(KEYUSE_SSL, "USE SSL SOCKET", "This option controls if SSL should be used on the socket."); 176 181 177 182 DEFINE_SETTING_I(PAYLOAD_LENGTH, NRPE_SECTION_PROTOCOL, "payload length", 1024); 178 DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work.");183 //DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work."); 179 184 180 185 DEFINE_SETTING_B(ALLOW_PERFDATA, NRPE_SECTION, "performance data", true); 181 DESCRIBE_SETTING_ADVANCED(ALLOW_PERFDATA, "PERFORMANCE DATA", "Send performance data back to nagios (set this to 0 to remove all performance data)."); 182 183 DEFINE_SETTING_S(SCRIPT_PATH, NRPE_SECTION, "script path", ""); 184 DESCRIBE_SETTING_ADVANCED(SCRIPT_PATH, "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but usefull if you have loads of scripts :)"); 186 //DESCRIBE_SETTING_ADVANCED(ALLOW_PERFDATA, "PERFORMANCE DATA", "Send performance data back to nagios (set this to 0 to remove all performance data)."); 185 187 186 188 DEFINE_SETTING_I(CMD_TIMEOUT, NRPE_SECTION, "command timeout", 60); 187 DESCRIBE_SETTING(CMD_TIMEOUT, "COMMAND TIMEOUT", "This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off.");189 //DESCRIBE_SETTING(CMD_TIMEOUT, "COMMAND TIMEOUT", "This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off."); 188 190 189 191 DEFINE_SETTING_B(ALLOW_ARGS, NRPE_SECTION, "allow arguments", false); 190 DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed.");192 //DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."); 191 193 192 194 DEFINE_SETTING_B(ALLOW_NASTY, NRPE_SECTION, "allow nasy characters", false); 193 DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 194 195 DEFINE_PATH(SECTION_HANDLERS, NRPE_SECTION_HANDLERS); 196 DESCRIBE_SETTING(SECTION_HANDLERS, "NRPE COMMAND DEFINITIONS -- DEPRECATED", "Command definitions that this daemon will run (it will also run all internal commands such as those from ther ExternalScriptModule)."); 195 //DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 197 196 198 197 } … … 233 232 namespace external_scripts { 234 233 DEFINE_PATH(SECTION, EXTSCRIPT_SECTION); 235 DESCRIBE_SETTING(SECTION, "EXTERNAL SCRIPT SECTION", "Section for external scripts (CheckExternalScripts.dll).");234 //DESCRIBE_SETTING(SECTION, "EXTERNAL SCRIPT SECTION", "Section for external scripts (CheckExternalScripts.dll)."); 236 235 237 236 DEFINE_SETTING_I(TIMEOUT, EXTSCRIPT_SECTION, "timeout", 60); 238 DESCRIBE_SETTING(TIMEOUT, "COMMAND TIMEOUT", "The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.");237 //DESCRIBE_SETTING(TIMEOUT, "COMMAND TIMEOUT", "The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones."); 239 238 240 239 DEFINE_SETTING_B(ALLOW_ARGS, EXTSCRIPT_SECTION, "allow arguments", false); 241 DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the we will allow clients to specify arguments to commands that are executed.");240 //DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the we will allow clients to specify arguments to commands that are executed."); 242 241 243 242 DEFINE_SETTING_B(ALLOW_NASTY, EXTSCRIPT_SECTION, "allow nasy characters", false); 244 DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.");243 //DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 245 244 246 245 DEFINE_SETTING_S(SCRIPT_PATH, EXTSCRIPT_SECTION, "script path", ""); 247 DESCRIBE_SETTING_ADVANCED(SCRIPT_PATH, "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but usefull if you have loads of scripts :)");246 //DESCRIBE_SETTING_ADVANCED(SCRIPT_PATH, "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but usefull if you have loads of scripts :)"); 248 247 249 248 DEFINE_PATH(SCRIPT_SECTION, EXTSCRIPT_SCRIPT_SECTION); 250 DESCRIBE_SETTING(SCRIPT_SECTION, "EXTERNAL SCRIPT SCRIPTS SECTION", "A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments> for instance:");249 //DESCRIBE_SETTING(SCRIPT_SECTION, "EXTERNAL SCRIPT SCRIPTS SECTION", "A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments> for instance:"); 251 250 252 251 DEFINE_PATH(ALIAS_SECTION, EXTSCRIPT_ALIAS_SECTION); 253 DESCRIBE_SETTING(ALIAS_SECTION, "EXTERNAL SCRIPT ALIAS SECTION", "Works like the \"inject\" concept of NRPE scripts module. But in short a list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)");252 //DESCRIBE_SETTING(ALIAS_SECTION, "EXTERNAL SCRIPT ALIAS SECTION", "Works like the \"inject\" concept of NRPE scripts module. But in short a list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)"); 254 253 255 254 DEFINE_PATH(WRAPPINGS_SECTION, EXTSCRIPT_WRAPPINGS_SECTION); 256 DESCRIBE_SETTING(WRAPPINGS_SECTION, "EXTERNAL SCRIPT WRAPPINGS SECTION", "");255 //DESCRIBE_SETTING(WRAPPINGS_SECTION, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); 257 256 258 257 DEFINE_PATH(WRAPPED_SCRIPT, EXTSCRIPT_WRAPPED_SCRIPT); 259 DESCRIBE_SETTING(WRAPPED_SCRIPT, "EXTERNAL SCRIPT WRAPPINGS SECTION", "");258 //DESCRIBE_SETTING(WRAPPED_SCRIPT, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); 260 259 261 260 } -
trunk/include/settings/settings_ini.hpp
r244 r281 7 7 #include <boost/filesystem/operations.hpp> 8 8 9 #include <settings/Settings.h> 9 #include <settings/settings_core.hpp> 10 #include <settings/settings_core_impl.hpp> 10 11 #include <simpleini/simpleini.h> 11 12 #include <error.hpp> 12 13 13 namespace Settings {14 class INISettings : public Settings::SettingsInterfaceImpl {14 namespace settings { 15 class INISettings : public settings::SettingsInterfaceImpl { 15 16 private: 16 17 boost::filesystem::wpath filename_; … … 19 20 20 21 public: 21 INISettings(Settings::SettingsCore *core, std::wstring context) : ini(false, false, false), is_loaded_(false), Settings::SettingsInterfaceImpl(core, context) {} 22 INISettings(settings::settings_core *core, std::wstring context) : ini(false, false, false), is_loaded_(false), settings::SettingsInterfaceImpl(core, context) { 23 load_data(); 24 } 22 25 ////////////////////////////////////////////////////////////////////////// 23 26 /// Create a new settings interface of "this kind" … … 38 41 /// 39 42 /// @author mickem 40 virtual std::wstring get_real_string( SettingsCore::key_path_type key) {43 virtual std::wstring get_real_string(settings_core::key_path_type key) { 41 44 load_data(); 42 45 const wchar_t *val = ini.GetValue(key.first.c_str(), key.second.c_str(), NULL); … … 53 56 /// 54 57 /// @author mickem 55 virtual int get_real_int( SettingsCore::key_path_type key) {58 virtual int get_real_int(settings_core::key_path_type key) { 56 59 std::wstring str = get_real_string(key); 57 60 return strEx::stoi(str); … … 65 68 /// 66 69 /// @author mickem 67 virtual bool get_real_bool( SettingsCore::key_path_type key) {70 virtual bool get_real_bool(settings_core::key_path_type key) { 68 71 std::wstring str = get_real_string(key); 69 72 return SettingsInterfaceImpl::string_to_bool(str); … … 77 80 /// 78 81 /// @author mickem 79 virtual bool has_real_key( SettingsCore::key_path_type key) {82 virtual bool has_real_key(settings_core::key_path_type key) { 80 83 return ini.GetValue(key.first.c_str(), key.second.c_str()) != NULL; 81 84 } … … 86 89 /// 87 90 /// @author mickem 88 virtual SettingsCore::settings_type get_type() {89 return SettingsCore::ini_file;90 }91 // virtual settings_core::settings_type get_type() { 92 // return settings_core::ini_file; 93 // } 91 94 ////////////////////////////////////////////////////////////////////////// 92 95 /// Is this the active settings store … … 95 98 /// 96 99 /// @author mickem 97 virtual bool is_active() {98 return true;99 }100 // virtual bool is_active() { 101 // return true; 102 // } 100 103 ////////////////////////////////////////////////////////////////////////// 101 104 /// Write a value to the resulting context. … … 105 108 /// 106 109 /// @author mickem 107 virtual void set_real_value( SettingsCore::key_path_type key, conainer value) {110 virtual void set_real_value(settings_core::key_path_type key, conainer value) { 108 111 try { 109 const SettingsCore::key_description desc = get_core()->get_registred_key(key.first, key.second);112 const settings_core::key_description desc = get_core()->get_registred_key(key.first, key.second); 110 113 std::wstring comment = _T("; "); 111 114 if (!desc.title.empty()) … … 120 123 } catch (KeyNotFoundException e) { 121 124 ini.SetValue(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), _T("; Undocumented key")); 122 } catch ( SettingsException e) {125 } catch (settings_exception e) { 123 126 get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 124 127 } catch (...) { … … 130 133 try { 131 134 get_core()->get_logger()->quick_debug(_T("Setting path: ") + path); 132 const SettingsCore::path_description desc = get_core()->get_registred_path(path);135 const settings_core::path_description desc = get_core()->get_registred_path(path); 133 136 if (!desc.description.empty()) { 134 137 std::wstring comment = _T("; ") + desc.description; … … 137 140 } catch (KeyNotFoundException e) { 138 141 ini.SetValue(path.c_str(), NULL, NULL, _T("; Undocumented section")); 139 } catch ( SettingsException e) {142 } catch (settings_exception e) { 140 143 get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write section: ") + e.getError())); 141 144 } catch (...) { … … 211 214 throw_SI_error(rc, _T("Failed to save file")); 212 215 } 213 virtual SettingsCore::key_type get_key_type(std::wstring path, std::wstring key) {214 return SettingsCore::key_string;216 virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 217 return settings_core::key_string; 215 218 } 216 219 private: … … 225 228 if (rc < 0) 226 229 throw_SI_error(rc, _T("Failed to load file")); 230 231 CSimpleIni::TNamesDepend lst; 232 ini.GetAllKeys(_T("/includes"), lst); 233 for (CSimpleIni::TNamesDepend::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) { 234 add_child(ini.GetValue(_T("/includes"), (*cit).pItem)); 235 } 227 236 is_loaded_ = true; 228 237 } … … 235 244 if (err == SI_FILE) 236 245 error_str = _T("I/O error: ") + error::lookup::last_error(); 237 throw SettingsException(msg + _T(": ") + get_context() + _T(" - ") + error_str);246 throw settings_exception(msg + _T(": ") + get_context() + _T(" - ") + error_str); 238 247 } 239 248 boost::filesystem::wpath get_file_name() { 240 249 if (filename_.empty()) { 241 filename_ = get_core()->get_base() / boost::filesystem::wpath(get_core()->get_boot_string(get_context(), _T("file"), _T("nsclient.ini"))); 250 filename_ = get_file_from_context(); 251 //filename_ = get_core()->get_base() / boost::filesystem::wpath(get_core()->get_boot_string(get_context(), _T("file"), _T("nsclient.ini"))); 242 252 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading INI settings from: ") + filename_.string()); 243 253 } … … 247 257 return boost::filesystem::is_regular(get_file_name()); 248 258 } 259 virtual std::wstring get_info() { 260 return _T("INI settings: (") + context_ + _T(", ") + get_file_name().string() + _T(")"); 261 } 262 249 263 }; 250 264 } -
trunk/include/settings/settings_old.hpp
r244 r281 3 3 #include <string> 4 4 #include <map> 5 #include <settings/ Settings.h>5 #include <settings/settings_core.hpp> 6 6 #include <simpleini/SimpleIni.h> 7 7 #include <settings/macros.h> … … 11 11 #define MAIN_STRING_LENGTH _T("string_length") 12 12 13 namespace Settings {14 class OLDSettings : public Settings::SettingsInterfaceImpl {13 namespace settings { 14 class OLDSettings : public settings::SettingsInterfaceImpl { 15 15 std::wstring filename_; 16 16 public: 17 OLDSettings( Settings::SettingsCore *core, std::wstring context) :Settings::SettingsInterfaceImpl(core, context) {17 OLDSettings(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) { 18 18 add_mapping(MAIN_MODULES_SECTION, MAIN_MODULES_SECTION_OLD); 19 19 add_mapping(setting_keys::settings_def::PAYLOAD_LEN_PATH, setting_keys::settings_def::PAYLOAD_LEN, MAIN_SECTION_TITLE, MAIN_STRING_LENGTH); … … 80 80 SETTINGS_MAP_KEY_A(nrpe::PAYLOAD_LENGTH,NRPE_SECTION_TITLE, NRPE_SETTINGS_STRLEN); 81 81 SETTINGS_MAP_KEY_A(nrpe::ALLOW_PERFDATA,NRPE_SECTION_TITLE, NRPE_SETTINGS_PERFDATA); 82 SETTINGS_MAP_KEY_A(nrpe::SCRIPT_PATH, NRPE_SECTION_TITLE, NRPE_SETTINGS_SCRIPTDIR);83 82 SETTINGS_MAP_KEY_A(nrpe::CMD_TIMEOUT, NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT); 84 83 SETTINGS_MAP_KEY_A(nrpe::ALLOW_ARGS, NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS); 85 84 SETTINGS_MAP_KEY_A(nrpe::ALLOW_NASTY, NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META); 86 87 SETTINGS_MAP_SECTION_A(nrpe::SECTION_HANDLERS,NRPE_HANDLER_SECTION_TITLE);88 89 85 90 86 #define NSCA_AGENT_SECTION_TITLE _T("NSCA Agent") … … 126 122 } 127 123 typedef std::map<std::wstring,std::wstring> path_map; 128 typedef std::map< SettingsCore::key_path_type,SettingsCore::key_path_type> key_map;124 typedef std::map<settings_core::key_path_type,settings_core::key_path_type> key_map; 129 125 path_map sections_; 130 126 key_map keys_; … … 133 129 } 134 130 void add_mapping(std::wstring path_new, std::wstring key_new, std::wstring path_old, std::wstring key_old) { 135 SettingsCore::key_path_type new_key(path_new, key_new);136 SettingsCore::key_path_type old_key(path_old, key_old);131 settings_core::key_path_type new_key(path_new, key_new); 132 settings_core::key_path_type old_key(path_old, key_old); 137 133 keys_[new_key] = old_key; 138 134 } … … 144 140 return (*it).second; 145 141 } 146 SettingsCore::key_path_type map_key(SettingsCore::key_path_type new_key) {142 settings_core::key_path_type map_key(settings_core::key_path_type new_key) { 147 143 key_map::iterator it1 = keys_.find(new_key); 148 144 if (it1 != keys_.end()) … … 150 146 path_map::iterator it2 = sections_.find(new_key.first); 151 147 if (it2 != sections_.end()) 152 return SettingsCore::key_path_type((*it2).second, new_key.second);148 return settings_core::key_path_type((*it2).second, new_key.second); 153 149 return new_key; 154 150 } … … 171 167 /// 172 168 /// @author mickem 173 virtual std::wstring get_real_string( SettingsCore::key_path_type key) {169 virtual std::wstring get_real_string(settings_core::key_path_type key) { 174 170 key = map_key(key); 175 171 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second); … … 182 178 TCHAR* buffer = new TCHAR[bufferSize+2]; 183 179 if (buffer == NULL) 184 throw SettingsException(_T("Out of memmory error!"));180 throw settings_exception(_T("Out of memmory error!")); 185 181 int retVal = GetPrivateProfileString(path.c_str(), key.c_str(), UNLIKELY_STRING, buffer, bufferSize, get_file_name().c_str()); 186 182 if (retVal == bufferSize-1) { … … 207 203 /// 208 204 /// @author mickem 209 virtual int get_real_int( SettingsCore::key_path_type key) {205 virtual int get_real_int(settings_core::key_path_type key) { 210 206 std::wstring str = get_real_string(key); 211 207 return strEx::stoi(str); … … 219 215 /// 220 216 /// @author mickem 221 virtual bool get_real_bool( SettingsCore::key_path_type key) {217 virtual bool get_real_bool(settings_core::key_path_type key) { 222 218 std::wstring str = get_real_string(key); 223 219 return SettingsInterfaceImpl::string_to_bool(str); … … 231 227 /// 232 228 /// @author mickem 233 virtual bool has_real_key( SettingsCore::key_path_type key) {229 virtual bool has_real_key(settings_core::key_path_type key) { 234 230 return has_key_int(key.first, key.second); 235 231 } … … 239 235 TCHAR* buffer = new TCHAR[bufferLength+1]; 240 236 if (buffer == NULL) 241 throw SettingsException(_T("has_key_int:: Failed to allocate memory for buffer!"));237 throw settings_exception(_T("has_key_int:: Failed to allocate memory for buffer!")); 242 238 std::wstring mapped = map_path(path); 243 239 unsigned int count = ::GetPrivateProfileSection(mapped.c_str(), buffer, bufferLength-2, get_file_name().c_str()); … … 262 258 return false; 263 259 } 264 ////////////////////////////////////////////////////////////////////////// 265 /// Get the type this settings store represent. 266 /// 267 /// @return the type of settings store 268 /// 269 /// @author mickem 270 virtual SettingsCore::settings_type get_type() { 271 return SettingsCore::old_ini_file; 272 } 273 ////////////////////////////////////////////////////////////////////////// 274 /// Is this the active settings store 275 /// 276 /// @return 277 /// 278 /// @author mickem 279 virtual bool is_active() { 280 return true; 281 } 260 282 261 ////////////////////////////////////////////////////////////////////////// 283 262 /// Write a value to the resulting context. … … 287 266 /// 288 267 /// @author mickem 289 virtual void set_real_value( SettingsCore::key_path_type key, conainer value) {268 virtual void set_real_value(settings_core::key_path_type key, conainer value) { 290 269 try { 291 270 key = map_key(key); 292 271 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second + _T("//") + value.get_string()); 293 272 WritePrivateProfileString(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), get_file_name().c_str()); 294 } catch ( SettingsException e) {273 } catch (settings_exception e) { 295 274 get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 296 275 } catch (...) { … … 375 354 TCHAR* buffer = new TCHAR[bufferLength+1]; 376 355 if (buffer == NULL) 377 throw SettingsException(_T("getSections:: Failed to allocate memory for buffer!"));356 throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 378 357 unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, get_file_name().c_str()); 379 358 if (count == bufferLength-2) { … … 405 384 int_read_section(mapped_path, list); 406 385 /* 407 Settings::SettingsCore::mapped_key_list_type mapped_keys = get_core()->find_maped_keys(path);408 for ( Settings::SettingsCore::mapped_key_list_type::const_iterator cit = mapped_keys.begin(); cit != mapped_keys.end(); ++cit) {386 settings::settings_core::mapped_key_list_type mapped_keys = get_core()->find_maped_keys(path); 387 for (settings::settings_core::mapped_key_list_type::const_iterator cit = mapped_keys.begin(); cit != mapped_keys.end(); ++cit) { 409 388 if (has_key((*cit).dst.first, (*cit).dst.second)) 410 389 list.push_back((*cit).src.second); … … 412 391 */ 413 392 } 414 virtual SettingsCore::key_type get_key_type(std::wstring path, std::wstring key) {415 return SettingsCore::key_string;393 virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 394 return settings_core::key_string; 416 395 } 417 396 private: … … 428 407 TCHAR* buffer = new TCHAR[bufferLength+1]; 429 408 if (buffer == NULL) 430 throw SettingsException(_T("getSections:: Failed to allocate memory for buffer!"));409 throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 431 410 unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 432 411 if (count == bufferLength-2) { … … 452 431 inline std::wstring get_file_name() { 453 432 if (filename_.empty()) { 454 filename_ = (get_core()->get_base() / get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"))).string(); 433 filename_ = get_file_from_context(); 434 //filename_ = (get_core()->get_base() / get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"))).string(); 455 435 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading old settings from: ") + filename_); 456 436 } … … 460 440 return boost::filesystem::is_regular_file(get_file_name()); 461 441 } 442 virtual std::wstring get_info() { 443 return _T("INI settings: (") + context_ + _T(", ") + get_file_name() + _T(")"); 444 } 462 445 }; 463 446 } -
trunk/include/settings/settings_registry.hpp
r244 r281 3 3 #include <string> 4 4 #include <windows.h> 5 #include <settings/ Settings.h>5 #include <settings/settings_core.hpp> 6 6 #include <msvc_wrappers.h> 7 7 #include <error.hpp> … … 10 10 11 11 12 namespace Settings {13 class REGSettings : public Settings::SettingsInterfaceImpl {12 namespace settings { 13 class REGSettings : public settings::SettingsInterfaceImpl { 14 14 private: 15 15 struct reg_key { … … 26 26 27 27 public: 28 REGSettings( Settings::SettingsCore *core, std::wstring context) : Settings::SettingsInterfaceImpl(core, context) {}28 REGSettings(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) {} 29 29 30 30 virtual ~REGSettings(void) {} … … 48 48 /// 49 49 /// @author mickem 50 virtual std::wstring get_real_string( SettingsCore::key_path_type key) {50 virtual std::wstring get_real_string(settings_core::key_path_type key) { 51 51 return getString_(get_reg_key(key.first), key.second); 52 52 } … … 59 59 /// 60 60 /// @author mickem 61 virtual int get_real_int( SettingsCore::key_path_type key) {61 virtual int get_real_int(settings_core::key_path_type key) { 62 62 throw KeyNotFoundException(key); 63 63 } … … 70 70 /// 71 71 /// @author mickem 72 virtual bool get_real_bool( SettingsCore::key_path_type key) {72 virtual bool get_real_bool(settings_core::key_path_type key) { 73 73 throw KeyNotFoundException(key); 74 74 } … … 81 81 /// 82 82 /// @author mickem 83 virtual bool has_real_key( SettingsCore::key_path_type key) {83 virtual bool has_real_key(settings_core::key_path_type key) { 84 84 return false; 85 }86 //////////////////////////////////////////////////////////////////////////87 /// Get the type this settings store represent.88 ///89 /// @return the type of settings store90 ///91 /// @author mickem92 virtual SettingsCore::settings_type get_type() {93 return SettingsCore::registry;94 }95 //////////////////////////////////////////////////////////////////////////96 /// Is this the active settings store97 ///98 /// @return99 ///100 /// @author mickem101 virtual bool is_active() {102 return true;103 85 } 104 86 ////////////////////////////////////////////////////////////////////////// … … 109 91 /// 110 92 /// @author mickem 111 virtual void set_real_value( SettingsCore::key_path_type key, conainer value) {112 if (value.type == SettingsCore::key_string) {93 virtual void set_real_value(settings_core::key_path_type key, conainer value) { 94 if (value.type == settings_core::key_string) { 113 95 if (!setString_(get_reg_key(key), key.second, value.get_string())) 114 throw SettingsException(_T("Failed to write key: ") + key.first + _T(".") + key.second);115 } else if (value.type == SettingsCore::key_integer) {96 throw settings_exception(_T("Failed to write key: ") + key.first + _T(".") + key.second); 97 } else if (value.type == settings_core::key_integer) { 116 98 if (!setInt_(get_reg_key(key), key.second, value.get_int())) 117 throw SettingsException(_T("Failed to write key: ") + key.first + _T(".") + key.second);118 } else if (value.type == SettingsCore::key_bool) {99 throw settings_exception(_T("Failed to write key: ") + key.first + _T(".") + key.second); 100 } else if (value.type == settings_core::key_bool) { 119 101 if (!setInt_(get_reg_key(key), key.second, value.get_bool()?1:0)) 120 throw SettingsException(_T("Failed to write key: ") + key.first + _T(".") + key.second);102 throw settings_exception(_T("Failed to write key: ") + key.first + _T(".") + key.second); 121 103 } else { 122 throw SettingsException(_T("Invalid settings type."));104 throw settings_exception(_T("Invalid settings type.")); 123 105 } 124 106 } … … 151 133 getValues_(get_reg_key(path), list); 152 134 } 153 virtual SettingsCore::key_type get_key_type(std::wstring path, std::wstring key) {154 return SettingsCore::key_string;135 virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 136 return settings_core::key_string; 155 137 } 156 138 private: 157 reg_key get_reg_key( SettingsCore::key_path_type key) {139 reg_key get_reg_key(settings_core::key_path_type key) { 158 140 return get_reg_key(key.first); 159 141 } … … 217 199 return ret; 218 200 } 219 throw SettingsException(_T("String to long: ") + path.to_string());201 throw settings_exception(_T("String to long: ") + path.to_string()); 220 202 } else if (type == REG_DWORD) { 221 203 DWORD dw = *(reinterpret_cast<DWORD*>(bData)); 222 204 return strEx::itos(dw); 223 205 } 224 throw SettingsException(_T("Unsupported key type: ") + path.to_string());206 throw settings_exception(_T("Unsupported key type: ") + path.to_string()); 225 207 } else if (lRet == ERROR_FILE_NOT_FOUND) 226 208 throw KeyNotFoundException(_T("Key not found: ") + path.to_string()); 227 throw SettingsException(_T("Failed to open key: ") + path.to_string() + _T(": ") + error::lookup::last_error(lRet));209 throw settings_exception(_T("Failed to open key: ") + path.to_string() + _T(": ") + error::lookup::last_error(lRet)); 228 210 } 229 211 static DWORD getInt_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, DWORD def) { … … 266 248 if (bRet != ERROR_SUCCESS) { 267 249 delete [] lpValueName; 268 throw SettingsException(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error());250 throw settings_exception(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error()); 269 251 } 270 252 list.push_back(std::wstring(lpValueName)); … … 290 272 if (bRet != ERROR_SUCCESS) { 291 273 delete [] lpValueName; 292 throw SettingsException(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error());274 throw settings_exception(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error()); 293 275 } 294 276 list.push_back(std::wstring(lpValueName)); … … 297 279 } 298 280 } 299 /* 300 void setSection(std::wstring section, sectionList data) { 301 std::wcout << _T("Unsupported function call") << std::endl; 302 } 303 */ 281 virtual std::wstring get_info() { 282 return _T("Registry settings: (") + context_ + _T(",TODO)"); 283 } 304 284 }; 305 285 } -
trunk/include/simple_timer.hpp
r270 r281 14 14 ~simple_timer() { 15 15 if (log) 16 std:: cout << text << stop() << std::endl;;16 std::wcout << text << stop() << std::endl;; 17 17 } 18 18 -
trunk/include/strEx.h
r277 r281 33 33 #include <iostream> 34 34 35 #include <cctype> 36 35 37 #include <unicode_char.hpp> 36 38 … … 77 79 return result; 78 80 } 81 } 82 83 namespace net { 84 85 struct url { 86 std::wstring protocol; 87 std::wstring host; 88 std::wstring path; 89 std::wstring query; 90 91 }; 92 inline url parse(const std::wstring& url_s) { 93 url ret; 94 const std::wstring prot_end(_T("://")); 95 std::wstring::const_iterator prot_i = std::search(url_s.begin(), url_s.end(), prot_end.begin(), prot_end.end()); 96 ret.protocol.reserve(std::distance(url_s.begin(), prot_i)); 97 std::transform(url_s.begin(), prot_i, std::back_inserter(ret.protocol), std::ptr_fun<int,int>(std::tolower)); // protocol is icase 98 if( prot_i == url_s.end() ) 99 return ret; 100 std::advance(prot_i, prot_end.length()); 101 std::wstring::const_iterator path_i = std::find(prot_i, url_s.end(), L'/'); 102 ret.host.reserve(std::distance(prot_i, path_i)); 103 std::transform(prot_i, path_i, std::back_inserter(ret.host), std::ptr_fun<int,int>(std::tolower)); // host is icase 104 std::wstring::const_iterator query_i = std::find(path_i, url_s.end(), L'?'); 105 ret.path.assign(path_i, query_i); 106 if( query_i != url_s.end() ) 107 ++query_i; 108 ret.query.assign(query_i, url_s.end()); 109 return ret; 110 } 111 112 79 113 } 80 114 namespace strEx { … … 630 664 631 665 666 667 template<class char_type> 668 struct ci_char_traits : public std::char_traits<char_type> { 669 static bool eq( char_type c1, char_type c2 ) { 670 return toupper(c1) == toupper(c2); 671 } 672 673 static bool ne( char_type c1, char_type c2 ) { 674 return toupper(c1) != toupper(c2); 675 } 676 677 static bool lt( char_type c1, char_type c2 ) { 678 return toupper(c1) < toupper(c2); 679 } 680 681 static int compare( const char_type* s1, const char_type* s2, size_t n ) { 682 return memicmp( s1, s2, n ); 683 // if available on your compiler, 684 // otherwise you can roll your own 685 } 686 687 static const char* find( const char_type* s, int n, char_type a ) { 688 while( n-- > 0 && toupper(*s) != toupper(a) ) { 689 ++s; 690 } 691 return s; 692 } 693 }; 694 typedef std::basic_string<wchar_t, ci_char_traits<wchar_t> > wci_string; 695 632 696 template<class _E> 633 697 struct blind_traits : public std::char_traits<_E> -
trunk/modules/CheckEventLog/CheckEventLog.cpp
r273 r281 30 30 #include <error.hpp> 31 31 #include <map> 32 <<<<<<< .working33 32 #include <vector> 34 33 #include <config.h> 35 =======36 #include <vector>37 >>>>>>> .merge-right.r27238 34 39 35 #include <boost/bind.hpp> … … 49 45 CheckEventLog gCheckEventLog; 50 46 51 52 53 54 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)55 {56 NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);57 return TRUE;58 }59 60 47 CheckEventLog::CheckEventLog() { 61 48 } … … 70 57 #include <parsers/ast.cpp> 71 58 72 <<<<<<< .working73 bool CheckEventLog::loadModule(NSCAPI::moduleLoadMode mode) {74 try {75 SETTINGS_REG_PATH(event_log::SECTION);76 SETTINGS_REG_KEY_B(event_log::DEBUG_KEY);77 SETTINGS_REG_KEY_S(event_log::SYNTAX);78 79 NSCModuleHelper::registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!"));80 debug_ = SETTINGS_GET_BOOL(event_log::DEBUG_KEY);81 lookup_names_ = SETTINGS_GET_BOOL(event_log::LOOKUP_NAMES);82 syntax_ = SETTINGS_GET_STRING(event_log::SYNTAX);83 buffer_length_ = SETTINGS_GET_INT(event_log::BUFFER_SIZE);84 buffer_length_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_BUFFER, EVENTLOG_BUFFER_DEFAULT);85 } catch (NSCModuleHelper::NSCMHExcpetion &e) {86 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_);87 } catch (...) {88 NSC_LOG_ERROR_STD(_T("Failed to register command."));89 =======90 59 namespace filter { 91 60 namespace where { … … 226 195 } 227 196 }; 228 >>>>>>> .merge-right.r272 229 } 230 } 231 232 233 namespace simple_registry { 234 class registry_exception { 235 std::wstring what_; 236 public: 237 registry_exception(std::wstring what) : what_(what) {} 238 registry_exception(std::wstring path, std::wstring what) : what_(path + _T(" -- ") + what) {} 239 registry_exception(std::wstring path, std::wstring key, std::wstring what) : what_(path + _T(".") + key + _T(" -- ") + what) {} 240 std::wstring what() { 241 return what_; 242 } 243 }; 244 class registry_key { 245 HKEY hKey_; 246 std::wstring path_; 247 BYTE *bData_; 248 TCHAR *buffer_; 249 public: 250 registry_key(HKEY hRootKey, std::wstring path) : path_(path), hKey_(NULL), bData_(NULL), buffer_(NULL) { 251 LONG lRet = ERROR_SUCCESS; 252 if (lRet = RegOpenKeyEx(hRootKey, path.c_str(), 0, KEY_QUERY_VALUE|KEY_READ, &hKey_) != ERROR_SUCCESS) 253 throw registry_exception(path, _T("Failed to open key: ") + error::format::from_system(lRet)); 254 } 255 ~registry_key() { 256 if (hKey_ != NULL) 257 RegCloseKey(hKey_); 258 delete [] bData_; 259 delete [] buffer_; 260 } 261 std::wstring get_string(std::wstring key, DWORD buffer_length = 2048) { 262 DWORD type; 263 std::wstring ret; 264 DWORD cbData = buffer_length; 265 delete [] bData_; 266 bData_ = new BYTE[cbData+2]; 267 // TODO: add get size here ! 268 LONG lRet = RegQueryValueEx(hKey_, key.c_str(), NULL, &type, bData_, &cbData); 269 if (lRet != ERROR_SUCCESS) 270 throw registry_exception(path_, key, _T("Failed to get value: ") + error::format::from_system(lRet)); 271 if (cbData >= buffer_length || cbData < 0) 272 throw registry_exception(path_, key, _T("Failed to get value: buffer to small")); 273 bData_[cbData] = 0; 274 if (type == REG_SZ) { 275 ret = reinterpret_cast<LPCTSTR>(bData_); 276 } else if (type == REG_EXPAND_SZ) { 277 std::wstring s = reinterpret_cast<LPCTSTR>(bData_); 278 delete [] buffer_; 279 buffer_ = new TCHAR[buffer_length+1]; 280 DWORD expRet = ExpandEnvironmentStrings(s.c_str(), buffer_, buffer_length); 281 if (expRet >= buffer_length) 282 throw registry_exception(path_, key, _T("Buffer to small (expand)")); 283 else 284 ret = buffer_; 285 } else { 286 throw registry_exception(path_, key, _T("Unknown type (not a string)")); 287 } 288 return ret; 289 } 290 DWORD get_int(std::wstring key) { 291 DWORD type; 292 DWORD cbData = sizeof(DWORD); 293 DWORD ret = 0; 294 LONG lRet = RegQueryValueEx(hKey_, key.c_str(), NULL, &type, reinterpret_cast<LPBYTE>(&ret), &cbData); 295 if (lRet != ERROR_SUCCESS) 296 throw registry_exception(path_, key, _T("Failed to get value: ") + error::format::from_system(lRet)); 297 if (type != REG_DWORD) 298 throw registry_exception(path_, key, _T("Unknown type (not a DWORD)")); 299 return ret; 300 } 301 302 <<<<<<< .working 303 std::list<std::wstring> get_keys(DWORD buffer_length = 2048) { 304 std::list<std::wstring> ret; 305 DWORD cSubKeys=0; 306 DWORD cMaxKeyLen; 307 // Get the class name and the value count. 308 LONG lRet = RegQueryInfoKey(hKey_,NULL,NULL,NULL,&cSubKeys,&cMaxKeyLen,NULL,NULL,NULL,NULL,NULL,NULL); 309 if (lRet != ERROR_SUCCESS) 310 throw registry_exception(path_, _T("Failed to query key info: ") + error::format::from_system(lRet)); 311 if (cSubKeys == 0) 312 return ret; 313 delete [] buffer_; 314 buffer_ = new TCHAR[cMaxKeyLen+20]; 315 for (unsigned int i=0; i<cSubKeys; i++) { 316 lRet = RegEnumKey(hKey_, i, buffer_, cMaxKeyLen+10); 317 if (lRet != ERROR_SUCCESS) { 318 throw registry_exception(path_, _T("Failed to enumerate: ") + error::lookup::last_error(lRet)); 319 } 320 std::wstring str = buffer_; 321 ret.push_back(str); 322 } 323 return ret; 324 } 325 326 }; 327 328 std::wstring get_string(HKEY hKey, std::wstring path, std::wstring key) { 329 registry_key reg(hKey, path); 330 return reg.get_string(key); 331 } 332 } 333 334 std::wstring find_eventlog_name(std::wstring name) { 335 try { 336 simple_registry::registry_key key(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog")); 337 std::list<std::wstring> list = key.get_keys(); 338 for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 339 try { 340 simple_registry::registry_key sub_key(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + *cit); 341 std::wstring file = sub_key.get_string(_T("DisplayNameFile")); 342 int id = sub_key.get_int(_T("DisplayNameID")); 343 std::wstring real_name = error::format::message::from_module(file, id); 344 strEx::replace(real_name, _T("\n"), _T("")); 345 strEx::replace(real_name, _T("\r"), _T("")); 346 NSC_DEBUG_MSG(_T("Attempting to match: ") + real_name + _T(" with ") + name); 347 if (real_name == name) 348 return *cit; 349 } catch (simple_registry::registry_exception &e) {} 350 } 351 return name; 352 } catch (simple_registry::registry_exception &e) { 353 NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand): ") + e.what()); 354 return name; 355 } catch (...) { 356 NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand)")); 357 return name; 358 } 359 } 360 361 class EventLogRecord { 362 EVENTLOGRECORD *pevlr_; 363 __int64 currentTime_; 364 std::wstring file_; 365 public: 366 EventLogRecord(std::wstring file, EVENTLOGRECORD *pevlr, __int64 currentTime) : file_(file), pevlr_(pevlr), currentTime_(currentTime) { 367 ======= 197 } 198 } 199 200 201 368 202 369 203 struct filter_container { … … 412 246 } 413 247 return true; 414 >>>>>>> .merge-right.r272415 248 } 416 249 … … 439 272 440 273 } 441 <<<<<<< .working442 443 std::wstring userSID() const {444 if (pevlr_->UserSidOffset == 0)445 return _T("");446 PSID p = reinterpret_cast<PSID>(reinterpret_cast<LPBYTE>(pevlr_) + + pevlr_->UserSidOffset);447 DWORD userLen = 0;448 DWORD domainLen = 0;449 SID_NAME_USE sidName;450 451 LookupAccountSid(NULL, p, NULL, &userLen, NULL, &domainLen, &sidName);452 LPTSTR user = new TCHAR[userLen+10];453 LPTSTR domain = new TCHAR[domainLen+10];454 455 LookupAccountSid(NULL, p, user, &userLen, domain, &domainLen, &sidName);456 user[userLen] = 0;457 domain[domainLen] = 0;458 std::wstring ustr = user;459 std::wstring dstr = domain;460 delete [] user;461 delete [] domain;462 if (!dstr.empty())463 dstr = dstr + _T("\\");464 if (ustr.empty() && dstr.empty())465 return _T("missing");466 467 return dstr + ustr;468 =======469 274 std::wstring get_name() { 470 275 return _T("deprecated"); 471 >>>>>>> .merge-right.r272 472 } 473 <<<<<<< .working 474 ======= 276 } 475 277 std::wstring get_subject() { return _T("TODO"); } 476 >>>>>>> .merge-right.r272477 278 478 279 }; … … 519 320 return _T("old"); 520 321 } 521 <<<<<<< .working522 static DWORD translateType(std::wstring sType) {523 if (sType == _T("error"))524 return EVENTLOG_ERROR_TYPE;525 if (sType == _T("warning"))526 return EVENTLOG_WARNING_TYPE;527 if (sType == _T("info"))528 return EVENTLOG_INFORMATION_TYPE;529 if (sType == _T("auditSuccess"))530 return EVENTLOG_AUDIT_SUCCESS;531 if (sType == _T("auditFailure"))532 return EVENTLOG_AUDIT_FAILURE;533 return strEx::stoi(sType);534 }535 static std::wstring translateType(DWORD dwType) {536 if (dwType == EVENTLOG_ERROR_TYPE)537 return _T("error");538 if (dwType == EVENTLOG_WARNING_TYPE)539 return _T("warning");540 if (dwType == EVENTLOG_INFORMATION_TYPE)541 return _T("info");542 if (dwType == EVENTLOG_AUDIT_SUCCESS)543 return _T("auditSuccess");544 if (dwType == EVENTLOG_AUDIT_FAILURE)545 return _T("auditFailure");546 return strEx::itos(dwType);547 }548 static DWORD translateSeverity(std::wstring sType) {549 if (sType == _T("success"))550 return 0;551 if (sType == _T("informational"))552 return 1;553 if (sType == _T("warning"))554 return 2;555 if (sType == _T("error"))556 return 3;557 return strEx::stoi(sType);558 }559 static std::wstring translateSeverity(DWORD dwType) {560 if (dwType == 0)561 return _T("success");562 if (dwType == 1)563 return _T("informational");564 if (dwType == 2)565 return _T("warning");566 if (dwType == 3)567 return _T("error");568 return strEx::itos(dwType);569 }570 std::wstring get_dll() {571 try {572 return simple_registry::get_string(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + file_ + (std::wstring)_T("\\") + eventSource(), _T("EventMessageFile"));573 } catch (simple_registry::registry_exception &e) {574 NSC_LOG_ERROR_STD(_T("Could not extract DLL for eventsource: ") + eventSource() + _T(": ") + e.what());575 return _T("");576 =======577 322 std::wstring get_subject() { return _T("TODO"); } 578 323 }; … … 595 340 message = _T("Parsing failed: ") + ast_parser.rest; 596 341 return false; 597 >>>>>>> .merge-right.r272 598 } 599 <<<<<<< .working 600 } 601 ======= 342 } 602 343 if (data.bDebug) 603 344 NSC_DEBUG_MSG_STD(_T("Parsing succeeded: ") + ast_parser.result_as_tree()); … … 609 350 if (data.bDebug) 610 351 NSC_DEBUG_MSG_STD(_T("Type resolution succeeded: ") + ast_parser.result_as_tree()); 611 >>>>>>> .merge-right.r272 612 613 <<<<<<< .working 614 std::wstring render_message() { 615 std::vector<std::wstring> args; 616 TCHAR* *pArgs = new TCHAR*[pevlr_->NumStrings+1]; 617 TCHAR* p = reinterpret_cast<TCHAR*>(reinterpret_cast<LPBYTE>(pevlr_) + pevlr_->StringOffset); 618 for (unsigned int i =0;i<pevlr_->NumStrings;i++) { 619 args.push_back(p); 620 pArgs[i] = p; 621 DWORD len = wcslen(p); 622 p = &(p[len+1]); 623 //p += len+1; 624 ======= 352 625 353 if (!ast_parser.bind(dummy) || dummy.has_error()) { 626 354 message = _T("Variable and function binding failed: ") + dummy.get_error(); 627 355 return false; 628 >>>>>>> .merge-right.r272629 356 } 630 357 if (data.bDebug) 631 358 NSC_DEBUG_MSG_STD(_T("Binding succeeded: ") + ast_parser.result_as_tree()); 632 359 633 <<<<<<< .working634 std::wstring ret;635 strEx::splitList dlls = strEx::splitEx(get_dll(), _T(";"));636 for (strEx::splitList::const_iterator cit = dlls.begin(); cit != dlls.end(); ++cit) {637 //std::wstring msg = error::format::message::from_module((*cit), eventID(), _sz);638 std::wstring msg;639 try {640 msg = error::format::message::from_module_x64((*cit), eventID(), pArgs, pevlr_->NumStrings);641 if (msg.empty()) {642 msg = error::format::message::from_module_x64((*cit), pevlr_->EventID, pArgs, pevlr_->NumStrings);643 }644 } catch (...) {645 msg = _T("Unknown exception getting message");646 }647 strEx::replace(msg, _T("\n"), _T(" "));648 strEx::replace(msg, _T("\t"), _T(" "));649 std::string::size_type pos = msg.find_last_not_of(_T("\n\t "));650 if (pos != std::string::npos) {651 msg = msg.substr(0,pos);652 }653 if (!msg.empty()) {654 if (!ret.empty())655 ret += _T(", ");656 ret += msg;657 }658 =======659 360 if (!ast_parser.static_eval(dummy) || dummy.has_error()) { 660 361 message = _T("Static evaluation failed: ") + dummy.get_error(); … … 672 373 if (obj.has_error()) { 673 374 NSC_LOG_ERROR_STD(_T("Error: ") + obj.get_error()); 674 >>>>>>> .merge-right.r272 675 } 676 <<<<<<< .working 677 delete [] pArgs; 678 ======= 679 >>>>>>> .merge-right.r272 375 } 680 376 return ret; 681 377 } 682 <<<<<<< .working683 // SYSTEMTIME684 boost::posix_time::ptime get_time(DWORD time) {685 FILETIME FileTime, LocalFileTime;686 SYSTEMTIME SysTime;687 __int64 lgTemp;688 __int64 SecsTo1970 = 116444736000000000;689 =======690 378 std::wstring get_name() { 691 379 return _T("where"); … … 693 381 std::wstring get_subject() { return data.filter; } 694 382 }; 695 >>>>>>> .merge-right.r272 696 697 698 699 <<<<<<< .working 700 return boost::date_time::time_from_ftime<boost::posix_time::ptime>(FileTime); 701 702 703 /* 704 FileTimeToLocalFileTime(&FileTime, &LocalFileTime); 705 FileTimeToSystemTime(&LocalFileTime, &SysTime); 706 return SysTime; 707 */ 708 } 709 ======= 383 384 385 710 386 void CheckEventLog::parse(std::wstring expr) { 711 387 //return false; … … 717 393 */ 718 394 } 719 >>>>>>> .merge-right.r272720 721 <<<<<<< .working722 boost::posix_time::ptime get_time_generated() {723 return get_time(pevlr_->TimeGenerated);724 =======725 395 bool CheckEventLog::loadModule() { 396 return false; 397 } 398 399 bool CheckEventLog::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 726 400 try { 727 NSCModuleHelper::registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 728 debug_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_DEBUG, EVENTLOG_DEBUG_DEFAULT)==1; 729 lookup_names_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_LOOKUP_NAMES, EVENTLOG_LOOKUP_NAMES_DEFAULT)==1; 730 syntax_ = NSCModuleHelper::getSettingsString(EVENTLOG_SECTION_TITLE, EVENTLOG_SYNTAX, EVENTLOG_SYNTAX_DEFAULT); 731 buffer_length_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_BUFFER, EVENTLOG_BUFFER_DEFAULT); 732 } catch (NSCModuleHelper::NSCMHExcpetion &e) { 401 SETTINGS_REG_PATH(event_log::SECTION); 402 SETTINGS_REG_KEY_B(event_log::DEBUG_KEY); 403 SETTINGS_REG_KEY_S(event_log::SYNTAX); 404 405 GET_CORE()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 406 407 debug_ = SETTINGS_GET_BOOL(event_log::DEBUG_KEY); 408 lookup_names_ = SETTINGS_GET_BOOL(event_log::LOOKUP_NAMES); 409 syntax_ = SETTINGS_GET_STRING(event_log::SYNTAX); 410 buffer_length_ = SETTINGS_GET_INT(event_log::BUFFER_SIZE); 411 } catch (nscapi::nscapi_exception &e) { 733 412 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 734 413 } catch (...) { 735 414 NSC_LOG_ERROR_STD(_T("Failed to register command.")); 736 >>>>>>> .merge-right.r272 737 } 738 <<<<<<< .working 739 boost::posix_time::ptime get_time_written() { 740 return get_time(pevlr_->TimeWritten); 741 } 742 ======= 415 } 743 416 /* 744 417 parse(_T("321 = 123")); … … 746 419 parse(_T("id = 123")); 747 420 parse(_T("id = 321")); 748 >>>>>>> .merge-right.r272749 421 750 422 parse(_T("id = '123'")); … … 815 487 } catch (simple_registry::registry_exception &e) { e;} 816 488 } 817 <<<<<<< .working818 819 strEx::replace(syntax, _T("%source%"), eventSource());820 strEx::replace(syntax, _T("%generated%"), strEx::format_date(get_time_generated(), date_format));821 strEx::replace(syntax, _T("%written%"), strEx::format_date(get_time_written(), date_format));822 strEx::replace(syntax, _T("%type%"), translateType(eventType()));823 strEx::replace(syntax, _T("%severity%"), translateSeverity(severity()));824 strEx::replace(syntax, _T("%strings%"), enumStrings());825 strEx::replace(syntax, _T("%id%"), strEx::itos(eventID()));826 strEx::replace(syntax, _T("%user%"), userSID());827 return syntax;828 =======829 489 return name; 830 490 } catch (simple_registry::registry_exception &e) { … … 834 494 NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand)")); 835 495 return name; 836 >>>>>>> .merge-right.r272837 496 } 838 497 } … … 882 541 }; 883 542 884 <<<<<<< .working 885 886 #define MAP_FILTER(value, obj, filtermode) \ 887 else if (p__.first == value) { eventlog_filter filter; filter.obj = p__.second; filter_chain.push_back(filteritem_type(filtermode, filter)); } 888 889 struct event_log_buffer { 890 BYTE *bBuffer; 891 DWORD bufferSize_; 892 event_log_buffer(DWORD bufferSize) : bufferSize_(bufferSize) { 893 bBuffer = new BYTE[bufferSize+10]; 894 } 895 ~event_log_buffer() { 896 delete [] bBuffer; 897 } 898 EVENTLOGRECORD* getBufferUnsafe() { 899 return reinterpret_cast<EVENTLOGRECORD*>(bBuffer); 900 } 901 DWORD getBufferSize() { 902 return bufferSize_; 903 } 904 }; 905 906 ======= 907 >>>>>>> .merge-right.r272 908 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 543 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 909 544 if (command != _T("CheckEventLog")) 910 545 return NSCAPI::returnIgnored; 911 <<<<<<< .working912 typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container;913 typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container;914 915 typedef std::pair<int,eventlog_filter> filteritem_type;916 typedef std::list<filteritem_type > filterlist_type;917 =======918 546 simple_timer time; 919 547 typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container; 920 548 typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container; 921 922 >>>>>>> .merge-right.r272 549 923 550 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 924 std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args);925 551 926 552 std::list<std::wstring> files; 927 <<<<<<< .working928 filterlist_type filter_chain;929 553 EventLogQuery1Container query1; 930 554 EventLogQuery2Container query2; 931 =======932 EventLogQuery1Container query1;933 EventLogQuery2Container query2;934 >>>>>>> .merge-right.r272935 555 936 556 … … 938 558 939 559 bool bPerfData = true; 940 <<<<<<< .working941 bool bFilterIn = true;942 bool bFilterAll = false;943 560 bool bFilterNew = true; 944 bool bShowDescriptions = false;945 =======946 bool bFilterNew = true;947 >>>>>>> .merge-right.r272948 561 bool unique = false; 949 562 unsigned int truncate = 0; … … 959 572 } 960 573 */ 961 event_log_buffer buffer(buffer_length_); 962 /* 574 963 575 try { 964 event_log_buffer buffer(buffer_length_); 965 } catch (std::exception e) { 966 message = std::wstring(_T("Failed to allocate memory: ")) + strEx::string_to_wstring(e.what()); 967 return NSCAPI::returnUNKNOWN; 968 } 969 */ 970 971 try { 972 MAP_OPTIONS_BEGIN(stl_args) 576 MAP_OPTIONS_BEGIN(arguments) 973 577 MAP_OPTIONS_NUMERIC_ALL(query1, _T("")) 974 578 MAP_OPTIONS_EXACT_NUMERIC_ALL(query2, _T("")) … … 1116 720 //GetOldestEventLogRecord(hLog, &dwThisRecord); 1117 721 1118 <<<<<<< .working1119 722 while (true) { 1120 723 BOOL bStatus = ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, … … 1123 726 DWORD err = GetLastError(); 1124 727 if (err == ERROR_INSUFFICIENT_BUFFER) { 1125 if (!buffer_error_reported) {1126 NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small change the value of ") + setting_keys::event_log::BUFFER_SIZE + _T("=") + strEx::itos(dwNeeded+1) + _T(" under [EventLog] in nsc.ini : ") + error::lookup::last_error(err));1127 buffer_error_reported = true;1128 }728 message = _T("EvenlogBuffer is too small change the value of ") + setting_keys::event_log::BUFFER_SIZE_PATH + _T("=") + strEx::itos(dwNeeded+1) + _T(": ") + error::lookup::last_error(err); 729 NSC_LOG_ERROR_STD(message); 730 CloseEventLog(hLog); 731 return NSCAPI::returnUNKNOWN; 1129 732 } else if (err == ERROR_HANDLE_EOF) { 1130 733 break; … … 1133 736 message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err); 1134 737 CloseEventLog(hLog); 1135 return NSCAPI::returnUNKNOWN;1136 }1137 }1138 EVENTLOGRECORD *pevlr = buffer.getBufferUnsafe();1139 while (dwRead > 0) {1140 //bool bMatch = bFilterAll;1141 bool bMatch = !bFilterIn;1142 EventLogRecord record((*cit2), pevlr, ltime);1143 1144 if (filter_chain.empty()) {1145 message = _T("No filters specified try adding: filter+generated=>2d");1146 =======1147 while (true) {1148 BOOL bStatus = ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ,1149 0, buffer.getBufferUnsafe(), buffer.getBufferSize(), &dwRead, &dwNeeded);1150 if (bStatus == FALSE) {1151 DWORD err = GetLastError();1152 if (err == ERROR_INSUFFICIENT_BUFFER) {1153 if (!buffer_error_reported) {1154 NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small change the value of ") + EVENTLOG_BUFFER + _T("=") + strEx::itos(dwNeeded+1) + _T(" under [EventLog] in nsc.ini : ") + error::lookup::last_error(err));1155 buffer_error_reported = true;1156 }1157 } else if (err == ERROR_HANDLE_EOF) {1158 break;1159 } else {1160 NSC_LOG_ERROR_STD(_T("Failed to read from eventlog: ") + error::lookup::last_error(err));1161 message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err);1162 CloseEventLog(hLog);1163 >>>>>>> .merge-right.r2721164 738 return NSCAPI::returnUNKNOWN; 1165 739 } … … 1208 782 pevlr = reinterpret_cast<EVENTLOGRECORD*>((LPBYTE)pevlr + pevlr->Length); 1209 783 } 1210 <<<<<<< .working1211 }1212 =======1213 }1214 >>>>>>> .merge-right.r2721215 DWORD err = GetLastError();1216 if (err == ERROR_INSUFFICIENT_BUFFER) {1217 NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small (set the value of ") + setting_keys::event_log::BUFFER_SIZE_TITLE + _T("): ") + error::lookup::last_error(err));1218 message = std::wstring(_T("EvenlogBuffer is too small (set the value of ")) + setting_keys::event_log::BUFFER_SIZE_TITLE + _T("): ") + error::lookup::last_error(err);1219 return NSCAPI::returnUNKNOWN;1220 } else if (err != ERROR_HANDLE_EOF) {1221 NSC_LOG_ERROR_STD(_T("Failed to read from eventlog: ") + error::lookup::last_error(err));1222 message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err);1223 return NSCAPI::returnUNKNOWN;1224 784 } 1225 785 CloseEventLog(hLog); … … 1256 816 1257 817 818 NSC_WRAP_DLL(); 1258 819 NSC_WRAPPERS_MAIN_DEF(gCheckEventLog); 1259 820 NSC_WRAPPERS_IGNORE_MSG_DEF(); -
trunk/modules/CheckEventLog/CheckEventLog.h
r273 r281 27 27 28 28 29 class CheckEventLog {29 class CheckEventLog : public nscapi::impl::SimpleCommand { 30 30 private: 31 31 bool debug_; … … 38 38 virtual ~CheckEventLog(); 39 39 // Module calls 40 bool loadModule(NSCAPI::moduleLoadMode mode); 40 bool loadModule(); 41 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 41 42 bool unloadModule(); 42 43 … … 44 45 return _T("Event log Checker."); 45 46 } 46 NSCModuleWrapper::module_version getModuleVersion() {47 NSCModuleWrapper::module_version version = {0, 0, 1 };47 nscapi::plugin_wrapper::module_version getModuleVersion() { 48 nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 48 49 return version; 49 50 } … … 56 57 bool hasCommandHandler(); 57 58 bool hasMessageHandler(); 58 NSCAPI::nagiosReturn handleCommand(const strEx:: blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf);59 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 59 60 }; -
trunk/modules/CheckEventLog/eventlog_record.hpp
r274 r281 200 200 } 201 201 202 inline boost::posix_time::ptime systemtime_to_time(const SYSTEMTIME &time) { 203 struct tm tmTime; 204 memset(&tmTime, 0, sizeof(tmTime)); 205 206 tmTime.tm_sec = time.wSecond; // seconds after the minute - [0,59] 207 tmTime.tm_min = time.wMinute; // minutes after the hour - [0,59] 208 tmTime.tm_hour = time.wHour; // hours since midnight - [0,23] 209 tmTime.tm_mday = time.wDay; // day of the month - [1,31] 210 tmTime.tm_mon = time.wMonth-1; // months since January - [0,11] 211 tmTime.tm_year = time.wYear-1900; // years since 1900 212 tmTime.tm_wday = time.wDayOfWeek; // days since Sunday - [0,6] 213 214 return boost::posix_time::ptime_from_tm(tmTime); 215 } 216 202 217 std::wstring render(bool propper, std::wstring syntax, std::wstring date_format = DATE_FORMAT) { 203 218 if (propper) { … … 209 224 210 225 strEx::replace(syntax, _T("%source%"), eventSource()); 211 strEx::replace(syntax, _T("%generated%"), strEx::format_date( get_time_generated(), date_format));212 strEx::replace(syntax, _T("%written%"), strEx::format_date( get_time_written(), date_format));226 strEx::replace(syntax, _T("%generated%"), strEx::format_date(systemtime_to_time(get_time_generated()), date_format)); 227 strEx::replace(syntax, _T("%written%"), strEx::format_date(systemtime_to_time(get_time_written()), date_format)); 213 228 strEx::replace(syntax, _T("%generated-raw%"), strEx::itos(pevlr_->TimeGenerated)); 214 229 strEx::replace(syntax, _T("%written-raw%"), strEx::itos(pevlr_->TimeWritten)); -
trunk/modules/CheckEventLog/stdafx.h
r207 r281 33 33 #include <functional> 34 34 35 #include <boost/lexical_cast.hpp> 36 37 #include <config.h> 38 #include <unicode_char.hpp> 39 #include <types.hpp> 35 40 #include <NSCAPI.h> 36 #include <nsc_module_wrapper.hpp> 37 #include <NSCHelper.h> 41 #include <nscapi/plugin.hpp> 38 42 39 43 #ifdef MEMCHECK -
trunk/modules/CheckExternalScripts/CheckExternalScripts.cpp
r279 r281 24 24 #include <string> 25 25 26 #include <settings/macros.h>27 26 #include <msvc_wrappers.h> 28 #include <config.h>29 27 #include <strEx.h> 30 #include <file_helpers.hpp>31 28 #include <file_helpers.hpp> 32 29 33 30 #include <boost/regex.hpp> 34 31 #include <boost/filesystem.hpp> 32 33 namespace sh = nscapi::settings_helper; 35 34 36 35 … … 43 42 boost::filesystem::wpath path = str_path; 44 43 if (path.has_relative_path()) 45 path = GET_CORE()->getBasePath() / path;44 path = get_core()->getBasePath() / path; 46 45 file_helpers::patterns::pattern_type split_path = file_helpers::patterns::split_pattern(path); 47 46 if (!boost::filesystem::is_directory(split_path.first)) … … 54 53 std::wstring name = itr->path().leaf(); 55 54 if (regex_match(name, pattern)) 56 add Command(name, (split_path.first / name).string(), _T(""));55 add_command(name.c_str(), (split_path.first / name).string()); 57 56 } 58 57 } … … 60 59 61 60 62 std::wstring CheckExternalScripts::getWrapping(std::wstring val) { 63 strEx::token tok = strEx::getToken(val, ' ', true); 64 std::wstring::size_type pos = tok.first.find_last_of(_T(".")); 65 if (pos == std::wstring::npos) 66 return _T(""); 67 return tok.first.substr(pos+1); 61 /** 62 * Load (initiate) module. 63 * Start the background collector thread and let it run until unloadModule() is called. 64 * @return true 65 */ 66 bool CheckExternalScripts::loadModule() { 67 return false; 68 68 } 69 69 70 void CheckExternalScripts::addWrappedCommand(std::wstring key, std::wstring tpl, std::wstring command ) {71 strEx::token tok = strEx::getToken(command, ' ', true);72 strEx::replace(tpl, _T("%SCRIPT%"), tok.first);73 strEx::replace(tpl, _T("%ARGS%"), tok.second);74 tok = strEx::getToken(tpl, ' ', true);75 addCommand(key.c_str(),tok.first, tok.second);76 }77 70 78 bool CheckExternalScripts::loadModule(NSCAPI::moduleLoadMode mode) {79 SETTINGS_REG_PATH(external_scripts::SECTION);80 SETTINGS_REG_PATH(external_scripts::SCRIPT_SECTION);81 SETTINGS_REG_PATH(external_scripts::ALIAS_SECTION);82 SETTINGS_REG_KEY_I(external_scripts::TIMEOUT);83 SETTINGS_REG_KEY_S(external_scripts::SCRIPT_PATH);84 SETTINGS_REG_KEY_B(external_scripts::ALLOW_ARGS);85 SETTINGS_REG_KEY_B(external_scripts::ALLOW_NASTY);86 71 87 timeout = SETTINGS_GET_INT(external_scripts::TIMEOUT); 88 scriptDirectory_ = SETTINGS_GET_STRING(external_scripts::SCRIPT_PATH); 89 allowArgs_ = SETTINGS_GET_BOOL(nrpe::ALLOW_ARGS); 90 allowNasty_ = SETTINGS_GET_BOOL(nrpe::ALLOW_NASTY); 91 std::list<std::wstring>::const_iterator it; 92 std::list<std::wstring> commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::SCRIPT_SECTION_PATH); 93 for (it = commands.begin(); it != commands.end(); ++it) { 94 if ((*it).empty()) 95 continue; 96 NSC_DEBUG_MSG_STD(_T("Looking under: ") + setting_keys::external_scripts::SCRIPT_SECTION_PATH + _T(", ") + (*it)); 97 std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::SCRIPT_SECTION_PATH, (*it), _T("")); 98 if (s.empty()) { 99 NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); 100 } else { 101 strEx::token tok = strEx::getToken(s, ' ', true); 102 addCommand((*it).c_str(), tok.first, tok.second); 72 bool CheckExternalScripts::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 73 try { 74 75 sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 76 settings.set_alias(alias, _T("external scripts")); 77 78 settings.add_path_to_settings() 79 (_T("EXTERNAL SCRIPT SECTION"), _T("Section for external scripts configuration options (CheckExternalScripts).")) 80 81 (_T("scripts"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_command, this, _1, _2)), 82 _T("EXTERNAL SCRIPT SCRIPT SECTION"), _T("A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>")) 83 84 (_T("alias"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_alias, this, _1, _2)), 85 _T("EXTERNAL SCRIPT ALIAS SECTION"), _T("A list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)")) 86 87 (_T("wrappings"), sh::wstring_map_path(&wrappings_) 88 , _T("EXTERNAL SCRIPT WRAPPINGS SECTION"), _T("")) 89 90 (_T("wrapped scripts"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_wrapping, this, _1, _2)), 91 _T("EXTERNAL SCRIPT WRAPPED SCRIPTS SECTION"), _T("")) 92 ; 93 94 settings.add_key_to_settings() 95 (_T("timeout"), sh::uint_key(&timeout, 60), 96 _T("COMMAND TIMEOUT"), _T("The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.")) 97 98 (_T("allow arguments"), sh::bool_key(&allowArgs_, false), 99 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 100 101 (_T("allow nasty characters"), sh::bool_key(&allowNasty_, false), 102 _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 103 104 (_T("script path"), sh::wstring_key(&scriptDirectory_), 105 _T("SCRIPT DIRECTORY"), _T("Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)")) 106 ; 107 108 settings.register_all(); 109 settings.notify(); 110 111 if (!scriptDirectory_.empty()) { 112 addAllScriptsFrom(scriptDirectory_); 103 113 } 114 root_ = get_core()->getBasePath(); 115 116 // } catch (nrpe::server::nrpe_exception &e) { 117 // NSC_LOG_ERROR_STD(_T("Exception caught: ") + e.what()); 118 // return false; 119 } catch (...) { 120 NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>")); 121 return false; 104 122 } 105 106 commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::ALIAS_SECTION_PATH);107 for (it = commands.begin(); it != commands.end(); ++it) {108 if ((*it).empty())109 continue;110 std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::ALIAS_SECTION_PATH, (*it), _T(""));111 if (s.empty()) {112 NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it));113 } else {114 strEx::token tok = strEx::getToken(s, ' ', true);115 addAlias((*it).c_str(), tok.first, tok.second);116 }117 }118 119 std::map<std::wstring,std::wstring> wrappers;120 std::list<std::wstring> wrappings = GET_CORE()->getSettingsSection(setting_keys::external_scripts::WRAPPINGS_SECTION_PATH);121 for (it = wrappings.begin(); it != wrappings.end(); ++it) {122 std::wstring val = GET_CORE()->getSettingsString(setting_keys::external_scripts::WRAPPINGS_SECTION_PATH, *it, _T(""));123 if (!(*it).empty() && !val.empty()) {124 wrappers[(*it)] = val;125 }126 }127 std::list<std::wstring> wscript = GET_CORE()->getSettingsSection(setting_keys::external_scripts::WRAPPED_SCRIPT_PATH);128 for (it = wscript.begin(); it != wscript.end(); ++it) {129 std::wstring val = GET_CORE()->getSettingsString(setting_keys::external_scripts::WRAPPED_SCRIPT_PATH, *it, _T(""));130 if (!(*it).empty() && !val.empty()) {131 std::wstring type = getWrapping(val);132 std::map<std::wstring,std::wstring>::const_iterator cit = wrappers.find(type);133 if (cit == wrappers.end()) {134 NSC_LOG_ERROR_STD(_T("Failed to find wrappings for: ") + type + _T(" (") + (*it) + _T(")"));135 } else {136 addWrappedCommand((*it), (*cit).second, val);137 }138 }139 }140 141 if (!scriptDirectory_.empty()) {142 addAllScriptsFrom(scriptDirectory_);143 }144 root_ = GET_CORE()->getBasePath();145 123 return true; 146 124 } … … 158 136 159 137 160 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 161 std::wstring cmd = command.c_str(); 162 boost::to_lower(cmd); 163 command_list::const_iterator cit = commands.find(cmd); 138 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 139 command_list::const_iterator cit = commands.find(command); 164 140 bool isAlias = false; 165 141 if (cit == commands.end()) { 166 cit = alias.find(c md);142 cit = alias.find(command); 167 143 if (cit == alias.end()) 168 144 return NSCAPI::returnIgnored; … … 193 169 } 194 170 return nscapi::plugin_helper::int2nagios(result); 195 /*196 } else if (cd.type == script_dir) {197 std::wstring args = arrayBuffer::arrayBuffer2string(char_args, argLen, _T(" "));198 std::wstring cmd = scriptDirectory_ + command.c_str() + _T(" ") +args;199 return executeNRPECommand(cmd, message, perf);200 } else {201 NSC_LOG_ERROR_STD(_T("Unknown script type: ") + command.c_str());202 return NSCAPI::critical;203 */204 171 } 205 172 -
trunk/modules/CheckExternalScripts/CheckExternalScripts.def
r257 r281 4 4 NSModuleHelperInit 5 5 NSLoadModule 6 NSLoadModuleEx 6 7 NSGetModuleName 7 8 NSGetModuleVersion -
trunk/modules/CheckExternalScripts/CheckExternalScripts.h
r273 r281 25 25 #include <execute_process.hpp> 26 26 27 class CheckExternalScripts : public nscapi::impl::SimpleCommand {27 class CheckExternalScripts : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 28 28 private: 29 29 struct command_data { … … 36 36 } 37 37 }; 38 typedef std::map<st d::wstring, command_data> command_list;38 typedef std::map<strEx::wci_string, command_data> command_list; 39 39 command_list commands; 40 40 command_list alias; … … 44 44 bool allowArgs_; 45 45 bool allowNasty_; 46 std::map<std::wstring,std::wstring> wrappings_; 46 47 47 48 public: … … 49 50 virtual ~CheckExternalScripts(); 50 51 // Module calls 51 bool loadModule(NSCAPI::moduleLoadMode mode); 52 bool loadModule(); 53 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 52 54 bool unloadModule(); 53 55 … … 66 68 bool hasCommandHandler(); 67 69 bool hasMessageHandler(); 68 NSCAPI::nagiosReturn handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);70 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 69 71 std::wstring getConfigurationMeta(); 70 72 … … 84 86 private: 85 87 void addAllScriptsFrom(std::wstring path); 86 void addCommand(std::wstring key, std::wstring cmd, std::wstring args) { 88 void add_command(std::wstring key, std::wstring command) { 89 strEx::token tok = strEx::getToken(command, ' ', true); 87 90 boost::to_lower(key); 88 command_data cd = command_data( cmd, args);89 commands[key ] = cd;90 GET_CORE()->registerCommand(key, _T("Script: ") + cd.to_string());91 command_data cd = command_data(tok.first, tok.second); 92 commands[key.c_str()] = cd; 93 get_core()->registerCommand(key.c_str(), _T("Script: ") + cd.to_string()); 91 94 } 92 void addAlias(std::wstring key, std::wstring cmd, std::wstring args) { 95 void add_alias(std::wstring key, std::wstring command) { 96 strEx::token tok = strEx::getToken(command, ' ', true); 93 97 boost::to_lower(key); 94 command_data cd = command_data( cmd, args);95 alias[key ] = cd;96 GET_CORE()->registerCommand(key, _T("Alias for: ") + cd.to_string());98 command_data cd = command_data(tok.first, tok.second); 99 alias[key.c_str()] = cd; 100 get_core()->registerCommand(key.c_str(), _T("Alias for: ") + cd.to_string()); 97 101 } 98 std::wstring getWrapping( std::wstring val ); 99 void addWrappedCommand( std::wstring key, std::wstring tpl, std::wstring command ); 102 void add_wrapping(std::wstring key, std::wstring command) { 103 strEx::token tok = strEx::getToken(command, ' ', true); 104 std::wstring::size_type pos = tok.first.find_last_of(_T(".")); 105 std::wstring type; 106 if (pos != std::wstring::npos) 107 type = tok.first.substr(pos+1); 108 109 std::wstring tpl = wrappings_[type]; 110 111 strEx::replace(tpl, _T("%SCRIPT%"), tok.first); 112 strEx::replace(tpl, _T("%ARGS%"), tok.second); 113 114 add_command(key,tpl); 115 } 100 116 }; 101 117 -
trunk/modules/CheckHelpers/CheckHelpers.cpp
r275 r281 32 32 } 33 33 34 bool CheckHelpers::loadModule() { 35 return false; 36 } 34 37 35 bool CheckHelpers::loadModule (NSCAPI::moduleLoadMode mode) {38 bool CheckHelpers::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 36 39 try { 37 40 GET_CORE()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); … … 74 77 } 75 78 76 NSCAPI::nagiosReturn CheckHelpers::handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {79 NSCAPI::nagiosReturn CheckHelpers::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 77 80 if (command == _T("checkversion")) { 78 81 message = GET_CORE()->getApplicationVersionString(); -
trunk/modules/CheckHelpers/CheckHelpers.h
r257 r281 30 30 virtual ~CheckHelpers(); 31 31 // Module calls 32 bool loadModule(NSCAPI::moduleLoadMode mode); 32 bool loadModule(); 33 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 33 34 bool unloadModule(); 34 35 … … 47 48 bool hasCommandHandler(); 48 49 bool hasMessageHandler(); 49 NSCAPI::nagiosReturn handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);50 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 50 51 51 52 // Check commands -
trunk/modules/CheckSystem/CheckSystem.cpp
r278 r281 49 49 */ 50 50 CheckSystem::~CheckSystem() {} 51 51 52 /** 52 53 * Load (initiate) module. … … 54 55 * @return true 55 56 */ 56 57 bool CheckSystem::loadModule(NSCAPI::moduleLoadMode mode) { 57 bool CheckSystem::loadModule() { 58 return loadModuleEx(_T(""), NSCAPI::normalStart); 59 } 60 61 /** 62 * New version of the load call. 63 * Start the background collector thread and let it run until unloadModule() is called. 64 * @return true 65 */ 66 67 bool CheckSystem::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 58 68 if (mode == NSCAPI::normalStart) { 59 69 pdhThread.createThread(); … … 318 328 * @return 319 329 */ 320 NSCAPI::nagiosReturn CheckSystem::handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) {330 NSCAPI::nagiosReturn CheckSystem::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) { 321 331 CheckSystem::returnBundle rb; 322 if (command == _T("check cpu")) {332 if (command == _T("checkCPU")) { 323 333 return checkCPU(arguments, msg, perf); 324 } else if (command == _T("check uptime")) {334 } else if (command == _T("checkUpTime")) { 325 335 return checkUpTime(arguments, msg, perf); 326 } else if (command == _T("check servicestate")) {336 } else if (command == _T("checkServiceState")) { 327 337 return checkServiceState(arguments, msg, perf); 328 } else if (command == _T("check procstate")) {338 } else if (command == _T("checkProcState")) { 329 339 return checkProcState(arguments, msg, perf); 330 } else if (command == _T("check mem")) {340 } else if (command == _T("checkMem")) { 331 341 return checkMem(arguments, msg, perf); 332 } else if (command == _T("check counter")) {342 } else if (command == _T("checkCounter")) { 333 343 return checkCounter(arguments, msg, perf); 334 } else if (command == _T("list counterinstances")) {344 } else if (command == _T("listCounterInstances")) { 335 345 return listCounterInstances(arguments, msg, perf); 336 } else if (command == _T("check singleregentry")) {346 } else if (command == _T("checkSingleRegEntry")) { 337 347 return checkSingleRegEntry(arguments, msg, perf); 338 348 } … … 1141 1151 msg += _T(", "); 1142 1152 msg += (*it); 1153 } 1154 if (msg.empty()) { 1155 msg = _T("ERROR: No instances found"); 1156 return NSCAPI::returnUNKNOWN; 1143 1157 } 1144 1158 } catch (const PDH::PDHException e) { -
trunk/modules/CheckSystem/CheckSystem.h
r278 r281 47 47 virtual ~CheckSystem(); 48 48 // Module calls 49 bool loadModule(NSCAPI::moduleLoadMode mode); 49 bool loadModule(); 50 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 50 51 bool unloadModule(); 51 52 std::wstring getConfigurationMeta(); … … 72 73 bool hasCommandHandler(); 73 74 bool hasMessageHandler(); 74 NSCAPI::nagiosReturn handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);75 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 75 76 int commandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args); 76 77 -
trunk/modules/FileLogger/FileLogger.cpp
r273 r281 83 83 } 84 84 85 bool FileLogger::loadModule(NSCAPI::moduleLoadMode mode) { 85 bool FileLogger::loadModule() { 86 return false; 87 } 88 89 bool FileLogger::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 86 90 //_tzset(); 87 91 getFileName(); -
trunk/modules/FileLogger/FileLogger.h
r257 r281 34 34 virtual ~FileLogger(); 35 35 // Module calls 36 bool loadModule(NSCAPI::moduleLoadMode mode); 36 bool loadModule(); 37 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 37 38 bool unloadModule(); 38 39 std::wstring getConfigurationMeta(); -
trunk/modules/NRPEClient/NRPEClient.cpp
r278 r281 40 40 } 41 41 42 bool NRPEClient::loadModule(NSCAPI::moduleLoadMode mode) { 42 bool NRPEClient::loadModule() { 43 return false; 44 } 45 46 bool NRPEClient::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 43 47 std::list<std::wstring> commands; 44 48 buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); … … 52 56 } 53 57 54 boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T(" security/nrpe_dh_512.pem"));58 boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("/security/nrpe_dh_512.pem")); 55 59 cert_ = p.string(); 56 60 if (boost::filesystem::is_regular(p)) { … … 136 140 return false; 137 141 } 138 NSCAPI::nagiosReturn NRPEClient::handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf)142 NSCAPI::nagiosReturn NRPEClient::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) 139 143 { 140 144 command_list::const_iterator cit = commands.find(strEx::blindstr(command.c_str())); -
trunk/modules/NRPEClient/NRPEClient.h
r278 r281 93 93 virtual ~NRPEClient(); 94 94 // Module calls 95 bool loadModule(NSCAPI::moduleLoadMode mode); 95 bool loadModule(); 96 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 96 97 bool unloadModule(); 97 98 … … 121 122 bool hasCommandHandler(); 122 123 bool hasMessageHandler(); 123 NSCAPI::nagiosReturn handleCommand(const st d::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);124 NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 124 125 int commandLineExec(const unsigned int argLen,TCHAR** args); 125 126 std::wstring getConfigurationMeta(); -
trunk/modules/NRPEServer/NRPEServer.cpp
r280 r281 27 27 #include "handler_impl.hpp" 28 28 29 namespace sh = nscapi::settings_helper; 30 29 31 NRPEListener gNRPEListener; 30 32 31 NRPEListener::NRPEListener() : noPerfData_(false), info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(0))) { 32 } 33 NRPEListener::~NRPEListener() { 34 std::cout << "TERMINATING TERMINATING!!!" << std::endl; 35 } 33 NRPEListener::NRPEListener() : info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(1024))) { 34 } 35 NRPEListener::~NRPEListener() {} 36 36 37 37 std::wstring getAllowedHosts() { … … 44 44 45 45 46 bool NRPEListener::loadModule(NSCAPI::moduleLoadMode mode) { 47 SETTINGS_REG_KEY_I(nrpe::PORT); 48 SETTINGS_REG_KEY_S(nrpe::BINDADDR); 49 SETTINGS_REG_KEY_I(nrpe::LISTENQUE); 50 SETTINGS_REG_KEY_I(nrpe::READ_TIMEOUT); 51 SETTINGS_REG_KEY_B(nrpe::KEYUSE_SSL); 52 SETTINGS_REG_KEY_I(nrpe::PAYLOAD_LENGTH); 53 SETTINGS_REG_KEY_B(nrpe::ALLOW_PERFDATA); 54 SETTINGS_REG_KEY_S(nrpe::SCRIPT_PATH); 55 SETTINGS_REG_KEY_I(nrpe::CMD_TIMEOUT); 56 SETTINGS_REG_KEY_B(nrpe::ALLOW_ARGS); 57 SETTINGS_REG_KEY_B(nrpe::ALLOW_NASTY); 58 59 SETTINGS_REG_PATH(nrpe::SECTION); 60 SETTINGS_REG_PATH(nrpe::SECTION_HANDLERS); 61 62 info_.use_ssl = SETTINGS_GET_BOOL(nrpe::KEYUSE_SSL)==1; 46 bool NRPEListener::loadModule() { 47 return false; 48 } 49 50 bool NRPEListener::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 51 52 /* 53 DEFINE_SETTING_S(ALLOWED_HOSTS, NRPE_SECTION_PROTOCOL, GENERIC_KEY_ALLOWED_HOSTS, ""); 54 DESCRIBE_SETTING(ALLOWED_HOSTS, "ALLOWED HOST ADDRESSES", "This is a comma-delimited list of IP address of hosts that are allowed to talk to NSClient deamon. If you leave this blank the global version will be used instead."); 55 56 DEFINE_SETTING_B(CACHE_ALLOWED, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_CACHE_ALLOWED, false); 57 DESCRIBE_SETTING_ADVANCED(CACHE_ALLOWED, "ALLOWED HOSTS CACHING", "Used to cache looked up hosts if you check dynamic/changing hosts set this to false."); 58 */ 59 try { 60 61 sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 62 settings.set_alias(alias, _T("NRPE/server")); 63 64 settings.add_path_to_settings() 65 (_T("NRPE SERVER SECTION"), _T("Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options.")) 66 ; 67 68 settings.add_key_to_settings() 69 (_T("port"), sh::uint_key(&info_.port, 5666), 70 _T("PORT NUMBER"), _T("Port to use for NRPE.")) 71 72 (_T("bind to"), sh::string_key(&info_.address), 73 _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 74 75 (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 76 _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 77 78 (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 79 _T("THREAD POOL"), _T("")) 80 81 (_T("timeout"), sh::uint_key(&info_.timeout, 30), 82 _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 83 84 (_T("use ssl"), sh::bool_key(&info_.use_ssl, true), 85 _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 86 87 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024), 88 _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work.")) 89 90 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false), 91 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 92 93 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 94 _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 95 96 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true), 97 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 98 99 (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 100 _T("SSL CERTIFICATE"), _T("")) 101 ; 102 103 settings.register_all(); 104 settings.notify(); 105 63 106 64 107 #ifndef USE_SSL 65 if (bUseSSL_) {66 NSC_LOG_ERROR_STD(_T("SSL not avalible! (not compiled with openssl support)"));67 }108 if (info_.use_ssl) { 109 NSC_LOG_ERROR_STD(_T("SSL not avalible! (not compiled with openssl support)")); 110 } 68 111 #endif 69 70 noPerfData_ = SETTINGS_GET_INT(nrpe::ALLOW_PERFDATA)==0; 71 timeout = SETTINGS_GET_INT(nrpe::READ_TIMEOUT); 72 info_.request_handler->set_payload_length(SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH)); 73 if (info_.request_handler->get_payload_length() != 1024) 74 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(info_.request_handler->get_payload_length())); 75 76 boost::asio::io_service io_service_; 77 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 78 NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 79 try { 80 81 boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 82 info_.certificate = to_string(p.string()); 83 if (boost::filesystem::is_regular(p)) { 84 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + p.string()); 85 } 86 info_.port = to_string(SETTINGS_GET_INT(nrpe::PORT)); 87 info_.address = to_string(SETTINGS_GET_STRING(nrpe::BINDADDR)); 88 unsigned int backLog = SETTINGS_GET_INT(nrpe::LISTENQUE); // @todo: add to info block 89 info_.thread_pool_size = 10; // @todo Add as option 112 if (info_.request_handler->get_payload_length() != 1024) 113 NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(info_.request_handler->get_payload_length())); 114 if (!boost::filesystem::is_regular(info_.certificate)) 115 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 116 117 boost::asio::io_service io_service_; 118 119 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 120 NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 121 90 122 if (mode == NSCAPI::normalStart) { 91 123 if (info_.use_ssl) { 92 124 #ifdef USE_SSL 93 125 server_.reset(new nrpe::server::server(info_)); 94 // NSC_LOG_ERROR_STD(_T("SSL not implemented"));95 // return false;96 126 #else 97 127 NSC_LOG_ERROR_STD(_T("SSL is not supported (not compiled with openssl)")); … … 114 144 return false; 115 145 } 146 147 116 148 return true; 117 149 } -
trunk/modules/NRPEServer/NRPEServer.def
r257 r281 4 4 NSModuleHelperInit 5 5 NSLoadModule 6 NSLoadModuleEx 6 7 NSGetModuleName 7 8 NSGetModuleVersion -
trunk/modules/NRPEServer/NRPEServer.h
r278 r281 37 37 }; 38 38 39 unsigned int timeout;40 39 socketHelpers::allowedHosts allowedHosts; 41 bool noPerfData_;42 40 nrpe::server::server::connection_info info_; 43 41 … … 46 44 virtual ~NRPEListener(); 47 45 // Module calls 48 bool loadModule(NSCAPI::moduleLoadMode mode); 46 bool loadModule(); 47 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 49 48 bool unloadModule(); 50 49 -
trunk/modules/NRPEServer/handler_impl.hpp
r278 r281 11 11 bool noPerfData_; 12 12 public: 13 handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false) {}13 handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false), allowNasty_(false), allowArgs_(false) {} 14 14 15 15 unsigned int get_payload_length() { … … 26 26 } 27 27 28 virtual void set_allow_arguments(bool v) { 29 allowArgs_ = v; 30 } 31 virtual void set_allow_nasty_arguments(bool v) { 32 allowNasty_ = v; 33 } 34 virtual void set_perf_data(bool v) { 35 noPerfData_ = !v; 36 } 37 28 38 void log_debug(std::wstring file, int line, std::wstring msg) { 29 39 GET_CORE()->Message(NSCAPI::debug, file, line, msg); -
trunk/modules/NSCAAgent/NSCAAgent.cpp
r279 r281 46 46 * @return true 47 47 */ 48 bool NSCAAgent::loadModule(NSCAPI::moduleLoadMode mode) { 48 bool NSCAAgent::loadModule() { 49 return false; 50 } 51 52 bool NSCAAgent::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 49 53 try { 50 54 -
trunk/modules/NSCAAgent/NSCAAgent.h
r273 r281 41 41 virtual ~NSCAAgent(); 42 42 // Module calls 43 bool loadModule(NSCAPI::moduleLoadMode mode); 43 bool loadModule(); 44 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 44 45 bool unloadModule(); 45 46 std::wstring getConfigurationMeta(); -
trunk/modules/Scheduler/Scheduler.cpp
r257 r281 28 28 Scheduler gInstance; 29 29 30 bool Scheduler::loadModule(NSCAPI::moduleLoadMode mode) { 30 bool Scheduler::loadModule() { 31 return false; 32 } 33 34 bool Scheduler::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 31 35 try { 32 36 SETTINGS_REG_PATH(scheduler::SECTION); -
trunk/modules/Scheduler/Scheduler.h
r257 r281 35 35 virtual ~Scheduler() {} 36 36 // Module calls 37 bool loadModule(NSCAPI::moduleLoadMode mode); 37 bool loadModule(); 38 bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 38 39 bool unloadModule(); 39 40 -
trunk/service/CMakeLists.txt
r270 r281 54 54 ${NSCP_INCLUDEDIR}/settings/settings_old.hpp 55 55 ${NSCP_INCLUDEDIR}/settings/settings_registry.hpp 56 ${NSCP_INCLUDEDIR}/settings/Settings.h 56 ${NSCP_INCLUDEDIR}/settings/settings_core.hpp 57 ${NSCP_INCLUDEDIR}/settings/settings_core_impl.hpp 57 58 ${NSCP_INCLUDEDIR}/com_helpers.hpp 58 59 ${NSCP_INCLUDEDIR}/dll/dll.hpp -
trunk/service/NSCPlugin.cpp
r257 r281 30 30 * @param file The file (DLL) to load as a NSC plug in. 31 31 */ 32 NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file )32 NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file, std::wstring alias) 33 33 : module_(file.string()) 34 34 ,fLoadModule(NULL) … … 50 50 ,broken_(false) 51 51 ,plugin_id_(id) 52 ,alias_(alias) 52 53 { 53 54 … … 137 138 if (!fLoadModule) 138 139 throw NSPluginException(module_, _T("Critical error (fLoadModule)")); 139 return fLoadModule( mode);140 return fLoadModule(alias_.c_str(), mode); 140 141 } 141 142 … … 356 357 357 358 try { 358 fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModule ");359 fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModuleEx"); 359 360 if (!fLoadModule) 360 361 throw NSPluginException(module_, _T("Could not load NSLoadModule")); -
trunk/service/NSCPlugin.h
r257 r281 110 110 bool broken_; 111 111 unsigned int plugin_id_; 112 std::wstring alias_; 112 113 113 114 nscapi::plugin_api::lpModuleHelperInit fModuleHelperInit; … … 129 130 130 131 public: 131 NSCPlugin(const unsigned int id, const boost::filesystem::wpath file );132 NSCPlugin(const unsigned int id, const boost::filesystem::wpath file, std::wstring alias); 132 133 //NSCPlugin(NSCPlugin &other); 133 134 virtual ~NSCPlugin(void); … … 135 136 std::wstring getName(void); 136 137 std::wstring getDescription(); 137 void load_dll( void);138 void load_dll(); 138 139 bool load_plugin(NSCAPI::moduleLoadMode mode); 139 140 void setBroken(bool broken); -
trunk/service/NSClient++.cpp
r278 r281 15 15 #include "StdAfx.h" 16 16 #include "NSClient++.h" 17 #include <settings/ Settings.h>17 #include <settings/settings_core.hpp> 18 18 #include <charEx.h> 19 19 //#include <Socket.h> … … 39 39 #include "service_manager.hpp" 40 40 #include <nscapi/nscapi_helper.hpp> 41 #include "cli_parser.hpp" 41 42 42 43 #include "../libs/protobuf/plugin.proto.h" … … 77 78 /* 78 79 #define SETTINGS_SET_STRING_CORE(key, value) \ 79 Settings::get_settings()->set_string(setting_keys::key ## _PATH, setting_keys::key, value);80 settings::get_settings()->set_string(setting_keys::key ## _PATH, setting_keys::key, value); 80 81 */ 81 82 /** … … 236 237 bool is_module(boost::filesystem::wpath file ) 237 238 { 238 return boost::ends_with(file.string(), _T(".dll")) || boost::ends_with(file.string(), _T(".so")); 239 #ifdef WIN32 240 return boost::ends_with(file.string(), _T(".dll")); 241 #else 242 return boost::ends_with(file.string(), _T(".so")); 243 #endif 239 244 } 240 245 /** … … 268 273 { 269 274 srand( (unsigned)time( NULL ) ); 275 276 cli_parser parser(&mainClient); 277 g_bConsoleLog = true; 278 279 parser.parse(argc, argv); 280 281 return -1; 282 270 283 int nRetCode = 0; 271 284 if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) ) { … … 289 302 g_bConsoleLog = true; 290 303 std::wstring password; 291 if (!settings_manager::init_settings( mainClient.getBasePath())) {304 if (!settings_manager::init_settings()) { 292 305 std::wcout << _T("Could not find settings") << std::endl;; 293 306 return 1; … … 319 332 LOG_MESSAGE_STD(_T("Found: ") + file); 320 333 if (is_module(pluginPath / file)) { 321 NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file );334 NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file, _T("")); 322 335 std::wstring name = _T("<unknown>"); 323 336 std::wstring description = _T("<unknown>"); … … 400 413 client.start(); 401 414 return 0; 402 } else if ( wcscasecmp( _T("settings"), argv[1]+1 ) == 0 ) {403 nsclient::settings_client client(&mainClient);404 g_bConsoleLog = true;405 if (argc > 2)406 client.parse(argv[2], argc-3, argv+3);407 else408 client.help();409 return 0;410 415 } else { 411 416 std::wcerr << _T("Usage: -version, -about, -install, -uninstall, -start, -stop, -encrypt -settings") << std::endl; … … 442 447 } 443 448 444 void migrate() {}445 446 449 std::list<std::wstring> NSClientT::list_commands() { 447 450 return commands_.list(); … … 459 462 info.dll = itr->leaf(); 460 463 try { 461 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 462 NSCPlugin plugin(next_plugin_id_++, pluginPath / file); 464 std::wstring alias = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()); 465 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string() + _T(" as ") + alias); 466 NSCPlugin plugin(next_plugin_id_++, pluginPath / file, alias); 463 467 plugin.load_dll(); 464 468 plugin.load_plugin(NSCAPI::dontStart); … … 488 492 if (is_module(modPath / file)) { 489 493 if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file.string())) { 490 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()) == _T("disabled")) { 494 std::wstring alias = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()); 495 if (alias == _T("disabled")) { 491 496 try { 492 497 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 493 NSCPlugin plugin(next_plugin_id_++, modPath / file );498 NSCPlugin plugin(next_plugin_id_++, modPath / file, alias); 494 499 plugin.load_dll(); 495 500 plugin.load_plugin(mode); … … 505 510 std::wstring name = file.string(); 506 511 try { 507 NSCPlugin plugin(next_plugin_id_++, modPath / file );512 NSCPlugin plugin(next_plugin_id_++, modPath / file, _T("")); 508 513 name = plugin.getModule(); 509 514 plugin.load_dll(); … … 519 524 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 520 525 } 521 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false);526 settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, settings::settings_core::key_string, desc, desc, _T("disabled"), false); 522 527 } 523 528 } … … 549 554 bool NSClientT::initCore(bool boot) { 550 555 LOG_MESSAGE(_T("Attempting to start NSCLient++ - ") SZVERSION); 551 if (!settings_manager::init_settings( getBasePath())) {556 if (!settings_manager::init_settings()) { 552 557 return false; 553 558 } … … 558 563 settings_manager::get_settings()->set_int(_T("Settings"), _T("shared_Session"), 1); 559 564 enable_shared_session_ = SETTINGS_GET_BOOL_CORE(settings_def::SHARED_SESSION); 560 } catch ( SettingsException e) {565 } catch (settings_exception e) { 561 566 LOG_ERROR_CORE_STD(_T("Could not find settings: ") + e.getMessage()); 562 567 } … … 625 630 if (boot) { 626 631 try { 627 Settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION);628 for ( Settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) {632 settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 633 for (settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 629 634 std::wstring file = NSCPlugin::get_plugin_file(*cit); 630 LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file);635 std::wstring alias; 631 636 try { 632 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit) == _T("disabled")) { 637 alias = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit); 638 if (alias == _T("disabled")) { 633 639 LOG_DEBUG_STD(_T("Not booting: ") + file + _T(" since it is disabled.")); 634 640 continue; 635 } 641 } else if (alias == _T("enabled")) 642 alias = _T(""); 643 636 644 } catch (...) { 637 645 // If we except we load the plugin in as-is 638 646 } 647 LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file + _T(" as ") + alias); 639 648 try { 640 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file) );649 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file), alias); 641 650 } catch(const NSPluginException& e) { 642 651 LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); … … 650 659 } 651 660 } 652 } catch ( SettingsException e) {661 } catch (settings_exception e) { 653 662 LOG_ERROR_CORE_STD(_T("Failed to set settings file") + e.getMessage()); 654 663 } catch (...) { … … 838 847 } 839 848 try { 840 plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module) );849 plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module), _T("")); 841 850 LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 842 851 plugin->load_plugin(NSCAPI::dontStart); … … 853 862 * @param plugins A list with plug-ins (DLL files) to load 854 863 */ 855 void NSClientT::addPlugins(const std::list<std::wstring> plugins) {856 boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10));857 if (!readLock.owns_lock()) {858 LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex."));859 return;860 }861 std::list<std::wstring>::const_iterator it;862 for (it = plugins.begin(); it != plugins.end(); ++it) {863 loadPlugin(*it);864 }865 }864 // void NSClientT::addPlugins(const std::list<std::wstring> plugins) { 865 // boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 866 // if (!readLock.owns_lock()) { 867 // LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex.")); 868 // return; 869 // } 870 // std::list<std::wstring>::const_iterator it; 871 // for (it = plugins.begin(); it != plugins.end(); ++it) { 872 // loadPlugin(*it); 873 // } 874 // } 866 875 /** 867 876 * Unload all plug-ins (in reversed order) … … 935 944 } 936 945 for (pluginList::iterator it=plugins_.begin(); it != plugins_.end();) { 937 LOG_DEBUG_STD(_T(" Loading plugin: ") + (*it)->getName() + _T("..."));946 LOG_DEBUG_STD(_T(" * * * (FIX THIS) Loading plugin: ") + (*it)->getName() + _T("...")); 938 947 try { 939 948 if (!(*it)->load_plugin(NSCAPI::normalStart)) { … … 972 981 * @param file The DLL file 973 982 */ 974 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file ) {975 plugin_type plugin(new NSCPlugin(next_plugin_id_++, file ));983 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file, std::wstring alias) { 984 plugin_type plugin(new NSCPlugin(next_plugin_id_++, file, alias)); 976 985 return addPlugin(plugin); 977 986 } … … 996 1005 if (plugin->hasMessageHandler()) 997 1006 messageHandlers_.insert(messageHandlers_.end(), plugin); 998 settings_manager::get_core()->register_key(_T("/modules"), plugin->getModule(), Settings::SettingsCore::key_string, plugin->getName(), plugin->getDescription(), _T(""), false);1007 settings_manager::get_core()->register_key(_T("/modules"), plugin->getModule(), settings::settings_core::key_string, plugin->getName(), plugin->getDescription(), _T(""), false); 999 1008 } 1000 1009 return plugin; … … 1017 1026 try { 1018 1027 len = settings_manager::get_settings()->get_int(SETTINGS_KEY(settings_def::PAYLOAD_LEN)); 1019 } catch ( SettingsException &e) {1028 } catch (settings_exception &e) { 1020 1029 LOG_DEBUG_STD(_T("Failed to get length: ") + e.getMessage()); 1021 1030 return setting_keys::settings_def::PAYLOAD_LEN_DEFAULT; … … 1192 1201 else 1193 1202 debug_ = log_nodebug; 1194 } catch ( SettingsException e) {1203 } catch (settings_exception e) { 1195 1204 return true; 1196 1205 } … … 1326 1335 try { 1327 1336 settings_manager::get_core()->set_base(basePath); 1328 } catch ( SettingsException e) {1337 } catch (settings_exception e) { 1329 1338 LOG_ERROR_CORE_STD(_T("Failed to set settings file: ") + e.getMessage()); 1330 1339 } catch (...) { … … 1385 1394 exitCore(true); 1386 1395 } 1396 1397 1398 std::wstring NSClientT::expand_path(std::wstring file) { 1399 strEx::replace(file, _T("${certificate-path}"), _T("${shared-path}/security")); 1400 strEx::replace(file, _T("${base-path}"), getBasePath().string()); 1401 #ifdef WIN32 1402 strEx::replace(file, _T("${shared-path}"), getBasePath().string()); 1403 #else 1404 strEx::replace(file, _T("${shared-path}"), _T("/usr/shared/nsclient++")); 1405 #endif 1406 strEx::replace(file, _T("${exe-path}"), getBasePath().string()); 1407 strEx::replace(file, _T("${etc}"), _T("/etc")); 1408 return file; 1409 } 1410 1387 1411 #ifdef _WIN32 1388 1412 void NSClientT::handle_session_change(unsigned long dwSessionId, bool logon) { -
trunk/service/NSClient++.h
r257 r281 1 1 2 /************************************************************************** 2 3 * Copyright (C) 2004-2007 by Michael Medin <michael@medin.name> * … … 173 174 int commandLineExec(const wchar_t* module, const unsigned int argLen, wchar_t** args); 174 175 175 void addPlugins(const std::list<std::wstring> plugins); 176 plugin_type loadPlugin(const boost::filesystem::wpath plugin); 176 plugin_type loadPlugin(const boost::filesystem::wpath plugin, std::wstring alias); 177 177 void loadPlugins(NSCAPI::moduleLoadMode mode); 178 178 void unloadPlugins(bool unloadLoggers); … … 202 202 } 203 203 204 std::wstring expand_path(std::wstring file); 205 204 206 205 207 public: -
trunk/service/core_api.cpp
r271 r281 23 23 //#include <settings/settings_registry.hpp> 24 24 //#include <settings/settings_old.hpp> 25 #ifdef WIN32x 26 #include <Userenv.h> 27 #endif 28 #include <settings/Settings.h> 25 #include <settings/settings_core.hpp> 29 26 #include "settings_manager_impl.h" 30 27 #include <b64/b64.h> … … 47 44 #define LOG_ANY(msg, type) NSAPIMessage(type, __FILEW__, __LINE__, msg) 48 45 46 NSCAPI::errorReturn NSAPIExpandPath(const wchar_t* key, wchar_t* buffer,unsigned int bufLen) { 47 try { 48 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.expand_path(key), NSCAPI::isSuccess); 49 } catch (...) { 50 LOG_ERROR_STD(_T("Failed to getString: ") + key); 51 return NSCAPI::hasFailed; 52 } 53 } 54 49 55 NSCAPI::errorReturn NSAPIGetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* defaultValue, wchar_t* buffer, unsigned int bufLen) { 50 56 try { … … 58 64 try { 59 65 return settings_manager::get_settings()->get_int(section, key, defaultValue); 60 } catch ( SettingsException e) {66 } catch (settings_exception e) { 61 67 LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 62 68 return defaultValue; … … 98 104 *bufLen = len; 99 105 return NSCAPI::isSuccess; 100 } catch ( SettingsException e) {106 } catch (settings_exception e) { 101 107 LOG_ERROR_STD(_T("Failed to get section: ") + e.getMessage()); 102 108 } catch (...) { … … 222 228 return NSCAPI::isSuccess; 223 229 } 224 NSCAPI::errorReturn NSAPIWriteSettings( int type) {225 try { 226 if (type == NSCAPI::settings_registry)227 settings_manager::get_core()->migrate_to(Settings::SettingsCore::registry);228 else if (type == NSCAPI::settings_inifile)229 settings_manager::get_core()->migrate_to(Settings::SettingsCore::ini_file);230 else231 settings_manager::get_settings()->save();232 } catch ( SettingsException e) {230 NSCAPI::errorReturn NSAPIWriteSettings(const wchar_t* key) { 231 try { 232 settings::instance_ptr inst = settings_manager::get_core()->create_instance(key); 233 if (!inst) { 234 LOG_ERROR_STD(_T("Failed to create settings: ") + key); 235 return NSCAPI::hasFailed; 236 } 237 settings_manager::get_core()->migrate_to(inst); 238 } catch (settings_exception e) { 233 239 LOG_ERROR_STD(_T("Failed to write settings: ") + e.getMessage()); 234 240 return NSCAPI::hasFailed; … … 239 245 return NSCAPI::isSuccess; 240 246 } 241 NSCAPI::errorReturn NSAPIReadSettings(int type) { 242 try { 243 if (type == NSCAPI::settings_registry) 244 settings_manager::get_core()->migrate_from(Settings::SettingsCore::registry); 245 else if (type == NSCAPI::settings_inifile) 246 settings_manager::get_core()->migrate_from(Settings::SettingsCore::ini_file); 247 else 248 settings_manager::get_settings()->reload(); 249 } catch (SettingsException e) { 247 NSCAPI::errorReturn NSAPIReadSettings(const wchar_t* key) { 248 try { 249 settings::instance_ptr inst = settings_manager::get_core()->create_instance(key); 250 if (!inst) { 251 LOG_ERROR_STD(_T("Failed to create settings: ") + key); 252 return NSCAPI::hasFailed; 253 } 254 settings_manager::get_core()->migrate_from(inst); 255 settings_manager::get_settings()->reload(); 256 } catch (settings_exception e) { 250 257 LOG_ERROR_STD(_T("Failed to read settings: ") + e.getMessage()); 251 258 return NSCAPI::hasFailed; … … 289 296 try { 290 297 if (type == NSCAPI::key_string) 291 settings_manager::get_core()->register_key(path, key, Settings::SettingsCore::key_string, title, description, defVal, advanced);298 settings_manager::get_core()->register_key(path, key, settings::settings_core::key_string, title, description, defVal, advanced); 292 299 if (type == NSCAPI::key_bool) 293 settings_manager::get_core()->register_key(path, key, Settings::SettingsCore::key_bool, title, description, defVal, advanced);300 settings_manager::get_core()->register_key(path, key, settings::settings_core::key_bool, title, description, defVal, advanced); 294 301 if (type == NSCAPI::key_integer) 295 settings_manager::get_core()->register_key(path, key, Settings::SettingsCore::key_integer, title, description, defVal, advanced);296 return NSCAPI::hasFailed; 297 } catch ( SettingsException e) {302 settings_manager::get_core()->register_key(path, key, settings::settings_core::key_integer, title, description, defVal, advanced); 303 return NSCAPI::hasFailed; 304 } catch (settings_exception e) { 298 305 LOG_ERROR_STD(_T("Failed register key: ") + e.getMessage()); 299 306 return NSCAPI::hasFailed; … … 309 316 try { 310 317 settings_manager::get_core()->register_path(path, title, description, advanced); 311 } catch ( SettingsException e) {318 } catch (settings_exception e) { 312 319 LOG_ERROR_STD(_T("Failed register path: ") + e.getMessage()); 313 320 return NSCAPI::hasFailed; … … 355 362 try { 356 363 settings_manager::get_settings()->save(); 357 } catch ( SettingsException e) {364 } catch (settings_exception e) { 358 365 LOG_ERROR_STD(_T("Failed to save: ") + e.getMessage()); 359 366 return NSCAPI::hasFailed; … … 426 433 if (wcscasecmp(buffer, _T("NSAPIDestroyBuffer")) == 0) 427 434 return reinterpret_cast<LPVOID>(&NSAPIDestroyBuffer); 435 if (wcscasecmp(buffer, _T("NSAPIExpandPath")) == 0) 436 return reinterpret_cast<LPVOID>(&NSAPIExpandPath); 428 437 429 438 LOG_ERROR_STD(_T("Function not found: ") + buffer); -
trunk/service/core_api.h
r257 r281 46 46 NSCAPI::errorReturn NSAPISetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* value); 47 47 NSCAPI::errorReturn NSAPISetSettingsInt(const wchar_t* section, const wchar_t* key, int value); 48 NSCAPI::errorReturn NSAPIWriteSettings( int type);49 NSCAPI::errorReturn NSAPIReadSettings( int type);48 NSCAPI::errorReturn NSAPIWriteSettings(const wchar_t* key); 49 NSCAPI::errorReturn NSAPIReadSettings(const wchar_t* key); 50 50 NSCAPI::errorReturn NSAPIRehash(int flag); 51 51 NSCAPI::errorReturn NSAPIDescribeCommand(const wchar_t*,wchar_t*,unsigned int); … … 60 60 NSCAPI::errorReturn NSAPINotify(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, char*, unsigned int); 61 61 void NSAPIDestroyBuffer(char**); 62 NSCAPI::errorReturn NSAPIExpandPath(const wchar_t*,wchar_t*,unsigned int); -
trunk/service/settings_client.hpp
r230 r281 7 7 NSClient* core_; 8 8 public: 9 settings_client(NSClient* core) : core_(core) { 9 settings_client(NSClient* core) : core_(core) {} 10 10 11 std::wstring get_source() { 12 settings_manager::get_core()->get()->get_context(); 11 13 } 12 void parse(std::wstring sarg, int argc, wchar_t* argv[]) { 13 core_->enableDebug(true);14 if (!core_->initCore( false)) {14 15 void boot() { 16 if (!core_->initCore(true)) { 15 17 std::wcout << _T("Service *NOT* started!") << std::endl; 16 18 return; 17 19 } 18 std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl;20 } 19 21 22 void migrate_from(std::wstring src, std::wstring target, bool def) { 20 23 try { 21 if (sarg == _T("migrate")) { 22 if (argc == 0) { 23 error_msg(_T("In correct syntax: nsclient++ -settings migrate <to>")); 24 return; 25 } 26 std::wstring to = argv[0]; 27 debug_msg(_T("Migrating to: ") + to); 28 try { 29 settings_manager::get_core()->migrate_to(Settings::SettingsCore::string_to_type(to)); 30 } catch (SettingsException e) { 31 error_msg(_T("Failed to migrate settings: ") + e.getError()); 32 } 33 } else if (sarg == _T("generate")) { 34 if (argc == 0) { 35 error_msg(_T("In correct syntax: nsclient++ -settings generate <what>")); 36 error_msg(_T(" where <what> is one of ths following:")); 37 error_msg(_T(" trac")); 38 error_msg(_T(" default")); 39 error_msg(_T(" <type>")); 40 return; 41 } 42 std::wstring arg1 = argv[0]; 43 if (arg1 == _T("default")) { 44 try { 45 core_->load_all_plugins(NSCAPI::dontStart); 46 settings_manager::get_core()->update_defaults(); 47 settings_manager::get_core()->get()->save(); 48 } catch (SettingsException e) { 49 error_msg(_T("Failed to migrate settings: ") + e.getError()); 50 } 51 } else if (arg1 == _T("trac")) { 52 try { 53 core_->load_all_plugins(NSCAPI::dontStart); 54 55 Settings::string_list s = settings_manager::get_core()->get_reg_sections(); 56 for (Settings::string_list::const_iterator cit = s.begin(); cit != s.end(); ++cit) { 57 std::wcout << _T("== ") << (*cit) << _T(" ==") << std::endl; 58 Settings::string_list k = settings_manager::get_core()->get_reg_keys(*cit); 59 bool first = true; 60 for (Settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 61 Settings::SettingsCore::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 62 if (!desc.advanced) { 63 if (first) 64 std::wcout << _T("'''Normal settings'''") << std::endl; 65 first = false; 66 std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description 67 << std::endl; 68 } 69 } 70 first = true; 71 for (Settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 72 Settings::SettingsCore::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 73 if (desc.advanced) { 74 if (first) 75 std::wcout << _T("'''Advanced settings'''") << std::endl; 76 first = false; 77 std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description 78 << std::endl; 79 } 80 } 81 } 82 } catch (SettingsException e) { 83 error_msg(_T("Failed to migrate settings: ") + e.getError()); 84 } 85 } else { 86 try { 87 Settings::SettingsCore::settings_type type = settings_manager::get_core()->string_to_type(arg1); 88 core_->load_all_plugins(NSCAPI::dontStart); 89 settings_manager::get_core()->update_defaults(); 90 settings_manager::get_core()->get(type)->save(); 91 } catch (SettingsException e) { 92 error_msg(_T("Failed to migrate settings: ") + e.getError()); 93 } 94 } 24 if (def) 25 settings_manager::get_core()->update_defaults(); 26 if (!src.empty() && !target.empty()) { 27 debug_msg(_T("Migrating ") + src + _T(" to ") + target); 28 settings_manager::get_core()->migrate(src, target); 95 29 } else { 96 std::wcout << _T("Unknown keyword: ") << sarg << std::endl;97 help();30 debug_msg(_T("Migrating ") + src + _T(" to ") + target); 31 settings_manager::get_core()->migrate_from(src); 98 32 } 99 100 101 } catch (SettingsException e) { 33 core_->exitCore(true); 34 } catch (settings_exception e) { 102 35 error_msg(_T("Failed to initialize settings: ") + e.getError()); 103 36 } catch (...) { 104 37 error_msg(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 105 38 } 39 } 40 void migrate_to(std::wstring src, std::wstring target, bool def) { 41 try { 42 if (def) 43 settings_manager::get_core()->update_defaults(); 44 if (!src.empty() && !target.empty()) { 45 debug_msg(_T("Migrating ") + src + _T(" to ") + target); 46 settings_manager::get_core()->migrate(src, target); 47 } else { 48 debug_msg(_T("Migrating ") + src + _T(" to ") + target); 49 settings_manager::get_core()->migrate_to(target); 50 } 51 core_->exitCore(true); 52 } catch (settings_exception e) { 53 error_msg(_T("Failed to initialize settings: ") + e.getError()); 54 } catch (...) { 55 error_msg(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 56 } 57 } 106 58 59 void generate(std::wstring target) { 60 try { 61 core_->load_all_plugins(NSCAPI::dontStart); 62 if (target == _T("default") || target.empty()) { 63 settings_manager::get_core()->update_defaults(); 64 settings_manager::get_core()->get()->save(); 65 } else if (target == _T("trac")) { 66 settings::string_list s = settings_manager::get_core()->get_reg_sections(); 67 for (settings::string_list::const_iterator cit = s.begin(); cit != s.end(); ++cit) { 68 std::wcout << _T("== ") << (*cit) << _T(" ==") << std::endl; 69 settings::string_list k = settings_manager::get_core()->get_reg_keys(*cit); 70 bool first = true; 71 for (settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 72 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 73 if (!desc.advanced) { 74 if (first) 75 std::wcout << _T("'''Normal settings'''") << std::endl; 76 first = false; 77 std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description << std::endl; 78 } 79 } 80 first = true; 81 for (settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 82 settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 83 if (desc.advanced) { 84 if (first) 85 std::wcout << _T("'''Advanced settings'''") << std::endl; 86 first = false; 87 std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description << std::endl; 88 } 89 } 90 } 91 } else { 92 settings_manager::get_core()->update_defaults(); 93 settings_manager::get_core()->get()->save_to(target); 94 } 95 } catch (settings_exception e) { 96 error_msg(_T("Failed to initialize settings: ") + e.getError()); 97 } catch (...) { 98 error_msg(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 99 } 107 100 core_->exitCore(true); 108 101 } 109 110 102 void error_msg(std::wstring msg) { 111 103 core_->reportMessage(NSCAPI::error, __FILEW__, __LINE__, msg.c_str()); … … 114 106 core_->reportMessage(NSCAPI::debug, __FILEW__, __LINE__, msg.c_str()); 115 107 } 116 117 void help() {118 std::wcout << _T("Usage: nsclient++ -settings <key>") << std::endl;119 std::wcout << _T("In correct syntax: nsclient++ -settings <keyword>") << std::endl;120 std::wcout << _T(" <keyword> : ") << std::endl;121 std::wcout << _T(" migrate - migrate to a new setings subsystem") << std::endl;122 std::wcout << _T(" copy - copy settings from one subsystem to another") << std::endl;123 std::wcout << _T(" set - Set a setting system as the default store") << std::endl;124 }125 126 108 }; 127 109 } -
trunk/service/settings_logger_impl.hpp
r205 r281 2 2 3 3 #include "core_api.h" 4 #include <settings/ Settings.h>4 #include <settings/settings_core.hpp> 5 5 6 class settings_logger : public Settings::LoggerInterface {6 class settings_logger : public settings::logger_interface { 7 7 public: 8 8 ////////////////////////////////////////////////////////////////////////// -
trunk/service/settings_manager_impl.cpp
r216 r281 2 2 3 3 #include "settings_manager_impl.h" 4 #include <config.h> 5 #include "NSClient++.h" 4 6 5 7 #define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::wstring)msg).c_str()) … … 7 9 NSAPIMessage(NSCAPI::critical, __FILEW__, __LINE__, msg) 8 10 11 extern NSClient mainClient; 12 9 13 namespace settings_manager { 10 14 // Alias to make handling "compatible" with old syntax 11 Settings::SettingsInterface*get_settings() {15 boost::shared_ptr<settings::settings_interface> get_settings() { 12 16 return SettingsHandler::getInstance()->get(); 13 17 } 14 Settings::SettingsCore* get_core() {18 settings::settings_core* get_core() { 15 19 return SettingsHandler::getInstance(); 16 20 } … … 18 22 SettingsHandler::destroyInstance(); 19 23 } 20 bool init_settings(boost::filesystem::wpath path) { 24 25 std::wstring NSCSettingsImpl::find_file(std::wstring file, std::wstring fallback) { 26 // @todo: replace this with a proper parser! 27 if (file.size() == 0) 28 file = fallback; 29 return mainClient.expand_path(file); 30 } 31 32 ////////////////////////////////////////////////////////////////////////// 33 /// Create an instance of a given type. 34 /// Used internally to create instances of various settings types. 35 /// 36 /// @param type the type to create 37 /// @param context the context to use 38 /// @return a new instance of given type. 39 /// 40 /// @author mickem 41 settings::instance_ptr NSCSettingsImpl::create_instance(std::wstring key) { 42 net::url url = net::parse(key); 43 get_logger()->debug(__FILEW__, __LINE__, _T("Trying to create: ") + url.protocol + _T(": ") + key); 44 #ifdef WIN32 45 if (url.protocol == _T("old")) { 46 old_ = true; 47 return settings::instance_ptr(new settings::OLDSettings(this, key)); 48 } 49 if (url.protocol == _T("registry")) 50 return settings::instance_ptr(new settings::REGSettings(this, key)); 51 #endif 52 if (url.protocol == _T("ini")) 53 return settings::instance_ptr(new settings::INISettings(this, key)); 54 throw settings_exception(_T("Undefined settings protocol: ") + url.protocol); 55 } 56 57 ////////////////////////////////////////////////////////////////////////// 58 /// Boot the settings subsystem from the given file (boot.ini). 59 /// 60 /// @param file the file to use when booting. 61 /// 62 /// @author mickem 63 void NSCSettingsImpl::boot(std::wstring file) { 64 boot_ = get_base() / file; 65 std::wstring key = get_boot_string(_T("settings"), _T("location"), DEFAULT_CONF_LOCATION); 66 get_logger()->debug(__FILEW__, __LINE__, _T("Trying to boot: ") + key + _T(" from base: ") + boot_.string()); 67 set_instance(key); 68 } 69 70 bool init_settings() { 21 71 try { 22 72 get_core()->set_logger(new settings_logger()); 23 get_core()->set_base( path);73 get_core()->set_base(mainClient.expand_path(_T("${base-path}"))); 24 74 get_core()->boot(_T("boot.ini")); 25 get_core()->register_key(SETTINGS_REG_KEY_I_GEN(settings_def::PAYLOAD_LEN, Settings::SettingsCore::key_integer)); 26 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::ALLOWED_HOSTS, Settings::SettingsCore::key_string)); 27 get_core()->register_key(SETTINGS_REG_KEY_B_GEN(protocol_def::CACHE_ALLOWED, Settings::SettingsCore::key_bool)); 28 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::MASTER_KEY, Settings::SettingsCore::key_string)); 29 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::PWD, Settings::SettingsCore::key_string)); 30 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::OBFUSCATED_PWD, Settings::SettingsCore::key_string)); 75 get_core()->register_key(SETTINGS_REG_KEY_I_GEN(settings_def::PAYLOAD_LEN, settings::settings_core::key_integer)); 76 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::ALLOWED_HOSTS, settings::settings_core::key_string)); 77 get_core()->register_key(SETTINGS_REG_KEY_B_GEN(protocol_def::CACHE_ALLOWED, settings::settings_core::key_bool)); 78 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::MASTER_KEY, settings::settings_core::key_string)); 79 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::PWD, settings::settings_core::key_string)); 80 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::OBFUSCATED_PWD, settings::settings_core::key_string)); 81 LOG_CRITICAL_STD(_T("Loaded: ") + get_core()->to_string()); 31 82 32 } catch ( SettingsException e) {83 } catch (settings_exception e) { 33 84 LOG_CRITICAL_STD(_T("Failed to initialize settings: ") + e.getError()); 34 85 return false; -
trunk/service/settings_manager_impl.h
r216 r281 2 2 3 3 #include "settings_logger_impl.hpp" 4 #include <settings/ Settings.h>4 #include <settings/settings_core.hpp> 5 5 #include <settings/settings_ini.hpp> 6 6 #ifdef WIN32 … … 10 10 11 11 namespace settings_manager { 12 class NSCSettingsImpl : public Settings::SettingsHandlerImpl {12 class NSCSettingsImpl : public settings::settings_handler_impl { 13 13 private: 14 14 boost::filesystem::wpath boot_; … … 36 36 #endif 37 37 } 38 //////////////////////////////////////////////////////////////////////////39 /// Boot the settings subsystem from the given file (boot.ini).40 ///41 /// @param file the file to use when booting.42 ///43 /// @author mickem44 void boot(std::wstring file = _T("boot.ini")) {45 boot_ = get_base() / file;46 #ifdef WIN3247 std::wstring subsystem = get_boot_string(_T("settings"), _T("type"), _T("old"));48 #else49 std::wstring subsystem = get_boot_string(_T("settings"), _T("type"), _T("ini"));50 #endif51 get_logger()->debug(__FILEW__, __LINE__, _T("Trying to boot: ") + subsystem + _T(" from base: ") + boot_.string());52 settings_type type = string_to_type(subsystem);53 std::wstring context = get_boot_string(_T("settings"), _T("context"), subsystem);54 Settings::SettingsInterface *impl = create_instance(type, context);55 if (impl == NULL)56 throw Settings::SettingsException(_T("Could not create settings instance: ") + subsystem);57 add_type_impl(type, impl);58 set_type(type);59 }60 //////////////////////////////////////////////////////////////////////////61 /// Create an instance of a given type.62 /// Used internally to create instances of various settings types.63 ///64 /// @param type the type to create65 /// @param context the context to use66 /// @return a new instance of given type.67 ///68 /// @author mickem69 Settings::SettingsInterface* create_instance(settings_type type, std::wstring context) {70 get_logger()->debug(__FILEW__, __LINE__, _T("Trying to create: ") + SettingsCore::type_to_string(type) + _T(": ") + context);71 #ifdef WIN3272 if (type == SettingsCore::old_ini_file) {73 old_ = true;74 return new Settings::OLDSettings(this, context);75 }76 if (type == SettingsCore::registry)77 return new Settings::REGSettings(this, context);78 #endif79 if (type == SettingsCore::ini_file)80 return new Settings::INISettings(this, context);81 throw SettingsException(_T("Undefined settings type: ") + SettingsCore::type_to_string(type));82 }83 38 39 void boot(std::wstring file = _T("boot.ini")); 40 std::wstring find_file(std::wstring file, std::wstring fallback = _T("")); 41 std::wstring expand_path(std::wstring file); 42 settings::instance_ptr create_instance(std::wstring key); 84 43 }; 85 44 … … 87 46 88 47 // Alias to make handling "compatible" with old syntax 89 Settings::SettingsInterface*get_settings();90 Settings::SettingsCore* get_core();48 settings::instance_ptr get_settings(); 49 settings::settings_core* get_core(); 91 50 void destroy_settings(); 92 bool init_settings( boost::filesystem::wpath path);51 bool init_settings(); 93 52 } -
trunk/service/simple_client.hpp
r257 r281 14 14 return; 15 15 } 16 std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl;16 //std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl; 17 17 std::wcout << _T("Enter command to inject or exit to terminate...") << std::endl; 18 18 /*
Note: See TracChangeset
for help on using the changeset viewer.







