1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 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 /* Basic setup, remove eventually registered sessions */
22 $timing= array();
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 header("Content-type: text/html; charset=UTF-8");
27 /* Reset error handler */
28 $error_collector= "";
29 set_error_handler('gosaRaiseError');
31 /* Find all class files and include them */
32 get_dir_list("$BASE_DIR/plugins");
34 /* Set the text domain as 'messages' */
35 $domain = 'messages';
36 bindtextdomain($domain, "$BASE_DIR/locale");
37 textdomain($domain);
39 /* Remember everything we did after the last click */
40 session_start ();
41 if ($_SERVER["REQUEST_METHOD"] == "POST"){
42 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
43 }
44 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
46 /* Logged in? Simple security check */
47 if (!isset($_SESSION['config'])){
48 gosa_log ("main.php called without session");
49 header ("Location: index.php");
50 exit;
51 }
53 /* Reset errors */
54 $_SESSION['errors']= "";
56 /* Check for uniqe ip address */
57 $ui= $_SESSION["ui"];
58 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
59 gosa_log ("main.php called with session which has a changed IP address.", 3);
60 header ("Location: logout.php");
61 exit;
62 }
63 $config= $_SESSION['config'];
64 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
66 /* Set template compile directory */
67 if (isset ($config->data['MAIN']['COMPILE'])){
68 $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
69 } else {
70 $smarty->compile_dir= '/var/spool/gosa/';
71 }
73 /* Language setup */
74 if ($config->data['MAIN']['LANG'] == ""){
75 $lang= get_browser_language();
76 } else {
77 $lang= $config->data['MAIN']['LANG'];
78 }
79 $lang.=".UTF-8";
80 putenv("LANGUAGE=");
81 putenv("LANG=$lang");
82 setlocale(LC_ALL, $lang);
83 $GLOBALS['t_language']= $lang;
84 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
86 /* Set the text domain as 'messages' */
87 $domain = 'messages';
88 bindtextdomain($domain, "$BASE_DIR/locale");
89 textdomain($domain);
90 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
92 /* Prepare plugin list */
93 if (!isset($_SESSION['plist'])){
94 $_SESSION['plist']= new pluglist($config, $ui);
95 }
96 $plist= $_SESSION['plist'];
98 /* Check for register globals */
99 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
100 print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
101 echo $_SESSION['errors'];
102 gosa_log ("Register globals is on. For security reasons, this should be turned off.");
103 session_destroy ();
104 exit ();
105 }
107 /* Check Plugin variable */
108 if (isset($_SESSION['plugin_dir'])){
109 $old_plugin_dir= $_SESSION['plugin_dir'];
110 } else {
111 $old_plugin_dir= "";
112 }
113 if (isset($_GET['plug'])){
114 $plug= validate($_GET['plug']);
115 $plugin_dir= $plist->get_path($plug);
116 $_SESSION['plugin_dir']= $plugin_dir;
117 if ($plugin_dir == ""){
118 gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
119 header ("Location: logout.php");
120 exit;
121 }
122 } else {
123 /* set to welcome page as default plugin */
124 $_SESSION['plugin_dir']= "welcome";
125 $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
126 }
128 /* Check if we need to delete a lock */
129 if ($old_plugin_dir != $plugin_dir){
130 if (is_file("$old_plugin_dir/main.inc")){
131 $remove_lock= true;
132 require_once ("$old_plugin_dir/main.inc");
133 }
134 }
135 $remove_lock= false;
137 /* Check for sizelimits */
138 eval_sizelimit();
140 /* Check for memory */
141 if (function_exists("memory_get_usage")){
142 if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
143 print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
144 }
145 }
147 /* Redirect on back event */
148 if ($_SERVER["REQUEST_METHOD"] == "POST"){
150 /* Look for button events that match /^back[0-9]+$/,
151 extract the number and step the correct plugin. */
152 foreach ($_POST as $key => $value){
153 if (preg_match("/^back[0-9]+$/", $key)){
154 $back= substr($key, 4);
155 header ("Location: main.php?plug=$back");
156 exit;
157 }
158 }
159 }
161 /* Redirect on password back event */
162 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
163 header ("Location: main.php");
164 exit;
165 }
167 /* Check for multiple windows logout */
168 if ($_SERVER["REQUEST_METHOD"] == "POST"){
169 if (isset($_POST['reset_session'])){
170 header ("Location: logout.php");
171 exit;
172 }
174 if (isset($_POST['cancel_lock'])){
175 unset ($_SESSION['dn']);
176 }
177 }
180 /* Load department list when plugin has changed. That is some kind of
181 compromise between speed and beeing up to date */
182 if (isset($_GET['reset'])){
183 $config->departments= get_departments();
184 $config->make_idepartments ();
185 if (isset($_SESSION['objectinfo'])){
186 unset ($_SESSION['objectinfo']);
187 }
188 }
190 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
191 if(isset($_GET['explorer'])){
192 $_SESSION{'eGosa'}=1;
193 }
194 if(isset($_SESSION['POST'])){
195 $_SERVER["REQUEST_METHOD"] = "POST";
196 foreach ($_SESSION['POST'] as $key => $dummy){
197 $_POST[$key]=$_SESSION['POST'][$key];
198 }
199 unset($_SESSION['POST']);
200 }
202 /* show web frontend */
203 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
204 $smarty->assign ("must", "<font class=\"must\">*</font>");
205 if (isset($plug)){
206 $plug= "?plug=$plug";
207 } else {
208 $plug= "";
209 }
210 if ($_SESSION['js']==FALSE){
211 $smarty->assign("javascript", "false");
212 $smarty->assign("help_method", "href='helpviewer.php$plug' target='_new'");
213 } else {
214 $smarty->assign("javascript", "true");
215 $smarty->assign("help_method","href='' onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
216 }
218 $smarty->assign ("username", $ui->username);
219 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
220 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
221 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
222 $smarty->assign ("go_out", get_template_path('images/stop.png'));
223 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
224 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
225 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
226 $smarty->assign ("go_help", get_template_path('images/help.png'));
227 $plist->gen_menu();
228 $smarty->assign ("menu", $plist->menu);
229 $smarty->assign ("plug", "$plug");
231 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
234 /* React on clicks */
235 if ($_SERVER["REQUEST_METHOD"] == "POST"){
237 /* 'delete_lock' is set by the lock removal dialog. We should remove the
238 lock at this point globally. Plugins do not need to remove it. */
239 if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
240 del_lock ($_SESSION['dn']);
241 sess_del ('dn');
242 }
245 /* I don't want multiple browser windows open. One way to check it is
246 to count a hidden field and warn the user if SESSION and INPUT count
247 differ. */
248 if (isset($_POST['session_cnt'])){
249 if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
250 $smarty->display(get_template_path('conflict.tpl'));
251 exit ();
252 }
253 $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
254 $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
255 }
256 }
258 /* Only generate hidden click counter, if post_cnt is defined */
259 if (isset ($_SESSION['post_cnt'])){
260 echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
261 }
263 /* Load plugin */
264 if (is_file("$plugin_dir/main.inc")){
265 require_once ("$plugin_dir/main.inc");
266 } else {
267 print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
268 echo $_SESSION['errors'];
269 exit();
270 }
272 /* Close div/tables */
273 $smarty->assign("contents", $display);
274 if (isset($_SESSION['errors'])){
275 $smarty->assign("errors", $_SESSION['errors']);
276 }
277 if ($error_collector != ""){
278 $smarty->assign("php_errors", $error_collector."</div>");
279 } else {
280 $smarty->assign("php_errors", "");
281 }
282 $smarty->assign("w3c", "");
283 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
285 /* For development, perform a W3C conformance check if specified in gosa.conf */
286 if (isset($config->data['MAIN']['W3CTEST'])) {
287 $fp = fopen("/tmp/gosa.html","w+");
288 fwrite($fp, $display, strlen($display));
289 $url= $config->data['MAIN']['W3CTEST'];
290 $str = shell_exec( "curl -F uploaded_file=@/tmp/gosa.html $url/check");
291 if(!preg_match("/This Page Is Valid/i",$str )){
292 /* Show errors */
293 echo $str;
294 } else {
295 /* Re-render page with W3C logo */
296 $smarty->assign("w3c", "<a href=\"$url/check?uri=referer\"><img alt=\"\" border=\"0\" src=\"$url/images/vh401.png\" alt=\"Valid HTML 4.01!\" height=\"31\" width=\"88\"></a>");
297 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
298 }
299 }
301 /* Show page... */
302 echo $display;
304 /* Save plist */
305 $_SESSION['plist']= $plist;
307 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
308 ?>