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 var $b_displayCheckbutton = TRUE;
31 function Step_Finish()
32 {
33 $this->update_strings();
34 }
37 function update_strings()
38 {
39 $this->s_title = _("Finish");
40 $this->s_info = _("Write configuration file");
41 $this->s_title_long = _("Finish - write the configuration file");
42 }
45 function get_conf_data()
46 {
47 $smarty = get_smarty();
48 $smarty->assign("cv",xmlentities($this->parent->captured_values));
49 $smarty->assign("config_checksum", md5(file_get_contents(CONFIG_TEMPLATE_DIR.$this->gosa_conf_contrib)));
50 $str = $smarty->fetch(CONFIG_TEMPLATE_DIR.$this->gosa_conf_contrib);
51 return($str);
52 }
55 function execute()
56 {
58 if(!function_exists("posix_getgrgid")){
59 $webgroup = "";
60 }else{
61 $info= posix_getgrgid(posix_getgid());
62 $webgroup = $info['name'];
63 }
65 /* Check if there is currently an active gosa.conf
66 */
67 $exists = file_exists(CONFIG_DIR."/".CONFIG_FILE);
69 /* Redirect to GOsa login, if :
70 * - gosa.conf exists
71 * - Permisssion are set correctly
72 */
73 if(isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
74 session::destroy();
75 header("Location: index.php");
76 exit();
77 }
79 /* Downlaod config */
80 if(isset($_POST['getconf'])){
82 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
83 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
84 header("Cache-Control: no-cache");
85 header("Pragma: no-cache");
86 header("Cache-Control: post-check=0, pre-check=0");
87 header("Content-type: text/plain");
89 if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
90 preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
91 header('Content-Disposition: filename="'.CONFIG_FILE.'"');
92 } else {
93 header('Content-Disposition: attachment; filename="'.CONFIG_FILE.'"');
94 }
96 $str = $this->get_conf_data();
97 $str = preg_replace("/\n[ ]*\n/","",$str);
99 echo $this->get_conf_data();
100 exit();
101 }
103 $err_msg= "";
105 if($exists && $this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
106 $err_msg = _("Your configuration file is currently world readable. Please update the file permissions!");
107 }elseif(!$exists){
108 $err_msg = _("The configuration is currently not readable or it does not exists.");
109 }
111 $smarty = get_smarty();
112 $smarty->assign("err_msg",$err_msg);
113 $smarty->assign("webgroup", $webgroup);
114 $smarty->assign("CONFIG_DIR",CONFIG_DIR);
115 $smarty->assign("CONFIG_FILE" , CONFIG_FILE);
117 $smarty->assign("msg2", sprintf(_("After downloading and placing the file under %s, please make sure that the user the web server 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));
119 $smarty->assign("cv",$this->parent->captured_values);
120 return($smarty -> fetch (get_template_path("../setup/setup_finish.tpl")));
121 }
124 /* check if given file is world readable */
125 function is_world_readable($file)
126 {
127 clearstatcache();
128 $p = fileperms($file);
129 $w_r = (decbin($p & 4) == TRUE);
130 return($w_r);
131 }
134 function save_object()
135 {
136 if(isset($_POST['step8_posted'])){
138 /* Get attributes */
139 foreach($this->attributes as $attr){
140 if(isset($_POST[$attr])){
141 $this->$attr = get_post($attr);
142 }
143 }
144 }
145 }
146 }
148 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
149 ?>