4 // TODO : we should accept a "-n" option that will mean : "don't do any action, but tell us" :)
6 echo "Connecting to AlternC MySQL database... "; flush();
9 require_once("/usr/share/alternc/panel/class/config.php");
12 echo "------------------------------------------------------------\n";
13 echo "Statistics : \n";
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";
30 if (!$m1 && !$m2 && !$m3 && !$m4 && !$m5) {
31 echo "All statistics are wrong. We certainly have a connection problem. Please check !\n";
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",
47 echo "------------------------------------------------------------\n";
48 echo "The following checks can be done : \n";
49 foreach($checks as $k=>$v) {
55 echo "\nPlease choose the check you want to do (or [a]ll of them) : ";
56 $f=fopen("php://stdin","rb");
58 $r=strtolower(trim($r));
61 $r=strtolower(trim($argv[1]));
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"]));
75 echo "WARNING: Folder ".$c["path"]." does not exist. Please do relevant check to delete associated pop account\n";
81 echo "========== ".$checks[1]." ENDING (".date("d/m/Y H:i:s").")\n";
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"]));
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";
97 echo "========== ".$checks[2]." ENDING (".date("d/m/Y H:i:s").")\n";
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";
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)."';"));
114 echo "WARNING: NOT FOUND: ".$mail."/".$c1."/".$c2.", deleting old pop folder.\n";
115 exec("rm -rf ".escapeshellarg($mail."/".$c1."/".$c2));
119 } elseif (is_file($mail."/".$c1."/".$c2)) {
120 echo "WARNING: File ".$mail."/".$c1."/".$c2." unexpected. You may delete it...\n";
124 } elseif (is_file($mail."/".$c1)) {
125 echo "WARNING: File ".$mail."/".$c1." unexpected. You may delete it...\n";
130 echo "========== ".$checks[3]." ENDING (".date("d/m/Y H:i:s").")\n";
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";
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";
148 list($uid)=@mysql_fetch_array(mysql_query("SELECT uid FROM membres WHERE login='".addslashes($c2)."';"));
150 echo "WARNING: NOT FOUND: ".$html."/".$c1."/".$c2.", deleting old alternc account.\n";
151 exec("rm -rf ".escapeshellarg($html."/".$c1."/".$c2));
153 echo $c2." (".$uid.") OK\n";
156 } elseif (is_file($html."/".$c1."/".$c2)) {
157 echo "WARNING: File ".$html."/".$c1."/".$c2." unexpected. You may delete it...\n";
161 } elseif (is_file($html."/".$c1)) {
162 echo "WARNING: File ".$html."/".$c1." unexpected. You may delete it...\n";
166 echo "========== ".$checks[4]." ENDING (".date("d/m/Y H:i:s").")\n";
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";
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";
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";
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";
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");
205 while ($s=fgets($f,1024)) {