From 08bca2a87e06083739366738bbf361a44ffa30ea Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 18 Jan 2013 13:28:30 -0800 Subject: [PATCH] Move mail-related setup issues to setup checks Summary: Ports mail stuff from the existing setup process to the more modular setup checks. Test Plan: Configured my local install to have all these errors, verified setup raised them. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T2228 Differential Revision: https://secure.phabricator.com/D4494 --- src/__phutil_library_map__.php | 2 + .../PhabricatorApplicationConfig.php | 4 - .../check/PhabricatorSetupCheckMail.php | 83 +++++++++++++ src/infrastructure/PhabricatorSetup.php | 109 ------------------ 4 files changed, 85 insertions(+), 113 deletions(-) create mode 100644 src/applications/config/check/PhabricatorSetupCheckMail.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ff42eb8a5b..abfda33402 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1206,6 +1206,7 @@ phutil_register_library_map(array( 'PhabricatorSetupCheckAPC' => 'applications/config/check/PhabricatorSetupCheckAPC.php', 'PhabricatorSetupCheckExtraConfig' => 'applications/config/check/PhabricatorSetupCheckExtraConfig.php', 'PhabricatorSetupCheckInvalidConfig' => 'applications/config/check/PhabricatorSetupCheckInvalidConfig.php', + 'PhabricatorSetupCheckMail' => 'applications/config/check/PhabricatorSetupCheckMail.php', 'PhabricatorSetupCheckTimezone' => 'applications/config/check/PhabricatorSetupCheckTimezone.php', 'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php', 'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php', @@ -2554,6 +2555,7 @@ phutil_register_library_map(array( 'PhabricatorSetupCheckAPC' => 'PhabricatorSetupCheck', 'PhabricatorSetupCheckExtraConfig' => 'PhabricatorSetupCheck', 'PhabricatorSetupCheckInvalidConfig' => 'PhabricatorSetupCheck', + 'PhabricatorSetupCheckMail' => 'PhabricatorSetupCheck', 'PhabricatorSetupCheckTimezone' => 'PhabricatorSetupCheck', 'PhabricatorSetupIssueView' => 'AphrontView', 'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO', diff --git a/src/applications/config/application/PhabricatorApplicationConfig.php b/src/applications/config/application/PhabricatorApplicationConfig.php index d4a58599d6..70c542c217 100644 --- a/src/applications/config/application/PhabricatorApplicationConfig.php +++ b/src/applications/config/application/PhabricatorApplicationConfig.php @@ -18,10 +18,6 @@ final class PhabricatorApplicationConfig extends PhabricatorApplication { return self::GROUP_ADMIN; } - public function shouldAppearInLaunchView() { - return false; - } - public function getRoutes() { return array( '/config/' => array( diff --git a/src/applications/config/check/PhabricatorSetupCheckMail.php b/src/applications/config/check/PhabricatorSetupCheckMail.php new file mode 100644 index 0000000000..ee1f4a6b1e --- /dev/null +++ b/src/applications/config/check/PhabricatorSetupCheckMail.php @@ -0,0 +1,83 @@ +newIssue('config.metamta.mail-adapter') + ->setShortName(pht('Missing Sendmail')) + ->setName(pht('No Sendmail Binary Found')) + ->setMessage($message) + ->addPhabricatorConfig('metamta.mail-adapter'); + } + break; + case 'PhabricatorMailImplementationAmazonSESAdapter': + if (PhabricatorEnv::getEnvConfig('metamta.can-send-as-user')) { + $message = pht( + 'Amazon SES does not support sending email as users. Disable '. + 'send as user, or choose a different mail adapter.'); + + $this->newIssue('config.can-send-as-user') + ->setName(pht("SES Can't Send As User")) + ->setMessage($message) + ->addPhabricatorConfig('metamta.mail-adapter') + ->addPhabricatorConfig('metamta.can-send-as-user'); + } + + if (!PhabricatorEnv::getEnvConfig('amazon-ses.access-key')) { + $message = pht( + 'Amazon SES is selected as the mail adapter, but no SES access '. + 'key is configured. Provide an SES access key, or choose a '. + 'different mail adapter.'); + + $this->newIssue('config.amazon-ses.access-key') + ->setName(pht("Amazon SES Access Key Not Set")) + ->setMessage($message) + ->addPhabricatorConfig('metamta.mail-adapter') + ->addPhabricatorConfig('amazon-ses.access-key'); + } + + if (!PhabricatorEnv::getEnvConfig('amazon-ses.secret-key')) { + $message = pht( + 'Amazon SES is selected as the mail adapter, but no SES secret '. + 'key is configured. Provide an SES secret key, or choose a '. + 'different mail adapter.'); + + $this->newIssue('config.amazon-ses.secret-key') + ->setName(pht("Amazon SES Secret Key Not Set")) + ->setMessage($message) + ->addPhabricatorConfig('metamta.mail-adapter') + ->addPhabricatorConfig('amazon-ses.secret-key'); + } + + $address_key = 'metamta.default-address'; + $options = PhabricatorApplicationConfigOptions::loadAllOptions(); + $default = $options[$address_key]->getDefault(); + $value = PhabricatorEnv::getEnvConfig($address_key); + if ($default === $value) { + $message = pht( + 'Amazon SES requires verification of the "From" address, but '. + 'you have not configured a "From" address. Configure and verify '. + 'a "From" address, or choose a different mail adapter.'); + + $this->newIssue('config.metamta.default-address') + ->setName(pht("No SES From Address Configured")) + ->setMessage($message) + ->addPhabricatorConfig('metamta.mail-adapter') + ->addPhabricatorConfig('metamta.default-address'); + } + break; + } + + } +} diff --git a/src/infrastructure/PhabricatorSetup.php b/src/infrastructure/PhabricatorSetup.php index e7e6a30261..7e7edfef15 100644 --- a/src/infrastructure/PhabricatorSetup.php +++ b/src/infrastructure/PhabricatorSetup.php @@ -607,115 +607,6 @@ final class PhabricatorSetup { self::write("[OKAY] Database and storage configuration OKAY\n"); - - self::writeHeader("OUTBOUND EMAIL CONFIGURATION"); - - $have_adapter = false; - $is_ses = false; - - $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); - switch ($adapter) { - case 'PhabricatorMailImplementationPHPMailerLiteAdapter': - - $have_adapter = true; - - if (!Filesystem::pathExists('/usr/bin/sendmail') && - !Filesystem::pathExists('/usr/sbin/sendmail')) { - self::writeFailure(); - self::write( - "Setup failure! You don't have a 'sendmail' binary on this system ". - "but outbound email is configured to use sendmail. Install an MTA ". - "(like sendmail, qmail or postfix) or use a different outbound ". - "mail configuration. See this guide for configuring outbound ". - "email:\n"); - self::writeDoc('article/Configuring_Outbound_Email.html'); - return; - } else { - self::write(" okay Sendmail is configured.\n"); - } - - break; - case 'PhabricatorMailImplementationAmazonSESAdapter': - - $is_ses = true; - $have_adapter = true; - - if (PhabricatorEnv::getEnvConfig('metamta.can-send-as-user')) { - self::writeFailure(); - self::write( - "Setup failure! 'metamta.can-send-as-user' must be false when ". - "configured with Amazon SES."); - return; - } else { - self::write(" okay Sender config looks okay.\n"); - } - - if (!PhabricatorEnv::getEnvConfig('amazon-ses.access-key')) { - self::writeFailure(); - self::write( - "Setup failure! 'amazon-ses.access-key' is not set, but ". - "outbound mail is configured to deliver via Amazon SES."); - return; - } else { - self::write(" okay Amazon SES access key is set.\n"); - } - - if (!PhabricatorEnv::getEnvConfig('amazon-ses.secret-key')) { - self::writeFailure(); - self::write( - "Setup failure! 'amazon-ses.secret-key' is not set, but ". - "outbound mail is configured to deliver via Amazon SES."); - return; - } else { - self::write(" okay Amazon SES secret key is set.\n"); - } - - if (PhabricatorEnv::getEnvConfig('metamta.send-immediately')) { - self::writeNote( - "Your configuration uses Amazon SES to deliver email but tries ". - "to send it immediately. This will work, but it's slow. ". - "Consider configuring the MetaMTA daemon."); - } - break; - case 'PhabricatorMailImplementationTestAdapter': - self::write(" skip You have disabled outbound email.\n"); - break; - default: - self::write(" skip Configured with a custom adapter.\n"); - break; - } - - if ($have_adapter) { - $default = PhabricatorEnv::getEnvConfig('metamta.default-address'); - if (!$default || $default == 'noreply@example.com') { - self::writeFailure(); - self::write( - "Setup failure! You have not set 'metamta.default-address'."); - return; - } else { - self::write(" okay metamta.default-address is set.\n"); - } - - if ($is_ses) { - self::writeNote( - "Make sure you've verified your 'from' address ('{$default}') with ". - "Amazon SES. Until you verify it, you will be unable to send mail ". - "using Amazon SES."); - } - - $domain = PhabricatorEnv::getEnvConfig('metamta.domain'); - if (!$domain || $domain == 'example.com') { - self::writeFailure(); - self::write( - "Setup failure! You have not set 'metamta.domain'."); - return; - } else { - self::write(" okay metamta.domain is set.\n"); - } - - self::write("[OKAY] Mail configuration OKAY\n"); - } - self::writeHeader('SUCCESS!'); self::write( "Congratulations! Your setup seems mostly correct, or at least fairly ".