Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[r1090]: branches / 2.5.4 / cgi-bin / yabb2 / Sources / Freespace.pm Maximize Restore History

Download this file

Freespace.pm    129 lines (108 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
###############################################################################
# Freespace.pm #
# $Date: 2013-07-14 17:10:34 +0000 (Sun, 14 Jul 2013) $
###############################################################################
# YaBB: Yet another Bulletin Board #
# Open-Source Community Software for Webmasters #
# Version: YaBB 2.5.4 #
# Packaged: July 1, 2013 #
# Distributed by: http://www.yabbforum.com #
# =========================================================================== #
# Copyright (c) 2000-2013 YaBB (www.yabbforum.com) - All Rights Reserved. #
# Software by: The YaBB Development Team #
# with assistance from the YaBB community. #
###############################################################################
# use strict;
# use warnings;
no warnings qw(uninitialized once redefine);
use CGI::Carp qw(fatalsToBrowser);
use English qw(-no_match_vars);
our $VERSION = '2.5.4';
$freespacepmver = 'YaBB 2.5.4 $Revision: 1090 $';
sub freespace {
my ( $FreeBytes, $hostchecked );
if ( $OSNAME =~ /Win/sm ) {
if ($enable_freespace_check) {
my @x =
qx{DIR /-C}; # Do an ordinary DOS dir command and grab the output
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$/sm ) {
$FreeBytes = $3 - 100_000; # 100000 bytes reserve
}
}
else {
return;
}
$yyfreespace = 'Windows';
}
else {
if ($enable_quota) {
my @quota = qx{quota -u $hostusername -v};
# Do an ordinary *nix quota command and grab the output
return -1 if !$quota[2];
# error trapping if output fails.
@quota = split / +/sm, $quota[$enable_quota], 5;
$quota[2] =~ s/\*//xsm;
$FreeBytes =
( ( $quota[3] - $quota[2] ) * 1024 ) -
100_000; # 100000 bytes reserve
$hostchecked = 1;
}
elsif ($findfile_maxsize) {
( $FreeBytes, $hostchecked ) = split /<>/xsm, $findfile_space;
if ( $FreeBytes < 1 || $hostchecked < $date ) {
# fork the process since the *nix find command can take a while
$child_pid = fork;
if ( !$child_pid ) { # child process runs here and exits then
$findfile_space = 0;
map { $findfile_space += $_ }
split /-/xsm,
qx(find $findfile_root -noleaf -type f -printf '%s-');
$findfile_space =
( ( $findfile_maxsize * 1024 * 1024 ) - $findfile_space )
. '<>'
. ( $date + ( $findfile_time * 60 ) );
# actual free host space <> time for next check
require Admin::NewSettings;
SaveSettingsTo('Settings.pm');
exit 0;
}
}
$hostchecked = 1;
}
elsif ($enable_freespace_check) {
my @x = qx{df -k .};
# Do an ordinary *nix df -k . command and grab the output
my $lastline = pop @x;
# should look like: /dev/path 151694892 5495660 134063644 4% /
if ( $lastline !~ m/\%/xsm ) { return -1; }
# error trapping if output fails. The % sign should be in the line
$FreeBytes =
( ( split / +/sm, $lastline, 5 )[3] * 1024 ) -
100_000; # 100000 bytes reserve
}
else {
return;
}
$yyfreespace = 'Unix/Linux/BSD';
}
if ( $FreeBytes < 1 ) { automaintenance( 'on', 'low_disk' ); }
if ( $FreeBytes >= _1073_741_824 ) {
$yyfreespace = sprintf '%.2f',
$FreeBytes / ( 1024 * 1024 * 1024 ) . " GB ($yyfreespace)";
}
elsif ( $FreeBytes >= 1_048_576 ) {
$yyfreespace = sprintf '%.2f',
$FreeBytes / ( 1024 * 1024 ) . " MB ($yyfreespace)";
}
else {
$yyfreespace =
sprintf( '%.2f', $FreeBytes / 1024 ) . " KB ($yyfreespace)";
}
return $hostchecked;
}
1;