fixing quota class, sorry boys <3
This commit is contained in:
		
							parent
							
								
									5c6f4071a3
								
							
						
					
					
						commit
						4a8bde0304
					
				|  | @ -1,40 +1,40 @@ | ||||||
| <?php | <?php | ||||||
| /* | /* | ||||||
|  ---------------------------------------------------------------------- |   ---------------------------------------------------------------------- | ||||||
|  AlternC - Web Hosting System |   AlternC - Web Hosting System | ||||||
|  Copyright (C) 2000-2012 by the AlternC Development Team. |   Copyright (C) 2000-2012 by the AlternC Development Team. | ||||||
|  https://alternc.org/ |   https://alternc.org/ | ||||||
|  ---------------------------------------------------------------------- |   ---------------------------------------------------------------------- | ||||||
|  LICENSE |   LICENSE | ||||||
| 
 | 
 | ||||||
|  This program is free software; you can redistribute it and/or |   This program is free software; you can redistribute it and/or | ||||||
|  modify it under the terms of the GNU General Public License (GPL) |   modify it under the terms of the GNU General Public License (GPL) | ||||||
|  as published by the Free Software Foundation; either version 2 |   as published by the Free Software Foundation; either version 2 | ||||||
|  of the License, or (at your option) any later version. |   of the License, or (at your option) any later version. | ||||||
| 
 | 
 | ||||||
|  This program is distributed in the hope that it will be useful, |   This program is distributed in the hope that it will be useful, | ||||||
|  but WITHOUT ANY WARRANTY; without even the implied warranty of |   but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  GNU General Public License for more details. |   GNU General Public License for more details. | ||||||
| 
 | 
 | ||||||
|  To read the license please visit http://www.gnu.org/copyleft/gpl.html |   To read the license please visit http://www.gnu.org/copyleft/gpl.html | ||||||
|  ---------------------------------------------------------------------- |   ---------------------------------------------------------------------- | ||||||
|  Purpose of file: Manage user quota |   Purpose of file: Manage user quota | ||||||
|  ---------------------------------------------------------------------- |   ---------------------------------------------------------------------- | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| * Class for hosting quotas management |  * Class for hosting quotas management | ||||||
| * |  * | ||||||
| * This class manages services' quotas for each user of AlternC. |  * This class manages services' quotas for each user of AlternC. | ||||||
| * The available quotas for each service is stored in the system.quotas |  * The available quotas for each service is stored in the system.quotas | ||||||
| * mysql table. The used value is computed by the class using a |  * mysql table. The used value is computed by the class using a | ||||||
| * callback function <code>alternc_quota_check($uid)</code> that |  * callback function <code>alternc_quota_check($uid)</code> that | ||||||
| * may by exported by each service class.<br> |  * may by exported by each service class.<br> | ||||||
| * each class may also export a function <code>alternc_quota_names()</code> |  * each class may also export a function <code>alternc_quota_names()</code> | ||||||
| * that returns an array with the quotas names managed by this class. |  * that returns an array with the quotas names managed by this class. | ||||||
| * |  * | ||||||
| */ |  */ | ||||||
| class m_quota { | class m_quota { | ||||||
| 
 | 
 | ||||||
|   var $disk=Array(  /* disk resource for which we will manage quotas */ |   var $disk=Array(  /* disk resource for which we will manage quotas */ | ||||||
|  | @ -127,49 +127,49 @@ class m_quota { | ||||||
|         return array("t"=>0, "u"=>0); |         return array("t"=>0, "u"=>0); | ||||||
|       } else { |       } else { | ||||||
|         while ($db->next_record()) { |         while ($db->next_record()) { | ||||||
|         $ttmp[]=$db->Record; | 	  $ttmp[]=$db->Record; | ||||||
|       }              | 	}              | ||||||
| 	// TODO: old hook method FIXME: remove when unused
 | 	// TODO: old hook method FIXME: remove when unused
 | ||||||
|       foreach ($ttmp as $tt) { | 	foreach ($ttmp as $tt) { | ||||||
| 	if (! isset( $this->clquota[$tt["name"]] )) continue; | 	  if (! isset( $this->clquota[$tt["name"]] )) continue; | ||||||
|         if (method_exists($GLOBALS[$this->clquota[$tt["name"]]],"alternc_get_quota")) { | 	  if (method_exists($GLOBALS[$this->clquota[$tt["name"]]],"alternc_get_quota")) { | ||||||
|           $this->quotas[$tt["name"]] =  | 	    $this->quotas[$tt["name"]] =  | ||||||
| 	    array(  | 	      array(  | ||||||
| 		  "t"=>$tt["total"],  | 		    "t"=>$tt["total"],  | ||||||
| 		  "u"=> $GLOBALS[$this->clquota[$tt["name"]]]->alternc_get_quota($tt["name"]) | 		    "u"=> $GLOBALS[$this->clquota[$tt["name"]]]->alternc_get_quota($tt["name"]) | ||||||
| 		   ); | 		     ); | ||||||
|         } |  | ||||||
|       }    |  | ||||||
|       foreach ($ttmp as $tt) { |  | ||||||
| 	$res=$hooks->invoke("",$tt["name"]); |  | ||||||
| 	foreach($res as $r) { |  | ||||||
| 	  if ($r) { |  | ||||||
| 	    $this->quotas[$tt["name"]]=array("t"=>$tt["total"],"u"); |  | ||||||
| 	  } | 	  } | ||||||
| 	} | 	} | ||||||
|  | 	foreach ($ttmp as $tt) { | ||||||
|  | 	  $res=$hooks->invoke("",$tt["name"]); | ||||||
|  | 	  foreach($res as $r) { | ||||||
|  | 	    if ($r) { | ||||||
|  | 	      $this->quotas[$tt["name"]]=array("t"=>$tt["total"],"u"); | ||||||
|  | 	    } | ||||||
|  | 	  } | ||||||
|  | 	} | ||||||
|  | 	reset($this->disk); | ||||||
|  | 	while (list($key,$val)=each($this->disk)) { | ||||||
|  | 	  $a=array();  | ||||||
|  | 	  exec("/usr/lib/alternc/quota_get ".$cuid ,$a); | ||||||
|  | 	  $this->quotas[$val]=array("t"=>$a[1],"u"=>$a[0]); | ||||||
|  | 	}    | ||||||
|  | 	$get_quota_cache[$cuid] = $this->quotas; | ||||||
|       } |       } | ||||||
|       reset($this->disk); |  | ||||||
|       while (list($key,$val)=each($this->disk)) { |  | ||||||
|         $a=array();  |  | ||||||
|         exec("/usr/lib/alternc/quota_get ".$cuid ,$a); |  | ||||||
|         $this->quotas[$val]=array("t"=>$a[1],"u"=>$a[0]); |  | ||||||
|       }    |  | ||||||
|       $get_quota_cache[$cuid] = $this->quotas; |  | ||||||
|     } |     } | ||||||
|      |        | ||||||
|     if ($ressource) { |     if ($ressource) { | ||||||
|       if (isset($this->quotas[$ressource]) ) { |       if (isset($this->quotas[$ressource]) ) { | ||||||
|         return $this->quotas[$ressource]; | 	return $this->quotas[$ressource]; | ||||||
|       } else { |       } else { | ||||||
|         return 0; | 	return 0; | ||||||
|       }  |       }  | ||||||
|     } else { |     } else { | ||||||
|       return $this->quotas; |       return $this->quotas; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 |    | ||||||
| 
 |    | ||||||
| 
 |  | ||||||
|   /* ----------------------------------------------------------------- */ |   /* ----------------------------------------------------------------- */ | ||||||
|   /** Set the quota for a user (and for a ressource) |   /** Set the quota for a user (and for a ressource) | ||||||
|    * @param string $ressource ressource to set quota of |    * @param string $ressource ressource to set quota of | ||||||
|  | @ -184,7 +184,7 @@ class m_quota { | ||||||
|       exec("/usr/lib/alternc/quota_edit $cuid $size &> /dev/null &"); |       exec("/usr/lib/alternc/quota_edit $cuid $size &> /dev/null &"); | ||||||
|       // Now we check that the value has been written properly : 
 |       // Now we check that the value has been written properly : 
 | ||||||
|       exec("/usr/lib/alternc/quota_get $cuid &> /dev/null &",$a); |       exec("/usr/lib/alternc/quota_get $cuid &> /dev/null &",$a); | ||||||
|     if ($size!=$a[1]) { |       if ($size!=$a[1]) { | ||||||
| 	$err->raise("quota",1); | 	$err->raise("quota",1); | ||||||
| 	return false; | 	return false; | ||||||
|       } |       } | ||||||
|  | @ -192,9 +192,9 @@ class m_quota { | ||||||
|     // We check that this ressource exists for this client :
 |     // 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='$cuid' AND name='$ressource'"); | ||||||
|     if ($db->num_rows()) { |     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='$cuid' AND name='$ressource';"); | ||||||
|     } else { |     } else { | ||||||
| 	$db->query("INSERT INTO quotas (uid,name,total) VALUES ('$cuid','$ressource','$size');"); |       $db->query("INSERT INTO quotas (uid,name,total) VALUES ('$cuid','$ressource','$size');"); | ||||||
|     } |     } | ||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Benjamin Sonntag
						Benjamin Sonntag