git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@29 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
void | void | ||||
PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) { | PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) { | ||||
MtaIsRunningCommand = "ps -axl root | grep -v grep | grep -q 'postfix/master'"; | |||||
MtaIsRunningCommand = "ps axl | grep -v grep | grep -q 'postfix/master'"; | |||||
if ("OpenBSD" == OperatingSystemType) { | if ("OpenBSD" == OperatingSystemType) { | ||||
throw std::runtime_error(Temp); | throw std::runtime_error(Temp); | ||||
} | } | ||||
} | |||||
OutputVerboseEnd(); | |||||
if (!Explain()) { | |||||
if (MtaIsRunningDetected()) { | if (MtaIsRunningDetected()) { | ||||
ReloadMta(); | ReloadMta(); | ||||
} | } | ||||
OutputVerboseEnd(); | |||||
} | } | ||||
void | void | ||||
} | } | ||||
} | |||||
OutputVerboseEnd(); | |||||
if (!Explain()) { | |||||
if (MtaIsRunningDetected()) { | if (MtaIsRunningDetected()) { | ||||
ReloadMta(); | ReloadMta(); | ||||
} | } | ||||
OutputVerboseEnd(); | |||||
} | } | ||||
bool | bool | ||||
if (Verbose()) { | if (Verbose()) { | ||||
std::cout << (IsRunningDetected ? "yes" : "no"); | |||||
std::cout << (IsRunningDetected ? "yes..." : "no..."); | |||||
} | } | ||||
if (Verbose()) { | if (Verbose()) { | ||||
std::cout << "Reloading postfix..."; | |||||
std::cout << "Reloading postfix...\n"; | |||||
std::cout.flush(); | |||||
} | } | ||||
bool Failed; | |||||
bool Succeeded; | |||||
if (!Explain()) { | if (!Explain()) { | ||||
Failed = (std::system(ReloadMtaCommand.c_str()) == 0); | |||||
Succeeded = (std::system(ReloadMtaCommand.c_str()) == 0); | |||||
if (Verbose()) { | if (Verbose()) { | ||||
std::cout << (Failed ? "failed..." : "succeeded..."); | |||||
std::cout << (Succeeded ? "succeeded..." : "failed..."); | |||||
} | } | ||||
OutputVerboseEnd(); | OutputVerboseEnd(); | ||||
return !Failed; | |||||
return Succeeded; | |||||
} | } | ||||
Integrated = true; // Found it. | Integrated = true; // Found it. | ||||
if (Verbose()) { | |||||
std::cout << "found '" << Line << "'..."; | |||||
} | |||||
break; | break; | ||||
} | } | ||||
throw std::runtime_error(Temp); | throw std::runtime_error(Temp); | ||||
} | } | ||||
if (Verbose()) { | |||||
if (Integrated) { | |||||
std::cout << "found '" << Line << "'..."; | |||||
} else { | |||||
std::cout << "none found..."; | |||||
} | |||||
} | |||||
OutputVerboseEnd(); | OutputVerboseEnd(); | ||||
return Integrated; | return Integrated; |
const string SNFMilterConfig::ApplicationName("SNFMilter"); | const string SNFMilterConfig::ApplicationName("SNFMilter"); | ||||
const string IntegrateWithNoneKey("-mta=none"); | |||||
const string IntegrateWithPostfixKey("-mta=postfix"); | |||||
const string IntegrateWithSendmailKey("-mta=sendmail"); | |||||
const string IntegrateWithNoneKey("-with=none"); | |||||
const string IntegrateWithPostfixKey("-with=postfix"); | |||||
const string IntegrateWithSendmailKey("-with=sendmail"); | |||||
const string SnfMilterMainCfSearchString("Added by SNFMilterConfig"); | const string SnfMilterMainCfSearchString("Added by SNFMilterConfig"); | ||||
ExclusiveCommands += IntegrateWithSendmailKey + " | "; | ExclusiveCommands += IntegrateWithSendmailKey + " | "; | ||||
ExclusiveCommands += IntegrateWithNoneKey; | ExclusiveCommands += IntegrateWithNoneKey; | ||||
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 = " -with=postfix Integrate with postfix and start/reload postfix\n"; | |||||
ExclusiveCommandsHelp += " -with=sendmail Integrate with sendmail and start/reload sendmail\n"; | |||||
ExclusiveCommandsHelp += " -with=none Remove any integration with all supported MTAs\n"; | |||||
cout | cout | ||||
<< Version << endl | << Version << endl | ||||
void | void | ||||
SNFMilterConfig::ExecuteCommand() { | SNFMilterConfig::ExecuteCommand() { | ||||
switch (Command) { | |||||
Postfix.SetOperatingSystem(GetOperatingSystemType()); | |||||
Postfix.SetVerbose(Verbose()); | |||||
Postfix.SetExplain(Explain()); | |||||
case SetupRepairCommand: | |||||
#if 0 | |||||
Sendmail.SetOperatingSystem(GetOperatingSystemType()); | |||||
Sendmail.SetVerbose(Verbose()); | |||||
Sendmail.SetExplain(Explain()); | |||||
#endif | |||||
SetConfigFileName(DefaultConfigFile); | |||||
if (SetupRepairCommand == Command) { | |||||
SetConfigFileName(DefaultConfigFile); | |||||
CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist, | CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist, | ||||
// Set owner and mode in any case. | // Set owner and mode in any case. | ||||
LoadConfig(); | |||||
LoadInfo(); // Load the file paths. | |||||
LoadSocketInfo(); // Load the socket path. | |||||
} | |||||
LoadConfig(); | |||||
LoadInfo(); // Load the file paths. | |||||
LoadSocketInfo(); // Load the socket path. | |||||
switch (Command) { | |||||
case SetupRepairCommand: | |||||
SetupRepair(SampleIdentityFile); | SetupRepair(SampleIdentityFile); | ||||
SetupRepairSocketDir(); | SetupRepairSocketDir(); | ||||
case UpdateCredentialsCommand: | case UpdateCredentialsCommand: | ||||
SetConfigFileName(DefaultConfigFile); | |||||
LoadConfig(); | |||||
LoadInfo(); // Load the file paths. | |||||
LoadSocketInfo(); // Load the socket path. | |||||
UpdateRulebaseScriptCredentials(); | UpdateRulebaseScriptCredentials(); | ||||
DownloadRulebase(); | DownloadRulebase(); | ||||
UpdateIdentityFile(); | UpdateIdentityFile(); | ||||
break; | break; | ||||
case IntegrateWithPostfixCommand: | case IntegrateWithPostfixCommand: | ||||
UnintegrateWithAllExcept("postfix"); | UnintegrateWithAllExcept("postfix"); | ||||
Postfix.Integrate(&SaveFile); | Postfix.Integrate(&SaveFile); | ||||
break; | break; | ||||
case StartSnifferCommand: | case StartSnifferCommand: | ||||
SetConfigFileName(DefaultConfigFile); | |||||
LoadConfig(); | |||||
LoadInfo(); | |||||
LoadSocketInfo(); | |||||
LoadCredentials(); | LoadCredentials(); | ||||
StartSniffer("snf-milter start", ApplicationName); | StartSniffer("snf-milter start", ApplicationName); | ||||
case StopSnifferCommand: | case StopSnifferCommand: | ||||
SetConfigFileName(DefaultConfigFile); | |||||
LoadConfig(); | |||||
LoadInfo(); | |||||
LoadSocketInfo(); | |||||
LoadCredentials(); | LoadCredentials(); | ||||
StopSniffer("snf-milter stop", ApplicationName); | StopSniffer("snf-milter stop", ApplicationName); |
Integration with postfix | Integration with postfix | ||||
------------------------ | ------------------------ | ||||
POSTFIX-01: Set up the environment as follows: | |||||
POSTFIX-01: On Ubuntu, set up the environment as follows: | |||||
1) Default configuration files for SNFMilter. | 1) Default configuration files for SNFMilter. | ||||
postfix configuration files are not updated, and that both | postfix configuration files are not updated, and that both | ||||
postfix and SNFMilter are stopped. | postfix and SNFMilter are stopped. | ||||
Result: | |||||
Result: Pass. | |||||
POSTFIX-02: Repeat POSTFIX-01 but without "-v". | POSTFIX-02: Repeat POSTFIX-01 but without "-v". | ||||
Result: | |||||
Result: Pass. | |||||
POSTFIX-03: Configure as for POSTFIX-01, and do the following: | POSTFIX-03: Configure as for POSTFIX-01, and do the following: | ||||
output, and that SNFMilterConfig doesn't update the postfix | output, and that SNFMilterConfig doesn't update the postfix | ||||
configuration files or reload any MTA. | configuration files or reload any MTA. | ||||
Result: | |||||
3) Run SNFMilterConfig with "-with=postfix". Verify correct output, | |||||
and that SNFMilterConfig updates the postfix configuration files. | |||||
POSTFIX-04: Set up the environment as follows: | |||||
4) Run SNFMilterConfig with "-with=postfix -explain". Verify | |||||
correct output, and that SNFMilterConfig doesn't update the | |||||
postfix configuration files or reload any MTA. | |||||
5) Run SNFMilterConfig with "-with=none -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't update the postfix | |||||
configuration files or reload any MTA. | |||||
Result: Pass | |||||
POSTFIX-04: On Ubuntu, set up the environment as follows: | |||||
1) Default configuration files for SNFMilter. | 1) Default configuration files for SNFMilter. | ||||
postfix configuration files are not updated, and that SNFMilter | postfix configuration files are not updated, and that SNFMilter | ||||
is not running and that postfix is running and was not reloaded. | is not running and that postfix is running and was not reloaded. | ||||
Result: | |||||
Result: Pass. | |||||
POSTFIX-05: Repeat POSTFIX-04 but without "-v". | POSTFIX-05: Repeat POSTFIX-04 but without "-v". | ||||
Result: | |||||
Result: Pass. | |||||
POSTFIX-06: Configure as for POSTFIX-04, and do the following: | POSTFIX-06: Configure as for POSTFIX-04, and do the following: | ||||
output, and that SNFMilterConfig doesn't update the postfix | output, and that SNFMilterConfig doesn't update the postfix | ||||
configuration files or reload any MTA. | configuration files or reload any MTA. | ||||
Result: | |||||
3) Run SNFMilterConfig with "-with=postfix". Verify correct output, | |||||
and that SNFMilterConfig updates the postfix configuration files | |||||
and reloads the MTA. | |||||
4) Run SNFMilterConfig with "-with=postfix -explain". Verify | |||||
correct output, and that SNFMilterConfig doesn't update the | |||||
postfix configuration files or reload any MTA. | |||||
5) Run SNFMilterConfig with "-with=none -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't update the postfix | |||||
configuration files or reload any MTA. | |||||
Result: Pass. | |||||
POSTFIX-07: Repeat POSTFIX-01 thru POSTFIX-07 on Fedora. | |||||
Result: | |||||
POSTFIX-08: Repeat POSTFIX-01 thru POSTFIX-07 on OpenSuse. | |||||
Result: | |||||
POSTFIX-09: Repeat POSTFIX-01 thru POSTFIX-07 on CentOS. | |||||
Result: | |||||
POSTFIX-10: Repeat POSTFIX-01 thru POSTFIX-07 on OpenBSD. | |||||
Result: | |||||
POSTFIX-11: Repeat POSTFIX-01 thru POSTFIX-07 on FreeBSD. | |||||
Result: | |||||