MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/editquota
#!/usr/bin/perl
# cpanel - editquota                              Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use strict;
use warnings;
use Cpanel::cPQuota;
use Cpanel::FindBin            ();
use Cpanel::Logger             ();
use Cpanel::OSSys              ();
use Cpanel::LoadFile           ();
use Cpanel::SafeRun::Errors    ();
use Cpanel::Config             ();
use Cpanel::Config::Numeric    ();
use Cpanel::Config::LoadCpConf ();

$| = 1;

if ( !@ARGV ) {
    print "Usage: editquota <user> <?M>\n";
    exit 1;
}

my $user     = $ARGV[0];
my $quot     = $ARGV[1];
my $quotaoff = $ARGV[2] || '';

if ( !defined $user || ( ( $user =~ m/^\d+$/ && !getpwuid($user) ) && !getpwnam($user) ) ) {
    print "Invalid user\n";
    print "Usage: editquota <user> <?M>\n";
    exit 1;
}

my $megquota;
if ( !defined $quot || ( $quot !~ m/^\d+M$/i && $quot !~ m/unlimited/i ) ) {
    print "Invalid quota\n";
    print "Usage: editquota <user> <?M>\n";
    exit 1;
}

my %cmd = (
    'quotaon'  => undef,
    'quotaoff' => undef,
    'edquota'  => undef,
    );
my @missing_cmds;
foreach my $cmd_name ( keys %cmd ) {
    $cmd{$cmd_name} = Cpanel::FindBin::findbin( $cmd_name );
    if ( !-x $cmd{$cmd_name} ) {
        push @missing_cmds, $cmd_name;
    }
}
if ( scalar @missing_cmds ) {
    print "Incomplete quota kit: unable to edit quotas.\n";
    print 'Missing commands: ', join( ', ', @missing_cmds ), "\n";
    exit 1;
}


if ( $user =~ m/^\d+$/ ) {
    $user = ( getpwuid($user) )[0];
}

if ( $user =~ /^cpanel(horde|phpmyadmin|phppgadmin|roundcube|sqmail)$/ ) {
    $quot = 0;
}

if ( $quot !~ m/unlimited/i ) {
    $quot =~ s/M$//i;
    $megquota = $quot;       # Store original value for vsrvmgradmin
    $quot     = int $quot;
}
else {
    $quot     = 0;
    $megquota = $quot;
}

my $logger = Cpanel::Logger->new();

my $quotaconf_ref = Cpanel::Config::Numeric::load_numeric_Config('/etc/quota.conf');
if ( !$quotaconf_ref ) {
    $logger->die('Unable to fetch quota configuration');
}

$quotaconf_ref->{$user} = $quot;

if ( !Cpanel::Config::flushConfig( '/etc/quota.conf', $quotaconf_ref ) ) {
    $logger->die('Unable to save quota configuration');
}

if ( -e '/vsrvmgrq' ) {
    $user = ( getpwnam($user) )[2];
    system( '/usr/local/cpanel/bin/vsrvmgradmin', 0, 'EDITQUOTA', $user, $megquota );
    exit;
}

$quot = ( $quot * 1024 );
$quot = sprintf( '%.0f', $quot );    # convert back from scientific notation

$ENV{'NQUOTA'} = $quot;
$ENV{'VISUAL'} = '/scripts/pedquota';
$ENV{'EDITOR'} = '/scripts/pedquota';

## Some systems require that the quotas be disabled
## prior to modifying them.
my $has_broken_quota_system = $quotaoff ? 1 : 0;

my $envtype = Cpanel::LoadFile::loadfile('/var/cpanel/envtype') || 'standard';

if ( $envtype !~ m/cpanel-vserver/ ) {    # Never disable/enable quotas for cpanel-vserver

    # Always disable/enable quotas for virtuozzo
    if ( $envtype =~ m/zzo/ ) {
        $has_broken_quota_system = 1;
    }
    else {
        my $cpconf_ref = Cpanel::Config::LoadCpConf::loadcpconf();
        my ( $system, $nodename, $release, $version, $machine ) = Cpanel::OSSys::uname();

        # Linux 2.4 kernels will always disable/enable quotas
        if ( $system =~ m/linux/i && $release =~ m/^2\.4/ ) {
            $has_broken_quota_system = 1;
        }

        elsif ( $cpconf_ref->{'use_safe_quotas'} ) {
            $has_broken_quota_system = 1;
        }
    }
}

if ($has_broken_quota_system) {
    Cpanel::SafeRun::Errors::saferunnoerror( $cmd{'quotaoff'}, '-a' );
}
system $cmd{'edquota'}, '-u', $user;

# Invalidate the repquota.datastore file but leave it in case something
# does not care about the valitity period (ie account transfer getacctlist)
if ( -e '/var/cpanel/repquota.cache' ) {
    utime 0, 0, '/var/cpanel/repquota.cache';
}
if ( -e '/var/cpanel/repquota.datastore' ) {
    utime 0, 0, '/var/cpanel/repquota.datastore';
}

# Update quota file mtimes
Cpanel::cPQuota::updatemtime();

unlink('/var/cpanel/overquota/' . $user); #case 36820

if ($has_broken_quota_system) {
    Cpanel::SafeRun::Errors::saferunnoerror( $cmd{'quotaon'}, '-a' );
}