quota_init 1.47 KB
Newer Older
1
#!/usr/bin/php -q
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<?php

/*
 This script create a quota entry for each existing user.
 and set the default quota to the specified value.
 (this script may be used when installing / upgrading an AlternC module)

 $argv[1] = The named quota to create
 $argv[2] = The default quota value for each user.
*/

if ($argc!=3) {
	echo "Usage : ".$argv[0]." <quota name> <quota value>
 Create a quota entry for each existing user and set the default quota to the 
 specified value.
";
	return 1;
}

$name=$argv[1];
$quota=$argv[2];

include("/var/alternc/bureau/class/local.php");

if (!mysql_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) {
	echo "Cannot connect to Mysql !\n";
	return 1;
}

if (!mysql_select_db($L_MYSQL_DATABASE)) {
	echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n";
	return 1;
}

$r=mysql_query("DELETE FROM defquotas WHERE quota='$name';");
if (mysql_errno()) {
	echo "Mysql Error : ".mysql_error()."\n";
	return 1;
}

$r=mysql_query("INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');");
if (mysql_errno()) {
	echo "Mysql Error : ".mysql_error()."\n";
	return 1;
}

$r=mysql_query("SELECT uid FROM membres;");
if (mysql_errno()) {
        echo "Mysql Error : ".mysql_error()."\n";
        return 1;
}
while ($c=mysql_fetch_array($r)) {
	$s=mysql_query("SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';");
	if (!mysql_num_rows($s)) {
		mysql_query("INSERT INTO quotas (uid,name,total,used) VALUES ('$c[uid]','$name','$value',0);");
	}
}

return 0;

62
?>