90a6a4814c73ff1179d64ffb0b14424f43a4404c
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2005 Cajus Pollmeier
6 This program 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.
11 This program 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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 /* Load required includes */
22 require_once ("../include/php_setup.inc");
23 require_once ("functions.inc");
24 header("Content-type: text/html; charset=UTF-8");
26 /* Reset error handler */
27 $error_collector= "";
28 set_error_handler('gosaRaiseError');
30 /* Set error handler to own one, initialize time calculation
31 and start session. */
32 session_start ();
33 $username= "";
35 /* Check if we need to run setup */
36 if (!file_exists(CONFIG_DIR."/gosa.conf")){
37 header("location:setup.php");
38 exit();
39 }
41 /* Reset errors */
42 $_SESSION['errors']= "";
44 /* Check for java script */
45 if (!isset($_GET['js']) && !isset($_SESSION['js'])){
46 echo '<script language="JavaScript" type="text/javascript">';
47 echo ' location = "index.php?js=true";';
48 echo '</script>';
50 $_SESSION['js']= FALSE;
51 } else {
52 $_SESSION['js']= TRUE;
53 }
55 /* Check if gosa.conf is accessable */
56 if (!is_readable(CONFIG_DIR."/gosa.conf")){
57 print_red(sprintf(_("GOsa configuration %s/gosa.conf is not readable. Aborted."), CONFIG_DIR));
58 echo $_SESSION['errors'];
59 exit();
60 }
62 /* Parse configuration file */
63 $config= new config(CONFIG_DIR."/gosa.conf", $BASE_DIR);
64 $_SESSION['DEBUGLEVEL']= $config->data['MAIN']['DEBUGLEVEL'];
65 if ($_SERVER["REQUEST_METHOD"] != "POST"){
66 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
67 }
69 /* Set template compile directory */
70 if (isset ($config->data['MAIN']['COMPILE'])){
71 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
72 } else {
73 $smarty->compile_dir= '/var/spool/gosa';
74 }
75 $smarty->assign ('nextfield', 'username');
77 /* Check for compile directory */
78 if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))){
79 print_red(sprintf(_("Directory '%s' specified as compile directory is not accessable!"),
80 $smarty->compile_dir));
81 echo $_SESSION['errors'];
82 exit();
83 }
86 /* Language setup */
87 if ($config->data['MAIN']['LANG'] == ""){
88 $lang= get_browser_language();
89 } else {
90 $lang= $config->data['MAIN']['LANG'];
91 }
92 $lang.=".UTF-8";
93 putenv("LANGUAGE=");
94 putenv("LANG=$lang");
95 setlocale(LC_ALL, $lang);
96 $GLOBALS['t_language']= $lang;
97 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
99 /* Set the text domain as 'messages' */
100 $domain = 'messages';
101 bindtextdomain($domain, "$BASE_DIR/locale");
102 textdomain($domain);
105 if ($_SERVER["REQUEST_METHOD"] != "POST"){
106 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
107 }
110 /* Check for SSL connection */
111 $ssl= "";
112 if (!isset($HTTP_SERVER_VARS['HTTPS']) ||
113 !stristr($HTTP_SERVER_VARS['HTTPS'], "on")) {
115 if (empty($HTTP_SERVER_VARS['REQUEST_URI'])) {
116 $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
117 $HTTP_SERVER_VARS['PATH_INFO'];
118 } else {
119 $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
120 $HTTP_SERVER_VARS['REQUEST_URI'];
121 }
122 }
124 /* If SSL is forced, just forward to the SSL enabled site */
125 if ($config->data['MAIN']['FORCESSL'] == 'true'){
126 header ("Location: $ssl");
127 exit;
128 }
130 /* Got a formular answer, validate and try to log in */
131 if ($_SERVER["REQUEST_METHOD"] == "POST"){
133 /* Reset error messages */
134 $message= "";
136 $server= validate($_POST["server"]);
137 $config->set_current($server);
139 /* Admin-logon and verify */
140 $ldap = $config->get_ldap_link();
141 if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){
142 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
143 echo $_SESSION['errors'];
144 exit();
145 }
147 /* Check for locking area */
148 $ldap->cat($config->current['CONFIG']);
149 $attrs= $ldap->fetch();
150 if (!count ($attrs)){
151 $ldap->cd($config->current['BASE']);
152 $ldap->create_missing_trees($config->current['CONFIG']);
153 }
155 /* Check for at least one subtreeACL in the complete tree */
156 $ldap->cd($config->current['BASE']);
157 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
158 if ($ldap->count() < 1){
159 #FIXME: -> ldapsetup.tpl would be better
160 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
161 echo $_SESSION['errors'];
162 exit;
163 }
165 /* Check for valid input */
166 $username= $_POST["username"];
167 if (!ereg("^[A-Za-z0-9_.-]+$", $username)){
168 $message= _("Please specify a valid username!");
169 } elseif (mb_strlen($_POST["password"], 'UTF-8') == 0){
170 $message= _("Please specify your password!");
171 $smarty->assign ('nextfield', 'password');
172 } else {
174 /* Login as user, initialize user ACL's */
175 $ui= ldap_login_user($username, $_POST["password"]);
176 if ($ui === NULL || $ui == 0){
177 $message= _("Please check the username/password combination.");
178 $smarty->assign ('nextfield', 'password');
179 gosa_log ("Authentication failed for user \"$username\"");
180 } else {
181 /* Remove all locks of this user */
182 del_user_locks($ui->dn);
184 /* Save userinfo and plugin structure */
185 $_SESSION['ui']= $ui;
186 $_SESSION['session_cnt']= 0;
188 /* Let GOsa trigger a new connection for each POST, save
189 config to session. */
190 $_SESSION['config']= $config;
192 /* Go to main page */
193 gosa_log ("User \"$username\" logged in successfully");
194 header ("Location: main.php?global_check=1");
195 exit;
196 }
197 }
198 }
200 /* Fill template with required values */
201 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
202 $smarty->assign ('username', $username);
203 $smarty->assign ('personal_img', get_template_path('images/personal.png'));
204 $smarty->assign ('password_img', get_template_path('images/password.png'));
205 $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
207 /* Some error to display? */
208 if (!isset($message)){
209 $message= "";
210 }
211 $smarty->assign ("message", $message);
213 /* Displasy SSL mode warning? */
214 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
215 $smarty->assign ("ssl", "<b>"._("Warning").":</b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."</b></a>!");
216 } else {
217 $smarty->assign ("ssl", "");
218 }
220 /* Generate server list */
221 $servers= array();
222 if (isset($_POST['server'])){
223 $selected= validate($_POST['server']);
224 } else {
225 $selected= $config->data['MAIN']['DEFAULT'];
226 }
227 foreach ($config->data['LOCATIONS'] as $key => $ignored){
228 $servers[$key]= $key;
229 }
230 $smarty->assign ("server_options", $servers);
231 $smarty->assign ("server_id", $selected);
233 /* show login screen */
234 $smarty->display (get_template_path('headers.tpl'));
235 $smarty->assign ("PHPSESSID", session_id());
236 if (isset($_SESSION['errors'])){
237 $smarty->assign("errors", $_SESSION['errors']);
238 }
239 $smarty->assign("php_error", $error_collector."</div>");
240 $smarty->display (get_template_path('login.tpl'));
242 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
243 ?>
245 </body>
246 </html>