conn = $conn; } public function calculate() { $quota['home'] = $this->getUsedHomeQuota(); $quota['mysql'] = $this->getUsedMysqlQuota(); $emailQuota = $this->getUsedEmailQuota(); $usersEmailDomainsPost = $this->getUserEmailDomainsPost(); $quota['email'] = $this->joinEmailDomainsWithQuota($usersEmailDomainsPost, $emailQuota); return $quota; } public function getUsedHomeQuota() { $homeQuota = shell_exec("du -bs /home/*"); $homeQuotaAll = explode("\n", $homeQuota); $quota = []; foreach ($homeQuotaAll as $homeQuotaInfo) { if (!empty($homeQuotaInfo)) { $userQuotaInfo = explode('/', trim($homeQuotaInfo), 2); $userName = trim(str_replace('home/', '', $userQuotaInfo[1])); $userQuota = trim($userQuotaInfo[0]); $quota[$userName] = (int) $userQuota; } } return $quota; } public function getUsedMysqlQuota() { $allQuota = shell_exec("du -bs /var/lib/mysql/*"); $allQuotaRows = explode("\n", $allQuota); $quota = []; foreach ($allQuotaRows as $rowQuotaInfo) { if (!empty($rowQuotaInfo)) { $userQuotaInfo = explode('/', trim($rowQuotaInfo), 2); $fileQuota = trim($userQuotaInfo[0]); $userNameDb = trim(str_replace('var/lib/mysql/', '', $userQuotaInfo[1])); $userNameDbExploded = explode('_', trim($userNameDb), 2); $userName = $userNameDbExploded[0]; if (isset($userNameDbExploded[1])) { $dbName = $userNameDbExploded[1]; }; if (isset($quota[$userName])) { if (isset($dbName)) { $quota[$userName]['db'][$dbName] = (int) $fileQuota; } $quota[$userName]['db_quota'] += (int) $fileQuota; $quota[$userName]['db_count']++; } else { if (isset($dbName)) { $quota[$userName]['db'][$dbName] = (int) $fileQuota; } $quota[$userName]['db_quota'] = (int) $fileQuota; $quota[$userName]['db_count'] = 1; } unset($dbName); } } return $quota; } public function getUsedEmailQuota() { $emailQuota = shell_exec("du -bs /var/vmail/*"); $emailQuotaAll = explode("\n", $emailQuota); $quota = []; foreach ($emailQuotaAll as $emailQuotaInfo) { if (!empty($emailQuotaInfo)) { $domainQuotaInfo = explode('/', trim($emailQuotaInfo), 2); $domainName = trim(str_replace('var/vmail/', '', $domainQuotaInfo[1])); $emailQuota = trim($domainQuotaInfo[0]); $quota[$domainName] = (int) $emailQuota; } } return $quota; } public function getUserEmailDomainsPost() { $sql = " SELECT cu.username, cu.domain, pm.local_part AS post FROM root_cwp.user cu, postfix.mailbox pm WHERE pm.domain = cu.domain UNION ALL SELECT cd.user, cd.domain, pm.local_part FROM root_cwp.domains cd, postfix.mailbox pm WHERE pm.domain = cd.domain UNION ALL SELECT cs.user, CONCAT(cs.subdomain, '.', cs.domain), pm.local_part FROM root_cwp.subdomains cs, postfix.mailbox pm WHERE pm.domain = CONCAT(cs.subdomain, '.', cs.domain) "; $result = $this->conn->query($sql); $usersDomains = []; while ($row = $result->fetch_assoc()) { if (!isset($usersDomains['user'][$row['username']][$row['domain']])) { $usersDomains['user'][$row['username']][$row['domain']] = 1; } else { $usersDomains['user'][$row['username']][$row['domain']] += 1; } $usersDomains['domain'][$row['domain']] = $row['username']; } return $usersDomains; } public function joinEmailDomainsWithQuota(array $usersDomains, array $emailQuota) { $data = []; foreach ($emailQuota as $domain => $quota) { if (!isset($usersDomains['domain'][$domain])) { continue; } $user = $usersDomains['domain'][$domain]; if (isset($data[$user])) { $data[$user]['quota'] += (int) $quota; } else { $data[$user]['quota'] = (int) $quota; } $data[$user]['count'] = (int) $usersDomains['user'][$user][$domain]; } return $data; } } $cwpUsersQuota = new CwpUsersUsedQuota($conn); $quota = $cwpUsersQuota->calculate(); ?>
prepare($sql); $stmt->execute(); $meta = $stmt->result_metadata(); $result = null; $params = null; while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array([ $stmt, 'bind_result', ], $params); while ($stmt->fetch()) { foreach ($row as $key => $val) { $c[$key] = $val; } $result[] = $c; } $stmt->close(); ?>
LP. User Name Domain Package name Package quota Home dir quota MySql quota Mail quota Used quota Free quota Percent
. GB GB 50) { $progressBarClass = 'progressBarOrange'; } if ($usedQuotaProgress > 90) { $progressBarClass = 'progressBarRed'; } if ($usedQuotaProgress > 100) { $usedQuotaProgress = 100; } ?>
Total users: Sum: GB GB [] GB GB GB