unsupported
     ˆ¾Äƒh¹ÃÂ      1
     �Áa–Ü4ý()¨‰P@Š7+�:¦-ÿÃ      File not found.
  #   ˆl–Ãa¾”êeJq@ŠãO\d*bÑ¿Æ„¡p_¿Ä ?÷     #!/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.

use strict;
use warnings;

use Cpanel::TempFile           ();
use Cpanel::SafeFile           ();
use Cpanel::Filesys::FindParse ();
use Cpanel::DiskLib            ();
use Getopt::Long;
use Cpanel::Logger             ();
use Cpanel::SafeRun::Errors    ();
use Cpanel::SafeRun::Simple    ();
use Cpanel::Filesys::Mounts    ();
use Cpanel::Config::LoadCpConf ();

my $logger = Cpanel::Logger->new();

$| = 1;    ## no critic qw(RequireLocalizedPunctuationVars)

my $has_loop_device = 0;

my $install   = 0;    # Add securetmp to system startup
my $uninstall = 0;    # Remove from system startup
my $auto      = 0;    # Secure /tmp and /var/tmp
my $daemonize = 1;
my $help      = 0;

# Get command line options
GetOptions( 'auto' => \$auto, 'install' => \$install, 'uninstall' => \$uninstall, 'daemonize!' => \$daemonize, 'help' => \$help );

if ($help) {
    print <<"MANUAL";
$0 - secure /tmp and /var/tmp

Options:
- auto: skip interactive customization questions
- install: install & enable securetmp service
- uninstall: disable & uninstal securetmp service
- daemonize: run securetmp in background ( default true )

Sample usages:
# run in interactive mode
> $0

# disable interactive mode, run in background
> $0 --auto

# disable interactive mode, do not run in background
> $0 --auto --nodaemonize
MANUAL
    exit;
}

if ( -e '/var/cpanel/version/securetmp_disabled' ) {
    print "[securetmp] Disabled per /var/cpanel/version/securetmp_disabled\n";
    exit;
}
elsif ( -e '/var/cpanel/disabled/securetmp' ) {
    print "[securetmp] Disabled per /var/cpanel/disabled/securetmp\n";
    exit;
}
elsif ( -e '/var/cpanel/dev_sandbox' ) {
    print "[securetmp] Disabled on development sandboxes\n";
    exit;
}

# do check for loopback module for Linux based VPS
my @modules = Cpanel::SafeRun::Errors::saferunallerrors('lsmod');
$has_loop_device = check_loop_device();

if ( !grep /loop/, @modules ) {
    print "*** Notice *** No loop module detected\n";    # could be built into kernel, so don't bail out yet
    print "If the loopback block device is built as a module, try running `modprobe loop` as root via ssh and running this script again.\n";
    print "If the loopback block device is built into the kernel itself, you can ignore this message.\n";
}
if ( !$has_loop_device ) {
    print "*** Notice *** No working loopback device files found. Try running `modprobe loop` as root via ssh and running this script again.\n";
    exit(0);
}

# Start interactive setup
if ( !$auto && !$install && !$uninstall && -t STDIN ) {
    print 'Would you like to secure /tmp & /var/tmp at boot time? (y/n) ';
    my $answer;
    chomp( $answer = <STDIN> );
    if ( $answer =~ m/^y/i ) {
        $install = 1;
    }
    else {
        print "securetmp will not be added to system startup at this time.\n";
    }
    undef $answer;

    if ( !$install ) {
        print 'Would you like to disable securetmp from the system startup? (y/n) ';
        chomp( $answer = <STDIN> );
        if ( $answer =~ m/^y/i ) {
            $uninstall = 1;
        }
        else {
            print "securetmp will not be removed from system startup.\n";
        }
        undef $answer;
    }

    print 'Would you like to secure /tmp & /var/tmp now? (y/n) ';
    chomp( $answer = <STDIN> );
    if ( $answer =~ m/^y/i ) {
        $auto = 1;
    }
    else {
        print "/tmp & /var/tmp will not be secured at this time.\n";
    }

    exit if ( !$install && !$auto && !$uninstall );
}
elsif ( !$auto && !$install && !$uninstall ) {
    exit 1;
}

## ADD/REMOVE from startup
#--------------