Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISPConfig
ISPConfig 3
Commits
95870536
Commit
95870536
authored
Jan 08, 2008
by
tbrehm
Browse files
Added a function to update all email addresses when a mail domain is changed.
parent
baf2ef33
Changes
7
Hide whitespace changes
Inline
Side-by-side
install/sql/ispconfig3.sql
View file @
95870536
...
...
@@ -407,7 +407,7 @@ CREATE TABLE `mail_user` (
`uid`
int
(
10
)
unsigned
NOT
NULL
default
'5000'
,
`gid`
int
(
10
)
unsigned
NOT
NULL
default
'5000'
,
`maildir`
varchar
(
255
)
NOT
NULL
default
''
,
`quota`
int
(
11
)
NOT
NULL
,
`quota`
int
(
11
)
NOT
NULL
default
'0'
,
`homedir`
varchar
(
255
)
NOT
NULL
,
`autoresponder`
enum
(
'n'
,
'y'
)
NOT
NULL
default
'n'
,
`autoresponder_text`
tinytext
NOT
NULL
,
...
...
interface/lib/classes/db_mysql.inc.php
View file @
95870536
...
...
@@ -214,6 +214,77 @@ class db
if
(
$debug
==
1
){
echo
'mySQL Error Message: '
.
$this
->
errorMessage
;
}
}
}
//** Function to fill the datalog with a full differential record.
public
function
datalogSave
(
$db_table
,
$action
,
$primary_field
,
$primary_id
,
$record_old
,
$record_new
)
{
global
$app
,
$conf
;
// Insert backticks only for incomplete table names.
if
(
stristr
(
$db_table
,
'.'
))
{
$escape
=
''
;
}
else
{
$escape
=
'`'
;
}
$diffrec_full
=
array
();
$diff_num
=
0
;
if
(
is_array
(
$record_old
)
&&
count
(
$record_old
)
>
0
)
{
foreach
(
$record_old
as
$key
=>
$val
)
{
if
(
isset
(
$record_new
[
$key
])
&&
$record_new
[
$key
]
!=
$val
)
{
// Record has changed
$diffrec_full
[
'old'
][
$key
]
=
$val
;
$diffrec_full
[
'new'
][
$key
]
=
$record_new
[
$key
];
$diff_num
++
;
}
else
{
$diffrec_full
[
'old'
][
$key
]
=
$val
;
$diffrec_full
[
'new'
][
$key
]
=
$val
;
}
}
}
elseif
(
is_array
(
$record_new
))
{
foreach
(
$record_new
as
$key
=>
$val
)
{
if
(
isset
(
$record_new
[
$key
])
&&
$record_old
[
$key
]
!=
$val
)
{
// Record has changed
$diffrec_full
[
'new'
][
$key
]
=
$val
;
$diffrec_full
[
'old'
][
$key
]
=
$record_old
[
$key
];
$diff_num
++
;
}
else
{
$diffrec_full
[
'new'
][
$key
]
=
$val
;
$diffrec_full
[
'old'
][
$key
]
=
$val
;
}
}
}
// Insert the server_id, if the record has a server_id
$server_id
=
(
isset
(
$record_old
[
"server_id"
])
&&
$record_old
[
"server_id"
]
>
0
)
?
$record_old
[
"server_id"
]
:
0
;
if
(
isset
(
$record_new
[
"server_id"
]))
$server_id
=
$record_new
[
"server_id"
];
if
(
$diff_num
>
0
)
{
$diffstr
=
$app
->
db
->
quote
(
serialize
(
$diffrec_full
));
$username
=
$app
->
db
->
quote
(
$_SESSION
[
"s"
][
"user"
][
"username"
]);
$dbidx
=
$primary_field
.
":"
.
$primary_id
;
if
(
$action
==
'INSERT'
)
$action
=
'i'
;
if
(
$action
==
'UPDATE'
)
$action
=
'u'
;
if
(
$action
==
'DELETE'
)
$action
=
'd'
;
$sql
=
"INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('"
.
$db_table
.
"','
$dbidx
','
$server_id
','
$action
','"
.
time
()
.
"','
$username
','
$diffstr
')"
;
$app
->
db
->
query
(
$sql
);
}
return
true
;
}
//** Updates a record and saves the cahnges into the datalog
public
function
datalogUpdate
(
$tablename
,
$update_data
,
$index_field
,
$index_value
)
{
global
$app
;
$old_rec
=
$this
->
queryOneRecord
(
"SELECT * FROM
$tablename
WHERE
$index_field
= '
$index_value
'"
);
$this
->
query
(
"UPDATE
$tablename
SET
$update_data
WHERE
$index_field
= '
$index_value
'"
);
$new_rec
=
$this
->
queryOneRecord
(
"SELECT * FROM
$tablename
WHERE
$index_field
= '
$index_value
'"
);
$this
->
datalogSave
(
$tablename
,
'UPDATE'
,
$index_field
,
$index_value
,
$old_rec
,
$new_rec
);
return
true
;
}
public
function
closeConn
()
{
...
...
interface/lib/classes/tform.inc.php
View file @
95870536
...
...
@@ -875,15 +875,6 @@ class tform {
}
else
{
$escape
=
'`'
;
}
/*
if($action == "UPDATE" or $action == "DELETE") {
$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
$record_old = $app->db->queryOneRecord($sql);
} else {
$record_old = array();
}
*/
$diffrec
=
array
();
...
...
@@ -934,12 +925,6 @@ class tform {
}
}
/*
echo "<pre>";
print_r($diffrec_full);
echo "</pre>";
*/
// Insert the server_id, if the record has a server_id
$server_id
=
(
isset
(
$record_old
[
"server_id"
])
&&
$record_old
[
"server_id"
]
>
0
)
?
$record_old
[
"server_id"
]
:
0
;
if
(
isset
(
$record_new
[
"server_id"
]))
$server_id
=
$record_new
[
"server_id"
];
...
...
interface/lib/classes/tform_actions.inc.php
View file @
95870536
...
...
@@ -41,6 +41,7 @@ class tform_actions {
var
$activeTab
;
var
$dataRecord
;
var
$plugins
=
array
();
var
$oldDataRecord
;
// This array is only filled during updates and when db_history is enabled.
function
onLoad
()
{
global
$app
,
$conf
,
$tform_def_file
;
...
...
@@ -104,7 +105,7 @@ class tform_actions {
if
(
$app
->
tform
->
errorMessage
==
''
)
{
if
(
$app
->
tform
->
formDef
[
'db_history'
]
==
'yes'
)
{
$old
_d
ata
_r
ecord
=
$app
->
tform
->
getDataRecord
(
$this
->
id
);
$
this
->
old
D
ata
R
ecord
=
$app
->
tform
->
getDataRecord
(
$this
->
id
);
}
// Save record in database
...
...
@@ -124,7 +125,7 @@ class tform_actions {
// Write data history (sys_datalog)
if
(
$app
->
tform
->
formDef
[
'db_history'
]
==
'yes'
)
{
$new_data_record
=
$app
->
tform
->
getDataRecord
(
$this
->
id
);
$app
->
tform
->
datalogSave
(
'UPDATE'
,
$this
->
id
,
$old
_d
ata
_r
ecord
,
$new_data_record
);
$app
->
tform
->
datalogSave
(
'UPDATE'
,
$this
->
id
,
$
this
->
old
D
ata
R
ecord
,
$new_data_record
);
unset
(
$new_data_record
);
unset
(
$old_data_record
);
}
...
...
interface/web/mail/form/mail_user.tform.php
View file @
95870536
...
...
@@ -94,7 +94,7 @@ $form["tabs"]['mailuser'] = array (
'validators'
=>
array
(
0
=>
array
(
'type'
=>
'ISINT'
,
'errmsg'
=>
'quota_error_isint'
),
),
'default'
=>
''
,
'default'
=>
'
0
'
,
'value'
=>
''
,
'width'
=>
'30'
,
'maxlength'
=>
'255'
...
...
interface/web/mail/mail_domain_edit.php
View file @
95870536
...
...
@@ -216,6 +216,26 @@ class page_action extends tform_actions {
$app
->
db
->
query
(
$sql
);
}
}
// endif spamfilter policy
//** If the domain name has been changed, change the domain in all mailbox records
if
(
$this
->
oldDataRecord
[
'domain'
]
!=
$this
->
dataRecord
[
'domain'
])
{
$app
->
uses
(
'getconf'
);
$mail_config
=
$app
->
getconf
->
get_server_config
(
$this
->
dataRecord
[
"server_id"
],
'mail'
);
$mailusers
=
$app
->
db
->
queryAllRecords
(
"SELECT * FROM mail_user WHERE email like '%@"
.
addslashes
(
$this
->
oldDataRecord
[
'domain'
])
.
"'"
);
if
(
is_array
(
$mailusers
))
{
foreach
(
$mailusers
as
$rec
)
{
// setting Maildir, Homedir, UID and GID
$mail_parts
=
explode
(
"@"
,
$rec
[
'email'
]);
$maildir
=
str_replace
(
"[domain]"
,
$this
->
dataRecord
[
'domain'
],
$mail_config
[
"maildir_path"
]);
$maildir
=
str_replace
(
"[localpart]"
,
$mail_parts
[
0
],
$maildir
);
$maildir
=
addslashes
(
$maildir
);
//$app->db->query("UPDATE mail_user SET maildir = '$maildir' WHERE mailuser_id = ".$rec['mailuser_id']);
//$rec_new = $app->db->queryOneRecord("SELECT * FROM mail_user WHERE mailuser_id = ".$rec['mailuser_id']);
$app
->
db
->
datalogUpdate
(
'mail_user'
,
"maildir = '
$maildir
'"
,
'mailuser_id'
,
$rec
[
'mailuser_id'
]);
}
}
}
// end if domain name changed
}
}
...
...
server/plugins-available/mail_plugin.inc.php
View file @
95870536
...
...
@@ -48,7 +48,7 @@ class mail_plugin {
$app
->
plugins
->
registerEvent
(
'mail_user_insert'
,
$this
->
plugin_name
,
'user_insert'
);
$app
->
plugins
->
registerEvent
(
'mail_user_update'
,
$this
->
plugin_name
,
'user_update'
);
$app
->
plugins
->
registerEvent
(
'mail_user_delete'
,
$this
->
plugin_name
,
'user_delete'
);
}
...
...
@@ -58,7 +58,7 @@ class mail_plugin {
// Create the maildir, if it does not exist
if
(
!
is_dir
(
$data
[
'new'
][
'maildir'
]))
{
mkdir
(
$data
[
'new'
][
'maildir'
]);
exec
(
'mkdir -p '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
])
)
;
exec
(
'chown '
.
$mail_config
[
'mailuser_name'
]
.
':'
.
$mail_config
[
'mailuser_group'
]
.
' '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
]));
$app
->
log
(
'Created Maildir: '
.
$data
[
'new'
][
'maildir'
],
LOGLEVEL_DEBUG
);
}
...
...
@@ -74,15 +74,16 @@ class mail_plugin {
// Create the maildir, if it does not exist
if
(
!
is_dir
(
$data
[
'new'
][
'maildir'
]))
{
mkdir
(
$data
[
'new'
][
'maildir'
]);
exec
(
'mkdir -p '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
])
)
;
exec
(
'chown '
.
$mail_config
[
'mailuser_name'
]
.
':'
.
$mail_config
[
'mailuser_group'
]
.
' '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
]));
$app
->
log
(
'Created Maildir: '
.
$data
[
'new'
][
'maildir'
],
LOGLEVEL_DEBUG
);
}
// Move mailbox, if domain has changed and delete old mailbox
if
(
$data
[
'new'
][
'maildir'
]
!=
$data
[
'old'
][
'maildir'
]
&&
is_dir
(
$data
[
'old'
][
'maildir'
]))
{
exec
(
'mv -f'
.
escapeshellcmd
(
$data
[
'old'
][
'maildir'
])
.
'* '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
]));
unlink
(
$data
[
'old'
][
'maildir'
]);
exec
(
'mv -f '
.
escapeshellcmd
(
$data
[
'old'
][
'maildir'
])
.
'* '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
]));
if
(
is_file
(
$data
[
'old'
][
'maildir'
]
.
'.ispconfig_mailsize'
))
exec
(
'mv -f '
.
escapeshellcmd
(
$data
[
'old'
][
'maildir'
])
.
'.ispconfig_mailsize '
.
escapeshellcmd
(
$data
[
'new'
][
'maildir'
]));
rmdir
(
$data
[
'old'
][
'maildir'
]);
$app
->
log
(
'Moved Maildir from: '
.
$data
[
'old'
][
'maildir'
]
.
' to '
.
$data
[
'new'
][
'maildir'
],
LOGLEVEL_DEBUG
);
}
...
...
@@ -93,7 +94,7 @@ class mail_plugin {
$old_maildir_path
=
escapeshellcmd
(
$data
[
'old'
][
'maildir'
]);
if
(
!
stristr
(
$old_maildir_path
,
'..'
)
&&
!
stristr
(
$old_maildir_path
,
'*'
)
&&
strlen
(
$old_maildir_path
)
>=
10
)
{
exec
(
'rm -rf '
.
$old_maildir_path
);
exec
(
'rm -rf '
.
escapeshellcmd
(
$old_maildir_path
)
)
;
$app
->
log
(
'Deleted the Maildir: '
.
$data
[
'old'
][
'maildir'
],
LOGLEVEL_DEBUG
);
}
else
{
$app
->
log
(
'Possible security violation when deleting the maildir: '
.
$data
[
'old'
][
'maildir'
],
LOGLEVEL_ERROR
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment