This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.php
145 lines (134 loc) · 4.73 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php declare(strict_types = 1);
defined('ROOT_PATH') or define('ROOT_PATH', '');
defined('INCLUDE_PATH') or define('INCLUDE_PATH', ROOT_PATH . 'includes/');
require_once INCLUDE_PATH . 'define.php';
require CONFIG_PATH . 'dbconnect.php';
// L'installation a-t-elle été faite ?
if (!\includes\SQL::existsDatabase($mysql_database)) {
echo "L'application n'est pas installée. Veuillez passer par l'installateur.";
exit();
}
function redirectAuth() : void
{
$request= "SELECT u_nom, u_passwd, u_prenom, u_is_resp, u_is_hr, u_is_admin, u_is_active FROM conges_users where u_login = '". \includes\SQL::quote($_SESSION['userlogin'])."' " ;
$rs = \includes\SQL::query($request );
if ($rs->num_rows != 1) {
redirect(ROOT_PATH . 'authentification');
} else {
$row = $rs->fetch_array();
$is_hr = $row["u_is_hr"];
$is_resp = $row["u_is_resp"];
$is_active = $row["u_is_active"];
if($is_active === "N") {
errorInactif();
return;
}
if ($is_hr === "Y") {
redirect( ROOT_PATH .'hr/page_principale');
} elseif ($is_resp==="Y") {
redirect( ROOT_PATH .'responsable/resp_index.php');
} else {
redirect( ROOT_PATH . 'utilisateur/user_index.php');
}
}
}
function errorInactif()
{
header_error();
echo _('session_compte_inactif') ."<br>\n";
echo _('session_contactez_admin') ."\n";
bottom();
}
function errorAuthentification() {
header_error();
echo _('session_pas_de_compte_dans_dbconges') ."<br>\n";
echo _('session_contactez_admin') ."\n";
bottom();
}
function authCas(\App\Libraries\ApiClient $api, \App\Libraries\Configuration $config)
{
try {
$authData = authentification_passwd_conges_CAS();
if ($authData['username'] == "") {
throw new \Exception("Nom d'utilisateur vide");
}
session_create($authData['username']);
storeTokenApi($api, $authData['username'], $authData['proxyTicket']);
} catch (\Exception $e) {
errorAuthentification();
deconnexion_CAS($config->getUrlAccueil());
}
}
function authSso(\App\Libraries\ApiClient $api)
{
if (session_id() != "") {
session_destroy();
}
try {
$usernameSSO = authentification_AD_SSO();
if ($usernameSSO == "") {
throw new \Exception("Nom d'utilisateur vide");
}
session_create($usernameSSO);
storeTokenApi($api, $usernameSSO, '');
} catch (\Exception $e) {
errorAuthentification();
}
}
function authDefault(string $authMethod, \App\Libraries\ApiClient $api)
{
$session_username = $_POST['session_username'] ?? '';
$session_password = $_POST['session_password'] ?? '';
if (session_id() !== "") {
session_destroy();
}
if (($session_username == "") || ($session_password == "")) {
session_saisie_user_password("", "");
} else {
if ('ldap' == $authMethod) {
$usernameAuth = authentification_ldap_conges($session_username, $session_password);
} else {
$usernameAuth = authentification_passwd_conges($session_username, $session_password);
}
try {
if ($usernameAuth !== $session_username) {
throw new \Exception("Noms d'utilisateurs différents");
}
session_create($session_username);
storeTokenApi($api, $session_username, $session_password);
} catch (\Exception $e) {
// Log failed accesses, matching the default fail2ban nginx/apache auth rules
if (isset($_SERVER['SERVER_SOFTWARE']) && preg_match('/nginx/i', $_SERVER['SERVER_SOFTWARE'])) {
error_log('user "' . $session_username . '" was not found in "Libertempo"', 4);
} else {
error_log('user "' . $session_username . '" authentication failure for "Libertempo"', 4);
}
dd($e->getMessage());
$session_username="";
$session_password="";
$erreur="login_passwd_incorrect";
session_saisie_user_password($erreur, $session_username);
}
}
}
$sql = \includes\SQL::singleton();
$config = new \App\Libraries\Configuration($sql);
$injectableCreator = new \App\Libraries\InjectableCreator($sql, $config);
$api = $injectableCreator->get(\App\Libraries\ApiClient::class);
if (!session_is_valid()) {
$authMethod = $config->getHowToConnectUser();
switch ($authMethod) {
case 'cas':
authCas($api, $config);
break;
case 'sso':
authSso($api);
break;
default:
authDefault($authMethod, $api);
break;
}
}
if (isset($_SESSION['userlogin'])) {
redirectAuth();
}