système de quota - quota Vs du.pl + affichage des quotas pour les utilisateurs
This commit is contained in:
		
							parent
							
								
									7d993ea51d
								
							
						
					
					
						commit
						5e0d4e8dc7
					
				| 
						 | 
				
			
			@ -43,10 +43,11 @@ if (!is_array($q) || empty($q) ) {
 | 
			
		|||
} 
 | 
			
		||||
 | 
			
		||||
echo "<table cellspacing=\"0\" cellpadding=\"4\" class='tlist'>";
 | 
			
		||||
echo "<tr><th>"._("Quota")."</th><th>"._("Used")."</th><th>"._("Total")."</th></tr>";
 | 
			
		||||
echo "<tr><th>"._("Quota")."</th><th>"._("Used")."</th><th>"._("Total")."</th><th>"._("Size on disk")."</th></tr>";
 | 
			
		||||
$qlist=$quota->qlist();
 | 
			
		||||
reset($qlist);
 | 
			
		||||
 while (list($key,$val)=each($qlist)) {
 | 
			
		||||
$totalsize = 0;
 | 
			
		||||
while (list($key,$val)=each($qlist)) {
 | 
			
		||||
  if ( !isset($q[$key]) || !$q[$key]["t"]) continue;
 | 
			
		||||
   echo "<tr class=\"lst\">";
 | 
			
		||||
   echo "<td>";
 | 
			
		||||
| 
						 | 
				
			
			@ -55,13 +56,20 @@ reset($qlist);
 | 
			
		|||
  if ($q[$key]["u"] >= $q[$key]["t"]) echo "</font>";
 | 
			
		||||
 | 
			
		||||
  if (($key == 'web')||(isset($q[$key]['type'])&&($q[$key]['type']=='size'))) {
 | 
			
		||||
    echo " </td><td>". format_size($q[$key]["u"] * 1024) . " </td><td>". format_size($q[$key]["t"] * 1024) ." </td>";
 | 
			
		||||
    echo " </td><td>". format_size($q[$key]["u"] * 1024) . " </td><td> </td>";
 | 
			
		||||
  } else {
 | 
			
		||||
    echo " </td><td>".$q[$key]["u"]." </td><td>".$q[$key]["t"]." </td>";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
   echo "</tr>";
 | 
			
		||||
 }
 | 
			
		||||
  if (isset($q[$key]['s'])) {
 | 
			
		||||
    $totalsize += $q[$key]["s"];
 | 
			
		||||
    echo "<td>". format_size($q[$key]["s"] * 1024) . " </td>";
 | 
			
		||||
  } else {
 | 
			
		||||
    echo "<td>- </td>";
 | 
			
		||||
  }
 | 
			
		||||
  echo "</tr>";
 | 
			
		||||
}
 | 
			
		||||
echo "<tr><td colspan='2'></td><td align='right'><b>"._("Total").": </b></td><td><b>".format_size($totalsize * 1024)." / ".format_size($q['web']["t"] * 1024)."</b></td></tr>";
 | 
			
		||||
echo "</table>";
 | 
			
		||||
 | 
			
		||||
include_once("foot.php"); 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,7 +77,7 @@ class m_cron {
 | 
			
		|||
            'title' => _("Scheduled tasks"),
 | 
			
		||||
            'ico' => 'images/schedule.png',
 | 
			
		||||
            'link' => 'cron.php',
 | 
			
		||||
            'pos' => 90,
 | 
			
		||||
            'pos' => 120,
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
        return $obj;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,7 +58,7 @@ class m_ftp {
 | 
			
		|||
            'title' => _("FTP accounts"),
 | 
			
		||||
            'ico' => 'images/ftp.png',
 | 
			
		||||
            'link' => 'toggle',
 | 
			
		||||
            'pos' => 60,
 | 
			
		||||
            'pos' => 100,
 | 
			
		||||
            'links' => array(),
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -200,12 +200,13 @@ class m_mail {
 | 
			
		|||
     * or false if I'm not the one for the named quota
 | 
			
		||||
     */
 | 
			
		||||
    function hook_quota_get() {
 | 
			
		||||
        global $db, $msg, $cuid;
 | 
			
		||||
        global $db, $msg, $cuid, $quota;
 | 
			
		||||
        $msg->log("mail", "getquota");
 | 
			
		||||
        $q = Array("name" => "mail", "description" => _("Email addresses"), "used" => 0);
 | 
			
		||||
        $db->query("SELECT COUNT(*) AS cnt FROM address a, domaines d WHERE a.domain_id=d.id AND d.compte= ? AND a.type='';", array($cuid));
 | 
			
		||||
        if ($db->next_record()) {
 | 
			
		||||
            $q['used'] = $db->f("cnt");
 | 
			
		||||
            $q['sizeondisk'] =  $quota->get_size_mail_sum_user($cuid)/1024;
 | 
			
		||||
        }
 | 
			
		||||
        return $q;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -942,12 +942,13 @@ class m_mysql {
 | 
			
		|||
     * @access private
 | 
			
		||||
     */
 | 
			
		||||
    function hook_quota_get() {
 | 
			
		||||
        global $msg;
 | 
			
		||||
        global $msg, $mem, $quota;
 | 
			
		||||
        $msg->log("mysql", "alternc_get_quota");
 | 
			
		||||
        $q = Array("name" => "mysql", "description" => _("MySQL Databases"), "used" => 0);
 | 
			
		||||
        $c = $this->get_dblist();
 | 
			
		||||
        if (is_array($c)) {
 | 
			
		||||
            $q['used'] = count($c);
 | 
			
		||||
            $q['sizeondisk'] = $quota->get_size_db_sum_user($mem->user["login"])/1024;
 | 
			
		||||
        }
 | 
			
		||||
        return $q;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,6 +40,7 @@ class m_quota {
 | 
			
		|||
 | 
			
		||||
    var $disk = Array();  /* disk resource for which we will manage quotas */
 | 
			
		||||
    var $disk_quota_enable;
 | 
			
		||||
    var $disk_quota_not_blocking;
 | 
			
		||||
    var $quotas;
 | 
			
		||||
    var $clquota; // Which class manage which quota.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -52,6 +53,8 @@ class m_quota {
 | 
			
		|||
        $this->disk_quota_enable = variable_get('disk_quota_enable', 1, 'Are disk quota enabled for this server', array('desc' => 'Enabled', 'type' => 'boolean'));
 | 
			
		||||
        if ($this->disk_quota_enable) {
 | 
			
		||||
            $this->disk = Array("web" => "web");
 | 
			
		||||
 | 
			
		||||
	    $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'));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -60,11 +63,13 @@ class m_quota {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    function hook_menu() {
 | 
			
		||||
        global $cuid, $mem, $quota;
 | 
			
		||||
 | 
			
		||||
        $obj = array(
 | 
			
		||||
            'title' => _("Show my quotas"),
 | 
			
		||||
            'ico' => 'images/quota.png',
 | 
			
		||||
            'link' => 'toggle',
 | 
			
		||||
            'pos' => 110,
 | 
			
		||||
            'pos' => 5,
 | 
			
		||||
            'divclass' => 'menu-quota',
 | 
			
		||||
            'links' => array(),
 | 
			
		||||
        );
 | 
			
		||||
| 
						 | 
				
			
			@ -77,9 +82,10 @@ class m_quota {
 | 
			
		|||
        	        continue;
 | 
			
		||||
		}
 | 
			
		||||
	            
 | 
			
		||||
		$usage_percent = (int) ($q[$key]["u"] / $q[$key]["t"] * 100);
 | 
			
		||||
                $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;
 | 
			
		||||
		$usage_percent = (int) ($totalsize_used / $q[$key]["t"] * 100);
 | 
			
		||||
		$obj['links'][] = array('txt' => _("quota_" . $key) . " " . sprintf(_("%s%% of %s"), $usage_percent, format_size($q[$key]["t"] * 1024)), 'url' => 'quota_show.php');
 | 
			
		||||
		$obj['links'][] = array('txt' => 'progressbar', 'total' => $q[$key]["t"], 'used' => $q[$key]["u"]);
 | 
			
		||||
		$obj['links'][] = array('txt' => 'progressbar', 'total' => $q[$key]["t"], 'used' => $totalsize_used);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
        // do not return menu item if there is no quota
 | 
			
		||||
| 
						 | 
				
			
			@ -186,6 +192,8 @@ class m_quota {
 | 
			
		|||
            foreach ($res as $r) {
 | 
			
		||||
                $this->quotas[$r['name']] = $r;
 | 
			
		||||
                $this->quotas[$r['name']]['u'] = $r['used']; // retrocompatibilité
 | 
			
		||||
                if (isset($r['sizeondisk']))
 | 
			
		||||
                    $this->quotas[$r['name']]['s'] = $r['sizeondisk'];
 | 
			
		||||
                $this->quotas[$r['name']]['t'] = 0; // Default quota = 0
 | 
			
		||||
            }
 | 
			
		||||
            reset($this->disk);
 | 
			
		||||
| 
						 | 
				
			
			@ -202,14 +210,20 @@ class m_quota {
 | 
			
		|||
                        // If there is a cached value
 | 
			
		||||
                        $a = $disk_cached[$val];
 | 
			
		||||
                    } else {
 | 
			
		||||
                        exec("/usr/lib/alternc/quota_get " . intval($cuid), $ak);
 | 
			
		||||
                        $a['u'] = intval($ak[0]);
 | 
			
		||||
                        $a['t'] = @intval($ak[1]);
 | 
			
		||||
                        if ($this->disk_quota_not_blocking) {
 | 
			
		||||
                            $a['u'] = $this->get_size_web_sum_user($cuid);
 | 
			
		||||
                            $a['t'] = $this->get_quota_user_cat($cuid, 'web');
 | 
			
		||||
                        } else {
 | 
			
		||||
                            exec("/usr/lib/alternc/quota_get " . intval($cuid), $ak);
 | 
			
		||||
                            $a['u'] = intval($ak[0]);
 | 
			
		||||
                            $a['t'] = @intval($ak[1]);
 | 
			
		||||
                        }
 | 
			
		||||
			$a['sizeondisk'] = $a['u'];
 | 
			
		||||
                        $a['timestamp'] = time();
 | 
			
		||||
                        $a['uid'] = $cuid;
 | 
			
		||||
                        $disk_cached = $mem->session_tempo_params_set('quota_cache_disk', array($val => $a));
 | 
			
		||||
                    }
 | 
			
		||||
                    $this->quotas[$val] = array("name" => "$val", 'description' => _("quota_" . $val), "t" => $a['t'], "u" => $a['u']);
 | 
			
		||||
		    $this->quotas[$val] = array("name" => "$val", 'description' => _("Web disk space"), "s" => $a['sizeondisk'], "t" => $a['t'], "u" => $a['u']);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -245,7 +259,7 @@ class m_quota {
 | 
			
		|||
        if (floatval($size) == 0) {
 | 
			
		||||
            $size = "0";
 | 
			
		||||
        }
 | 
			
		||||
        if (isset($this->disk[$ressource])) {
 | 
			
		||||
        if (!$this->disk_quota_not_blocking && isset($this->disk[$ressource])) {
 | 
			
		||||
            // It's a disk resource, update it with shell command
 | 
			
		||||
            exec("sudo /usr/lib/alternc/quota_edit " . intval($cuid) . " " . intval($size) . " &> /dev/null &");
 | 
			
		||||
            // Now we check that the value has been written properly : 
 | 
			
		||||
| 
						 | 
				
			
			@ -463,6 +477,12 @@ class m_quota {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* get the quota from one user for a cat */
 | 
			
		||||
 | 
			
		||||
    function get_quota_user_cat($uid, $name) {
 | 
			
		||||
	return $this->_get_sum_sql("SELECT SUM(total) AS sum FROM quotas WHERE uid='$uid' AND name='$name';");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* sum of websites sizes from all users */
 | 
			
		||||
 | 
			
		||||
    function get_size_web_sum_all() {
 | 
			
		||||
| 
						 | 
				
			
			@ -488,6 +508,12 @@ class m_quota {
 | 
			
		|||
        return $mail->get_total_size_for_domain($dom);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* sum of mailbox size for ine user */
 | 
			
		||||
 | 
			
		||||
    function get_size_mail_sum_user($u) {
 | 
			
		||||
      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 ='')");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* count of mailbox sizes from all domains */
 | 
			
		||||
 | 
			
		||||
    function get_size_mail_count_all() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,7 @@
 | 
			
		|||
# Every hour, check for slave_dns refreshes
 | 
			
		||||
5 * * * *	root            /usr/lib/alternc/slave_dns
 | 
			
		||||
 | 
			
		||||
# Every day at 2am, compute web, mail and db space usage per account.
 | 
			
		||||
# Every day at 2am, compute web, mailman and db space usage per account.
 | 
			
		||||
# You may put this computing every week only or on your filer on busy services.
 | 
			
		||||
0 2 * * *	alterncpanel 	/usr/lib/alternc/spoolsize.php 2>&1 > /dev/null
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -34,3 +34,6 @@
 | 
			
		|||
# Every 20 minutes, do actions
 | 
			
		||||
*/20 * * * *	root	/usr/lib/alternc/do_actions.php
 | 
			
		||||
 | 
			
		||||
# Calculate the mail accounts size once a week beacause the dovecot plugin to do that is not precise (see ticket AlternC #168)
 | 
			
		||||
# Every Sunday at 4am
 | 
			
		||||
0 4 * * 0	root	/usr/lib/alternc/update_quota_mail.sh -a
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,9 +18,14 @@ if ($db->query("SELECT uid,login FROM membres;")) {
 | 
			
		|||
  while ($db->next_record()) {
 | 
			
		||||
    if (isset($list_quota[$db->f('uid')])) {
 | 
			
		||||
      $qu=$list_quota[$db->f('uid')];
 | 
			
		||||
      $db2->query("REPLACE INTO size_web SET uid=?, size=?;",array(intval($db->f('uid')),intval($qu['used'])));
 | 
			
		||||
      echo $db->f('login')." (".$qu['used']." B)\n";
 | 
			
		||||
    }  
 | 
			
		||||
      $size=$qu['used'];
 | 
			
		||||
    } else {
 | 
			
		||||
      // Le système de quota n'étant pas actif, on doit passer par un 'du' sur chaque dossier
 | 
			
		||||
      $login = $db->f('login');
 | 
			
		||||
      $size=exec("/usr/lib/alternc/du.pl /var/www/alternc/".substr($login,0,1)."/".$login);
 | 
			
		||||
    }
 | 
			
		||||
    $db2->query("REPLACE INTO size_web SET uid=?, size=?;",array(intval($db->f('uid')),intval($size)));
 | 
			
		||||
    echo $db->f('login')." (".(round($size/1024, 1))." MB)\n";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +43,7 @@ foreach($allsrv as $c) {
 | 
			
		|||
  echo "++ Processing ".$c["name"]." ++\n";
 | 
			
		||||
  foreach ($tab as $dbname=>$size) {
 | 
			
		||||
    $db->query("REPLACE INTO size_db SET db=?,size=?;",array($dbname,$size)); 
 | 
			
		||||
    echo "   $dbname done ($size B) \n"; flush();
 | 
			
		||||
    echo "   $dbname done (".(round(($size/1024)/1024,1))." MB) \n"; flush();
 | 
			
		||||
  }
 | 
			
		||||
  echo "\n";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +63,7 @@ if ($db->query("SELECT uid, name FROM mailman;")) {
 | 
			
		|||
      $size3=exec("sudo /usr/lib/alternc/du.pl ".escapeshellarg("/var/lib/mailman/archives/private/".$c["name"].".mbox"));
 | 
			
		||||
      $size=(intval($size1)+intval($size2)+intval($size3));
 | 
			
		||||
      $db->query("REPLACE INTO size_mailman SET uid=?,list=?,size=?;",array($c["uid"],$c["name"],$size));
 | 
			
		||||
      echo " done ($size KB) \n"; flush();
 | 
			
		||||
      echo " done (".(round($size/1024, 1))." MB) \n"; flush();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,8 +108,9 @@ for i in $maildirs ; do
 | 
			
		|||
	echo "dir size : "$size
 | 
			
		||||
	echo ""
 | 
			
		||||
	#update the mailbox table accordingly
 | 
			
		||||
	mysql_query "UPDATE mailbox SET bytes=$size WHERE path='$i' ; "
 | 
			
		||||
	mysql_query "UPDATE mailbox SET messages=$mail_count WHERE path='$i' ; " 
 | 
			
		||||
	MAILADD=`basename $i`
 | 
			
		||||
	MAILADD=${MAILADD/_/@}
 | 
			
		||||
	mysql_query "REPLACE INTO dovecot_quota VALUES('$MAILADD', $size, $mail_count);"
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# may cause a problem, let's fix this here :) 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue