Current File : //scripts/update_existing_mail_quotas_for_account
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/update_existing_mail_quotas_for_account
#                                                  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::update_existing_mail_quotas_for_account;

use cPstrict;

use parent qw( Cpanel::HelpfulScript );

use Cpanel::AcctUtils::Account ();
use Cpanel::Config::Users      ();
use Cpanel::JSON               ();
use Cpanel::PIDFile            ();
use Cpanel::SafeRun::Errors    ();

use Try::Tiny;

=encoding utf-8

=head1 NAME

scripts::update_existing_mail_quotas_for_account

=head1 SYNOPSIS

    update_existing_mail_quotas_for_account [ --all --quota <quota_in_megabytes> | --user <username> --quota <quota_in_megabytes> | --help ]

    NOTE: <quota_in_megabytes> must be a positive integer.  Use 0 for unlimited or maximum allowed quota (based on MAX_EMAILACCT_QUOTA for account).

=head1 DESCRIPTION

This command will update the quota for all existing email accounts for a given user
or for all users on the system

=cut

our $PID_FILE = '/var/run/update_existing_mail_quotas_for_account.pid';

# Use bin/uapi instead of Cpanel::API::execute because this script is uncompiled
# and the API code we need is not shipped
our $uapi_bin = '/usr/local/cpanel/bin/uapi';

sub _OPTIONS {
    return qw( user=s all quota=i );
}

__PACKAGE__->new(@ARGV)->script() unless caller();

sub script ($self) {

    my $quota = $self->getopt('quota');
    if ( !defined $quota || $quota < 0 ) {
        print "\n" . $self->help();
        return;
    }

    if ( $self->getopt('user') ) {
        my $user = $self->getopt('user');
        print "Changing quota to ‘${quota}MB’ for all email accounts owned by the user ‘$user’\n";

        try {
            $self->call_for_one_user( $user, $quota );
        }
        catch {
            warn "There was an error updating the quotas of all email addresses for ‘$user’: $_\n";
        };

        return;
    }
    elsif ( !$self->getopt('all') ) {
        print "\n" . $self->help();
        return;
    }

    Cpanel::PIDFile->do(
        $PID_FILE,
        sub {
            print "Changing quota to ‘${quota}MBs’ for all email accounts of all users\n";

            for my $user ( Cpanel::Config::Users::getcpusers() ) {
                try {
                    $self->call_for_one_user( $user, $quota );
                }
                catch {
                    warn "There was an error updating the quotas of all email addresses for ‘$user’: $_\n";
                };
            }
        }
    );

    return;
}

sub call_for_one_user ( $self, $user, $quota ) {

    Cpanel::AcctUtils::Account::accountexists_or_die($user);

    my $mail_accounts = $self->get_mail_accounts($user);
    foreach my $mail_account (@$mail_accounts) {
        my ( $email, $domain ) = split /@/, $mail_account;
        try {
            print "… updating ‘$mail_account’ account for ‘$user’ user\n";
            $self->update_mail_quota( { user => $user, quota => $quota, email => $email, domain => $domain } );
        }
        catch {
            warn "There was an error updating the quota for ‘$mail_account’: $_\n";
        };
    }

    return;
}

sub update_mail_quota ( $self, $opts ) {

    my $json = Cpanel::SafeRun::Errors::saferunnoerror(
        $uapi_bin,
        $< ? () : ( '--user', $opts->{user} ),    # if we are running as root, we need to tell it which user to run the API call for
        '--output', 'json',
        'Email',    'edit_pop_quota',
        'email',    $opts->{email},
        'domain',   $opts->{domain},
        'quota',    $opts->{quota},
    );
    my $res = Cpanel::JSON::Load($json);

    if ( !$res->{result}{status} ) {
        my $errors = join( "\n", @{ $res->{result}{errors} } );
        die "Email::list_pops API call failed:  $errors";
    }

    return;
}

sub get_mail_accounts ( $self, $user ) {

    my $json = Cpanel::SafeRun::Errors::saferunnoerror(
        $uapi_bin,
        $< ? () : ( '--user', $user ),    # if we are running as root, we need to tell it which user to run the API call for
        '--output', 'json',
        'Email',    'list_pops',
    );
    my $res = Cpanel::JSON::Load($json);

    if ( !$res->{result}{status} ) {
        my $errors = join( "\n", @{ $res->{result}{errors} } );
        die "Email::list_pops API call failed:  $errors";
    }

    my $data     = $res->{result}{data};
    my $accounts = [];
    foreach my $account_href ( @{ $res->{result}{data} } ) {
        next if $account_href->{login} eq 'Main Account';
        push @$accounts, $account_href->{login};
    }

    return $accounts;
}

1;
Seguro Celular
Home business sonyw300 6 de febrero de 2020
SEGURO PARA CUALQUIER MOMENTO
Evita cualquier situación con nuestro seguro para celular.

Contar con un seguro para celular te brinda una protección integral contra situaciones comunes como robo, accidentes y pérdida. No solo te ahorrará dinero en reparaciones o reemplazos, sino que también te proporcionará la tranquilidad de saber que estás respaldado en caso de cualquier eventualidad. Es una inversión inteligente para salvaguardar tu dispositivo, tus datos y tu tranquilidad.

De viaje
Protegido siempre ante cualquier imprevisto
Contratar ahora!
Robo
Asegura tu equipo ante un posible robo
Contratar ahora!
Accidentes
No pases un mal momento, protege tu dispositivo
Contratar ahora!
Previous slide
Next slide
¿Porqué seguro celular es para ti?
Nos comprometemos en brindarte la mejor protección para tu dispositivo
Cobertura mundial

Sea cual sea el problema estamos aquí para proteger tu inversión y brindarte la tranquilidad que necesitas.

Proceso de reclamación fácil y rápido

Sabemos que necesitas una solución rápida en caso de cualquier incidente.

Opciones personalizadas:

Ofrecemos opciones flexibles que se adaptan a tus requisitos individuales.

Atención al cliente excepcional

Estamos disponible para responder y brindarte asistencia personalizada en todo momento.

Tu tranquilidad está a
solo un clic de distancia

Protege tu dispositivo de cualquier imprevisto
TESTIMONIOS
¿Qué dicen nuestros
valiosos clientes?
"¡Increíble servicio de seguro para celular! Rápido, eficiente y confiable. Mi reclamo fue procesado sin problemas y recibí un reemplazo de mi teléfono en tiempo récord. ¡Gracias por brindar una excelente protección para mis dispositivos!"
male1085054890319
Herman Miller
"Me encanta la tranquilidad que me brinda su servicio de seguro para celular. Sé que mi dispositivo está protegido contra cualquier daño accidental o robo. Además, el proceso de reclamación es sencillo. Super recomendado!
female1021755931884
Sofia Millan
"Me ha salvado en más de una ocasión. El personal siempre está dispuesto a ayudar y resolver cualquier problema que surja. Gracias a su servicio, puedo disfrutar de mi teléfono sin preocupaciones.
male20131085934506012
Alexander Rodriguez