Code

Hide errors if session is already destroyed
[gosa.git] / gosa-core / setup / class_setupStep_Finish.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2007 Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
23 class Step_Finish extends setup_step
24 {
25   var $gosa_conf_contrib   = "/gosa.conf";
26   var $cfg_file_written = FALSE;
27   var $header_image= 'images/ldapserver.png';
29   function Step_Finish()
30   {
31     $this->update_strings();
32   }
34   
35   function update_strings()
36   {
37     $this->s_title      = _("Finish");
38     $this->s_info       = _("Write configuration file");
39     $this->s_title_long = _("Finish - write the configuration file");
40   }
43   function get_conf_data()
44   {
45     $smarty = get_smarty();
46     $smarty->assign("cv",xmlentities($this->parent->captured_values));
47     $smarty->assign("get_gosa_version",get_gosa_version());
48     $str =  $smarty->fetch(CONFIG_TEMPLATE_DIR.$this->gosa_conf_contrib);
49     return($str);
50   }  
53   function execute()
54   {
56     $info= posix_getgrgid(posix_getgid());
57     $webgroup = $info['name'];
58       
59     
60     /* Check if there is currently an active gosa.conf 
61      */
62     $exists = file_exists(CONFIG_DIR."/".CONFIG_FILE); 
64     /* Redirect to GOsa login, if : 
65      *   - gosa.conf exists
66      *   - Permisssion are set correctly 
67      */ 
68     if(isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
69       session::destroy();
70       header("Location: index.php");
71       exit();
72     }
74     /* Downlaod config */
75     if(isset($_POST['getconf'])){
77       header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
78       header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
79       header("Cache-Control: no-cache");
80       header("Pragma: no-cache");
81       header("Cache-Control: post-check=0, pre-check=0");
82       header("Content-type: text/plain");
83      
84       if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
85           preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
86         header('Content-Disposition: filename="'.CONFIG_FILE.'"');
87       } else {
88         header('Content-Disposition: attachment; filename="'.CONFIG_FILE.'"');
89       }
91       $str = $this->get_conf_data();
92       $str = preg_replace("/\n[ ]*\n/","",$str);
94       echo $this->get_conf_data();
95       exit();
96     }
97    
98     $err_msg= "";
99     
100     if($exists && $this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
101       $err_msg = _("Your configuration file is currently world readable. Please update the file permissions!");
102     }elseif(!$exists){
103       $err_msg = _("The configuration is currently not readable or it does not exists.");
104     }
106     $smarty = get_smarty();
107     $smarty->assign("err_msg",$err_msg);
108     $smarty->assign("webgroup", $webgroup);
109     $smarty->assign("CONFIG_DIR",CONFIG_DIR);
110     $smarty->assign("CONFIG_FILE" , CONFIG_FILE);
112     $smarty->assign("msg2", sprintf(_("After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn't. You may want to execute these commands to achieve this requirement:"),CONFIG_DIR,CONFIG_FILE));
114     $smarty->assign("cv",$this->parent->captured_values);
115     return($smarty -> fetch (get_template_path("../setup/setup_finish.tpl")));
116   }
119   /* check if given file is world readable */
120   function is_world_readable($file)
121   {
122     clearstatcache();
123     $p = fileperms($file);
124     $w_r = (decbin($p & 4) == TRUE);
125     return($w_r);
126   }
129   function save_object()
130   {
131     if(isset($_POST['step8_posted'])){
133       /* Get attributes */
134       foreach($this->attributes as $attr){
135         if(isset($_POST[$attr])){
136           $this->$attr = validate($_POST[$attr]);
137         }
138       }
139     }
140   }
143 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
144 ?>