36 lines
1.4 KiB
PHP
Executable File
36 lines
1.4 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
if (php_sapi_name() === 'cli') {
|
|
$method = 'GET';
|
|
} else {
|
|
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
|
|
}
|
|
|
|
try {
|
|
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
switch($method) {
|
|
case 'GET':
|
|
$stmt = $pdo->query("SELECT id, name, host, port, daily_limit, priority, status, created_at FROM smtp_servers ORDER BY priority, id");
|
|
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
echo json_encode(['success' => true, 'data' => $data], JSON_PRETTY_PRINT);
|
|
break;
|
|
|
|
case 'POST':
|
|
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
|
$stmt = $pdo->prepare("INSERT INTO smtp_servers (name, host, port, daily_limit, priority) VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->execute([$input['name'] ?? '', $input['host'] ?? '', $input['port'] ?? 587, $input['daily_limit'] ?? 1000, $input['priority'] ?? 1]);
|
|
echo json_encode(['success' => true, 'id' => $pdo->lastInsertId()]);
|
|
break;
|
|
|
|
default:
|
|
echo json_encode(['success' => false, 'error' => 'Method not supported: ' . $method]);
|
|
}
|
|
|
|
} catch(Exception $e) {
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|
|
?>
|