1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2007 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 */
22 function displayPWchanger()
23 {
24 global $smarty;
25 $smarty->display(get_template_path('passwords.tpl'));
26 exit();
27 }
29 /* Load required includes */
30 require_once ("../include/php_setup.inc");
31 require_once ("functions.inc");
32 header("Content-type: text/html; charset=UTF-8");
34 session_start();
36 /* Destroy old session if exists.
37 Else you will get your old session back, if you not logged out correctly. */
38 if(is_array($_SESSION) && count($_SESSION)){
39 session_destroy();
40 session_start();
41 }
43 /* Reset errors */
44 $_SESSION['errors'] = "";
45 $_SESSION['errorsAlreadyPosted']= array();
46 $_SESSION['LastError'] = "";
48 /* Check if CONFIG_FILE is accessible */
49 if (!is_readable(CONFIG_DIR."/".CONFIG_FILE)){
50 echo sprintf(_("GOsa configuration %s/%s is not readable. Aborted."), CONFIG_DIR,CONFIG_FILE);
51 exit();
52 }
54 /* Parse configuration file */
55 $config= new config(CONFIG_DIR."/".CONFIG_FILE, $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 }
68 /* Check for compile directory */
69 if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))){
70 echo sprintf(_("Directory '%s' specified as compile directory is not accessible!"),
71 $smarty->compile_dir);
72 exit();
73 }
75 /* Check for old files in compile directory */
76 clean_smarty_compile_dir($smarty->compile_dir);
78 /* Language setup */
79 if ($config->data['MAIN']['LANG'] == ""){
80 $lang= get_browser_language();
81 } else {
82 $lang= $config->data['MAIN']['LANG'];
83 }
84 $lang.=".UTF-8";
85 putenv("LANGUAGE=");
86 putenv("LANG=$lang");
87 setlocale(LC_ALL, $lang);
88 $GLOBALS['t_language']= $lang;
89 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
91 /* Set the text domain as 'messages' */
92 $domain = 'messages';
93 bindtextdomain($domain, "$BASE_DIR/locale");
94 textdomain($domain);
97 if ($_SERVER["REQUEST_METHOD"] != "POST"){
98 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
99 }
102 /* Check for SSL connection */
103 $ssl= "";
104 if (!isset($_SERVER['HTTPS']) ||
105 !stristr($_SERVER['HTTPS'], "on")) {
107 if (empty($_SERVER['REQUEST_URI'])) {
108 $ssl= "https://".$_SERVER['HTTP_HOST'].
109 $_SERVER['PATH_INFO'];
110 } else {
111 $ssl= "https://".$_SERVER['HTTP_HOST'].
112 $_SERVER['REQUEST_URI'];
113 }
114 }
116 /* If SSL is forced, just forward to the SSL enabled site */
117 if ($config->data['MAIN']['FORCESSL'] == 'true' && $ssl != ''){
118 header ("Location: $ssl");
119 exit;
120 }
122 /* Got a formular answer, validate and try to log in */
123 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){
125 /* Reset error messages */
126 $message= "";
128 /* Destroy old sessions, they cause a successfull login to relog again ...*/
129 if(isset($_SESSION['_LAST_PAGE_REQUEST'])){
130 $_SESSION['_LAST_PAGE_REQUEST'] = time();
131 }
133 echo "Well - I'm lazy...";
134 }
136 /* Fill template with required values */
137 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
138 $smarty->assign ('username', $username);
139 $smarty->assign ('password_img', get_template_path('images/password.png'));
141 /* Some error to display? */
142 if (!isset($message)){
143 $message= "";
144 }
146 $smarty->assign ("message", $message);
148 /* Displasy SSL mode warning? */
149 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
150 $smarty->assign ("ssl", "<b>"._("Warning").":<\/b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."<\/b></a>!");
151 } else {
152 $smarty->assign ("ssl", "");
153 }
155 /* show login screen */
156 $smarty->assign ("PHPSESSID", session_id());
157 if (isset($_SESSION['errors'])){
158 $smarty->assign("errors", $_SESSION['errors']);
159 }
160 if ($error_collector != ""){
161 $smarty->assign("php_errors", $error_collector."</div>");
162 } else {
163 $smarty->assign("php_errors", "");
164 }
166 /* Set focus to the error button if we've an error message */
167 $focus= "";
168 if (isset($_SESSION['errors']) && $_SESSION['errors'] != ""){
169 $focus= '<script language="JavaScript" type="text/javascript">';
170 $focus.= 'document.forms[0].error_accept.focus();';
171 $focus.= '</script>';
172 }
173 $smarty->assign("focus", $focus);
175 displayPWchanger();
177 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
178 ?>
180 </body>
181 </html>