git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@16 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
/// Help command-line input. | /// Help command-line input. | ||||
const string HelpKey("-h"); | 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. | /// Configuration file command-line input. | ||||
const string ConfigFileKey("-config="); | const string ConfigFileKey("-config="); | ||||
SetExplain(false); | SetExplain(false); | ||||
SetVerbose(false); | SetVerbose(false); | ||||
SetHelp(false); | SetHelp(false); | ||||
SetSetupRepair(false); | |||||
SetStartSniffer(false); | |||||
SetStopSniffer(false); | |||||
} | } | ||||
SetHelp(true); | 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) { | } else if (OneInput == ConfigFileKey) { | ||||
SetConfigFileName(OneInput.substr(ConfigFileKey.length())); | SetConfigFileName(OneInput.substr(ConfigFileKey.length())); | ||||
return Desc; | 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; | |||||
} | |||||
public: | public: | ||||
/// Enumeration describing the running status of the Sniffer application. | |||||
enum SnifferRunningStatue { | |||||
/// Running status of the Sniffer application. | |||||
enum SnifferRunningStateEnum { | |||||
SnifferIsRunning, ///< OpenBSD OS. | SnifferIsRunning, ///< OpenBSD OS. | ||||
SnifferIsStopped, ///< FreeBSD OS. | SnifferIsStopped, ///< FreeBSD OS. | ||||
SnifferRunningStatusIsUknown ///< Ubuntu and variants. | SnifferRunningStatusIsUknown ///< Ubuntu and variants. | ||||
/// Output the description of the legal command-line input. | /// Output the description of the legal command-line input. | ||||
std::string HelpDescription(); | 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: | private: | ||||
/// Update the credentials of an existing rulebase script. | /// Update the credentials of an existing rulebase script. | ||||
// This is either Windows or the value specified for | // This is either Windows or the value specified for | ||||
// --enable-os-type when configuring for *nix. | // --enable-os-type when configuring for *nix. | ||||
static const std::string OperatingSystemType; | 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 | #endif |
int NumCommandsFound = 0; | int NumCommandsFound = 0; | ||||
string OneInput; | 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. | for (i = 1; i < argc; i++) { // Check each input. | ||||
OneInput = argv[i]; | OneInput = argv[i]; | ||||
if (OneInput == IntegrateWithNoneKey) { | |||||
if (OneInput == IntegrateWithPostfixKey) { | |||||
MtaCommand = IntegrateWithNoneCmd; | |||||
Command = IntegrateWithPostfixCommand; | |||||
NumCommandsFound++; | NumCommandsFound++; | ||||
} else if (OneInput == IntegrateWithPostfixKey) { | |||||
} else if (0 == OneInput.find(IntegrateWithSendmailKey)) { | |||||
MtaCommand = IntegrateWithPostfixCmd; | |||||
Command = IntegrateWithSendmailCommand; | |||||
NumCommandsFound++; | NumCommandsFound++; | ||||
} else if (0 == OneInput.find(IntegrateWithSendmailKey)) { | |||||
} else if (OneInput == IntegrateWithNoneKey) { | |||||
MtaCommand = IntegrateWithSendmailCmd; | |||||
Command = IntegrateWithNoneCommand; | |||||
NumCommandsFound++; | NumCommandsFound++; | ||||
} else { | } else { | ||||
// Process command-line input by the base class. | // Process command-line input by the base class. | ||||
if (!ProcessCommandLineItem(OneInput)) { | if (!ProcessCommandLineItem(OneInput)) { | ||||
Command = UnknownCommand; | |||||
return false; // Illegal input. | return false; // Illegal input. | ||||
} | } | ||||
} | } | ||||
if (UpdateCredentialsSpecified()) { | |||||
Command = UpdateCredentialsCommand; | |||||
NumCommandsfound++; | |||||
} | |||||
if (SetupRepairSpecified()) { | |||||
Command = SetupRepairCommand; | |||||
NumCommandsFound++; | |||||
} | |||||
if (StartSnifferSpecified()) { | |||||
Command = StartSnifferCommand; | |||||
NumCommandsFound++; | |||||
} | |||||
if (StopSnifferSpecified()) { | |||||
Command = StopSnifferCommand; | |||||
NumCommandsFound++; | |||||
} | |||||
return (NumCommandsFound == 1); | return (NumCommandsFound == 1); | ||||
} | } | ||||
void | void | ||||
SNFMilterConfig::DoIntegrationCommand() { | SNFMilterConfig::DoIntegrationCommand() { | ||||
switch (MtaCommand) { | |||||
switch (Command) { | |||||
case NoCommand: | case NoCommand: | ||||
break; | break; | ||||
ostringstream Temp; | ostringstream Temp; | ||||
Temp << "Internal error in SNFMilterConfig::DoIntegrationCommand: Invalid value of command: " | Temp << "Internal error in SNFMilterConfig::DoIntegrationCommand: Invalid value of command: " | ||||
<< MtaCommand; | |||||
<< Command; | |||||
throw runtime_error(Temp.str()); | throw runtime_error(Temp.str()); | ||||
public: | 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. | /// Display usage. | ||||
// | // | ||||
void UnintegrateWithAllExcept(std::string Except = ""); | void UnintegrateWithAllExcept(std::string Except = ""); | ||||
MtaCommandEnum MtaCommand; ///< Specified MTA integration/unintegration command. | |||||
CommandEnum Command; ///< Specified command. | |||||
static const std::string DefaultConfigFile; ///< Default config file. | static const std::string DefaultConfigFile; ///< Default config file. | ||||