#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - scripts/suspendacct 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::suspendacct;
use strict;
## no critic qw(TestingAndDebugging::RequireUseWarnings) -- suspendacct is not yet warnings safe
use Try::Tiny;
use Whostmgr::ACLS ();
use Cpanel::Auth::Digest::DB::Manage ();
use Cpanel::Auth::Shadow ();
use Cpanel::AcctUtils::AccountingLog ();
use Cpanel::AcctUtils::DomainOwner::Tiny ();
use Cpanel::AcctUtils::Owner ();
use Cpanel::AcctUtils::Domain ();
use Cpanel::Config::LoadCpUserFile ();
use Cpanel::PwCache::Clear ();
use Cpanel::Validate::Domain::Tiny ();
use Cpanel::Encoder::Tiny ();
use Cpanel::Exception ();
use Cpanel::Dovecot::Action ();
use Cpanel::AccessIds::ReducedPrivileges ();
use Cpanel::AcctUtils::Suspended ();
use Cpanel::SafetyBits ();
use Cpanel::Config::CpUserGuard ();
use Cpanel::ConfigFiles ();
use Cpanel::FileUtils::Copy ();
use Cpanel::FileUtils::Match ();
use Cpanel::FileUtils::Write ();
use Cpanel::Hooks ();
use Cpanel::Hostname ();
use Cpanel::IP::Remote ();
use Cpanel::MysqlUtils::Suspension ();
use Cpanel::SafeFile ();
use Cpanel::Sys::Kill ();
use Cpanel::OS ();
use Cpanel::Passwd::Shell ();
use Cpanel::ServerTasks ();
use Cpanel::Services::Enabled ();
use Cpanel::Session::SinglePurge ();
use Cpanel::PwCache ();
use Cpanel::Validate::Username ();
use Cpanel::Validate::Domain::Normalize ();
use Cpanel::Quota::Temp ();
use Whostmgr::Accounts::Suspend ();
use Whostmgr::Accounts::Email ();
use Whostmgr::Accounts::SuspensionData::Writer ();
use AcctLock ();
use Cpanel::Notify ();
use Getopt::Long ();
use Cpanel::Team::Constants ();
use Cpanel::Team::Config ();
exit( run(@ARGV) ) unless caller;
sub run { ## no critic qw(Subroutines::ProhibitExcessComplexity)
my (@args) = @_;
my $leave_ftp_enabled = 0;
my $usage = 0;
my $force = 0;
my $child_ok = 0;
return usage(1) if !@args;
Getopt::Long::GetOptionsFromArray(
\@args,
'leave-ftp-accts-enabled' => \$leave_ftp_enabled,
'help|usage' => \$usage,
'force' => \$force,
'child-ok' => \$child_ok,
);
my $user = $args[0];
$user =~ s/\///g;
my $reason = Cpanel::Encoder::Tiny::safe_html_decode_str( $args[1] // '' );
$reason =~ s/[=\n\0]//g;
my $prevent_reseller_unsuspend = $args[2] // 0;
return usage(0) if $usage;
return usage(1) if ( !$user || is_forbidden_user($user) );
local $ENV{'USER'} = $ENV{'USER'};
local $ENV{'REMOTE_USER'} = $ENV{'REMOTE_USER'};
if ( ( !$ENV{'USER'} || !$ENV{'REMOTE_USER'} ) && $> == 0 ) {
$ENV{'REMOTE_USER'} = 'root';
$ENV{'USER'} = 'root';
}
# Needed for changing quotas.
Whostmgr::ACLS::init_acls();
return usage( 1, "Invalid user $user\n" ) if !is_valid_user($user);
if ( $prevent_reseller_unsuspend && !Whostmgr::ACLS::hasroot() ) {
print "Can not prevent resellers from unsuspending this account without the 'all' ACL.\n";
return 1;
}
if ( $leave_ftp_enabled && !Whostmgr::ACLS::hasroot() ) {
print "Can not leave FTP accounts enabled without the 'all' ACL.\n";
return 1;
}
if ( Cpanel::AcctUtils::Suspended::is_suspended($user) && !$force ) {
print "User '$user' is already suspended. Provide '--force' argument if you wish to do this.\n";
return 1;
}
if ( !$child_ok ) {
my $cpuser_obj = Cpanel::Config::LoadCpUserFile::load_or_die($user);
if ( $cpuser_obj->child_workloads() ) {
print "To suspend “$user”, do so on the account’s parent node.\n";
return 1;
}
}
# this one doesn't seem to exist
if ( !do_hook( $user, $reason, $prevent_reseller_unsuspend, 'pre' ) ) {
print "Pre-suspend hook script returned failure.\n";
return 1;
}
system '/usr/local/cpanel/scripts/presuspendacct', @args if -x '/usr/local/cpanel/scripts/presuspendacct';
$ENV{'REMOTE_USER'} ||= 'root';
Whostmgr::ACLS::init_acls();
my ( $pass, $homedir, $shell ) = ( Cpanel::PwCache::getpwnam($user) )[ 1, 7, 8 ];
my $host;
AcctLock::acctlock();
print "Changing Shell to /bin/false...";
try {
Cpanel::Passwd::Shell::update_shell_without_acctlock( 'user' => $user, 'shell' => '/bin/false' );
}
catch {
print Cpanel::Exception::get_string($_);
};
print "Done\n";
print "Locking Password...";
my ( $status, $statusmsg ) = Cpanel::Auth::Shadow::update_shadow_without_acctlock( $user, '!!' . ( Cpanel::PwCache::getpwnam($user) )[1] );
print $statusmsg if !$status;
print "Done\n";
AcctLock::acctunlock();
Cpanel::Auth::Digest::DB::Manage::lock($user) if Cpanel::Auth::Digest::DB::Manage::has_entry($user);
my $owner = Cpanel::AcctUtils::Owner::getowner($user);
$owner =~ s/\n//g;
my $domain = Cpanel::AcctUtils::Domain::getdomain($user);
if ( $owner eq '' || $owner eq 'root' || $user eq $owner ) {
$host = Cpanel::Hostname::gethostname();
}
else {
$host = $domain;
}
if ( !$host ) {
$host = Cpanel::Hostname::gethostname();
}
my $susp_info_hr = {
'shell' => $shell,
'leave-ftp-accts-enabled' => $leave_ftp_enabled,
};
my $suspend_data = Whostmgr::Accounts::SuspensionData::Writer->new();
if ( $prevent_reseller_unsuspend == 1 ) {
$suspend_data->suspend_locked( $user, $reason // q<>, $susp_info_hr );
}
else {
$suspend_data->suspend_unlocked( $user, $reason // q<>, $susp_info_hr );
}
# session deletion and then
# kill -9 must be done after the suspendfile is created
# to ensure cpsrvd will not allow any more processes
# to be created as the user. this also avoids having to check
# each cpsrvd request
Cpanel::Session::SinglePurge::purge_user( $user, 'suspend' );
Cpanel::Sys::Kill::kill_pids_owned_by( $user, '-9' );
my $cpuser_guard = Cpanel::Config::CpUserGuard->new($user);
my $cpuser_data = $cpuser_guard->{'data'};
my @DNS = ( $cpuser_data->{'DOMAIN'} );
if ( exists $cpuser_data->{'DOMAINS'} ) {
push @DNS, @{ $cpuser_data->{'DOMAINS'} };
}
mkdir( "$Cpanel::ConfigFiles::MAILMAN_ROOT/suspended.lists", 0755 );
{
my $tempquota = Cpanel::Quota::Temp->new( user => $user );
$tempquota->disable();
if ( -f "$homedir/etc/webdav/shadow" && !-l "$homedir/etc/webdav/shadow" ) {
print "Suspending webdav users\n";
suspendshadowfile( $user, "$homedir/etc/webdav/shadow" );
}
foreach my $dns (@DNS) {
$dns = Cpanel::Validate::Domain::Normalize::normalize( $dns, 1 );
next if !Cpanel::Validate::Domain::Tiny::validdomainname($dns);
if ( -f "${homedir}/etc/${dns}/shadow"
&& !-l "${homedir}/etc/${dns}/shadow" ) {
print "Suspending email account logins for ${dns} .... ";
suspendshadowfile( $user, "${homedir}/etc/${dns}/shadow" );
print "Done\n";
}
}
#This will recreate the files in the user homedir,
#so we want to do it under a quota-lift.
Cpanel::Dovecot::Action::flush_all_auth_caches_for_user($user);
}
# Suspend team_user's if exists.
if ( -e "$Cpanel::Team::Constants::TEAM_CONFIG_DIR/$user" ) {
print "Suspending team account ... ";
eval { Cpanel::Team::Config->new($user)->suspend_team(); };
$@ ? warn "Unable to suspend Team Account" : print "Done\n";
}
my $dns_list = join( '|', map { quotemeta($_) } @DNS );
my $list_files = Cpanel::FileUtils::Match::get_matching_files( "$Cpanel::ConfigFiles::MAILMAN_ROOT/lists", "_(?:$dns_list)" . '$' );
foreach my $list ( @{$list_files} ) {
my ($list_name) = $list =~ m{^.*/([^/]+)$};
$list_name =~ tr{_}{@};
print "Suspending mailing list for $list_name\n";
my $suspended_list = $list;
$suspended_list =~ s/\/lists\//\/suspended.lists\//;
if ( -e $suspended_list ) { rename( $suspended_list, $suspended_list . '.' . time() ) }
rename( $list, $suspended_list );
}
if ( Cpanel::Services::Enabled::are_provided('mysql') ) {
print "Suspending mysql users\n";
Cpanel::MysqlUtils::Suspension::suspend_mysql_users($user);
}
# FIXME: Everything in this script should eventually be done via
# this function call (or similar logic).
try {
Whostmgr::Accounts::Suspend->new(
$user,
reason => $reason,
prevent_reseller_unsuspend => $prevent_reseller_unsuspend,
);
}
catch {
warn Cpanel::Exception::get_string($_);
};
my %account_creation_notification = (
'user' => $user,
'user_domain' => $domain,
'reason' => $reason,
'env_remote_user' => $ENV{'REMOTE_USER'},
'env_user' => $ENV{'USER'},
'host_server' => $host,
'origin' => 'Suspend Account',
'source_ip_address' => Cpanel::IP::Remote::get_current_remote_ip(),
);
# send root notification
Cpanel::Notify::notification_class(
'class' => 'suspendacct::Notify',
'application' => 'suspendacct::Notify',
'constructor_args' => [%account_creation_notification]
);
# send one to account reseller as well as long as they are not root
if ( $owner ne 'root' ) {
Cpanel::Notify::notification_class(
'class' => 'suspendacct::Notify',
'application' => 'suspendacct::Notify',
'constructor_args' => [ %account_creation_notification, 'to' => $owner, 'username' => $owner ]
);
}
if ( $pass =~ /^\!/ || $pass =~ /^\*/ ) {
print "Account previously suspended (password was locked).\n";
}
$cpuser_data->{'SUSPENDTIME'} = time();
$cpuser_data->{'SUSPENDED'} = 1;
$cpuser_guard->save();
my $user_crontab_dir = Cpanel::OS::user_crontab_dir();
if ( !-e "$user_crontab_dir.suspended" ) {
mkdir( "$user_crontab_dir.suspended", 0700 );
}
if ( -f "$user_crontab_dir/${user}" ) {
link( "$user_crontab_dir/${user}", "$user_crontab_dir.suspended/${user}" );
unlink("$user_crontab_dir/${user}");
}
Cpanel::SafetyBits::safe_chmod( 0000, $user, "${homedir}/public_ftp" );
my $tempquota = Cpanel::Quota::Temp->new( user => $user );
$tempquota->disable();
print "Suspending websites...\n";
_generate_account_suspension_include($user);
$tempquota->restore();
_suspend_ftp($user) if not $leave_ftp_enabled;
Cpanel::ServerTasks::schedule_task( ['CpDBTasks'], 10, "ftpupdate" );
print "Suspending outgoing email....";
Whostmgr::Accounts::Email::suspend_outgoing_email( 'user' => $user );
print "Done\n";
print ${user} . "'s account has been suspended\n";
Cpanel::AcctUtils::AccountingLog::append_entry( 'SUSPEND', [ $user, $domain, $reason ] );
Cpanel::PwCache::Clear::clear_global_cache();
do_hook( $user, $reason, $prevent_reseller_unsuspend, 'post' );
system '/usr/local/cpanel/scripts/postsuspendacct', @args if -x '/usr/local/cpanel/scripts/postsuspendacct';
return;
}
# TODO: Refactor this function (along with the unsuspension logic)
# to a Whostmgr::Accounts::Suspension::* module.
sub _suspend_ftp {
my ($username) = @_;
my $ftpfile = "$Cpanel::ConfigFiles::FTP_PASSWD_DIR/$username";
my $ftplock = Cpanel::SafeFile::safelock($ftpfile); # Manipulation of these files isn't thread safe.
if ( -e $ftpfile && !-e $ftpfile . '.suspended' && -e "/var/cpanel/suspended/$username" ) {
print "Suspending FTP accounts...\n";
my ( $ok, $err ) = Cpanel::FileUtils::Copy::copy( $ftpfile, qq{$ftpfile.suspended} );
if ($err) {
warn "Could not copy $ftpfile to $ftpfile.suspended: $err";
}
else {
Cpanel::FileUtils::Write::overwrite_no_exceptions( $ftpfile, '# Account suspended', 0640 );
}
}
Cpanel::SafeFile::safeunlock($ftplock);
return;
}
sub is_valid_user {
my $user = shift;
my $pass = ( Cpanel::PwCache::getpwnam_noshadow($user) )[1];
if ( !defined $pass ) {
$user = Cpanel::AcctUtils::DomainOwner::Tiny::getdomainowner( $user, { 'default' => '' } );
return 0 if !$user;
$pass = ( Cpanel::PwCache::getpwnam_noshadow($user) )[1];
return 0 if !defined $pass;
}
return is_forbidden_user($user) ? 0 : 1;
}
sub is_forbidden_user {
my ($user) = @_;
return ( grep { $user eq $_ } Cpanel::Validate::Username::list_reserved_usernames() ) ? 1 : 0;
}
# helpers
sub suspendshadowfile {
my ( $user, $file ) = @_;
# user cannot be root, tested previously
# we should not write file as root in the user's home directory...
my $access_ids = Cpanel::AccessIds::ReducedPrivileges->new($user);
return _suspendshadowfile($file);
}
sub _suspendshadowfile {
my ($file) = @_;
my @shadow_file;
my $shadowlock = Cpanel::SafeFile::safeopen( \*SHF, '<', $file );
if ($shadowlock) {
@shadow_file = <SHF>;
Cpanel::SafeFile::safeclose( \*SHF, $shadowlock );
undef $shadowlock;
}
else {
if ( -e $file ) {
warn "Failed to read $file: $!";
return;
}
else {
return 1;
}
}
if (@shadow_file) {
$shadowlock = Cpanel::SafeFile::safeopen( \*SHF, '>', $file );
if ($shadowlock) {
foreach (@shadow_file) {
chomp;
next if $_ !~ m{\S}; # ensure we're not processing a blank line.
my @DC = split( /:/, $_ );
foreach my $field ( 1, 8 ) {
$DC[$field] = '' unless defined $DC[$field];
if ( $DC[$field] !~ m/^\*LOCKED\*/ ) {
$DC[$field] = "*LOCKED*" . $DC[$field];
}
}
print SHF join( ':', map { defined $_ ? $_ : '' } @DC ) . "\n";
}
truncate( SHF, tell(SHF) );
Cpanel::SafeFile::safeclose( \*SHF, $shadowlock );
}
else {
warn "Failed to update $file: $!";
return;
}
return 1;
}
else {
return 1;
}
}
sub do_hook {
my ( $user, $reason, $prevent_reseller_unsuspend, $stage ) = @_;
my ( $result, $hooks_msgs ) = Cpanel::Hooks::hook(
{
'category' => 'Whostmgr',
'event' => 'Accounts::suspendacct',
'stage' => $stage,
'escalateprivs' => 1,
},
{
'args' => {
'user' => $user,
'reason' => $reason,
'disallowun' => $prevent_reseller_unsuspend,
},
'result' => 1,
'user' => 'root',
},
);
if ( ref $hooks_msgs eq 'ARRAY' && @$hooks_msgs != 0 ) {
foreach my $error ( @{$hooks_msgs} ) {
print $error;
}
return 0;
}
return 1;
}
sub _generate_account_suspension_include {
require "/usr/local/cpanel/scripts/generate_account_suspension_include"; ## no critic qw(Modules::RequireBarewordIncludes) -- refactoring this is too large
generate_account_suspension_include::update_include_and_restart_httpd();
return 1;
}
sub usage {
my ( $retval, $msg ) = @_;
my $fh = $retval ? \*STDERR : \*STDOUT;
my $p = $0;
$p =~ s{^.+/(.+)$}{$1};
if ( !defined $msg ) {
$msg = <<EOF;
Usage: $p user [reason] [disallow] [--leave-ftp-accts-enabled] [--child-ok] [--force] [--usage | --help]
Suspend a user's account with possibly a more stringent
suspension as determined by disallow.
where
user -- is a valid user name (required)
reason -- is a quote bound description for the suspension
and is written into the /var/cpanel/suspended/<user> file
(optional)
disallow -- is for additionally generating a user.lock file
in /var/cpanel/suspended and to issue this the argument needs to
be 1 (optional)
Note that the order of user, reason and disallow must be maintained.
Users with reserved usernames (e.g. root and nobody) cannot be suspended.
--leave-ftp-accts-enabled -- FTP accounts associated with the
cPanel account are left enabled. **WARNING** Do not use this flag unless
you have considered the security implications. This will allow suspended
users continued access to the server.
The --force argument will allow for the suspension process to be run against an
already suspended account.
The --child-ok argument defeats the usual protection against
suspending distributed accounts on child nodes. Ordinarily you should
suspend and unsuspend distributed accounts on their parent nodes.
Use of this flag is UNSUPPORTED.
Now supports driving instructions via --help, --usage
EOF
}
print {$fh} $msg;
return $retval;
}
1;
Rosenblum TV: Video training, virtual workshops, classes, tutorials
RE-INVENTING THE TELEVISION NEWS BUSINESS*
A revolution in video storytelling
Creating entirely new & cost-effective production methods
From the world leaders in video production training and the creators of Character Driven Storytelling™
*and every other business that uses video
WHAT WE DO
Over the past 35 years, we have designed, built or restructured some of the most powerful news and journalism companies in the world.
We replace the traditional TV news ‘crew’ with one highly trained journalist, working alone with nothing but an iPhone.
No more TV news ‘crews’, no editors and no field producers.
This is television news done the way newspaper journalism is done – one reporter with their electronic pad and pencil.
In doing this, we can cut the cost of production by as much as 75% while increasing ratings and audience engagement.
In the place of conventional TV news ‘packages’ – ie, reporter stand up, interview, b-roll, man on the street, we marry great journalism with Netflix and Hollywood storytelling.
It’s a combination that works.
We have taken most of our clients to #1 in their respective markets.
And it’s not just for news. Any company, any profit, any NGO and anyone else who is online needs to tell their story in compelling yet cost-effective video. We can teach you to do that. Either in person or virtually.
EXAMPLES OF WHAT WE CAN TEACH YOUR STAFF TO PRODUCE
ITAY HOD
Itay Hod, MMJ with KPIX/CBS in San Francisco, took the 5-Day Intensive Video Storytelling Bootcamp in 2018.
Because he works alone, with only an iPhone, he was able to embed himself with a homeless family.
Here’s the story he produced in a one-day turn.
KIET DO
Kiet Do, an MMJ with KPIX/CBS in San Francisco, took the 5-Day Intensive Video Storytelling Bootcamp in 2021.
Here is a story he produced, all on his own, with only an iPhone and in a one-day turn.
TAYLOR SCHAUB
Taylor Schaub, an MMJ with Spectrum News 1 in LA, took the 5-Day Intensive Video Storytelling Bootcamp in 2023.
Here is a story he turned in only one day, using only an iPhone. It was the first video story he ever did and it was nominated for an Emmy.
THE BOOTCAMP
How do we convert stations and whole networks to working in this way?
Since 1988, we have run intensive 5-Day Video Storytelling Bootcamps
We have done these all over the world.
These are hands-on bootcamps, and participants learn an entirely new way of creating TV news stories.
-We shoot at a 3:1 ratio or lower, so turnaround times are fast.
-We go directly from camera to timelilne and edit – no written scripts. We work in the medium of pictures and sound.
-We are entirely character-driven.
-We are driven by pictures and real events.
-We are focused almost entirely on ’the viewer experience’.
Since 1988, more than 70,000 journalists around the world have taken our bootcamps, either in person on virtualy.
We have started to work with CBS News, bringing our ideas of character-driven storytelling to one of the most successful and biggest networks in the United States. Since beginning to work with them ratings have climbed and more importantly, audience engagement is through the ceiling.
We started New York Times Television in 1990 and it was the first paper to be brought into the world of TV. It quickly became one of the most successful non-fiction production companies in the United States. The series and documentaries we produced won many awards including multiple Emmys.
We have been working with the BBC since the year 2000 helping to convert their national news network to our visual storytelling technique. Most recently we have trained teams from their sports, documentaries, and comedy divisions to make character-driven stories using only smartphones.
For the past five years we have worked with Spectrum News to introduce and train their journalists on visual, character driven storytelling using smartphones helping to create a different kind of local news for their network of 24-Hour News Stations across the United States.
In 2006, we were approached by the United Nations. Rather than rely on news outlets, it would be much easier to train the field operatives to produce their own stories. We spent two years working with the UN, training more than 100 of their staff in bootcamps in Geneva and Nairobi.
We trained 50 print reporters at the paper to shoot and tell their own stories, in conjunction with their print work. We built a TV newsroom in their existing print newsroom – you could not ask for a better set and they began to live stream their stories in conjunction with their print work.
We spent two years with McGraw Hill, training more than 150 of their staffers, making them completely video literate. McGraw/Hill media properties we transit included Business Week, Aviation Week, (what was the name of the architecture magazine), and JD Power and Associates.
In 1990, we were approached by The Voice of America, the official broadcasting agency for the United States Government. When we met with VOA, they were only a short wave radio broadcaster, but working with them, we took them into television, launching VOA-TV.
British based Oyster Yachts makes some of the finest yachts in the world. Like every other company, they had to find a way to feed the never-ending video demands of social media – sites like Instagram and TikTok. We trained the Oyster staff to tell their own stories, using only iPhones.
We were approached by SEPA, the Scottish Environmental Protection Agency because they had to continually find a way to ‘feed the media beast’. The result was that SEPA was able to tell their own stories, whenever they wanted, and at almost no additional cost.
Michael Rosenblum has been writing about the media since 1988. His work and ideas have appeared in The Guardian, The Huffington Post, Ilkeston Life and many other publications.
He has been blogging regularly for the past 35 years on this subject. Having taught media studies at Columbia University, NYU and now the University of Oxford, he is considered an expert on this subject.
Continue reading this post or look back at previous posts.