Skip to content

Commit 04c7ebe

Browse files
committed
- Completed the mail fiter rules
- fixed bugs when websites and dns zones were deleted.
1 parent eea5cff commit 04c7ebe

File tree

5 files changed

+126
-61
lines changed

5 files changed

+126
-61
lines changed

interface/web/dns/dns_soa_del.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,25 @@
4545
//* Check permissions for module
4646
$app->auth->check_module_permissions('dns');
4747

48-
$app->uses("tform_actions");
49-
$app->tform_actions->onDelete();
48+
$app->uses('tpl,tform,tform_actions');
49+
$app->load('tform_actions');
50+
51+
class page_action extends tform_actions {
52+
53+
function onBeforeDelete() {
54+
global $app; $conf;
55+
56+
if($app->tform->checkPerm($this->id,'d') == false) $app->error($app->lng('error_no_delete_permission'));
57+
58+
// Delete all records that belog to this zone.
59+
$records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE zone = '".intval($this->id)."'");
60+
foreach($records as $rec) {
61+
$app->db->datalogDelete('dns_rr','id',$rec['id']);
62+
}
63+
}
64+
}
65+
66+
$page = new page_action;
67+
$page->onDelete();
5068

5169
?>

interface/web/mail/mail_user_filter_edit.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ function getRule() {
114114
if($this->dataRecord["action"] == 'move') {
115115

116116
$content .= "
117-
`test -e ".'$DEFAULT/'.$this->dataRecord["target"]."`
117+
`test -e ".'$DEFAULT/.'.$this->dataRecord["target"]."`
118118
if ( ".'$RETURNCODE'." != 0 )
119119
{
120120
`maildirmake -f ".$this->dataRecord["target"].' $DEFAULT'."`
121121
`chmod -R 0700 ".'$DEFAULT/'.$this->dataRecord["target"]."`
122+
`echo INBOX.".$this->dataRecord["target"]." >> ".'$MAILDIR'."/courierimapsubscribed`
122123
}
123124
";
124125
}
@@ -139,7 +140,7 @@ function getRule() {
139140
$content .= "exception {\n";
140141

141142
if($this->dataRecord["action"] == 'move') {
142-
$content .= 'to $DEFAULT/'.$this->dataRecord["target"]."/\n";
143+
$content .= 'to $DEFAULT/.'.$this->dataRecord["target"]."/\n";
143144
} else {
144145
$content .= "to /dev/null\n";
145146
}

interface/web/sites/web_domain_del.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,37 @@
4545
//* Check permissions for module
4646
$app->auth->check_module_permissions('sites');
4747

48-
$app->uses("tform_actions");
49-
$app->tform_actions->onDelete();
48+
$app->uses('tpl,tform,tform_actions');
49+
$app->load('tform_actions');
50+
51+
class page_action extends tform_actions {
52+
53+
function onBeforeDelete() {
54+
global $app; $conf;
55+
56+
if($app->tform->checkPerm($this->id,'d') == false) $app->error($app->lng('error_no_delete_permission'));
57+
58+
// Delete all records that belog to this zone.
59+
$records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE parent_domain_id = '".intval($this->id)."' AND type != 'vhost'");
60+
foreach($records as $rec) {
61+
$app->db->datalogDelete('web_domain','domain_id',$rec['domain_id']);
62+
}
63+
64+
// Delete all records that belog to this zone.
65+
$records = $app->db->queryAllRecords("SELECT ftp_user_id FROM ftp_user WHERE parent_domain_id = '".intval($this->id)."'");
66+
foreach($records as $rec) {
67+
$app->db->datalogDelete('ftp_user','ftp_user_id',$rec['ftp_user_id']);
68+
}
69+
70+
// Delete all records that belog to this zone.
71+
$records = $app->db->queryAllRecords("SELECT shell_user_id FROM shell_user WHERE parent_domain_id = '".intval($this->id)."'");
72+
foreach($records as $rec) {
73+
$app->db->datalogDelete('shell_user','shell_user_id',$rec['shell_user_id']);
74+
}
75+
}
76+
}
77+
78+
$page = new page_action;
79+
$page->onDelete();
5080

5181
?>

server/conf/autoresponder.master

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
cc $DEFAULT
1+
# cc $DEFAULT
22
xfilter "reformail -r -t -I 'From: $LOGNAME'"
33
/^To:.*/
44
getaddr{$MATCH}=~ /^.*/;
5-
MATH=tolower${MATCH}
5+
MATCH=tolower${MATCH}
66
flock "{vmail_mailbox_base}/mailfilters/$HOST/$USER/.vacation.lock" {
77
`fgrep -iqx "$MATCH" {vmail_mailbox_base}/mailfilters/$HOST/$USER/.vacation.lst 2>/dev/null || { \
88
echo "$MATCH" >> {vmail_mailbox_base}/mailfilters/$HOST/$USER/.vacation.lst ; \
@@ -11,4 +11,4 @@ flock "{vmail_mailbox_base}/mailfilters/$HOST/$USER/.vacation.lock" {
1111
}
1212
if ( $RETURNCODE == 0 )
1313
exit
14-
to "| (cat - ; echo ''; cat {vmail_mailbox_base}/mailfilters/$HOST/$USER/.vacation.msg) | $SENDMAIL -t"
14+
cc "| (cat - ; echo ''; cat {vmail_mailbox_base}/mailfilters/$HOST/$USER/.vacation.msg) | $SENDMAIL -t"

server/plugins-available/maildrop_plugin.inc.php

Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -67,67 +67,81 @@ function update($event_name,$data) {
6767

6868
// Check if the config directory exists.
6969
if(!is_dir($this->mailfilter_config_dir)) {
70-
$app->log("Mailfilter config directory '".$this->mailfilter_config_dir."' does not exist.",LOGLEVEL_ERROR);
70+
$app->log("Mailfilter config directory '".$this->mailfilter_config_dir."' does not exist. Creating it now.",LOGLEVEL_WARN);
71+
mkdir($this->mailfilter_config_dir);
72+
exec("chown vmail ".$this->mailfilter_config_dir);
73+
exec("chmod 770 ".$this->mailfilter_config_dir);
74+
}
75+
76+
if(isset($data["new"]["email"])) {
77+
$email_parts = explode("@",$data["new"]["email"]);
7178
} else {
72-
// Check if something has been changed regarding the autoresponders
73-
if($data["old"]["autoresponder_text"] != $data["new"]["autoresponder_text"]
79+
$email_parts = explode("@",$data["old"]["email"]);
80+
}
81+
82+
// make sure that the config directories exist
83+
if(!is_dir($this->mailfilter_config_dir.'/'.$email_parts[1])) {
84+
mkdir($this->mailfilter_config_dir.'/'.$email_parts[1]);
85+
exec("chown vmail ".$this->mailfilter_config_dir.'/'.$email_parts[1]);
86+
exec("chmod 770 ".$this->mailfilter_config_dir.'/'.$email_parts[1]);
87+
}
88+
if(!is_dir($this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0])) {
89+
mkdir($this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
90+
exec("chown vmail ".$this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
91+
exec("chmod 770 ".$this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
92+
}
93+
94+
95+
// Check if something has been changed regarding the autoresponders
96+
if($data["old"]["autoresponder_text"] != $data["new"]["autoresponder_text"]
7497
or $data["old"]["autoresponder"] != $data["new"]["autoresponder"]
7598
or (isset($data["new"]["email"]) and $data["old"]["email"] != $data["new"]["email"])) {
7699

77-
// We delete the old autoresponder, if it exists
78-
$email_parts = explode("@",$data["old"]["email"]);
79-
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lock';
80-
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
81-
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst';
82-
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
83-
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.msg';
84-
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
85-
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
86-
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
100+
// We delete the old autoresponder, if it exists
101+
$email_parts = explode("@",$data["old"]["email"]);
102+
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lock';
103+
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
104+
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst';
105+
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
106+
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.msg';
107+
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
108+
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
109+
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
87110

88-
//Now we create the new autoresponder, if it is enabled
89-
if($data["new"]["autoresponder"] == 'y') {
90-
if(isset($data["new"]["email"])) {
91-
$email_parts = explode("@",$data["new"]["email"]);
92-
} else {
93-
$email_parts = explode("@",$data["old"]["email"]);
94-
}
95-
96-
// make sure that the config directories exist
97-
if(!is_dir($this->mailfilter_config_dir.'/'.$email_parts[1])) {
98-
mkdir($this->mailfilter_config_dir.'/'.$email_parts[1]);
99-
exec("chown vmail ".$this->mailfilter_config_dir.'/'.$email_parts[1]);
100-
exec("chmod 400 ".$this->mailfilter_config_dir.'/'.$email_parts[1]);
101-
}
102-
if(!is_dir($this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0])) {
103-
mkdir($this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
104-
exec("chown vmail ".$this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
105-
exec("chmod 400 ".$this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
106-
}
111+
//Now we create the new autoresponder, if it is enabled
112+
if($data["new"]["autoresponder"] == 'y') {
113+
if(isset($data["new"]["email"])) {
114+
$email_parts = explode("@",$data["new"]["email"]);
115+
} else {
116+
$email_parts = explode("@",$data["old"]["email"]);
117+
}
107118

108-
// Load the master template
109-
$tpl = file_get_contents($conf["rootpath"].'/conf/autoresponder.master');
110-
$tpl = str_replace('{vmail_mailbox_base}',$mail_config["homedir_path"],$tpl);
111-
// Write the config file.
112-
$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
113-
file_put_contents($config_file_path,$tpl);
114-
$app->log("Writing Autoresponder mailfilter file: $config_file_path",LOGLEVEL_DEBUG);
115-
exec("chmod 400 $config_file_path");
116-
exec("chown vmail $config_file_path");
117-
unset($tpl);
118-
unset($config_file_path);
119+
// Load the master template
120+
$tpl = file_get_contents($conf["rootpath"].'/conf/autoresponder.master');
121+
$tpl = str_replace('{vmail_mailbox_base}',$mail_config["homedir_path"],$tpl);
122+
// Write the config file.
123+
$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
124+
file_put_contents($config_file_path,$tpl);
125+
$app->log("Writing Autoresponder mailfilter file: $config_file_path",LOGLEVEL_DEBUG);
126+
exec("chmod 770 $config_file_path");
127+
exec("chown vmail $config_file_path");
128+
unset($tpl);
129+
unset($config_file_path);
119130

120-
// Write the autoresponder message file
121-
$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.msg';
122-
file_put_contents($config_file_path,$data["new"]["autoresponder_text"]);
123-
exec("chmod 400 $config_file_path");
124-
exec("chown vmail $config_file_path");
125-
$app->log("Writing Autoresponder message file: $config_file_path",LOGLEVEL_DEBUG);
126-
}
131+
// Write the autoresponder message file
132+
$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.msg';
133+
file_put_contents($config_file_path,$data["new"]["autoresponder_text"]);
134+
exec("chmod 770 $config_file_path");
135+
exec("chown vmail $config_file_path");
136+
$app->log("Writing Autoresponder message file: $config_file_path",LOGLEVEL_DEBUG);
127137
}
138+
}
139+
140+
$app->log("HERE",LOGLEVEL_DEBUG);
128141

129142
// Write the custom mailfilter script, if mailfilter recipe has changed
130143
if($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"]) {
144+
$app->log("Mailfilter config has been changed",LOGLEVEL_DEBUG);
131145
if(trim($data["new"]["custom_mailfilter"]) != '') {
132146
// Delete the old filter recipe
133147
$email_parts = explode("@",$data["old"]["email"]);
@@ -142,16 +156,18 @@ function update($event_name,$data) {
142156
}
143157
$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.mailfilter';
144158
file_put_contents($config_file_path,$data["new"]["custom_mailfilter"]);
145-
exec("chmod 400 $config_file_path");
159+
$app->log("Writing new custom Mailfiter".$config_file_path,LOGLEVEL_DEBUG);
160+
exec("chmod 770 $config_file_path");
146161
exec("chown vmail $config_file_path");
147162
unset($config_file_path);
148163
} else {
149164
// Delete the mailfilter recipe
150165
$email_parts = explode("@",$data["old"]["email"]);
151166
$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.mailfilter';
152167
if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
168+
$app->log("Deleting custom Mailfiter".$file,LOGLEVEL_DEBUG);
153169
}
154-
}
170+
//}
155171
}
156172
}
157173

0 commit comments

Comments
 (0)