65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
#!/usr/bin/php -q
|
|
<?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("/usr/share/alternc/panel/class/local.php");
|
|
|
|
if (!mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) {
|
|
echo "Cannot connect to Mysql !\n";
|
|
return 1;
|
|
}
|
|
|
|
$co = mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD);
|
|
|
|
if (!mysqli_select_db($co, $L_MYSQL_DATABASE)) {
|
|
echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n";
|
|
return 1;
|
|
}
|
|
|
|
$r=mysqli_query($co, "DELETE FROM defquotas WHERE quota='$name';");
|
|
if (mysqli_errno($co)) {
|
|
echo "Mysql Error : ".mysqli_error($co)."\n";
|
|
return 1;
|
|
}
|
|
|
|
$r=mysqli_query($co, "INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');");
|
|
if (mysqli_errno($co)) {
|
|
echo "Mysql Error : ".mysqli_error($co)."\n";
|
|
return 1;
|
|
}
|
|
|
|
$r=mysqli_query($co, "SELECT uid FROM membres;");
|
|
if (mysqli_errno($co)) {
|
|
echo "Mysql Error : ".mysqli_error($co)."\n";
|
|
return 1;
|
|
}
|
|
while ($c=mysqli_fetch_array($r)) {
|
|
$s=mysqli_query($co, "SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';");
|
|
if (!mysqli_num_rows($s)) {
|
|
mysqli_query($co, "INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;");
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
?>
|