Ignore:
Timestamp:
11/23/09 22:54:09 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
9b3f53c
Parents:
858ecc1
Message:

Added back openssl now builds (and presumably the NRPEClient works with it haven't tested but will do after I get the NRPEListener up and running...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/NRPEClient/NRPEClient.cpp

    r1e0bbec rdcd90b2  
    2626#include <msvc_wrappers.h> 
    2727//#include <execute_process.hpp> 
    28 #include <program_options_ex.hpp> 
    2928#include <strEx.h> 
     29 
     30 
    3031 
    3132NRPEClient gNRPEClient; 
     
    3940#endif 
    4041 
    41 NRPEClient::NRPEClient() : buffer_length_(0), bInitSSL(false) { 
     42NRPEClient::NRPEClient() : buffer_length_(0) { 
    4243} 
    4344 
     
    6768  return true; 
    6869} 
    69 void NRPEClient::initSSL() { 
    70   if (bInitSSL) 
    71     return; 
    72 #ifdef USE_SSL 
    73   simpleSSL::SSL_init(); 
    74 #endif 
    75   bInitSSL = true; 
    76 } 
     70 
     71void 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 
    7784 
    7885void NRPEClient::addCommand(strEx::blindstr key, std::wstring args) { 
    7986  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; 
    8589    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; 
    94115  } catch (boost::program_options::validation_error &e) { 
    95116    NSC_LOG_ERROR_STD(_T("Could not parse: ") + key.c_str() + strEx::string_to_wstring(e.what())); 
     
    138159} 
    139160 
    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; 
    162161int NRPEClient::commandLineExec(const unsigned int argLen, TCHAR** args) { 
    163162  try { 
     
    168167    po::options_description desc("Allowed options"); 
    169168    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); 
    180170 
    181171    po::positional_options_description p; 
     
    185175    po::notify(vm); 
    186176    command_data.parse_arguments(); 
    187  
    188     std::wcout << _T("parsed data: ") << command_data.toString()<< std::endl; 
    189177 
    190178    if (vm.count("help")) { 
     
    229217#else 
    230218   
    231   initSSL(); 
    232219  simpleSSL::Socket socket(true); 
    233220  socket.connect(host, port); 
Note: See TracChangeset for help on using the changeset viewer.