git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@16 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
@@ -99,6 +99,18 @@ const string ExplainKey("-explain"); | |||
/// Help command-line input. | |||
const string HelpKey("-h"); | |||
/// Setup command-line input. | |||
const string SetupKey("-setup"); | |||
/// Repair command-line input. | |||
const string RepairKey("-repair"); | |||
/// Start sniffer command-line input. | |||
const string StartSnifferKey("-start"); | |||
/// Stop sniffer command-line input. | |||
const string StopSnifferKey("-stop"); | |||
/// Configuration file command-line input. | |||
const string ConfigFileKey("-config="); | |||
@@ -130,6 +142,9 @@ UtilityConfig::UtilityConfig() : | |||
SetExplain(false); | |||
SetVerbose(false); | |||
SetHelp(false); | |||
SetSetupRepair(false); | |||
SetStartSniffer(false); | |||
SetStopSniffer(false); | |||
} | |||
@@ -835,6 +850,22 @@ UtilityConfig::ProcessCommandLineItem(std::string OneInput) { | |||
SetHelp(true); | |||
} else if (OneInput == SetupKey) { | |||
SetSetupRepair(true); | |||
} else if (OneInput == RepairKey) { | |||
SetSetupRepair(true); | |||
} else if (OneInput == StartSnifferKey) { | |||
SetStartSniffer(true); | |||
} else if (OneInput == StopSnifferKey) { | |||
SetStopSniffer(true); | |||
} else if (OneInput == ConfigFileKey) { | |||
SetConfigFileName(OneInput.substr(ConfigFileKey.length())); | |||
@@ -903,3 +934,47 @@ UtilityConfig::HelpDescription() { | |||
return Desc; | |||
} | |||
void | |||
UtilityConfig::SetSetupRepair(bool Specified) { | |||
SetupRepairRequested = Specified; | |||
} | |||
bool | |||
UtilityConfig::SetupRepairSpecified() { | |||
return SetupRepairRequested; | |||
} | |||
void | |||
UtilityConfig::SetStartSniffer(bool Specified) { | |||
StartSnifferRequested = Specified; | |||
} | |||
bool | |||
UtilityConfig::StartSnifferSpecified() { | |||
return StartSnifferRequested; | |||
} | |||
void | |||
UtilityConfig::SetStopSniffer(bool Specified) { | |||
StopSnifferRequested = Specified; | |||
} | |||
bool | |||
UtilityConfig::StopSnifferSpecified() { | |||
return StopSnifferRequested; | |||
} | |||
@@ -24,8 +24,8 @@ class UtilityConfig : public Utility { | |||
public: | |||
/// Enumeration describing the running status of the Sniffer application. | |||
enum SnifferRunningStatue { | |||
/// Running status of the Sniffer application. | |||
enum SnifferRunningStateEnum { | |||
SnifferIsRunning, ///< OpenBSD OS. | |||
SnifferIsStopped, ///< FreeBSD OS. | |||
SnifferRunningStatusIsUknown ///< Ubuntu and variants. | |||
@@ -269,6 +269,42 @@ public: | |||
/// Output the description of the legal command-line input. | |||
std::string HelpDescription(); | |||
/// Store whether the setup/help command was specified. | |||
// | |||
// \param[in] Specified specifies whether the command was specified. | |||
// | |||
void SetSetupRepair(bool Specified); | |||
/// Setup/repair specified? | |||
// | |||
// \returns true if the setup/help command was specified on the command line. | |||
// | |||
bool SetupRepairSpecified(); | |||
/// Store whether the start sniffer command was specified. | |||
// | |||
// \param[in] Specified specifies whether the command was specified. | |||
// | |||
void SetStartSniffer(bool Specified); | |||
/// Start sniffer specified? | |||
// | |||
// \returns true if the start sniffer command was specified on the command line. | |||
// | |||
bool StartSnifferSpecified(); | |||
/// Store whether the stop sniffer command was specified. | |||
// | |||
// \param[in] Specified specifies whether the command was specified. | |||
// | |||
void SetStopSniffer(bool Specified); | |||
/// Stop sniffer specified? | |||
// | |||
// \returns true if the stop sniffer command was specified on the command line. | |||
// | |||
bool StopSnifferSpecified(); | |||
private: | |||
/// Update the credentials of an existing rulebase script. | |||
@@ -302,6 +338,11 @@ private: | |||
// This is either Windows or the value specified for | |||
// --enable-os-type when configuring for *nix. | |||
static const std::string OperatingSystemType; | |||
bool SetupRepairRequested; ///< User requested setup/repair. | |||
bool StartSnifferRequested; ///< User requested that Sniffer be started. | |||
bool StopSnifferRequested; ///< User requested that Sniffer be stopped. | |||
}; | |||
#endif |
@@ -105,25 +105,25 @@ SNFMilterConfig::GetCommandLineInput(int argc, char* argv[]) { | |||
int NumCommandsFound = 0; | |||
string OneInput; | |||
MtaCommand = NoCommand; // Default is to do nothing. | |||
Command = NoCommand; // Default is to do nothing. | |||
for (i = 1; i < argc; i++) { // Check each input. | |||
OneInput = argv[i]; | |||
if (OneInput == IntegrateWithNoneKey) { | |||
if (OneInput == IntegrateWithPostfixKey) { | |||
MtaCommand = IntegrateWithNoneCmd; | |||
Command = IntegrateWithPostfixCommand; | |||
NumCommandsFound++; | |||
} else if (OneInput == IntegrateWithPostfixKey) { | |||
} else if (0 == OneInput.find(IntegrateWithSendmailKey)) { | |||
MtaCommand = IntegrateWithPostfixCmd; | |||
Command = IntegrateWithSendmailCommand; | |||
NumCommandsFound++; | |||
} else if (0 == OneInput.find(IntegrateWithSendmailKey)) { | |||
} else if (OneInput == IntegrateWithNoneKey) { | |||
MtaCommand = IntegrateWithSendmailCmd; | |||
Command = IntegrateWithNoneCommand; | |||
NumCommandsFound++; | |||
} else { | |||
@@ -131,6 +131,7 @@ SNFMilterConfig::GetCommandLineInput(int argc, char* argv[]) { | |||
// Process command-line input by the base class. | |||
if (!ProcessCommandLineItem(OneInput)) { | |||
Command = UnknownCommand; | |||
return false; // Illegal input. | |||
} | |||
@@ -139,6 +140,34 @@ SNFMilterConfig::GetCommandLineInput(int argc, char* argv[]) { | |||
} | |||
if (UpdateCredentialsSpecified()) { | |||
Command = UpdateCredentialsCommand; | |||
NumCommandsfound++; | |||
} | |||
if (SetupRepairSpecified()) { | |||
Command = SetupRepairCommand; | |||
NumCommandsFound++; | |||
} | |||
if (StartSnifferSpecified()) { | |||
Command = StartSnifferCommand; | |||
NumCommandsFound++; | |||
} | |||
if (StopSnifferSpecified()) { | |||
Command = StopSnifferCommand; | |||
NumCommandsFound++; | |||
} | |||
return (NumCommandsFound == 1); | |||
} | |||
@@ -249,7 +278,7 @@ SNFMilterConfig::UpdateConfigFiles() { | |||
void | |||
SNFMilterConfig::DoIntegrationCommand() { | |||
switch (MtaCommand) { | |||
switch (Command) { | |||
case NoCommand: | |||
break; | |||
@@ -274,7 +303,7 @@ SNFMilterConfig::DoIntegrationCommand() { | |||
ostringstream Temp; | |||
Temp << "Internal error in SNFMilterConfig::DoIntegrationCommand: Invalid value of command: " | |||
<< MtaCommand; | |||
<< Command; | |||
throw runtime_error(Temp.str()); | |||
@@ -27,12 +27,17 @@ class SNFMilterConfig : public UtilityConfig { | |||
public: | |||
/// Command. | |||
enum MtaCommandEnum { | |||
NoCommand, ///< Take no MTA integration/unintegration action. | |||
IntegrateWithNoneCmd, ///< Remove integration with all MTAs. | |||
IntegrateWithPostfixCmd, ///< Integrate with postfix. | |||
IntegrateWithSendmailCmd ///< Integrate with sendmail. | |||
/// Command specified. | |||
enum CommandEnum { | |||
SetupRepairCommand, ///< Setup or repair the configuration. | |||
IntegrateWithPostfixCommand, ///< Integrate with postfix. | |||
IntegrateWithSendmailCommand, ///< Integrate with sendmail. | |||
IntegrateWithNoneCommand, ///< Unintegrate with all supported MTAs. | |||
UpdateCredentialsCommand, ///< Update the credentials. | |||
StartSnifferCommand, ///< Start the Sniffer. | |||
StopSnifferCommand, ///< Stop the Sniffer. | |||
NoCommand, ///< No command specified. | |||
UnknownCommand ///< Unknown. | |||
}; | |||
/// Display usage. | |||
@@ -111,7 +116,7 @@ private: | |||
// | |||
void UnintegrateWithAllExcept(std::string Except = ""); | |||
MtaCommandEnum MtaCommand; ///< Specified MTA integration/unintegration command. | |||
CommandEnum Command; ///< Specified command. | |||
static const std::string DefaultConfigFile; ///< Default config file. | |||