diff --git a/src/alternc_fix_myadm_users.php b/src/alternc_fix_myadm_users.php index 2abbd421..0adf6bfb 100755 --- a/src/alternc_fix_myadm_users.php +++ b/src/alternc_fix_myadm_users.php @@ -44,58 +44,58 @@ function create_pass($length = 8){ return $password; } -$res=mysql_connect($mhost,$muser,$mpass); -if (!$res) { +require_once("/usr/share/alternc/panel/class/db_mysql.php"); +$db=new DB_Sql($mdb,$mhost,$muser,$mpass); +if (!$db) { echo "Can't connect to MySQL !\n"; exit(1); } -if (!mysql_select_db($mdb)) { - echo "Can't connect to DB MySQL !\n"; - exit(1); -} // Fix a bug in 3.0.0 -mysql_query("UPDATE dbusers SET enable='ACTIVATED' WHERE name!=CONCAT(uid,'_myadm');"); +$db->query("UPDATE dbusers SET enable='ACTIVATED' WHERE name!=CONCAT(uid,'_myadm');"); -$r=mysql_query("SELECT * FROM db_servers",$res); +$db->query("SELECT * FROM db_servers"); $srv=array(); $client=array(); -while ($c=mysql_fetch_array($r)) { - $srv[$c["id"]]=mysql_connect($c["host"],$c["login"],$c["password"]); - if (!$srv[$c["id"]]) { - echo "Can't connect to server having id ".$c["id"]." at host ".$c["host"]." EXITING !\n"; - exit(); - } +while ($db->next_record()) { + $c=$db->Record; + $srv[$c["id"]]=new DB_Sql("mysql",$c["host"],$c["login"],$c["password"]); + if (!$srv[$c["id"]]) { + echo "Can't connect to server having id ".$c["id"]." at host ".$c["host"]." EXITING !\n"; + exit(); + } $client[$c["id"]]=$c["client"]; } -$r=mysql_query("SELECT uid, login, db_server_id FROM membres;",$res); -while ($c=mysql_fetch_array($r)) { - $membres[$c["uid"]]=array($c["login"],$c["db_server_id"]); +$r=$db->query("SELECT uid, login, db_server_id FROM membres;"); +while ($db->next_record()) { + $c=$db->Record; + $membres[$c["uid"]]=array($c["login"],$c["db_server_id"]); } foreach($membres as $uid => $data) { $membre=$data[0]; $srvid=$data[1]; - $ok=@mysql_fetch_array(mysql_query("SELECT * FROM dbusers WHERE uid=$uid AND NAME='".$uid."_myadm';",$res)); - if (!$ok) { + $db->query("SELECT * FROM dbusers WHERE uid=$uid AND NAME='".$uid."_myadm';"); + if (!$db->next_record()) { echo "Creating user ".$uid."_myadm for login ".$membre."\n"; $pass=create_pass(8); - mysql_query("INSERT INTO dbusers SET uid=$uid, name='".$uid."_myadm', password='$pass', enable='ADMIN';",$res); - echo mysql_error(); + $db->query("INSERT INTO dbusers SET uid=$uid, name='".$uid."_myadm', password='$pass', enable='ADMIN';"); + if (is_array($db->last_error())) echo implode("\n",$db->last_error()); } else { $pass=$ok["password"]; } echo "Granting rights to user ".$uid."_myadm for login ".$membre." ... "; // Now granting him access to all user's databases - mysql_query("GRANT USAGE ON *.* TO '".$uid."_myadm'@'".$client[$srvid]."' IDENTIFIED BY '$pass';",$srv[$srvid]); - echo mysql_error(); - $t=mysql_query("SELECT * FROM db WHERE uid=$uid;",$res); - echo mysql_error(); - while ($d=mysql_fetch_array($t)) { - mysql_query("GRANT ALL ON ".$d["db"].".* TO '".$uid."_myadm'@'".$client[$srvid]."';",$srv[$srvid]); - echo " ".$d["db"]; - echo mysql_error(); + $srv[$srvid]->query("GRANT USAGE ON *.* TO '".$uid."_myadm'@'".$client[$srvid]."' IDENTIFIED BY '$pass';"); + if (is_array($srv[$srvid]->last_error())) echo implode("\n",$srv[$srvid]->last_error()); + $t=$db->query("SELECT * FROM db WHERE uid=$uid;"); + if (is_array($db->last_error())) echo implode("\n",$db->last_error()); + while ($db->next_record()) { + $d=$db->Record; + $srv[$srvid]->query("GRANT ALL ON ".$d["db"].".* TO '".$uid."_myadm'@'".$client[$srvid]."';"); + echo " ".$d["db"]; + if (is_array($srv[$srvid]->last_error())) echo implode("\n",$srv[$srvid]->last_error()); } echo "\n"; } diff --git a/src/alternc_fix_opendkim.php b/src/alternc_fix_opendkim.php index 11aaf349..c956d9ab 100755 --- a/src/alternc_fix_opendkim.php +++ b/src/alternc_fix_opendkim.php @@ -52,41 +52,40 @@ if (!file_exists("/usr/bin/opendkim-genkey") exit(1); } -$res=mysql_connect($mhost,$muser,$mpass); -if (!$res) { + +require_once("/usr/share/alternc/panel/class/db_mysql.php"); +$db=new DB_Sql($mdb,$mhost,$muser,$mpass); +if (!$db) { echo "Can't connect to MySQL !\n"; exit(1); } -if (!mysql_select_db($mdb)) { - echo "Can't connect to DB MySQL !\n"; - exit(1); -} $hasdoneone=false; -$r=mysql_query("SELECT domaine FROM domaines where gesmx=1 AND gesdns=1;"); -while ($c=mysql_fetch_array($r)) { - if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") || - !file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) { - echo "Creating Opendkim key for domain ".$c["domaine"]."\n"; - if (!is_dir("/etc/opendkim/keys/".$c["domaine"]."")) { - if (!mkdir("/etc/opendkim/keys/".$c["domaine"]."")) { - echo "Error creating the directory /etc/opendkim/keys/".$c["domaine"]." !\n"; - } else { - echo "Created the directory /etc/opendkim/keys/".$c["domaine"]."\n"; - } +$r=$db->query("SELECT domaine FROM domaines where gesmx=1 AND gesdns=1;"); +while ($db->next_record()) { + $c=$db->Record; + if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") || + !file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) { + echo "Creating Opendkim key for domain ".$c["domaine"]."\n"; + if (!is_dir("/etc/opendkim/keys/".$c["domaine"]."")) { + if (!mkdir("/etc/opendkim/keys/".$c["domaine"]."")) { + echo "Error creating the directory /etc/opendkim/keys/".$c["domaine"]." !\n"; + } else { + echo "Created the directory /etc/opendkim/keys/".$c["domaine"]."\n"; + } + } + chdir("/etc/opendkim/keys/".$c["domaine"].""); + passthru("opendkim-genkey -r -d ".$c["domaine"]." -s alternc 2>&1"); + passthru("chown opendkim:opendkim alternc.private 2>&1"); + $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='".$c["domaine"]."';"); + $hasdoneone=true; } - chdir("/etc/opendkim/keys/".$c["domaine"].""); - passthru("opendkim-genkey -r -d ".$c["domaine"]." -s alternc 2>&1"); - passthru("chown opendkim:opendkim alternc.private 2>&1"); - mysql_query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='".$c["domaine"]."';"); - $hasdoneone=true; - } } if ($hasdoneone) { - echo "I created some keys, launching update_domaines...\n"; - passthru("/usr/lib/alternc/update_domains.sh 2>&1"); + echo "I created some keys, launching update_domaines...\n"; + passthru("/usr/lib/alternc/update_domains.sh 2>&1"); } else { - echo "I did nothing, opendkim seems fine...\n"; + echo "I did nothing, opendkim seems fine...\n"; }