From 29a213cc267e5ebfa8fdd53c1e266df14d8e3ddb Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 17 May 2018 15:15:56 -0400 Subject: [PATCH 1/3] Change function calls from mysql_* to mysqli_* Sourced from: https://raw.githubusercontent.com/soul9/AlternC/470ed9cd1535461c7a809ce6c8d55919b76f14a0/stretch/quota_init.diff @see https://github.com/AlternC/AlternC/issues/222 --- src/quota_init | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/quota_init b/src/quota_init index 8279109e..4013135b 100644 --- a/src/quota_init +++ b/src/quota_init @@ -23,37 +23,39 @@ $quota=$argv[2]; include("/usr/share/alternc/panel/class/local.php"); -if (!mysql_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) { +if (!mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) { echo "Cannot connect to Mysql !\n"; return 1; } -if (!mysql_select_db($L_MYSQL_DATABASE)) { +$co = mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD); + +if (!mysqli_select_db($co, $L_MYSQL_DATABASE)) { echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n"; return 1; } -$r=mysql_query("DELETE FROM defquotas WHERE quota='$name';"); -if (mysql_errno()) { - echo "Mysql Error : ".mysql_error()."\n"; +$r=mysqli_query($co, "DELETE FROM defquotas WHERE quota='$name';"); +if (mysqli_errno($co)) { + echo "Mysql Error : ".mysqli_error($co)."\n"; return 1; } -$r=mysql_query("INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');"); -if (mysql_errno()) { - echo "Mysql Error : ".mysql_error()."\n"; +$r=mysqli_query($co, "INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');"); +if (mysqli_errno($co)) { + echo "Mysql Error : ".mysqli_error($co)."\n"; return 1; } -$r=mysql_query("SELECT uid FROM membres;"); -if (mysql_errno()) { - echo "Mysql Error : ".mysql_error()."\n"; +$r=mysqli_query($co, "SELECT uid FROM membres;"); +if (mysqli_errno($co)) { + echo "Mysql Error : ".mysqli_error($co)."\n"; return 1; } -while ($c=mysql_fetch_array($r)) { - $s=mysql_query("SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';"); - if (!mysql_num_rows($s)) { - mysql_query("INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;"); +while ($c=mysqli_fetch_array($r)) { + $s=mysqli_query("SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';"); + if (!mysqli_num_rows($s)) { + mysqli_query("INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;"); } } From be8edc140da7eabd6ba61cadbf5f8c78b2d67d20 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 17 May 2018 17:57:32 -0400 Subject: [PATCH 2/3] Include connection parameter when calling mysqli_query --- src/quota_init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/quota_init b/src/quota_init index 4013135b..1b50632c 100644 --- a/src/quota_init +++ b/src/quota_init @@ -53,9 +53,9 @@ if (mysqli_errno($co)) { return 1; } while ($c=mysqli_fetch_array($r)) { - $s=mysqli_query("SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';"); + $s=mysqli_query($co, "SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';"); if (!mysqli_num_rows($s)) { - mysqli_query("INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;"); + mysqli_query($co, "INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;"); } } From 1c910f4448e75867a4504d81aac3f57f28ff0642 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 17 May 2018 17:58:38 -0400 Subject: [PATCH 3/3] Remove trailing spaces / tabs from quota_init --- src/quota_init | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/quota_init b/src/quota_init index 1b50632c..5cd58deb 100644 --- a/src/quota_init +++ b/src/quota_init @@ -11,11 +11,11 @@ */ if ($argc!=3) { - echo "Usage : ".$argv[0]." - Create a quota entry for each existing user and set the default quota to the + echo "Usage : ".$argv[0]." + Create a quota entry for each existing user and set the default quota to the specified value. "; - return 1; + return 1; } $name=$argv[1]; @@ -24,27 +24,27 @@ $quota=$argv[2]; include("/usr/share/alternc/panel/class/local.php"); if (!mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD)) { - echo "Cannot connect to Mysql !\n"; - return 1; + echo "Cannot connect to Mysql !\n"; + return 1; } $co = mysqli_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD); if (!mysqli_select_db($co, $L_MYSQL_DATABASE)) { - echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n"; - return 1; + echo "Cannot connect to Mysql database $L_MYSQL_DATABASE !\n"; + return 1; } $r=mysqli_query($co, "DELETE FROM defquotas WHERE quota='$name';"); if (mysqli_errno($co)) { - echo "Mysql Error : ".mysqli_error($co)."\n"; - return 1; + echo "Mysql Error : ".mysqli_error($co)."\n"; + return 1; } $r=mysqli_query($co, "INSERT INTO defquotas (quota,value) VALUES ('$name','$quota');"); if (mysqli_errno($co)) { - echo "Mysql Error : ".mysqli_error($co)."\n"; - return 1; + echo "Mysql Error : ".mysqli_error($co)."\n"; + return 1; } $r=mysqli_query($co, "SELECT uid FROM membres;"); @@ -53,10 +53,10 @@ if (mysqli_errno($co)) { return 1; } while ($c=mysqli_fetch_array($r)) { - $s=mysqli_query($co, "SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';"); - if (!mysqli_num_rows($s)) { - mysqli_query($co, "INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;"); - } + $s=mysqli_query($co, "SELECT name FROM quotas WHERE uid='$c[uid]' AND name='$name';"); + if (!mysqli_num_rows($s)) { + mysqli_query($co, "INSERT INTO quotas (uid,name,total) VALUES ('$c[uid]','$name','$quota') on DUPLICATE KEY UPDATE total=$quota;"); + } } return 0;