Skip to content

Commit c26a9f6

Browse files
committed
Option calculate Website Disk usage without Quota
1 parent 9954d8f commit c26a9f6

File tree

1 file changed

+108
-45
lines changed

1 file changed

+108
-45
lines changed

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

Lines changed: 108 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,55 +70,118 @@ public function onRunJob() {
7070
//* The state of the harddisk_quota.
7171
$state = 'ok';
7272

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

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

0 commit comments

Comments
 (0)