Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / htdocs / login.php @ b069f62c

Historique | Voir | Annoter | Télécharger (9,15 ko)

1
<?php
2

    
3

    
4
/*
5
 * @version $Id: login.php 7763 2009-01-06 18:44:50Z moyo $
6
 -------------------------------------------------------------------------
7
 GLPI - Gestionnaire Libre de Parc Informatique
8
 Copyright (C) 2003-2009 by the INDEPNET Development Team.
9

10
 http://indepnet.net/   http://glpi-project.org
11
 -------------------------------------------------------------------------
12

13
 LICENSE
14

15
 This file is part of GLPI.
16

17
 GLPI is free software; you can redistribute it and/or modify
18
 it under the terms of the GNU General Public License as published by
19
 the Free Software Foundation; either version 2 of the License, or
20
 (at your option) any later version.
21

22
 GLPI is distributed in the hope that it will be useful,
23
 but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 GNU General Public License for more details.
26

27
 You should have received a copy of the GNU General Public License
28
 along with GLPI; if not, write to the Free Software
29
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
 --------------------------------------------------------------------------
31
 */
32

    
33
// ----------------------------------------------------------------------
34
// Original Author of file:
35
// Purpose of file:
36
// ----------------------------------------------------------------------
37

    
38
define('GLPI_ROOT', '.');
39
$NEEDED_ITEMS = array (
40
        "user",
41
        "profile",
42
        "setup",
43
        "group",
44
        "entity",
45
        "rulesengine",
46
        "rule.right",
47
);
48

    
49
include (GLPI_ROOT . "/inc/includes.php");
50

    
51
if (!isset($_SESSION["glpitest"])||$_SESSION["glpitest"]!='testcookie'){
52
        if (!is_writable(GLPI_SESSION_DIR)){
53
                glpi_header($CFG_GLPI['root_doc'] . "/index.php?error=2");
54
        } else {
55
                glpi_header($CFG_GLPI['root_doc'] . "/index.php?error=1");
56
        }
57
}
58

    
59
$_POST = array_map('stripslashes', $_POST);
60

    
61
//Do login and checks
62
//$user_present = 1;
63
if (!isset ($_POST['login_name'])){
64
        $_POST['login_name'] = "";
65
}
66

    
67
$identificat = new Identification();
68
$identificat->getAuthMethods();
69
$identificat->user_present=1;
70
$identificat->auth_succeded = false;
71

    
72
if (isset ($_POST['login_password'])) {
73
        $_POST['login_password'] = unclean_cross_side_scripting_deep($_POST['login_password']);
74
}
75

    
76
if (!isset ($_POST["noAUTO"]) && $auth_method=checkAlternateAuthSystems()) {
77

    
78
        if ($identificat->getAlternateAuthSystemsUserLogin($auth_method)&&!empty($identificat->user->fields['name'])){
79
                $user=$identificat->user->fields['name'];
80
                $identificat->auth_succeded = true;
81
                $identificat->extauth = 1;
82
                $identificat->user_present = $identificat->user->getFromDBbyName(addslashes($user));
83
                $identificat->user->fields['auth_method'] = $auth_method; 
84

    
85
                // if LDAP enabled too, get user's infos from LDAP
86
                $identificat->user->fields["id_auth"]=$CFG_GLPI['extra_ldap_server'];
87
                if (canUseLdap()){
88
                        if (isset($identificat->auth_methods["ldap"][$identificat->user->fields["id_auth"]])) {
89
                                $ldap_method = $identificat->auth_methods["ldap"][$identificat->user->fields["id_auth"]];
90
                                
91
                                $ds = connect_ldap($ldap_method["ldap_host"], $ldap_method["ldap_port"], $ldap_method["ldap_rootdn"], $ldap_method["ldap_pass"], $ldap_method["ldap_use_tls"],$ldap_method["ldap_opt_deref"]);
92
                                if ($ds) {
93
                                        $user_dn = ldap_search_user_dn($ds, $ldap_method["ldap_basedn"], $ldap_method["ldap_login"], $user, $ldap_method["ldap_condition"]);
94
                                        if ($user_dn) {
95
                                                $identificat->user->getFromLDAP($ds,$ldap_method, $user_dn, $ldap_method["ldap_rootdn"], $ldap_method["ldap_pass"]);
96
                                        }
97
                                }
98
                        }
99
                }
100
                // Reset to secure it
101
                $identificat->user->fields['name']=$user;
102
                $identificat->user->fields["last_login"] = $_SESSION["glpi_currenttime"];
103
        } else {
104
                $identificat->addToError($LANG["login"][8]);
105
        }
106
}
107

    
108
        if (isset ($_POST["noAUTO"])){
109
                $_SESSION["noAUTO"] = 1;
110
        }
