2001-07-30 17:59:25 +02:00
< ? php
2006-05-29 04:56:16 +02:00
/**
2016-05-01 17:56:49 +02:00
* EGroupware Setup - create admin account
2006-05-29 04:56:16 +02:00
*
* @ link http :// www . egroupware . org
* @ package setup
* @ author Miles Lott < milos @ groupwhere . org >
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ version $Id $
*/
2016-03-05 15:02:13 +01:00
use EGroupware\Api ;
2016-05-01 17:56:49 +02:00
use EGroupware\Api\Framework ;
2016-03-05 15:02:13 +01:00
2008-08-20 08:04:28 +02:00
if ( strpos ( $_SERVER [ 'PHP_SELF' ], 'admin_account.php' ) !== false )
{
include ( './inc/functions.inc.php' );
// Authorize the user to use setup app and load the database
// Does not return unless user is authorized
if ( ! $GLOBALS [ 'egw_setup' ] -> auth ( 'Config' ) || get_var ( 'cancel' , Array ( 'POST' )))
2001-09-17 04:23:41 +02:00
{
2008-08-20 08:04:28 +02:00
Header ( 'Location: index.php' );
exit ;
2001-07-30 17:59:25 +02:00
}
2008-08-20 08:04:28 +02:00
$GLOBALS [ 'egw_setup' ] -> loaddb ( true );
}
$error = '' ;
if ( $_POST [ 'submit' ])
{
2014-05-01 08:26:09 +02:00
// for POST (not GET or cli call via setup_cmd_admin) validate CSRF token
if ( $_SERVER [ 'REQUEST_METHOD' ] == 'POST' )
{
2016-03-05 15:02:13 +01:00
Api\Csrf :: validate ( $_POST [ 'csrf_token' ], __FILE__ );
2014-05-01 08:26:09 +02:00
}
2008-08-20 08:04:28 +02:00
/* Posted admin data */
$passwd = get_var ( 'passwd' , Array ( 'POST' ));
$passwd2 = get_var ( 'passwd2' , Array ( 'POST' ));
$username = get_var ( 'username' , Array ( 'POST' ));
$fname = get_var ( 'fname' , Array ( 'POST' ));
$lname = get_var ( 'lname' , Array ( 'POST' ));
$email = get_var ( 'email' , Array ( 'POST' ));
if ( $passwd != $passwd2 || ! $username )
2005-11-27 08:48:22 +01:00
{
2008-08-20 08:04:28 +02:00
$error = '<p>' . lang ( 'Passwords did not match, please re-enter' ) . " .</p> \n " ;
2005-11-27 08:48:22 +01:00
}
2008-08-20 08:04:28 +02:00
if ( ! $username )
2001-12-11 05:36:40 +01:00
{
2008-08-20 08:04:28 +02:00
$error = '<p>' . lang ( 'You must enter a username for the admin' ) . " .</p> \n " ;
2001-12-11 05:36:40 +01:00
}
2008-08-20 08:04:28 +02:00
}
if ( ! $_POST [ 'submit' ] || $error )
{
$tpl_root = $GLOBALS [ 'egw_setup' ] -> html -> setup_tpl_dir ( 'setup' );
2016-05-01 17:56:49 +02:00
$setup_tpl = new Framework\Template ( $tpl_root );
2008-08-20 08:04:28 +02:00
$setup_tpl -> set_file ( array (
'T_head' => 'head.tpl' ,
'T_footer' => 'footer.tpl' ,
'T_alert_msg' => 'msg_alert_msg.tpl' ,
'T_login_main' => 'login_main.tpl' ,
'T_login_stage_header' => 'login_stage_header.tpl' ,
'T_admin_account' => 'admin_account.tpl'
));
$setup_tpl -> set_block ( 'T_login_stage_header' , 'B_multi_domain' , 'V_multi_domain' );
$setup_tpl -> set_block ( 'T_login_stage_header' , 'B_single_domain' , 'V_single_domain' );
2001-12-11 05:36:40 +01:00
2008-08-20 08:04:28 +02:00
$GLOBALS [ 'egw_setup' ] -> html -> show_header ( lang ( 'Create admin account' ));
2001-07-30 17:59:25 +02:00
2008-08-20 08:04:28 +02:00
$setup_tpl -> set_var ( array (
'error' => $error ,
'username' => $username ,
'fname' => $fname ,
'lname' => $lname ,
'email' => $email ,
));
$setup_tpl -> set_var ( 'action_url' , 'admin_account.php' );
$setup_tpl -> set_var ( 'description' , lang ( 'This will create a first user in eGroupWare or reset password and admin rights of an exiting user' ));
$setup_tpl -> set_var ( 'lang_deleteall' , lang ( 'Delete all existing SQL accounts, groups, ACLs and preferences (normally not necessary)?' ));
2004-03-21 17:11:51 +01:00
2008-08-20 08:04:28 +02:00
$setup_tpl -> set_var ( 'detailadmin' , lang ( 'Details for Admin account' ));
$setup_tpl -> set_var ( 'adminusername' , lang ( 'Admin username' ));
$setup_tpl -> set_var ( 'adminfirstname' , lang ( 'Admin first name' ));
$setup_tpl -> set_var ( 'adminlastname' , lang ( 'Admin last name' ));
$setup_tpl -> set_var ( 'adminemail' , lang ( 'Admin email address' ));
$setup_tpl -> set_var ( 'adminpassword' , lang ( 'Admin password' ));
$setup_tpl -> set_var ( 'adminpassword2' , lang ( 'Re-enter password' ));
$setup_tpl -> set_var ( 'admin_all_apps' , lang ( 'Give admin access to all installed apps' ));
$setup_tpl -> set_var ( 'all_apps_desc' , lang ( 'Usually more annoying.<br />Admins can use Admin >> Manage accounts or groups to give access to further apps.' ));
$setup_tpl -> set_var ( 'create_demo_accounts' , lang ( 'Create demo accounts' ));
$setup_tpl -> set_var ( 'demo_desc' , lang ( 'The username/passwords are: demo/guest, demo2/guest and demo3/guest.' ));
2016-05-01 17:56:49 +02:00
$setup_tpl -> set_var ( 'hidden_vars' , Api\Html :: input_hidden ( 'csrf_token' , Api\Csrf :: token ( __FILE__ )));
2014-05-01 08:26:09 +02:00
2008-08-20 08:04:28 +02:00
$setup_tpl -> set_var ( 'lang_submit' , lang ( 'Save' ));
$setup_tpl -> set_var ( 'lang_cancel' , lang ( 'Cancel' ));
$setup_tpl -> pparse ( 'out' , 'T_admin_account' );
$GLOBALS [ 'egw_setup' ] -> html -> show_footer ();
}
else
{
/* Begin transaction for acl, etc */
$GLOBALS [ 'egw_setup' ] -> db -> transaction_begin ();
if ( $_POST [ 'delete_all' ])
{
/* Now, clear out existing tables */
2013-05-22 19:22:20 +02:00
foreach ( array ( $GLOBALS [ 'egw_setup' ] -> accounts_table , $GLOBALS [ 'egw_setup' ] -> acl_table , 'egw_access_log' ) as $table )
2004-03-21 17:11:51 +01:00
{
2008-08-20 08:04:28 +02:00
$GLOBALS [ 'egw_setup' ] -> db -> delete ( $table , '1=1' , __LINE__ , __FILE__ );
2006-06-08 01:10:06 +02:00
}
2013-05-22 19:22:20 +02:00
// keep default and forced prefs from installed apps
2013-05-22 20:30:04 +02:00
$GLOBALS [ 'egw_setup' ] -> db -> delete ( $GLOBALS [ 'egw_setup' ] -> prefs_table , 'preference_owner NOT IN (-1,-2)' , __LINE__ , __FILE__ );
2013-05-22 19:22:20 +02:00
// remove accounts from addressbook
$GLOBALS [ 'egw_setup' ] -> db -> delete ( 'egw_addressbook' , 'account_id IS NOT NULL' , __LINE__ , __FILE__ );
2008-08-20 08:04:28 +02:00
}
2015-07-01 09:25:16 +02:00
// create our stock groups: Default (all users) and Admins (administrators)
2008-08-20 08:04:28 +02:00
$defaultgroupid = ( int ) $GLOBALS [ 'egw_setup' ] -> add_account ( 'Default' , 'Default' , 'Group' , False , False );
$admingroupid = ( int ) $GLOBALS [ 'egw_setup' ] -> add_account ( 'Admins' , 'Admin' , 'Group' , False , False );
if ( ! $defaultgroupid || ! $admingroupid )
{
if ( strpos ( $_SERVER [ 'PHP_SELF' ], 'admin_account.php' ) === false )
2006-06-08 01:10:06 +02:00
{
2008-08-20 08:04:28 +02:00
return 42 ; //lang('Error in group-creation !!!'); // dont exit on setup-cli
2004-03-21 17:11:51 +01:00
}
2008-08-20 08:04:28 +02:00
echo '<p><b>' . lang ( 'Error in group-creation !!!' ) . " </b></p> \n " ;
echo '<p>' . lang ( 'click <a href="index.php">here</a> to return to setup.' ) . " </p> \n " ;
$GLOBALS [ 'egw_setup' ] -> db -> transaction_abort ();
exit ;
}
// Group perms for the default group
2015-07-07 16:15:52 +02:00
$default_group_apps = array ( 'addressbook' , 'calendar' , 'infolog' , 'mail' , 'filemanager' , 'preferences' , 'manual' , 'groupdav' , 'notifications' , 'timesheet' , 'importexport' , 'activesync' );
2015-07-01 09:25:16 +02:00
$GLOBALS [ 'egw_setup' ] -> add_acl ( $default_group_apps , 'run' , $defaultgroupid );
2008-08-20 08:04:28 +02:00
$apps = array ();
2011-03-30 09:54:29 +02:00
foreach ( $GLOBALS [ 'egw_setup' ] -> db -> select ( $GLOBALS [ 'egw_setup' ] -> applications_table , 'app_name' , 'app_enabled < 3' , __LINE__ , __FILE__ ) as $row )
2008-08-20 08:04:28 +02:00
{
2011-03-30 09:54:29 +02:00
$apps [] = $row [ 'app_name' ];
2008-08-20 08:04:28 +02:00
}
// if not otherwise selected, give admin only access to the rest of the default apps,
// not yet set for the default group or development only apps like (etemplate, jinn, tt's)
if ( ! $_POST [ 'admin_all_apps' ])
{
2015-07-01 09:25:16 +02:00
$apps = array_intersect (
// also give Admins apps of all users group Defaults, in case one forgot to add admins to it
array_unique ( array_merge ( $default_group_apps ,
array ( 'admin' , 'bookmarks' , 'emailadmin' , 'news_admin' , 'phpbrain' , 'phpsysinfo' , 'phpfreechat' , 'projectmanager' , 'resources' , 'sitemgr' , 'timesheet' , 'tracker' , 'wiki' ))), $apps );
2008-08-20 08:04:28 +02:00
}
$GLOBALS [ 'egw_setup' ] -> add_acl ( $apps , 'run' , $admingroupid );
/* Creation of the demo accounts is optional - the checkbox is on by default. */
if ( get_var ( 'create_demo' , Array ( 'POST' )))
{
// Create 3 demo accounts
$GLOBALS [ 'egw_setup' ] -> add_account ( 'demo' , 'Demo' , 'Account' , 'guest' );
$GLOBALS [ 'egw_setup' ] -> add_account ( 'demo2' , 'Demo2' , 'Account' , 'guest' );
$GLOBALS [ 'egw_setup' ] -> add_account ( 'demo3' , 'Demo3' , 'Account' , 'guest' );
}
2001-09-17 04:23:41 +02:00
2008-08-20 08:04:28 +02:00
/* Create records for administrator account, with Admins as primary and Default as additional group */
$accountid = $GLOBALS [ 'egw_setup' ] -> add_account ( $username , $fname , $lname , $passwd , 'Admins' , True , $email );
if ( ! $accountid )
{
if ( strpos ( $_SERVER [ 'PHP_SELF' ], 'admin_account.php' ) === false )
2004-07-13 00:06:13 +02:00
{
2008-08-20 08:04:28 +02:00
return 41 ; //lang('Error in admin-creation !!!'); // dont exit on setup-cli
2004-07-13 00:06:13 +02:00
}
2008-08-20 08:04:28 +02:00
echo '<p><b>' . lang ( 'Error in admin-creation !!!' ) . " </b></p> \n " ;
echo '<p>' . lang ( 'click <a href="index.php">here</a> to return to setup.' ) . " </p> \n " ;
$GLOBALS [ 'egw_setup' ] -> db -> transaction_abort ();
exit ;
}
$GLOBALS [ 'egw_setup' ] -> set_memberships ( array ( $admingroupid , $defaultgroupid ), $accountid );
2002-03-03 22:53:00 +01:00
2008-08-20 08:04:28 +02:00
$GLOBALS [ 'egw_setup' ] -> db -> transaction_commit ();
2001-12-11 05:36:40 +01:00
2008-08-20 08:04:28 +02:00
if ( strpos ( $_SERVER [ 'PHP_SELF' ], 'admin_account.php' ) !== false )
{
Header ( 'Location: index.php' );
2001-12-11 05:36:40 +01:00
}
2008-08-20 08:04:28 +02:00
}