Server IP : 103.119.228.120 / Your IP : 3.16.137.229 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/modify_packages 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 strict; use warnings; use Cpanel::Config::Constants ('DEFAULT_CPANEL_THEME'); use Cpanel::Logger (); use Cpanel::SafeFile (); use Cpanel::Themes::Utils (); use Whostmgr::ACLS (); use Whostmgr::Packages::Fetch (); use Whostmgr::Packages::Load (); use Getopt::Long (); my $logger = Cpanel::Logger->new(); $| = 1; if ( $> != 0 ) { $logger->die("Sorry, only root can use this script."); } my ( $theme, $packages, $help, $all_packages ); Getopt::Long::GetOptions( 'help' => \$help, 'theme=s' => \$theme, 'all-packages' => \$all_packages, 'packages=s' => \$packages ) || do { usage(); exit 1; }; if ($help) { usage(); exit; } unless ( $theme && ( $all_packages || $packages ) ) { usage(); exit 1; } my $theme_docroot = Cpanel::Themes::Utils::get_theme_root($theme); $logger->die( "The specified theme [" . $theme . "] does not exist." ) unless -d $theme_docroot; if ( !$ENV{'REMOTE_USER'} ) { $ENV{'REMOTE_USER'} = 'root'; } Whostmgr::ACLS::init_acls(); my @list_pkgs = (); my %pkgs = %{ Whostmgr::Packages::Fetch::fetch_package_list( 'want' => 'editable' ) }; my %valid_pkgs = (); if ($all_packages) { @list_pkgs = keys %pkgs; %valid_pkgs = map { ( $_ => $pkgs{$_} ) } @list_pkgs; } else { @list_pkgs = split( /\s*\,\s*/, $packages ); %valid_pkgs = map { exists( $pkgs{"$_"} ) ? ( $_ => $pkgs{$_} ) : () } @list_pkgs; } unless ( scalar( keys %valid_pkgs ) ) { $logger->die("No valid packages are specified."); } my %updated_pkgs = (); my $package_dir = Whostmgr::Packages::Load::package_dir(); foreach my $name ( keys %valid_pkgs ) { # Should not happen but just in case next unless -e $package_dir . $name; my $pkglock = Cpanel::SafeFile::safeopen( \*PKG, '+<', $package_dir . $name ); if ( !$pkglock ) { $logger->warn("Could not edit ${package_dir}$name"); next; } $updated_pkgs{$name} = 1; my %PKG_CONFIG = %{ $valid_pkgs{$name} }; seek( PKG, 0, 0 ); foreach my $pkgitem ( sort keys %PKG_CONFIG ) { next if !$pkgitem; next if ( $pkgitem eq '_PACKAGE_EXTENSIONS' ); my $line = qq{$pkgitem=$PKG_CONFIG{$pkgitem}}; $line =~ s/[\r\n]//g; if ( $pkgitem eq 'CPMOD' ) { $line = qq{$pkgitem=$theme}; } print PKG $line . "\n"; } print PKG qq{_PACKAGE_EXTENSIONS=$PKG_CONFIG{_PACKAGE_EXTENSIONS}\n} if $PKG_CONFIG{_PACKAGE_EXTENSIONS}; # _PACKAGE_EXTENSIONS last in file. truncate( PKG, tell(PKG) ); Cpanel::SafeFile::safeclose( \*PKG, $pkglock ); } # The default package may or may not have a file. my @failed_pkgs = grep { !$updated_pkgs{$_} && $_ ne 'default' } @list_pkgs; if ( scalar @failed_pkgs ) { $logger->warn( "Could not update these package(s): " . join( ', ', @failed_pkgs ) ); exit 1; } else { $logger->info("Packages are successfully updated."); exit 0; } sub usage { print <<"EOM"; $0: Modify existing packages to use a theme Usage: $0 --theme=$Cpanel::Config::Constants::DEFAULT_CPANEL_THEME [--packages=my_pkg,another_pkg|--all-packages] Options: --help: print usage and exit --theme: the theme to be adopted --packages: a list of packages to be modified, comma separated --all-packages: update all packages on the system EOM return; }