mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-24 23:58:54 +01:00
added draft of an exception class for eGW, plus a global exception handler and replaced the fatal errors in the db-class plus the application rights check in the egw object with exceptions, modified the exceptions in admin_cmd* to use egw_excpetion*, instead just Exception
This commit is contained in:
parent
1fdebc6582
commit
cae8bb40a8
@ -48,6 +48,9 @@ $GLOBALS['egw_info'] = array(
|
||||
|
||||
include('../header.inc.php');
|
||||
|
||||
// set our own exception handler, to not get the html from eGW's default one
|
||||
set_exception_handler('admin_cli_exception_handler');
|
||||
|
||||
switch($action)
|
||||
{
|
||||
case '--edit-user':
|
||||
@ -143,21 +146,9 @@ function run_command(admin_cmd $cmd)
|
||||
}
|
||||
}
|
||||
//_debug_array($cmd);
|
||||
$msg = $cmd->run($time,true,$skip_checks);
|
||||
print_r($cmd->run($time,true,$skip_checks));
|
||||
echo "\n";
|
||||
|
||||
if ($cmd->errno)
|
||||
{
|
||||
fail($cmd->errno,$cmd->error);
|
||||
}
|
||||
if (($value = unserialize($msg)) !== false && $msg !== serialize(false))
|
||||
{
|
||||
print_r($value);
|
||||
echo "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $msg."\n\n";
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -374,10 +365,10 @@ function do_change_account_id($args)
|
||||
* @param int $exit_code
|
||||
* @param string $message
|
||||
*/
|
||||
function fail($exit_code,$message)
|
||||
function admin_cli_exception_handler(Exception $e)
|
||||
{
|
||||
echo $message."\n";
|
||||
exit($exit_code);
|
||||
echo $e->getMessage()."\n";
|
||||
exit($e->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,6 +376,8 @@ function fail($exit_code,$message)
|
||||
*
|
||||
* The list is generated by "greping" this file for calls to the fail() function.
|
||||
* Calls to fail() have to be in one line, to be recogniced!
|
||||
*
|
||||
* @ToDo adapt it to the exceptions
|
||||
*/
|
||||
function list_exit_codes()
|
||||
{
|
||||
@ -416,7 +409,7 @@ function do_subscribe_other($account_lid,$pw=null)
|
||||
{
|
||||
if (!($account_id = $GLOBALS['egw']->accounts->name2id($account_lid)))
|
||||
{
|
||||
fail(15,lang("Unknown account: %1 !!!",$account_lid));
|
||||
throw new egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$account_lid),15);
|
||||
}
|
||||
$GLOBALS['egw_info']['user'] = array(
|
||||
'account_id' => $account_id,
|
||||
|
@ -132,7 +132,8 @@ abstract class admin_cmd
|
||||
* @param int $time=null timestamp to run the command or null to run it immediatly
|
||||
* @param boolean $set_modifier=null should the current user be set as modifier, default true
|
||||
* @param booelan $skip_checks=false do not yet run the checks for a scheduled command
|
||||
* @return mixed string with execution error or success message, false for other errors
|
||||
* @return mixed return value of the command
|
||||
* @throws Exceptions on error
|
||||
*/
|
||||
function run($time=null,$set_modifier=true,$skip_checks=false)
|
||||
{
|
||||
@ -176,7 +177,11 @@ abstract class admin_cmd
|
||||
}
|
||||
if (!$dont_save && !$this->save($set_modifier))
|
||||
{
|
||||
return false;
|
||||
throw new egw_exception_db(lang('Error saving the command!'));
|
||||
}
|
||||
if ($e instanceof Exception)
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
@ -201,7 +206,7 @@ abstract class admin_cmd
|
||||
|
||||
if (!($remote = admin_cmd::$remote->read($this->remote_id)))
|
||||
{
|
||||
throw new Exception(lang('Invalid remote id or name "%1"!',$id_or_name),997);
|
||||
throw new egw_exception_wrong_userinput(lang('Invalid remote id or name "%1"!',$id_or_name),997);
|
||||
}
|
||||
if (!$this->uid)
|
||||
{
|
||||
@ -227,11 +232,15 @@ abstract class admin_cmd
|
||||
$message = file_get_contents($url, false, stream_context_create($opts));
|
||||
//echo "got: $message\n";
|
||||
|
||||
if (($value = unserialize($message)) !== false && $message !== serialize(false))
|
||||
{
|
||||
$message = $value;
|
||||
}
|
||||
$message = $GLOBALS['egw']->translation->convert($message,'utf-8');
|
||||
|
||||
if (preg_match('/^([0-9]+) (.*)$/',$message,$matches))
|
||||
if (is_string($message) && preg_match('/^([0-9]+) (.*)$/',$message,$matches))
|
||||
{
|
||||
throw new Exception($matches[2],(int)$matches[1]);
|
||||
throw new egw_exception($matches[2],(int)$matches[1]);
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
@ -318,8 +327,7 @@ abstract class admin_cmd
|
||||
* @static
|
||||
* @param array $data
|
||||
* @return admin_cmd
|
||||
* @throws Exception(lang('Unknown command %1!',$class),0);
|
||||
* @throws Exception(lang('%1 is no command!',$class),0);
|
||||
* @throws egw_exception_wrong_parameter if class does not exist or is no instance of admin_cmd
|
||||
*/
|
||||
static function instanciate(array $data)
|
||||
{
|
||||
@ -329,7 +337,7 @@ abstract class admin_cmd
|
||||
}
|
||||
if (!class_exists($class = $data['type']))
|
||||
{
|
||||
throw new Exception(lang('Unknown command %1!',$class),0);
|
||||
throw new egw_exception_wrong_parameter(lang('Unknown command %1!',$class),0);
|
||||
}
|
||||
$cmd = new $class($data);
|
||||
|
||||
@ -337,7 +345,7 @@ abstract class admin_cmd
|
||||
{
|
||||
return $cmd;
|
||||
}
|
||||
throw new Exception(lang('%1 is no command!',$class),0);
|
||||
throw new egw_exception_wrong_parameter(lang('%1 is no command!',$class),0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -455,7 +463,7 @@ abstract class admin_cmd
|
||||
*
|
||||
* @param string $extra_acl=null further admin rights to check, eg. 'account_access'
|
||||
* @param int $extra_deny=null further admin rights to check, eg. 16 = deny edit accounts
|
||||
* @throws Exception(lang("Permission denied !!!"),2);
|
||||
* @throws egw_exception_no_admin
|
||||
*/
|
||||
protected function _check_admin($extra_acl=null,$extra_deny=null)
|
||||
{
|
||||
@ -466,7 +474,7 @@ abstract class admin_cmd
|
||||
if (!admin_cmd::$acl->check('run',1,'admin') && // creator is no longer admin
|
||||
$extra_acl && $extra_deny && admin_cmd::$acl->check($extra_acl,$extra_deny,'admin')) // creator is explicitly forbidden to do something
|
||||
{
|
||||
throw new Exception(lang("Permission denied !!!"),2);
|
||||
throw new egw_exception_no_permission_admin();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -476,7 +484,7 @@ abstract class admin_cmd
|
||||
*
|
||||
* @param array $apps names, titles or localised names
|
||||
* @return array of app-names
|
||||
* @throws Exception(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
* @throws egw_exception_wrong_userinput lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8
|
||||
*/
|
||||
static function parse_apps(array $apps)
|
||||
{
|
||||
@ -495,7 +503,7 @@ abstract class admin_cmd
|
||||
}
|
||||
if (!isset($GLOBALS['egw_info']['apps'][$name]))
|
||||
{
|
||||
throw new Exception(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
throw new egw_exception_wrong_userinput(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
}
|
||||
}
|
||||
return $apps;
|
||||
@ -507,8 +515,8 @@ abstract class admin_cmd
|
||||
* @param string/int $account account_id or account_lid
|
||||
* @param boolean $allow_only_user=null true=only user, false=only groups, default both
|
||||
* @return int/array account_id
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$account),15);
|
||||
* @throws Exception(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')),15);
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')),15);
|
||||
*/
|
||||
static function parse_account($account,$allow_only_user=null)
|
||||
{
|
||||
@ -517,11 +525,11 @@ abstract class admin_cmd
|
||||
if (!($type = admin_cmd::$accounts->exists($account)) ||
|
||||
!is_numeric($id=$account) && !($id = admin_cmd::$accounts->name2id($account)))
|
||||
{
|
||||
throw new Exception(lang("Unknown account: %1 !!!",$account),15);
|
||||
throw new egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$account),15);
|
||||
}
|
||||
if (!is_null($allow_only_user) && $allow_only_user !== ($type == 1))
|
||||
{
|
||||
throw new Exception(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')),15);
|
||||
throw new egw_exception_wrong_userinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only_user?lang('user'):lang('group')),15);
|
||||
}
|
||||
if ($type == 2 && $id > 0) $id = -$id; // groups use negative id's internally, fix it, if user given the wrong sign
|
||||
|
||||
@ -534,8 +542,8 @@ abstract class admin_cmd
|
||||
* @param string/int/array $accounts array or comma-separated account_id's or account_lid's
|
||||
* @param boolean $allow_only_user=null true=only user, false=only groups, default both
|
||||
* @return array of account_id's or null if none specified
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$account),15);
|
||||
* @throws Exception(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only?lang('user'):lang('group')),15);
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang("Wrong account type: %1 is NO %2 !!!",$account,$allow_only?lang('user'):lang('group')),15);
|
||||
*/
|
||||
static function parse_accounts($accounts,$allow_only_user=null)
|
||||
{
|
||||
@ -554,7 +562,7 @@ abstract class admin_cmd
|
||||
*
|
||||
* @param string $date
|
||||
* @return int timestamp
|
||||
* @throws Exception(lang('Invalid formated date "%1"!',$datein),6);
|
||||
* @throws egw_exception_wrong_userinput(lang('Invalid formated date "%1"!',$datein),6);
|
||||
*/
|
||||
static function parse_date($date)
|
||||
{
|
||||
@ -566,7 +574,7 @@ abstract class admin_cmd
|
||||
|
||||
if (($date = strtotime($date)) === false)
|
||||
{
|
||||
throw new Exception(lang('Invalid formated date "%1"!',$datein),6);
|
||||
throw new egw_exception_wrong_userinput(lang('Invalid formated date "%1"!',$datein),6);
|
||||
}
|
||||
}
|
||||
return (int)$date;
|
||||
@ -578,7 +586,7 @@ abstract class admin_cmd
|
||||
* @param string $value
|
||||
* @param boolean $default=null
|
||||
* @return boolean
|
||||
* @throws Exception(lang('Invalid value "%1" use yes or no!',$value),998);
|
||||
* @throws egw_exception_wrong_userinput(lang('Invalid value "%1" use yes or no!',$value),998);
|
||||
*/
|
||||
static function parse_boolean($value,$default=null)
|
||||
{
|
||||
@ -594,7 +602,7 @@ abstract class admin_cmd
|
||||
{
|
||||
return false;
|
||||
}
|
||||
throw new Exception(lang('Invalid value "%1" use yes or no!',$value),998);
|
||||
throw new egw_exception_wrong_userinput(lang('Invalid value "%1" use yes or no!',$value),998);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -602,7 +610,7 @@ abstract class admin_cmd
|
||||
*
|
||||
* @param string $id_or_name
|
||||
* @return int remote_id
|
||||
* @throws Exception(lang('Invalid remote id or name "%1"!',$id_or_name),997);
|
||||
* @throws egw_exception_wrong_userinput(lang('Invalid remote id or name "%1"!',$id_or_name),997);
|
||||
*/
|
||||
static function parse_remote($id_or_name)
|
||||
{
|
||||
@ -614,7 +622,7 @@ abstract class admin_cmd
|
||||
'remote_domain' => $id_or_name,
|
||||
),true,'','','',false,'OR')) || count($remotes) != 1)
|
||||
{
|
||||
throw new Exception(lang('Invalid remote id or name "%1"!',$id_or_name),997);
|
||||
throw new egw_exception_wrong_userinput(lang('Invalid remote id or name "%1"!',$id_or_name),997);
|
||||
}
|
||||
return $remotes[0]['remote_id'];
|
||||
}
|
||||
@ -623,7 +631,7 @@ abstract class admin_cmd
|
||||
* Instanciated accounts class
|
||||
*
|
||||
* @todo accounts class instanciation for setup
|
||||
* @throws Exception(lang('%1 class not instanciated','accounts'),999);
|
||||
* @throws egw_exception_assertion_failed(lang('%1 class not instanciated','accounts'),999);
|
||||
*/
|
||||
protected function _instanciate_accounts()
|
||||
{
|
||||
@ -631,7 +639,7 @@ abstract class admin_cmd
|
||||
{
|
||||
if (!is_object($GLOBALS['egw']->accounts))
|
||||
{
|
||||
throw new Exception(lang('%1 class not instanciated','accounts'),999);
|
||||
throw new egw_exception_assertion_failed(lang('%1 class not instanciated','accounts'),999);
|
||||
}
|
||||
admin_cmd::$accounts = $GLOBALS['egw']->accounts;
|
||||
}
|
||||
@ -642,7 +650,7 @@ abstract class admin_cmd
|
||||
*
|
||||
* @todo acl class instanciation for setup
|
||||
* @param int $account=null account_id the class needs to be instanciated for, default need only account-independent methods
|
||||
* @throws Exception(lang('%1 class not instanciated','acl'),999);
|
||||
* @throws egw_exception_assertion_failed(lang('%1 class not instanciated','acl'),999);
|
||||
*/
|
||||
protected function _instanciate_acl($account=null)
|
||||
{
|
||||
@ -650,7 +658,7 @@ abstract class admin_cmd
|
||||
{
|
||||
if (!is_object($GLOBALS['egw']->acl))
|
||||
{
|
||||
throw new Exception(lang('%1 class not instanciated','acl'),999);
|
||||
throw new egw_exception_assertion_failed(lang('%1 class not instanciated','acl'),999);
|
||||
}
|
||||
if ($account && $GLOBALS['egw']->acl->account_id != $account)
|
||||
{
|
||||
@ -822,14 +830,14 @@ abstract class admin_cmd
|
||||
}
|
||||
elseif ($data['install_id'] || $data['config_passwd'] || !$data['remote_hash'])
|
||||
{
|
||||
throw new Exception(lang('Either Install ID AND config password needed OR the remote hash!'));
|
||||
throw new egw_exception_wrong_userinput(lang('Either Install ID AND config password needed OR the remote hash!'));
|
||||
}
|
||||
//_debug_array($data);
|
||||
admin_cmd::$remote->init($data);
|
||||
|
||||
if (admin_cmd::$remote->save() != 0)
|
||||
{
|
||||
throw new Exception (lang('Error saving to db:').' '.$this->sql->db->Error.' ('.$this->sql->db->Errno.')',$this->sql->db->Errno);
|
||||
throw new egw_exception_db(lang('Error saving to db:').' '.$this->sql->db->Error.' ('.$this->sql->db->Errno.')',$this->sql->db->Errno);
|
||||
}
|
||||
return admin_cmd::$remote->data['remote_id'];
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ class admin_cmd_account_app extends admin_cmd
|
||||
*
|
||||
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang("Permission denied !!!"),2)
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws Exception(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
* @throws egw_exception_no_admin
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
|
@ -181,9 +181,9 @@ class admin_cmd_change_account_id extends admin_cmd
|
||||
*
|
||||
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang("Permission denied !!!"),2)
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws Exception(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
* @throws egw_exception_no_admin
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8);
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
@ -191,7 +191,7 @@ class admin_cmd_change_account_id extends admin_cmd
|
||||
{
|
||||
if (!(int)$from || !(int)$to)
|
||||
{
|
||||
throw new Exception (lang("Account-id's have to be integers!"),16);
|
||||
throw new egw_exception_wrong_userinput(lang("Account-id's have to be integers!"),16);
|
||||
}
|
||||
}
|
||||
if ($check_only) return true;
|
||||
|
@ -38,9 +38,9 @@ class admin_cmd_change_pw extends admin_cmd
|
||||
*
|
||||
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang("Permission denied !!!"),2)
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws Exception(lang('Error changing the password for %1 !!!',$this->account),99);
|
||||
* @throws egw_exception_no_admin
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang('Error changing the password for %1 !!!',$this->account),99);
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
|
@ -40,9 +40,9 @@ class admin_cmd_delete_account extends admin_cmd
|
||||
*
|
||||
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang("Permission denied !!!"),2)
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws Exception(lang('Error changing the password for %1 !!!',$this->account),99);
|
||||
* @throws egw_exception_no_admin
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang('Error changing the password for %1 !!!',$this->account),99);
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
|
@ -38,8 +38,8 @@ class admin_cmd_edit_group extends admin_cmd
|
||||
*
|
||||
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang("Permission denied !!!"),2)
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws egw_exception_no_admin
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
@ -64,16 +64,16 @@ class admin_cmd_edit_group extends admin_cmd
|
||||
}
|
||||
if (!$data['account_lid'] && (!$this->account || !is_null($data['account_lid'])))
|
||||
{
|
||||
throw new Exception(lang('You must enter a group name.'),9);
|
||||
throw new egw_exception_wrong_userinput(lang('You must enter a group name.'),9);
|
||||
}
|
||||
if (!is_null($data['account_lid']) && ($id = admin_cmd::$accounts->name2id($data['account_lid'],'account_lid','g')) &&
|
||||
$id !== $data['account_id'])
|
||||
{
|
||||
throw new Exception(lang('That loginid has already been taken'),999);
|
||||
throw new egw_exception_wrong_userinput(lang('That loginid has already been taken'),999);
|
||||
}
|
||||
if (!$data['account_members'] && !$this->account)
|
||||
{
|
||||
throw new Exception(lang('You must select at least one group member.'),9);
|
||||
throw new egw_exception_wrong_userinput(lang('You must select at least one group member.'),9);
|
||||
}
|
||||
if ($data['account_members'])
|
||||
{
|
||||
@ -85,7 +85,7 @@ class admin_cmd_edit_group extends admin_cmd
|
||||
{
|
||||
if (!($old = admin_cmd::$accounts->read($data['account_id'])))
|
||||
{
|
||||
throw new Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
throw new egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
}
|
||||
// as the current account class always sets all values, we have to add the not specified ones
|
||||
foreach($data as $name => &$value)
|
||||
@ -96,7 +96,7 @@ class admin_cmd_edit_group extends admin_cmd
|
||||
if (!($data['account_id'] = admin_cmd::$accounts->save($data)))
|
||||
{
|
||||
//_debug_array($data);
|
||||
throw new Exception(lang("Error saving account!"),11);
|
||||
throw new egw_exception_db(lang("Error saving account!"),11);
|
||||
}
|
||||
$GLOBALS['hook_values'] =& $data;
|
||||
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
|
||||
|
@ -40,9 +40,9 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
|
||||
*
|
||||
* @param boolean $check_only=false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang("Permission denied !!!"),2)
|
||||
* @throws Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws Exception(lang('Error changing the password for %1 !!!',$this->account),99);
|
||||
* @throws egw_exception_no_admin
|
||||
* @throws egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
* @throws egw_exception_wrong_userinput(lang('Error changing the password for %1 !!!',$this->account),99);
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
@ -60,20 +60,20 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
|
||||
}
|
||||
if (!$data['account_lid'] && (!$this->account || !is_null($data['account_lid'])))
|
||||
{
|
||||
throw new Exception(lang('You must enter a loginid'),9);
|
||||
throw new egw_exception_wrong_userinput(lang('You must enter a loginid'),9);
|
||||
}
|
||||
if (!$data['account_lastname'] && (!$this->account || !is_null($data['account_lastname'])))
|
||||
{
|
||||
throw new Exception(lang('You must enter a lastname'),9);
|
||||
throw new egw_exception_wrong_userinput(lang('You must enter a lastname'),9);
|
||||
}
|
||||
if (!is_null($data['account_lid']) && ($id = admin_cmd::$accounts->name2id($data['account_lid'],'account_lid','u')) &&
|
||||
$id !== $data['account_id'])
|
||||
{
|
||||
throw new Exception(lang('That loginid has already been taken'),999);
|
||||
throw new egw_exception_wrong_userinput(lang('That loginid has already been taken'),999);
|
||||
}
|
||||
if (isset($data['account_passwd_2']) && $data['account_passwd'] != $data['account_passwd_2'])
|
||||
{
|
||||
throw new Exception(lang('The two passwords are not the same'),0);
|
||||
throw new egw_exception_wrong_userinput(lang('The two passwords are not the same'),0);
|
||||
}
|
||||
$data['account_expires'] = $expires = self::_parse_expired($data['account_expires'],(boolean)$this->account);
|
||||
$data['account_status'] = is_null($expires) ? null : ($expires == -1 || $expires > time() ? 'A' : '');
|
||||
@ -111,7 +111,7 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
|
||||
{
|
||||
if (!($old = admin_cmd::$accounts->read($data['account_id'])))
|
||||
{
|
||||
throw new Exception(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
throw new egw_exception_wrong_userinput(lang("Unknown account: %1 !!!",$this->account),15);
|
||||
}
|
||||
// as the current account class always sets all values, we have to add the not specified ones
|
||||
foreach($data as $name => &$value)
|
||||
@ -122,7 +122,7 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
|
||||
if (!($data['account_id'] = admin_cmd::$accounts->save($data)))
|
||||
{
|
||||
//_debug_array($data);
|
||||
throw new Exception(lang("Error saving account!"),11);
|
||||
throw new egw_exception_db(lang("Error saving account!"),11);
|
||||
}
|
||||
if ($data['account_groups'])
|
||||
{
|
||||
@ -183,7 +183,7 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
|
||||
* @param string $str date, 'never', 'already' or '' (=dont change, or default of never of new accounts)
|
||||
* @param boolean $exists
|
||||
* @return int timestamp, 0 for already, -1 for never or null for dont change
|
||||
* @throws Exception(lang('Invalid formated date "%1"!',$datein),6);
|
||||
* @throws egw_exception_wrong_userinput(lang('Invalid formated date "%1"!',$datein),6);
|
||||
*/
|
||||
private function _parse_expired($str,$existing)
|
||||
{
|
||||
|
@ -85,6 +85,13 @@ try {
|
||||
$cmd = admin_cmd::instanciate($data);
|
||||
//_debug_array($cmd); exit;
|
||||
$success_msg = $cmd->run();
|
||||
|
||||
$GLOBALS['egw']->translation->convert($success_msg,$GLOBALS['egw']->translation->charset(),'utf-8');
|
||||
|
||||
if (!is_string($success_msg))
|
||||
{
|
||||
$success_msg = serialize($success_msg);
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
header('HTTP/1.1 200 '.$e->getMessage());
|
||||
@ -107,6 +114,7 @@ function exit_with_status($cmd,$success_msg='Successful')
|
||||
// fall through
|
||||
case admin_cmd::successful:
|
||||
header('HTTP/1.1 200 '.$cmd->stati[$cmd->status]);
|
||||
header('Content-type: text/plain; charset=utf-8');
|
||||
echo $success_msg;
|
||||
}
|
||||
$GLOBALS['egw']->common->egw_exit();
|
||||
|
@ -338,9 +338,18 @@
|
||||
if ($GLOBALS['egw_info']['flags']['currentapp'] != 'about')
|
||||
{
|
||||
// This will need to use ACL in the future
|
||||
if (!$GLOBALS['egw_info']['user']['apps'][$GLOBALS['egw_info']['flags']['currentapp']] ||
|
||||
if (!$GLOBALS['egw_info']['user']['apps'][$currentapp = $GLOBALS['egw_info']['flags']['currentapp']] ||
|
||||
($GLOBALS['egw_info']['flags']['admin_only'] && !$GLOBALS['egw_info']['user']['apps']['admin']))
|
||||
{
|
||||
if ($currentapp == 'admin' || $GLOBALS['egw_info']['flags']['admin_only'])
|
||||
{
|
||||
throw new egw_exception_no_permission_admin();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new egw_exception_no_permission_app($currentapp);
|
||||
}
|
||||
// old code no longer called
|
||||
$this->common->egw_header();
|
||||
if ($GLOBALS['egw_info']['flags']['nonavbar'])
|
||||
{
|
||||
|
@ -188,6 +188,8 @@
|
||||
* @param string $Port database port to connect to (optional)
|
||||
* @param string $User name of database user (optional)
|
||||
* @param string $Password password for database user (optional)
|
||||
* @param string $Type type of database (optional)
|
||||
* @return ADONewConnection
|
||||
*/
|
||||
function connect($Database = NULL, $Host = NULL, $Port = NULL, $User = NULL, $Password = NULL,$Type = NULL)
|
||||
{
|
||||
@ -285,7 +287,7 @@
|
||||
!dl(PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX)))
|
||||
{
|
||||
$this->halt("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!");
|
||||
return 0; // in case error-reporting = 'no'
|
||||
return null; // in case error-reporting = 'no'
|
||||
}
|
||||
if (!is_object($GLOBALS['egw']->ADOdb)) // use the global object to store the connection
|
||||
{
|
||||
@ -299,7 +301,7 @@
|
||||
if (!$this->Link_ID)
|
||||
{
|
||||
$this->halt("No ADOdb support for '$type' ($this->Type) !!!");
|
||||
return 0; // in case error-reporting = 'no'
|
||||
return null; // in case error-reporting = 'no'
|
||||
}
|
||||
$connect = $GLOBALS['egw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect';
|
||||
if (($Ok = $this->Link_ID->$connect($Host, $User, $Password)))
|
||||
@ -314,7 +316,7 @@
|
||||
if (!$Ok)
|
||||
{
|
||||
$this->halt("ADOdb::$connect($Host, $User, \$Password, $Database) failed.");
|
||||
return 0; // in case error-reporting = 'no'
|
||||
return null; // in case error-reporting = 'no'
|
||||
}
|
||||
if ($this->Debug)
|
||||
{
|
||||
@ -838,6 +840,10 @@
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($this->Halt_On_Error == 'yes')
|
||||
{
|
||||
throw new egw_exception_db($msg.($this->Error?":\n".$this->Error:''),$this->Errno);
|
||||
}
|
||||
$this->haltmsg($msg);
|
||||
|
||||
if ($file)
|
||||
|
@ -1293,4 +1293,68 @@
|
||||
return $GLOBALS['egw']->translation->translate($key,$vars);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* php5 autoload function for eGroupWare understanding the following naming schema:
|
||||
* 1. new (prefered) nameing schema: app_class_something loading app/inc/class.class_something.inc.php
|
||||
* 2. API classes: classname loading phpgwapi/inc/class.classname.inc.php
|
||||
* 2a.API classes containing multiple classes per file eg. egw_exception* in class.egw_exception.inc.php
|
||||
* 3. eTemplate classes: classname loading etemplate/inc/class.classname.inc.php
|
||||
* 4. classes of the current app: classname loading $GLOBALS['egw_info']['flags']['currentapp']/inc/class.classname.inc.php
|
||||
*
|
||||
* @param string $class name of class to load
|
||||
*/
|
||||
function __autoload($class)
|
||||
{
|
||||
list($app,$baseclass) = explode('_',$class);
|
||||
|
||||
// classes using the new naming schema app_class_name, eg. admin_cmd
|
||||
if (file_exists($file = EGW_INCLUDE_ROOT.'/'.$app.'/inc/class.'.$class.'.inc.php') ||
|
||||
// classes using the new naming schema app_class_name, eg. admin_cmd
|
||||
file_exists($file = EGW_INCLUDE_ROOT.'/'.$app.'/inc/class.'.$app.'_'.$baseclass.'.inc.php') ||
|
||||
// eGW api classes using the old naming schema, eg. html
|
||||
file_exists($file = EGW_API_INC.'/class.'.$class.'.inc.php') ||
|
||||
// eGW api classes using the old naming schema, eg. html
|
||||
file_exists($file = EGW_API_INC.'/class.'.$app.'_'.$baseclass.'.inc.php') ||
|
||||
// eGW eTemplate classes using the old naming schema, eg. etemplate
|
||||
file_exists($file = EGW_INCLUDE_ROOT.'/etemplate/inc/class.'.$class.'.inc.php') ||
|
||||
// classes of the current application using the old naming schema
|
||||
file_exists($file = EGW_INCLUDE_ROOT.'/'.$GLOBALS['egw_info']['flags']['currentapp'].'/inc/class.'.$class.'.inc.php'))
|
||||
{
|
||||
//error_log("autoloaded class $class from $file");
|
||||
include_once($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail a little bit more gracefully then an uncought exception
|
||||
*
|
||||
* Does NOT return
|
||||
*
|
||||
* @param Exception $e
|
||||
*/
|
||||
function egw_exception_handler(Exception $e)
|
||||
{
|
||||
if ($e instanceof egw_exception_no_permission)
|
||||
{
|
||||
$headline = lang('Permission denied!');
|
||||
}
|
||||
elseif ($e instanceof egw_exception_db)
|
||||
{
|
||||
$headline = lang('Database error');
|
||||
}
|
||||
else
|
||||
{
|
||||
$headline = lang('An error happend');
|
||||
}
|
||||
$GLOBALS['egw']->framework->render(
|
||||
'<h3>'.$headline."</h3>\n".
|
||||
'<pre><b>'.$e->getMessage()."</b>\n\n".
|
||||
$e->getTraceAsString()."</pre>\n".
|
||||
'<p><a href="'.$GLOBALS['egw']->link('/index.php').'">'.lang('Click here to resume your eGroupWare Session.').'</a>',
|
||||
$headline);
|
||||
|
||||
$GLOBALS['egw']->common->egw_exit();
|
||||
}
|
||||
|
||||
set_exception_handler('egw_exception_handler');
|
||||
|
@ -208,30 +208,3 @@ if ($GLOBALS['egw_info']['server']['sessions_type'] == 'php4-restore' && $GLOBAL
|
||||
}
|
||||
$_SESSION['egw_object_cache'] = serialize($GLOBALS['egw']);
|
||||
}
|
||||
|
||||
/**
|
||||
* php5 autoload function for eGroupWare understanding the following naming schema:
|
||||
* 1. new (prefered) nameing schema: app_class_something loading app/inc/class.class_something.inc.php
|
||||
* 2. API classe: classname loading phpgwapi/inc/class.classname.inc.php
|
||||
* 3. eTemplate classes: classname loading etemplate/inc/class.classname.inc.php
|
||||
* 4. classes of the current app: classname loading $GLOBALS['egw_info']['flags']['currentapp']/inc/class.classname.inc.php
|
||||
*
|
||||
* @param string $class name of class to load
|
||||
*/
|
||||
function __autoload($class)
|
||||
{
|
||||
list($app) = explode('_',$class);
|
||||
|
||||
// classes using the new naming schema app_class_name, eg. admin_cmd
|
||||
if (file_exists($file = EGW_INCLUDE_ROOT.'/'.$app.'/inc/class.'.$class.'.inc.php') ||
|
||||
// eGW api classes using the old naming schema, eg. html
|
||||
file_exists($file = EGW_API_INC.'/inc/class.'.$class.'.inc.php') ||
|
||||
// eGW eTemplate classes using the old naming schema, eg. etemplate
|
||||
file_exists($file = EGW_INCLUDE_ROOT.'/etemplate/inc/class.'.$class.'.inc.php') ||
|
||||
// classes of the current application using the old naming schema
|
||||
file_exists($file = EGW_INCLUDE_ROOT.'/'.$GLOBALS['egw_info']['flags']['currentapp'].'/inc/class.'.$class.'.inc.php'))
|
||||
{
|
||||
//error_log("autoloaded class $class from $file");
|
||||
include_once($file);
|
||||
}
|
||||
}
|
@ -62,16 +62,60 @@ class setup_cmd_showheader extends setup_cmd
|
||||
|
||||
// include the api version of this instance
|
||||
$GLOBALS['egw_info']['server']['versions']['phpgwapi'] = $egw_info_backup['server']['versions']['phpgwapi'];
|
||||
|
||||
$ret = serialize(array(
|
||||
|
||||
// fetching the install id's stored in the database
|
||||
foreach($GLOBALS['egw_domain'] as $domain => &$data)
|
||||
{
|
||||
$data += $this->_fetch_config($data);
|
||||
}
|
||||
$ret = array(
|
||||
'egw_info' => $GLOBALS['egw_info'],
|
||||
'egw_domain' => $GLOBALS['egw_domain'],
|
||||
'EGW_SERVER_ROOT' => EGW_SERVER_ROOT,
|
||||
'EGW_INCLUDE_ROOT' => EGW_INCLUDE_ROOT,
|
||||
));
|
||||
);
|
||||
|
||||
$GLOBALS['egw_info'] = $egw_info_backup;
|
||||
|
||||
// restoring the db connection, seems to be necessary when we run via remote execution
|
||||
$GLOBALS['egw']->db->disconnect();
|
||||
$GLOBALS['egw']->db->connect();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the install_id, and webserver_url of a domain from the DB
|
||||
*
|
||||
* @param array $data with values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type'
|
||||
* @return array with values for keys install_id, webserver_url
|
||||
*/
|
||||
private function _fetch_config(array $data)
|
||||
{
|
||||
$db = new egw_db();
|
||||
|
||||
ob_start(); // not available db connection echos a lot grab ;-)
|
||||
$err_rep = error_reporting(0);
|
||||
|
||||
$config = array();
|
||||
try {
|
||||
$db->connect($data['db_name'],$data['db_host'],$data['db_port'],$data['db_user'],$data['db_pass'],$data['db_type']);
|
||||
$db->set_app('phpgwapi');
|
||||
$db->select('egw_config','config_name,config_value',array(
|
||||
'config_name'=>array('install_id','webserver_url'),
|
||||
'config_app'=>'phpgwapi',
|
||||
),__LINE__,__FILE__);
|
||||
while (($row = $db->row(true)))
|
||||
{
|
||||
$config[$row['config_name']] = $row['config_value'];
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$config['error'] = strip_tags($e->getMessage());
|
||||
}
|
||||
error_reporting($err_rep);
|
||||
ob_end_clean();
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user