2001-07-30 17:59:25 +02:00
< ? php
/************************************************************************** \
2004-01-27 21:49:25 +01:00
* eGroupWare - Setup *
* http :// www . egroupware . org *
2001-07-30 17:59:25 +02:00
* -------------------------------------------- *
* This program is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation ; either version 2 of the License , or ( at your *
* option ) any later version . *
\ **************************************************************************/
/* $Id$ */
2001-12-18 03:25:55 +01:00
$phpgw_info = array ();
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'phpgw_info' ][ 'flags' ] = array (
2001-07-30 17:59:25 +02:00
'noheader' => True ,
'nonavbar' => True ,
2001-09-12 18:49:41 +02:00
'currentapp' => 'home' ,
2001-07-30 17:59:25 +02:00
'noapi' => True
);
include ( './inc/functions.inc.php' );
2001-12-18 03:20:31 +01:00
/*
Authorize the user to use setup app and load the database
Does not return unless user is authorized
*/
2003-10-04 15:24:34 +02:00
if ( ! $GLOBALS [ 'phpgw_setup' ] -> auth ( 'Config' ) || @ $_POST [ 'cancel' ])
2001-12-18 03:20:31 +01:00
{
Header ( 'Location: index.php' );
exit ;
}
2001-07-30 17:59:25 +02:00
2002-03-03 22:53:00 +01:00
$tpl_root = $GLOBALS [ 'phpgw_setup' ] -> html -> setup_tpl_dir ( 'setup' );
2002-08-12 01:54:58 +02:00
$setup_tpl = CreateObject ( 'setup.Template' , $tpl_root );
2003-08-28 16:31:11 +02:00
// test if $path lies within the webservers document-root
//
function in_docroot ( $path )
{
2004-01-16 13:52:05 +01:00
$docroots = array ( PHPGW_SERVER_ROOT , $_SERVER [ 'DOCUMENT_ROOT' ]);
2003-08-28 16:31:11 +02:00
foreach ( $docroots as $docroot )
{
$len = strlen ( $docroot );
if ( $docroot == substr ( $path , 0 , $len ))
{
$rest = substr ( $path , $len );
if ( ! strlen ( $rest ) || $rest [ 0 ] == DIRECTORY_SEPARATOR )
{
return True ;
}
}
}
return False ;
}
2001-07-30 17:59:25 +02:00
$setup_tpl -> set_file ( array (
'T_head' => 'head.tpl' ,
'T_footer' => 'footer.tpl' ,
'T_alert_msg' => 'msg_alert_msg.tpl' ,
'T_config_pre_script' => 'config_pre_script.tpl' ,
'T_config_post_script' => 'config_post_script.tpl'
));
2001-11-15 00:17:27 +01:00
/* Following to ensure windows file paths are saved correctly */
set_magic_quotes_runtime ( 0 );
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> loaddb ();
2001-07-30 17:59:25 +02:00
/* Check api version, use correct table */
2002-03-03 22:53:00 +01:00
$setup_info = $GLOBALS [ 'phpgw_setup' ] -> detection -> get_db_versions ();
2003-08-28 16:31:11 +02:00
2002-03-03 22:53:00 +01:00
if ( $GLOBALS [ 'phpgw_setup' ] -> alessthanb ( $setup_info [ 'phpgwapi' ][ 'currentver' ], '0.9.10pre7' ))
2001-07-30 17:59:25 +02:00
{
$configtbl = 'config' ;
}
else
{
$configtbl = 'phpgw_config' ;
}
2003-10-04 15:24:34 +02:00
$newsettings = $_POST [ 'newsettings' ];
$files_in_docroot = in_docroot ( $newsettings [ 'files_dir' ]);
2003-08-28 16:31:11 +02:00
if ( @ get_var ( 'submit' , Array ( 'POST' )) && @ $newsettings && ! $files_in_docroot )
2001-07-30 17:59:25 +02:00
{
2002-08-14 01:39:39 +02:00
$datetime = CreateObject ( 'phpgwapi.datetime' );
2003-12-10 12:45:03 +01:00
switch (( int ) $newsettings [ 'daytime_port' ])
2002-08-14 01:39:39 +02:00
{
case 13 :
$newsettings [ 'tz_offset' ] = $datetime -> getntpoffset ();
break ;
case 80 :
$newsettings [ 'tz_offset' ] = $datetime -> gethttpoffset ();
break ;
default :
$newsettings [ 'tz_offset' ] = $datetime -> getbestguess ();
break ;
}
unset ( $datetime );
print_debug ( 'TZ_OFFSET' , $newsettings [ 'tz_offset' ]);
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> transaction_begin ();
2001-07-30 17:59:25 +02:00
/* This is only temp: */
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " DELETE FROM $configtbl WHERE config_name='useframes' " );
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " INSERT INTO $configtbl (config_app,config_name, config_value) values ('phpgwapi','useframes','never') " );
2001-07-30 17:59:25 +02:00
2002-03-03 22:53:00 +01:00
while ( list ( $setting , $value ) = @ each ( $newsettings ))
2001-07-30 17:59:25 +02:00
{
2001-12-26 18:21:24 +01:00
/* echo '<br>Updating: ' . $setting . '=' . $value; */
2001-12-21 23:41:44 +01:00
/* Don't erase passwords, since we also do not print them below */
2003-08-28 16:31:11 +02:00
if ( $value || ( ! ereg ( 'passwd' , $setting ) && ! ereg ( 'password' , $setting ) && ! ereg ( 'root_pw' , $setting )))
2001-12-21 23:41:44 +01:00
{
2002-03-03 22:53:00 +01:00
@ $GLOBALS [ 'phpgw_setup' ] -> db -> query ( " DELETE FROM $configtbl WHERE config_name=' " . $setting . " ' " );
2001-12-21 23:41:44 +01:00
}
2001-07-30 17:59:25 +02:00
if ( $value )
{
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> query ( " INSERT INTO $configtbl (config_app,config_name, config_value) VALUES ('phpgwapi',' " . $GLOBALS [ 'phpgw_setup' ] -> db -> db_addslashes ( $setting )
. " ',' " . $GLOBALS [ 'phpgw_setup' ] -> db -> db_addslashes ( $value ) . " ') " );
2001-07-30 17:59:25 +02:00
}
}
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> transaction_commit ();
2001-07-30 17:59:25 +02:00
/* Add cleaning of app_sessions per skeeter, but with a check for the table being there, just in case */
2002-03-03 22:53:00 +01:00
$tablenames = $GLOBALS [ 'phpgw_setup' ] -> db -> table_names ();
2001-07-30 17:59:25 +02:00
while ( list ( $key , $val ) = @ each ( $tablenames ))
{
$tables [] = $val [ 'table_name' ];
}
2002-03-03 22:53:00 +01:00
if ( in_array ( 'phpgw_app_sessions' , $tables ))
2001-07-30 17:59:25 +02:00
{
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> db -> lock ( array ( 'phpgw_app_sessions' ));
@ $GLOBALS [ 'phpgw_setup' ] -> db -> query ( " DELETE FROM phpgw_app_sessions WHERE sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config' " , __LINE__ , __FILE__ );
@ $GLOBALS [ 'phpgw_setup' ] -> db -> query ( " DELETE FROM phpgw_app_sessions WHERE app = 'phpgwapi' and location = 'phpgw_info_cache' " , __LINE__ , __FILE__ );
$GLOBALS [ 'phpgw_setup' ] -> db -> unlock ();
2001-07-30 17:59:25 +02:00
}
2002-03-03 22:53:00 +01:00
if ( $newsettings [ 'auth_type' ] == 'ldap' )
2001-07-30 17:59:25 +02:00
{
Header ( 'Location: ' . $newsettings [ 'webserver_url' ] . '/setup/ldap.php' );
exit ;
}
else
{
Header ( 'Location: index.php' );
exit ;
}
}
2002-03-03 22:53:00 +01:00
if ( $newsettings [ 'auth_type' ] != 'ldap' )
2001-07-30 17:59:25 +02:00
{
2004-01-20 01:40:38 +01:00
$GLOBALS [ 'phpgw_setup' ] -> html -> show_header ( lang ( 'Configuration' ), False , 'config' , $GLOBALS [ 'phpgw_setup' ] -> ConfigDomain . '(' . $phpgw_domain [ $GLOBALS [ 'phpgw_setup' ] -> ConfigDomain ][ 'db_type' ] . ')' );
2001-07-30 17:59:25 +02:00
}
2002-03-03 22:53:00 +01:00
@ $GLOBALS [ 'phpgw_setup' ] -> db -> query ( " SELECT * FROM $configtbl " );
while ( @ $GLOBALS [ 'phpgw_setup' ] -> db -> next_record ())
2001-07-30 17:59:25 +02:00
{
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'current_config' ][ $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 'config_name' )] = $GLOBALS [ 'phpgw_setup' ] -> db -> f ( 'config_value' );
2001-07-30 17:59:25 +02:00
}
2003-08-28 16:31:11 +02:00
// are we here because of an error: files-dir in docroot
2004-01-16 13:52:05 +01:00
if ( is_array ( $_POST [ 'newsettings' ]) && $files_in_docroot )
2001-07-30 17:59:25 +02:00
{
2003-08-28 16:31:11 +02:00
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 " ;
2004-01-16 13:52:05 +01:00
foreach ( $_POST [ 'newsettings' ] as $key => $val )
2003-08-28 16:31:11 +02:00
{
$GLOBALS [ 'current_config' ][ $key ] = $val ;
}
2001-07-30 17:59:25 +02:00
}
2002-04-29 21:49:24 +02:00
if ( $GLOBALS [ 'error' ] == 'badldapconnection' )
2001-07-30 17:59:25 +02:00
{
/* Please check the number and dial again :) */
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> html -> show_alert_msg ( 'Error' ,
2001-07-30 17:59:25 +02:00
lang ( 'There was a problem trying to connect to your LDAP server. <br>'
. 'please check your LDAP server configuration' ) . '.' );
}
$setup_tpl -> pparse ( 'out' , 'T_config_pre_script' );
2001-09-21 22:14:04 +02:00
/* Now parse each of the templates we want to show here */
class phpgw
{
var $common ;
var $accounts ;
var $applications ;
var $db ;
}
2001-11-21 16:01:43 +01:00
$GLOBALS [ 'phpgw' ] = new phpgw ;
$GLOBALS [ 'phpgw' ] -> common = CreateObject ( 'phpgwapi.common' );
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw' ] -> db = $GLOBALS [ 'phpgw_setup' ] -> db ;
2001-09-21 22:14:04 +02:00
2002-12-07 03:12:15 +01:00
/* $cfg_apps = array ( 'phpgwapi' , 'admin' , 'preferences' );
2001-09-21 22:14:04 +02:00
while ( list (, $cfg_app ) = each ( $cfg_apps ))
2002-12-07 03:12:15 +01:00
{ */
$t = CreateObject ( 'setup.Template' , $GLOBALS [ 'phpgw' ] -> common -> get_tpl_dir ( 'setup' ));
2001-09-21 22:14:04 +02:00
$t -> set_unknowns ( 'keep' );
$t -> set_file ( array ( 'config' => 'config.tpl' ));
$t -> set_block ( 'config' , 'body' , 'body' );
$vars = $t -> get_undefined ( 'body' );
2002-12-07 03:12:15 +01:00
$GLOBALS [ 'phpgw_setup' ] -> hook ( 'config' , 'setup' );
2001-09-21 22:14:04 +02:00
2002-03-03 22:53:00 +01:00
while ( list ( $null , $value ) = each ( $vars ))
2001-09-21 22:14:04 +02:00
{
$valarray = explode ( '_' , $value );
$type = $valarray [ 0 ];
$new = $newval = '' ;
while ( $chunk = next ( $valarray ))
{
$new [] = $chunk ;
}
$newval = implode ( ' ' , $new );
switch ( $type )
{
case 'lang' :
$t -> set_var ( $value , lang ( $newval ));
break ;
case 'value' :
2003-12-10 12:45:03 +01:00
$newval = str_replace ( ' ' , '_' , $newval );
2001-12-21 23:38:03 +01:00
/* Don't show passwords in the form */
2004-01-18 22:03:56 +01:00
if ( strstr ( $value , 'passwd' ) || strstr ( $value , 'password' ) || strstr ( $value , 'root_pw' ))
2001-12-21 23:38:03 +01:00
{
$t -> set_var ( $value , '' );
}
else
{
2002-04-29 21:49:24 +02:00
$t -> set_var ( $value , @ $current_config [ $newval ]);
2001-12-21 23:38:03 +01:00
}
2001-09-21 22:14:04 +02:00
break ;
case 'selected' :
$configs = array ();
$config = '' ;
$newvals = explode ( ' ' , $newval );
$setting = end ( $newvals );
2002-03-03 22:53:00 +01:00
for ( $i = 0 ; $i < ( count ( $newvals ) - 1 ); $i ++ )
2001-09-21 22:14:04 +02:00
{
$configs [] = $newvals [ $i ];
}
$config = implode ( '_' , $configs );
/* echo $config . '=' . $current_config[$config]; */
2002-04-29 21:49:24 +02:00
if ( @ $current_config [ $config ] == $setting )
2001-09-21 22:14:04 +02:00
{
$t -> set_var ( $value , ' selected' );
}
else
{
$t -> set_var ( $value , '' );
}
break ;
case 'hook' :
2003-12-10 12:45:03 +01:00
$newval = str_replace ( ' ' , '_' , $newval );
2001-09-21 22:14:04 +02:00
$t -> set_var ( $value , $newval ( $current_config ));
break ;
default :
$t -> set_var ( $value , '' );
break ;
}
}
$t -> pfp ( 'out' , 'body' );
unset ( $t );
2002-12-07 03:12:15 +01:00
//}
2001-09-21 22:14:04 +02:00
2003-12-19 13:34:45 +01:00
$setup_tpl -> set_var ( 'more_configs' , lang ( 'Please login to egroupware and run the admin application for additional site configuration' ) . '.' );
2001-07-30 17:59:25 +02:00
2003-08-28 16:31:11 +02:00
$setup_tpl -> set_var ( 'lang_submit' , lang ( 'Save' ));
$setup_tpl -> set_var ( 'lang_cancel' , lang ( 'Cancel' ));
2001-07-30 17:59:25 +02:00
$setup_tpl -> pparse ( 'out' , 'T_config_post_script' );
2002-03-03 22:53:00 +01:00
$GLOBALS [ 'phpgw_setup' ] -> html -> show_footer ();
2001-07-30 17:59:25 +02:00
?>
2003-08-28 16:31:11 +02:00