Alternc  latest
Alternc logiel libre pour l'hébergement
quota_init
Go to the documentation of this file.
1 #!/usr/bin/php -q
2 <?php
3 
4 /*
5  This script create a quota entry for each existing user.
6  and set the default quota to the specified value.
7  (this script may be used when installing / upgrading an AlternC module)
8 
9  $argv[1] = The named quota to create
10  $argv[2] = The default quota value for each user.
11 */
12 
13 if ($argc!=3) {
14  echo "Usage : ".$argv[0]." <quota name> <quota value>
15  Create a quota entry for each existing user and set the default quota to the
16  specified value.
17 ";
18  return 1;
19 }
20 
21 $name=$argv[1];
22 $quota=$argv[2];
23 
24 include("/usr/share/alternc/panel/class/local.php");
25 
26 if (!mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) {
27  echo "Cannot connect to Mysql !\n";
28  return 1;
29 }
30 
31 $co = mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD);
32 
33 if (!mysqli_select_db($co, $L_MYSQL_DATABASE)) {
34  echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n";
35  return 1;
36 }
37 
38 $r=mysqli_query($co, "DELETE FROM defquotas WHERE quota='$name';");
39 if (mysqli_errno($co)) {
40  echo "Mysql Error : ".mysqli_error($co)."\n";
41  return 1;
42 }
43 
44 $r=mysqli_query($co, "INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');");
45 if (mysqli_errno($co)) {
46  echo "Mysql Error : ".mysqli_error($co)."\n";
47  return 1;
48 }
49 
50 $r=mysqli_query($co, "SELECT uid FROM membres;");
51 if (mysqli_errno($co)) {
52  echo "Mysql Error : ".mysqli_error($co)."\n";
53  return 1;
54 }
55 while ($c=mysqli_fetch_array($r)) {
56  $s=mysqli_query($co, "SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';");
57  if (!mysqli_num_rows($s)) {
58  mysqli_query($co, "INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;");
59  }
60 }
61 
62 return 0;
63 
64 ?>