From 65da25ba402a308f72dd3692335fbffbe1409f56 Mon Sep 17 00:00:00 2001 From: Thibault Pelloquin Date: Tue, 19 Oct 2021 23:32:45 +0200 Subject: Add script to handle ssh keys Work by Thibault --- .../websites/tools/tools/landing/ldap_ssh_keys.php | 348 +++++++++++++++++++++ 1 file changed, 348 insertions(+) create mode 100644 modules/private/websites/tools/tools/landing/ldap_ssh_keys.php (limited to 'modules') diff --git a/modules/private/websites/tools/tools/landing/ldap_ssh_keys.php b/modules/private/websites/tools/tools/landing/ldap_ssh_keys.php new file mode 100644 index 0000000..259e28d --- /dev/null +++ b/modules/private/websites/tools/tools/landing/ldap_ssh_keys.php @@ -0,0 +1,348 @@ + + + + ImmaeEu Account + + + + + + +
+

Gestion des clés SSH

+ $apps, + 'public_key' => $publicKey, + 'comment' => $comment, + ]; + } + + return $keys; +} + +function pushLdapInfos($keys) +{ + $con = doConnect(); + if (!isset($_SESSION["user_dn"])) + return false; + + return ldap_mod_replace($con, $_SESSION["user_dn"], array("immaeSshKey" => $keys)); +} + + +// Script +if (isset($_POST['deconnexion'])) { + $_SESSION = []; +} + +if (isset($_POST['sauvegarder'])) { + $editedKeys = []; + $errors = false; + $keysToSave = []; + foreach($_POST['keys'] as $id => $key) { + $editedKeys[$id] = $key; + if (!checkSshKey($key['public_key'])) { + $editedKeys[$id]['error'] = true; + $errors = true; + } + + if (!isset($key['apps'])) { + $editedKeys[$id]['apps'] = $key['apps'] = []; + + } + foreach ($key['apps'] as $app) { + if (!in_array($app, apps)) { + die("integrity"); + } + } + + if (!isset($editedKeys[$id]['error']) || $editedKeys[$id]['error'] !== true) { + $keysToSave[] = implode('|', $key['apps']) . ' ' . $key['public_key'] . ' ' . $key['comment']; + } + } + + if (!$errors) { + $successSave = pushLdapInfos($keysToSave); + } +} + +$loginErrors = ""; +if (isset($_POST['login'])) { + if (empty($_POST['username']) || empty($_POST['password'])) { + $loginErrors = "Le nom d'utilisateur et le mot de passe sont requis."; + } elseif (!checkLogin($_POST['username'], $_POST['password'])) { + $loginErrors = "Identifiants incorrects."; + } else { + $_SESSION['login'] = $_POST['username']; + } +} + +if (isUserLogged()) : + $keys = isset($editedKeys) ? $editedKeys : getLdapInfo(); +?> +

Connecté en tant que

+ +
+ +
+ + +

Clés enregistrées avec succès.

+ + +
+ + + $sshKey) : + ?> + + + + + + + + + + + + + + + + + + + +
Description
>
+ + + +
+ + +
+ + +
+

Login

+ + +

+ + + + + + + + + +
+ +
+ + + + -- cgit v1.2.3