* Admin: fix fatal error in admin >> bulk password reset

This commit is contained in:
Ralf Becker 2014-11-20 13:54:03 +00:00
parent a71d0d7a80
commit df39e04e95
5 changed files with 40 additions and 267 deletions

View File

@ -5,7 +5,7 @@
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package admin * @package admin
* @copyright (c) 2011 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2011-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
*/ */
@ -105,6 +105,7 @@ class admin_passwordreset
} }
$change_pw = $content['random_pw'] || $content['hash'] && $content['hash'] != $current_hash; $change_pw = $content['random_pw'] || $content['hash'] && $content['hash'] != $current_hash;
$changed = array(); $changed = array();
$emailadmin = null;
foreach($content['users'] as $account_id) foreach($content['users'] as $account_id)
{ {
if (($account = $GLOBALS['egw']->accounts->read($account_id))) if (($account = $GLOBALS['egw']->accounts->read($account_id)))
@ -156,8 +157,12 @@ class admin_passwordreset
{ {
if (!isset($emailadmin)) if (!isset($emailadmin))
{ {
$emailadmin = new emailadmin_bo(); $emailadmin = emailadmin_account::get_default();
$domain = $GLOBALS['egw_info']['server']['mail_suffix']; if (!emailadmin_account::is_multiple($emailadmin))
{
$msg = lang('No default account found!');
break;
}
} }
if (($userData = $emailadmin->getUserData ($account_id))) if (($userData = $emailadmin->getUserData ($account_id)))
{ {
@ -171,11 +176,11 @@ class admin_passwordreset
} }
if (strpos($content['mail']['domain'], '.') !== false) if (strpos($content['mail']['domain'], '.') !== false)
{ {
$userData['mailLocalAddress'] = preg_replace('/@'.preg_quote($domain).'$/', '@'.$content['mail']['domain'], $userData['mailLocalAddress']); $userData['mailLocalAddress'] = preg_replace('/@'.preg_quote($emailadmin->acc_domain).'$/', '@'.$content['mail']['domain'], $userData['mailLocalAddress']);
foreach($userData['mailAlternateAddress'] as &$alias) foreach($userData['mailAlternateAddress'] as &$alias)
{ {
$alias = preg_replace('/@'.preg_quote($domain).'$/', '@'.$content['mail']['domain'], $alias); $alias = preg_replace('/@'.preg_quote($emailadmin->acc_domain).'$/', '@'.$content['mail']['domain'], $alias);
} }
} }
$emailadmin->saveUserData($account_id, $userData); $emailadmin->saveUserData($account_id, $userData);
@ -215,6 +220,7 @@ class admin_passwordreset
} }
catch (phpmailerException $e) catch (phpmailerException $e)
{ {
unset ($e);
$msg .= lang('Notifying account "%1" %2 failed!',$account['account_lid'],$account['account_email']). $msg .= lang('Notifying account "%1" %2 failed!',$account['account_lid'],$account['account_email']).
': '.strip_tags(str_replace('<p>',"\n",$send->ErrorInfo))."\n"; ': '.strip_tags(str_replace('<p>',"\n",$send->ErrorInfo))."\n";
} }
@ -247,7 +253,7 @@ class admin_passwordreset
$GLOBALS['egw_info']['flags']['app_header'] = lang('Bulk password reset'); $GLOBALS['egw_info']['flags']['app_header'] = lang('Bulk password reset');
$tmpl = new etemplate('admin.passwordreset'); $tmpl = new etemplate_new('admin.passwordreset');
$tmpl->exec('admin.admin_passwordreset.index',$content,$sel_options,$readonlys,array( $tmpl->exec('admin.admin_passwordreset.index',$content,$sel_options,$readonlys,array(
'changed' => $changed, 'changed' => $changed,
)); ));

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- $Id$ --> <!-- $Id$ -->
<overlay> <overlay>
<template id="admin.passwordreset" template="" lang="" group="0" version="1.9.001"> <template id="admin.passwordreset" template="" lang="" group="0" version="14.1">
<grid> <grid>
<columns> <columns>
<column/> <column/>
@ -9,11 +9,6 @@
<column/> <column/>
</columns> </columns>
<rows> <rows>
<row disabled="!@msg">
<description id="msg" span="all" class="redItalic"/>
<description/>
<description/>
</row>
<row> <row>
<description value="Select users"/> <description value="Select users"/>
<description/> <description/>
@ -32,7 +27,7 @@
<menulist> <menulist>
<menupopup type="select-bool" label="Can change password" id="changepassword" onchange="var mustchange=document.getElementById(form::name('mustchangepassword')); if (this.value=='0' &amp;&amp; mustchange.value) mustchange.value='0';" options="Leave unchanged"/> <menupopup type="select-bool" label="Can change password" id="changepassword" onchange="var mustchange=document.getElementById(form::name('mustchangepassword')); if (this.value=='0' &amp;&amp; mustchange.value) mustchange.value='0';" options="Leave unchanged"/>
</menulist> </menulist>
<hbox options="0,0"> <hbox>
<menulist> <menulist>
<menupopup label="Change password hash to" id="hash" options="Leave unchanged"/> <menupopup label="Change password hash to" id="hash" options="Leave unchanged"/>
</menulist> </menulist>
@ -52,8 +47,8 @@
<row valign="top"> <row valign="top">
<groupbox> <groupbox>
<caption label="Notification mail"/> <caption label="Notification mail"/>
<textbox blur="Subject" id="subject" size="64"/> <textbox blur="Subject" id="subject" size="64" class="et2_fullWidth"/>
<textbox multiline="true" id="body" rows="15" cols="64"/> <textbox multiline="true" id="body" rows="15" cols="64" class="et2_fullWidth"/>
</groupbox> </groupbox>
<vbox> <vbox>
<description value="Available placeholders" class="gray"/> <description value="Available placeholders" class="gray"/>

View File

@ -1318,12 +1318,13 @@ class emailadmin_account implements ArrayAccess
} }
/** /**
* Get ID of default mail account for either IMAP or SMTP * Get default mail account object either for IMAP or SMTP
* *
* @param boolean $smtp =false false: usable for IMAP, true: usable for SMTP * @param boolean $smtp =false false: usable for IMAP, true: usable for SMTP
* @return int * @param boolean $return_id =false true: return acc_id, false return account object
* @return emailadmin_account|null
*/ */
static function get_default_acc_id($smtp=false) static function get_default($smtp=false, $return_id=false)
{ {
try try
{ {
@ -1356,7 +1357,8 @@ class emailadmin_account implements ArrayAccess
// continue if we have either no imap username or password // continue if we have either no imap username or password
if (!$account->is_imap()) continue; if (!$account->is_imap()) continue;
} }
return $acc_id; return $return_id ? $acc_id : (isset($account) && $account->acc_id == $acc_id ?
$account : new emailadmin_account($params));
} }
} }
catch (Exception $e) catch (Exception $e)
@ -1366,6 +1368,17 @@ class emailadmin_account implements ArrayAccess
return null; return null;
} }
/**
* Get ID of default mail account for either IMAP or SMTP
*
* @param boolean $smtp =false false: usable for IMAP, true: usable for SMTP
* @return int
*/
static function get_default_acc_id($smtp=false)
{
return self::get_default($smtp, true);
}
/** /**
* build an identity name * build an identity name
* *

View File

@ -1,241 +0,0 @@
<?php
/**
* EGroupware EMailAdmin: Business logic
*
* @link http://www.stylite.de
* @package emailadmin
* @author Ralf Becker <rb@stylite.de>
* @author Klaus Leithoff <kl@stylite.de>
* @author Lars Kneschke
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
/**
* Business logic
*/
class emailadmin_bo
{
/**
* Name of app the table is registered
*/
const APP = 'emailadmin';
static $sessionData = array();
#var $userSessionData;
var $LDAPData;
//var $SMTPServerType = array(); // holds a list of config options
static $SMTPServerType = array(
'emailadmin_smtp' => array(
'description' => 'standard SMTP-Server',
'classname' => 'emailadmin_smtp'
),
);
//var $IMAPServerType = array(); // holds a list of config options
static $IMAPServerType = array(
'defaultimap' => array(
'description' => 'standard IMAP server',
'protocol' => 'imap',
'classname' => 'defaultimap'
)
);
var $imapClass; // holds the imap/pop3 class
var $smtpClass; // holds the smtp class
var $tracking; // holds the tracking object
/**
* @var emailadmin_so
*/
var $soemailadmin;
function __construct($_profileID=false,$_restoreSesssion=true)
{
//error_log(__METHOD__.function_backtrace());
if (!is_object($GLOBALS['emailadmin_bo']))
{
$GLOBALS['emailadmin_bo'] = $this;
}
//init with all servertypes and translate the standard entry description
self::$SMTPServerType = self::getSMTPServerTypes();
self::$IMAPServerType = self::getIMAPServerTypes();
self::$SMTPServerType['emailadmin_smtp']['description'] = lang('standard SMTP-Server');
self::$IMAPServerType['defaultimap']['description'] = lang('standard IMAP Server');
if ($_restoreSesssion) // && !(is_array(self::$sessionData) && (count(self::$sessionData)>0)) )
{
$this->restoreSessionData();
}
if ($_restoreSesssion===false) // && (is_array(self::$sessionData) && (count(self::$sessionData)>0)) )
{
// make sure session data will be created new
self::$sessionData = array();
self::saveSessionData();
}
#_debug_array(self::$sessionData);
}
function getAccountEmailAddress($_accountName, $_profileID)
{
$profileData = $this->getProfile($_profileID);
#$smtpClass = self::$SMTPServerType[$profileData['smtpType']]['classname'];
if ($profileData['smtpType']=='defaultsmtp') $profileData['smtpType']='emailadmin_smtp';
$smtpClass = CreateObject('emailadmin.'.self::$SMTPServerType[$profileData['smtpType']]['classname']);
#return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData);
return is_object($smtpClass) ? $smtpClass->getAccountEmailAddress($_accountName) : False;
}
function getMailboxString($_folderName)
{
if (is_object($this->imapClass))
{
return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData);
return $this->imapClass->getMailboxString($_folderName);
}
else
{
return false;
}
}
/**
* Get a list of supported SMTP servers
*
* Calls hook "smtp_server_types" to allow applications to supply own server-types
*
* @return array classname => label pairs
* @deprecated use emailadmin_base::getSMTPServerTypes()
*/
static public function getSMTPServerTypes($extended=true)
{
return emailadmin_base::getSMTPServerTypes($extended);
}
/**
* Get a list of supported IMAP servers
*
* Calls hook "imap_server_types" to allow applications to supply own server-types
*
* @param boolean $extended=true
* @return array classname => label pairs
* @deprecated use emailadmin_base::getIMAPServerTypes()
*/
static public function getIMAPServerTypes($extended=true)
{
return emailadmin_base::getIMAPServerTypes($extended);
}
/**
* Query user data from incomming (IMAP) and outgoing (SMTP) mail-server
*
* @param int $_accountID
* @return array
*/
function getUserData($_accountID)
{
return false;
}
function restoreSessionData()
{
$GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload');
//echo function_backtrace()."<br>";
//unserializing the sessiondata, since they are serialized for objects sake
self::$sessionData = (array) unserialize($GLOBALS['egw']->session->appsession('session_data','emailadmin'));
}
/**
* Autoload classes from emailadmin, 'til they get autoloading conform names
*
* @param string $class
*/
static function autoload($class)
{
if (strlen($class)<100)
{
if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'))
{
include_once($file);
}
elseif (strpos($class,'activesync')===0)
{
//temporary solution/hack to fix the false loading of activesync stuff, even as we may not need it for ui
//but trying to load it blocks the mail app
//error_log(__METHOD__.__LINE__.' '.$class);
include_once(EGW_INCLUDE_ROOT.'/activesync/backend/egw.php');
}
}
}
function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy)
{
if (is_object($this->smtpClass))
{
#$smtpClass = CreateObject('emailadmin.'.$this->smtpClass,$this->profileID);
#$smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy);
$this->smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy);
}
}
/**
* called by the validation hook in setup
*
* @param array $settings following keys: mail_server, mail_server_type {IMAP|IMAPS|POP-3|POP-3S},
* mail_login_type {standard|vmailmgr}, mail_suffix (domain), smtp_server, smtp_port, smtp_auth_user, smtp_auth_passwd
*/
function setDefaultProfile($settings)
{
return false;
}
function saveSessionData()
{
// serializing the session data, for the sake of objects
if (is_object($GLOBALS['egw']->session)) // otherwise setup(-cli) fails
{
$GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(self::$sessionData));
}
#$GLOBALS['egw']->session->appsession('user_session_data','',$this->userSessionData);
}
function updateAccount($_hookValues) {
if (is_object($this->imapClass)) {
#ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData);
$this->imapClass->updateAccount($_hookValues);
}
if (is_object($this->smtpClass)) {
#ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData);
$this->smtpClass->updateAccount($_hookValues);
}
self::$sessionData = array();
$this->saveSessionData();
}
/**
* Get ID of default new account profile
*
* @return int
* @deprecated use emailadmin_account::get_default_acc_id()
*/
static function getDefaultAccID()
{
return emailadmin_account::get_default_acc_id();
}
/**
* Get ID of User specific default new account profile
*
* @return int
* @deprecated use emailadmin_account::get_default_acc_id()
*/
static function getUserDefaultAccID()
{
return emailadmin_account::get_default_acc_id();
}
}

