[fix] fixing utility scripts to use PDO instead of mysql_query (php7 compatibility for stretch)
This commit is contained in:
parent
6d804d1a95
commit
24b37b2777
|
@ -44,58 +44,58 @@ 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;
|
||||||
if (!$srv[$c["id"]]) {
|
$srv[$c["id"]]=new DB_Sql("mysql",$c["host"],$c["login"],$c["password"]);
|
||||||
echo "Can't connect to server having id ".$c["id"]." at host ".$c["host"]." EXITING !\n";
|
if (!$srv[$c["id"]]) {
|
||||||
exit();
|
echo "Can't connect to server having id ".$c["id"]." at host ".$c["host"]." EXITING !\n";
|
||||||
}
|
exit();
|
||||||
|
}
|
||||||
$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()) {
|
||||||
$membres[$c["uid"]]=array($c["login"],$c["db_server_id"]);
|
$c=$db->Record;
|
||||||
|
$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;
|
||||||
echo " ".$d["db"];
|
$srv[$srvid]->query("GRANT ALL ON ".$d["db"].".* TO '".$uid."_myadm'@'".$client[$srvid]."';");
|
||||||
echo mysql_error();
|
echo " ".$d["db"];
|
||||||
|
if (is_array($srv[$srvid]->last_error())) echo implode("\n",$srv[$srvid]->last_error());
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,41 +52,40 @@ 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()) {
|
||||||
if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") ||
|
$c=$db->Record;
|
||||||
!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) {
|
if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") ||
|
||||||
echo "Creating Opendkim key for domain ".$c["domaine"]."\n";
|
!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) {
|
||||||
if (!is_dir("/etc/opendkim/keys/".$c["domaine"]."")) {
|
echo "Creating Opendkim key for domain ".$c["domaine"]."\n";
|
||||||
if (!mkdir("/etc/opendkim/keys/".$c["domaine"]."")) {
|
if (!is_dir("/etc/opendkim/keys/".$c["domaine"]."")) {
|
||||||
echo "Error creating the directory /etc/opendkim/keys/".$c["domaine"]." !\n";
|
if (!mkdir("/etc/opendkim/keys/".$c["domaine"]."")) {
|
||||||
} else {
|
echo "Error creating the directory /etc/opendkim/keys/".$c["domaine"]." !\n";
|
||||||
echo "Created 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) {
|
if ($hasdoneone) {
|
||||||
echo "I created some keys, launching update_domaines...\n";
|
echo "I created some keys, launching update_domaines...\n";
|
||||||
passthru("/usr/lib/alternc/update_domains.sh 2>&1");
|
passthru("/usr/lib/alternc/update_domains.sh 2>&1");
|
||||||
} else {
|
} else {
|
||||||
echo "I did nothing, opendkim seems fine...\n";
|
echo "I did nothing, opendkim seems fine...\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue