Changeset b9498ef in nscp
- Timestamp:
- 08/15/11 18:40:17 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- fe75eff
- Parents:
- 2c95d22
- Files:
-
- 2 added
- 21 edited
-
changelog (modified) (1 diff)
-
include/NSCAPI.h (modified) (1 diff)
-
include/check_nt/server/server.cpp (modified) (5 diffs)
-
include/check_nt/server/server.hpp (modified) (4 diffs)
-
include/nrpe/client/socket.hpp (modified) (3 diffs)
-
include/nrpe/server/server.cpp (modified) (5 diffs)
-
include/nrpe/server/server.hpp (modified) (4 diffs)
-
include/nsca/nsca_socket.hpp (modified) (3 diffs)
-
include/socket/socket_helpers.cpp (added)
-
include/socket/socket_helpers.hpp (added)
-
include/socket_helpers.hpp (modified) (1 diff)
-
include/strEx.h (modified) (1 diff)
-
modules/NRPEClient/CMakeLists.txt (modified) (2 diffs)
-
modules/NRPEServer/CMakeLists.txt (modified) (2 diffs)
-
modules/NRPEServer/NRPEServer.cpp (modified) (4 diffs)
-
modules/NRPEServer/NRPEServer.h (modified) (1 diff)
-
modules/NSCAAgent/CMakeLists.txt (modified) (2 diffs)
-
modules/NSCAAgent/NSCAAgent.cpp (modified) (1 diff)
-
modules/NSCAAgent/stdafx.h (modified) (1 diff)
-
modules/NSClientServer/CMakeLists.txt (modified) (2 diffs)
-
modules/NSClientServer/NSClientServer.cpp (modified) (4 diffs)
-
modules/NSClientServer/NSClientServer.h (modified) (1 diff)
-
modules/PythonScript/script_wrapper.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r2c95d22 rb9498ef 3 3 * Fix configuration GUI (low priority) 4 4 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 5 * Improved socket performance (would be nice if we could be used as a "hub")6 5 * Fixa dependonservice LanManWorkStation (old win) 7 6 * Fix RtlStringFromGUID problem on NT4 7 8 2011-08-15 MickeM 9 * Readded allowed hosts function 10 * Moved default socket options to /settings/default/socket 11 * Added more default socket options 8 12 9 13 2011-08-14 MickeM -
include/NSCAPI.h
r2c95d22 rb9498ef 116 116 std::wstring msg_; 117 117 nscapi_exception(std::wstring msg) : msg_(msg) {} 118 119 120 virtual ~nscapi_exception() throw() {} 118 121 std::string what() { 119 122 return utf8::cvt<std::string>(msg_); -
include/check_nt/server/server.cpp
re1d9a58 rb9498ef 14 14 15 15 16 const int server::connection_info::backlog_default = 0; 17 18 server::server(connection_info info) 19 : thread_pool_size_(info.thread_pool_size) 16 server::server(connection_info infoo) 17 : info_(infoo) 20 18 , acceptor_(io_service_) 21 19 , accept_strand_(io_service_) 22 , request_handler_(info .request_handler) // nrpe::length::get_payload_length())20 , request_handler_(infoo.request_handler) // nrpe::length::get_payload_length()) 23 21 , context_(io_service_, boost::asio::ssl::context::sslv23) 24 , use_ssl_(info.use_ssl)25 22 { 26 23 if (!request_handler_) … … 29 26 ip::tcp::resolver resolver(io_service_); 30 27 ip::tcp::resolver::iterator endpoint_iterator; 31 if (info .address.empty()) {32 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info .get_port()));28 if (info_.address.empty()) { 29 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_port())); 33 30 } else { 34 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info .get_address(), info.get_port()));31 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_address(), info_.get_port())); 35 32 } 36 33 ip::tcp::resolver::iterator end; 37 34 if (endpoint_iterator == end) { 38 request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info .get_endpoint_str());35 request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info_.get_endpoint_str()); 39 36 return; 40 37 } 41 if (info .use_ssl) {38 if (info_.use_ssl) { 42 39 SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 43 request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info .certificate));44 context_.use_tmp_dh_file(to_string(info .certificate));40 request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info_.certificate)); 41 context_.use_tmp_dh_file(to_string(info_.certificate)); 45 42 context_.set_verify_mode(boost::asio::ssl::context::verify_none); 46 43 } 47 44 48 new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, use_ssl_));45 new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 49 46 50 47 ip::tcp::endpoint endpoint = *endpoint_iterator; 51 48 acceptor_.open(endpoint.protocol()); 52 49 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 53 request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info .get_endpoint_str());50 request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info_.get_endpoint_str()); 54 51 acceptor_.bind(endpoint); 55 if (info .back_log == connection_info::backlog_default)52 if (info_.back_log == connection_info::backlog_default) 56 53 acceptor_.listen(); 57 54 else 58 acceptor_.listen(info .back_log);55 acceptor_.listen(info_.back_log); 59 56 60 57 acceptor_.async_accept(new_connection_->socket(), … … 63 60 ) 64 61 ); 65 request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info .get_endpoint_str());62 request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info_.get_endpoint_str()); 66 63 67 64 //io_service_.post(boost::bind(&Server::startAccept, this)); … … 73 70 void server::start() { 74 71 // Create a pool of threads to run all of the io_services. 75 for (std::size_t i = 0; i < thread_pool_size_; ++i) {72 for (std::size_t i = 0; i < info_.thread_pool_size; ++i) { 76 73 boost::shared_ptr<boost::thread> thread( 77 74 new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service_) )); 78 75 threads_.push_back(thread); 79 76 } 80 request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring( thread_pool_size_));77 request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring(info_.thread_pool_size)); 81 78 82 79 // Wait for all threads in the pool to exit. … … 93 90 void server::handle_accept(const boost::system::error_code& e) { 94 91 if (!e) { 92 std::list<std::string> errors; 95 93 std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 96 request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 94 if (info_.allowed_hosts.is_allowed(new_connection_->socket().remote_endpoint().address().to_v4().to_ulong(), errors)) { 95 request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 96 new_connection_->start(); 97 } else { 98 BOOST_FOREACH(const std::string &e, errors) { 99 request_handler_->log_error(__FILE__, __LINE__, utf8::cvt<std::wstring>(e)); 100 } 101 request_handler_->log_error(__FILE__, __LINE__, _T("Rejcted connection from: ") + to_wstring(s)); 102 new_connection_->stop(); 103 } 97 104 98 new_connection_->start(); 99 new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, use_ssl_)); 105 new_connection_.reset(check_nt::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 100 106 101 107 acceptor_.async_accept(new_connection_->socket(), -
include/check_nt/server/server.hpp
re1d9a58 rb9498ef 1 1 #pragma once 2 2 3 #include <boost/asio.hpp>4 3 #include <string> 5 4 #include <vector> 5 6 6 #include <boost/noncopyable.hpp> 7 7 #include <boost/shared_ptr.hpp> 8 8 #include <boost/thread.hpp> 9 #include <boost/asio.hpp> 10 11 #include <socket/socket_helpers.hpp> 9 12 #include <check_nt/server/connection.hpp> 10 13 #include "handler.hpp" … … 35 38 class server : private boost::noncopyable { 36 39 public: 37 struct connection_info { 38 static const int backlog_default; 39 connection_info(boost::shared_ptr<check_nt::server::handler> request_handler_) : request_handler(request_handler_), back_log(backlog_default) {} 40 std::string address; 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; 46 bool use_ssl; 47 bool allow_args; 48 bool allow_nasty; 49 unsigned int timeout; 40 struct connection_info : public socket_helpers::connection_info { 41 connection_info(boost::shared_ptr<check_nt::server::handler> request_handler_) : request_handler(request_handler_) {} 42 connection_info(const connection_info &other) 43 : socket_helpers::connection_info(other) 44 , request_handler(other.request_handler) 45 {} 46 connection_info& operator=(const connection_info &other) { 47 socket_helpers::connection_info::operator=(other); 48 request_handler = other.request_handler; 49 return *this; 50 } 51 50 52 boost::shared_ptr<check_nt::server::handler> request_handler; 51 std::wstring certificate;52 std::wstring get_endpoint_str() {53 return to_wstring(address) + _T(":") + to_wstring(port);54 }55 53 }; 56 54 … … 73 71 void handle_accept(const boost::system::error_code& e); 74 72 75 /// The number of threads that will call io_service::run().76 std::size_t thread_pool_size_;77 78 73 /// The io_service used to perform asynchronous operations. 79 74 boost::asio::io_service io_service_; … … 93 88 boost::asio::ssl::context context_; 94 89 95 bool use_ssl_;96 97 90 /// The strand for handleTcpAccept(), handleSslAccept() and handleStop() 98 91 boost::asio::strand accept_strand_; 92 93 connection_info info_; 99 94 100 95 }; -
include/nrpe/client/socket.hpp
r65a2940 rb9498ef 3 3 #include <boost/shared_ptr.hpp> 4 4 5 #include <socket _helpers.hpp>5 #include <socket/socket_helpers.hpp> 6 6 #include <nsca/nsca_packet.hpp> 7 7 … … 69 69 } 70 70 virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 71 socket Helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout);71 socket_helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 72 72 } 73 73 virtual void write_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 74 socket Helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout);74 socket_helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 75 75 } 76 76 }; … … 106 106 107 107 virtual void write_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 108 socket Helpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout);108 socket_helpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 109 109 } 110 110 111 111 virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 112 socket Helpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout);112 socket_helpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 113 113 } 114 114 }; -
include/nrpe/server/server.cpp
r1f24a1c rb9498ef 14 14 15 15 16 const int server::connection_info::backlog_default = 0;17 18 16 server::server(connection_info info) 19 : thread_pool_size_(info.thread_pool_size) 20 , acceptor_(io_service_) 17 : acceptor_(io_service_) 21 18 , accept_strand_(io_service_) 22 19 , request_handler_(info.request_handler) // nrpe::length::get_payload_length()) 23 20 , context_(io_service_, boost::asio::ssl::context::sslv23) 24 , use_ssl_(info.use_ssl)21 , info_(info) 25 22 { 26 23 if (!request_handler_) … … 29 26 ip::tcp::resolver resolver(io_service_); 30 27 ip::tcp::resolver::iterator endpoint_iterator; 31 if (info .address.empty()) {32 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info .get_port()));28 if (info_.address.empty()) { 29 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_port())); 33 30 } else { 34 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info .get_address(), info.get_port()));31 endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info_.get_address(), info_.get_port())); 35 32 } 36 33 ip::tcp::resolver::iterator end; 37 34 if (endpoint_iterator == end) { 38 request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info .get_endpoint_str());35 request_handler_->log_error(__FILE__, __LINE__, std::wstring(_T("Failed to lookup: ")) + info_.get_endpoint_str()); 39 36 return; 40 37 } 41 if (info .use_ssl) {38 if (info_.use_ssl) { 42 39 SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 43 request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info .certificate));44 context_.use_tmp_dh_file(to_string(info .certificate));40 request_handler_->log_debug(__FILE__, __LINE__, _T("Using cert: ") + to_wstring(info_.certificate)); 41 context_.use_tmp_dh_file(to_string(info_.certificate)); 45 42 context_.set_verify_mode(boost::asio::ssl::context::verify_none); 46 43 } 47 44 48 new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, use_ssl_));45 new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 49 46 50 47 ip::tcp::endpoint endpoint = *endpoint_iterator; 51 48 acceptor_.open(endpoint.protocol()); 52 49 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 53 request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info .get_endpoint_str());50 request_handler_->log_debug(__FILE__, __LINE__, _T("Attempting to bind to: ") + info_.get_endpoint_str()); 54 51 acceptor_.bind(endpoint); 55 if (info .back_log == connection_info::backlog_default)52 if (info_.back_log == connection_info::backlog_default) 56 53 acceptor_.listen(); 57 54 else 58 acceptor_.listen(info .back_log);55 acceptor_.listen(info_.back_log); 59 56 60 57 acceptor_.async_accept(new_connection_->socket(), … … 63 60 ) 64 61 ); 65 request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info .get_endpoint_str());62 request_handler_->log_debug(__FILE__, __LINE__, _T("Bound to: ") + info_.get_endpoint_str()); 66 63 67 64 //io_service_.post(boost::bind(&Server::startAccept, this)); … … 73 70 void server::start() { 74 71 // Create a pool of threads to run all of the io_services. 75 for (std::size_t i = 0; i < thread_pool_size_; ++i) {72 for (std::size_t i = 0; i < info_.thread_pool_size; ++i) { 76 73 boost::shared_ptr<boost::thread> thread( 77 74 new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service_) )); 78 75 threads_.push_back(thread); 79 76 } 80 request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring( thread_pool_size_));77 request_handler_->log_debug(__FILE__, __LINE__, _T("Thredpool containes: ") + to_wstring(info_.thread_pool_size)); 81 78 82 79 // Wait for all threads in the pool to exit. … … 93 90 void server::handle_accept(const boost::system::error_code& e) { 94 91 if (!e) { 92 std::list<std::string> errors; 95 93 std::string s = new_connection_->socket().remote_endpoint().address().to_string(); 96 request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 94 if (info_.allowed_hosts.is_allowed(new_connection_->socket().remote_endpoint().address().to_v4().to_ulong(), errors)) { 95 request_handler_->log_debug(__FILE__, __LINE__, _T("Accepting connection from: ") + to_wstring(s)); 96 new_connection_->start(); 97 } else { 98 BOOST_FOREACH(const std::string &e, errors) { 99 request_handler_->log_error(__FILE__, __LINE__, utf8::cvt<std::wstring>(e)); 100 } 101 request_handler_->log_error(__FILE__, __LINE__, _T("Rejcted connection from: ") + to_wstring(s)); 102 new_connection_->stop(); 103 } 97 104 98 new_connection_->start(); 99 new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, use_ssl_)); 105 new_connection_.reset(nrpe::server::factories::create(io_service_, context_, request_handler_, info_.use_ssl)); 100 106 101 107 acceptor_.async_accept(new_connection_->socket(), -
include/nrpe/server/server.hpp
r497b779 rb9498ef 4 4 #include <string> 5 5 #include <vector> 6 6 7 #include <boost/noncopyable.hpp> 7 8 #include <boost/shared_ptr.hpp> 8 9 #include <boost/thread.hpp> 10 11 #include <socket/socket_helpers.hpp> 9 12 #include <nrpe/server/connection.hpp> 13 10 14 #include "handler.hpp" 11 15 … … 33 37 }; 34 38 35 class server : privateboost::noncopyable {39 class server : boost::noncopyable { 36 40 public: 37 struct connection_info { 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) {} 40 std::string address; 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; 46 bool use_ssl; 41 struct connection_info : public socket_helpers::connection_info { 42 connection_info(boost::shared_ptr<nrpe::server::handler> request_handler) : request_handler(request_handler) {} 43 connection_info(const connection_info &other) 44 : socket_helpers::connection_info(other) 45 , allow_args(other.allow_args) 46 , allow_nasty(other.allow_nasty) 47 , request_handler(other.request_handler) 48 {} 49 connection_info& operator=(const connection_info &other) { 50 socket_helpers::connection_info::operator=(other); 51 allow_args = other.allow_args; 52 allow_nasty = other.allow_nasty; 53 request_handler = other.request_handler; 54 return *this; 55 } 47 56 bool allow_args; 48 57 bool allow_nasty; 49 unsigned int timeout;50 58 boost::shared_ptr<nrpe::server::handler> request_handler; 51 std::wstring certificate;52 std::wstring get_endpoint_str() {53 return to_wstring(address) + _T(":") + to_wstring(port);54 }55 59 }; 56 60 … … 74 78 75 79 /// The number of threads that will call io_service::run(). 76 std::size_t thread_pool_size_;80 //std::size_t thread_pool_size_; 77 81 78 82 /// The io_service used to perform asynchronous operations. … … 93 97 boost::asio::ssl::context context_; 94 98 95 bool use_ssl_;99 //bool use_ssl_; 96 100 97 101 /// The strand for handleTcpAccept(), handleSslAccept() and handleStop() 98 102 boost::asio::strand accept_strand_; 103 connection_info info_; 99 104 100 105 }; -
include/nsca/nsca_socket.hpp
rd66ccee rb9498ef 3 3 #include <boost/shared_ptr.hpp> 4 4 5 #include <socket _helpers.hpp>5 #include <socket/socket_helpers.hpp> 6 6 7 7 #include <nsca/nsca_packet.hpp> … … 67 67 } 68 68 virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 69 socket Helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout);69 socket_helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 70 70 } 71 71 virtual void write_with_timeout(std::string &buf, boost::posix_time::seconds timeout) { 72 socket Helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout);72 socket_helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout); 73 73 } 74 74 /* … … 107 107 108 108 virtual void write_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 109 socket Helpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout);109 socket_helpers::io::write_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 110 110 } 111 111 112 112 virtual void read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 113 socket Helpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout);113 socket_helpers::io::read_with_timeout(*ssl_socket_, get_socket(), boost::asio::buffer(buf), timeout); 114 114 } 115 115 }; -
include/socket_helpers.hpp
r04ef932 rb9498ef 4 4 #include <boost/bind.hpp> 5 5 #include <boost/optional.hpp> 6 7 namespace socketHelpers { 8 class allowedHosts { 9 struct host_record { 10 host_record() : mask(0) {} 11 host_record(std::wstring r) : mask(0), record(r) {} 12 std::wstring record; 13 std::wstring host; 14 u_long in_addr; 15 unsigned long mask; 16 }; 17 public: 18 typedef std::list<host_record> host_list; 19 typedef std::list<std::wstring> string_list; 20 private: 21 host_list allowed_list_; 22 string_list lookup_list; 23 bool cachedAddresses_; 24 public: 25 allowedHosts() : cachedAddresses_(true) {} 26 27 unsigned int lookupMask(std::wstring mask) { 28 unsigned int masklen = 32; 29 if (!mask.empty()) { 30 std::wstring::size_type pos = mask.find_first_of(_T("0123456789")); 31 if (pos != std::wstring::npos) { 32 masklen = strEx::stoi(mask.substr(pos)); 33 } 34 } 35 if (masklen > 32) 36 masklen = 32; 37 return (~((unsigned int)0))>>(32-masklen); 38 } 39 void lookupList(boost::asio::io_service& io_service) { 40 allowed_list_.clear(); 41 for (string_list::iterator it = lookup_list.begin();it!=lookup_list.end();++it) { 42 std::wstring host = (*it); 43 host_record tmp_record; 44 if (!host.empty()) { 45 try { 46 std::wstring::size_type pos = host.find('/'); 47 if (pos == std::wstring::npos) { 48 tmp_record.host = host; 49 tmp_record.mask = lookupMask(_T("")); 50 } else { 51 tmp_record.host = host.substr(0, pos); 52 tmp_record.mask = lookupMask(host.substr(pos)); 53 } 54 boost::asio::ip::tcp::resolver resolver(io_service); 55 boost::asio::ip::tcp::resolver::query query(utf8::cvt<std::string>(tmp_record.host), ""); 56 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 57 boost::asio::ip::tcp::resolver::iterator end; 58 for (;endpoint_iterator != end; ++endpoint_iterator) { 59 tmp_record.in_addr = endpoint_iterator->endpoint().address().to_v4().to_ulong(); 60 tmp_record.host = utf8::cvt<std::wstring>(endpoint_iterator->endpoint().address().to_string()); 61 allowed_list_.push_back(tmp_record); 62 } 63 /* 64 std::cerr << "Added: " 65 + simpleSocket::Socket::inet_ntoa((*it).in_addr) 66 + " with mask " 67 + simpleSocket::Socket::inet_ntoa((*it).mask) 68 + " from " 69 + (*it).record << 70 std::endl; 71 */ 72 } catch (std::exception &e) { 73 std::cerr << "Filed to lookup host: " << e.what() << std::endl; 74 } catch (...) { 75 std::wcerr << _T("Filed to lookup host: ") << std::endl; 76 } 77 } 78 } 79 } 80 81 void setAllowedHosts(const std::list<std::wstring> list, bool cachedAddresses, boost::asio::io_service& io_service) { 82 for (std::list<std::wstring>::const_iterator it = list.begin(); it != list.end(); ++it) { 83 if (!(*it).empty()) 84 lookup_list.push_back(*it); 85 } 86 cachedAddresses_ = cachedAddresses; 87 lookupList(io_service); 88 } 89 bool matchHost(host_record allowed, struct in_addr remote) { 90 /* 91 if ((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)) { 92 std::cerr << "Matched: " << simpleSocket::Socket::inet_ntoa(allowed.in_addr) << " with " << 93 simpleSocket::Socket::inet_ntoa(remote.S_un.S_addr) << std::endl; 94 } 95 */ 96 return true; //((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)); 97 } 98 bool inAllowedHosts(boost::asio::io_service& io_service, struct in_addr remote) { 99 if (lookup_list.empty()) 100 return true; 101 if (!cachedAddresses_) { 102 lookupList(io_service); 103 } 104 for (host_list::const_iterator cit = allowed_list_.begin();cit!=allowed_list_.end();++cit) { 105 if (matchHost((*cit), remote)) 106 return true; 107 } 108 return false; 109 } 110 std::wstring to_string() { 111 std::wstring ret; 112 BOOST_FOREACH(host_record r, allowed_list_) { 113 if (!ret.empty()) ret += _T(", "); 114 ret += r.host; 115 } 116 return ret; 117 } 118 }; 119 120 namespace io { 121 void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) { 122 a->reset(b); 123 } 124 125 template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 126 void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 127 boost::optional<boost::system::error_code> timer_result; 128 boost::asio::deadline_timer timer(sock.get_io_service()); 129 timer.expires_from_now(duration); 130 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 131 132 boost::optional<boost::system::error_code> read_result; 133 async_read(sock, buffers, boost::bind(set_result, &read_result, _1)); 134 135 sock.get_io_service().reset(); 136 while (sock.get_io_service().run_one()) { 137 if (read_result) 138 timer.cancel(); 139 else if (timer_result) 140 rawSocket.close(); 141 } 142 143 if (*read_result) 144 throw boost::system::system_error(*read_result); 145 } 146 147 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 148 void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) { 149 boost::optional<boost::system::error_code> timer_result; 150 boost::asio::deadline_timer timer(sock.get_io_service()); 151 timer.expires_from_now(duration); 152 timer.async_wait(boost::bind(set_result, &timer_result, _1)); 153 154 boost::optional<boost::system::error_code> read_result; 155 async_write(sock, buffers, boost::bind(set_result, &read_result, _1)); 156 157 sock.get_io_service().reset(); 158 while (sock.get_io_service().run_one()) { 159 if (read_result) 160 timer.cancel(); 161 else if (timer_result) 162 rawSocket.close(); 163 } 164 165 if (*read_result) 166 throw boost::system::system_error(*read_result); 167 } 168 169 } 170 } 171 6 // 7 // namespace socketHelpers { 8 // class allowedHosts { 9 // struct host_record { 10 // host_record() : mask(0) {} 11 // host_record(std::wstring r) : mask(0), record(r) {} 12 // std::wstring record; 13 // std::wstring host; 14 // u_long in_addr; 15 // unsigned long mask; 16 // }; 17 // public: 18 // typedef std::list<host_record> host_list; 19 // typedef std::list<std::wstring> string_list; 20 // private: 21 // host_list allowed_list_; 22 // string_list lookup_list; 23 // bool cachedAddresses_; 24 // public: 25 // allowedHosts() : cachedAddresses_(true) {} 26 // 27 // unsigned int lookupMask(std::wstring mask) { 28 // unsigned int masklen = 32; 29 // if (!mask.empty()) { 30 // std::wstring::size_type pos = mask.find_first_of(_T("0123456789")); 31 // if (pos != std::wstring::npos) { 32 // masklen = strEx::stoi(mask.substr(pos)); 33 // } 34 // } 35 // if (masklen > 32) 36 // masklen = 32; 37 // return (~((unsigned int)0))>>(32-masklen); 38 // } 39 // void lookupList(boost::asio::io_service& io_service) { 40 // allowed_list_.clear(); 41 // for (string_list::iterator it = lookup_list.begin();it!=lookup_list.end();++it) { 42 // std::wstring host = (*it); 43 // host_record tmp_record; 44 // if (!host.empty()) { 45 // try { 46 // std::wstring::size_type pos = host.find('/'); 47 // if (pos == std::wstring::npos) { 48 // tmp_record.host = host; 49 // tmp_record.mask = lookupMask(_T("")); 50 // } else { 51 // tmp_record.host = host.substr(0, pos); 52 // tmp_record.mask = lookupMask(host.substr(pos)); 53 // } 54 // boost::asio::ip::tcp::resolver resolver(io_service); 55 // boost::asio::ip::tcp::resolver::query query(utf8::cvt<std::string>(tmp_record.host), ""); 56 // boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 57 // boost::asio::ip::tcp::resolver::iterator end; 58 // for (;endpoint_iterator != end; ++endpoint_iterator) { 59 // tmp_record.in_addr = endpoint_iterator->endpoint().address().to_v4().to_ulong(); 60 // tmp_record.host = utf8::cvt<std::wstring>(endpoint_iterator->endpoint().address().to_string()); 61 // allowed_list_.push_back(tmp_record); 62 // } 63 // /* 64 // std::cerr << "Added: " 65 // + simpleSocket::Socket::inet_ntoa((*it).in_addr) 66 // + " with mask " 67 // + simpleSocket::Socket::inet_ntoa((*it).mask) 68 // + " from " 69 // + (*it).record << 70 // std::endl; 71 // */ 72 // } catch (std::exception &e) { 73 // std::cerr << "Filed to lookup host: " << e.what() << std::endl; 74 // } catch (...) { 75 // std::wcerr << _T("Filed to lookup host: ") << std::endl; 76 // } 77 // } 78 // } 79 // } 80 // 81 // void setAllowedHosts(const std::list<std::wstring> list, bool cachedAddresses, boost::asio::io_service& io_service) { 82 // for (std::list<std::wstring>::const_iterator it = list.begin(); it != list.end(); ++it) { 83 // if (!(*it).empty()) 84 // lookup_list.push_back(*it); 85 // } 86 // cachedAddresses_ = cachedAddresses; 87 // lookupList(io_service); 88 // } 89 // bool matchHost(host_record allowed, struct in_addr remote) { 90 // /* 91 // if ((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)) { 92 // std::cerr << "Matched: " << simpleSocket::Socket::inet_ntoa(allowed.in_addr) << " with " << 93 // simpleSocket::Socket::inet_ntoa(remote.S_un.S_addr) << std::endl; 94 // } 95 // */ 96 // return true; //((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)); 97 // } 98 // bool inAllowedHosts(boost::asio::io_service& io_service, struct in_addr remote) { 99 // if (lookup_list.empty()) 100 // return true; 101 // if (!cachedAddresses_) { 102 // lookupList(io_service); 103 // } 104 // for (host_list::const_iterator cit = allowed_list_.begin();cit!=allowed_list_.end();++cit) { 105 // if (matchHost((*cit), remote)) 106 // return true; 107 // } 108 // return false; 109 // } 110 // std::wstring to_string() { 111 // std::wstring ret; 112 // BOOST_FOREACH(host_record r, allowed_list_) { 113 // if (!ret.empty()) ret += _T(", "); 114 // ret += r.host; 115 // } 116 // return ret; 117 // } 118 // }; 119 // 120 // } 121 // -
include/strEx.h
r04ef932 rb9498ef 334 334 return boost::lexical_cast<int>(s.c_str()); 335 335 } 336 inline int stoi(std::string s) { 337 return boost::lexical_cast<int>(s.c_str()); 338 } 336 339 inline double stod(std::wstring s) { 337 340 return boost::lexical_cast<double>(s.c_str()); -
modules/NRPEClient/CMakeLists.txt
r04ef932 rb9498ef 9 9 "${TARGET}.cpp" 10 10 ${NSCP_INCLUDEDIR}/nrpe/packet.cpp 11 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 11 12 12 13 ${NSCP_DEF_PLUGIN_CPP} … … 20 21 "${TARGET}.h" 21 22 "${TARGET}.def" 22 ${NSCP_INCLUDEDIR}/socket_helpers.hpp23 23 ${NSCP_INCLUDEDIR}/nrpe/packet.hpp 24 24 ${NSCP_INCLUDEDIR}/nrpe/client/socket.hpp 25 25 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 26 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 26 27 27 28 ${NSCP_DEF_PLUGIN_HPP} -
modules/NRPEServer/CMakeLists.txt
r04ef932 rb9498ef 17 17 ${NSCP_INCLUDEDIR}/nrpe/server/ssl_connection.cpp 18 18 ${NSCP_INCLUDEDIR}/nrpe/packet.cpp 19 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 19 20 20 21 ${NSCP_DEF_PLUGIN_CPP} … … 35 36 ${NSCP_INCLUDEDIR}/nrpe/server/handler.hpp 36 37 ${NSCP_INCLUDEDIR}/nrpe/server/parser.hpp 37 ${NSCP_INCLUDEDIR}/socket_helpers.hpp38 38 ${NSCP_INCLUDEDIR}/nrpe/packet.hpp 39 39 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 40 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 40 41 41 42 ${NSCP_DEF_PLUGIN_HPP} -
modules/NRPEServer/NRPEServer.cpp
r7ec3dd1 rb9498ef 38 38 NRPEListener::~NRPEListener() {} 39 39 40 std::wstring getAllowedHosts() {41 return SETTINGS_GET_STRING_FALLBACK(nrpe::ALLOWED_HOSTS, protocol_def::ALLOWED_HOSTS);42 }43 bool getCacheAllowedHosts() {44 return SETTINGS_GET_BOOL_FALLBACK(nrpe::CACHE_ALLOWED, protocol_def::CACHE_ALLOWED);45 }46 47 48 49 40 bool NRPEListener::loadModule() { 50 41 return false; … … 73 64 _T("PORT NUMBER"), _T("Port to use for NRPE.")) 74 65 66 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024), 67 _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.")) 68 69 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false), 70 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 71 72 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 73 _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.")) 74 75 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true), 76 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 77 78 ; 79 80 settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 81 75 82 (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 76 83 _T("THREAD POOL"), _T("")) 77 84 85 (_T("bind to"), sh::string_key(&info_.address), 86 _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.")) 87 88 (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 89 _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.")) 90 91 (_T("allowed hosts"), sh::string_fun_key<std::wstring>(boost::bind(&socket_helpers::allowed_hosts_manager::set_source, &info_.allowed_hosts, _1), _T("127.0.0.1")), 92 _T("ALLOWED HOSTS"), _T("A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.")) 93 94 (_T("cache allowed hosts"), sh::bool_key(&info_.allowed_hosts.cached, true), 95 _T("CACHE ALLOWED HOSTS"), _T("If hostnames should be cached, improves speed and security somewhat but wont allow you to have dynamic IPs for your nagios server.")) 96 78 97 (_T("timeout"), sh::uint_key(&info_.timeout, 30), 79 98 _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) … … 82 101 _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 83 102 84 (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024),85 _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."))86 87 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false),88 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed."))89 90 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false),91 _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."))92 93 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true),94 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data)."))95 96 103 (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 97 104 _T("SSL CERTIFICATE"), _T("")) 105 98 106 ; 99 100 settings.alias().add_parent(_T("/settings/default")).add_key_to_settings()101 102 (_T("bind to"), sh::string_key(&info_.address),103 _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."))104 105 (_T("socket queue size"), sh::int_key(&info_.back_log, 0),106 _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."))107 108 ;109 110 111 107 112 108 settings.register_all(); … … 124 120 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 125 121 122 123 std::list<std::string> errors; 124 info_.allowed_hosts.refresh(errors); 125 BOOST_FOREACH(const std::string &e, errors) { 126 NSC_LOG_ERROR_STD(utf8::cvt<std::wstring>(e)); 127 } 128 NSC_DEBUG_MSG_STD(_T("Allowed hosts definition: ") + info_.allowed_hosts.to_wstring()); 129 126 130 boost::asio::io_service io_service_; 127 128 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_);129 NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string());130 131 131 132 if (mode == NSCAPI::normalStart) { -
modules/NRPEServer/NRPEServer.h
r3bdaf18 rb9498ef 37 37 }; 38 38 39 socketHelpers::allowedHosts allowedHosts;40 39 nrpe::server::server::connection_info info_; 41 40 -
modules/NSCAAgent/CMakeLists.txt
r04ef932 rb9498ef 8 8 stdafx.cpp 9 9 "${TARGET}.cpp" 10 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 10 11 11 12 ${NSCP_DEF_PLUGIN_CPP} … … 31 32 ${NSCP_INCLUDEDIR}/nsca/nsca_enrypt.hpp 32 33 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 34 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 33 35 34 36 ${NSCP_DEF_PLUGIN_HPP} -
modules/NSCAAgent/NSCAAgent.cpp
rd66ccee rb9498ef 107 107 settings.notify(); 108 108 109 } catch (nscapi::nscapi_exception &e) { 110 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 111 return false; 109 112 } catch (std::exception &e) { 110 113 NSC_LOG_ERROR_STD(_T("Exception caught: ") + utf8::cvt<std::wstring>(e.what())); 111 return false;112 } catch (nscapi::nscapi_exception &e) {113 NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_);114 114 return false; 115 115 } catch (...) { -
modules/NSCAAgent/stdafx.h
r3bdaf18 rb9498ef 26 26 #include <iostream> 27 27 #include <string> 28 #include <hash_map>29 28 #include <list> 30 29 -
modules/NSClientServer/CMakeLists.txt
rb8c44b4 rb9498ef 17 17 ${NSCP_INCLUDEDIR}/check_nt/server/ssl_connection.cpp 18 18 ${NSCP_INCLUDEDIR}/check_nt/packet.cpp 19 ${NSCP_INCLUDEDIR}/socket/socket_helpers.cpp 19 20 20 21 ${NSCP_DEF_PLUGIN_CPP} … … 35 36 ${NSCP_INCLUDEDIR}/check_nt/server/handler.hpp 36 37 ${NSCP_INCLUDEDIR}/check_nt/server/parser.hpp 37 ${NSCP_INCLUDEDIR}/socket_helpers.hpp38 38 ${NSCP_INCLUDEDIR}/check_nt/packet.hpp 39 39 ${NSCP_INCLUDEDIR}/swap_bytes.hpp 40 ${NSCP_INCLUDEDIR}/socket/socket_helpers.hpp 40 41 41 42 ${NSCP_DEF_PLUGIN_HPP} -
modules/NSClientServer/NSClientServer.cpp
rb8c44b4 rb9498ef 67 67 _T("PORT NUMBER"), _T("Port to use for check_nt.")) 68 68 69 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_perf_data, info_.request_handler, _1), true), 70 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 71 72 ; 73 74 settings.alias().add_parent(_T("/settings/default/socket")).add_key_to_settings() 75 69 76 (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 70 77 _T("THREAD POOL"), _T("")) 71 78 79 (_T("bind to"), sh::string_key(&info_.address), 80 _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.")) 81 82 (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 83 _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.")) 84 85 (_T("allowed hosts"), sh::string_fun_key<std::wstring>(boost::bind(&socket_helpers::allowed_hosts_manager::set_source, &info_.allowed_hosts, _1), _T("127.0.0.1")), 86 _T("ALLOWED HOSTS"), _T("A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.")) 87 88 (_T("cache allowed hosts"), sh::bool_key(&info_.allowed_hosts.cached, true), 89 _T("CACHE ALLOWED HOSTS"), _T("If hostnames should be cached, improves speed and security somewhat but wont allow you to have dynamic IPs for your nagios server.")) 90 72 91 (_T("timeout"), sh::uint_key(&info_.timeout, 30), 73 92 _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) … … 76 95 _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 77 96 78 (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_allow_arguments, info_.request_handler, _1), false),79 _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed."))80 81 (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false),82 _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."))83 84 (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&check_nt::server::handler::set_perf_data, info_.request_handler, _1), true),85 _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data)."))86 87 97 (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 88 98 _T("SSL CERTIFICATE"), _T("")) 99 89 100 ; 90 101 91 102 settings.alias().add_parent(_T("/settings/default")).add_key_to_settings() 92 103 93 (_T("bind to"), sh::string_key(&info_.address), 94 _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.")) 95 96 (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 97 _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.")) 98 99 ; 100 101 104 (_T("password"), sh::string_fun_key<std::wstring>(boost::bind(&check_nt::server::handler::set_password, info_.request_handler, _1), _T("")), 105 _T("PASSWORD"), _T("Password used to authenticate againast server")) 106 ; 102 107 103 108 settings.register_all(); … … 105 110 } catch (...) {} 106 111 107 // allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts());108 // unsigned short port = SETTINGS_GET_INT(nsclient::PORT);109 // std::wstring host = SETTINGS_GET_STRING(nsclient::BINDADDR);110 // unsigned int backLog = SETTINGS_GET_INT(nsclient::LISTENQUE);111 // socketTimeout_ = SETTINGS_GET_INT(nsclient::READ_TIMEOUT);112 113 114 info_.request_handler->set_password(_T("TODO"));115 116 112 #ifndef USE_SSL 117 113 if (info_.use_ssl) { … … 122 118 NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 123 119 120 121 std::list<std::string> errors; 122 info_.allowed_hosts.refresh(errors); 123 BOOST_FOREACH(const std::string &e, errors) { 124 NSC_LOG_ERROR_STD(utf8::cvt<std::wstring>(e)); 125 } 126 NSC_DEBUG_MSG_STD(_T("Allowed hosts definition: ") + info_.allowed_hosts.to_wstring()); 127 124 128 boost::asio::io_service io_service_; 125 126 allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_);127 NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string());128 129 129 130 if (mode == NSCAPI::normalStart) { 130 131 try { 131 132 133 134 132 if (info_.use_ssl) { 135 133 #ifdef USE_SSL -
modules/NSClientServer/NSClientServer.h
rb8c44b4 rb9498ef 28 28 private: 29 29 30 socketHelpers::allowedHosts allowedHosts;31 30 check_nt::server::server::connection_info info_; 32 31 boost::shared_ptr<check_nt::server::server> server_; -
modules/PythonScript/script_wrapper.cpp
r2c95d22 rb9498ef 265 265 266 266 void script_wrapper::command_wrapper::simple_submit(std::string channel, std::string command, status code, std::string message, std::string perf) { 267 core->submit_simple_message(utf8::cvt<std::wstring>(channel), utf8::cvt<std::wstring>(command), code, utf8::cvt<std::wstring>(message), utf8::cvt<std::wstring>(perf)); 267 NSCAPI::nagiosReturn c = NSCAPI::returnUNKNOWN; 268 if (code == OK) 269 c = NSCAPI::returnOK; 270 if (code == WARN) 271 c = NSCAPI::returnWARN; 272 if (code == CRIT) 273 c = NSCAPI::returnCRIT; 274 std::wstring wmessage = utf8::cvt<std::wstring>(message); 275 std::wstring wperf = utf8::cvt<std::wstring>(perf); 276 core->submit_simple_message(utf8::cvt<std::wstring>(channel), utf8::cvt<std::wstring>(command), c, wmessage, wperf); 268 277 } 269 278
Note: See TracChangeset
for help on using the changeset viewer.








