Skip to content

Commit

Permalink
Fixed: Listener sample for overriding of default config.inc.php con…
Browse files Browse the repository at this point in the history
…figuration file.

Fixed: Useless import of the `File::Temp` package (package handler).
Fixed: Wrong return value on success for the `deleteMail()` routine (package handler).
CS fixes.
  • Loading branch information
nuxwin committed Apr 10, 2019
1 parent 080bb1a commit d0e341e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 44 deletions.
29 changes: 27 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 1.0.2 - TBD

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Listener sample for overriding of default `config.inc.php` configuration file.
- Useless import of the `File::Temp` package (package handler).
- Wrong return value on success for the `deleteMail()` routine (package handler).
- CS fixes.

## 1.0.1 - 20190401

### Added
Expand All @@ -20,8 +45,8 @@

### Fixed

- Roundcube cronjob not removed on uninstallation
- LOGROTATE(8) configuration file not removed on uninstallation
- Roundcube cronjob not removed on uninstallation.
- LOGROTATE(8) configuration file not removed on uninstallation.

## 1.0.0 - 20190401

Expand Down
87 changes: 47 additions & 40 deletions src/Handler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use strict;
use warnings;
use Class::Autouse qw/ :nostat iMSCP::Composer /;
use File::Spec;
use File::Temp;
use iMSCP::Boolean;
use iMSCP::Crypt qw/ decryptRijndaelCBC encryptRijndaelCBC randomStr /;
use iMSCP::Cwd '$CWD';
Expand Down Expand Up @@ -210,7 +209,7 @@ sub postinstall
),
"$CWD/public/tools/roundcube"
) ) {
error( sprintf( "Couldn't create symlink for Roundcube webmail" ));
error( sprintf( "Couldn't create symlink for the Roundcube webmail" ));
return 1;
}

Expand Down Expand Up @@ -342,7 +341,7 @@ sub deleteMail
return 1;
}

1;
0;
}

=back
Expand Down Expand Up @@ -410,7 +409,7 @@ sub _init

=item _buildConfigFiles( )
Build PhpMyadminConfiguration files
Build Roundcube configuration files
Return int 0 on success, other on failure
Expand All @@ -424,7 +423,11 @@ sub _buildConfigFiles
local $self->{'dbh'}->{'RaiseError'} = TRUE;

my %config = @{ $self->{'dbh'}->selectcol_arrayref(
"SELECT `name`, `value` FROM `config` WHERE `name` LIKE 'ROUNDCUBE_%'",
"
SELECT `name`, `value`
FROM `config` WHERE `name`
LIKE 'ROUNDCUBE_%'
",
{ Columns => [ 1, 2 ] }
) };

Expand All @@ -449,7 +452,7 @@ sub _buildConfigFiles
$config{'ROUNDCUBE_SQL_USER'}, $config{'ROUNDCUBE_SQL_USER_PASSWD'}
);

local $self->{'dbh'}->{'RaiseError'} = TRUE;
# Save generated values in database (encrypted)
$self->{'dbh'}->do(
'
INSERT INTO `config` (`name`,`value`)
Expand Down Expand Up @@ -535,7 +538,7 @@ sub _buildConfigFiles
};
if ( $@ ) {
error( $@ );
return 1;
$rs = 1;
}

$rs;
Expand Down Expand Up @@ -640,7 +643,7 @@ sub _setupDatabase
{
my ( $self ) = @_;

eval {
my $rs = eval {
local $self->{'dbh'}->{'RaiseError'} = TRUE;

my $database = ::setupGetQuestion( 'DATABASE_NAME' ) . '_roundcube';
Expand All @@ -667,45 +670,49 @@ sub _setupDatabase
\my $stderr
);
debug( $stdout ) if length $stdout;
$rs == 0 or die( $stderr || 'Unknown error' );
} else {
# Update Roundcube database
my $rs = execute(
$self->_getSuCmd(
"$CWD/vendor/imscp/roundcube/roundcubemail/bin/updatedb.sh",
'--dir', "$CWD/vendor/imscp/roundcube/roundcubemail/SQL",
'--package', 'roundcube'
),
\my $stdout,
\my $stderr
);
debug( $stdout ) if length $stdout;
$rs == 0 or die( $stderr || 'Unknown error' );
error( $stderr || 'Unknown error' ) if $rs;
return $rs;
}

# Ensure tha `users`.`mail_host` entries are set with expected hostname
my $hostname = 'localhost';
$self->{'events'}->trigger(
'beforeUpdateRoundCubeMailHostEntries', \$hostname
);
# Update Roundcube database
my $rs = execute(
$self->_getSuCmd(
"$CWD/vendor/imscp/roundcube/roundcubemail/bin/updatedb.sh",
'--dir', "$CWD/vendor/imscp/roundcube/roundcubemail/SQL",
'--package', 'roundcube'
),
\my $stdout,
\my $stderr
);
debug( $stdout ) if length $stdout;
error( $stderr || 'Unknown error' ) if $rs;
return $rs if $rs;

$self->{'dbh'}->do(
"UPDATE IGNORE $quotedDatabase.`users` SET `mail_host` = ?",
undef,
$hostname
);
$self->{'dbh'}->do(
"DELETE FROM $quotedDatabase.`users` WHERE `mail_host` <> ?",
undef,
$hostname
);
}
# Ensure tha `users`.`mail_host` entries are set with expected hostname
my $hostname = 'localhost';
$self->{'events'}->trigger(
'beforeUpdateRoundCubeMailHostEntries', \$hostname
);

$self->{'dbh'}->do(
"UPDATE IGNORE $quotedDatabase.`users` SET `mail_host` = ?",
undef,
$hostname
);
$self->{'dbh'}->do(
"DELETE FROM $quotedDatabase.`users` WHERE `mail_host` <> ?",
undef,
$hostname
);

0;
};
if ( $@ ) {
error( $@ );
return 1;
$rs = 1;
}

0;
$rs;
}

=item _getSuCmd( @_ )
Expand Down
8 changes: 6 additions & 2 deletions src/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*
* Perl code:
*
* Package Listener::Roundcube::CustomConfigIncFile;
*
* use strict;
* use warnings;
* use iMSCP::EventManager;
* use iMSCP::File;
*
Expand All @@ -20,9 +24,9 @@
*
* # Load custom Roundcube configuration file into the $cfgTplContent
* # variable.
* return 1 unless defined ${ $cfgTplContent } = iMSCP::File->new(
* return 1 unless defined ( ${ $cfgTplContent } = iMSCP::File->new(
* filename => 'path/to/your/roundcube/conf/file'
* )->get();
* )->get() );
*
* 0;
* });
Expand Down

0 comments on commit d0e341e

Please sign in to comment.