noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
otp-link.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright Author Dany De Bontridder danydb@aevalys.eu 22/10/23
21
22
23/**
24 * @file
25 * @brief generate a QRCode for setting up freeOTP
26 *
27 *
28 */
29if (!file_exists($dirname . '/config.inc.php')) {
30 die("system not installed");
31}
32
33require_once __DIR__ . '/constant.php';
34?>
35<style>
36
37/***
38 * LOGO
39*************************************/
40#logo_id {
41 position:static;
42 top : 0px;
43 left:0px;
44 width:60px;
45 height:auto;
46 margin-left:10px;
47}
48/** small **/
49@media (min-width : 576px) {
50 #logo_id {
51 top : 10px;
52 left:20px;
53 width: 90px;
54 margin-left:20px;
55
56
57 }
58}
59/** medium**/
60@media (min-width : 768px) {
61 #logo_id {
62
63 }
64
65}
66/** large**/
67@media (min-width : 992px) {
68 #logo_id {
69
70 }
71}
72/** XL **/
73@media (min-width : 1200px) {
74 #logo_id {
75
76
77 }
78}
79div.content {
80
81}
82@media (min-width: 576px) {
83 div.content {
84 margin-left: 16px;
85 }
86}
87/* MeDium */
88@media (min-width: 768px) {
89 div.content {
90 margin-left: 32px;
91 }
92}
93/* LarGe */
94@media (min-width: 992px) {
95 div.content {
96 margin-left: 64px;
97 }
98}
99/* eXtraLarge */
100@media (min-width: 1200px) {
101 div.content {
102 margin-left: 128px;
103 }
104
105}
106#vrf_code {
107 font-size:200%;
108 width:9rem;
109 padding:0.5rem;
110}
111
112input[type=submit]{
113 font-size:200%;
114 width:9rem;
115 padding:0.5rem;
116}
117form {
118 width:70%;
119 margin-left:15%;
120}
121</style>
122 <img id="logo_id" src="image/logo10000.png" >
123<div class="content">
124<?php
125use Endroid\QrCode\Color\Color;
126use Endroid\QrCode\Encoding\Encoding;
127use Endroid\QrCode\ErrorCorrectionLevel;
128use Endroid\QrCode\QrCode;
129use Endroid\QrCode\Label\Label;
130use Endroid\QrCode\Logo\Logo;
131use Endroid\QrCode\RoundBlockSizeMode;
132use Endroid\QrCode\Writer\PngWriter;
133use Endroid\QrCode\Writer\ValidationException;
134use chillerlan\Authenticator\{
135 Authenticator,
136 AuthenticatorOptions
137};
138use chillerlan\Authenticator\Authenticators\AuthenticatorInterface;
139
141try {
142 $uuid = $http->get('otp');
143 $repository = new \Database(0);
144// remove old request (> 24 hours)
145 $repository->exec_sql("delete from otp_send_secret where os_timestamp < now()-interval '12 hours'");
146
147// check if UUID exist
148 $id = $repository->get_value("select os_id from otp_send_secret where os_request=$1",
149 [$uuid]);
150// if UUID doesn't exist exit
151 if ($repository->count() == 0) {
152 echo _("Expiré : vous devez redemander le renvoi de la clef");
153 return;
154 }
155
156// get email from id
158 $user = new Noalyss_User($repository, $otp_send->get('use_id'));
159 $secret = $user->get_otp_secret();
160
161 // OTP
162
163 $authenticator = new \Noalyss\OTP();
164 $authenticator->get_authenticator()->setSecret($secret);
165 $data= $authenticator->get_authenticator()->getUri(label:"noalyss:".$user->getEmail(),issuer:"noalyss.eu");
166// load secret for this id
167//echo "use with php -S localhost:5000 puis ouvrir index.html ";
168 $writer = new PngWriter();
169
170// Create QR code
171 $qrCode = new QrCode(
172 data: $data,
173 encoding: new Encoding('UTF-8'),
174 errorCorrectionLevel: ErrorCorrectionLevel::Medium,
175 size: 600,
176 margin: 10,
177 roundBlockSizeMode: RoundBlockSizeMode::Margin,
178 foregroundColor: new Color(0, 0, 0),
179 backgroundColor: new Color(255, 255, 255)
180 );
181
183 echo '<div style="margin:4rem">';
184 // generate the QRCode
185 echo '<h1>',_("Scanner ceci avec votre application OTP"),'</h1>';
186 ?>
187 <ol>
188 <li>
189 <a href="https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp" target="_blank">FreeOTP (libre)</a>
190 </li>
191 <li>
192 <a href="https://play.google.com/store/apps/details?id=com.beemdevelopment.aegis" target="_blank">AEgis Authenticator (libre)</a>
193 </li>
194 <li>
195 <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target="_blank">Google Authenticator</a>
196 </li>
197 </ol>
198 <?php
199 echo '<p>';
200 echo _("Scanner ce QRCode avec votre application OTP afin de l'ajouter");
201
202 if ( DEBUGNOALYSS > 1) { echo "code attendu",$authenticator->code();}
203 echo '</p>';
204
205
206 printf('<img src="data:image/png;base64,%s">', base64_encode($result->getString()));
207
208} catch (Exception $exc) {
209 record_log($e);
210 return;
211}
212?>
213
214</div>
215
216
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
$ret label
$opd_description style
$name size
$input_from type
manage the http input (get , post, request) and extract from an array
Data & function about connected users.
abstract of the table public.otp_send_secret
$dirname
Definition constant.php:42
$desc width