111

    
112
        // If not already auth
113
        if (!$identificat->auth_succeded){ 
114
                if (empty ($_POST['login_name']) || empty ($_POST['login_password'])) {
115
                        $identificat->addToError($LANG["login"][8]);
116
                } else {
117
        
118
                        // exists=0 -> no exist
119
                        // exists=1 -> exist with password
120
                        // exists=2 -> exist without password
121
                        $exists = $identificat->userExists(addslashes($_POST['login_name']));
122
        
123
                        // Pas en premier car sinon on ne fait pas le blankpassword
124
                        // First try to connect via le DATABASE
125
                        if ($exists == 1) {
126
                                
127
                                // Without UTF8 decoding
128
                                if (!$identificat->auth_succeded){
129
                                        $identificat->auth_succeded = $identificat->connection_db(addslashes($_POST['login_name']), $_POST['login_password']);
130
                                        if ($identificat->auth_succeded) {
131
                                                $identificat->extauth=0;
132
                                                $identificat->user_present = $identificat->user->getFromDBbyName(addslashes($_POST['login_name']));
133
                                                $identificat->user->fields["auth_method"] = AUTH_DB_GLPI;
134
                                                $identificat->user->fields["password"] = $_POST['login_password'];
135
                                        } 
136
        
137
                                }
138
                        }
139
                        elseif ($exists == 2) {
140
                                //The user is not authenticated on the GLPI DB, but we need to get informations about him
141
                                //The determine authentication method
142
                                $identificat->user->getFromDBbyName(addslashes($_POST['login_name']));
143
                                
144
                                //If the user has already been logged, the method_auth and id_auth are already set
145
                                //so we test this connection first
146
                                switch ($identificat->user->fields["auth_method"]) {
147
                                        case AUTH_EXTERNAL:
148
                                        case AUTH_LDAP :
149
                                                if (canUseLdap()){
150
                                                        error_reporting(0);
151
                                                        $identificat = try_ldap_auth($identificat, $_POST['login_name'],
152
                                                                        $_POST['login_password'],$identificat->user->fields["id_auth"]);
153
                                                }
154
                                                break;
155
                                        case AUTH_MAIL :
156
                                                if (canUseImapPop()){
157
                                                        $identificat = try_mail_auth($identificat,$_POST['login_name'],
158
                                                                        $_POST['login_password'],$identificat->user->fields["id_auth"]);
159
                                                }
160
                                                break;
161
                                        case NOT_YET_AUTHENTIFIED:
162
                                                break;
163
                                }
164
                        }
165
        
166
                        //If the last good auth method is not valid anymore, we test all the methods !
167
                        //test all the ldap servers
168
                        if (!$identificat->auth_succeded && canUseLdap()){
169
                                error_reporting(0);
170
                                $identificat = try_ldap_auth($identificat,$_POST['login_name'],$_POST['login_password']);
171
                        }
172
        
173
                        //test all the imap/pop servers
174
                        if (!$identificat->auth_succeded && canUseImapPop()){
175
                                $identificat = try_mail_auth($identificat,$_POST['login_name'],$_POST['login_password']);
176
                        }
177
                        // Fin des tests de connexion
178
        
179
                }
180
        }
181

    
182
        // Ok, we have gathered sufficient data, if the first return false the user
