usr/local/cpanel/scripts/convert_accesshash_to_token000075500000010113147207262670017106 0ustar00#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/convert_accesshash_to_token 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 File::Basename (); use Getopt::Long (); use Cpanel::Rand::Get (); use Cpanel::ResellerFunctions (); use Cpanel::SafeFile (); use Cpanel::ConfigFiles (); use Cpanel::Security::Authn::APITokens::Write::whostmgr (); use Whostmgr::AccessHash (); use Digest::SHA (); exit _main(@ARGV) unless caller; sub _main { my @args = @_; unless ( $> == 0 && $< == 0 ) { return bail_out('error: This program can only be run by root!'); } Getopt::Long::GetOptionsFromArray( \@args, 'help|?' => \my $print_help, 'verbose' => \my $verbose, 'all-resellers' => \my $all_resellers, ) || return bail_out('Invalid usage. See --help'); return print_help() if $print_help; $ENV{'REMOTE_USER'} = 'root'; my @users = @args; @users = Cpanel::ResellerFunctions::getresellerslist() if $all_resellers; @users = ( $ENV{'REMOTE_USER'} ) if !@users; foreach my $user (@users) { my $details = eval { import_accesshash($user) }; if ($@) { next if $@ =~ m/^No accesshash exists for/; print STDERR "error: $user: $@"; } elsif ($verbose) { print "Imported accesshash for “$user” as “$details->{name}”\n"; } } return 0; } sub _update_accounting_log { my ( $action, $token_name ) = @_; my $acctlog = Cpanel::SafeFile::safeopen( my $accounting_log_fh, '>>', $Cpanel::ConfigFiles::ACCOUNTING_LOG_FILE ); if ( !$acctlog ) { logger->warn("Could not write to /var/cpanel/accounting.log"); } else { chmod 0600, $Cpanel::ConfigFiles::ACCOUNTING_LOG_FILE; # The accounting log format is: #