Code

First page W3c Conform (first step done)
[gosa.git] / html / main.php
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 ();
107 /* Check Plugin variable */
108 if (isset($_SESSION['plugin_dir'])){
109   $old_plugin_dir= $_SESSION['plugin_dir'];
110 } else {
111   $old_plugin_dir= "";
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";
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   }
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   }
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   }
161 /* Redirect on password back event */
162 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
163   header ("Location: main.php");
164   exit;
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   }
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   }
190 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
191 if(isset($_GET['explorer'])){
192   $_SESSION{'eGosa'}=1;
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']);
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 ($_SESSION['js']==FALSE){
206   $smarty->assign("javascript", "false");
207 } else {
208   $smarty->assign("javascript", "true");
210 $smarty->assign ("username", $ui->username);
211 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
212 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
213 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
214 $smarty->assign ("go_out", get_template_path('images/stop.png'));
215 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
216 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
217 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
218 $smarty->assign ("go_help", get_template_path('images/help.png'));
219 $plist->gen_menu();
220 $smarty->assign ("menu", $plist->menu);
221 if (isset($plug)){
222   $smarty->assign ("plug", "?plug=$plug");
223 } else {
224   $smarty->assign ("plug", "");
226 $mtmp= $smarty->fetch(get_template_path('headers.tpl'));
228 /* React on clicks */
229 if ($_SERVER["REQUEST_METHOD"] == "POST"){
231   /* 'delete_lock' is set by the lock removal dialog. We should remove the
232      lock at this point globally. Plugins do not need to remove it. */
233   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
234     del_lock ($_SESSION['dn']);
235     sess_del ('dn');
236   }
239   /* I don't want multiple browser windows open. One way to check it is
240      to count a hidden field and warn the user if SESSION and INPUT count
241      differ. */
242   if (isset($_POST['session_cnt'])){
243     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
244       $smarty->display(get_template_path('conflict.tpl'));
245       exit ();
246     }
247     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
248     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
249   }
252 /* Only generate hidden click counter, if post_cnt is defined */
253 if (isset ($_SESSION['post_cnt'])){
254   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
257 /* Load plugin */
258 if (is_file("$plugin_dir/main.inc")){
259   require_once ("$plugin_dir/main.inc");
260   print $plugin_dir;
261 } else {
262   print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
263   echo $_SESSION['errors'];
264   exit();
267 /* Close div/tables */
268 $smarty->assign("contents", $display);
269 if (isset($_SESSION['errors'])){
270   $smarty->assign("errors", $_SESSION['errors']);
272 if ($error_collector != ""){
273   $smarty->assign("php_errors", $error_collector."</div>");
274 } else {
275   $smarty->assign("php_errors", "");
277 $display = $mtmp.$smarty->fetch(get_template_path('framework.tpl'));
278 print $display;
280 $fp = fopen("/tmp/current.html","w+");
281 fwrite($fp,$display,strlen($display));
282 $str = shell_exec( "curl -F uploaded_file=@/tmp/current.html http://127.0.0.1/w3c-markup-validator/check ");
283 print $str;
285 $_SESSION['plist']= $plist;
287 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
288 ?>