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