33a89c3391250244ac0f66d2d99cf371582d5530
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 }
81 /* Check for old files in compile directory */
82 clean_smarty_compile_dir($smarty->compile_dir);
84 /* Language setup */
85 if ($config->data['MAIN']['LANG'] == ""){
86 $lang= get_browser_language();
87 } else {
88 $lang= $config->data['MAIN']['LANG'];
89 }
90 $lang.=".UTF-8";
91 putenv("LANGUAGE=");
92 putenv("LANG=$lang");
93 setlocale(LC_ALL, $lang);
94 $GLOBALS['t_language']= $lang;
95 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
97 /* Set the text domain as 'messages' */
98 $domain = 'messages';
99 bindtextdomain($domain, "$BASE_DIR/locale");
100 textdomain($domain);
103 if ($_SERVER["REQUEST_METHOD"] != "POST"){
104 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
105 }
108 /* Check for SSL connection */
109 $ssl= "";
110 if (!isset($HTTP_SERVER_VARS['HTTPS']) ||
111 !stristr($HTTP_SERVER_VARS['HTTPS'], "on")) {
113 if (empty($HTTP_SERVER_VARS['REQUEST_URI'])) {
114 $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
115 $HTTP_SERVER_VARS['PATH_INFO'];
116 } else {
117 $ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
118 $HTTP_SERVER_VARS['REQUEST_URI'];
119 }
120 }
122 /* If SSL is forced, just forward to the SSL enabled site */
123 if ($config->data['MAIN']['FORCESSL'] == 'true'){
124 header ("Location: $ssl");
125 exit;
126 }
128 /* Got a formular answer, validate and try to log in */
129 if ($_SERVER["REQUEST_METHOD"] == "POST"){
131 /* Reset error messages */
132 $message= "";
134 $server= validate($_POST["server"]);
135 $config->set_current($server);
137 /* Admin-logon and verify */
138 $ldap = $config->get_ldap_link();
139 if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){
140 print_red (_("Can't bind to LDAP. Please contact the system administrator."));
141 echo $_SESSION['errors'];
142 exit();
143 }
145 $ldap->search("(objectClass=*)",array("subschemaSubentry"));
146 $attrs= $ldap->fetch();
147 if(!count($attrs)){
148 print_red(_("GOsa cannot retrieve information about the installed schema files. Please make sure, that this is possible."));
149 echo $_SESSION['errors'];
150 exit();
151 }else{
152 require_once("functions_setup.inc");
153 $str = (schema_check($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD']));
154 $checkarr = array();
155 foreach($str as $tr){
156 if(isset($tr['needonstartup'])){
157 // print_red($tr['msg']);
158 print_red(_("Your Schema files are not at actual version, please move your gosa.conf and run Setup again, to check this."));
159 print $_SESSION['errors'];
160 exit();
161 }
162 }
163 }
166 /* Check for locking area */
167 $ldap->cat($config->current['CONFIG']);
168 $attrs= $ldap->fetch();
169 if (!count ($attrs)){
170 $ldap->cd($config->current['BASE']);
171 $ldap->create_missing_trees($config->current['CONFIG']);
172 }
174 /* Check for at least one subtreeACL in the complete tree */
175 $ldap->cd($config->current['BASE']);
176 $ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
177 if ($ldap->count() < 1){
178 #FIXME: -> ldapsetup.tpl would be better
179 print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
180 echo $_SESSION['errors'];
181 exit;
182 }
184 /* Check for valid input */
185 $username= $_POST["username"];
186 if (!ereg("^[A-Za-z0-9_.-]+$", $username)){
187 $message= _("Please specify a valid username!");
188 } elseif (mb_strlen($_POST["password"], 'UTF-8') == 0){
189 $message= _("Please specify your password!");
190 $smarty->assign ('nextfield', 'password');
191 } else {
193 /* Login as user, initialize user ACL's */
194 $ui= ldap_login_user($username, $_POST["password"]);
195 if ($ui === NULL || $ui == 0){
196 $message= _("Please check the username/password combination.");
197 $smarty->assign ('nextfield', 'password');
198 gosa_log ("Authentication failed for user \"$username\"");
199 } else {
200 /* Remove all locks of this user */
201 del_user_locks($ui->dn);
203 /* Save userinfo and plugin structure */
204 $_SESSION['ui']= $ui;
205 $_SESSION['session_cnt']= 0;
207 /* Let GOsa trigger a new connection for each POST, save
208 config to session. */
209 $_SESSION['config']= $config;
211 /* Go to main page */
212 gosa_log ("User \"$username\" logged in successfully");
213 header ("Location: main.php?global_check=1");
214 exit;
215 }
216 }
217 }
219 /* Fill template with required values */
220 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
221 $smarty->assign ('username', $username);
222 $smarty->assign ('personal_img', get_template_path('images/personal.png'));
223 $smarty->assign ('password_img', get_template_path('images/password.png'));
224 $smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
226 /* Some error to display? */
227 if (!isset($message)){
228 $message= "";
229 }
230 $smarty->assign ("message", $message);
232 /* Displasy SSL mode warning? */
233 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
234 $smarty->assign ("ssl", "<b>"._("Warning").":</b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."</b></a>!");
235 } else {
236 $smarty->assign ("ssl", "");
237 }
239 /* Generate server list */
240 $servers= array();
241 if (isset($_POST['server'])){
242 $selected= validate($_POST['server']);
243 } else {
244 $selected= $config->data['MAIN']['DEFAULT'];
245 }
246 foreach ($config->data['LOCATIONS'] as $key => $ignored){
247 $servers[$key]= $key;
248 }
249 $smarty->assign ("server_options", $servers);
250 $smarty->assign ("server_id", $selected);
252 /* show login screen */
253 $smarty->display (get_template_path('headers.tpl'));
254 $smarty->assign ("PHPSESSID", session_id());
255 if (isset($_SESSION['errors'])){
256 $smarty->assign("errors", $_SESSION['errors']);
257 }
258 if ($error_collector != ""){
259 $smarty->assign("php_errors", $error_collector."</div>");
260 } else {
261 $smarty->assign("php_errors", "");
262 }
263 $smarty->display (get_template_path('login.tpl'));
265 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
266 ?>
268 </body>
269 </html>