3
     À0¿ÂÅ  "   ˆl–ßi~”ªj"Tâ€À¿q¦ÔÅ£É594ÃÆ R    # This service runs once each boot to remove potential leftover
# container state from previous boots.

# This is needed when using transient storage mode in podman where the
# database and other configs are stored in tmpfs, but some other files
# are not. If we don't run this after an unclean boot then there may
# be some leftover files that grow over time.

[Unit]
Description=Clean up podman transient data
RequiresMountsFor=%t/containers
Documentation=man:podman-system-prune(1)

[Service]
Type=oneshot
ExecStart=/usr/bin/podman system prune --external

[Install]
WantedBy=default.target
  #   ˆl–äY>”TÔD¨ 	ÅÝÀ»p,©‹FÿÊ„Y¿ÄÇ ?÷     #!/usr/local/cpanel/3rdparty/bin/perl

package scripts::smtpmailgidonly;

#                                      Copyright 2026 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

use strict;
use warnings;

use Cpanel::Binaries             ();
use Cpanel::Chkservd             ();
use Cpanel::Config::CpConfGuard  ();
use Cpanel::Exim::Config::Ports  ();
use Cpanel::FileUtils::TouchFile ();
use Cpanel::FileUtils::Write     ();
use Cpanel::LoadFile             ();
use Cpanel::OS                   ();
use Cpanel::PwCache              ();
use Cpanel::SafeRun::Errors      ();
use Cpanel::SafeRun::Object      ();
use Cpanel::Services::Firewall   ();
use Cpanel::Validate::IP         ();
use Cpanel::Validate::IP::v4     ();
use Cpanel::YAML                 ();

use constant NFT_TABLE => 'cpanel_smtp_restrict';

our @PORTS;
our @RULE_TYPES;
our @RULES;

sub run {
    my (@argv) = @_;

    my $version = '2.4';
    my $action  = lc( ( grep( m/^-*(?:on|off|status|refresh|start|stop)$/i, @argv ) )[0] // '' ) || 0;
    $action =~ s/^-*//g;
    my $no_run_header = "$0 version $version - Copyright(C) 2020 cPanel, L.L.C.\nThis may be freely redistributed under the terms of the Artistic License.";

    if ( !$action ) {
        print STDERR <<"EOM";
$no_run_header

    usage:  $0 <on|off|status|refresh|start|stop>

EOM
        return 1;
    }

    my $cpaneluid  = ( Cpanel::PwCache::getpwnam('cpanel') )[2];
    my $mailgid    = ( Cpanel::PwCache::getpwnam('mail') )[3];
    my $mailmangid = ( Cpanel::PwCache::getpwnam('mailman') )[3];

    my $exim_alt_port = Cpanel::Chkservd::geteximport(1);    #first arg allows fetch more than the first port
    if ($exim_alt_port) {
        foreach my $port ( split( m/\s*\,\s*/, $exim_alt_port ) ) {
            $Cpanel::Exim::Config::Ports::LISTEN_PORTS{$port} = 1 if _valid_port($port);
        }
    }

    @PORTS      = sort { $a <=> $b } keys %Cpanel::Exim::Config::Ports::LISTEN_PORTS;
    @RULE_TYPES = (
        { 'table' => 'nat', 'target' => 'RETURN', 'method' => '-I' },
        { 'table' => '',    'target' => 'ACCEPT', 'method' => '-I' }
    );
    @RULES = (
        { 'type' => 'uid', 'value' => 0, 'name' => 'root' },    #aka root
        $cpaneluid  ? { 'type' => 'uid', 'value' => $cpaneluid, 'name' => 'cpanel', 'args' => [ '-d', '127.0.0.1' ] } : (),
        $mailgid    ? { 'type' => 'gid', 'value' => $mailgid,    'name' => 'mail' }    : (),
        $mailmangid ? { 'type' => 'gid', 'value' => $mailmangid, 'name' => 'mailman' } : ()
    );

    # for future expansion
    if ( -e '/var/cpanel/smtpmailgidonly/conf.yaml' ) {
        print "Loaded custom smtpmailgidonly/conf.yaml\n";
        my $cfg = Cpanel::YAML::LoadFile('/var/cpanel/smtpmailgidonly/conf.yaml');
        push @PORTS, grep { _valid_port($_) } @{ $cfg->{'PORTS'} } if ref $cfg->{'PORTS'} eq 'ARRAY';
        push @RULES, grep { _valid_rule($_) } @{ $cfg->{'RULES'} } if ref $cfg->{'RULES'} eq 'ARRAY';
    }

    my $enabled = -e '/var/cpanel/smtpgidonlytweak';

    if ( $action eq 'status' ) {
        print "Protection is: " . ( $enabled ? 'on' : 'off' ) . "\n";
        return 0;
    }

    if ( $action eq 'refresh' 