Code

Changed scaling
[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 /* Set error handler to own one, initialize time calculation
27    and start session. */
28 session_start ();
29 $username= "";
31 /* Check if we need to run setup */
32 if (!file_exists(CONFIG_DIR."/gosa.conf")){
33   header("location:setup.php");
34   exit();
35 }
37 /* Reset errors */
38 $_SESSION['errors']= "";
40 /* Check for java script */
41 if(isset($_POST['javascript']) && $_POST['javascript'] == "true") {
42   $_SESSION['js']= TRUE;
43 }elseif(isset($_POST['javascript'])) {
44   $_SESSION['js']= FALSE;
45 }
47 /* Check if gosa.conf is accessable */
48 if (!is_readable(CONFIG_DIR."/gosa.conf")){
49   print_red(sprintf(_("GOsa configuration %s/gosa.conf is not readable. Aborted."), CONFIG_DIR));
50   echo $_SESSION['errors'];
51   exit();
52 }
54 /* Parse configuration file */
55 $config= new config(CONFIG_DIR."/gosa.conf", $BASE_DIR);
56 $_SESSION['DEBUGLEVEL']= $config->data['MAIN']['DEBUGLEVEL'];
57 if ($_SERVER["REQUEST_METHOD"] != "POST"){
58   @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
59 }
61 /* Set template compile directory */
62 if (isset ($config->data['MAIN']['COMPILE'])){
63   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
64 } else {
65   $smarty->compile_dir= '/var/spool/gosa';
66 }
67 $smarty->assign ('nextfield', 'username');
69 /* Check for compile directory */
70 if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))){
71   print_red(sprintf(_("Directory '%s' specified as compile directory is not accessable!"),
72         $smarty->compile_dir));
73   echo $_SESSION['errors'];
74   exit();
75 }
77 /* Check for old files in compile directory */
78 clean_smarty_compile_dir($smarty->compile_dir);
80 /* Language setup */
81 if ($config->data['MAIN']['LANG'] == ""){
82   $lang= get_browser_language();
83 } else {
84   $lang= $config->data['MAIN']['LANG'];
85 }
86 $lang.=".UTF-8";
87 putenv("LANGUAGE=");
88 putenv("LANG=$lang");
89 setlocale(LC_ALL, $lang);
90 $GLOBALS['t_language']= $lang;
91 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
93 /* Set the text domain as 'messages' */
94 $domain = 'messages';
95 bindtextdomain($domain, "$BASE_DIR/locale");
96 textdomain($domain);
99 if ($_SERVER["REQUEST_METHOD"] != "POST"){
100   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
104 /* Check for SSL connection */
105 $ssl= "";
106 if (!isset($HTTP_SERVER_VARS['HTTPS']) ||
107     !stristr($HTTP_SERVER_VARS['HTTPS'], "on")) {
109   if (empty($HTTP_SERVER_VARS['REQUEST_URI'])) {
110     $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
111       $HTTP_SERVER_VARS['PATH_INFO'];
112   } else {
113     $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
114       $HTTP_SERVER_VARS['REQUEST_URI'];
115   }
118 /* If SSL is forced, just forward to the SSL enabled site */
119 if ($config->data['MAIN']['FORCESSL'] == 'true' && $ssl != ''){
120   header ("Location: $ssl");
121   exit;
124 /* Got a formular answer, validate and try to log in */
125 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){
127   /* Reset error messages */
128   $message= "";
130   /* Destroy old sessions, they cause a successfull login to relog again ...*/
131   if(isset($_SESSION['_LAST_PAGE_REQUEST'])){
132     $_SESSION['_LAST_PAGE_REQUEST'] = time();
133   }
135   $server= validate($_POST["server"]);
136   $config->set_current($server);
138   /* Admin-logon and verify */
139   $ldap = $config->get_ldap_link();
140   if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){
141     print_red (_("Can't bind to LDAP. Please contact the system administrator."));
142     echo $_SESSION['errors'];
143     $smarty->display(get_template_path('login.tpl'));
144     exit();
145   }
147   /* Check for schema file presence */
148   if(!isset($config->data['MAIN']['SCHEMA_CHECK'])){
149     $config->data['MAIN']['SCHEMA_CHECK'] = "true";
150   }
151   if(isset($config->data['MAIN']['SCHEMA_CHECK'])&&preg_match("/true/i",$config->data['MAIN']['SCHEMA_CHECK'])){
152     require_once("functions_setup.inc");
153     if(!is_schema_readable($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'])){
154       print_red(_("GOsa cannot retrieve information about the installed schema files. Please make sure, that this is possible."));
155       echo $_SESSION['errors'];
156       exit();
157     }else{
158       $str = (schema_check($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'],0,TRUE));
159       $checkarr = array();
160       foreach($str as $tr){
161         if(isset($tr['needonstartup'])){
162           print_red($tr['msg']."<br>"._("Your ldap setup contains old schema definitions. Please re-run the setup."));
163           print $_SESSION['errors'];
164           exit();
165         }
166       }
167     }
168   }
169   /* Check for locking area */
170   $ldap->cat($config->current['CONFIG']);
171   $attrs= $ldap->fetch();
172   if (!count ($attrs)){
173     $ldap->cd($config->current['BASE']);
174     $ldap->create_missing_trees($config->current['CONFIG']);
175   }
177   /* Check for at least one subtreeACL in the complete tree */
178   $ldap->cd($config->current['BASE']);
179   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
180   if ($ldap->count() < 1){
181     print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
182     displayLogin();
183     exit();
184   }
186   /* Check for valid input */
187   $username= $_POST["username"];
188   if (!ereg("^[A-Za-z0-9_.-]+$", $username)){
189     $message= _("Please specify a valid username!");
190   } elseif (mb_strlen($_POST["password"], 'UTF-8') == 0){
191     $message= _("Please specify your password!");
192     $smarty->assign ('nextfield', 'password');
193   } else {
195     /* Login as user, initialize user ACL's */
196     $ui= ldap_login_user($username, $_POST["password"]);
197     if ($ui === NULL || $ui == 0){
198       $message= _("Please check the username/password combination.");
199       $smarty->assign ('nextfield', 'password');
200       gosa_log ("Authentication failed for user \"$username\"");
201     } else {
202       /* Remove all locks of this user */
203       del_user_locks($ui->dn);
205       /* Save userinfo and plugin structure */
206       $_SESSION['ui']= $ui;
207       $_SESSION['session_cnt']= 0;
209       /* Let GOsa trigger a new connection for each POST, save
210          config to session. */
211       $_SESSION['config']= $config;
213       /* Go to main page */
214       gosa_log ("User \"$username\" logged in successfully");
215       header ("Location: main.php?global_check=1");
216       exit;
217     }
218   }
221 /* Fill template with required values */
222 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
223 $smarty->assign ('username', $username);
224 $smarty->assign ('personal_img', get_template_path('images/personal.png'));
225 $smarty->assign ('password_img', get_template_path('images/password.png'));
226 $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
228 /* Some error to display? */
229 if (!isset($message)){
230   $message= "";
233 $smarty->assign ("message", $message);
235 /* Displasy SSL mode warning? */
236 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
237   $smarty->assign ("ssl", "<b>"._("Warning").":</b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."</b></a>!");
238 } else {
239   $smarty->assign ("ssl", "");
242 /* Translation of cookie-warning. Whether to display it, is determined by JavaScript */
243 $smarty->assign ("cookies", "<b>"._("Warning").":</b> "._("Your browser has cookies disabled. Please enable cookies and reload this page before logging in!"));
246 /* Generate server list */
247 $servers= array();
248 if (isset($_POST['server'])){
249   $selected= validate($_POST['server']);
250 } else {
251   $selected= $config->data['MAIN']['DEFAULT'];
253 foreach ($config->data['LOCATIONS'] as $key => $ignored){
254   $servers[$key]= $key;
256 $smarty->assign ("server_options", $servers);
257 $smarty->assign ("server_id", $selected);
259 /* show login screen */
260 $smarty->display (get_template_path('headers.tpl'));
261 $smarty->assign ("PHPSESSID", session_id());
262 if (isset($_SESSION['errors'])){
263   $smarty->assign("errors", $_SESSION['errors']);
265 if ($error_collector != ""){
266   $smarty->assign("php_errors", $error_collector."</div>");
267 } else {
268   $smarty->assign("php_errors", "");
270 $smarty->display (get_template_path('login.tpl'));
278 function displayLogin()
280   global $smarty,$message,$config,$ssl,$error_collector;
281   error_reporting(E_ALL);
282     /* Fill template with required values */
283     $username = "";
284     if(isset($_POST["username"])){
285       $username= $_POST["username"];
286     }
287     $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
288     $smarty->assign ('username', $username);
289     $smarty->assign ('personal_img', get_template_path('images/personal.png'));
290     $smarty->assign ('password_img', get_template_path('images/password.png'));
291     $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
293     /* Some error to display? */
294     if (!isset($message)){
295       $message= "";
296     }
297     $smarty->assign ("message", $message);
299     /* Displasy SSL mode warning? */
300     if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
301       $smarty->assign ("ssl", "<b>"._("Warning").":</b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."</b></a>!");
302     } else {
303       $smarty->assign ("ssl", "");
304     }
306     /* Generate server list */
307     $servers= array();
308     if (isset($_POST['server'])){
309       $selected= validate($_POST['server']);
310     } else {
311       $selected= $config->data['MAIN']['DEFAULT'];
312     }
313     foreach ($config->data['LOCATIONS'] as $key => $ignored){
314       $servers[$key]= $key;
315     }
316     $smarty->assign ("server_options", $servers);
317     $smarty->assign ("server_id", $selected);
319     /* show login screen */
320     $smarty->display (get_template_path('headers.tpl'));
321     $smarty->assign ("PHPSESSID", session_id());
322     if (isset($_SESSION['errors'])){
323       $smarty->assign("errors", $_SESSION['errors']);
324     }
325     if ($error_collector != ""){
326       $smarty->assign("php_errors", $error_collector."</div>");
327     } else {
328       $smarty->assign("php_errors", "");
329     }
331     $smarty->display(get_template_path('login.tpl'));
332     exit();
337 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
338 ?>
340 </body>
341 </html>