ac59df5b8e5c69b702ddc462693dc0de3763b55b
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 setup_step_8 extends setup_step
24 {
25 var $create_backup = TRUE;
26 var $gosa_conf_name = "/gosa.conf";
27 var $cfg_file_written = FALSE;
28 var $last_backup_name = "";
30 function setup_step_8()
31 {
32 $this->s_title = _("Configuration file");
33 $this->s_info = _("In this step the configuration file will be created.");
34 $this->s_title_long = _("Saving configuration file");
35 }
38 function get_conf_data()
39 {
40 return("currently not implemented.");
41 }
44 function execute()
45 {
48 /* Check if there is currently an active gosa.conf
49 */
50 $exists = file_exists(CONFIG_DIR.$this->gosa_conf_name);
52 /* Check if existing config file is writeable */
53 if($exists){
54 $writeable = is_writeable(CONFIG_DIR.$this->gosa_conf_name);
55 }else{
56 $writeable = is_writeable(CONFIG_DIR);
57 }
59 /* Downlaod config */
60 if(isset($_POST['getconf'])){
61 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
62 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
63 header("Cache-Control: no-cache");
64 header("Pragma: no-cache");
65 header("Cache-Control: post-check=0, pre-check=0");
66 header("Content-type: text/plain");
67 header('Content-Disposition: attachment; filename="gosa.conf"');
68 echo $this->get_conf_data();
69 exit();
70 }
73 /* Try to save configuration */
74 $abort = FALSE;
75 $err_msg = "";
76 if(isset($_POST['saveconf'])){
77 if($exists && $this->create_backup){
78 if(!$this->create_backup()){
79 $abort = TRUE;
80 $err_msg = _("Could not create requested configuration file backup. Aborted writing config file. Please check folder permission and try again. Or use the manual method if this can not be fixed anyway.");
81 }
82 }
84 if(!$abort){
86 /* Try to create file handle */
87 $fp = @fopen(CONFIG_DIR.$this->gosa_conf_name, "w");
89 if(!$fp){
90 $err_msg = sprintf(_("Can not create handle on file '%s', the configuration could not be written. Please check folder permission and try again. Or use the manual method if this can not be fixed anyway."),CONFIG_DIR.$this->gosa_conf_name);
91 $abort =TRUE;
92 }else{
94 $data = $this->get_conf_data();
95 if(!fwrite($fp,strlen($data))){
96 $err_msg = sprintf(_("Can not write file '%s'. Please check folder permission and try again. Or use the manual method if this can not be fixed anyway."),CONFIG_DIR.$this->gosa_conf_name);
97 $abort =TRUE;
98 }
99 }
100 }
101 }
104 if($exists && $this->is_world_readable(CONFIG_DIR.$this->gosa_conf_name)){
105 $err_msg = _("Your configuration file is currently world readable. This is a big security issue. Please updated the file permissions as shown in the manual configuration part below.");
106 }
108 $info= posix_getgrgid(posix_getgid());
110 $smarty = get_smarty();
111 $smarty->assign("save_requested", isset($_POST['saveconf']));
112 $smarty->assign("err_msg",$err_msg);
113 $smarty->assign("webgroup", $info['name']);
114 $smarty->assign("gosa_conf_name" , $this->gosa_conf_name);
115 $smarty->assign("create_backup" , $this->create_backup);
116 $smarty->assign("CONFIG_DIR",CONFIG_DIR);
117 $smarty->assign("exists",$exists);
118 $smarty->assign("last_backup_name",$this->last_backup_name);
119 $smarty->assign("writeable",$writeable);
120 $smarty->assign("cv",$this->parent->captured_values);
121 $smarty->assign("msg_permissions",
122 sprintf(_("The following file(s), folders(s) must be writeable for the web-user '%s'."),$info['name']));
123 return($smarty -> fetch (get_template_path("../setup/setup_step8.tpl")));
124 }
127 /* check if given file is world readable */
128 function is_world_readable($file)
129 {
130 clearstatcache();
131 $p = fileperms($file);
132 $w_r = (decbin($p & 4) == TRUE);
133 return($w_r);
134 }
137 /* Create a backup of the currently existing configuration file.
138 */
139 function create_backup()
140 {
141 if(is_writeable(CONFIG_DIR) && is_writeable(CONFIG_DIR.$this->gosa_conf_name)){
142 $src = CONFIG_DIR.$this->gosa_conf_name;
143 $dst = CONFIG_DIR.$this->gosa_conf_name."_".date("Ymd");
144 $dst_backup= $dst;
145 $i = 1;
146 while(file_exists($dst)){
147 $dst = $dst_backup."-".$i;
148 $i ++;
149 }
150 # if(rename($src,$dst)){
151 if(copy($src,$dst)){
152 $this->last_backup_name = $dst;
153 return(TRUE);
154 }else{
155 return(FALSE);
156 }
157 }else{
158 return(FALSE);
159 }
160 }
163 function save_object()
164 {
165 if(isset($_POST['step8_posted'])){
167 /* Get attributes */
168 foreach($this->attributes as $attr){
169 if(isset($_POST[$attr])){
170 $this->$attr = validate($_POST[$attr]);
171 }
172 }
174 /* Backup toggle */
175 if(isset($_POST['create_backup_visible'])){
176 if(isset($_POST['create_backup'])){
177 $this->create_backup = TRUE;
178 }else{
179 $this->create_backup = FALSE;
180 }
181 }
182 }
183 }
184 }
186 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
187 ?>