blob: 019dc67299095216410be43d8597bccd0005de90 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01002/*
3 * hores
4 * Copyright (c) 2023 Adrià Vilanova Martínez
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program.
18 * If not, see http://www.gnu.org/licenses/.
19 */
20
Copybara botbe50d492023-11-30 00:16:42 +010021require_once("core.php");
22security::checkType(security::WORKER);
23security::checkWorkerUIEnabled();
24secondFactor::checkAvailability();
25
26$mdHeaderRowBefore = visual::backBtn("security.php");
27?>
28<!DOCTYPE html>
29<html>
30<head>
31 <title><?php echo $conf["appName"]; ?></title>
32 <?php visual::includeHead(); ?>
33 <link rel="stylesheet" href="css/dashboard.css">
34
35 <style>
36 .addsecuritykey {
37 position: fixed;
38 bottom: 16px;
39 right: 16px;
40 z-index: 1000;
41 }
42 </style>
43</head>
44<?php visual::printBodyTag(); ?>
45 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
46 <button class="addsecuritykey mdl-button md-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--accent"><i class="material-icons">add</i><span class="mdl-ripple"></span></button>
47 <?php visual::includeNav(); ?>
48 <main class="mdl-layout__content">
49 <div class="page-content">
50 <div class="main mdl-shadow--4dp">
51 <h2>Llaves de seguridad</h2>
52 <?php
53 $securityKeys = secondFactor::getSecurityKeys();
54 if ($securityKeys === false) {
55 echo "<p>Ha ocurrido un error inesperado y no se ha podido obtener un listado de tus llaves de seguridad.</p>";
56 } elseif (count($securityKeys)) {
57 ?>
58 <div class="overflow-wrapper overflow-wrapper--for-table">
59 <table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
60 <thead>
61 <tr>
62 <th class="mdl-data-table__cell--non-numeric">Nombre</th>
63 <th class="mdl-data-table__cell--non-numeric">Fecha de registro</th>
64 <th class="mdl-data-table__cell--non-numeric">Último uso</th>
65 <th class="mdl-data-table__cell--non-numeric"></th>
66 </tr>
67 </thead>
68 <tbody>
69 <?php
70 foreach ($securityKeys as $s) {
71 ?>
72 <tr>
73 <td class="mdl-data-table__cell--non-numeric"><?=security::htmlsafe($s["name"])?></td>
74 <td class="mdl-data-table__cell--non-numeric"><?=security::htmlsafe($s["added"] !== null ? date("d/m/Y H:i", $s["added"]) : "-")?></td>
75 <td class="mdl-data-table__cell--non-numeric"><?=security::htmlsafe($s["lastused"] !== null ? date("d/m/Y H:i", $s["lastused"]) : "-")?></td>
76 <td class='mdl-data-table__cell--non-numeric'><a href='dynamic/deletesecuritykey.php?id=<?=(int)$s["id"]?>' data-dyndialog-href='dynamic/deletesecuritykey.php?id=<?=(int)$s["id"]?>' title='Eliminar llave de seguridad'><i class='material-icons icon'>delete</i></a></td>
77 </tr>
78 <?php
79 }
80 ?>
81 </tbody>
82 </table>
83 </div>
84 <?php
85 } else {
86 ?>
87 <p>Todavía no has añadido ninguna llave de seguridad.</p>
88 <p>Puedes añadir una haciendo clic en el botón de la esquina inferior derecha de la página.</p>
89 <?php
90 }
91 ?>
92 </div>
93 </div>
94 </main>
95 </div>
96
97 <dialog class="mdl-dialog" id="addsecuritykey">
98 <form method="POST" id="addsecuritykeyform">
99 <h4 class="mdl-dialog__title">Añadir llave de seguridad</h4>
100 <div class="mdl-dialog__content">
101 <p>Introduce un nombre para la llave de seguridad y haz clic en el botón añadir para empezar el proceso de registro:</p>
102 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
103 <input class="mdl-textfield__input" type="text" name="name" id="name" autocomplete="off" data-required>
104 <label class="mdl-textfield__label" for="name">Nombre</label>
105 </div>
106 </div>
107 <div class="mdl-dialog__actions">
108 <button id="registersecuritykey" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Registrar</button>
109 <button onclick="event.preventDefault(); document.querySelector('#addsecuritykey').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
110 </div>
111 </form>
112 </dialog>
113
114 <?php
115 visual::smartSnackbar([
116 ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."],
117 ["empty", "Faltan datos por introducir en el formulario."],
118 ["securitykeyadded", "Se ha registrado correctamente la llave de seguridad."],
119 ["securitykeydeleted", "Se ha eliminado correctamente la llave de seguridad."]
120 ]);
121 ?>
122
123 <script src="js/common_webauthn.js"></script>
124 <script src="js/securitykeys.js"></script>
125</body>
126</html>