Skip to content

Commit 6621101

Browse files
authored
Merge pull request #363 from kirtangajjar/fix/postfix-configuration
Fix relayhost and msmrtpc changes in postifx
2 parents a655120 + 4604870 commit 6621101

File tree

6 files changed

+86
-10
lines changed

6 files changed

+86
-10
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace EE\Migration;
4+
5+
use EE;
6+
use EE\RevertableStepProcessor;
7+
use EE\Model\Site;
8+
9+
class PostfixMsmtrpcFix extends Base {
10+
11+
private $sites;
12+
/** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */
13+
private static $rsp;
14+
15+
public function __construct() {
16+
17+
parent::__construct();
18+
$this->sites = Site::all();
19+
if ( $this->is_first_execution || ! $this->sites ) {
20+
$this->skip_this_migration = true;
21+
}
22+
}
23+
24+
/**
25+
* Execute nginx config updates.
26+
*
27+
* @throws EE\ExitException
28+
*/
29+
public function up() {
30+
31+
if ( $this->skip_this_migration ) {
32+
EE::debug( 'Skipping postfix-msmtrpc-fix migration as it is not needed.' );
33+
34+
return;
35+
}
36+
37+
foreach ( $this->sites as $site ) {
38+
39+
if ( $site->site_type !== 'html' ) {
40+
mkdir( $site->site_fs_path . '/config/php/misc' );
41+
touch( $site->site_fs_path . '/config/php/misc/msmtprc' );
42+
43+
chdir( $site->site_fs_path );
44+
EE::exec( \EE_DOCKER::docker_compose_with_custom() . " exec --user=root php sh -c 'rm /etc/msmtprc'" );
45+
EE::exec( \EE_DOCKER::docker_compose_with_custom() . " exec --user=root php sh -c 'ln -s /usr/local/etc/misc/msmtprc /etc/msmtprc'" );
46+
EE::exec( \EE_DOCKER::docker_compose_with_custom() . " exec --user=root php sh -c 'chown -R www-data:www-data /usr/local/etc/misc'" );
47+
EE::exec( \EE_DOCKER::docker_compose_with_custom() . " exec --user=root php sh -c 'chown -R www-data:www-data /etc/msmtprc'" );
48+
49+
EE\Site\Utils\configure_postfix( $site->site_url, $site->site_fs_path );
50+
51+
}
52+
}
53+
54+
}
55+
56+
/**
57+
* Bring back the existing old nginx config.
58+
*
59+
* @throws EE\ExitException
60+
*/
61+
public function down() {
62+
63+
}
64+
}

