Ticket #1130 (new defect)

Opened 2 weeks ago

Last modified 4 days ago

Impossible de faire un reset des quotas d'un membre

Reported by: mlutfy Assigned to: anonymous
Priority: normal Milestone: alternc-0.9.9
Component: Quotas Version: alternc-0.9.8
Severity: major Keywords:
Cc:

Description

La fonction "setquota" dans class/m_quota.php utilise la variable globale $cuid pour re-initialiser le quota du membre (Gestion des membres -> Edit John Doe -> reset quotas).

Par conséquent, si on est loggé en admin (uid 2000), et que l'on veut modifier johdoe (uid 2001), ça va re-initialiser les quotas de l'admin, car $cuid = 2000.

Change History

04/30/08 05:57:09 changed by mlutfy

Patch proposée. Appliqué sur alternc.koumbit.net:

root@alternc:/var/alternc/bureau# hg diff
diff -r 6f8888f5530b admin/adm_quotadoedit.php
--- a/admin/adm_quotadoedit.php	Sat Apr 26 23:20:13 2008 -0400
+++ b/admin/adm_quotadoedit.php	Tue Apr 29 23:45:26 2008 -0400
@@ -42,7 +42,7 @@ if ($submit) {
   
   while (list($key,$val)=each($qlist)) {
     $var="q_".$key;
-    $quota->setquota($key,$$var);
+    $quota->setquota($key,$$var,$uid);
   }
   $mem->unsu();
   $error=_("The quotas has been successfully edited");
diff -r 6f8888f5530b class/m_admin.php
--- a/class/m_admin.php	Sat Apr 26 23:20:13 2008 -0400
+++ b/class/m_admin.php	Tue Apr 29 23:49:37 2008 -0400
@@ -277,7 +277,7 @@ class m_admin {
       $mem->su($uid);
       foreach($classes as $c) {
 	if (method_exists($GLOBALS[$c],"alternc_add_member")) {
-	  $GLOBALS[$c]->alternc_add_member();
+	  $GLOBALS[$c]->alternc_add_member($uid);
 	}
       }
       $mem->unsu();
@@ -342,7 +342,7 @@ class m_admin {
     if (($db->query("UPDATE local SET nom='$nom', prenom='$prenom' WHERE uid='$uid';"))
 	&&($db->query("UPDATE membres SET mail='$mail', canpass='$canpass', enabled='$enabled', type='$type' $ssq WHERE uid='$uid';"))){
       if($_POST['reset_quotas'] == "on")
-	$quota->addquotas();
+	$quota->addquotas($uid);
       $this->renew_update($uid, $duration);
       return true;
     }
diff -r 6f8888f5530b class/m_quota.php
--- a/class/m_quota.php	Sat Apr 26 23:20:13 2008 -0400
+++ b/class/m_quota.php	Tue Apr 29 23:54:49 2008 -0400
@@ -157,27 +157,34 @@ class m_quota {
   /** Set the quota for a user (and for a ressource)
    * @param string ressource to set quota of
    * @param integer size of the quota (available or used)
-   */
-  function setquota($ressource,$size) {
+   * @uid integer user id of the user (if 0, uses the connected user, which was the default behaviour before 0.9.9)
+   */
+  function setquota($ressource,$size,$uid=0) {
     global $err,$db,$cuid;
-    $err->log("quota","setquota",$ressource."/".$size);
-    if (intval($size)==0) $size="0";
+
+    // Default behaviour before AlternC 0.9.9 (which, IMHO, is wrong and should be removed)
+    if (! $uid) {
+	    $uid = $cuid;
+    }
+
+    $err->log("quota","setquota",$uid."/".$ressource."/".$size);
+    if (floatval($size)==0) $size="0";
     if ($this->disk[$ressource]) {
       // It's a disk resource, update it with shell command
-      exec("/usr/lib/alternc/quota_edit $cuid $size");
+      exec("/usr/lib/alternc/quota_edit $uid $size");
       // Now we check that the value has been written properly : 
-      exec("/usr/lib/alternc/quota_get ".$cuid,$a);
+      exec("/usr/lib/alternc/quota_get ".$uid,$a);
       if ($size!=$a[1]) {
 	$err->raise("quota",1);
 	return false;
       }
     }
     // We check that this ressource exists for this client :
-    $db->query("SELECT * FROM quotas WHERE uid='$cuid' AND name='$ressource'");
+    $db->query("SELECT * FROM quotas WHERE uid='$uid' AND name='$ressource'");
     if ($db->num_rows()) {
-	$db->query("UPDATE quotas SET total='$size' WHERE uid='$cuid' AND name='$ressource';");
+	$db->query("UPDATE quotas SET total='$size' WHERE uid='$uid' AND name='$ressource';");
     } else {
-	$db->query("INSERT INTO quotas (uid,name,total) VALUES ('$cuid','$ressource','$size');");
+	$db->query("INSERT INTO quotas (uid,name,total) VALUES ('$uid','$ressource','$size');");
     }
     return true;
   }
@@ -308,8 +315,9 @@ class m_quota {
   /* ----------------------------------------------------------------- */
   /**
    * Create default quotas entries for a new user.
-   */
-  function addquotas() {
+   * @param int user id
+   */
+  function addquotas($uid) {
     global $db,$err,$cuid;
     $err->log("quota","addquota");
     $ql=$this->qlist();
@@ -319,14 +327,14 @@ class m_quota {
     if(!$db->next_record())
       $this->addtype('default');
 
-    $db->query("SELECT type FROM membres WHERE uid='$cuid'");
+    $db->query("SELECT type FROM membres WHERE uid='$uid'");
     $db->next_record();
     $t = $db->f("type");
 
     foreach($ql as $res => $val) {
       $db->query("SELECT value FROM defquotas WHERE quota='$res' AND type='$t'");
       $q = $db->next_record() ? $db->f("value") : 0;
-      $this->setquota($res, $q);
+      $this->setquota($res, $q, $uid);
     }
     return true;
   }
@@ -360,9 +368,10 @@ class m_quota {
   /* ----------------------------------------------------------------- */
   /** Hook function call when a user is deleted
    * AlternC's standard function called when a user is deleted
-   */
-  function alternc_add_member() {
-    $this->addquotas();
+   * @param int user id
+   */
+  function alternc_add_member($uid) {
+    $this->addquotas($uid);
   }

05/13/08 04:43:35 changed by mlutfy

22:40 <@anarcat> si tu permets les commentaires... 22:40 <@anarcat> + function addquotas($uid) { 22:40 <@anarcat> je mettrais $uid = null 22:40 <@anarcat> pour ne pas briser l'api 22:40 <@anarcat> et faire un if is_null($uid) { $uid = $cuid }