[763] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - Setup * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | $phpgw_info = array(); |
---|
| 14 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 15 | 'noheader' => True, |
---|
| 16 | 'nonavbar' => True, |
---|
| 17 | 'currentapp' => 'home', |
---|
| 18 | 'noapi' => True |
---|
| 19 | ); |
---|
| 20 | include('./inc/functions.inc.php'); |
---|
| 21 | |
---|
| 22 | /* |
---|
| 23 | Authorize the user to use setup app and load the database |
---|
| 24 | Does not return unless user is authorized |
---|
| 25 | */ |
---|
| 26 | if(!$GLOBALS['phpgw_setup']->auth('Config') || @$_POST['cancel']) |
---|
| 27 | { |
---|
| 28 | Header('Location: index.php'); |
---|
| 29 | exit; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup'); |
---|
| 33 | $setup_tpl = CreateObject('setup.Template',$tpl_root); |
---|
| 34 | |
---|
| 35 | // test if $path lies within the webservers document-root |
---|
| 36 | // |
---|
| 37 | function in_docroot($path) |
---|
| 38 | { |
---|
| 39 | $docroots = array(PHPGW_SERVER_ROOT,$_SERVER['DOCUMENT_ROOT']); |
---|
| 40 | |
---|
| 41 | foreach ($docroots as $docroot) |
---|
| 42 | { |
---|
| 43 | $len = strlen($docroot); |
---|
| 44 | |
---|
| 45 | if ($docroot == substr($path,0,$len)) |
---|
| 46 | { |
---|
| 47 | $rest = substr($path,$len); |
---|
| 48 | |
---|
| 49 | if (!strlen($rest) || $rest[0] == DIRECTORY_SEPARATOR) |
---|
| 50 | { |
---|
| 51 | return True; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | return False; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | $setup_tpl->set_file(array( |
---|
| 59 | 'T_head' => 'head.tpl', |
---|
| 60 | 'T_footer' => 'footer.tpl', |
---|
| 61 | 'T_alert_msg' => 'msg_alert_msg.tpl', |
---|
| 62 | 'T_config_pre_script' => 'config_pre_script.tpl', |
---|
| 63 | 'T_config_post_script' => 'config_post_script.tpl' |
---|
| 64 | )); |
---|
| 65 | |
---|
| 66 | /* Following to ensure windows file paths are saved correctly */ |
---|
| 67 | set_magic_quotes_runtime(0); |
---|
| 68 | |
---|
| 69 | $GLOBALS['phpgw_setup']->loaddb(); |
---|
| 70 | |
---|
| 71 | /* Check api version, use correct table */ |
---|
| 72 | $setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions(); |
---|
| 73 | |
---|
| 74 | if($GLOBALS['phpgw_setup']->alessthanb($setup_info['phpgwapi']['currentver'], '0.9.10pre7')) |
---|
| 75 | { |
---|
| 76 | $configtbl = 'config'; |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | $configtbl = 'phpgw_config'; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | $newsettings = $_POST['newsettings']; |
---|
| 84 | $files_in_docroot = in_docroot($newsettings['files_dir']); |
---|
| 85 | |
---|
| 86 | if(@get_var('submit',Array('POST')) && @$newsettings && !$files_in_docroot) |
---|
| 87 | { |
---|
| 88 | $datetime = CreateObject('phpgwapi.date_time'); |
---|
| 89 | switch((int)$newsettings['daytime_port']) |
---|
| 90 | { |
---|
| 91 | case 13: |
---|
| 92 | $newsettings['tz_offset'] = $datetime->getntpoffset(); |
---|
| 93 | break; |
---|
| 94 | case 80: |
---|
| 95 | $newsettings['tz_offset'] = $datetime->gethttpoffset(); |
---|
| 96 | break; |
---|
| 97 | default: |
---|
| 98 | $newsettings['tz_offset'] = $datetime->getbestguess(); |
---|
| 99 | break; |
---|
| 100 | } |
---|
| 101 | unset($datetime); |
---|
| 102 | |
---|
| 103 | print_debug('TZ_OFFSET',$newsettings['tz_offset']); |
---|
| 104 | |
---|
| 105 | $GLOBALS['phpgw_setup']->db->transaction_begin(); |
---|
| 106 | /* This is only temp: */ |
---|
| 107 | $GLOBALS['phpgw_setup']->db->query("DELETE FROM $configtbl WHERE config_name='useframes'"); |
---|
| 108 | $GLOBALS['phpgw_setup']->db->query("INSERT INTO $configtbl (config_app,config_name, config_value) values ('phpgwapi','useframes','never')"); |
---|
| 109 | |
---|
| 110 | while(list($setting,$value) = @each($newsettings)) |
---|
| 111 | { |
---|
| 112 | /* echo '<br>Updating: ' . $setting . '=' . $value; */ |
---|
| 113 | /* Don't erase passwords, since we also do not print them below */ |
---|
| 114 | if($value || (!ereg('passwd',$setting) && !ereg('password',$setting) && !ereg('root_pw',$setting))) |
---|
| 115 | { |
---|
| 116 | @$GLOBALS['phpgw_setup']->db->query("DELETE FROM $configtbl WHERE config_name='" . $setting . "'"); |
---|
| 117 | } |
---|
| 118 | if($value) |
---|
| 119 | { |
---|
| 120 | $GLOBALS['phpgw_setup']->db->query("INSERT INTO $configtbl (config_app,config_name, config_value) VALUES ('phpgwapi','" . $GLOBALS['phpgw_setup']->db->db_addslashes($setting) |
---|
| 121 | . "','" . $GLOBALS['phpgw_setup']->db->db_addslashes($value) . "')"); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | $GLOBALS['phpgw_setup']->db->transaction_commit(); |
---|
| 125 | |
---|
| 126 | /* Add cleaning of app_sessions per skeeter, but with a check for the table being there, just in case */ |
---|
| 127 | $tablenames = $GLOBALS['phpgw_setup']->db->table_names(); |
---|
| 128 | while(list($key,$val) = @each($tablenames)) |
---|
| 129 | { |
---|
| 130 | $tables[] = $val['table_name']; |
---|
| 131 | } |
---|
| 132 | if(in_array('phpgw_app_sessions',$tables)) |
---|
| 133 | { |
---|
| 134 | $GLOBALS['phpgw_setup']->db->lock(array('phpgw_app_sessions')); |
---|
| 135 | @$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_app_sessions WHERE sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config'",__LINE__,__FILE__); |
---|
| 136 | @$GLOBALS['phpgw_setup']->db->query("DELETE FROM phpgw_app_sessions WHERE app = 'phpgwapi' and location = 'phpgw_info_cache'",__LINE__,__FILE__); |
---|
| 137 | $GLOBALS['phpgw_setup']->db->unlock(); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | if($newsettings['auth_type'] == 'ldap') |
---|
| 141 | { |
---|
| 142 | Header('Location: '.$newsettings['webserver_url'].'/setup/ldap.php'); |
---|
| 143 | exit; |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | Header('Location: index.php'); |
---|
| 148 | exit; |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | if($newsettings['auth_type'] != 'ldap') |
---|
| 153 | { |
---|
| 154 | $GLOBALS['phpgw_setup']->html->show_header(lang('Configuration'),False,'config',$GLOBALS['phpgw_setup']->ConfigDomain . '(' . $phpgw_domain[$GLOBALS['phpgw_setup']->ConfigDomain]['db_type'] . ')'); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | @$GLOBALS['phpgw_setup']->db->query("SELECT * FROM $configtbl where config_app='phpgwapi'"); |
---|
| 158 | while(@$GLOBALS['phpgw_setup']->db->next_record()) |
---|
| 159 | { |
---|
| 160 | $GLOBALS['current_config'][$GLOBALS['phpgw_setup']->db->f('config_name')] = $GLOBALS['phpgw_setup']->db->f('config_value'); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // are we here because of an error: files-dir in docroot |
---|
| 164 | if (is_array($_POST['newsettings']) && $files_in_docroot) |
---|
| 165 | { |
---|
| 166 | echo '<p align="center"><font color="red"><b>'.lang('Path to user and group files HAS TO BE OUTSIDE of the webservers document-root!!!')."</b></font></p>\n"; |
---|
| 167 | |
---|
| 168 | foreach($_POST['newsettings'] as $key => $val) |
---|
| 169 | { |
---|
| 170 | $GLOBALS['current_config'][$key] = $val; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | if($GLOBALS['error'] == 'badldapconnection') |
---|
| 175 | { |
---|
| 176 | /* Please check the number and dial again :) */ |
---|
| 177 | $GLOBALS['phpgw_setup']->html->show_alert_msg('Error', |
---|
| 178 | lang('There was a problem trying to connect to your LDAP server. <br>' |
---|
| 179 | .'please check your LDAP server configuration') . '.'); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | $setup_tpl->pparse('out','T_config_pre_script'); |
---|
| 183 | |
---|
| 184 | /* Now parse each of the templates we want to show here */ |
---|
| 185 | class phpgw |
---|
| 186 | { |
---|
| 187 | var $common; |
---|
| 188 | var $accounts; |
---|
| 189 | var $applications; |
---|
| 190 | var $db; |
---|
| 191 | } |
---|
| 192 | $GLOBALS['phpgw'] = new phpgw; |
---|
| 193 | $GLOBALS['phpgw']->common = CreateObject('phpgwapi.common'); |
---|
| 194 | $GLOBALS['phpgw']->db = $GLOBALS['phpgw_setup']->db; |
---|
| 195 | |
---|
| 196 | /*$cfg_apps = array('phpgwapi','admin','preferences'); |
---|
| 197 | while(list(,$cfg_app) = each($cfg_apps)) |
---|
| 198 | {*/ |
---|
| 199 | $t = CreateObject('setup.Template',$GLOBALS['phpgw']->common->get_tpl_dir('setup')); |
---|
| 200 | |
---|
| 201 | $t->set_unknowns('keep'); |
---|
| 202 | $t->set_file(array('config' => 'config.tpl')); |
---|
| 203 | $t->set_block('config','body','body'); |
---|
| 204 | |
---|
| 205 | $vars = $t->get_undefined('body'); |
---|
| 206 | $GLOBALS['phpgw_setup']->hook('config','setup'); |
---|
| 207 | |
---|
| 208 | while(list($null,$value) = each($vars)) |
---|
| 209 | { |
---|
| 210 | $valarray = explode('_',$value); |
---|
| 211 | $type = $valarray[0]; |
---|
| 212 | $new = $newval = ''; |
---|
| 213 | |
---|
| 214 | while($chunk = next($valarray)) |
---|
| 215 | { |
---|
| 216 | $new[] = $chunk; |
---|
| 217 | } |
---|
| 218 | $newval = implode(' ',$new); |
---|
| 219 | |
---|
| 220 | switch ($type) |
---|
| 221 | { |
---|
| 222 | case 'lang': |
---|
| 223 | $t->set_var($value,lang($newval)); |
---|
| 224 | break; |
---|
| 225 | case 'value': |
---|
| 226 | $newval = str_replace(' ','_',$newval); |
---|
| 227 | /* Don't show passwords in the form */ |
---|
| 228 | if(strstr($value,'passwd') || strstr($value,'password') || strstr($value,'root_pw')) |
---|
| 229 | { |
---|
| 230 | $t->set_var($value,''); |
---|
| 231 | } |
---|
| 232 | else |
---|
| 233 | { |
---|
| 234 | $t->set_var($value,@$current_config[$newval]); |
---|
| 235 | } |
---|
| 236 | break; |
---|
| 237 | case 'selected': |
---|
| 238 | $configs = array(); |
---|
| 239 | $config = ''; |
---|
| 240 | $newvals = explode(' ',$newval); |
---|
| 241 | $setting = end($newvals); |
---|
| 242 | for($i=0;$i<(count($newvals) - 1); $i++) |
---|
| 243 | { |
---|
| 244 | $configs[] = $newvals[$i]; |
---|
| 245 | } |
---|
| 246 | $config = implode('_',$configs); |
---|
| 247 | /* echo $config . '=' . $current_config[$config]; */ |
---|
| 248 | if(@$current_config[$config] == $setting) |
---|
| 249 | { |
---|
| 250 | $t->set_var($value,' selected'); |
---|
| 251 | } |
---|
| 252 | else |
---|
| 253 | { |
---|
| 254 | $t->set_var($value,''); |
---|
| 255 | } |
---|
| 256 | break; |
---|
| 257 | case 'hook': |
---|
| 258 | $newval = str_replace(' ','_',$newval); |
---|
| 259 | $t->set_var($value,$newval($current_config)); |
---|
| 260 | break; |
---|
| 261 | default: |
---|
| 262 | $t->set_var($value,''); |
---|
| 263 | break; |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | $t->pfp('out','body'); |
---|
| 268 | unset($t); |
---|
| 269 | //} |
---|
| 270 | |
---|
| 271 | $setup_tpl->set_var('more_configs',lang('Please login to egroupware and run the admin application for additional site configuration') . '.'); |
---|
| 272 | |
---|
| 273 | $setup_tpl->set_var('lang_submit',lang('Save')); |
---|
| 274 | $setup_tpl->set_var('lang_cancel',lang('Cancel')); |
---|
| 275 | $setup_tpl->pparse('out','T_config_post_script'); |
---|
| 276 | |
---|
| 277 | $GLOBALS['phpgw_setup']->html->show_footer(); |
---|
| 278 | ?> |
---|
| 279 | |
---|