|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::string UtilityConfig::RulebaseDownloadCommand("FIX THIS");
|
|
|
const std::string UtilityConfig::RulebaseDownloadCommand("FIX THIS");
|
|
|
|
|
|
|
|
|
|
|
|
const std::string UtilityConfig::RulebaseDownloadStatusFile("FIX THIS");
|
|
|
|
|
|
|
|
|
const std::string ScriptNameKey("FIX THIS"); ///< Text to replace with script name.
|
|
|
const std::string ScriptNameKey("FIX THIS"); ///< Text to replace with script name.
|
|
|
const std::string SnifferPathKey("FIX THIS"); ///< Text to replace with directory of the rulebase.
|
|
|
const std::string SnifferPathKey("FIX THIS"); ///< Text to replace with directory of the rulebase.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::string ScriptNameKey("SCRIPT"); ///< Text to replace with script name.
|
|
|
const std::string ScriptNameKey("SCRIPT"); ///< Text to replace with script name.
|
|
|
const std::string SnifferPathKey("SNIFFER_PATH"); ///< Text to replace with directory of the rulebase.
|
|
|
const std::string SnifferPathKey("SNIFFER_PATH"); ///< Text to replace with directory of the rulebase.
|
|
|
|
|
|
|
|
|
|
|
|
// SNIFFER_PATH is replaced with the path of the rulebase.
|
|
|
|
|
|
const std::string UtilityConfig::RulebaseDownloadStatusFile("SNIFFER_PATH/getRulebase.status");
|
|
|
|
|
|
|
|
|
#ifdef DEFAULT_DATA_DIR
|
|
|
#ifdef DEFAULT_DATA_DIR
|
|
|
// *nix, DEFAULT_DATA_DIR is specified on the compile command line.
|
|
|
// *nix, DEFAULT_DATA_DIR is specified on the compile command line.
|
|
|
const std::string UtilityConfig::SampleIgnoreListFile(DEFAULT_DATA_DIR "/GBUdbIgnoreList.txt.sample");
|
|
|
const std::string UtilityConfig::SampleIgnoreListFile(DEFAULT_DATA_DIR "/GBUdbIgnoreList.txt.sample");
|
|
|
|
|
|
|
|
|
/// Authentication command-line input.
|
|
|
/// Authentication command-line input.
|
|
|
const string AuthenticationKey("-auth=");
|
|
|
const string AuthenticationKey("-auth=");
|
|
|
|
|
|
|
|
|
|
|
|
/// String that indicates a successful rulebase download.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This string must be in the last line of the getRulebase status
|
|
|
|
|
|
// file. Note: The getRulebase status file is created by the
|
|
|
|
|
|
// getRulebase script, has the name getRulebase.status, and is in the
|
|
|
|
|
|
// same directory as the rulebase files.
|
|
|
|
|
|
const string SuccessKey("Success");
|
|
|
|
|
|
|
|
|
const string LicenseSearchString = "LICENSE_ID=";
|
|
|
const string LicenseSearchString = "LICENSE_ID=";
|
|
|
const string AuthSearchString = "AUTHENTICATION=";
|
|
|
const string AuthSearchString = "AUTHENTICATION=";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
|
std::cout << "Downloading the rulebase...";
|
|
|
std::cout << "Downloading the rulebase...";
|
|
|
|
|
|
std::cout.flush();
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string StatusFile; // Construct download status file name.
|
|
|
|
|
|
|
|
|
|
|
|
StatusFile = RulebaseDownloadStatusFile;
|
|
|
|
|
|
|
|
|
|
|
|
SnifferPathIndex = StatusFile.find(SnifferPathKey);
|
|
|
|
|
|
|
|
|
|
|
|
if (SnifferPathIndex != std::string::npos) { // Insert rulebase location?
|
|
|
|
|
|
|
|
|
|
|
|
StatusFile.replace(SnifferPathIndex, SnifferPathKey.length(), GetRulebasePath());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
if (!Explain()) {
|
|
|
if (!Explain()) {
|
|
|
|
|
|
|
|
|
if (std::system(Command.c_str()) != 0) {
|
|
|
|
|
|
|
|
|
if (0 != remove(StatusFile.c_str())) { // Delete the status file.
|
|
|
|
|
|
|
|
|
|
|
|
if (ENOENT != errno) { // No error if the file doesn't exist.
|
|
|
|
|
|
std::ostringstream Temp;
|
|
|
|
|
|
|
|
|
|
|
|
Temp << "Unable to remove rulebase download status file " << StatusFile
|
|
|
|
|
|
<< ": " << strerror(errno) << "\n";
|
|
|
|
|
|
|
|
|
|
|
|
throw runtime_error(Temp.str());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (std::system(Command.c_str()) != 0) { // Download the rulebase.
|
|
|
string Temp;
|
|
|
string Temp;
|
|
|
|
|
|
|
|
|
Temp = "Error running the command '" + Command;
|
|
|
Temp = "Error running the command '" + Command;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ifstream Input;
|
|
|
|
|
|
|
|
|
|
|
|
Input.open(StatusFile.c_str()); // Check the status.
|
|
|
|
|
|
if (!Input) {
|
|
|
|
|
|
string Temp;
|
|
|
|
|
|
|
|
|
|
|
|
Temp = "Error opening rulebase download scriptstatus file " + StatusFile;
|
|
|
|
|
|
Temp += ": ";
|
|
|
|
|
|
Temp += strerror(errno);
|
|
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string Line;
|
|
|
|
|
|
string PrevLine;
|
|
|
|
|
|
string Content;
|
|
|
|
|
|
|
|
|
|
|
|
while (getline(Input, Line)) { // Read the last line.
|
|
|
|
|
|
|
|
|
|
|
|
PrevLine = Line;
|
|
|
|
|
|
Content += Line + "\n";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (PrevLine.find(SuccessKey) == std::string::npos) { // Check the status.
|
|
|
|
|
|
string Temp;
|
|
|
|
|
|
|
|
|
|
|
|
Temp = "Error downloading the rulebase. Rulebase download status:\n\n" + Content;
|
|
|
|
|
|
throw runtime_error(Temp);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
OutputVerboseEnd();
|