noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
login.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20require_once '../include/constant.php';
21
22require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
23MaintenanceMode("block.html");
24/*! \file
25 * \brief Login page
26 */
27
28
29// Verif if User and Pass match DB
30 // if no, then redirect to the login page
32
33if (defined('MULTI') && MULTI == 0)
34 $version = $rep->get_value('select val from repo_version');
35 else
36 $version = $rep->get_value('select val from version');
37
39/**
40 * If p_user is set , it means that the user tries to connect, the $_SESSION
41 * does not exist yet
42 */
43if ( isset ($_POST["p_user"] ) )
44{
45 $http=new HttpInput();
46
47 // clean OLD session
48 Noalyss_user::clean_session($http->post("p_user"));
49 $User=new Noalyss_user($rep);
50 $User->Check(false,'LOGIN');
51
52 /*
53 * Check repository version
54 */
55
57 {
58 echo html_page_start();
59 echo h1(_("Version base de donneés incorrecte"));
60 echo span(_('Un instant svp'));
61 echo alert(_('Version de base de données incorrectes, vous devez mettre à jour'));
62 echo "<META HTTP-EQUIV=\"REFRESH\" content=\"3;url=admin-noalyss.php??action=upgrade&sb=database\">";
63 exit();
64 }
65 if (defined('NOALYSS_CAPTCHA') && NOALYSS_CAPTCHA==true)
66 {
67 include("securimage/securimage.php");
68 $img = new Securimage();
69 $valid = $img->check($_POST['captcha_code']);
70 if ( $valid == false )
71 {
72 echo alert(_('Code invalide'));
73
74 header("Location: ".NOALYSS_URL."/index.php");
75 exit();
76 }
77 }
78
79 // if auth method = 1 send an email with number but only for PC access
80 if ($User->get_access_mode() =='PC' && $User->get_authent_method() == 1) {
81 // send an email and get the uuid of the request
82 $uuid=$User->send_code_otp ();
83
84 // var $backurl (string url) url before being disconnected
85 $backurl=(isset($_POST['backurl']))?$_POST['backurl']:"";
86
87 // display form to enter digit from email
88 $User->input_otp($uuid,$backurl);
89 // end
90 return;
91 }
92
93 // if auth method = 2 , only for PC access ask code from freeOTP
94 if ($User->get_access_mode() =='PC' && $User->get_authent_method() ==2 ) {
95 // var $backurl (string url) url before being disconnected
96 $backurl=(isset($_POST['backurl']))?$_POST['backurl']:"";
97 // display form to enter digit from email
98 $User->input_otp(url:$backurl);
99 // end
100 return;
101 }
102
103 if ($User->get_access_mode()=='PC')
104 {
105 // retrieve the previous locationforce the nocache
106 $backurl=NOALYSS_URL.'/user_login.php?v='.microtime(true);
107 if ( isset ($_POST['backurl'])) {
108 $backurl=urldecode($_POST['backurl']);
109 // check that backurl is valid
110 $backurl=preg_replace('/^.*\?/','',$backurl);
111 $backurl=NOALYSS_URL."/do.php?$backurl";
112 }
113 header("Location: $backurl");
114 exit();
115 } else {
116 header("Location: ".NOALYSS_URL."/mobile.php");
117 exit();
118 }
119}
120else
121{
122 /**
123 * User has a session
124 */
125 $rep=new Database();
126
127 /*
128 * Check repository version
129 */
130
131 if ( $version != DBVERSIONREPO)
132 {
133 echo html_page_start();
134 echo h1(_("Version base de donneés incorrecte"));
135 echo span(_('Un instant svp'));
136 echo alert(_('Version de base de données incorrectes, vous devez mettre à jour'));
137 echo "<META HTTP-EQUIV=\"REFRESH\" content=\"3;url=admin-noalyss.php?action=upgrade&sb=database\">";
138 exit();
139
140 }
141 $User=new Noalyss_user($rep);
142 /**
143 * OTP is asked and authentication method is via OTP
144 */
145 if (isset($_POST['to_validate']) || $User->get_authent_method() != 0) {
146
147 // remove also old one
148 $rep->exec_sql("delete from otp_send_secret where os_valid_time < now()");
149 try {
150 $request = $http->post("rq", "string", "");
151 $vrf_code = $http->post("vrf_code");
152
153 // if code was sent by email
154 if ($request != "") {
155 // find the row concerning this request
156 $os_id = $rep->get_value("select os_id from otp_send_secret
157 where os_request=$1
158 and use_id=$2
159 ",
160 [$request, $User->id]);
161
162 if ($os_id == "") {
163 echo "Désolé, votre code a expiré";
164 echo "<META HTTP-EQUIV=\"REFRESH\" content=\"0;url=index.php?v=".microtime(true)."\">";
165 return;
166 }
167
168 $otp_send_secret = new Otp_Send_Secret_SQL($rep, $os_id);
169 /**
170 * second code is valid, so delete it
171 */
172 if (
173 $vrf_code == $otp_send_secret->get('os_code')
174 || $User->check_otp($vrf_code)
175 ) {
176 $User->set_identified();
177 // var $backurl (string url) url before being disconnected
178 $backurl=NOALYSS_URL.'/user_login.php?v='.microtime(true);
179 if ( isset ($_POST['backurl'])) {
180 $backurl=urldecode($_POST['backurl']);
181 // check that backurl is valid
182 $backurl=preg_replace('/^.*\?/','',$backurl);
183 $backurl=NOALYSS_URL."/do.php?$backurl";
184 $otp_send_secret->delete();
185 }
186 header("Location: $backurl");
187 return;
188 } else {
189 // var $backurl (string url) url before being disconnected
190 $backurl=(isset($_POST['backurl']))?$_POST['backurl']:"";
191 $User->input_otp(uuid:$request,url:$backurl);
192 return;
193 }
194 } else {
195 // connection avec freeOTP / Google Authenticator
196 if ($User->check_otp($vrf_code) == true) {
197 $User->set_identified();
198 // var $backurl (string url) url before being disconnected
199 $backurl=NOALYSS_URL.'/user_login.php?v='.microtime(true);
200 if ( isset ($_POST['backurl'])) {
201 // var $backurl (string url) url before being disconnected
202 $backurl=urldecode($_POST['backurl']);
203 // check that backurl is valid
204
205 $backurl=preg_replace('/^.*\?/','',$backurl);
206 $backurl=NOALYSS_URL."/do.php?$backurl";
207 }
208 header("Location: $backurl");
209 return;
210 } else {
211 // var $backurl (string url) url before being disconnected
212 $backurl=NOALYSS_URL.'/user_login.php?v='.microtime(true);
213 $User->input_otp(url:$backurl);
214 return;
215 }
216 }
217 } catch (Exception $exc) {
218
219 record_log($exc);
220 }
221 }
222 $User->Check();
223
224 echo "<META HTTP-EQUIV=\"REFRESH\" content=\"0;url=user_login.php?v=".microtime(true)."\">";
225}
227?>
MaintenanceMode($p_file)
When you want to prevent users to connect, create a file in noalyss/ (NOALYSS_BASE) with the message ...
span($p_string, $p_extra='')
Definition ac_common.php:43
html_page_stop()
end tag
html_page_start($p_theme="", $p_script="", $p_script2="")
Default page header for each page.
h1($p_string, $p_class="")
Definition ac_common.php:72
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...
alert($p_msg, $buffer=false)
alert in javascript
_("actif, passif,charge,...")
contains the class for connecting to Noalyss
manage the http input (get , post, request) and extract from an array
abstract of the table public.otp_send_secret
const DBVERSIONREPO
Definition constant.php:37
$_POST['ac']
Definition do.php:323
for($e=0; $e< count($afiche); $e++) exit
$version
Definition install.php:494
Project: Securimage: A PHP class for creating and managing form CAPTCHA images File: securimage....
$valid
Definition recover.php:57