View File

@ -179,7 +179,7 @@ class emailadmin_imapbase
{ {
//$_restoreSession=false; //$_restoreSession=false;
if (is_null($_reuseCache)) $_reuseCache = $_restoreSession; if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.emailadmin_bo::getUserDefaultAccID().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace()); //error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.emailadmin_account::get_default_acc_id().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace());
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject)); //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
if ($_oldImapServerObject instanceof emailadmin_imap) if ($_oldImapServerObject instanceof emailadmin_imap)
{ {
@ -202,7 +202,7 @@ class emailadmin_imapbase
} }
else else
{ {
$profileID = emailadmin_bo::getUserDefaultAccID(); $profileID = emailadmin_account::get_default_acc_id();
} }
if ($profileID!=$_profileID) $_restoreSession==false; if ($profileID!=$_profileID) $_restoreSession==false;
$_profileID=$profileID; $_profileID=$profileID;
@ -247,7 +247,7 @@ class emailadmin_imapbase
self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions']; self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
} catch (egw_exception $e) } catch (egw_exception $e)
{ {
$newprofileID = emailadmin_bo::getUserDefaultAccID(); $newprofileID = emailadmin_account::get_default_acc_id();
// try loading the default profile for the user // try loading the default profile for the user
error_log(__METHOD__.' ('.__LINE__.') '." Loading the Profile for ProfileID ".$_profileID.' failed for icServer; '.$e->getMessage().' Trigger new instance for Default-Profile '.$newprofileID.'. called from:'.function_backtrace()); error_log(__METHOD__.' ('.__LINE__.') '." Loading the Profile for ProfileID ".$_profileID.' failed for icServer; '.$e->getMessage().' Trigger new instance for Default-Profile '.$newprofileID.'. called from:'.function_backtrace());
if ($newprofileID) if ($newprofileID)
@ -284,7 +284,7 @@ class emailadmin_imapbase
} }
else else
{ {
$oldProfileID = emailadmin_bo::getUserDefaultAccID(); $oldProfileID = emailadmin_account::get_default_acc_id();
} }
if ($_testConnection) if ($_testConnection)
{ {
@ -294,7 +294,7 @@ class emailadmin_imapbase
} }
catch (Exception $e) catch (Exception $e)
{ {
if ($_profileID != emailadmin_bo::getUserDefaultAccID()) $_profileID = emailadmin_bo::getUserDefaultAccID(); if ($_profileID != emailadmin_account::get_default_acc_id()) $_profileID = emailadmin_account::get_default_acc_id();
error_log(__METHOD__.__LINE__.' '.$e->getMessage()); error_log(__METHOD__.__LINE__.' '.$e->getMessage());
return false; return false;
} }