183
        // are not present on the DB, so we add it.
184
        // if not, we update it.
185
        if (!$DB->isSlave() && $identificat->auth_succeded) {
186
                
187
                // Prepare data
188
                $identificat->user->fields["last_login"]=$_SESSION["glpi_currenttime"];
189
                if ($identificat->extauth){
190
                        $identificat->user->fields["_extauth"] = 1;                        
191
                }
192
                // Need auto add user ?
193
                if (!$identificat->user_present && $CFG_GLPI["auto_add_users"]) {
194
                        $input = $identificat->user->fields;
195
                        unset ($identificat->user->fields);
196
                        $identificat->user->add($input);
197
                } else        if (!$identificat->user_present) { // Auto add not enable so auth failed
198
                        $identificat->addToError($LANG["login"][11]);
199
                        $identificat->auth_succeded = false;
200
                } else        if ($identificat->user_present) {
201
                        // update user and Blank PWD to clean old database for the external auth
202
                        $identificat->user->update($identificat->user->fields);
203

    
204
                        if ($identificat->extauth) {
205
                                $identificat->user->blankPassword();
206
                        }
207
                }
208
        }
209
        // GET THE IP OF THE CLIENT
210
        $ip = (getenv("HTTP_X_FORWARDED_FOR") ? getenv("HTTP_X_FORWARDED_FOR") : getenv("REMOTE_ADDR"));
211

    
212
        // now we can continue with the process...
213
        if ($identificat->auth_succeded) {
214
                $identificat->initSession();
215
        } else { // we have done at least a good login? No, we exit. 
216
                nullHeader("Login", $_SERVER['PHP_SELF']);
217
                echo '<div align="center"><b>' . $identificat->getErr() . '</b><br><br>';
218
                echo '<b><a href="' . $CFG_GLPI["root_doc"] . '/logout.php">' . $LANG["login"][1] . '</a></b></div>';
219
                if ($CFG_GLPI["debug"] == DEMO_MODE){
220
                        logEvent(-1, "system", 1, "login", "failed login: " . $_POST['login_name'] . "  ($ip)");
221
                } else {
222
                        logEvent(-1, "system", 1, "login", $LANG["log"][41] . ": " . $_POST['login_name'] . " ($ip)");
223
                }
224
                nullFooter();
225
                exit();
226
        }
227

    
228
        // Log Event
229
        if ($CFG_GLPI["debug"] == DEMO_MODE){
230
                logEvent("-1", "system", 3, "login", $_POST['login_name'] . " logged in." . $LANG["log"][40] . " : " . $ip);
231
        } else {
232
                logEvent("-1", "system", 3, "login", $_POST['login_name'] . " " . $LANG["log"][40] . " : " . $ip);
233
        }
234

    
235
        // Redirect management
236
        $REDIRECT = "";
237
        if (isset ($_POST['redirect'])&&strlen($_POST['redirect'])>0){
238
                $REDIRECT = "?redirect=" .$_POST['redirect'];
239
        } else         if (isset ($_GET['redirect'])&&strlen($_GET['redirect'])>0){
240
                $REDIRECT = "?redirect=" .$_GET['redirect'];
241
        }
242

    
243
        // Redirect to Command Central if not post-only
244
        // ryxeo / erics 2009
245
        if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
246
                glpi_header($CFG_GLPI['root_doc'] . "/front/helpdesk.abuledu_details.php");
247
        } else {
248

    
249
          SimpleHeader("Erreur");
250
          print "<p>Vous ne devriez pas utiliser cette interface, votre compte vous donne accès à plus de choses que le simple suivi des interventions !</p>";
251
          print "<p>Retournez sur <a href=\"http://support.abuledu.net\">abuledu.net</a> et utilisez un compte utilisateur standard ou <a href=\"https://secure.ryxeo.com/glpi/index2.php\">connectez-vous sur la version complète d'AbulÉdu.NET</a>.</p>";
252
          nullFooter();
253

    
254
        }
255
?>
Redmine Appliance - Powered by TurnKey Linux