This repository has been archived on 2024-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
satori-services/public/get-user-names.php

66 lines
1.8 KiB
PHP
Raw Normal View History

2022-07-04 00:07:38 +00:00
<?php
$config = parse_ini_file(__DIR__ . '/../config/flashii.ini');
header('Content-Type: text/plain; charset=us-ascii');
$ids = filter_input(INPUT_GET, 'ids', FILTER_SANITIZE_STRING);
if(empty($ids))
die('-3:no ids');
$ids = explode(',', $ids);
if(count($ids) > 100)
die('-6:too many');
foreach($ids as $k => $id) {
$_id = intval($id);
if($id != $_id)
die('-4:format');
$ids[$k] = $_id;
}
$config = parse_ini_file($config['msz-config-path'], true, INI_SCANNER_TYPED);
if(empty($config))
die('-1:config gone');
$info = $config['Database'];
if(empty($config))
die('-2:config gone');
$dsn = 'mysql:';
if ($info['unix_socket'] ?? false) {
$dsn .= 'unix_socket=' . $info['unix_socket'] . ';';
} else {
$dsn .= 'host=' . ($info['host'] ?? '127.0.0.1') . ';';
$dsn .= 'port=' . intval($info['port'] ?? 3306) . ';';
}
$dsn .= 'charset=' . ($info['charset'] ?? 'utf8mb4') . ';';
$dsn .= 'dbname=' . ($info['database'] ?? 'misuzu') . ';';
try {
$flashii = new PDO($dsn, ($info['username'] ?? null), ($info['password'] ?? null), [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::MYSQL_ATTR_INIT_COMMAND => "
SET SESSION
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION',
time_zone = '+00:00';
"
]);
} catch(PDOException $ex) {
die('-5:db gone');
}
$rows = $flashii->query('SELECT `user_id`, `username` FROM `msz_users` WHERE `user_id` IN (' . implode(',', $ids) . ')')->fetchAll(PDO::FETCH_ASSOC);
$out = '';
foreach($rows as $row)
$out .= "{$row['user_id']}:{$row['username']};";
echo substr($out, 0, -1);