Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max_space option (issue 2) #4

Merged
merged 1 commit into from Jul 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config.php
Expand Up @@ -5,6 +5,7 @@

'base_path' => "/var/www/piratebox/",
'base_uri' => "/",
'max_space' => 80, // in percent
#'base_uploads' => "/var/spool/piratebox/public/uploads/",
#'base_chat' => "/var/spool/piratebox/public/chat/",

Expand Down
8 changes: 8 additions & 0 deletions controller.php
Expand Up @@ -177,6 +177,10 @@
exit('ERR:'.T_("Invalid directory."));
}

if(!hasAvailableSpace()) {
exit('ERR:'.T_("The file system has reached the maximum limit of space."));
}

if(empty($name)) {
exit('ERR:'.T_("Invalid filename."));
}
Expand Down Expand Up @@ -223,6 +227,10 @@
exit('ERR:'.T_("Unauthorized."));
}

if(!hasAvailableSpace()) {
exit('ERR:'.T_("The file system has reached the maximum limit of space."));
}

if(empty($cdir) || !is_dir($dirpath)) {
exit('ERR:'.T_("Invalid directory."));
}
Expand Down
1 change: 1 addition & 0 deletions framework.php
Expand Up @@ -34,6 +34,7 @@ function configure() {
option('debug', false);
option('base_path', $GLOBALS['options']['base_path'].'/');
option('base_uri', $GLOBALS['options']['base_uri'].'/');
option('max_space', $GLOBALS['options']['max_space']);

option('allow_renaming', $GLOBALS['options']['allow_renaming']);
option('allow_deleting', $GLOBALS['options']['allow_deleting']);
Expand Down
11 changes: 11 additions & 0 deletions functions.php
Expand Up @@ -238,3 +238,14 @@ function getFiles($dir, $newfiles = false) {

return $files;
}

function hasAvailableSpace() {
$command = sprintf('df %s | tail -n 1 | awk \'{print $5}\' | sed \'s/%%//\'', escapeshellarg(option('base_path')));
$df = shell_exec($command);

if($df !== null) {
return (int) $df < option('max_space');
}

return false;
}