Code

Removed version stuff which was CVS dependent
[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($_GET['js']) && !isset($_SESSION['js'])){
42   echo '<script language="JavaScript" type="text/javascript">';
43   echo '  location = "index.php?js=true";';
44   echo '</script>';
46   $_SESSION['js']= FALSE;
47 } else {
48   $_SESSION['js']= TRUE;
49 }
51 /* Check if gosa.conf is accessable */
52 if (!is_readable(CONFIG_DIR."/gosa.conf")){
53   print_red(sprintf(_("GOsa configuration %s/gosa.conf is not readable. Aborted."), CONFIG_DIR));
54   echo $_SESSION['errors'];
55   exit();
56 }
58 /* Parse configuration file */
59 $config= new config(CONFIG_DIR."/gosa.conf", $BASE_DIR);
60 $_SESSION['DEBUGLEVEL']= $config->data['MAIN']['DEBUGLEVEL'];
61 if ($_SERVER["REQUEST_METHOD"] != "POST"){
62   @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
63 }
65 /* Set template compile directory */
66 if (isset ($config->data['MAIN']['COMPILE'])){
67   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
68 } else {
69   $smarty->compile_dir= '/var/spool/gosa';
70 }
71 $smarty->assign ('nextfield', 'username');
73 /* Check for compile directory */
74 if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))){
75   print_red(sprintf(_("Directory '%s' specified as compile directory is not accessable!"),
76         $smarty->compile_dir));
77   echo $_SESSION['errors'];
78   exit();
79 }
82 /* Language setup */
83 if ($config->data['MAIN']['LANG'] == ""){
84   $lang= get_browser_language();
85 } else {
86   $lang= $config->data['MAIN']['LANG'];
87 }
88 $lang.=".UTF-8";
89 putenv("LANGUAGE=");
90 putenv("LANG=$lang");
91 setlocale(LC_ALL, $lang);
92 $GLOBALS['t_language']= $lang;
93 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
95 /* Set the text domain as 'messages' */
96 $domain = 'messages';
97 bindtextdomain($domain, "$BASE_DIR/locale");
98 textdomain($domain);
101 if ($_SERVER["REQUEST_METHOD"] != "POST"){
102   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
106 /* Check for SSL connection */
107 $ssl= "";
108 if (!isset($HTTP_SERVER_VARS['HTTPS']) ||
109     !stristr($HTTP_SERVER_VARS['HTTPS'], "on")) {
111   if (empty($HTTP_SERVER_VARS['REQUEST_URI'])) {
112     $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
113       $HTTP_SERVER_VARS['PATH_INFO'];
114   } else {
115     $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
116       $HTTP_SERVER_VARS['REQUEST_URI'];
117   }
120 /* If SSL is forced, just forward to the SSL enabled site */
121 if ($config->data['MAIN']['FORCESSL'] == 'true'){
122   header ("Location: $ssl");
123   exit;
126 /* Got a formular answer, validate and try to log in */
127 if ($_SERVER["REQUEST_METHOD"] == "POST"){
129   /* Reset error messages */
130   $message= "";
132   $server= validate($_POST["server"]);
133   $config->set_current($server);
135   /* Admin-logon and verify */
136   $ldap = $config->get_ldap_link();
137   if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){
138     print_red (_("Can't bind to LDAP. Please contact the system administrator."));
139     echo $_SESSION['errors'];
140     exit();
141   }
143   /* Check for locking area */
144   $ldap->cat($config->current['CONFIG']);
145   $attrs= $ldap->fetch();
146   if (!count ($attrs)){
147     $ldap->cd($config->current['BASE']);
148     $ldap->create_missing_trees($config->current['CONFIG']);
149   }
151   /* Check for at least one subtreeACL in the complete tree */
152   $ldap->cd($config->current['BASE']);
153   $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
154   if ($ldap->count() < 1){
155 #FIXME: -> ldapsetup.tpl would be better
156     print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
157     echo $_SESSION['errors'];
158     exit;
159   }
161   /* Check for valid input */
162   $username= $_POST["username"];
163   if (!ereg("^[A-Za-z0-9_.-]+$", $username)){
164     $message= _("Please specify a valid username!");
165   } elseif (mb_strlen($_POST["password"], 'UTF-8') == 0){
166     $message= _("Please specify your password!");
167     $smarty->assign ('nextfield', 'password');
168   } else {
170     /* Login as user, initialize user ACL's */
171     $ui= ldap_login_user($username, $_POST["password"]);
172     if ($ui === NULL || $ui == 0){
173       $message= _("Please check the username/password combination.");
174       $smarty->assign ('nextfield', 'password');
175       gosa_log ("Authentication failed for user \"$username\"");
176     } else {
177       /* Remove all locks of this user */
178       del_user_locks($ui->dn);
180       /* Save userinfo and plugin structure */
181       $_SESSION['ui']= $ui;
182       $_SESSION['session_cnt']= 0;
184       /* Let GOsa trigger a new connection for each POST, save
185          config to session. */
186       $_SESSION['config']= $config;
188       /* Go to main page */
189       gosa_log ("User \"$username\" logged in successfully");
190       header ("Location: main.php?global_check=1");
191       exit;
192     }
193   }
196 /* Fill template with required values */
197 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
198 $smarty->assign ('username', $username);
199 $smarty->assign ('personal_img', get_template_path('images/personal.png'));
200 $smarty->assign ('password_img', get_template_path('images/password.png'));
201 $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
203 /* Some error to display? */
204 if (!isset($message)){
205   $message= "";
207 $smarty->assign ("message", $message);
209 /* Displasy SSL mode warning? */
210 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
211   $smarty->assign ("ssl", "<b>"._("Warning").":</b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."</b></a>!");
212 } else {
213   $smarty->assign ("ssl", "");
216 /* Generate server list */
217 $servers= array();
218 if (isset($_POST['server'])){
219   $selected= validate($_POST['server']);
220 } else {
221   $selected= $config->data['MAIN']['DEFAULT'];
223 foreach ($config->data['LOCATIONS'] as $key => $ignored){
224   $servers[$key]= $key;
226 $smarty->assign ("server_options", $servers);
227 $smarty->assign ("server_id", $selected);
229 /* show login screen */
230 $smarty->display (get_template_path('headers.tpl'));
231 $smarty->assign ("PHPSESSID", session_id());
232 if (isset($_SESSION['errors'])){
233   $smarty->assign("errors", $_SESSION['errors']);
235 $smarty->display (get_template_path('login.tpl'));
237 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
238 ?>
240 </body>
241 </html>