Przeglądaj źródła

Implement UtilityConfig::StartSniffer().


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@12 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 lat temu
rodzic
commit
4e7ee39b87
3 zmienionych plików z 88 dodań i 4 usunięć
  1. 37
    0
      Common/UtilityConfig.cpp
  2. 24
    0
      Common/UtilityConfig.hpp
  3. 27
    4
      SNFMilterConfig/main.cpp

+ 37
- 0
Common/UtilityConfig.cpp Wyświetl plik

@@ -366,26 +366,31 @@ UtilityConfig::LoadInfo(){
PostfixMainCfPath = "/usr/local/etc/postfix/main.cf";
PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf";
SnifferStartScriptDir = "/usr/local/sbin/";
} else if ("FreeBSD" == OperatingSystemType) {
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
SnifferStartScriptDir = "/usr/local/etc/rc.d/";
} else if ("Ubuntu" == OperatingSystemType) {
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
SnifferStartScriptDir = "/etc/init.d/";
} else if ("RedHat" == OperatingSystemType) {
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
SnifferStartScriptDir = "/etc/init.d/";
} else if ("Suse" == OperatingSystemType) {
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
SnifferStartScriptDir = "/etc/init.d/";
} else {
@@ -780,6 +785,38 @@ UtilityConfig::UpdateIdentityFile() {
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
UtilityConfig::ProcessCommandLineItem(std::string OneInput) {

+ 24
- 0
Common/UtilityConfig.hpp Wyświetl plik

@@ -24,6 +24,13 @@ class UtilityConfig : public Utility {
public:
/// Enumeration describing the running status of the Sniffer application.
enum SnifferRunningStatue {
SnifferIsRunning, ///< OpenBSD OS.
SnifferIsStopped, ///< FreeBSD OS.
SnifferRunningStatusIsUknown ///< Ubuntu and variants.
};
/// Default constructor.
UtilityConfig();
@@ -165,6 +172,9 @@ public:
/// Postfix master.cf file path.
std::string PostfixMasterCfPath;
/// Directory containing the Sniffer start script.
std::string SnifferStartScriptDir;
/// Create or update the ignore list file.
//
// The ignore list file is created if it dosn't exist. In any
@@ -223,6 +233,20 @@ public:
//
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.
//
// \param[in] OneInput is the command-line item to process.

+ 27
- 4
SNFMilterConfig/main.cpp Wyświetl plik

@@ -82,11 +82,19 @@ int main(int argc, char* argv[]) {
try { // Catch anything that breaks loose.
#if 0
SnifferRunningStatue RunningStatus;
#endif
SnfMilterConfig.CreateLoadConfig(); // Save config file state and load config.
// Load the default if necessary.
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.CreateUpdateRulebaseScript(); // Create/update GetRulebase.
@@ -98,19 +106,34 @@ int main(int argc, char* argv[]) {
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.
catch(exception& e) { // Report any normal exceptions.
cerr << "SNFMilterConfig Exception: " << e.what() << endl;
cerr << "\n\nSNFMilterConfig Exception: " << e.what() << endl << endl;
RestoreFiles(&SnfMilterConfig);
}
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);
}
catch(...) { // Report any unexpected exceptions.
cerr << "SNFMilterConfig Panic! Unknown Exception!" << endl;
cerr << "\n\nSNFMilterConfig Panic! Unknown Exception!" << endl << endl;
RestoreFiles(&SnfMilterConfig);
}

Ładowanie…
Anuluj
Zapisz