###############################################################################
# Checkspace.pm #
# $Date: 26.7.26 $ #
###############################################################################
# YaBB: Yet another Bulletin Board #
# Open-Source Community Software for Webmasters #
# Version: YaBB 2.6.15 #
# Packaged: July 26, 2026 #
# Distributed by: https://yabbforum.nz #
# =========================================================================== #
# Copyright (c) 2000-2026 YaBB (yabbforum.nz) - All Rights Reserved. #
# Software by: The YaBB Development Team #
# with assistance from the YaBB community. #
###############################################################################
use CGI::Carp qw(fatalsToBrowser);
use English '-no_match_vars';
our $VERSION = '2.6.15';
$checkspacepmver = 'YaBB 2.6.15 $Revision: 2601 $';
if ( $action eq 'detailedversion' ) { return 1; }
sub checkspace {
is_admin_or_gmod();
# Free Disk Space Checking
if ( $OSNAME =~ /Win/sm ) {
open my $fh, q{-|}, 'DIR /-C' or croak "Can't open pipe: $!";
my @x = <$fh>;
close $fh or croak "Can't close pipe: $!";
my $lastline = pop @x;
# should look like: 17 Directory(s), 21305790464 Bytes free
return -1
if $lastline !~ m/byte/ism;
# error trapping if output fails. The word byte should be in the line
if ( $lastline =~ /^\s+(\d+)\s+(.+?)\s+(\d+)\s+(.+?)\n$/xsm ) {
$FreeBytes = $3 - 100_000;
} # 100000 bytes reserve
if ( $FreeBytes >= 1_073_741_824 ) {
$yyfreespace =
sprintf( '%.2f', $FreeBytes / ( 1024 * 1024 * 1024 ) ) . ' GB';
}
elsif ( $FreeBytes >= 1_048_576 ) {
$yyfreespace =
sprintf( '%.2f', $FreeBytes / ( 1024 * 1024 ) ) . ' MB';
}
else {
$yyfreespace = sprintf( '%.2f', $FreeBytes / 1024 ) . ' KB';
}
@disk_space = $yyfreespace;
}
else {
open my $dsh, q{-|}, 'df -k .' or croak "Can't open pipe: $!";
@disk_space = <$dsh>;
close $dsh or croak "Can't close pipe: $!";
map { $_ =~ s/ +/ /gsm } @disk_space;
open my $ffh, q{-|}, 'find . -noleaf -type f -printf "%s-"'
or croak "Can't open pipe: $!";
my @find = <$ffh>;
close $ffh or croak "Can't close pipe: $!";
}
$hostusername = $hostusername
|| ( split / +/sm, qx{ls -l YaBB.$yyext} )[2];
my @quota = qx{quota -u $hostusername -v};
$quota[0] =~ s/^ +//sm;
$quota[0] =~ s/ / /gsm;
$quota[1] =~ s/^ +//sm;
$quota[1] =~ s/ / /gsm;
my $quota_select = qq~$quota[0]
$quota[1]~;
if ( $quota[2] ) {
if ( !$enable_quota ) { $ds = ( split / +/sm, $disk_space[1], 2 )[0]; }
$my_q_select =
isselected( $i == $enable_quota
|| ( $ds && $quota[$i] =~ /^$ds/sm ) );
$quota_select .= q~
';
}
# }
$ch_spc = ischecked($enable_freespace_check);
$ch_enable_q = ischecked($enable_quota);
@settings = (
{
name => $settings_txt{'checkspace'},
id => 'checkspace',
items => [
{ header => $settings_txt{'freedisk'}, },
{
description =>
qq~~,
input_html =>
q~~,
name => 'enable_quota',
validate => 'boolean',
depends_on => (
!$quota[2] ? []
: [
'!enable_freespace_check',
'(findfile_time==0||',
'findfile_time==||',
'findfile_maxsize==0||',
'findfile_maxsize==)'
]
),
},
{
description =>
qq~~,
input_html => (
$quota[2] ? $quota_select
: q~~
),
name => 'enable_quota_value',
validate => 'number,null',
depends_on => ['enable_quota'],
},
{
description =>
qq~~,
input_html =>
qq~~,
name => 'hostusername',
validate => 'text,null',
depends_on => ['enable_quota'],
},
{
description =>
qq~~,
input_html =>
q~ $admin_txt{'537'}~,
name => 'findfile_time',
validate => 'number,null',
depends_on => (
@find ? [ '!enable_quota', '!enable_freespace_check' ]
: []
),
},
{
description =>
qq~~,
input_html =>
qq~~,
name => 'findfile_root',
validate => 'text,null',
depends_on => (
@find ? [ '!enable_quota', '!enable_freespace_check' ]
: []
),
},
{
description =>
qq~~,
input_html =>
qq~ MB~,
name => 'findfile_maxsize',
validate => 'number,null',
depends_on => (
@find ? [ '!enable_quota', '!enable_freespace_check' ]
: []
),
},
{
description =>
qq~~,
input_html =>
qq~
@disk_space~, name => 'enable_freespace_check', validate => 'boolean', depends_on => [ '!enable_quota', '(findfile_time==0||', 'findfile_time==||', 'findfile_maxsize==0||', 'findfile_maxsize==)' ], }, ], }, ); chsettings(); $action_area = 'checkspace'; AdminTemplate(); exit; } sub chsettings { is_admin_or_gmod(); $yytitle = $admin_txt{'checkspclabel'}; $page = 'checkspace'; my @requireorder; # an array for the correct order of the requirements my %requirements; # a hash that says "Y is required by X" $yymain .= qq~
| $yytitle |
$admin_txt{'347'} |