|
|
@@ -187,7 +187,7 @@ UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile[], int Nu |
|
|
|
|
|
|
|
Temp << "Internal error: NumDefaultFiles <= 0 at " << __FILE__ << ":" << __LINE__;
|
|
|
|
|
|
|
|
throw runtime_error(Temp.str());
|
|
|
|
throw std::runtime_error(Temp.str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -204,7 +204,7 @@ UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile[], int Nu |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -257,7 +257,7 @@ UtilityConfig::LoadConfig() { |
|
|
|
|
|
|
|
Temp = "Error reading configuration file " + GetConfigFileName();
|
|
|
|
Temp += ".";
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -276,7 +276,7 @@ UtilityConfig::LoadConfig() { |
|
|
|
Temp += "\n Log path: " + CFGData.paths_log_path;
|
|
|
|
Temp += "\n Update script: " + CFGData.update_script_call;
|
|
|
|
Temp += "\n Identity file: " + CFGData.node_identity;
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -324,6 +324,36 @@ UtilityConfig::GetLogPath(void) { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
UtilityConfig::GetStatusSecondLogFileName(void) {
|
|
|
|
|
|
|
|
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.second.log";
|
|
|
|
|
|
|
|
if (CFGData.Scan_XML_Mode) {
|
|
|
|
|
|
|
|
FileName += ".xml";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
UtilityConfig::GetStatusMinuteLogFileName(void) {
|
|
|
|
|
|
|
|
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.minute.log";
|
|
|
|
|
|
|
|
if (CFGData.Scan_XML_Mode) {
|
|
|
|
|
|
|
|
FileName += ".xml";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
UtilityConfig::GetIdentityFileName(void) {
|
|
|
|
|
|
|
@@ -404,7 +434,7 @@ UtilityConfig::LoadInfo(){ |
|
|
|
Temp << "Internal error in UtilityConfig::LoadInfo: Invalid value of OperatingSystemType: "
|
|
|
|
<< OperatingSystemType;
|
|
|
|
|
|
|
|
throw runtime_error(Temp.str());
|
|
|
|
throw std::runtime_error(Temp.str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -489,6 +519,293 @@ UtilityConfig::SetupRepairLogDir() { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UtilityConfig::StatusCheckMethod
|
|
|
|
UtilityConfig::GetPreferredStatusCheckMethod(void) {
|
|
|
|
|
|
|
|
if (CFGData.XCI_OnOff) {
|
|
|
|
|
|
|
|
return StatusCheckXci;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFGData.Status_SecondReport_Log_OnOff) {
|
|
|
|
|
|
|
|
return StatusCheckSecond;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFGData.Status_MinuteReport_Log_OnOff) {
|
|
|
|
|
|
|
|
return StatusCheckMinute;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StatusCheckNotAvailable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
UtilityConfig::GetSnifferStatusReport() {
|
|
|
|
|
|
|
|
std::string StatusReport;
|
|
|
|
|
|
|
|
switch (GetPreferredStatusCheckMethod()) {
|
|
|
|
|
|
|
|
case StatusCheckXci:
|
|
|
|
|
|
|
|
StatusReport = GetReportViaXci();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StatusCheckSecond:
|
|
|
|
|
|
|
|
StatusReport = GetReportViaLogFile(GetStatusSecondLogFileName(), 5000);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StatusCheckMinute:
|
|
|
|
|
|
|
|
std::cout << "Getting Sniffer status from status.minute log file (this takes about 70 s)...";
|
|
|
|
std::cout.flush();
|
|
|
|
StatusReport = GetReportViaLogFile(GetStatusMinuteLogFileName(), 70 * 1000);
|
|
|
|
std::cout << "done." << std::endl;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "No method for determining Sniffer status is available. ";
|
|
|
|
Temp += "Tried XCI, status.second logging, and status.minute logging.";
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StatusReport;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
UtilityConfig::GetReportViaXci() {
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "Getting Sniffer status report via XCI...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectSuccess = false;
|
|
|
|
std::string ResultString;
|
|
|
|
const std::string RequestString("<snf><xci><report><request><status class='second'/></request></report></xci></snf>");
|
|
|
|
|
|
|
|
// Code copied from SNFClient.
|
|
|
|
|
|
|
|
// Max time in this loop should be (100*50ms) = 5 seconds per try times
|
|
|
|
// 10 tries = 50 seconds, plus (9*500ms) = 4.5 secs for re-tries. ~ 55 secs.
|
|
|
|
|
|
|
|
const int ResultBufferSize = 4096;
|
|
|
|
char ResultBuffer[ResultBufferSize+1]; // Make an oversize buffer for the answer.
|
|
|
|
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Set the entire thing to nulls.
|
|
|
|
|
|
|
|
const int Tries = 20; // How many times to try this.
|
|
|
|
Sleeper SleepAfterAttempt(100); // How long to sleep between attempts.
|
|
|
|
|
|
|
|
const int OpenTries = 90; // How many tries at opening.
|
|
|
|
Sleeper WaitForOpen(10); // How long to wait for an open cycle.
|
|
|
|
|
|
|
|
const int ReadTries = 900; // How many tries at reading.
|
|
|
|
Sleeper SleepBeforeReading(10); // How long to pause before reading.
|
|
|
|
|
|
|
|
/*
|
|
|
|
** 20 * 100ms = 2 seconds for all tries.
|
|
|
|
** 90 * 10ms = 900ms for a failed connection.
|
|
|
|
** 900 * 10ms = 9 seconds for a failed read.
|
|
|
|
**
|
|
|
|
** Approximate wait for can't connect = 2.0 + (20 * 0.9) = ~ 20.0 seconds.
|
|
|
|
** Maximum impossible wait = 2.0 + (0.9 * 20) + (9.0 * 20) = 200.0 seconds.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for(int tryagain = Tries; (0<tryagain) && (!ConnectSuccess); tryagain--) { // Try a few times to get this done.
|
|
|
|
try {
|
|
|
|
ResultString = ""; // Clear our result string.
|
|
|
|
TCPHost SNFServer(9001); // Create connection to server.
|
|
|
|
SNFServer.makeNonBlocking(); // Make it non-blocking.
|
|
|
|
|
|
|
|
for(int tries = OpenTries; 0 < tries; tries--) { // Wait & Watch for a good connection.
|
|
|
|
try { SNFServer.open(); } catch(...) {} // Try opening the connection.
|
|
|
|
if(SNFServer.isOpen()) break; // When successful, let's Go!
|
|
|
|
else WaitForOpen(); // When not successful, pause.
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SNFServer.isOpen()) { // If we have a good connection:
|
|
|
|
|
|
|
|
SNFServer.transmit(
|
|
|
|
RequestString.c_str(), RequestString.length()); // Send the request.
|
|
|
|
|
|
|
|
for(int tries = ReadTries; 0 < tries; tries--) { // Try to read the result a few times.
|
|
|
|
SleepBeforeReading(); // Provide some time for each try.
|
|
|
|
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Clear the buffer.
|
|
|
|
SNFServer.receive(ResultBuffer, ResultBufferSize); // Receive the answer.
|
|
|
|
ResultString.append(ResultBuffer);
|
|
|
|
if(string::npos ==
|
|
|
|
ResultString.rfind("</snf>",ResultString.length())) { // If we don't have the end yet.
|
|
|
|
continue; // Try again.
|
|
|
|
} else { // If we got to end of line
|
|
|
|
ConnectSuccess = true; // Success!
|
|
|
|
break; // We're done.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SNFServer.close(); // No need for our connection after that.
|
|
|
|
}
|
|
|
|
} catch(...) { } // Ignore errors for now.
|
|
|
|
if(!ConnectSuccess) SleepAfterAttempt(); // Pause for a moment before trying again..
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ConnectSuccess) { // If no connection then Sniffer isn't running.
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "no response...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we should have a usable result.
|
|
|
|
if(Debug()) { cout << ResultString << endl; } // In debug, show the result string.
|
|
|
|
|
|
|
|
snf_xci Reader(ResultString); // Interpret the data and check for
|
|
|
|
if(Reader.bad()) { // a proper read. If it was bad...
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Bad result from Sniffer:\n" + ResultString;
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(0 < Reader.xci_error_message.length()) { // If the result was a general error...
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "XCI error when determing status of Sniffer: " + Reader.xci_error_message;
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
return Reader.report_response;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
UtilityConfig::GetReportViaLogFile(std::string LogFileName, int SleepTime_msec) {
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "Getting Sniffer status report via log file " << LogFileName << "...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InitialContents;
|
|
|
|
|
|
|
|
InitialContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read last part of log file.
|
|
|
|
|
|
|
|
Sleeper Sleep(SleepTime_msec); // Wait 5 s.
|
|
|
|
Sleep();
|
|
|
|
|
|
|
|
std::string FinalContents;
|
|
|
|
|
|
|
|
FinalContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read again.
|
|
|
|
|
|
|
|
if (InitialContents == FinalContents) { // If unchanged...
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "report unchanged...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""; // ...there is no report.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
return FinalContents;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UtilityConfig::CheckSnifferStatusReport(std::string StatusReport, std::string ApplicationName) {
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "Checking Sniffer status report...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationElement MyCFGReader("stats"); // Object to parse the XML.
|
|
|
|
ConfigurationData MyCFGData(StatusReport); // Object that contains the XML.
|
|
|
|
|
|
|
|
std::string PlatformContent;
|
|
|
|
|
|
|
|
MyCFGReader
|
|
|
|
.Element("version")
|
|
|
|
.Element("platform", PlatformContent, "")
|
|
|
|
.End("platform")
|
|
|
|
.End("version")
|
|
|
|
.End("stats");
|
|
|
|
|
|
|
|
MyCFGReader.initialize();
|
|
|
|
if (!MyCFGReader.interpret(MyCFGData)) {
|
|
|
|
std::ostringstream Temp;
|
|
|
|
|
|
|
|
Temp << "Error interpreting the Sniffer status report:\n" << StatusReport;
|
|
|
|
throw std::runtime_error(Temp.str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::string::npos == PlatformContent.find(ApplicationName)) { // Verify correct application.
|
|
|
|
std::ostringstream Temp;
|
|
|
|
|
|
|
|
Temp << "Error--The expected Sniffer application (" << ApplicationName
|
|
|
|
<< ") isn't running. The running application determined from the status report is "
|
|
|
|
<< PlatformContent;
|
|
|
|
throw std::runtime_error(Temp.str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UtilityConfig::SnifferRunningStateEnum
|
|
|
|
UtilityConfig::GetRunningState(std::string ApplicationName) {
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "Checking whether " << ApplicationName << " is running...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string StatusReport = GetSnifferStatusReport();
|
|
|
|
|
|
|
|
if (StatusReport.length() == 0) {
|
|
|
|
|
|
|
|
return SnifferIsStopped;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckSnifferStatusReport(StatusReport, ApplicationName);
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
return SnifferIsRunning;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UtilityConfig::SetupRepair(const std::string SampleIdentityFile) {
|
|
|
|
|
|
|
@@ -519,7 +836,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp = "Error opening rulebase download script file " + File;
|
|
|
|
Temp += " for reading: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
string Content;
|
|
|
@@ -536,7 +853,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
|
|
|
|
Temp = "Rulebase sownload script file " + File;
|
|
|
|
Temp += " has the wrong format: Found two lines beginning with " + LicenseSearchString;
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -558,7 +875,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
|
|
|
|
Temp = "Rulebase download script file " + File;
|
|
|
|
Temp += " has the wrong format: Found two lines beginning with " + AuthSearchString;
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
@@ -583,7 +900,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp += " has the wrong format: Missing required line beginning with '" + LicenseSearchString;
|
|
|
|
Temp += "' or '" + AuthSearchString;
|
|
|
|
Temp += "'";
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Input.eof()) { // Should be at end-of-file.
|
|
|
@@ -592,7 +909,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp = "Error reading the rulebase download script file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Input.close();
|
|
|
@@ -602,7 +919,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp = "Error closing the rulebase download script file " + File;
|
|
|
|
Temp += " after reading: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -619,7 +936,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp = "Error opening rulebase download script file " + File;
|
|
|
|
Temp += " for writing: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output << Content;
|
|
|
@@ -629,7 +946,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp = "Error writing the rulebase download script file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output.close();
|
|
|
@@ -639,7 +956,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() { |
|
|
|
Temp = "Error closing the rulebase download script file " + File;
|
|
|
|
Temp += " after writing: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
@@ -700,9 +1017,8 @@ UtilityConfig::DownloadRulebase() { |
|
|
|
std::ostringstream Temp;
|
|
|
|
|
|
|
|
Temp << "Unable to remove rulebase download status file " << StatusFile
|
|
|
|
<< ": " << strerror(errno) << "\n";
|
|
|
|
|
|
|
|
throw runtime_error(Temp.str());
|
|
|
|
<< ": " << strerror(errno);
|
|
|
|
throw std::runtime_error(Temp.str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -713,7 +1029,7 @@ UtilityConfig::DownloadRulebase() { |
|
|
|
|
|
|
|
Temp = "Error running the command '" + Command;
|
|
|
|
Temp += "'.";
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -726,7 +1042,7 @@ UtilityConfig::DownloadRulebase() { |
|
|
|
Temp = "Error opening rulebase download scriptstatus file " + StatusFile;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
string Line;
|
|
|
@@ -744,7 +1060,7 @@ UtilityConfig::DownloadRulebase() { |
|
|
|
string Temp;
|
|
|
|
|
|
|
|
Temp = "Error downloading the rulebase. Rulebase download status:\n\n" + Content;
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -774,7 +1090,7 @@ UtilityConfig::UpdateIdentityFile() { |
|
|
|
Temp = "Error opening identity file " + File;
|
|
|
|
Temp += " for reading: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ostringstream InputContents;
|
|
|
@@ -799,7 +1115,7 @@ UtilityConfig::UpdateIdentityFile() { |
|
|
|
Temp = "Error closing the identity file " + File;
|
|
|
|
Temp += " after reading: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
string Content = InputContents.str();
|
|
|
@@ -815,7 +1131,7 @@ UtilityConfig::UpdateIdentityFile() { |
|
|
|
Temp = "Error updating credentials for identity file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += e.what();
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -832,7 +1148,7 @@ UtilityConfig::UpdateIdentityFile() { |
|
|
|
Temp = "Error opening identity file " + File;
|
|
|
|
Temp += " for writing: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output << Content;
|
|
|
@@ -842,7 +1158,7 @@ UtilityConfig::UpdateIdentityFile() { |
|
|
|
Temp = "Error writing the identity file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output.close();
|
|
|
@@ -852,7 +1168,7 @@ UtilityConfig::UpdateIdentityFile() { |
|
|
|
Temp = "Error closing the identity file " + File;
|
|
|
|
Temp += " after writing: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
@@ -886,7 +1202,7 @@ UtilityConfig::UpdateIdentityFileOld() { |
|
|
|
Temp = "Error opening identity file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output << "<!-- License file created by SNFIdentity-->\n"
|
|
|
@@ -900,7 +1216,7 @@ UtilityConfig::UpdateIdentityFileOld() { |
|
|
|
Temp = "Error writing identity file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output.close();
|
|
|
@@ -910,7 +1226,7 @@ UtilityConfig::UpdateIdentityFileOld() { |
|
|
|
Temp = "Error closing identity file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
@@ -925,12 +1241,11 @@ UtilityConfig::UpdateIdentityFileOld() { |
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
UtilityConfig::StartSniffer(std::string Script) {
|
|
|
|
UtilityConfig::StartSniffer(std::string ScriptAndArgs, std::string ApplicationName) {
|
|
|
|
|
|
|
|
std::string Command;
|
|
|
|
|
|
|
|
Command = SnifferStartScriptDir + Script;
|
|
|
|
Command += " start";
|
|
|
|
Command = SnifferStartScriptDir + ScriptAndArgs;
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
@@ -938,6 +1253,14 @@ UtilityConfig::StartSniffer(std::string Script) { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SnifferIsRunning == GetRunningState(ApplicationName)) {
|
|
|
|
|
|
|
|
std::cout << ApplicationName << " is already running.\n";
|
|
|
|
OutputVerboseEnd();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Explain()) {
|
|
|
|
|
|
|
|
if (std::system(Command.c_str()) == -1) { // Start the sniffer.
|
|
|
@@ -946,12 +1269,67 @@ UtilityConfig::StartSniffer(std::string Script) { |
|
|
|
Temp = "Error running the command '" + Command;
|
|
|
|
Temp += "' to start the Sniffer: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SnifferIsRunning != GetRunningState(ApplicationName)) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Unable to start " + ApplicationName;
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UtilityConfig::StopSniffer(std::string ScriptAndArgs, std::string ApplicationName) {
|
|
|
|
|
|
|
|
std::string Command;
|
|
|
|
|
|
|
|
Command = SnifferStartScriptDir + ScriptAndArgs;
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "Stopping Sniffer with the command '" << Command << "'...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SnifferIsStopped == GetRunningState(ApplicationName)) {
|
|
|
|
|
|
|
|
std::cout << ApplicationName << " is already not running.\n";
|
|
|
|
OutputVerboseEnd();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Explain()) {
|
|
|
|
|
|
|
|
if (std::system(Command.c_str()) == -1) { // Start the sniffer.
|
|
|
|
string Temp;
|
|
|
|
|
|
|
|
Temp = "Error running the command '" + Command;
|
|
|
|
Temp += "' to stop the Sniffer: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SnifferIsStopped != GetRunningState(ApplicationName)) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Unable to sto " + ApplicationName;
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
}
|