git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@12 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
PostfixMainCfPath = "/usr/local/etc/postfix/main.cf"; | PostfixMainCfPath = "/usr/local/etc/postfix/main.cf"; | ||||
PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf"; | PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf"; | ||||
SnifferStartScriptDir = "/usr/local/sbin/"; | |||||
} else if ("FreeBSD" == OperatingSystemType) { | } else if ("FreeBSD" == OperatingSystemType) { | ||||
PostfixMainCfPath = "/etc/postfix/main.cf"; | PostfixMainCfPath = "/etc/postfix/main.cf"; | ||||
PostfixMasterCfPath = "/etc/postfix/master.cf"; | PostfixMasterCfPath = "/etc/postfix/master.cf"; | ||||
SnifferStartScriptDir = "/usr/local/etc/rc.d/"; | |||||
} else if ("Ubuntu" == OperatingSystemType) { | } else if ("Ubuntu" == OperatingSystemType) { | ||||
PostfixMainCfPath = "/etc/postfix/main.cf"; | PostfixMainCfPath = "/etc/postfix/main.cf"; | ||||
PostfixMasterCfPath = "/etc/postfix/master.cf"; | PostfixMasterCfPath = "/etc/postfix/master.cf"; | ||||
SnifferStartScriptDir = "/etc/init.d/"; | |||||
} else if ("RedHat" == OperatingSystemType) { | } else if ("RedHat" == OperatingSystemType) { | ||||
PostfixMainCfPath = "/etc/postfix/main.cf"; | PostfixMainCfPath = "/etc/postfix/main.cf"; | ||||
PostfixMasterCfPath = "/etc/postfix/master.cf"; | PostfixMasterCfPath = "/etc/postfix/master.cf"; | ||||
SnifferStartScriptDir = "/etc/init.d/"; | |||||
} else if ("Suse" == OperatingSystemType) { | } else if ("Suse" == OperatingSystemType) { | ||||
PostfixMainCfPath = "/etc/postfix/main.cf"; | PostfixMainCfPath = "/etc/postfix/main.cf"; | ||||
PostfixMasterCfPath = "/etc/postfix/master.cf"; | PostfixMasterCfPath = "/etc/postfix/master.cf"; | ||||
SnifferStartScriptDir = "/etc/init.d/"; | |||||
} else { | } else { | ||||
SetMode(File, S_IRUSR); // Set to readonly by owner. | SetMode(File, S_IRUSR); // Set to readonly by owner. | ||||
} | } | ||||
void | |||||
UtilityConfig::StartSniffer(std::string Script) { | |||||
std::string Command; | |||||
Command = SnifferStartScriptDir + Script; | |||||
Command += " start"; | |||||
if (Verbose()) { | |||||
cout << "Starting Sniffer with the command '" << Command << "'..."; | |||||
} | |||||
if (!Explain()) { | |||||
if (std::system(Command.c_str()) == -1) { // Start the sniffer. | |||||
string Temp; | |||||
Temp = "Error running the command '" + Command; | |||||
Temp += "' to start the Sniffer: "; | |||||
Temp += strerror(errno); | |||||
throw runtime_error(Temp); | |||||
} | |||||
} | |||||
OutputVerboseEnd(); | |||||
} | |||||
bool | bool | ||||
UtilityConfig::ProcessCommandLineItem(std::string OneInput) { | UtilityConfig::ProcessCommandLineItem(std::string OneInput) { | ||||
public: | public: | ||||
/// Enumeration describing the running status of the Sniffer application. | |||||
enum SnifferRunningStatue { | |||||
SnifferIsRunning, ///< OpenBSD OS. | |||||
SnifferIsStopped, ///< FreeBSD OS. | |||||
SnifferRunningStatusIsUknown ///< Ubuntu and variants. | |||||
}; | |||||
/// Default constructor. | /// Default constructor. | ||||
UtilityConfig(); | UtilityConfig(); | ||||
/// Postfix master.cf file path. | /// Postfix master.cf file path. | ||||
std::string PostfixMasterCfPath; | std::string PostfixMasterCfPath; | ||||
/// Directory containing the Sniffer start script. | |||||
std::string SnifferStartScriptDir; | |||||
/// Create or update the ignore list file. | /// Create or update the ignore list file. | ||||
// | // | ||||
// The ignore list file is created if it dosn't exist. In any | // The ignore list file is created if it dosn't exist. In any | ||||
// | // | ||||
void UpdateIdentityFile(void); | void UpdateIdentityFile(void); | ||||
/// Start the sniffer. | |||||
// | |||||
// This method runs the specified sniffer start script in the | |||||
// appropriate (i.e. OS-dependent) directory. The script is | |||||
// prepended with the directory, and run with an argument of | |||||
// "start". | |||||
// | |||||
// \param[in] Script is the name of the start script. | |||||
// | |||||
// \pre LoadInfo() must have been called. That method initializes | |||||
// the directory the script resides in. | |||||
// | |||||
void StartSniffer(std::string Script); | |||||
/// Process one command-line item. | /// Process one command-line item. | ||||
// | // | ||||
// \param[in] OneInput is the command-line item to process. | // \param[in] OneInput is the command-line item to process. |
try { // Catch anything that breaks loose. | try { // Catch anything that breaks loose. | ||||
#if 0 | |||||
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. | ||||
SnfMilterConfig.SaveFileState(); // Save state of all other files. | SnfMilterConfig.SaveFileState(); // Save state of all other files. | ||||
#if 0 | |||||
RunningStatus = SnfMilterConfig.GetSnifferRunningStatus(); // Get state before changing anything. | |||||
#endif | |||||
SnfMilterConfig.UpdateConfigFiles(); // Create/update config files | SnfMilterConfig.UpdateConfigFiles(); // Create/update config files | ||||
SnfMilterConfig.CreateUpdateRulebaseScript(); // Create/update GetRulebase. | SnfMilterConfig.CreateUpdateRulebaseScript(); // Create/update GetRulebase. | ||||
SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate. | SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate. | ||||
#if 0 | |||||
if (SnifferIsStopped == RunningStatus) { | |||||
SnfMilterConfig.StartSniffer(); | |||||
} else if (SnifferRunningStatusIsUknown == RunningStatus) { | |||||
std::cout << "SNFMilterConfig: Unable to determine whether SNFMilter is running.\n" | |||||
<< "Please start SNFMilter if it isn't running.\n"; | |||||
} | |||||
#else | |||||
SnfMilterConfig.StartSniffer("snf-milter"); | |||||
#endif | |||||
} // That's all folks. | } // That's all folks. | ||||
catch(exception& e) { // Report any normal exceptions. | catch(exception& e) { // Report any normal exceptions. | ||||
cerr << "SNFMilterConfig Exception: " << e.what() << endl; | |||||
cerr << "\n\nSNFMilterConfig Exception: " << e.what() << endl << endl; | |||||
RestoreFiles(&SnfMilterConfig); | RestoreFiles(&SnfMilterConfig); | ||||
} | } | ||||
catch (snfCFGmgr::LoadFailure) { // Error loading configuration file. | catch (snfCFGmgr::LoadFailure) { // Error loading configuration file. | ||||
cerr << "snfCFGmgr Exception: Unable to load the configuration file " | |||||
<< SnfMilterConfig.GetConfigFileName() << endl; | |||||
cerr << "\n\nsnfCFGmgr Exception: Unable to load the configuration file " | |||||
<< SnfMilterConfig.GetConfigFileName() << endl << endl; | |||||
RestoreFiles(&SnfMilterConfig); | RestoreFiles(&SnfMilterConfig); | ||||
} | } | ||||
catch(...) { // Report any unexpected exceptions. | catch(...) { // Report any unexpected exceptions. | ||||
cerr << "SNFMilterConfig Panic! Unknown Exception!" << endl; | |||||
cerr << "\n\nSNFMilterConfig Panic! Unknown Exception!" << endl << endl; | |||||
RestoreFiles(&SnfMilterConfig); | RestoreFiles(&SnfMilterConfig); | ||||
} | } | ||||