[fix] fixing utility scripts to use PDO instead of mysql_query (php7 compatibility for stretch)

This commit is contained in:
Benjamin Sonntag 2018-02-23 16:24:30 +01:00
parent 6d804d1a95
commit 24b37b2777
2 changed files with 54 additions and 55 deletions

View File

@ -44,24 +44,22 @@ function create_pass($length = 8){
return $password; return $password;
} }
$res=mysql_connect($mhost,$muser,$mpass); require_once("/usr/share/alternc/panel/class/db_mysql.php");
if (!$res) { $db=new DB_Sql($mdb,$mhost,$muser,$mpass);
if (!$db) {
echo "Can't connect to MySQL !\n"; echo "Can't connect to MySQL !\n";
exit(1); exit(1);
} }
if (!mysql_select_db($mdb)) {
echo "Can't connect to DB MySQL !\n";
exit(1);
}
// Fix a bug in 3.0.0 // 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(); $srv=array();
$client=array(); $client=array();
while ($c=mysql_fetch_array($r)) { while ($db->next_record()) {
$srv[$c["id"]]=mysql_connect($c["host"],$c["login"],$c["password"]); $c=$db->Record;
$srv[$c["id"]]=new DB_Sql("mysql",$c["host"],$c["login"],$c["password"]);
if (!$srv[$c["id"]]) { if (!$srv[$c["id"]]) {
echo "Can't connect to server having id ".$c["id"]." at host ".$c["host"]." EXITING !\n"; echo "Can't connect to server having id ".$c["id"]." at host ".$c["host"]." EXITING !\n";
exit(); exit();
@ -69,33 +67,35 @@ while ($c=mysql_fetch_array($r)) {
$client[$c["id"]]=$c["client"]; $client[$c["id"]]=$c["client"];
} }
$r=mysql_query("SELECT uid, login, db_server_id FROM membres;",$res); $r=$db->query("SELECT uid, login, db_server_id FROM membres;");
while ($c=mysql_fetch_array($r)) { while ($db->next_record()) {
$c=$db->Record;
$membres[$c["uid"]]=array($c["login"],$c["db_server_id"]); $membres[$c["uid"]]=array($c["login"],$c["db_server_id"]);
} }
foreach($membres as $uid => $data) { foreach($membres as $uid => $data) {
$membre=$data[0]; $membre=$data[0];
$srvid=$data[1]; $srvid=$data[1];
$ok=@mysql_fetch_array(mysql_query("SELECT * FROM dbusers WHERE uid=$uid AND NAME='".$uid."_myadm';",$res)); $db->query("SELECT * FROM dbusers WHERE uid=$uid AND NAME='".$uid."_myadm';");
if (!$ok) { if (!$db->next_record()) {
echo "Creating user ".$uid."_myadm for login ".$membre."\n"; echo "Creating user ".$uid."_myadm for login ".$membre."\n";
$pass=create_pass(8); $pass=create_pass(8);
mysql_query("INSERT INTO dbusers SET uid=$uid, name='".$uid."_myadm', password='$pass', enable='ADMIN';",$res); $db->query("INSERT INTO dbusers SET uid=$uid, name='".$uid."_myadm', password='$pass', enable='ADMIN';");
echo mysql_error(); if (is_array($db->last_error())) echo implode("\n",$db->last_error());
} else { } else {
$pass=$ok["password"]; $pass=$ok["password"];
} }
echo "Granting rights to user ".$uid."_myadm for login ".$membre." ... "; echo "Granting rights to user ".$uid."_myadm for login ".$membre." ... ";
// Now granting him access to all user's databases // Now granting him access to all user's databases
mysql_query("GRANT USAGE ON *.* TO '".$uid."_myadm'@'".$client[$srvid]."' IDENTIFIED BY '$pass';",$srv[$srvid]); $srv[$srvid]->query("GRANT USAGE ON *.* TO '".$uid."_myadm'@'".$client[$srvid]."' IDENTIFIED BY '$pass';");
echo mysql_error(); if (is_array($srv[$srvid]->last_error())) echo implode("\n",$srv[$srvid]->last_error());
$t=mysql_query("SELECT * FROM db WHERE uid=$uid;",$res); $t=$db->query("SELECT * FROM db WHERE uid=$uid;");
echo mysql_error(); if (is_array($db->last_error())) echo implode("\n",$db->last_error());
while ($d=mysql_fetch_array($t)) { while ($db->next_record()) {
mysql_query("GRANT ALL ON ".$d["db"].".* TO '".$uid."_myadm'@'".$client[$srvid]."';",$srv[$srvid]); $d=$db->Record;
$srv[$srvid]->query("GRANT ALL ON ".$d["db"].".* TO '".$uid."_myadm'@'".$client[$srvid]."';");
echo " ".$d["db"]; echo " ".$d["db"];
echo mysql_error(); if (is_array($srv[$srvid]->last_error())) echo implode("\n",$srv[$srvid]->last_error());
} }
echo "\n"; echo "\n";
} }

View File

@ -52,19 +52,18 @@ if (!file_exists("/usr/bin/opendkim-genkey")
exit(1); 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"; echo "Can't connect to MySQL !\n";
exit(1); exit(1);
} }
if (!mysql_select_db($mdb)) {
echo "Can't connect to DB MySQL !\n";
exit(1);
}
$hasdoneone=false; $hasdoneone=false;
$r=mysql_query("SELECT domaine FROM domaines where gesmx=1 AND gesdns=1;"); $r=$db->query("SELECT domaine FROM domaines where gesmx=1 AND gesdns=1;");
while ($c=mysql_fetch_array($r)) { while ($db->next_record()) {
$c=$db->Record;
if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") || if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") ||
!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) { !file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) {
echo "Creating Opendkim key for domain ".$c["domaine"]."\n"; echo "Creating Opendkim key for domain ".$c["domaine"]."\n";
@ -78,7 +77,7 @@ while ($c=mysql_fetch_array($r)) {
chdir("/etc/opendkim/keys/".$c["domaine"].""); chdir("/etc/opendkim/keys/".$c["domaine"]."");
passthru("opendkim-genkey -r -d ".$c["domaine"]." -s alternc 2>&1"); passthru("opendkim-genkey -r -d ".$c["domaine"]." -s alternc 2>&1");
passthru("chown opendkim:opendkim alternc.private 2>&1"); passthru("chown opendkim:opendkim alternc.private 2>&1");
mysql_query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='".$c["domaine"]."';"); $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='".$c["domaine"]."';");
$hasdoneone=true; $hasdoneone=true;
} }
} }