Alternc  latest
Alternc logiel libre pour l'hébergement
alternc-check
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 
4 // TODO : we should accept a "-n" option that will mean : "don't do any action, but tell us" :)
5 
6 echo "Connecting to AlternC MySQL database... "; flush();
7 
8 define('NOCHECK', 1);
9 require_once("/usr/share/alternc/panel/class/config.php");
10 
11 echo "done.\n";
12 echo "------------------------------------------------------------\n";
13 echo "Statistics : \n";
14 
15 list($m1)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM membres;"));
16 echo " $m1 accounts\n";
17 list($m2)=@mysql_fetch_array(mysql_query("SELECT COUNT(DISTINCT path) FROM mail_users;"));
18 echo " $m2 pop accounts\n";
19 list($m3)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM domaines;"));
20 echo " $m3 domains\n";
21 list($m4)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sub_domaines;"));
22 echo " $m4 subdomains\n";
23 list($m5)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ftpusers;"));
24 echo " $m5 ftp accounts\n";
25 list($m6)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM aws;"));
26 if ($m6) echo " $m6 awstats statistics\n";
27 list($m7)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM mailman;"));
28 if ($m7) echo " $m7 mailing-lists using mailman\n";
29 
30 if (!$m1 && !$m2 && !$m3 && !$m4 && !$m5) {
31  echo "All statistics are wrong. We certainly have a connection problem. Please check !\n";
32  exit();
33 }
34 
35 $checks=array(
36  "1" => "Change owner and group of pop mail accounts",
37  "2" => "Change owner and group of html folders",
38  "3" => "Remove non-existent pop accounts in ALTERNC_MAIL",
39  "4" => "Remove non-existent alternc accounts in ALTERNC_HTML",
40  "5" => "Delete subdomains of non-existents folders pointers (dangling links)",
41  "6" => "Delete ftp accounts of non-existents folders",
42  "7" => "Delete mailman mailing-lists in mailman alternc table who does not exists anymore in /var/lib/mailman/lists",
43  "8" => "Delete mailman mailing-lists in /var/lib/mailman/lists who does not exists anymore in mailman alternc table",
44  "100" => "Send anonymous statistics regarding your AlternC installation to alternc team",
45  );
46 
47 echo "------------------------------------------------------------\n";
48 echo "The following checks can be done : \n";
49 foreach($checks as $k=>$v) {
50  echo " - $k : $v\n";
51 }
52 
53 if (!$argv[1]) {
54  do {
55  echo "\nPlease choose the check you want to do (or [a]ll of them) : ";
56  $f=fopen("php://stdin","rb");
57  $r=fgets($f,1024);
58  $r=strtolower(trim($r));
59  } while (!$r);
60 } else {
61  $r=strtolower(trim($argv[1]));
62 }
63 
64 
65 // Change owner and group of pop mail accounts
66 if ($r=="1" || $r=="a") {
67  echo "========== ".$checks[1]." STARTING (".date("d/m/Y H:i:s").")\n";
68  $r=mysql_query("SELECT DISTINCT(path),uid from mail_users;");
69  while ($c=mysql_fetch_array($r)) {
70  echo $c["path"]." ".$c["uid"]."\n";
71  if (substr($c["path"],0,17)==ALTERNC_MAIL) {
72  if (is_dir($c["path"])) {
73  exec("chown -R 33.".$c["uid"]." ".escapeshellarg($c["path"]));
74  } else {
75  echo "WARNING: Folder ".$c["path"]." does not exist. Please do relevant check to delete associated pop account\n";
76  }
77  } else {
78  echo "SKIPPED\n";
79  }
80  }
81  echo "========== ".$checks[1]." ENDING (".date("d/m/Y H:i:s").")\n";
82 }
83 
84 
85 // Change owner and group of html folders
86 if ($r=="2" || $r=="a") {
87  echo "========== ".$checks[2]." STARTING (".date("d/m/Y H:i:s").")\n";
88  $r=mysql_query("SELECT uid,login FROM membres;");
89  while ($c=mysql_fetch_array($r)) {
90  echo $c["login"]." ".$c["uid"]."\n";
91  if (is_dir(ALTERNC_HTML."/".substr($c["login"],0,1)."/".$c["login"])) {
92  exec("chown -R 33.".$c["uid"]." ".escapeshellarg(ALTERNC_HTML."/".substr($c["login"],0,1)."/".$c["login"]));
93  } else {
94  echo "WARNING: Folder ".ALTERNC_HTML."/".substr($c["login"],0,1)."/".$c["login"]." does not exist. Please do relevant check to delete associated alternc account, or recreate the folder\n";
95  }
96  }
97  echo "========== ".$checks[2]." ENDING (".date("d/m/Y H:i:s").")\n";
98 }
99 
100 
101 // Remove non-existent pop accounts in ALTERNC_MAIL
102 if ($r=="3" || $r=="a") {
103  echo "========== ".$checks[3]." STARTING (".date("d/m/Y H:i:s").")\n";
104  $mail=ALTERNC_MAIL;
105  $d1=opendir($mail);
106  while (($c1=readdir($d1))!==false) {
107  if (substr($c1,0,1)!="." && is_dir($mail."/".$c1)) {
108  $d2=opendir($mail."/".$c1);
109  while ($c2=readdir($d2)) {
110  if (substr($c2,0,1)!="." && is_dir($mail."/".$c1."/".$c2)) {
111  // Ok, we have a mail folder in /var/mail/alternc/p/popaccount_domain.tld/ Let's check it in the db :
112  list($alias)=@mysql_fetch_array(mysql_query("SELECT alias FROM mail_users WHERE path='".addslashes($mail."/".$c1."/".$c2)."';"));
113  if (!$alias) {
114  echo "WARNING: NOT FOUND: ".$mail."/".$c1."/".$c2.", deleting old pop folder.\n";
115  exec("rm -rf ".escapeshellarg($mail."/".$c1."/".$c2));
116  } else {
117  echo $alias." OK\n";
118  }
119  } elseif (is_file($mail."/".$c1."/".$c2)) {
120  echo "WARNING: File ".$mail."/".$c1."/".$c2." unexpected. You may delete it...\n";
121  }
122  }
123  closedir($d2);
124  } elseif (is_file($mail."/".$c1)) {
125  echo "WARNING: File ".$mail."/".$c1." unexpected. You may delete it...\n";
126  }
127 
128  }
129  closedir($d1);
130  echo "========== ".$checks[3]." ENDING (".date("d/m/Y H:i:s").")\n";
131 }
132 
133 
134 // Remove non-existent alternc accounts in ALTERNC_HTML
135 if ($r=="4" || $r=="a") {
136  echo "========== ".$checks[4]." STARTING (".date("d/m/Y H:i:s").")\n";
137  $html=ALTERNC_HTML;
138  $d1=opendir($html);
139  while (($c1=readdir($d1))!==false) {
140  if (substr($c1,0,1)!="." && is_dir($html."/".$c1)) {
141  $d2=opendir($html."/".$c1);
142  while ($c2=readdir($d2)) {
143  if (substr($c2,0,1)!="." && is_dir($html."/".$c1."/".$c2)) {
144  // Ok, we have a html folder in ALTERNC_HTML/u/user/ Let's check it in the db :
145  if (substr($c2,0,1)!=$c1) {
146  echo "WARNING: html folder is inconsistent in ".$html."/".$c1."/".$c2." YOU SHOULD FIX IT MANUALLY !\n";
147  } else {
148  list($uid)=@mysql_fetch_array(mysql_query("SELECT uid FROM membres WHERE login='".addslashes($c2)."';"));
149  if (!$uid) {
150  echo "WARNING: NOT FOUND: ".$html."/".$c1."/".$c2.", deleting old alternc account.\n";
151  exec("rm -rf ".escapeshellarg($html."/".$c1."/".$c2));
152  } else {
153  echo $c2." (".$uid.") OK\n";
154  }
155  }
156  } elseif (is_file($html."/".$c1."/".$c2)) {
157  echo "WARNING: File ".$html."/".$c1."/".$c2." unexpected. You may delete it...\n";
158  }
159  }
160  closedir($d2);
161  } elseif (is_file($html."/".$c1)) {
162  echo "WARNING: File ".$html."/".$c1." unexpected. You may delete it...\n";
163  }
164  }
165  closedir($d1);
166  echo "========== ".$checks[4]." ENDING (".date("d/m/Y H:i:s").")\n";
167 }
168 
169 // Delete subdomains of non-existents folders pointers (dangling links)
170 if ($r=="5" || $r=="a") {
171  echo "========== ".$checks[5]." STARTING (".date("d/m/Y H:i:s").")\n";
172  echo "NOT YET IMPLEMENTED\n";
173  echo "========== ".$checks[5]." ENDING (".date("d/m/Y H:i:s").")\n";
174 }
175 
176 
177 // Delete ftp accounts of non-existents folders
178 if ($r=="6" || $r=="a") {
179  echo "========== ".$checks[6]." STARTING (".date("d/m/Y H:i:s").")\n";
180  echo "NOT YET IMPLEMENTED\n";
181  echo "========== ".$checks[6]." ENDING (".date("d/m/Y H:i:s").")\n";
182 }
183 
184 
185 // Delete mailman mailing-lists in mailman alternc table who does not exists anymore in /var/lib/mailman/lists
186 if ($r=="7" || $r=="a") {
187  echo "========== ".$checks[7]." STARTING (".date("d/m/Y H:i:s").")\n";
188  echo "NOT YET IMPLEMENTED\n";
189  echo "========== ".$checks[7]." ENDING (".date("d/m/Y H:i:s").")\n";
190 }
191 
192 
193 // Delete mailman mailing-lists in /var/lib/mailman/lists who does not exists anymore in mailman alternc table
194 if ($r=="8" || $r=="a") {
195  echo "========== ".$checks[8]." STARTING (".date("d/m/Y H:i:s").")\n";
196  echo "NOT YET IMPLEMENTED\n";
197  echo "========== ".$checks[8]." ENDING (".date("d/m/Y H:i:s").")\n";
198 }
199 
200 
201 // Send anonymous statistics to AlternC team.
202 if ($r=="100" || $r=="a") {
203  $f=fopen("https://alternc.com/stats.php?m1=$m1&m2=$m2&m3=$m3&m4=$m4&m5=$m5&m6=$m6&m7=$m7","rb");
204  if ($f) {
205  while ($s=fgets($f,1024)) {
206  }
207  fclose($f);
208  }
209  }
210 
211 
212 ?>