mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* peertube-test.php
|
|
*
|
|
* HTMX endpoint: tests PeerTube connectivity using the form's current values.
|
|
* Reads POST fields, performs a temporary settings update, tests, then returns
|
|
* an HTMX fragment with the result.
|
|
*/
|
|
require_once __DIR__ . '/../../../bootstrap.php';
|
|
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
|
AdminAuth::requireLogin();
|
|
|
|
require_once APP_ROOT . '/src/Database.php';
|
|
require_once APP_ROOT . '/src/SmtpRelay.php';
|
|
require_once APP_ROOT . '/src/PeerTubeService.php';
|
|
|
|
if (!isset($_POST['csrf_token'], $_SESSION['csrf_token'])
|
|
|| !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
|
|
http_response_code(403);
|
|
echo '<span style="color:var(--color-error);">Token CSRF invalide.</span>';
|
|
exit;
|
|
}
|
|
|
|
$db = new Database();
|
|
|
|
// Save current settings so we can test with the form values
|
|
$data = [
|
|
'instance_url' => $_POST['peertube_instance_url'] ?? '',
|
|
'channel_name' => $_POST['peertube_channel_name'] ?? '',
|
|
'privacy' => $_POST['peertube_privacy'] ?? 1,
|
|
];
|
|
PeerTubeService::updateSettings($db, $data);
|
|
|
|
$test = PeerTubeService::test($db);
|
|
|
|
if ($test['ok']) {
|
|
echo '<span style="color:var(--color-success);">✓ Connexion réussie — authentification et résolution de la chaîne OK.</span>';
|
|
} else {
|
|
echo '<span style="color:var(--color-error);">✗ ' . htmlspecialchars($test['error']) . '</span>';
|
|
}
|