Browse Source

Tested SetupRepair() functionality.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@18 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 years ago
parent
commit
796a1c243c

+ 18
- 13
Common/UtilityConfig.cpp View File

void void
UtilityConfig::SetupRepairIgnoreListFile() { UtilityConfig::SetupRepairIgnoreListFile() {
string IgnoreListFile = GetIgnoreListFileName();
string File = GetIgnoreListFileName();
if (!FileExists(IgnoreListFile)) {
if (!FileExists(File)) {
if (!Explain()) { if (!Explain()) {
} }
Copy(SampleIgnoreListFile, IgnoreListFile);
Copy(SampleIgnoreListFile, File);
} }
SetMode(IgnoreListFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // Set permissions.
SetOwnerGroup(IgnoreListFile); // Set to sniffer user.
SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // Set permissions.
SetOwnerGroup(File); // Set to sniffer user.
} }
} }
void void
SNFMilterConfig::SetupRepair(std::string SampleIdentityFile) {
UtilityConfig::SetupRepair(const std::string SampleIdentityFile) {
SetupRepairIdentityFile(SampleIdentityFile); SetupRepairIdentityFile(SampleIdentityFile);
SetupRepairRulebaseScript(); SetupRepairRulebaseScript();
throw runtime_error(Temp); throw runtime_error(Temp);
} }
string Content = InputContent.str();
string Content = InputContents.str();
try { try {
ReplaceXmlAttribute(&Content, IdentityElementName, LicenseAttributeName, LicenseId); ReplaceXmlAttribute(&Content, IdentityElementName, LicenseAttributeName, LicenseId);
ReplaceXmlAttribute(&Content, IdentityElementName, AuthenticationAtributeName, Authentication);
ReplaceXmlAttribute(&Content, IdentityElementName, AuthenticationAttributeName, Authentication);
} catch (std::exception &e) { } catch (std::exception &e) {
std::string Temp; std::string Temp;
Temp = "Error updating credentials for identity file " + File; Temp = "Error updating credentials for identity file " + File;
Temp += ": " + e.what();
Temp += ": ";
Temp += e.what();
throw runtime_error(Temp); throw runtime_error(Temp);
} }
std::string Desc; std::string Desc;
Desc = "creates the configuration files (snf-config-file and the\n";
Desc += "ignore list file), the rulebase download script (default: getRulebase) if\n";
Desc += "they don't exist, and also the identity file.\n\n";
Desc = "creates and updates the configuration files (snf-config-file and\n";
Desc += "the ignore list file), the rulebase download script (default: getRulebase),\n";
Desc += "and the identity file if they don't exist.\n\n";
Desc += " -setup Perform initial setup/replace missing files\n";
Desc += " -repair Perform initial setup/replace missing files\n";
Desc += ExclusiveCommandsHelp; Desc += ExclusiveCommandsHelp;
Desc += " -config=snf-config-file Specifies the configuration file\n";
Desc += " -id=licenseid Specifies the license ID\n"; Desc += " -id=licenseid Specifies the license ID\n";
Desc += " -auth=authentication Specifies the Authentication\n"; Desc += " -auth=authentication Specifies the Authentication\n";
Desc += " -start Start the sniffer\n";
Desc += " -stop Stop the sniffer\n";
Desc += " -config=snf-config-file Specifies the configuration file\n";
Desc += " -v Provide verbose output\n"; Desc += " -v Provide verbose output\n";
Desc += " -explain Provide an explaination of the actions\n"; Desc += " -explain Provide an explaination of the actions\n";
Desc += " without executing any commands\n"; Desc += " without executing any commands\n";

+ 18
- 0
Common/UtilityConfig.hpp View File

/// Directory containing the Sniffer start script. /// Directory containing the Sniffer start script.
std::string SnifferStartScriptDir; std::string SnifferStartScriptDir;
/// Setup/repair the configuration.
//
// Copy the following files from the sample files if they don't
// exist:
//
// <ol>
// <li> Identity file. </li>
// <li> Ignore list file. </li>
// <li> Rulebase script. </li>
// </ol>
//
// Set the owner/group of each of the above files.
//
// Make sure that the log directory exists and has the correct
// owner and permissions.
//
void SetupRepair(const std::string SampleIdentityFile);
/// Update the rulebase script credentials. /// Update the rulebase script credentials.
// //
// This method updates the rulebase with the credentials specified // This method updates the rulebase with the credentials specified

