diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index c8188f013a1a7d5b38a59dfc739bb0beda10269b..ebd094f484e061be6a97fc458713503725e2ae06 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -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, diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php index eeb7c5912bfaa43eb052130898384a720a33e491..54b210c409224372508e89678dab992a038ccb27 100644 --- a/interface/lib/classes/db_mysql.inc.php +++ b/interface/lib/classes/db_mysql.inc.php @@ -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() { diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php index e5644c321fb07c16c8c2af98a4ca8b8f45931afd..61ddefd7ff9657b3cd84e71da001517488c0e50a 100644 --- a/interface/lib/classes/tform.inc.php +++ b/interface/lib/classes/tform.inc.php @@ -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 "
";
-				print_r($diffrec_full);
-				echo "
"; - */ - // 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"]; diff --git a/interface/lib/classes/tform_actions.inc.php b/interface/lib/classes/tform_actions.inc.php index 7fb553fb621c851fe391bd94bce7538996955bcd..c19308178ec34e506ecd743f25ebe145d86f3a1c 100644 --- a/interface/lib/classes/tform_actions.inc.php +++ b/interface/lib/classes/tform_actions.inc.php @@ -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_data_record = $app->tform->getDataRecord($this->id); + $this->oldDataRecord = $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_data_record,$new_data_record); + $app->tform->datalogSave('UPDATE',$this->id,$this->oldDataRecord,$new_data_record); unset($new_data_record); unset($old_data_record); } diff --git a/interface/web/mail/form/mail_user.tform.php b/interface/web/mail/form/mail_user.tform.php index eba1e1f5ab7a8cca0b56e5c095a469de3a43a5c9..0015d23ec244a26a200f8ab5bac24d04152244a4 100644 --- a/interface/web/mail/form/mail_user.tform.php +++ b/interface/web/mail/form/mail_user.tform.php @@ -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' diff --git a/interface/web/mail/mail_domain_edit.php b/interface/web/mail/mail_domain_edit.php index a32190d160cdda43f5d4f2a4a48c04def937f2ae..91847d73451925912c53ec1e15b6b4822a1172b2 100644 --- a/interface/web/mail/mail_domain_edit.php +++ b/interface/web/mail/mail_domain_edit.php @@ -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 + } } diff --git a/server/plugins-available/mail_plugin.inc.php b/server/plugins-available/mail_plugin.inc.php index 95ef769b9adda5b2dfb14d791e3383ece143bf59..9140708fef0d7da958c080177c131b5de43b52a3 100644 --- a/server/plugins-available/mail_plugin.inc.php +++ b/server/plugins-available/mail_plugin.inc.php @@ -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);