Code

Removed debug output
[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/setup/server.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("config_checksum", md5(file_get_contents(CONFIG_TEMPLATE_DIR.$this->gosa_conf_contrib)));
48     $str =  $smarty->fetch(CONFIG_TEMPLATE_DIR.$this->gosa_conf_contrib);
49     return($str);
50   }  
53   function execute()
54   {
56     if(!function_exists("posix_getgrgid")){
57       $webgroup = "";
58     }else{
59       $info= posix_getgrgid(posix_getgid());
60       $webgroup = $info['name'];
61     }
63     /* Check if there is currently an active gosa.conf 
64      */
65     $exists = file_exists(CONFIG_DIR."/".CONFIG_FILE); 
67     /* Redirect to GOsa login, if : 
68      *   - gosa.conf exists
69      *   - Permisssion are set correctly 
70      */ 
71     if(isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
72       session::destroy();
73       header("Location: index.php");
74       exit();
75     }
77     /* Downlaod config */
78     if(isset($_POST['getconf'])){
80       header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
81       header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
82       header("Cache-Control: no-cache");
83       header("Pragma: no-cache");
84       header("Cache-Control: post-check=0, pre-check=0");
85       header("Content-type: text/plain");
86      
87       if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
88           preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
89         header('Content-Disposition: filename="'.CONFIG_FILE.'"');
90       } else {
91         header('Content-Disposition: attachment; filename="'.CONFIG_FILE.'"');
92       }
94       $str = $this->get_conf_data();
95       $str = preg_replace("/\n[ ]*\n/","",$str);
97       echo $this->get_conf_data();
98       exit();
99     }
100    
101     $err_msg= "";
102     
103     if($exists && $this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
104       $err_msg = _("Your configuration file is currently world readable. Please update the file permissions!");
105     }elseif(!$exists){
106       $err_msg = _("The configuration is currently not readable or it does not exists.");
107     }
109     $smarty = get_smarty();
110     $smarty->assign("err_msg",$err_msg);
111     $smarty->assign("webgroup", $webgroup);
112     $smarty->assign("CONFIG_DIR",CONFIG_DIR);
113     $smarty->assign("CONFIG_FILE" , CONFIG_FILE);
115     $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));
117     $smarty->assign("cv",$this->parent->captured_values);
118     return($smarty -> fetch (get_template_path("../setup/setup_finish.tpl")));
119   }
122   /* check if given file is world readable */
123   function is_world_readable($file)
124   {
125     clearstatcache();
126     $p = fileperms($file);
127     $w_r = (decbin($p & 4) == TRUE);
128     return($w_r);
129   }
132   function save_object()
133   {
134     if(isset($_POST['step8_posted'])){
136       /* Get attributes */
137       foreach($this->attributes as $attr){
138         if(isset($_POST[$attr])){
139           $this->$attr = validate($_POST[$attr]);
140         }
141       }
142     }
143   }
146 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
147 ?>