tp/read_sms_site_settings.php
2026-04-01 10:12:37 +08:00

41 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
$envPath = __DIR__ . DIRECTORY_SEPARATOR . '.env';
$lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (!$lines) {
echo "failed to read env: {$envPath}\n";
exit(1);
}
$map = [];
foreach ($lines as $line) {
$line = trim((string)$line);
if ($line === '' || strpos($line, '=') === false) {
continue;
}
$parts = explode('=', $line, 2);
$map[trim((string)$parts[0])] = trim((string)$parts[1]);
}
$dsn = 'mysql:host=' . $map['DB_HOST'] . ';port=' . $map['DB_PORT'] . ';dbname=' . $map['DB_NAME'] . ';charset=' . $map['DB_CHARSET'];
$pdo = new PDO($dsn, $map['DB_USER'], $map['DB_PASS'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
$stmt = $pdo->prepare('SELECT label,value FROM ' . $map['DB_PREFIX'] . 'system_site_settings WHERE label IN (?, ?) ORDER BY id ASC');
$stmt->execute(['backendUrl', 'apiKey']);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $r) {
$label = (string)$r['label'];
$value = (string)$r['value'];
if ($label === 'apiKey') {
$mask = substr($value, 0, 3) . '***' . substr($value, -3);
echo $label . '=' . $mask . PHP_EOL;
} else {
echo $label . '=' . $value . PHP_EOL;
}
}