Changeset dcd90b2 in nscp
- Timestamp:
- 11/23/09 22:54:09 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 9b3f53c
- Parents:
- 858ecc1
- Files:
-
- 7 edited
-
CMakeLists.txt (modified) (2 diffs)
-
build.cmake (modified) (1 diff)
-
include/program_options_ex.hpp (modified) (3 diffs)
-
modules/NRPEClient/CMakeLists.txt (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (7 diffs)
-
modules/NRPEClient/NRPEClient.h (modified) (3 diffs)
-
modules/NRPEClient/stdafx.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r1e0bbec rdcd90b2 49 49 ENDIF(WIN32) 50 50 51 SET(OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR} CACHE PATH "Look for OPENSSL headers here") 52 SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} CACHE PATH "Look for libraries here") 53 54 FIND_PACKAGE(OpenSSL) 55 if(OPENSSL_FOUND) 56 if(WIN32) 57 FIND_LIBRARY(LIB_EAY_DEBUG NAMES libeay32MDd libeay32) 58 FIND_LIBRARY(LIB_EAY_RELEASE NAMES libeay32MD libeay32) 59 IF(LIB_EAY_DEBUG AND LIB_EAY_RELEASE) 60 SET(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} optimized ${LIB_EAY_RELEASE} debug ${LIB_EAY_DEBUG}) 61 ELSE(LIB_EAY_DEBUG AND LIB_EAY_RELEASE) 62 SET(OPENSSL_FOUND FALSE) 63 SET(OPENSSL_LIBRARIES NOTFOUND) 64 MESSAGE(STATUS "Could not find the debug and release version of openssl") 65 ENDIF(LIB_EAY_DEBUG AND LIB_EAY_RELEASE) 66 endif(WIN32) 67 endif(OPENSSL_FOUND) 68 69 if(OPENSSL_FOUND) 70 message(STATUS, "Found openssl: ${OPENSSL_LIBRARIES}") 71 SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DUSE_SSL) 72 else(OPENSSL_FOUND) 73 message(STATUS, "openssl NOT found (no ssl support)") 74 endif(OPENSSL_FOUND) 75 51 76 FIND_PACKAGE(Boost COMPONENTS system filesystem thread REQUIRED) 52 77 … … 83 108 84 109 85 SET(NSCP_GLOBAL_DEFINES 86 -DUNICODE -D_UNICODE 87 ) 110 SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DUNICODE -D_UNICODE) 88 111 89 112 IF(CMAKE_HOST_UNIX) -
build.cmake
r1e0bbec rdcd90b2 4 4 set(BOOST_USE_MULTITHREADED ON) 5 5 6 SET(BOOST_INCLUDEDIR D:/source/include/boost-1_40)7 SET(BOOST_LIBRARYDIR d:/source/lib/x86/)6 SET(BOOST_INCLUDEDIR c:/src/include/boost-1_39) 7 #SET(BOOST_LIBRARYDIR c:/src/lib/x86/) 8 8 SET(BOOST_LIB_SUFFIX vc80-mt) 9 SET(BOOST_LIB_VERSION 1.40) 9 #SET(BOOST_LIB_VERSION 1.40) 10 11 12 SET(OPENSSL_INCLUDE_DIR c:/src/include/) 13 SET(CMAKE_LIBRARY_PATH c:/src/lib/x86/) -
include/program_options_ex.hpp
r1e0bbec rdcd90b2 7 7 class basic_command_line_parser_ex : public boost::program_options::basic_command_line_parser<charT> { 8 8 public: 9 /* 9 10 static boost::program_options::basic_parsed_options<charT> parse_command_line(int argc, charT* argv[], const boost::program_options::options_description& desc, 10 11 int style = 0, boost::function1<std::pair<std::string, std::string>, const std::string&> ext = boost::program_options::ext_parser()) … … 12 13 return basic_command_line_parser_ex<charT>(argc, argv).options(desc).style(style).extra_parser(ext).run(); 13 14 } 15 */ 14 16 15 17 template<class charTx, class Iterator> … … 31 33 ) 32 34 {} 33 /* 34 #ifdef _WIN32 35 basic_command_line_parser_ex(const std::wstring args) 36 : boost::program_options::basic_command_line_parser<charT>(boost::program_options::split_winmain(args)) 35 basic_command_line_parser_ex(std::vector<charT> v) 36 : boost::program_options::basic_command_line_parser<charT>(v) 37 37 {} 38 #endif39 */40 38 41 39 }; -
modules/NRPEClient/CMakeLists.txt
r858ecc1 rdcd90b2 36 36 ${Boost_LIBRARIES} 37 37 ${CMAKE_THREAD_LIBS_INIT} 38 ${OPENSSL_LIBRARIES} 38 39 ${EXTRA_LIBS} 39 40 ) -
modules/NRPEClient/NRPEClient.cpp
r1e0bbec rdcd90b2 26 26 #include <msvc_wrappers.h> 27 27 //#include <execute_process.hpp> 28 #include <program_options_ex.hpp>29 28 #include <strEx.h> 29 30 30 31 31 32 NRPEClient gNRPEClient; … … 39 40 #endif 40 41 41 NRPEClient::NRPEClient() : buffer_length_(0) , bInitSSL(false){42 NRPEClient::NRPEClient() : buffer_length_(0) { 42 43 } 43 44 … … 67 68 return true; 68 69 } 69 void NRPEClient::initSSL() { 70 if (bInitSSL) 71 return; 72 #ifdef USE_SSL 73 simpleSSL::SSL_init(); 74 #endif 75 bInitSSL = true; 76 } 70 71 void NRPEClient::add_options(po::options_description &desc, nrpe_connection_data command_data) { 72 desc.add_options() 73 ("help,h", "Show this help message.") 74 ("host,H", po::wvalue<std::wstring>(&command_data.host), "The address of the host running the NRPE daemon") 75 ("port,p", po::value<int>(&command_data.port), "The port on which the daemon is running (default=5666)") 76 ("command,c", po::wvalue<std::wstring>(&command_data.command), "The name of the command that the remote daemon should run") 77 ("timeout,t", po::value<int>(&command_data.timeout), "Number of seconds before connection times out (default=10)") 78 ("buffer-length,l", po::value<unsigned int>(&command_data.buffer_length), std::string("Length of payload (has to be same as on the server (default=" + to_string(buffer_length_) + ")").c_str()) 79 ("no-ssl,n", po::value<bool>(&command_data.no_ssl)->zero_tokens()->default_value(false), "Do not initial an ssl handshake with the server, talk in plaintext.") 80 ("arguments,a", po::wvalue<std::vector<std::wstring> >(&command_data.argument_vector), "list of arguments") 81 ; 82 } 83 77 84 78 85 void NRPEClient::addCommand(strEx::blindstr key, std::wstring args) { 79 86 try { 80 /* 81 TODO: reimplem,ent this! 82 boost::program_options::options_description desc = get_optionDesc(); 83 boost::program_options::positional_options_description p = get_optionsPositional(); 84 87 88 NRPEClient::nrpe_connection_data command_data; 85 89 boost::program_options::variables_map vm; 86 boost::program_options::store( 87 basic_command_line_parser_ex<wchar_t>(args).options(desc).positional(p).run() 88 , vm); 89 boost::program_options::notify(vm); 90 nrpe_connection_data cd = get_ConectionData(vm); 91 NSC_DEBUG_MSG_STD(_T("Added NRPE Client: ") + key.c_str() + _T(" = ") + cd.toString()); 92 commands[key] = cd; 93 */ 90 91 po::options_description desc("Allowed options"); 92 buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); 93 add_options(desc, command_data); 94 95 po::positional_options_description p; 96 p.add("arguments", -1); 97 98 std::vector<std::wstring> list; 99 //explicit escaped_list_separator(Char e = '\\', Char c = ',',Char q = '\"') 100 boost::escaped_list_separator<wchar_t> sep(L'\\', L' ', L'\"'); 101 typedef boost::tokenizer<boost::escaped_list_separator<wchar_t>,std::wstring::const_iterator, std::wstring > tokenizer_t; 102 tokenizer_t tok(args, sep); 103 for(tokenizer_t::iterator beg=tok.begin(); beg!=tok.end();++beg){ 104 std::wcout << *beg << std::endl; 105 list.push_back(*beg); 106 } 107 108 po::wparsed_options parsed = po::basic_command_line_parser<wchar_t>(list).options(desc).positional(p).run(); 109 po::store(parsed, vm); 110 po::notify(vm); 111 command_data.parse_arguments(); 112 113 NSC_DEBUG_MSG_STD(_T("Added NRPE Client: ") + key.c_str() + _T(" = ") + command_data.toString()); 114 commands[key] = command_data; 94 115 } catch (boost::program_options::validation_error &e) { 95 116 NSC_LOG_ERROR_STD(_T("Could not parse: ") + key.c_str() + strEx::string_to_wstring(e.what())); … … 138 159 } 139 160 140 boost::program_options::options_description NRPEClient::get_optionDesc() {141 boost::program_options::options_description desc("Allowed options");142 buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH);143 desc.add_options()144 ("help,h", "Show this help message.")145 ("host,H", boost::program_options::wvalue<std::wstring>(), "The address of the host running the NRPE daemon")146 ("port,p", boost::program_options::value<int>(), "The port on which the daemon is running (default=5666)")147 ("command,c", boost::program_options::wvalue<std::wstring>(), "The name of the command that the remote daemon should run")148 ("timeout,t", boost::program_options::value<int>(), "Number of seconds before connection times out (default=10)")149 ("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())150 ("no-ssl,n", "Do not initial an ssl handshake with the server, talk in plaintext.")151 ("arguments,a", boost::program_options::wvalue<std::vector<std::wstring> >(), "list of arguments")152 ;153 return desc;154 }155 boost::program_options::positional_options_description NRPEClient::get_optionsPositional() {156 boost::program_options::positional_options_description p;157 p.add("arguments", -1);158 return p;159 }160 161 namespace po = boost::program_options;162 161 int NRPEClient::commandLineExec(const unsigned int argLen, TCHAR** args) { 163 162 try { … … 168 167 po::options_description desc("Allowed options"); 169 168 buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); 170 desc.add_options() 171 ("help,h", "Show this help message.") 172 ("host,H", po::wvalue<std::wstring>(&command_data.host), "The address of the host running the NRPE daemon") 173 ("port,p", po::value<int>(&command_data.port), "The port on which the daemon is running (default=5666)") 174 ("command,c", po::wvalue<std::wstring>(&command_data.command), "The name of the command that the remote daemon should run") 175 ("timeout,t", po::value<int>(&command_data.timeout), "Number of seconds before connection times out (default=10)") 176 ("buffer-length,l", po::value<unsigned int>(&command_data.buffer_length), std::string("Length of payload (has to be same as on the server (default=" + to_string(buffer_length_) + ")").c_str()) 177 ("no-ssl,n", po::value<bool>(&command_data.no_ssl)->zero_tokens()->default_value(false), "Do not initial an ssl handshake with the server, talk in plaintext.") 178 ("arguments,a", po::wvalue<std::vector<std::wstring> >(&command_data.argument_vector), "list of arguments") 179 ; 169 add_options(desc, command_data); 180 170 181 171 po::positional_options_description p; … … 185 175 po::notify(vm); 186 176 command_data.parse_arguments(); 187 188 std::wcout << _T("parsed data: ") << command_data.toString()<< std::endl;189 177 190 178 if (vm.count("help")) { … … 229 217 #else 230 218 231 initSSL();232 219 simpleSSL::Socket socket(true); 233 220 socket.connect(host, port); -
modules/NRPEClient/NRPEClient.h
r1e0bbec rdcd90b2 23 23 #include <map> 24 24 #include <nrpe/nrpepacket.hpp> 25 #include <boost/program_options.hpp>26 25 27 26 … … 86 85 command_list commands; 87 86 unsigned int buffer_length_; 88 bool bInitSSL;89 87 90 88 public: … … 125 123 NRPEPacket send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet); 126 124 NRPEPacket send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet); 127 void initSSL(); 128 boost::program_options::options_description get_optionDesc(); 129 boost::program_options::positional_options_description get_optionsPositional(); 130 nrpe_connection_data get_ConectionData(boost::program_options::variables_map &vm); 125 void add_options(po::options_description &desc, nrpe_connection_data command_data); 131 126 132 127 -
modules/NRPEClient/stdafx.h
r1e0bbec rdcd90b2 46 46 #include <boost/asio/ssl.hpp> 47 47 #endif 48 #include <program_options_ex.hpp> 49 namespace po = boost::program_options; 48 50 51
Note: See TracChangeset
for help on using the changeset viewer.








