Code

Updated some styles
[gosa.git] / html / index.php
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 function displayLogin()
27 {
28   global $smarty,$message,$config,$ssl,$error_collector;
29   error_reporting(E_ALL);
30     /* Fill template with required values */
31     $username = "";
32     if(isset($_POST["username"])){
33       $username= $_POST["username"];
34     }
35     $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
36     $smarty->assign ('username', $username);
37     $smarty->assign ('personal_img', get_template_path('images/personal.png'));
38     $smarty->assign ('password_img', get_template_path('images/password.png'));
39     $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
41     /* Some error to display? */
42     if (!isset($message)){
43       $message= "";
44     }
45     $smarty->assign ("message", $message);
47     /* Displasy SSL mode warning? */
48     if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
49       $smarty->assign ("ssl", "<b>"._("Warning").":<\/b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."<\/b></a>!");
50     } else {
51       $smarty->assign ("ssl", "");
52     }
54     /* Generate server list */
55     $servers= array();
56     if (isset($_POST['server'])){
57       $selected= validate($_POST['server']);
58     } else {
59       $selected= $config->data['MAIN']['DEFAULT'];
60     }
61     foreach ($config->data['LOCATIONS'] as $key => $ignored){
62       $servers[$key]= $key;
63     }
64     $smarty->assign ("server_options", $servers);
65     $smarty->assign ("server_id", $selected);
67     /* show login screen */
68     $smarty->assign ("PHPSESSID", session_id());
69     if (isset($_SESSION['errors'])){
70       $smarty->assign("errors", $_SESSION['errors']);
71     }
72     if ($error_collector != ""){
73       $smarty->assign("php_errors", $error_collector."</div>");
74     } else {
75       $smarty->assign("php_errors", "");
76     }
78     $smarty->display (get_template_path('headers.tpl'));
79     $smarty->display(get_template_path('login.tpl'));
80     exit();
81 }
85 /* Set error handler to own one, initialize time calculation
86    and start session. */
87 session_start ();
89 /* Destroy old session if exists. 
90     Else you will get your old session back, if you not logged out correctly. */
91 if(is_array($_SESSION) && count($_SESSION)){
92   session_destroy();
93   session_start();
94 }
96 $username= "";
98 /* Reset errors */
99 $_SESSION['errors']             = "";
100 $_SESSION['errorsAlreadyPosted']= array();
101 $_SESSION['LastError']          = "";
103 /* Check if we need to run setup */
104 if (!file_exists(CONFIG_DIR."/gosa.conf-trunk")){
105   header("location:setup.php");
106   exit();
109 /* Reset errors */
110 $_SESSION['errors']= "";
112 /* Check for java script */
113 if(isset($_POST['javascript']) && $_POST['javascript'] == "true") {
114   $_SESSION['js']= TRUE;
115 }elseif(isset($_POST['javascript'])) {
116   $_SESSION['js']= FALSE;
119 /* Check if gosa.conf is accessible */
120 if (!is_readable(CONFIG_DIR."/gosa.conf")){
121   echo sprintf(_("GOsa configuration %s/gosa.conf is not readable. Aborted."), CONFIG_DIR);
122   exit();
125 /* Parse configuration file */
126 $config= new config(CONFIG_DIR."/gosa.conf-trunk", $BASE_DIR);
127 $_SESSION['DEBUGLEVEL']= $config->data['MAIN']['DEBUGLEVEL'];
128 if ($_SERVER["REQUEST_METHOD"] != "POST"){
129   @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
132 /* Set template compile directory */
133 if (isset ($config->data['MAIN']['COMPILE'])){
134   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
135 } else {
136   $smarty->compile_dir= '/var/spool/gosa';
138 $smarty->assign ('nextfield', 'username');
140 /* Check for compile directory */
141 if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))){
142   echo sprintf(_("Directory '%s' specified as compile directory is not accessible!"),
143         $smarty->compile_dir);
144   exit();
147 /* Check for old files in compile directory */
148 clean_smarty_compile_dir($smarty->compile_dir);
150 /* Language setup */
151 if ($config->data['MAIN']['LANG'] == ""){
152   $lang= get_browser_language();
153 } else {
154   $lang= $config->data['MAIN']['LANG'];
156 $lang.=".UTF-8";
157 putenv("LANGUAGE=");
158 putenv("LANG=$lang");
159 setlocale(LC_ALL, $lang);
160 $GLOBALS['t_language']= $lang;
161 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
163 /* Set the text domain as 'messages' */
164 $domain = 'messages';
165 bindtextdomain($domain, "$BASE_DIR/locale");
166 textdomain($domain);
169 if ($_SERVER["REQUEST_METHOD"] != "POST"){
170   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
174 /* Check for SSL connection */
175 $ssl= "";
176 if (!isset($_SERVER['HTTPS']) ||
177     !stristr($_SERVER['HTTPS'], "on")) {
179   if (empty($_SERVER['REQUEST_URI'])) {
180     $ssl= "https://".$_SERVER['HTTP_HOST'].
181       $_SERVER['PATH_INFO'];
182   } else {
183     $ssl= "https://".$_SERVER['HTTP_HOST'].
184       $_SERVER['REQUEST_URI'];
185   }
188 /* If SSL is forced, just forward to the SSL enabled site */
189 if ($config->data['MAIN']['FORCESSL'] == 'true' && $ssl != ''){
190   header ("Location: $ssl");
191   exit;
194 /* Got a formular answer, validate and try to log in */
195 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){
197   /* Reset error messages */
198   $message= "";
200   /* Destroy old sessions, they cause a successfull login to relog again ...*/
201   if(isset($_SESSION['_LAST_PAGE_REQUEST'])){
202     $_SESSION['_LAST_PAGE_REQUEST'] = time();
203   }
205   $server= validate($_POST["server"]);
206   $config->set_current($server);
208   /* Admin-logon and verify */
209   $ldap = $config->get_ldap_link();
210   if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){
211     print_red (_("Can't bind to LDAP. Please contact the system administrator."));
212     displayLogin();
213     exit();
214   }
216   /* Check for schema file presence */
217   if(!isset($config->data['MAIN']['SCHEMA_CHECK'])){
218     $config->data['MAIN']['SCHEMA_CHECK'] = "true";
219   }
220   if(isset($config->data['MAIN']['SCHEMA_CHECK'])&&preg_match("/true/i",$config->data['MAIN']['SCHEMA_CHECK'])){
221     require_once("functions_setup.inc");
222     $recursive = (isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true");
223     $tls =       (isset($config->current['TLS'])       && $config->current['TLS'] == "true");
225     if(!is_schema_readable($config->current['SERVER'], $config->current['ADMIN'], $config->current['PASSWORD'], $recursive, $tls)){
227       print_red(_("GOsa cannot retrieve information about the installed schema files. Please make sure, that this is possible."));
228       displayLogin();
229       exit()  ;
230     }else{
231       $str = (schema_check($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'], $recursive, $tls, 0, TRUE));
232       $checkarr = array();
233       foreach($str as $tr){
234         if(isset($tr['needonstartup'])){
235           print_red($tr['msg']."<br>"._("Your ldap setup contains old schema definitions. Please re-run the setup."));
236           displayLogin();
237           exit()  ;
238         }
239       }
240     }
241   }
242   /* Check for locking area */
243   $ldap->cat($config->current['CONFIG'], array("dn"));
244   $attrs= $ldap->fetch();
245   if (!count ($attrs)){
246     $ldap->cd($config->current['BASE']);
247     $ldap->create_missing_trees($config->current['CONFIG']);
248   }
250   /* Check for at least one subtreeACL in the complete tree */
251   $ldap->cd($config->current['BASE']);
252   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
253   if ($ldap->count() < 1){
254     print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
255     displayLogin();
256     exit();
257   }
259   /* Check for valid input */
260   $username= $_POST["username"];
261   if (!ereg("^[A-Za-z0-9_.-]+$", $username)){
262     $message= _("Please specify a valid username!");
263   } elseif (mb_strlen($_POST["password"], 'UTF-8') == 0){
264     $message= _("Please specify your password!");
265     $smarty->assign ('nextfield', 'password');
266   } else {
268     /* Login as user, initialize user ACL's */
269     $ui= ldap_login_user($username, $_POST["password"]);
270     if ($ui === NULL || $ui == 0){
271       $message= _("Please check the username/password combination.");
272       $smarty->assign ('nextfield', 'password');
273       gosa_log ("Authentication failed for user \"$username\"");
274     } else {
275       /* Remove all locks of this user */
276       del_user_locks($ui->dn);
278       /* Save userinfo and plugin structure */
279       $_SESSION['ui']= $ui;
280       $_SESSION['session_cnt']= 0;
282       /* Let GOsa trigger a new connection for each POST, save
283          config to session. */
284       $config->get_departments();
285       $config->make_idepartments();
286       $_SESSION['config']= $config;
288       /* are we using accountexpiration */
289       if((isset($config->data['MAIN']['ACCOUNT_EXPIRATION'])) && 
290           preg_match('/true/i', $config->data['MAIN']['ACCOUNT_EXPIRATION'])){
291       
292         $expired= ldap_expired_account($config, $ui->dn, $ui->username);
294         if ($expired == 1){
295           $message= _("Account locked. Please contact your system administrator.");
296           $smarty->assign ('nextfield', 'password');
297           gosa_log ("Account for user \"$username\" has expired");
298         } elseif ($expired == 3){
299             $plist= new pluglist($config, $ui);
300             foreach ($plist->dirlist as $key => $value){
301               if (preg_match("/\bpassword\b/i",$value)){
302                 $plug=$key;
303                 gosa_log ("User \"$username\" password forced to change");
304                 header ("Location: main.php?plug=$plug&amp;reset=1");
305                 exit;
306               }
307             }
308           }
310         /* Not account expired or password forced change go to main page */
311         gosa_log ("User \"$username\" logged in successfully");
312         header ("Location: main.php?global_check=1");
313         exit;
314         
315       } else {
316         /* Go to main page */
317         gosa_log ("User \"$username\" logged in successfully");
318         header ("Location: main.php?global_check=1");
319         exit;
320       }
321     }
322   }
325 /* Fill template with required values */
326 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
327 $smarty->assign ('username', $username);
328 $smarty->assign ('personal_img', get_template_path('images/personal.png'));
329 $smarty->assign ('password_img', get_template_path('images/password.png'));
330 $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
332 /* Some error to display? */
333 if (!isset($message)){
334   $message= "";
337 $smarty->assign ("message", $message);
339 /* Displasy SSL mode warning? */
340 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
341   $smarty->assign ("ssl", "<b>"._("Warning").":<\/b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."<\/b></a>!");
342 } else {
343   $smarty->assign ("ssl", "");
346 /* Translation of cookie-warning. Whether to display it, is determined by JavaScript */
347 $smarty->assign ("cookies", "<b>"._("Warning").":<\/b> "._("Your browser has cookies disabled. Please enable cookies and reload this page before logging in!"));
350 /* Generate server list */
351 $servers= array();
352 if (isset($_POST['server'])){
353   $selected= validate($_POST['server']);
354 } else {
355   $selected= $config->data['MAIN']['DEFAULT'];
357 foreach ($config->data['LOCATIONS'] as $key => $ignored){
358   $servers[$key]= $key;
360 $smarty->assign ("server_options", $servers);
361 $smarty->assign ("server_id", $selected);
363 /* show login screen */
364 $smarty->assign ("PHPSESSID", session_id());
365 if (isset($_SESSION['errors'])){
366   $smarty->assign("errors", $_SESSION['errors']);
368 if ($error_collector != ""){
369   $smarty->assign("php_errors", $error_collector."</div>");
370 } else {
371   $smarty->assign("php_errors", "");
373 displayLogin();
376 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
377 ?>
379 </body>
380 </html>