-
Notifications
You must be signed in to change notification settings - Fork 5
/
login.php
executable file
·217 lines (194 loc) · 6.46 KB
/
login.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Fichier de login pour remplacer le login Horde
* Permet la récupération des pièces jointes depuis le Courrielleur
*
* @version @package_version@
*
* @author PNE Annuaire et Messagerie/MEDDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Configuration des logs
define('LOG_PATH', '/var/log/roundcube');
define('LOG_FILE', 'attachment.log');
define('SESSION_PATH', '/m2/sessions');
// Configuration du nom de l'application pour l'ORM
if (!defined('CONFIGURATION_APP_LIBM2')) {
define('CONFIGURATION_APP_LIBM2', 'roundcube');
}
// Inclusion de l'ORM
@include_once 'includes/libm2.php';
// Inclusion des vendors (pour l'ORM)
require_once 'vendor/autoload.php';
if (!is_internal()) {
header('HTTP/1.0 403 Forbidden');
write_log("[ERROR] login.php Not internal, forbidden");
echo 'You are forbidden!';
}
else {
// Récupération des paramètres
$username = rcube_utils::get_input_string("horde_user", rcube_utils::INPUT_GPC);
$password = rcube_utils::get_input_string("horde_pass", rcube_utils::INPUT_GPC);
// Positionner le path de la sesion
session_save_path(SESSION_PATH);
// Démarrage de session
session_start();
// Est-ce qu'une session en cours existe ?
if (isset($_SESSION["user_uid"])) {
write_log("[INFO] Session déjà en cours pour '$_SESSION[user_uid]'");
echo "Session déjà en cours pour '$_SESSION[user_uid]'\r\n";
}
if (isset($username)
&& isset($password)
&& \LibMelanie\Ldap\Ldap::Authentification($username, $password)) {
// Authentification OK
// Positionne l'utilisateur en session
$_SESSION["user_uid"] = $username;
write_log("[INFO] Login success for '$username'");
echo "Auth OK";
}
else {
// Authentification NOK
// Detruit la session
unset($_SESSION["user_uid"]);
write_log("[ERROR] Bad login or password for '$username'");
session_destroy();
echo "Auth KO";
}
}
/**
* Ecriture dans un fichier de log
* @param unknown $message
*/
function write_log($message) {
// Récupèration de l'adresse IP
$addrip = get_address_ip();
// Récupération du process ID
$procid = getmypid();
// Récupération de la date
$time = @date('[d/M/Y:H:i:s]');
// try to open specific log file for writing
$logfile = LOG_PATH.'/'.LOG_FILE;
if ($fp = @fopen($logfile, 'a')) {
fwrite($fp, "$time $addrip [$procid] $message\r\n");
fflush($fp);
fclose($fp);
return true;
}
}
/**
* Retourne l'adresse ip
* @return string
*/
function get_address_ip() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
/**
* Défini si on est dans une instance interne ou extene de l'application
* Permet la selection de la bonne url
*/
function is_internal() {
return (!isset($_SERVER["HTTP_X_MINEQPROVENANCE"]) || strcasecmp($_SERVER["HTTP_X_MINEQPROVENANCE"], "intranet") === 0);
}
/**
* Utility class providing common functions
*
* @package Framework
* @subpackage Utils
*/
class rcube_utils
{
// define constants for input reading
const INPUT_GET = 1;
const INPUT_POST = 2;
const INPUT_COOKIE = 4;
const INPUT_GP = 3; // GET + POST
const INPUT_GPC = 7; // GET + POST + COOKIE
/**
* Read input value and make sure it is a string.
*
* @param string $fname Field name to read
* @param int $source Source to get value from (see self::INPUT_*)
* @param bool $allow_html Allow HTML tags in field value
* @param string $charset Charset to convert into
*
* @return string Request parameter value
* @see self::get_input_value()
*/
public static function get_input_string($fname, $source, $allow_html = false, $charset = null)
{
$value = self::get_input_value($fname, $source, $allow_html, $charset);
return is_string($value) ? $value : '';
}
/**
* Read request parameter value and convert it for internal use
* Performs stripslashes() and charset conversion if necessary
*
* @param string $fname Field name to read
* @param int $source Source to get value from (see self::INPUT_*)
* @param bool $allow_html Allow HTML tags in field value
* @param string $charset Charset to convert into
*
* @return string|array|null Request parameter value or NULL if not set
*/
public static function get_input_value($fname, $source, $allow_html = false, $charset = null)
{
$value = null;
if (($source & self::INPUT_GET) && isset($_GET[$fname])) {
$value = $_GET[$fname];
}
if (($source & self::INPUT_POST) && isset($_POST[$fname])) {
$value = $_POST[$fname];
}
if (($source & self::INPUT_COOKIE) && isset($_COOKIE[$fname])) {
$value = $_COOKIE[$fname];
}
return self::parse_input_value($value, $allow_html, $charset);
}
/**
* Parse/validate input value. See self::get_input_value()
* Performs stripslashes() and charset conversion if necessary
*
* @param string $value Input value
* @param bool $allow_html Allow HTML tags in field value
* @param string $charset Charset to convert into
*
* @return string Parsed value
*/
public static function parse_input_value($value, $allow_html = false, $charset = null)
{
if (empty($value)) {
return $value;
}
if (is_array($value)) {
foreach ($value as $idx => $val) {
$value[$idx] = self::parse_input_value($val, $allow_html, $charset);
}
return $value;
}
// remove HTML tags if not allowed
if (!$allow_html) {
$value = strip_tags($value);
}
return $value;
}
}