Added a function to update all email addresses when a mail domain is changed.
| | |
| | | `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, |
| | |
| | | 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() |
| | | { |
| | |
| | | } 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(); |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /* |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | // 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); |
| | | } |
| | |
| | | 'validators' => array ( 0 => array ( 'type' => 'ISINT', |
| | | 'errmsg'=> 'quota_error_isint'), |
| | | ), |
| | | 'default' => '', |
| | | 'default' => '0', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '255' |
| | |
| | | $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 |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | $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'); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | // 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); |
| | | } |
| | |
| | | |
| | | // 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); |
| | | } |
| | | |
| | |
| | | |
| | | $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); |