Browse Source

Check the getRulebase.status file for successful rulebase download.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@10 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 years ago
parent
commit
7eef0153be
2 changed files with 72 additions and 1 deletions
  1. 71
    1
      Common/UtilityConfig.cpp
  2. 1
    0
      Common/UtilityConfig.hpp

+ 71
- 1
Common/UtilityConfig.cpp View File

@@ -35,6 +35,8 @@ const std::string UtilityConfig::SampleIgnoreListFile("C:\\SNF\\GBUdbIgnoreList.
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 SnifferPathKey("FIX THIS"); ///< Text to replace with directory of the rulebase.
@@ -54,6 +56,9 @@ const std::string UtilityConfig::RulebaseDownloadCommand
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.
// SNIFFER_PATH is replaced with the path of the rulebase.
const std::string UtilityConfig::RulebaseDownloadStatusFile("SNIFFER_PATH/getRulebase.status");
#ifdef DEFAULT_DATA_DIR
// *nix, DEFAULT_DATA_DIR is specified on the compile command line.
const std::string UtilityConfig::SampleIgnoreListFile(DEFAULT_DATA_DIR "/GBUdbIgnoreList.txt.sample");
@@ -103,6 +108,14 @@ const string LicenseIdKey("-id=");
/// Authentication command-line input.
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 AuthSearchString = "AUTHENTICATION=";
@@ -607,6 +620,7 @@ UtilityConfig::DownloadRulebase() {
if (Verbose()) {
std::cout << "Downloading the rulebase...";
std::cout.flush();
}
@@ -630,10 +644,35 @@ UtilityConfig::DownloadRulebase() {
}
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 (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;
Temp = "Error running the command '" + Command;
@@ -642,6 +681,37 @@ UtilityConfig::DownloadRulebase() {
}
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();

+ 1
- 0
Common/UtilityConfig.hpp View File

@@ -266,6 +266,7 @@ private:
bool AuthenticationIsSpecified; ///< true if the Authentication was specified on the command line.
static const std::string RulebaseDownloadCommand; ///< Command to download the rulebase.
static const std::string RulebaseDownloadStatusFile; ///< Status file for rulebase download status.
static const std::string SampleIgnoreListFile; ///< Sample ignore list file.
static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file.

Loading…
Cancel
Save