47 $this->disk_quota_enable =
variable_get(
'disk_quota_enable', 1,
'Are disk quota enabled for this server', array(
'desc' =>
'Enabled',
'type' =>
'boolean'));
48 if ($this->disk_quota_enable) {
49 $this->disk = Array(
"web" =>
"web");
51 $this->disk_quota_not_blocking =
variable_get(
'disk_quota_not_blocking', 1,
"0 - Block data when quota are exceeded (you need a working quota system) | 1 - Just show quota but don't block anything", array(
'desc' =>
'Enabled',
'type' =>
'boolean'));
65 'title' => _(
"Show my quotas"),
66 'ico' =>
'images/quota.png',
69 'divclass' =>
'menu-quota',
81 $totalsize_used = $quota->get_size_web_sum_user(
$cuid) + $quota->get_size_mailman_sum_user(
$cuid) + ($quota->get_size_db_sum_user(
$mem->user[
"login"]) + $quota->get_size_mail_sum_user(
$cuid))/1024;
82 $usage_percent = (int) ($totalsize_used /
$q[
$key][
"t"] * 100);
83 $obj[
'links'][] = array(
'txt' => _(
"quota_" .
$key) .
" " . sprintf(_(
"%s%% of %s"), $usage_percent,
format_size(
$q[
$key][
"t"] * 1024)),
'url' =>
'quota_show.php');
84 $obj[
'links'][] = array(
'txt' =>
'progressbar',
'total' =>
$q[
$key][
"t"],
'used' => $totalsize_used);
88 if (!count($obj[
'links']))
return false;
97 define(
"QUOTASONE",
"1");
99 'include' =>
"quotas_oneuser.php"
111 return $t[
"u"] <
$t[
"t"];
121 while (list(
$key,
$val) = each($this->disk)) {
125 foreach ($this->
getquota() as $qq) {
126 if (isset($qq[
'name'])) {
127 $qlist[$qq[
'name']] = $qq[
'description'];
143 $msg->log(
"quota",
"synchronise_user_profile");
144 $q =
"INSERT INTO quotas SELECT m.uid AS uid, d.quota AS name, d.value AS total FROM membres m, defquotas d LEFT JOIN quotas q ON q.name=d.quota WHERE m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
145 if (!
$db->query(
$q)) {
158 $msg->log(
"quota",
"create_missing_quota_profile");
159 $qt = $quota->getquota(
'',
true);
160 $type = $quota->listtype();
161 foreach ($type as
$t) {
162 foreach ($qt as
$q => $vv) {
163 $db->query(
"INSERT IGNORE defquotas (value,quota,type) VALUES (0, ?, ?);", array(
$q,
$t));
174 function getquota($ressource =
"", $recheck =
false) {
176 $msg->debug(
"quota",
"getquota", $ressource);
178 $get_quota_cache =
null;
179 $this->quotas = array();
181 if (!empty($get_quota_cache[
$cuid])) {
183 $this->quotas = $get_quota_cache[
$cuid];
187 $this->quotas[
$r[
'name']] =
$r;
188 $this->quotas[
$r[
'name']][
'u'] =
$r[
'used'];
189 if (isset(
$r[
'sizeondisk']))
190 $this->quotas[
$r[
'name']][
's'] =
$r[
'sizeondisk'];
191 $this->quotas[
$r[
'name']][
't'] = 0;
195 if (!empty($this->disk)) {
197 $disk_cached =
$mem->session_tempo_params_get(
'quota_cache_disk');
199 while (list(
$key,
$val) = each($this->disk)) {
202 isset($disk_cached[
$val]) && !empty($disk_cached[
$val]) && $disk_cached[
$val][
'uid'] ==
$cuid && $disk_cached[
$val][
'timestamp'] > ( time() - (90) )
205 $a = $disk_cached[
$val];
207 if ($this->disk_quota_not_blocking) {
211 exec(
"/usr/lib/alternc/quota_get " . intval(
$cuid), $ak);
212 $a[
'u'] = intval($ak[0]);
213 $a[
't'] = @intval($ak[1]);
215 $a[
'sizeondisk'] = $a[
'u'];
216 $a[
'timestamp'] = time();
218 $disk_cached =
$mem->session_tempo_params_set(
'quota_cache_disk', array(
$val => $a));
220 $this->quotas[
$val] = array(
"name" =>
"$val",
'description' => _(
"Web disk space"),
"s" => $a[
'sizeondisk'],
"t" => $a[
't'],
"u" => $a[
'u']);
225 $db->query(
"select name, total from quotas where uid= ? ;", array(
$cuid));
226 while (
$db->next_record()) {
227 $this->quotas[
$db->f(
'name')][
't'] =
$db->f(
'total');
234 if (isset($this->quotas[$ressource])) {
235 return $this->quotas[$ressource];
251 $msg->log(
"quota",
"setquota", $ressource .
"/" . $size);
252 if (floatval($size) == 0) {
255 if (!$this->disk_quota_not_blocking && isset($this->disk[$ressource])) {
257 exec(
"sudo /usr/lib/alternc/quota_edit " . intval(
$cuid) .
" " . intval($size) .
" &> /dev/null &");
260 exec(
"sudo /usr/lib/alternc/quota_get " . intval(
$cuid) .
" &> /dev/null &", $a);
261 if (!isset($a[1]) || $size != $a[1]) {
262 $msg->raise(
"ERROR",
"quota", _(
"Error writing the quota entry!"));
267 $db->query(
"SELECT * FROM quotas WHERE uid= ? AND name= ? ", array(
$cuid, $ressource));
268 if (
$db->num_rows()) {
269 $db->query(
"UPDATE quotas SET total= ? WHERE uid= ? AND name= ?;", array($size,
$cuid, $ressource));
271 $db->query(
"INSERT INTO quotas (uid,name,total) VALUES (?, ?, ?);", array(
$cuid, $ressource, $size));
282 $msg->log(
"quota",
"delquota");
283 $db->query(
"DELETE FROM quotas WHERE uid= ?;", array(
$cuid));
296 $db->query(
"SELECT type,quota FROM defquotas WHERE type='default'");
297 if (!
$db->next_record()) {
300 $db->query(
"SELECT value,quota,type FROM defquotas ORDER BY type,quota");
301 while (
$db->next_record()) {
302 $type =
$db->f(
"type");
303 $c[$type][
$db->f(
"quota")] =
$db->f(
"value");
317 foreach ($newq as $type =>
$quotas) {
319 if (array_key_exists($qname,
$qlist)) {
320 if (!
$db->query(
"REPLACE INTO defquotas (value,quota,type) VALUES ( ?, ?, ?); ", array(
$value, $qname, $type))) {
341 $type = strtolower($type);
342 if (!preg_match(
"#^[a-z0-9]*$#", $type)) {
343 $msg->raise(
"ERROR",
"quota", _(
"Type can only contains characters a-z and 0-9"));
347 if (!
$db->query(
"INSERT IGNORE INTO defquotas (quota,type) VALUES(?, ?);", array(
$key, $type)) ||
$db->affected_rows() == 0) {
361 $db->query(
"SELECT distinct(type) FROM defquotas ORDER by type");
363 while (
$db->next_record()) {
364 $t[] =
$db->f(
"type");
377 if (
$db->query(
"UPDATE membres SET type='default' WHERE type= ? ;", array($type)) &&
378 $db->query(
"DELETE FROM defquotas WHERE type= ?;", array($type))) {
391 $msg->log(
"quota",
"addquota");
395 $db->query(
"SELECT type,quota FROM defquotas WHERE type='default'");
396 if (!
$db->next_record()) {
399 $db->query(
"SELECT type FROM membres WHERE uid= ?;", array(
$cuid));
404 $db->query(
"SELECT value FROM defquotas WHERE quota= ? AND type= ? ;", array(
$res,
$t));
405 $q =
$db->next_record() ?
$db->f(
"value") : 0;
434 if (
$db->num_rows() == 0) {
447 if (
$db->num_rows() == 0) {
460 if (
$db->num_rows() == 0) {
464 while (
$db->next_record()) {
465 $ret[] =
$db->Record;
474 return $this->
_get_sum_sql(
"SELECT SUM(total) AS sum FROM quotas WHERE uid='$uid' AND name='$name';");
480 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_web;");
486 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';");
492 return $this->
_get_sum_sql(
"SELECT SUM(quota_dovecot) AS sum FROM dovecot_quota ;");
499 return $mail->get_total_size_for_domain(
$dom);
505 return $this->
_get_sum_sql(
"SELECT SUM(quota_dovecot) as sum FROM dovecot_quota WHERE user IN (SELECT CONCAT(a.address, '@', d.domaine) as mail FROM `address` as a INNER JOIN domaines as d ON a.domain_id = d.id WHERE d.compte = '$u' AND a.type ='')");
511 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM dovecot_quota;");
517 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM dovecot_quota WHERE user LIKE '%@{$dom}'");
523 return $this->
_get_size_and_record_sql(
"SELECT user as alias,quota_dovecot as size FROM dovecot_quota WHERE user LIKE '%@{$dom}' ORDER BY alias;");
529 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_mailman;");
535 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_mailman s INNER JOIN mailman m ON s.list = m.list AND s.uid = m.uid WHERE m.domain = '$dom'");
541 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
547 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_mailman;");
553 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
559 return $this->
_get_size_and_record_sql(
"SELECT s.size,CONCAT(m.list,'@',m.domain) as list FROM size_mailman s LEFT JOIN mailman m ON s.list=m.name WHERE s.uid='{$u}' ORDER BY s.list ASC");
565 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_db;");
571 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
577 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_db;");
583 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
595 $units = array(1073741824 => _(
"GB"), 1048576 => _(
"MB"), 1024 => _(
"KB"), 0 => _(
"B"));
599 return array(
'size' => $size,
'unit' => $unit);
612 if ($color_type == 1) {
614 }
elseif ($color_type == 2) {
620 echo
'<div class="progress-bar">';
621 echo
'<div class="barre" style="width:' . $usage .
'%;' . $csscolor .
'" ></div>';
622 echo
'<div class="txt">' . $usage .
'%</div>';
645 $msg->log(
"quota",
"hook_admin_add_member");
657 $msg->log(
"quota",
"export");
661 foreach (
$q as $k => $v) {
663 $str.=
" <used>" . ($v[
"u"]) .
"</used>\n";
664 $str.=
" <total>" . ($v[
"t"]) .
"</total>\n";
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Class for hosting quotas management.
addquotas()
Create default quotas entries for a new user.
get_size_mailman_count_all()
getdefaults()
Get the default quotas as an associative array.
get_size_db_count_user($u)
get_size_mailman_count_user($u)
synchronise_user_profile()
Synchronise the quotas of the users with the quota of the user's profile.
get_quota_user_cat($uid, $name)
get_size_mail_details_domain($dom)
hook_admin_del_member()
Hook function call when a user is deleted AlternC's standard function called when a user is deleted g...
addtype($type)
Add an account type for quotas.
qlist()
List the quota-managed services in the server @Return array the quota names and description (translat...
get_size_mailman_sum_all()
get_size_mailman_sum_user($u)
create_missing_quota_profile()
delquotas()
Erase all quota information about the user.
display_val($type, $value)
Return a quota value with its unit (when it is a space quota) in MB, GB, TB ...
listtype()
List types of quotas.
_get_size_and_record_sql($sql)
setdefaults($newq)
Set the default quotas.
get_size_mailman_sum_domain($dom)
quota_displaybar($usage, $color_type=1)
show a progress-bar color_type : 0 = No colo change 1 = Progress from green to red depending on perce...
cancreate($ressource="")
Check if a user can use a ressource.
get_size_db_details_user($u)
alternc_export_conf()
Exports all the quota related information for an account.
deltype($type)
Delete an account type for quotas.
get_size_mail_sum_user($u)
get_size_mail_count_all()
setquota($ressource, $size)
Set the quota for a user (and for a ressource)
get_size_mailman_details_user($u)
get_size_mail_sum_domain($dom)
hook_admin_add_member()
Hook function called when a user is created This function initialize the user's quotas.
getquota($ressource="", $recheck=false)
Return a ressource usage (u) and total quota (t)
get_size_mail_count_domain($dom)
get_size_web_sum_user($u)
format_size($size, $html=0)
if(empty($site_name)) elseif($piwik->site_add( $site_name, $site_urls))
foreach($domaines_user as $domaine) $t
if(empty($_POST['key'])||empty($_POST['val'])) $key