137 lines
5.7 KiB
PHP
137 lines
5.7 KiB
PHP
<?php
|
|
// public/login/config.php
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
|
require_once dirname(__DIR__, 2) . '/app/bootstrap.php';
|
|
if (!defined('BASE_PATH')) {
|
|
require_once dirname(__DIR__, 2) . '/config/config.php';
|
|
}
|
|
require_once BASE_PATH . '/includes/db.php';
|
|
require_once BASE_PATH . '/includes/csrf.php';
|
|
require_once BASE_PATH . '/src/ConfigRepo.php';
|
|
|
|
Session::startSecure(getenv('SESSION_NAME') ?: 'SID_IDENT');
|
|
ensure_admin();
|
|
csrf_start();
|
|
|
|
$cfg = config_repo_get();
|
|
$msg = null;
|
|
$err = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (!csrf_check($_POST['csrf'] ?? '')) {
|
|
http_response_code(403);
|
|
exit('CSRF');
|
|
}
|
|
|
|
$in = [
|
|
'oidc_issuer' => trim((string)($_POST['oidc_issuer'] ?? '')),
|
|
'oidc_name' => trim((string)($_POST['oidc_name'] ?? '')),
|
|
'oidc_client_id' => trim((string)($_POST['oidc_client_id'] ?? '')),
|
|
'oidc_client_secret' => trim((string)($_POST['oidc_client_secret'] ?? '')),
|
|
'oidc_redirect_uri' => trim((string)($_POST['oidc_redirect_uri'] ?? '')),
|
|
];
|
|
|
|
// validations simples
|
|
if ($in['allow_oidc']) {
|
|
if ($in['oidc_issuer'] === '' || $in['oidc_client_id'] === '' || $in['oidc_client_secret'] === '' || $in['oidc_redirect_uri'] === '') {
|
|
$err = 'OIDC activé mais champs incomplets.';
|
|
}
|
|
}
|
|
|
|
if (!$err) {
|
|
config_repo_save($in);
|
|
|
|
// Mise à jour du .env
|
|
$envPairs = [
|
|
'OIDC_ISSUER' => $in['oidc_issuer'] !== '' ? $in['oidc_issuer'] : null,
|
|
'OIDC_NAME' => $in['oidc_name'] !== '' ? $in['oidc_name'] : null,
|
|
'OIDC_CLIENT_ID' => $in['oidc_client_id'] !== '' ? $in['oidc_client_id'] : null,
|
|
'OIDC_CLIENT_SECRET' => $in['oidc_client_secret'] !== '' ? $in['oidc_client_secret'] : null,
|
|
'OIDC_REDIRECT_URI' => $in['oidc_redirect_uri'] !== '' ? $in['oidc_redirect_uri'] : null,
|
|
];
|
|
env_set_pairs(BASE_PATH.'/.env', $envPairs);
|
|
|
|
$cfg = config_repo_get();
|
|
$msg = 'Configuration enregistrée.';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Configuration authentification</title>
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<link href="/assets/bootstrap.min.css" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-light">
|
|
<div class="container py-4">
|
|
<h1 class="h3 mb-3">Configuration authentification</h1>
|
|
|
|
<?php if ($msg): ?><div class="alert alert-success"><?=htmlspecialchars($msg)?></div><?php endif; ?>
|
|
<?php if ($err): ?><div class="alert alert-danger"><?=htmlspecialchars($err)?></div><?php endif; ?>
|
|
|
|
<form method="post" class="card p-3">
|
|
<input type="hidden" name="csrf" value="<?=htmlspecialchars(csrf_token())?>">
|
|
<fieldset class="mb-3">
|
|
<legend class="h5">Modes de connexion</legend>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="allow_password" name="allow_password" <?= $cfg['allow_password'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="allow_password">Login + mot de passe autorisé</label>
|
|
</div>
|
|
<div class="form-check mt-2">
|
|
<input class="form-check-input" type="checkbox" id="allow_oidc" name="allow_oidc" <?= $cfg['allow_oidc'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="allow_oidc">Connexion OIDC autorisée</label>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="mb-3">
|
|
<legend class="h5">Inscriptions</legend>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" id="reg_open" name="registrations_open" value="open" <?= $cfg['registrations_open'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="reg_open">Ouvertes à tous</label>
|
|
</div>
|
|
<div class="form-check mt-2">
|
|
<input class="form-check-input" type="radio" id="reg_closed" name="registrations_open" value="closed" <?= !$cfg['registrations_open'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="reg_closed">Fermées</label>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="mb-3">
|
|
<legend class="h5">Paramètres OIDC</legend>
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label">Issuer URL</label>
|
|
<input type="url" name="oidc_issuer" class="form-control" value="<?=htmlspecialchars((string)$cfg['oidc_issuer'])?>" placeholder="https://idp.example.com/realms/xxx">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Nom affiché</label>
|
|
<input type="text" name="oidc_name" class="form-control" value="<?=htmlspecialchars((string)$cfg['oidc_name'])?>" placeholder="Keycloak, Azure AD…">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Client ID</label>
|
|
<input type="text" name="oidc_client_id" class="form-control" value="<?=htmlspecialchars((string)$cfg['oidc_client_id'])?>">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Client Secret</label>
|
|
<input type="password" name="oidc_client_secret" class="form-control" value="<?=htmlspecialchars((string)$cfg['oidc_client_secret'])?>">
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label">Redirect URI</label>
|
|
<input type="url" name="oidc_redirect_uri" class="form-control" value="<?=htmlspecialchars((string)$cfg['oidc_redirect_uri'])?>" placeholder="<?=htmlspecialchars(rtrim(getenv('APP_URL') ?: '', '/').'/oidc/callback')?>">
|
|
</div>
|
|
</div>
|
|
<p class="form-text mt-2">Ces champs alimentent le fichier <code>.env</code>.</p>
|
|
</fieldset>
|
|
|
|
<div class="mt-3">
|
|
<button class="btn btn-primary" type="submit">Enregistrer</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|