2007-12-13 03:41:55 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGgroupWare setup - create a first eGroupWare user / admin and our two standard groups: Default & Admins
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package setup
|
2016-05-01 17:56:49 +02:00
|
|
|
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-12-13 03:41:55 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-11-23 17:46:32 +01:00
|
|
|
* @version $Id$
|
2007-12-13 03:41:55 +01:00
|
|
|
*/
|
|
|
|
|
2016-05-01 17:56:49 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2007-12-13 03:41:55 +01:00
|
|
|
/**
|
|
|
|
* setup command: create a first eGroupWare user / admin and our two standard groups: Default & Admins
|
2008-11-23 17:46:32 +01:00
|
|
|
*
|
2007-12-13 03:41:55 +01:00
|
|
|
* @ToDo: get rid of the ugly setup_admin.php include
|
|
|
|
*/
|
2008-11-23 17:46:32 +01:00
|
|
|
class setup_cmd_admin extends setup_cmd
|
2007-12-13 03:41:55 +01:00
|
|
|
{
|
2010-07-26 10:20:14 +02:00
|
|
|
/**
|
|
|
|
* Allow to run this command via setup-cli
|
|
|
|
*/
|
|
|
|
const SETUP_CLI_CALLABLE = true;
|
|
|
|
|
2007-12-13 03:41:55 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string|array $domain domain-name or array with all parameters
|
2016-05-01 17:56:49 +02:00
|
|
|
* @param string $config_user =null user to config the domain (or header_admin_user)
|
|
|
|
* @param string $config_passwd =null pw of above user
|
|
|
|
* @param string $admin_user =null
|
|
|
|
* @param string $admin_password =null
|
|
|
|
* @param string $admin_firstname =null
|
|
|
|
* @param string $admin_lastname =null
|
|
|
|
* @param string $admin_email =null
|
|
|
|
* @param array $config =array() extra config for the account object: account_repository, ldap_*
|
|
|
|
* @param string $lang ='en'
|
2007-12-13 03:41:55 +01:00
|
|
|
*/
|
|
|
|
function __construct($domain,$config_user=null,$config_passwd=null,$admin_user=null,$admin_password=null,
|
2008-11-23 17:46:32 +01:00
|
|
|
$admin_firstname=null,$admin_lastname=null,$admin_email=null,array $config=array(),$lang='en')
|
2007-12-13 03:41:55 +01:00
|
|
|
{
|
|
|
|
if (!is_array($domain))
|
|
|
|
{
|
|
|
|
$domain = array(
|
|
|
|
'domain' => $domain,
|
|
|
|
'config_user' => $config_user,
|
|
|
|
'config_passwd' => $config_passwd,
|
|
|
|
'admin_user' => $admin_user,
|
|
|
|
'admin_password' => $admin_password,
|
|
|
|
'admin_firstname' => $admin_firstname,
|
|
|
|
'admin_lastname' => $admin_lastname,
|
|
|
|
'admin_email' => $admin_email,
|
|
|
|
'config' => $config,
|
2008-11-23 17:46:32 +01:00
|
|
|
'lang' => $lang,
|
2007-12-13 03:41:55 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
//echo __CLASS__.'::__construct()'; _debug_array($domain);
|
|
|
|
admin_cmd::__construct($domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* run the command: create eGW admin and standard groups
|
2008-11-23 17:46:32 +01:00
|
|
|
*
|
2016-05-01 17:56:49 +02:00
|
|
|
* @param boolean $check_only =false only run the checks (and throw the exceptions), but not the command itself
|
2007-12-13 03:41:55 +01:00
|
|
|
* @return string success message
|
|
|
|
* @throws Exception(lang('Wrong credentials to access the header.inc.php file!'),2);
|
|
|
|
* @throws Exception('header.inc.php not found!');
|
|
|
|
*/
|
|
|
|
protected function exec($check_only=false)
|
|
|
|
{
|
|
|
|
if ($check_only && $this->remote_id)
|
|
|
|
{
|
|
|
|
return true; // can only check locally
|
|
|
|
}
|
|
|
|
$this->check_installed($this->domain,15);
|
|
|
|
|
|
|
|
if (!$this->admin_firstname) $this->set_defaults['admin_firstname'] = $this->admin_firstname = lang('Admin');
|
|
|
|
if (!$this->admin_lastname) $this->set_defaults['admin_lastname'] = $this->admin_lastname = lang('User');
|
2014-09-09 20:07:39 +02:00
|
|
|
if (strpos($this->admin_email,'$') !== false)
|
2010-08-20 21:28:08 +02:00
|
|
|
{
|
|
|
|
$this->set_defaults['email'] = $this->admin_email = str_replace(
|
|
|
|
array('$domain','$uid','$account_lid'),
|
|
|
|
array($this->domain,$this->admin_user,$this->admin_user),$this->admin_email);
|
|
|
|
}
|
2007-12-13 03:41:55 +01:00
|
|
|
$_POST['username'] = $this->admin_user;
|
|
|
|
$_POST['passwd2'] = $_POST['passwd'] = $this->admin_password;
|
|
|
|
$_POST['fname'] = $this->admin_firstname;
|
|
|
|
$_POST['lname'] = $this->admin_lastname;
|
|
|
|
$_POST['email'] = $this->admin_email;
|
2008-11-23 17:46:32 +01:00
|
|
|
$_POST['ConfigLang'] = $this->lang;
|
|
|
|
|
2007-12-13 03:41:55 +01:00
|
|
|
$_POST['submit'] = true;
|
|
|
|
$error = include(dirname(__FILE__).'/../admin_account.php');
|
|
|
|
|
|
|
|
$this->restore_db();
|
|
|
|
|
|
|
|
switch ($error)
|
|
|
|
{
|
|
|
|
case 41:
|
2016-05-01 17:56:49 +02:00
|
|
|
throw new Api\Exception\WrongUserinput(lang('Error in admin-creation !!!'),41);
|
2007-12-13 03:41:55 +01:00
|
|
|
case 42:
|
2016-05-01 17:56:49 +02:00
|
|
|
throw new Api\Exception\WrongUserinput(lang('Error in group-creation !!!'),42);
|
2007-12-13 03:41:55 +01:00
|
|
|
}
|
|
|
|
$this->restore_db();
|
2014-09-09 20:07:39 +02:00
|
|
|
|
2016-05-01 17:56:49 +02:00
|
|
|
// run admin/admin-cli.php --add-user to store the new Api\Accounts once in EGroupware
|
2010-08-20 21:28:08 +02:00
|
|
|
// to run all hooks (some of them can NOT run inside setup)
|
2010-08-20 22:28:59 +02:00
|
|
|
$cmd = EGW_SERVER_ROOT.'/admin/admin-cli.php --add-user '.
|
2010-08-20 21:28:08 +02:00
|
|
|
escapeshellarg($this->admin_user.'@'.$this->domain.','.$this->admin_password.','.$this->admin_user);
|
2014-09-09 20:07:39 +02:00
|
|
|
if (php_sapi_name() !== 'cli' || !file_exists(EGW_SERVER_ROOT.'/stylite') || file_exists(EGW_SERVER_ROOT.'/managementserver'))
|
|
|
|
{
|
2016-05-01 17:56:49 +02:00
|
|
|
$output = $ret = null;
|
2014-09-09 20:07:39 +02:00
|
|
|
exec($cmd,$output,$ret);
|
|
|
|
}
|
2010-08-20 21:28:08 +02:00
|
|
|
$output = implode("\n",$output);
|
|
|
|
//echo "ret=$ret\n".$output;
|
|
|
|
if ($ret)
|
|
|
|
{
|
2016-05-01 17:56:49 +02:00
|
|
|
throw new Api\Exception ($output,$ret);
|
2010-08-20 21:28:08 +02:00
|
|
|
}
|
2007-12-13 03:41:55 +01:00
|
|
|
return lang('Admin account successful created.');
|
|
|
|
}
|
|
|
|
}
|