Skip to content

Commit e16edeb

Browse files
author
Till Brehm
committed
Merge branch 'add_noquota' into 'develop'
Option calculate Website Disk usage without Quota See merge request ispconfig/ispconfig3!1704
2 parents 61e9ced + 8d44fa9 commit e16edeb

File tree

1 file changed

+107
-48
lines changed

1 file changed

+107
-48
lines changed

server/lib/classes/cron.d/100-monitor_hd_quota.inc.php

Lines changed: 107 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class cronjob_monitor_hd_quota extends cronjob {
3333
// job schedule
3434
protected $_schedule = '*/5 * * * *';
3535
protected $_run_at_new = true;
36-
3736
private $_tools = null;
3837

3938
/* this function is optional if it contains no custom code */
@@ -70,60 +69,120 @@ public function onRunJob() {
7069
//* The state of the harddisk_quota.
7170
$state = 'ok';
7271

73-
//* Fetch the data for all users
74-
$dfData = shell_exec('repquota -au 2>/dev/null');
75-
76-
//* Split into array
77-
$df = explode("\n", $dfData);
78-
79-
//* ignore the first 5 lines, process the rest
80-
for ($i = 5; $i <= sizeof($df); $i++) {
81-
if (isset($df[$i]) && $df[$i] != '') {
82-
//* Make a array of the data
83-
$s = preg_split('/[\s]+/', $df[$i]);
84-
$username = $s[0];
85-
if (substr($username, 0, 3) == 'web') {
86-
if (isset($data['user'][$username])) {
87-
$data['user'][$username]['used'] += $s[2];
88-
$data['user'][$username]['soft'] += $s[3];
89-
$data['user'][$username]['hard'] += $s[4];
90-
$data['user'][$username]['files'] += $s[5];
91-
} else {
92-
$data['user'][$username]['used'] = $s[2];
93-
$data['user'][$username]['soft'] = $s[3];
94-
$data['user'][$username]['hard'] = $s[4];
95-
$data['user'][$username]['files'] = $s[5];
72+
if(!$app->system->is_installed('setquota')) {
73+
//* No Quota on this System ...
74+
75+
//** Fetch the data for all users
76+
$dfData = shell_exec('du -s /var/www/clients/client*/we*');
77+
78+
//* split into array
79+
$df = explode("\n", $dfData);
80+
81+
//* Get Limits for Calculation
82+
$records = $app->db->queryAllRecords('SELECT hd_quota, system_user, system_group FROM `web_domain` WHERE `server_id` = ?', $conf['server_id']);
83+
foreach ($records as $record) {
84+
$options['group'][$record['system_group']] = $record['hd_quota']*1024;
85+
$options['user'][$record['system_user']] = $record['hd_quota']*1024;
86+
}
87+
88+
//* ignore the first 5 lines, process the rest
89+
for ($i = 0; $i <= sizeof($df); $i++) {
90+
if (isset($df[$i]) && $df[$i] != '') {
91+
//* Make a array of the data
92+
$s1 = preg_split('/[\s]+/', $df[$i]);
93+
$s2 = preg_split('/\//', $s1[1]);
94+
$groupname = $s2[4];
95+
if (substr($groupname, 0, 6) == 'client') {
96+
if (isset($data['group'][$groupname])) {
97+
$data['group'][$groupname]['used'] += $s1[0];
98+
$data['group'][$groupname]['soft'] = $options['group'][$groupname];
99+
$data['group'][$groupname]['hard'] = $options['group'][$groupname];
100+
} else {
101+
$data['group'][$groupname]['used'] = $s1[0];
102+
$data['group'][$groupname]['soft'] = $options['group'][$groupname];
103+
$data['group'][$groupname]['hard'] = $options['group'][$groupname];
104+
}
105+
}
106+
}
107+
}
108+
109+
//* ignore the first 5 lines, process the rest
110+
for ($i = 0; $i <= sizeof($df); $i++) {
111+
if (isset($df[$i]) && $df[$i] != '') {
112+
//* Make a array of the data
113+
$s1 = preg_split('/[\s]+/', $df[$i]);
114+
$s2 = preg_split('/\//', $s1[1]);
115+
$username = $s2[5];
116+
if (substr($username, 0, 3) == 'web') {
117+
if (isset($data['user'][$username])) {
118+
$data['user'][$username]['used'] += $s1[0];
119+
$data['user'][$username]['soft'] = $options['user'][$username];
120+
$data['user'][$username]['hard'] = $options['user'][$username];
121+
$data['user'][$username]['files'] = 0;
122+
} else {
123+
$data['user'][$username]['used'] = $s1[0];
124+
$data['user'][$username]['soft'] = $options['user'][$username];
125+
$data['user'][$username]['hard'] = $options['user'][$username];
126+
$data['user'][$username]['files'] = 0;
127+
}
96128
}
97129
}
98130
}
99-
}
100-
101-
//** Fetch the data for all users
102-
$dfData = shell_exec('repquota -ag 2>/dev/null');
103-
104-
//* split into array
105-
$df = explode("\n", $dfData);
106-
107-
//* ignore the first 5 lines, process the rest
108-
for ($i = 5; $i <= sizeof($df); $i++) {
109-
if (isset($df[$i]) && $df[$i] != '') {
110-
//* Make a array of the data
111-
$s = preg_split('/[\s]+/', $df[$i]);
112-
$groupname = $s[0];
113-
if (substr($groupname, 0, 6) == 'client') {
114-
if (isset($data['group'][$groupname])) {
115-
$data['group'][$groupname]['used'] += $s[2];
116-
$data['group'][$groupname]['soft'] += $s[3];
117-
$data['group'][$groupname]['hard'] += $s[4];
118-
} else {
119-
$data['group'][$groupname]['used'] = $s[2];
120-
$data['group'][$groupname]['soft'] = $s[3];
121-
$data['group'][$groupname]['hard'] = $s[4];
131+
}else{
132+
//* Fetch the data for all users
133+
$dfData = shell_exec('repquota -au 2>/dev/null');
134+
135+
//* Split into array
136+
$df = explode("\n", $dfData);
137+
138+
//* ignore the first 5 lines, process the rest
139+
for ($i = 5; $i <= sizeof($df); $i++) {
140+
if (isset($df[$i]) && $df[$i] != '') {
141+
//* Make a array of the data
142+
$s = preg_split('/[\s]+/', $df[$i]);
143+
$username = $s[0];
144+
if (substr($username, 0, 3) == 'web') {
145+
if (isset($data['user'][$username])) {
146+
$data['user'][$username]['used'] += $s[2];
147+
$data['user'][$username]['soft'] += $s[3];
148+
$data['user'][$username]['hard'] += $s[4];
149+
$data['user'][$username]['files'] += $s[5];
150+
} else {
151+
$data['user'][$username]['used'] = $s[2];
152+
$data['user'][$username]['soft'] = $s[3];
153+
$data['user'][$username]['hard'] = $s[4];
154+
$data['user'][$username]['files'] = $s[5];
155+
}
122156
}
123157
}
124158
}
125-
}
126159

160+
//** Fetch the data for all users
161+
$dfData = shell_exec('repquota -ag 2>/dev/null');
162+
163+
//* split into array
164+
$df = explode("\n", $dfData);
165+
166+
//* ignore the first 5 lines, process the rest
167+
for ($i = 5; $i <= sizeof($df); $i++) {
168+
if (isset($df[$i]) && $df[$i] != '') {
169+
//* Make a array of the data
170+
$s = preg_split('/[\s]+/', $df[$i]);
171+
$groupname = $s[0];
172+
if (substr($groupname, 0, 6) == 'client') {
173+
if (isset($data['group'][$groupname])) {
174+
$data['group'][$groupname]['used'] += $s[2];
175+
$data['group'][$groupname]['soft'] += $s[3];
176+
$data['group'][$groupname]['hard'] += $s[4];
177+
} else {
178+
$data['group'][$groupname]['used'] = $s[2];
179+
$data['group'][$groupname]['soft'] = $s[3];
180+
$data['group'][$groupname]['hard'] = $s[4];
181+
}
182+
}
183+
}
184+
}
185+
}
127186
$res = array();
128187
$res['server_id'] = $server_id;
129188
$res['type'] = $type;

0 commit comments

Comments
 (0)