Server IP : 103.119.228.120 / Your IP : 18.118.193.28 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/userdata_wildcard_cleanup 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 package scripts::userdata_wildcard_cleanup; use strict; use Cpanel (); use Cpanel::Config::userdata::Constants (); use Cpanel::Config::userdata::Guard (); use Cpanel::FileUtils::TouchFile (); use Cpanel::SafeRun::Errors (); use Cpanel::ServerTasks (); use Cpanel::WildcardDomain (); use Cpanel::WildcardDomain::Tiny (); use File::Basename (); BEGIN { unshift @INC, '/usr/local/cpanel'; } my @ssl_userdata_parts = qw( sslcertificatefile sslcertificatekeyfile sslcacertificatefile ); our $TOUCH_FILE = '/var/cpanel/ssl/wildcard_cleanup_complete'; __PACKAGE__->script(@ARGV) unless caller(); ######################################################################## # This script was created to fix an issue documented in case 67341 ######################################################################## sub script { my ( $class, @argv ) = @_; my ( $rebuild_apache, $forced ); for my $arg (@argv) { if ( $arg eq '--rebuildapache' ) { $rebuild_apache = 1; } if ( $arg eq '--force' ) { $forced = 1; } } return if -e $TOUCH_FILE && !$forced; my ( $httpd_conf_rebuild_needed, @migrated_servernames, @migrated_nobody_domains ); @migrated_servernames = _migrate_wildcard_encoded_userdata_files(); @migrated_nobody_domains = _migrate_nobody_userdata_files(); $httpd_conf_rebuild_needed = 1 if @migrated_servernames || @migrated_nobody_domains; #Rebuild apache because previous rebuilds might have accidentally #deleted the wildcard SSL vhosts from being unable to find their #userdata files. if ($httpd_conf_rebuild_needed) { if ($rebuild_apache) { print "Rebuilding Apache\n"; my $output = Cpanel::SafeRun::Errors::saferunallerrors("$Cpanel::root/bin/build_apache_conf"); if ( $output !~ /OK$/ ) { warn "Error rebuilding the apache configuration: $output\n"; } Cpanel::ServerTasks::queue_task( ['ApacheTasks'], 'apache_restart' ); } else { print "Skipping Apache Rebuild\n"; } } Cpanel::FileUtils::TouchFile::touchfile($TOUCH_FILE); return; } sub _migrate_nobody_userdata_files { my $userDir = $Cpanel::Config::userdata::Constants::USERDATA_DIR . "/nobody"; if ( !-e $userDir ) { return; } my @domains_processed = (); { my $main_guard = Cpanel::Config::userdata::Guard->new( 'nobody', 'main' ); my $maindata = $main_guard->data(); for my $domain ( $maindata->{'main_domain'}, @{ $maindata->{'sub_domains'} } ) { if ( !$domain || !Cpanel::WildcardDomain::Tiny::is_wildcard_domain($domain) || !-e $userDir . "/${domain}_SSL" ) { next; } my $guard = Cpanel::Config::userdata::Guard->new( 'nobody', $domain . '_SSL' ); my $userdata = $guard->data(); _fix_userdata($userdata); push @domains_processed, $userdata->{'servername'}; $guard->save(); } $main_guard->abort(); } return; } sub _migrate_wildcard_encoded_userdata_files { my @migrated_servernames = (); my @wildcard_encoded_userdata_files = glob("$Cpanel::Config::userdata::Constants::USERDATA_DIR/*/_wildcard_*"); for my $old_file (@wildcard_encoded_userdata_files) { next if !-f $old_file; if ( $old_file =~ m{\.cache\z} ) { unlink $old_file; next; } my ( $ok, %ret ) = _migrate_userdata_file($old_file); next if $ret{'deleted'}; my $new_file = $old_file; #We *shouldn't* need the fussiness of anchoring this substitution #with / and \z, but just in case. $new_file =~ s{/_wildcard_([^/]+)\z}{/*$1}; if ( !-f $new_file ) { if ( !rename( $old_file, $new_file ) ) { warn "The system failed to rename $old_file to $new_file because of an error: $!"; next; } push @migrated_servernames, $ret{'servername'}; } } return @migrated_servernames; } sub _migrate_userdata_file { my ($file) = @_; my ( $filename, $path, undef ) = File::Basename::fileparse($file); my $user = File::Basename::basename($path); my %return_data = (); { my $guard = Cpanel::Config::userdata::Guard->new( $user, $filename ); my $userdata = $guard->data(); if ( exists $userdata->{'servername'} ) { for my $ssl_part (@ssl_userdata_parts) { next if !$userdata->{$ssl_part}; if ( !-e $userdata->{$ssl_part} ) { $guard->abort(); unlink $file; return ( 1, 'deleted' => 1 ); } } _fix_userdata($userdata); $return_data{'servername'} = $userdata->{'servername'}; $guard->save(); } else { $guard->abort(); } } return ( 1, %return_data ); } sub _fix_userdata { my ($userdata) = @_; # Decodes wildcard encoded domains $userdata->{'servername'} = Cpanel::WildcardDomain::decode_wildcard_domain( $userdata->{'servername'} ); $userdata->{'serveradmin'} =~ s{(\@)_wildcard_\.}{$1}; $userdata->{'serveralias'} = $userdata->{'servername'}; return; } 1;