0 #ˆl–Ãa¾” ŠeJq@?q±\d bÑ¿É ƒ}çÈÀÆ&�#!/usr/local/cpanel/3rdparty/bin/perl # Copyright 2025 WebPros International, LLC # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited. package scripts::builddovecotconf; use cPstrict; use Try::Tiny; use Cpanel::Config::LoadCpConf (); use Cpanel::AdvConfig (); use Cpanel::AdvConfig::dovecot (); use Cpanel::AdvConfig::dovecotSNI (); use Cpanel::AdvConfig::dovecotSSL (); use Cpanel::AdvConfig::dovecot::utils (); use Cpanel::Usage (); use Cpanel::FileUtils::TouchFile (); use Cpanel::Autodie (); use Cpanel::FileUtils::Access (); use Cpanel::Mkdir (); use Cpanel::Rand (); use Cpanel::Rand::Get (); use Cpanel::Dovecot (); use DBI (); use DBD::SQLite (); use Cpanel::DBI::SQLite (); use Cpanel::LoadModule (); our $CONF_PERMS = 0644; our $itcd_file = '/var/cpanel/imap_tcp_check_disabled'; __PACKAGE__->script(@ARGV) unless caller(); sub script ( $class, @args ) { my ( $force, $leave_broken, $now ) = ( 0, 0, time() ); Cpanel::Usage::wrap_options( \@args, \&usage, { 'force' => \$force, 'leave-broken' => \$leave_broken, }, ); my $cpconf_ref = Cpanel::Config::LoadCpConf::loadcpconf(); if ( $> != 0 ) { die "Insufficient permissions to rebuild dovecot.conf"; } my $dovecot_conf = Cpanel::AdvConfig::dovecot::utils::find_dovecot_conf(); my $test_dovecot_conf = Cpanel::Rand::get_tmp_file_by_name($dovecot_conf); die 'Failed to get a temporary working file!' if ( $test_dovecot_conf eq '/dev/null' ); chmod( $CONF_PERMS, $test_dovecot_conf ) or die "Could not set permissions on $test_dovecot_conf: $!"; # make sure the local template is valid _check_local_template() if !$leave_broken; # It is a good idea to load "our" config and process any changes *before* # we rebuild "their" config. my $conf_hr = Cpanel::AdvConfig::dovecot::get_config(); if ( $conf_hr->{'protocols'} =~ /imap(\s|$)/ ) { unlink $itcd_file; # Doesn't matter if it does not exist } else { Cpanel::FileUtils::TouchFile::touchfile('/var/cpanel/imap_tcp_check_disabled'); } # Check if conf values need updating for this upgrade. # use save_config as otherwise the changes don't persist in the UI, etc. # save_config also processes config changes, so we should invoke that # instead of merely process_config_changes. # *AMAZINGLY*, this saves a *whole lot more* keys than say whostmgr's UI # will save, though that's a consequence of it building config entirely # based off the formref instead of augmenting/replacing the existing # configuration. # This may in fact be a bug in that UI, but is longstanding behavior. # All that said, I'm not sure I'm a fan of some of the keys this adds, # as things like legacy_wildcard_safe and uniq just seem like garbage. Cpanel::AdvConfig::dovecot::save_config(); my $values_to_change = _generate_config_and_check_syntax( $force, $test_dovecot_conf, $dovecot_conf, $leave_broken ); # If dovecot complained certain values are too low, we need to adjust them if ( scalar keys %$values_to_change ) { _generate_config_and_check_syntax( $force, $test_dovecot_conf, $dovecot_conf, $leave_broken, $values_to_change ); } _setup_dovecot_dirs(); _setup_sqlite_dbs(); rename $test_dovecot_conf, $dovecot_conf or do { warn "Failed to install $dovecot_conf: $!"; }; unlink $dovecot_conf . '.datastore'; # Just in case _build_includes(); # Test the config one more time, as the includes