blob: fd7184f37b4cd5cab1be1efe523cac2481168eac [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(__DIR__."/../core.php");
22security::checkType(security::WORKER, security::METHOD_NOTFOUND);
23security::checkWorkerUIEnabled();
24secondFactor::checkAvailability();
25
26if (secondFactor::isEnabled()) {
27 security::notFound();
28}
29
30$secret = secondFactor::generateSecret();
31$url = "otpauth://totp/".str_replace("+", "%20", urlencode($conf["appName"])).":".urlencode(people::userData('username'))."?secret=".urlencode($secret)."&issuer=".str_replace("+", "%20", urlencode($conf["appName"]));
32?>
33
34<style>
35#dynDialog {
36 max-width: 500px;
37 width: auto;
38}
39
40.step {
41 padding: 10px 0;
42 border-bottom: 1px solid #ebebeb;
43}
44
45.step .number {
46 display: inline-block;
47 vertical-align: middle;
48 font-family: "Arial", sans-serif;
49 font-size: 36px;
50 font-weight: bold;
51 color: green;
52 margin: 0;
53 margin-right: 15px;
54 padding: 0;
55 line-height: normal;
56}
57
58.step .text {
59 display: inline-block;
60 vertical-align: middle;
61 margin: 0;
62 padding: 0;
63 width: Calc(100% - 40px);
64}
65
66.step .icon_container {
67 float: right;
68 height: 24px;
69 padding-top: 9px;
70 padding-right: 9px;
71}
72
73#qrcode {
74 margin: 8px 0;
75}
76
77#qrcode img, #qrcode canvas {
78 margin: auto;
79}
80</style>
81
82<dynscript>
83new QRCode(document.getElementById("qrcode"), {
84 text: "<?=security::htmlsafe($url)?>",
85 width: 200,
86 height: 200
87});
88</dynscript>
89
90<form action="doenablesecondfactor.php" method="POST" autocomplete="off">
91 <input type="hidden" name="secret" value="<?=security::htmlsafe($secret)?>">
92 <h4 class="mdl-dialog__title">Activa la verificación en dos pasos</h4>
93 <div class="mdl-dialog__content">
94 <p>Para activar la verificación en dos pasos, sigue los siguientes pasos:</p>
95
96 <div class="step">
97 <div class="number">1</div>
98 <div class="text"><b>Instala la aplicación Google Authenticator en tu <a href="http://appstore.com/googleauthenticator" target="_blank" rel="noopener noreferrer">iPhone</a> o <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target="_blank" rel="noopener noreferrer">Android</a>.</b><br>También puedes usar otra aplicación si lo prefieres.</div>
99 </div>
100 <div class="step">
101 <div class="number">2</div><div class="text"><b>Configura tu cuenta en la app Google Authenticator escaneando el siguiente código QR:</b></div>
102 </div>
103
104 <div id="qrcode"></div>
105
106 <div class="step" style="border-top: 1px solid #ebebeb;">
107 <div class="number">3</div><div class="text"><b>¿No puedes escanear el código QR? Introduce manualmente la siguiente clave secreta:</b><br><?=security::htmlsafe(secondFactorView::renderSecret($secret))?></div>
108 </div>
109 <div class="step" style="margin-bottom: 5px;">
110 <div class="number">4</div><div class="text"><b>Introduce el código de verificación de 6 dígitos:</b></div>
111 </div>
112 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
113 <input class="mdl-textfield__input" type="text" name="code" id="code" autocomplete="off" pattern="[0-9]{6}" data-required>
114 <label class="mdl-textfield__label" for="code">Código de verificación</label>
115 </div>
116 </div>
117 <div class="mdl-dialog__actions">
118 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--primary">Activar</button>
119 <button data-dyndialog-close class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
120 </div>
121</form>