https://bugs.koozali.org/show_bug.cgi?id=13233

--- Comment #10 from Brian Read <[email protected]> ---
use DBI;

my $db = $mailstats{DBName} || 'mailstats';
my $user = $mailstats{DBUser} || 'mailstats_rw';
my $pass = $mailstats{DBPass} || 'changeme';

# Connect to MariaDB temporarily for escaping
my $dbh = DBI->connect("dbi:mysql:;host=localhost", 'root',
'your_root_password', { RaiseError => 1, AutoCommit => 1 });

# Properly escape the password for SQL using quote()
my $escaped_pass = $dbh->quote($pass);

# Quote username and hostname safely as well
my $escaped_user = $dbh->quote($user);
my $escaped_host = $dbh->quote('localhost');

$OUT .= <<"END";
#! /bin/sh
if [ -d /var/lib/mysql/$db ]; then
  exit
fi
/usr/bin/mariadb <<EOF
CREATE DATABASE $db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE $db;
CREATE TABLE IF NOT EXISTS SummaryLogs (
  id INT AUTO_INCREMENT PRIMARY KEY,
  Date DATE,
  Hour INT,
  logData TEXT
);
CREATE USER $escaped_user@localhost IDENTIFIED BY $escaped_pass;
GRANT SELECT, INSERT, UPDATE, DELETE ON $db.* TO $escaped_user@localhost;
FLUSH PRIVILEGES;
EOF
END

# Disconnect after escaping
$dbh->disconnect;

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
_______________________________________________
Mail for each SME Contribs bug report
To unsubscribe, e-mail [email protected]
Searchable archive at https://lists.contribs.org/mailman/public/contribteam/

Reply via email to