db][$line->user] = true; } return (array_key_exists($db, $mysql_access) && array_key_exists($account, $mysql_access[$db])); } function set_mysql_access($db, $account, $status) { $uid = $_SESSION['userinfo']['uid']; $db = mysql_real_escape_string($db); $account = mysql_real_escape_string($account); $query = ''; if ($status) { if (get_mysql_access($db, $account)) return NULL; $query = "INSERT INTO misc.mysql_access (`database`,user) VALUES ((SELECT id FROM misc.mysql_database WHERE name='{$db}' AND useraccount={$uid} LIMIT 1), (SELECT id FROM misc.mysql_accounts WHERE username='{$account}' AND useraccount={$uid}));"; logger("modules/mysql/include/mysql", "mysql", "granting access on »{$db}« to »{$account}«"); } else { if (! get_mysql_access($db, $account)) return NULL; $query = "DELETE FROM misc.mysql_access WHERE `database`=(SELECT id FROM misc.mysql_database WHERE name='{$db}' AND useraccount={$uid} LIMIT 1) AND user=(SELECT id FROM misc.mysql_accounts WHERE username='{$account}' AND useraccount={$uid});"; logger("modules/mysql/include/mysql", "mysql", "revoking access on »{$db}« from »{$account}«"); } db_query($query); } function create_mysql_account($username, $description = '') { if (! validate_mysql_username($username)) { logger("modules/mysql/include/mysql", "mysql", "illegal username »{$username}«"); input_error("Der eingegebene Benutzername entspricht leider nicht der Konvention. Bitte tragen Sie einen passenden Namen ein."); return NULL; } $uid = $_SESSION['userinfo']['uid']; $username = mysql_real_escape_string($username); $description = maybe_null($description); logger("modules/mysql/include/mysql", "mysql", "creating user »{$username}«"); db_query("INSERT INTO misc.mysql_accounts (username, password, useraccount, description) VALUES ('$username', '!', $uid, $description);"); } function delete_mysql_account($username) { $username = mysql_real_escape_string($username); $uid = $_SESSION['userinfo']['uid']; logger("modules/mysql/include/mysql", "mysql", "deleting user »{$username}«"); db_query("DELETE FROM misc.mysql_accounts WHERE username='{$username}' AND useraccount='{$uid}' LIMIT 1;"); } function create_mysql_database($dbname, $description = '') { if (! validate_mysql_dbname($dbname)) { logger("modules/mysql/include/mysql", "mysql", "illegal db-name »{$dbname}«"); input_error("Der eingegebene Datenbankname entspricht leider nicht der Konvention. Bitte tragen Sie einen passenden Namen ein."); return NULL; } $dbname = mysql_real_escape_string($dbname); $uid = $_SESSION['userinfo']['uid']; $description = maybe_null($description); logger("modules/mysql/include/mysql", "mysql", "creating database »{$dbname}«"); db_query("INSERT INTO misc.mysql_database (name, useraccount, description) VALUES ('$dbname', $uid, $description);"); } function delete_mysql_database($dbname) { $dbname = mysql_real_escape_string($dbname); $uid = $_SESSION['userinfo']['uid']; logger("modules/mysql/include/mysql", "mysql", "removing database »{$dbname}«"); db_query("DELETE FROM misc.mysql_database WHERE name='{$dbname}' AND useraccount='{$uid}' LIMIT 1;"); } function validate_mysql_dbname($dbname) { $sys_username = $_SESSION['userinfo']['username']; return preg_match("/^{$sys_username}(_[a-zA-Z0-9_-]+)?$/", $dbname); } function validate_mysql_username($username) { return validate_mysql_dbname($username) && (count($username) <= 16); } function set_mysql_password($username, $password) { $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $uid = $_SESSION['userinfo']['uid']; logger("modules/mysql/include/mysql", "mysql", "updating password for »{$username}«"); db_query("UPDATE misc.mysql_accounts SET password=PASSWORD('$password') WHERE username='$username' AND useraccount=$uid;"); } function has_mysql_database($dbname) { $uid = $_SESSION['userinfo']['uid']; $dbname = mysql_real_escape_string($dbname); $result = db_query("SELECT NULL FROM misc.mysql_database WHERE name='{$dbname}' AND useraccount='{$uid}' LIMIT 1;"); return (mysql_num_rows($result) == 1); } function has_mysql_user($username) { $uid = $_SESSION['userinfo']['uid']; $userame = mysql_real_escape_string($username); $result = db_query("SELECT NULL FROM misc.mysql_accounts WHERE username='{$username}' AND useraccount='{$uid}' LIMIT 1;"); return (mysql_num_rows($result) == 1); } ?>