Server IP : 103.119.228.120 / Your IP : 13.58.40.171 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /scripts/ |
Upload File : |
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/spamassassin_dbm_cleaner Copyright 2022 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 Cpanel::Rlimit (); use Cpanel::PwCache::Helpers (); use Cpanel::PwCache::Build (); use Cpanel::AccessIds::SetUids (); use Cpanel::PwCache (); use Cpanel::LoginDefs (); use DB_File (); use strict; my $VERSION = '1.0'; my $MAX_MEMORY_ALLOWED = 134217728; #128M Allowed for dbsize + this perlcode, We allow 256M for spamd+dbs+email my $MAX_DB_SIZE = ( 1024 * 1024 * 96 ); #96M is the max size before spamd falls apart print "$0: version $VERSION\n"; Cpanel::Rlimit::set_rlimit_to_infinity(); my $canary = '--cpanel_sa_test_key'; my $pwcache_ref; if ( !$ARGV[0] ) { Cpanel::PwCache::Helpers::no_uid_cache(); #uid cache only needed if we are going to make lots of getpwuid calls Cpanel::PwCache::Build::init_passwdless_pwcache(); $pwcache_ref = Cpanel::PwCache::Build::fetch_pwcache(); } else { my $user = $ARGV[0]; my @pw_data = Cpanel::PwCache::getpwnam($user); if ( !$pw_data[0] ) { die "Usage: $0 [user]"; } $pwcache_ref = [ \@pw_data ]; } print "Checking SpamAssassin dbm databases...."; my ( $ok_count, $broken_count, $user_count ); my $now = time(); my $uid_min = Cpanel::LoginDefs::get_uid_min(); my ( $user, $uid, $gid, $homedir ); foreach my $pwref ( grep { $_->[2] >= $uid_min } @$pwcache_ref ) { ( $user, $uid, $gid, $homedir ) = ( (@$pwref)[ 0, 2, 3, 7 ] ); if ( $homedir ne '/' && -e $homedir . '/.spamassassin' ) { my ( $ok_files, $broken_files ) = _test_sa_dbm_files( $user, $uid, $gid, $homedir ); $user_count++; $ok_count += scalar @$ok_files if $ok_files; $broken_count += scalar @$broken_files if $broken_files; if ( $broken_files && @$broken_files ) { if ( my $pid = fork() ) { waitpid( $pid, 0 ); } else { Cpanel::AccessIds::SetUids::setuids( $uid, $gid ) || die "Failed to setuid to $user"; foreach my $file_data_ref (@$broken_files) { print "\n\t$user: $file_data_ref->{'file'} has problem: $file_data_ref->{'error'}. Moving to $file_data_ref->{'file'}.broken.$now"; rename( $file_data_ref->{'file'}, "$file_data_ref->{'file'}.broken.$now" ); } exit(0); } } } } print "\n" if $broken_count; print "Done\n"; print "Checked " . ( $ok_count + $broken_count ) . " files for $user_count user(s), $ok_count ok, $broken_count broken\n"; sub _test_sa_dbm_files { my ( $user, $uid, $gid, $homedir ) = @_; my $test_files = _get_matching_files( "$homedir/.spamassassin", '(?:bayes_|auto-)[^\.]+$' ); my ( $test_canary, $file, $data, $error ); my ( @ok_files, @broken_files ); @$test_files = grep( !/_journal/, @$test_files ); #special journal file return if !@$test_files; my $loop_count = 0; while ( @$test_files && ++$loop_count <= 5 ) { my $readpid = open( my $child_rdr, '-|' ); if ($readpid) { while (<$child_rdr>) { chomp($_); next if !$_; ( $test_canary, $file, $data, $error ) = split( /:/, $_, 4 ); if ( $test_canary eq $canary ) { if ($file) { @$test_files = grep { $_ ne $file } @$test_files; if ( $data eq 'ok' ) { push @ok_files, { 'file' => $file, 'status' => 1 }; } else { push @broken_files, { 'file' => $file, 'status' => 0, 'error' => "$data:$error" }; } } } else { print STDERR "Error from child process for $user: $_\n"; } #print "DEBUG: $_\n";; } close($child_rdr); } else { alarm(60); Cpanel::Rlimit::set_rlimit($MAX_MEMORY_ALLOWED); Cpanel::AccessIds::SetUids::setuids( $uid, $gid ) || die "Failed to setuid to $user"; while ( my $test_file = pop(@$test_files) ) { print "\n"; my %test_hash; print "${canary}:$test_file:"; if ( ( stat($test_file) )[7] > $MAX_DB_SIZE ) { print "toobig:database too large:\n"; } elsif ( my $result = tie %test_hash, 'DB_File', $test_file, &DB_File::O_RDONLY ) { print "ok\n"; untie %test_hash; } else { print "failed:$!:$result\n"; } print "\n"; } exit(0); } } return ( \@ok_files, \@broken_files ); } # From pkgacct sub _get_matching_files { my $dir = shift; my $regex = shift; my $compiled_regex; eval { $compiled_regex = qr/$regex/; }; if ( !$compiled_regex ) { print "Failed to compile regex $regex\n"; return; } my $dot_files_regex = qr/^\.\.?$/; opendir( my $dir_h, $dir ); my @files = map { "$dir/$_" } grep { $_ !~ $dot_files_regex && $_ =~ $compiled_regex } readdir($dir_h); closedir($dir_h); return \@files; }