src/Site_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ public function __invoke( $args, $assoc_args ) {
164164
* @param array $args Command line arguments passed to site-command.
165165
* @param string $default_type Default site-type.
166166
*
167+
* @return string site-type.
167168
* @throws \EE\ExitException
168169
*
169-
* @return string site-type.
170170
*/
171171
private function determine_type( $default_type, $args ) {
172172

src/helper/class-ee-site.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ protected function sendmail_path_update( $msmtp ) {
845845
}, $custom_ini_data );
846846
} else {
847847
$custom_ini_data = array_map( function ( $custom_ini_data ) {
848-
$sendmail_path = 'sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]';
848+
$sendmail_path = 'sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]';
849849

850850
return stristr( $custom_ini_data, 'sendmail_path' ) ? "$sendmail_path\n" : $custom_ini_data;
851851
}, $custom_ini_data );

src/helper/site-utils.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ function get_site_info( $args, $site_enabled_check = true, $exit_if_not_found =
119119
/**
120120
* Populate basic site info from db.
121121
*
122-
* @param array $domains Array of all domains.
122+
* @param array $domains Array of all domains.
123123
*
124124
* @return string $preferred_challenge Type of challenge preffered.
125125
*/
126-
function get_preferred_ssl_challenge(array $domains) {
126+
function get_preferred_ssl_challenge( array $domains ) {
127127

128128
foreach ( $domains as $domain ) {
129129
if ( preg_match( '/^\*/', $domain ) ) {
@@ -436,7 +436,8 @@ function site_status_check( $site_url ) {
436436
* Function to pull the latest images and bring up the site containers and set EasyEngine header.
437437
*
438438
* @param string $site_fs_path Root directory of the site.
439-
* @param array $containers The minimum required conatainers to start the site. Default null, leads to starting of all containers.
439+
* @param array $containers The minimum required conatainers to start the site. Default null, leads to starting of
440+
* all containers.
440441
*
441442
* @throws \Exception when docker-compose up fails.
442443
*/
@@ -520,7 +521,17 @@ function set_postfix_files( $site_url, $site_service_dir ) {
520521
function configure_postfix( $site_url, $site_fs_path ) {
521522

522523
chdir( $site_fs_path );
523-
EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'relayhost =\'' );
524+
525+
$default_from = EE::launch( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix sh -c \'echo $REPLY_EMAIL\'' )->stdout;
526+
527+
if ( ! trim( $default_from ) ) {
528+
$default_from = "no-reply@$site_url";
529+
}
530+
531+
EE::exec( \EE_DOCKER::docker_compose_with_custom() . " exec php sh -c 'echo \"host postfix\ntls off\nfrom $default_from\" > /etc/msmtprc'" );
532+
$relay_host = EE::launch( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix sh -c \'echo $RELAY_HOST\'' )->stdout;
533+
$relay_host = trim( $relay_host, "\n\r" );
534+
EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'relayhost = ' . $relay_host . '\'' );
524535
EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'smtpd_recipient_restrictions = permit_mynetworks\'' );
525536
$launch = EE::launch( sprintf( 'docker inspect -f \'{{ with (index .IPAM.Config 0) }}{{ .Subnet }}{{ end }}\' %s', $site_url ) );
526537
$subnet_cidr = trim( $launch->stdout );

src/site-type/HTML.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ public function create( $args, $assoc_args ) {
132132
if ( ! empty( $alias_domains ) ) {
133133
$comma_seprated_domains = explode( ',', $alias_domains );
134134
foreach ( $comma_seprated_domains as $domain ) {
135-
$trimmed_domain = trim( $domain );
135+
$trimmed_domain = trim( $domain );
136136
$this->site_data['alias_domains'] .= $trimmed_domain . ',';
137137
}
138138
}
139+
139140
$this->site_data['alias_domains'] = substr( $this->site_data['alias_domains'], 0, - 1 );
140-
141141
$this->site_data['site_ssl'] = get_value_if_flag_isset( $assoc_args, 'ssl', 'le' );
142142

143143
if ( 'custom' === $this->site_data['site_ssl'] ) {
@@ -192,6 +192,7 @@ public function info( $args, $assoc_args ) {
192192
$site = (array) Site::find( $this->site_data['site_url'] );
193193
$site = reset( $site );
194194
EE::log( json_encode( $site ) );
195+
195196
return;
196197
}
197198

@@ -235,7 +236,7 @@ private function configure_site_files() {
235236

236237
$server_name = implode( ' ', explode( ',', $this->site_data['alias_domains'] ) );
237238

238-
$data = [
239+
$data = [
239240
'server_name' => $server_name,
240241
'document_root' => $this->site_data['site_container_fs_path'],
241242
];

src/site-type/Site_HTML_Docker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Site_HTML_Docker {
1212
* Generate docker-compose.yml according to requirement.
1313
*
1414
* @param array $filters Array to determine the docker-compose.yml generation.
15-
** @param array $volumes Array containing volume info passable to \EE_DOCKER::get_mounting_volume_array().
15+
* @param array $volumes Array containing volume info passable to \EE_DOCKER::get_mounting_volume_array().
1616
*
1717
* @return String docker-compose.yml content string.
1818
*/

0 commit comments

Comments
 (0)