#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - scripts/enablefileprotect Copyright 2019 cPanel, L.L.C.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
use strict;
use Cpanel::PwCache::Build ();
use Cpanel::FileProtect ();
use Cpanel::FileProtect::Sync ();
use Cpanel::LoginDefs ();
use Try::Tiny;
$| = 1;
display_help() if ( $ARGV[0] eq '--help' );
if ( !Cpanel::FileProtect->is_on() ) {
Cpanel::FileProtect->set_on() or die "Error while setting Fileprotect flag to on: $!";
}
print 'Setting permissions for.....';
my $pwcache_ref = Cpanel::PwCache::Build::fetch_pwcache();
my $min_uid = Cpanel::LoginDefs::get_uid_min();
foreach my $pw (@$pwcache_ref) {
next if ( !$pw->[0] || !-e '/var/cpanel/users/' . $pw->[0] );
my $useruid = $pw->[2];
my $usergid = $pw->[3];
next if ( $useruid < $min_uid );
my $homedir = $pw->[7];
next if !$homedir || !-d $homedir;
print "$pw->[0] …\n";
try {
warn $_->to_string() for Cpanel::FileProtect::Sync::sync_user_homedir( $pw->[0] );
}
catch {
print "Skipping $pw->[0] because of an error: $_\n";
};
}
print "...Done\n";
sub display_help {
print <<"EO_HELP";
Usage: $0 [--help]
Protect the public_html directory of each user account so that only Apache and the user may
view its contents. Use the disablefileprotect script to reverse the process.
Options:
--help This screen
EO_HELP
exit;
}
Copyright 2K16 - 2K18 Indonesian Hacker Rulez