Changeset 035c51f in nscp for modules/NSCAAgent
- Timestamp:
- 02/03/08 11:10:38 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 777180d
- Parents:
- 52215d7
- Location:
- modules/NSCAAgent
- Files:
-
- 1 added
- 3 edited
-
NSCAAgent-2005.vcproj (modified) (2 diffs)
-
NSCAThread.cpp (modified) (3 diffs)
-
NSCAThread.h (modified) (5 diffs)
-
nsca_enrypt.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
modules/NSCAAgent/NSCAAgent-2005.vcproj
r3f69109 r035c51f 70 70 Name="VCLinkerTool" 71 71 AdditionalDependencies="ws2_32.lib" 72 OutputFile=" $(OutDir)\$(ProjectName).dll"72 OutputFile="../../Debug/modules/$(ProjectName).dll" 73 73 LinkIncremental="2" 74 74 ModuleDefinitionFile="NSCAAgent.def" … … 1901 1901 <File 1902 1902 RelativePath="..\..\include\error.hpp" 1903 > 1904 </File> 1905 <File 1906 RelativePath=".\nsca_enrypt.hpp" 1903 1907 > 1904 1908 </File> -
modules/NSCAAgent/NSCAThread.cpp
r5ca3931 r035c51f 27 27 host_ = NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_HOSTNAME, NSCA_HOSTNAME_DEFAULT); 28 28 port_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_PORT, NSCA_PORT_DEFAULT); 29 encryption_method_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_ENCRYPTION, NSCA_ENCRYPTION_DEFAULT); 30 password_ = strEx::wstring_to_string(NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_PASSWORD, NSCA_PASSWORD_DEFAULT)); 29 31 std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(NSCA_CMD_SECTION_TITLE); 30 32 for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { … … 100 102 results.push_back((*cit).execute(host_)); 101 103 } 102 103 104 send(results); 104 105 105 _time64( &stop ); 106 106 __int64 elapsed = stop-start; … … 129 129 } 130 130 void NSCAThread::send(const std::list<Command::Result> &results) { 131 NSC_LOG_MESSAGE_STD(_T(">>> Attempting to send results...")); 132 simpleSocket::Socket socket(true); 133 simpleSocket::DataBuffer inc; 134 if (socket.connect(host_, port_) == SOCKET_ERROR) { 135 NSC_LOG_MESSAGE_STD(_T("<<< Could not connect to: ") + host_ + strEx::itos(port_)); 131 try { 132 nsca_encrypt crypt_inst; 133 simpleSocket::Socket socket(true); 134 simpleSocket::DataBuffer inc; 135 if (socket.connect(host_, port_) == SOCKET_ERROR) { 136 NSC_LOG_ERROR_STD(_T("<<< Could not connect to: ") + host_ + strEx::itos(port_)); 137 return; 138 } 139 if (!socket.readAll(inc, sizeof(NSCAPacket::init_packet_struct), sizeof(NSCAPacket::init_packet_struct))) { 140 NSC_LOG_ERROR_STD(_T("<<< Failed to read header: ") + host_ + strEx::itos(port_)); 141 return; 142 } 143 NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer(); 144 try { 145 crypt_inst.encrypt_init(password_.c_str(),encryption_method_,packet_in->iv); 146 } catch (nsca_encrypt::exception &e) { 147 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header: ") + e.getMessage()); 148 return; 149 } catch (...) { 150 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!")); 151 return; 152 } 153 154 try { 155 for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) { 156 //NSC_DEBUG_MSG_STD(_T("Sending : ") + (*cit).toString()); 157 socket.send((*cit).getBuffer(crypt_inst)); 158 } 159 } catch (nsca_encrypt::exception &e) { 160 NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet: ") + e.getMessage()); 161 return; 162 } catch (...) { 163 NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet!")); 164 return; 165 } 166 socket.close(); 167 } catch (...) { 168 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!")); 136 169 return; 137 170 } 138 NSC_DEBUG_MSG_STD(_T("... Connected, attempting to read: ") + strEx::itos(sizeof(NSCAPacket::init_packet_struct)));139 if (!socket.readAll(inc, sizeof(NSCAPacket::init_packet_struct), sizeof(NSCAPacket::init_packet_struct))) {140 NSC_LOG_MESSAGE_STD(_T("<<< Failed to read header: ") + host_ + strEx::itos(port_));141 return;142 }143 NSC_DEBUG_MSG_STD(_T("... Read..."));144 NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer();145 NSC_LOG_MESSAGE_STD(_T("Read: ") + strEx::format_date(packet_in->timestamp));146 for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) {147 NSC_LOG_MESSAGE_STD(_T("Sending : ") + (*cit).toString());148 socket.send((*cit).getBuffer());149 }150 NSC_DEBUG_MSG_STD(_T("... Done..."));151 socket.close();152 NSC_LOG_MESSAGE_STD(_T("<<< Attempting to send results..."));153 171 } 154 172 -
modules/NSCAAgent/NSCAThread.h
r5ca3931 r035c51f 25 25 #include <arrayBuffer.h> 26 26 #include <Socket.h> 27 #include "nsca_enrypt.hpp" 27 28 28 29 /** … … 139 140 Result(std::wstring _host) : host(_host){ 140 141 _time32(&time); 141 time+=60*60 + 2*60;142 //time+=60*60 + 2*60; 142 143 } 143 144 std::wstring service; … … 153 154 } 154 155 155 simpleSocket::DataBuffer getBuffer( ) const {156 simpleSocket::DataBuffer getBuffer(nsca_encrypt &crypt_inst) const { 156 157 std::string s = strEx::wstring_to_string(service); 157 158 std::string r = strEx::wstring_to_string(result); … … 170 171 unsigned int calculated_crc32=calculate_crc32(reinterpret_cast<char*>(&data),sizeof(data)); 171 172 data.crc32_value=static_cast<NSCAPacket::u_int32_t>(htonl(calculated_crc32)); 172 173 return simpleSocket::DataBuffer(reinterpret_cast<char*>(&data),sizeof(data)); 173 char * buffer = reinterpret_cast<char*>(&data); 174 crypt_inst.encrypt_buffer(buffer, sizeof(data)); 175 return simpleSocket::DataBuffer(buffer,sizeof(data)); 174 176 } 175 177 … … 207 209 std::wstring host_; 208 210 unsigned int port_; 211 std::string password_; 212 int encryption_method_; 209 213 210 214 public:
Note: See TracChangeset
for help on using the changeset viewer.








