Changeset 2f01f93 in nscp
- Timestamp:
- 02/20/08 16:16:16 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 5b9d247
- Parents:
- 95e4ace
- Files:
-
- 10 edited
-
AutoBuild.h (modified) (1 diff)
-
NSClient++.cpp (modified) (5 diffs)
-
NSClient++.h (modified) (2 diffs)
-
changelog (modified) (5 diffs)
-
include/SSLSocket.cpp (modified) (2 diffs)
-
include/SSLSocket.h (modified) (6 diffs)
-
include/Socket.h (modified) (2 diffs)
-
include/strEx.h (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (3 diffs)
-
modules/NRPEClient/NRPEClient.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
r394f7a1 r2f01f93 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,0, 586 #define PRODUCTVER 0,3,0, 587 #define STRFILEVER _T("0.3.0. 58")8 #define STRPRODUCTVER _T("0.3.0. 58")9 #define STRPRODUCTDATE _T("2008-02-1 4")5 #define FILEVER 0,3,0,60 6 #define PRODUCTVER 0,3,0,60 7 #define STRFILEVER _T("0.3.0.60") 8 #define STRPRODUCTVER _T("0.3.0.60") 9 #define STRPRODUCTDATE _T("2008-02-19") 10 10 #endif // AUTOBUILD_H -
NSClient++.cpp
r95e4ace r2f01f93 107 107 LOG_MESSAGE(SZAPPNAME _T(" Version: ") SZVERSION _T(", Plattform: ") SZARCH); 108 108 } else if ( _wcsicmp( _T("noboot"), argv[1]+1 ) == 0 ) { 109 g_bConsoleLog = true; 109 mainClient.setBoot(false); 110 g_bConsoleLog = false; 110 111 mainClient.enableDebug(true); 112 mainClient.InitiateService(); 111 113 int nRetCode = -1; 112 114 if (argc>=4) … … 114 116 else if (argc>=3) 115 117 nRetCode = mainClient.commandLineExec(argv[2], argv[3], 0, NULL); 118 mainClient.TerminateService(); 116 119 return nRetCode; 117 120 } else if ( _wcsicmp( _T("test"), argv[1]+1 ) == 0 ) { … … 221 224 return false; 222 225 } 223 try { 224 SettingsT::sectionList list = Settings::getInstance()->getSection(_T("modules")); 225 for (SettingsT::sectionList::iterator it = list.begin(); it != list.end(); it++) { 226 try { 227 loadPlugin(getBasePath() + _T("modules\\") + (*it)); 228 } catch(const NSPluginException& e) { 229 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 230 //return false; 231 } catch (...) { 232 LOG_ERROR_STD(_T("Unknown exception loading plugin: ") + (*it)); 233 return false; 234 } 235 } 236 } catch (SettingsException e) { 237 NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 238 } 239 try { 240 loadPlugins(); 241 } catch (...) { 242 LOG_ERROR_STD(_T("Unknown exception loading plugins")); 243 return false; 226 if (boot_) { 227 try { 228 SettingsT::sectionList list = Settings::getInstance()->getSection(_T("modules")); 229 for (SettingsT::sectionList::iterator it = list.begin(); it != list.end(); it++) { 230 try { 231 loadPlugin(getBasePath() + _T("modules\\") + (*it)); 232 } catch(const NSPluginException& e) { 233 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 234 //return false; 235 } catch (...) { 236 LOG_ERROR_STD(_T("Unknown exception loading plugin: ") + (*it)); 237 return false; 238 } 239 } 240 } catch (SettingsException e) { 241 NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 242 } 243 try { 244 loadPlugins(); 245 } catch (...) { 246 LOG_ERROR_STD(_T("Unknown exception loading plugins")); 247 return false; 248 } 244 249 } 245 250 return true; … … 250 255 */ 251 256 void NSClientT::TerminateService(void) { 252 try { 253 mainClient.unloadPlugins(); 254 } catch(NSPluginException &e) { 255 std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 257 if (boot_) { 258 try { 259 mainClient.unloadPlugins(); 260 } catch(NSPluginException &e) { 261 std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 262 } 256 263 } 257 264 try { … … 307 314 } 308 315 } 309 LOG_MESSAGE_STD(_T("Module was not loaded, attempt to load it"));310 316 try { 311 317 plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module); -
NSClient++.h
r394f7a1 r2f01f93 72 72 typedef enum log_status {log_unknown, log_debug, log_nodebug }; 73 73 log_status debug_; 74 bool boot_; 74 75 75 76 public: 76 77 // c-tor, d-tor 77 NSClientT(void) : debug_(log_unknown) {}78 NSClientT(void) : debug_(log_unknown), boot_(true) {} 78 79 virtual ~NSClientT(void) {} 79 80 void enableDebug(bool debug = true) { … … 82 83 else 83 84 debug_ = log_nodebug; 85 } 86 void setBoot(bool boot = true) { 87 boot_ = boot; 84 88 } 85 89 -
changelog
r95e4ace r2f01f93 3 3 * Fix configuration GUI (low priority) 4 4 * Fix installer (after configuration UI) 5 * Add module for relaying events 5 * Add module for relaying events (in progress) 6 6 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 7 * Improved socket performance (would be nice if we could be used as a "hub") 8 9 2008-02-19 MickeM 10 + Added new module NRPEClient that can act as a NRPE client, might be useful for testing things and 11 eventually for relaying events. 12 Usage: nsclient++ -noboot NRPEClient -H 192.168.0.1 -p 5666 -c check_something -a foo bar 13 This is an early concept so don't expect much... 7 14 8 15 2008-02-19 MickeM … … 10 17 11 18 2008-02-18 MickeM 12 + Added prop per output handling to process subsystem (now you can execute programs tat return "much" data.19 + Added proper output handling to process subsystem (now you can execute programs tat return "much" data. 13 20 + Added select support for SSL_write (now you can send "any amount of data" to the (SSL) socket. 14 21 Since check_nrpe doesn't do this it wont work in that end, but still... 15 22 16 23 2008-02-16 MickeM 17 + Re factored ExternalCommand handling so NRPE and new module does the same thing.24 + Re factored ExternalCommand handling so NRPE and new module does the same thing. 18 25 19 26 2008-02-14 MickeM … … 23 30 2008-02-13 MickeM 24 31 + Added string_length to [Settings] as well (used internally) for all "injected" buffers. 25 * Fixed issue with scripts result truncated efter 1024 chars26 (now they return "all" output and thus you can use the NRPE settings I adde yesterday :)27 + Added hostname setting to [NSCA] section (must have been braindeadwhen I did not add it before)32 * Fixed issue with scripts result truncated after 1024 chars 33 (now they return "all" output and thus you can use the NRPE settings I added yesterday :) 34 + Added hostname setting to [NSCA] section (must have been when I did not add it before) 28 35 + Added to NSCA truncates output when to long. 29 36 … … 34 41 35 42 2008-02-11 MickeM 36 + Added encryption support for NSCA module (about half of the algorithms are ava lible,43 + Added encryption support for NSCA module (about half of the algorithms are available, 37 44 if someone wants to use one not available let me know, and I will try to add it) 38 45 … … 48 55 49 56 2008-02-07 MickeM 50 + Added default catch handlers to all wrapped plug in calls.57 + Added default catch handlers to all wrapped plug in calls. 51 58 52 59 2008-02-05 MickeM -
include/SSLSocket.cpp
r394f7a1 r2f01f93 134 134 } 135 135 136 void simpleSSL::Listener::StartListener(std::wstring host, int port, unsigned int listenQue) { 137 // @todo init SSL 136 int simpleSSL::Socket::connect_() { 138 137 simpleSSL::SSL_init(); 139 138 140 context.createSSLv23(); 139 Context context; 140 context.createSSLv23Client(); 141 context.setCipherList(); 142 /* 143 simpleSSL::DH dh; 144 dh.create(); 145 setupDH(dh); 146 context.setTmpDH(dh.getDH()); 147 dh.free(); 148 */ 149 if (tBase::connect_() == SOCKET_ERROR) { 150 throw simpleSocket::SocketException(_T("Failed to connect to host: ") + inet_ntoa(to_.sin_addr.s_addr), WSAGetLastError()); 151 } 152 ssl.setContext(context); 153 ssl.set_fd(socket_); 154 ssl.connect(); 155 return 0; 156 } 157 158 159 void simpleSSL::Listener::StartListener(std::wstring host, int port, unsigned int listenQue) { 160 simpleSSL::SSL_init(); 161 context.createSSLv23Server(); 141 162 context.setCipherList(); 142 163 simpleSSL::DH dh; … … 145 166 context.setTmpDH(dh.getDH()); 146 167 dh.free(); 147 148 168 if (!lock_cs) { 149 169 lock_cs_count = simpleSSL::Crypto::getNumberOfLocks(); -
include/SSLSocket.h
r394f7a1 r2f01f93 112 112 113 113 void destroy() { 114 assert(ctx_); 114 if (ctx_ != NULL) 115 throw SSLException(_T("Error: SSL Context already initalized.")); 115 116 SSL_CTX_free(ctx_); 116 117 ctx_ = NULL; 117 118 } 118 void createSSLv23() { 119 assert(ctx_ == NULL); 119 void createSSLv23Server() { 120 if (ctx_ != NULL) 121 throw SSLException(_T("Error: SSL Context already initalized.")); 120 122 ctx_ = SSL_CTX_new(SSLv23_server_method()); 121 123 if (ctx_ == NULL) { … … 123 125 } 124 126 } 127 void createSSLv23Client() { 128 if (ctx_ != NULL) 129 throw SSLException(_T("Error: SSL Context already initalized.")); 130 ctx_ = SSL_CTX_new(SSLv23_client_method()); 131 if (ctx_ == NULL) 132 throw SSLException(_T("Error: could not create SSL context.")); 133 SSL_CTX_set_options(ctx_,SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); 134 } 125 135 void setCipherList(std::string s = "ADH") { 126 assert(ctx_); 136 if (ctx_ == NULL) 137 throw SSLException(_T("Error: SSL Context already initalized.")); 127 138 SSL_CTX_set_cipher_list(ctx_, s.c_str()); 128 139 } … … 169 180 } 170 181 void create() { 171 assert(!ssl_); 182 if (ssl_ != NULL) 183 throw SSLException(_T("Error: Could not create SSL connection structure, SSL is already inatialized.")); 172 184 ssl_ = context_.newSSL(); 173 185 if (ssl_ == NULL) … … 186 198 int i = 0; 187 199 while ((rc = SSL_accept(ssl_)) != 1) { 200 if (++i >= 100) { 201 throw SSLException(_T("SSL: Could not complete SSL handshake.")); 202 } 203 int rc2 = getError(rc); 204 if ((rc2 == SSL_ERROR_WANT_READ) || (rc2 == SSL_ERROR_WANT_WRITE)) { 205 Sleep(100); 206 continue; 207 } else { 208 throw SSLException(_T("Error: Could not complete SSL handshake : "), rc, rc2); 209 } 210 } 211 /**/ 212 } 213 void connect() { 214 if (!ssl_) 215 create(); 216 int rc = 0; 217 int i = 0; 218 while ((rc = SSL_connect(ssl_)) != 1) { 188 219 if (++i >= 100) { 189 220 throw SSLException(_T("SSL: Could not complete SSL handshake.")); … … 244 275 Socket(Socket &other) : tBase(other), ssl(other.ssl) { 245 276 } 277 Socket(bool create) : tBase(create) { 278 } 246 279 virtual ~Socket() { 247 280 ssl.shutdown(); … … 302 335 tBase::close(); 303 336 } 337 virtual int connect(std::wstring host, u_short port) { 338 return tBase::connect(host, port); 339 } 340 341 virtual int connect_(); 304 342 void setContext(Context c) { 305 343 ssl.setContext(c); -
include/Socket.h
r394f7a1 r2f01f93 211 211 to_.sin_port = htons(port); 212 212 to_.sin_addr.s_addr = inet_addr(host); 213 return ::connect(socket_, (SOCKADDR*) &to_, sizeof(to_));213 return connect_(); 214 214 } 215 215 return SOCKET_ERROR; 216 } 217 virtual int connect_() { 218 return ::connect(socket_, (SOCKADDR*) &to_, sizeof(to_)); 216 219 } 217 220 … … 252 255 else 253 256 ::select(NULL, &read_, &write_, &excp_, &timeout_); 254 return FD_ISSET(socket_, &write_); 257 if (FD_ISSET(socket_, &write_)) 258 return true; 259 return false; 255 260 } 256 261 -
include/strEx.h
r394f7a1 r2f01f93 35 35 36 36 namespace strEx { 37 namespace s { 38 inline std::string itos(float i) { 39 std::stringstream ss; 40 ss << i; 41 return ss.str(); 42 } 43 inline std::string itos(int i) { 44 std::stringstream ss; 45 ss << i; 46 return ss.str(); 47 } 48 inline std::string itos(unsigned int i) { 49 std::stringstream ss; 50 ss << i; 51 return ss.str(); 52 } 53 } 37 54 38 55 inline void append_list(std::wstring &lst, std::wstring &append) { -
modules/NRPEClient/NRPEClient.cpp
r394f7a1 r2f01f93 66 66 67 67 int NRPEClient::commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR** args) { 68 if (_wcsicmp(command, _T("check")) == 0) {69 std::wcout << args[0] << std::endl;70 71 72 68 try { 73 69 boost::program_options::options_description desc("Allowed options"); 70 buffer_length_ = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_STRLEN, NRPE_SETTINGS_STRLEN_DEFAULT); 74 71 desc.add_options() 75 ("help", "Show this help message.") 76 ("host", boost::program_options::value<std::string>(), "remote NRPE host") 77 ("port", boost::program_options::value<int>(), "remote NRPE port") 78 ("-c", "command to execute") 79 ("-a", "list of arguments") 80 ("compression", boost::program_options::value<int>(), "set compression level") 72 ("help,h", "Show this help message.") 73 ("host,H", boost::program_options::wvalue<std::wstring>(), "The address of the host running the NRPE daemon") 74 ("port,p", boost::program_options::value<int>(), "The port on which the daemon is running (default=5666)") 75 ("command,c", boost::program_options::wvalue<std::wstring>(), "The name of the command that the remote daemon should run") 76 ("timeout,t", boost::program_options::value<int>(), "Number of seconds before connection times out (default=10)") 77 ("buffer-length,l", boost::program_options::value<int>(), std::string("Length of payload (has to be same as on the server (default=" + strEx::s::itos(buffer_length_) + ")").c_str()) 78 ("no-ssl,n", "Do not initial an ssl handshake with the server, talk in plaintext.") 79 ("arguments,a", boost::program_options::wvalue<std::vector<std::wstring>>(), "list of arguments") 81 80 ; 82 81 boost::program_options::positional_options_description p; 82 p.add("arguments", -1); 83 83 84 boost::program_options::variables_map vm; 84 boost::program_options::store(basic_command_line_parser_ex<wchar_t>::parse_command_line(argLen, args, desc, 0), vm); 85 boost::program_options::store( 86 basic_command_line_parser_ex<TCHAR>(command, argLen, args).options(desc).positional(p).run() 87 , vm); 85 88 boost::program_options::notify(vm); 86 89 … … 89 92 return 1; 90 93 } 91 92 if (vm.count("host")) { 93 std::cout << "Host level was set to " 94 << vm["host"].as<std::string>() << ".\n"; 95 std::cout << "Port level was set to " 96 << vm["port"].as<int>() << ".\n"; 97 } else { 98 std::cout << "Compression level was not set.\n"; 94 std::wstring host = _T("localhost"); 95 std::wstring command; 96 std::wstring arguments; 97 int port = 5666; 98 int timeout = 10; 99 bool ssl = true; 100 101 if (vm.count("host")) 102 host = vm["host"].as<std::wstring>(); 103 if (vm.count("port")) 104 port = vm["port"].as<int>(); 105 if (vm.count("timeout")) 106 timeout = vm["timeout"].as<int>(); 107 if (vm.count("buffer-length")) 108 buffer_length_ = vm["buffer-length"].as<int>(); 109 if (vm.count("command")) 110 command = vm["command"].as<std::wstring>(); 111 if (vm.count("arguments")) { 112 std::vector<std::wstring> v = vm["arguments"].as<std::vector<std::wstring>>(); 113 for (std::vector<std::wstring>::const_iterator cit = v.begin(); cit != v.end(); ++cit) { 114 if (!arguments.empty()) 115 arguments += _T("!"); 116 arguments += *cit; 117 } 99 118 } 119 if (vm.count("no-ssl")) 120 ssl = false; 121 return execute_nrpe_command(host, port, ssl, timeout, command, arguments); 100 122 } catch (boost::program_options::validation_error &e) { 101 123 std::cout << e.what() << std::endl; … … 103 125 std::cout << "Unknown exception parsing command line" << std::endl; 104 126 } 105 std::wcout << _T("Checking...") << std::endl;106 }107 127 return 0; 108 128 } 129 int NRPEClient::execute_nrpe_command(std::wstring host, int port, bool ssl, int timeout, std::wstring command, std::wstring arguments) { 130 try { 131 std::wstring cmd = command; 132 if (cmd.empty()) 133 cmd = _T("_NRPE_CHECK"); 134 if (!arguments.empty()) 135 cmd += _T("!") + arguments; 136 NRPEPacket packet; 137 if (ssl) 138 packet = send_ssl(host, port, timeout, NRPEPacket::make_request(cmd, buffer_length_)); 139 else 140 packet = send_nossl(host, port, timeout, NRPEPacket::make_request(cmd, buffer_length_)); 141 std::wcout << packet.getPayload() << std::endl; 142 return packet.getResult(); 143 } catch (simpleSocket::SocketException &e) { 144 std::wcout << _T("whoops...") << e.getMessage() << std::endl; 145 } catch (simpleSSL::SSLException &e) { 146 std::wcout << _T("whoops...") << e.getMessage() << std::endl; 147 } catch (...) { 148 std::cout << "whoops..." << std::endl; 149 } 150 return NSCAPI::returnUNKNOWN; 151 } 152 NRPEPacket NRPEClient::send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet) 153 { 154 simpleSSL::Socket socket(true); 155 socket.connect(host, port); 156 socket.sendAll(packet.getBuffer(), packet.getBufferLength()); 157 simpleSocket::DataBuffer buffer; 158 socket.readAll(buffer); 159 packet.readFrom(buffer.getBuffer(), buffer.getLength()); 160 return packet; 161 } 162 NRPEPacket NRPEClient::send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet) 163 { 164 simpleSocket::Socket socket(true); 165 socket.connect(host, port); 166 socket.sendAll(packet.getBuffer(), packet.getBufferLength()); 167 simpleSocket::DataBuffer buffer; 168 socket.readAll(buffer); 169 packet.readFrom(buffer.getBuffer(), buffer.getLength()); 170 return packet; 171 } 172 173 109 174 110 175 -
modules/NRPEClient/NRPEClient.h
r394f7a1 r2f01f93 75 75 76 76 private: 77 int execute_nrpe_command(std::wstring host, int port, bool ssl, int timeout, std::wstring command, std::wstring arguments); 78 NRPEPacket send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet); 79 NRPEPacket send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet); 77 80 class NRPEException { 78 81 std::wstring error_;
Note: See TracChangeset
for help on using the changeset viewer.








