True, 'nonavbar' => True, 'currentapp' => 'home', 'noapi' => True ); 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['phpgw_setup']->auth('Config') || get_var('cancel',Array('POST'))) { Header('Location: index.php'); exit; } function add_account($username,$first,$last,$passwd,$type='u') { if($type == 'u') { $account_info = array( 'account_type' => $type, 'account_lid' => $username, 'account_passwd' => $passwd, 'account_firstname' => $first, 'account_lastname' => $last, 'account_status' => 'A', 'account_primary_group' => $GLOBALS['phpgw']->accounts->name2id('default'), 'account_groups' => array($GLOBALS['phpgw']->accounts->name2id('default')), 'account_expires' => -1 ); } else { $account_info = array( 'account_type' => $type, 'account_lid' => $username, 'account_passwd' => $passwd, 'account_firstname' => $first, 'account_lastname' => $last, 'account_status' => 'A', 'account_expires' => -1 ); } $GLOBALS['phpgw']->accounts->create($account_info); return $GLOBALS['phpgw']->accounts->name2id($username); } if(!get_var('submit',Array('POST'))) { $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup'); $setup_tpl = CreateObject('setup.Template',$tpl_root); $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_setup_demo' => 'setup_demo.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'); $GLOBALS['phpgw_setup']->html->show_header(lang('Demo Server Setup')); $setup_tpl->set_var('action_url','setup_demo.php'); $setup_tpl->set_var('description',lang('This will create 1 admin account and 3 demo accounts
The username/passwords are: demo/guest, demo2/guest and demo3/guest.
!!!THIS WILL DELETE ALL EXISTING ACCOUNTS!!!
') . ' '. lang('(account deletion in SQL only)' )); $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('adminpassword',lang('Admin password')); $setup_tpl->set_var('adminpassword2',lang('Re-enter password')); $setup_tpl->set_var('create_demo_accounts',lang('Create demo accounts')); $setup_tpl->set_var('lang_submit',lang('Save')); $setup_tpl->set_var('lang_cancel',lang('Cancel')); $setup_tpl->pparse('out','T_setup_demo'); $GLOBALS['phpgw_setup']->html->show_footer(); } else { /* 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')); if($passwd != $passwd2) { echo lang('Passwords did not match, please re-enter') . '.'; exit; } if(!$username) { echo lang('You must enter a username for the admin') . '.'; exit; } $GLOBALS['phpgw_setup']->loaddb(); /* Load up some configured values */ $GLOBALS['phpgw_setup']->db->query("SELECT config_name,config_value FROM phpgw_config ". "WHERE config_name LIKE 'ldap%' OR config_name LIKE 'account_%'",__LINE__,__FILE__); while ($GLOBALS['phpgw_setup']->db->next_record()) { $config[$GLOBALS['phpgw_setup']->db->f('config_name')] = $GLOBALS['phpgw_setup']->db->f('config_value'); } $GLOBALS['phpgw_info']['server']['ldap_host'] = $config['ldap_host']; $GLOBALS['phpgw_info']['server']['ldap_context'] = $config['ldap_context']; $GLOBALS['phpgw_info']['server']['ldap_group_context'] = $config['ldap_group_context']; $GLOBALS['phpgw_info']['server']['ldap_root_dn'] = $config['ldap_root_dn']; $GLOBALS['phpgw_info']['server']['ldap_root_pw'] = $config['ldap_root_pw']; $GLOBALS['phpgw_info']['server']['ldap_extra_attributes'] = $config['ldap_extra_attributes']; $GLOBALS['phpgw_info']['server']['ldap_account_home'] = $config['ldap_account_home']; $GLOBALS['phpgw_info']['server']['ldap_account_shell'] = $config['ldap_account_shell']; $GLOBALS['phpgw_info']['server']['ldap_encryption_type'] = $config['ldap_encryption_type']; $GLOBALS['phpgw_info']['server']['account_repository'] = $config['account_repository']; $GLOBALS['phpgw_info']['server']['ldap_version3'] = $config['ldap_version3']; $GLOBALS['phpgw_info']['server']['account_min_id'] = $config['account_min_id']; $GLOBALS['phpgw_info']['server']['account_max_id'] = $config['account_max_id']; unset($config); /* Create dummy class, then accounts object */ class phpgw { var $db; var $common; var $accounts; } $GLOBALS['phpgw'] = new phpgw; $GLOBALS['phpgw']->db = $GLOBALS['phpgw_setup']->db; $GLOBALS['phpgw']->common = CreateObject('phpgwapi.common'); $GLOBALS['phpgw']->accounts = CreateObject('phpgwapi.accounts'); $GLOBALS['phpgw']->translation = CreateObject('phpgwapi.translation'); if(($GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap') && !$GLOBALS['phpgw']->accounts->ds) { printf("Error: Error connecting to LDAP server %s!
",$GLOBALS['phpgw_info']['server']['ldap_host']); exit; } /* Begin transaction for acl, etc */ $GLOBALS['phpgw_setup']->db->transaction_begin(); /* Now, clear out existing tables */ $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_accounts'); $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_preferences'); $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_acl'); /* Create the demo groups */ $defaultgroupid = intval(add_account('Default','Default','Group',$passwd,'g')); $admingroupid = intval(add_account('Admins','Admin', 'Group',$passwd,'g')); /* Group perms for the default group */ $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('addressbook','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('filemanager','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('calendar','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('email','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('notes','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('todo','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('manual','run'," . $defaultgroupid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('preferences','run'," . $defaultgroupid . ", 1)"); function insert_default_prefs($accountid) { $defaultprefs = array( "common" => array( "maxmatchs" => 15, "template_set" => "idots", "theme" => "idots", "navbar_format"=> "icons", "tz_offset" => 0, "dateformat" => "Y/m/d", "timeformat" => "24", "lang" => get_var('ConfigLang',Array('POST','COOKIE'),'en'), "default_app" => "calendar", "currency" => "$", 'show_help' => True, ), "calendar" => array( "workdaystarts" => 9, "workdayends" => 17, "weekdaystarts" => "Monday", "defaultcalendar" => "day", 'planner_start_with_group' => $GLOBALS['defaultgroupid'], ), ); foreach ($defaultprefs as $app => $prefs) { $prefs = addslashes(serialize($prefs)); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_preferences(preference_owner,preference_app,preference_value) VALUES($accountid,'$app','$prefs')",__FILE__,__LINE__); } } insert_default_prefs(-2); // set some default prefs /* Creation of the demo accounts is optional - the checkbox is on by default. */ if(get_var('create_demo',Array('POST'))) { /* Create records for demo accounts */ $accountid = add_account('demo','Demo','Account','guest'); /* User permissions based on group membership with additional user perms for the messenger and infolog apps */ $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('preferences','changepassword', " . $accountid . ",0)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('phpgw_group', '" . $defaultgroupid."'," . $accountid . ",1)"); $accountid = add_account('demo2','Demo2','Account','guest'); /* User permissions based solely on group membership */ $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('preferences','changepassword', ".$accountid.", 0)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('phpgw_group','" . $defaultgroupid . "'," . $accountid . ",1)"); $accountid = add_account('demo3','Demo3','Account','guest'); /* User-specific perms, no group membership */ $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('preferences','changepassword', " . $accountid . ",0)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('addressbook','run', " . $accountid . ", 1)"); } /* Create records for administrator account */ $accountid = add_account($username,$fname,$lname,$passwd); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('phpgw_group','" . $defaultgroupid."'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('phpgw_group','" . $admingroupid."'," . $accountid . ",1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('preferences','changepassword', " . $accountid . ",1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('admin','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('addressbook','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('calendar','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('email','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('infolog','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('headlines','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('bookmarks','run'," . $accountid . ", 1)"); $GLOBALS['phpgw_setup']->db->transaction_commit(); Header('Location: index.php'); exit; } ?>