+ 6
- 9
SNFMilterConfig/SNFMilterConfig.cpp View File

ExclusiveCommands += IntegrateWithSendmailKey + " | "; ExclusiveCommands += IntegrateWithSendmailKey + " | ";
ExclusiveCommands += IntegrateWithNoneKey; ExclusiveCommands += IntegrateWithNoneKey;
ExclusiveCommandsHelp = " -mta=postfix Integrate with postfix\n";
ExclusiveCommandsHelp += " -mta=sendmail Integrate with sendmail\n";
ExclusiveCommandsHelp = " -mta=postfix Integrate with postfix and start/reload postfix\n";
ExclusiveCommandsHelp += " -mta=sendmail Integrate with sendmail and start/reload sendmail\n";
ExclusiveCommandsHelp += " -mta=none Remove any integration with all supported MTAs\n"; ExclusiveCommandsHelp += " -mta=none Remove any integration with all supported MTAs\n";
cout cout
<< " " << DefaultConfigFile << "\n\n" << " " << DefaultConfigFile << "\n\n"
<< "If snf-config-file is not specified and the above file doesn't exist, then it is\n" << "If snf-config-file is not specified and the above file doesn't exist, then it is\n"
<< "copied from the following file:\n\n" << "copied from the following file:\n\n"
<< " " << SampleConfigFile << "\n\n";
<< " " << SampleConfigFile << "\n\n"
<< "If integration with an MTA is specified, that MTA is started if it isn't running,\n"
<< "or the MTA's configuration is reloaded if it is running.\n\n";
}; };
#if 0 #if 0
SnifferRunningStatue RunningStatus; SnifferRunningStatue RunningStatus;
#endif
SnfMilterConfig.CreateLoadConfig(); // Save config file state and load config. SnfMilterConfig.CreateLoadConfig(); // Save config file state and load config.
// Load the default if necessary. // Load the default if necessary.
#if 0
SnfMilterConfig.SaveFileState(); // Save state of all other files. SnfMilterConfig.SaveFileState(); // Save state of all other files.
RunningStatus = SnfMilterConfig.GetSnifferRunningStatus(); // Get state before changing anything. RunningStatus = SnfMilterConfig.GetSnifferRunningStatus(); // Get state before changing anything.
#endif
SnfMilterConfig.UpdateConfigFiles(); // Create/update config files SnfMilterConfig.UpdateConfigFiles(); // Create/update config files
SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate. SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate.
#if 0
if (SnifferIsStopped == RunningStatus) { if (SnifferIsStopped == RunningStatus) {
SnfMilterConfig.StartSniffer(); SnfMilterConfig.StartSniffer();
<< "Please start SNFMilter if it isn't running.\n"; << "Please start SNFMilter if it isn't running.\n";
} }
#else
SnfMilterConfig.StartSniffer("snf-milter");
#endif #endif
} }

+ 5
- 19
SNFMilterConfig/SNFMilterConfig.hpp View File

// //
void SaveFileState(void); // OBSOLETE. void SaveFileState(void); // OBSOLETE.
/// Setup/repair the configuration.
//
// Copy the following files from the sample files if they don't
// exist:
//
// <ol>
// <li> Identity file. </li>
// <li> Ignore list file. </li>
// <li> Rulebase script. </li>
// </ol>
//
// Set the owner/group of each of the above files.
//
// Make sure that the log directory exists and has the correct
// owner and permissions.
//
void SetupRepair();
/// Execute the command to integrate/unintegrate with the MTAs. /// Execute the command to integrate/unintegrate with the MTAs.
void DoIntegrationCommand(); void DoIntegrationCommand();
/// of the loaded config file. /// of the loaded config file.
void LoadSocketInfo(); void LoadSocketInfo();
void CreateSocketDir();
/// Setup/repair the directory containing the milter socket.
//
// This method ensures that the directore to contain the milter
// socket exists and has the correct owner and permissions.
void SetupRepairSocketDir();
PostfixIntegrate Postfix; ///< Postfix integration object. PostfixIntegrate Postfix; ///< Postfix integration object.

Loading…
Cancel
Save