Skip to content
Snippets Groups Projects

Option calculate Website Disk usage without Quota

Merged Joel Kuder requested to merge Lokutos/ispconfig3:add_noquota into develop
@@ -33,7 +33,6 @@ class cronjob_monitor_hd_quota extends cronjob {
// job schedule
protected $_schedule = '*/5 * * * *';
protected $_run_at_new = true;
private $_tools = null;
/* this function is optional if it contains no custom code */
@@ -70,60 +69,120 @@ class cronjob_monitor_hd_quota extends cronjob {
//* The state of the harddisk_quota.
$state = 'ok';
//* Fetch the data for all users
$dfData = shell_exec('repquota -au 2>/dev/null');
//* Split into array
$df = explode("\n", $dfData);
//* ignore the first 5 lines, process the rest
for ($i = 5; $i <= sizeof($df); $i++) {
if (isset($df[$i]) && $df[$i] != '') {
//* Make a array of the data
$s = preg_split('/[\s]+/', $df[$i]);
$username = $s[0];
if (substr($username, 0, 3) == 'web') {
if (isset($data['user'][$username])) {
$data['user'][$username]['used'] += $s[2];
$data['user'][$username]['soft'] += $s[3];
$data['user'][$username]['hard'] += $s[4];
$data['user'][$username]['files'] += $s[5];
} else {
$data['user'][$username]['used'] = $s[2];
$data['user'][$username]['soft'] = $s[3];
$data['user'][$username]['hard'] = $s[4];
$data['user'][$username]['files'] = $s[5];
if(!$app->system->is_installed('setquota')) {
//* No Quota on this System ...
//** Fetch the data for all users
$dfData = shell_exec('du -s /var/www/clients/client*/we*');
//* split into array
$df = explode("\n", $dfData);
//* Get Limits for Calculation
$records = $app->db->queryAllRecords('SELECT hd_quota, system_user, system_group FROM `web_domain` WHERE `server_id` = ?', $conf['server_id']);
foreach ($records as $record) {
$options['group'][$record['system_group']] = $record['hd_quota']*1024;
$options['user'][$record['system_user']] = $record['hd_quota']*1024;
}
//* ignore the first 5 lines, process the rest
for ($i = 0; $i <= sizeof($df); $i++) {
if (isset($df[$i]) && $df[$i] != '') {
//* Make a array of the data
$s1 = preg_split('/[\s]+/', $df[$i]);
$s2 = preg_split('/\//', $s1[1]);
$groupname = $s2[4];
if (substr($groupname, 0, 6) == 'client') {
if (isset($data['group'][$groupname])) {
$data['group'][$groupname]['used'] += $s1[0];
$data['group'][$groupname]['soft'] = $options['group'][$groupname];
$data['group'][$groupname]['hard'] = $options['group'][$groupname];
} else {
$data['group'][$groupname]['used'] = $s1[0];
$data['group'][$groupname]['soft'] = $options['group'][$groupname];
$data['group'][$groupname]['hard'] = $options['group'][$groupname];
}
}
}
}
//* ignore the first 5 lines, process the rest
for ($i = 0; $i <= sizeof($df); $i++) {
if (isset($df[$i]) && $df[$i] != '') {
//* Make a array of the data
$s1 = preg_split('/[\s]+/', $df[$i]);
$s2 = preg_split('/\//', $s1[1]);
$username = $s2[5];
if (substr($username, 0, 3) == 'web') {
if (isset($data['user'][$username])) {
$data['user'][$username]['used'] += $s1[0];
$data['user'][$username]['soft'] = $options['user'][$username];
$data['user'][$username]['hard'] = $options['user'][$username];
$data['user'][$username]['files'] = 0;
} else {
$data['user'][$username]['used'] = $s1[0];
$data['user'][$username]['soft'] = $options['user'][$username];
$data['user'][$username]['hard'] = $options['user'][$username];
$data['user'][$username]['files'] = 0;
}
}
}
}
}
//** Fetch the data for all users
$dfData = shell_exec('repquota -ag 2>/dev/null');
//* split into array
$df = explode("\n", $dfData);
//* ignore the first 5 lines, process the rest
for ($i = 5; $i <= sizeof($df); $i++) {
if (isset($df[$i]) && $df[$i] != '') {
//* Make a array of the data
$s = preg_split('/[\s]+/', $df[$i]);
$groupname = $s[0];
if (substr($groupname, 0, 6) == 'client') {
if (isset($data['group'][$groupname])) {
$data['group'][$groupname]['used'] += $s[2];
$data['group'][$groupname]['soft'] += $s[3];
$data['group'][$groupname]['hard'] += $s[4];
} else {
$data['group'][$groupname]['used'] = $s[2];
$data['group'][$groupname]['soft'] = $s[3];
$data['group'][$groupname]['hard'] = $s[4];
}else{
//* Fetch the data for all users
$dfData = shell_exec('repquota -au 2>/dev/null');
//* Split into array
$df = explode("\n", $dfData);
//* ignore the first 5 lines, process the rest
for ($i = 5; $i <= sizeof($df); $i++) {
if (isset($df[$i]) && $df[$i] != '') {
//* Make a array of the data
$s = preg_split('/[\s]+/', $df[$i]);
$username = $s[0];
if (substr($username, 0, 3) == 'web') {
if (isset($data['user'][$username])) {
$data['user'][$username]['used'] += $s[2];
$data['user'][$username]['soft'] += $s[3];
$data['user'][$username]['hard'] += $s[4];
$data['user'][$username]['files'] += $s[5];
} else {
$data['user'][$username]['used'] = $s[2];
$data['user'][$username]['soft'] = $s[3];
$data['user'][$username]['hard'] = $s[4];
$data['user'][$username]['files'] = $s[5];
}
}
}
}
}
//** Fetch the data for all users
$dfData = shell_exec('repquota -ag 2>/dev/null');
//* split into array
$df = explode("\n", $dfData);
//* ignore the first 5 lines, process the rest
for ($i = 5; $i <= sizeof($df); $i++) {
if (isset($df[$i]) && $df[$i] != '') {
//* Make a array of the data
$s = preg_split('/[\s]+/', $df[$i]);
$groupname = $s[0];
if (substr($groupname, 0, 6) == 'client') {
if (isset($data['group'][$groupname])) {
$data['group'][$groupname]['used'] += $s[2];
$data['group'][$groupname]['soft'] += $s[3];
$data['group'][$groupname]['hard'] += $s[4];
} else {
$data['group'][$groupname]['used'] = $s[2];
$data['group'][$groupname]['soft'] = $s[3];
$data['group'][$groupname]['hard'] = $s[4];
}
}
}
}
}
$res = array();
$res['server_id'] = $server_id;
$res['type'] = $type;
Loading