Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
2d4bd4 1 <?php
T 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 class postfix_filter_plugin {
b1a6a5 32
2d4bd4 33     var $plugin_name = 'postfix_filter_plugin';
T 34     var $class_name = 'postfix_filter_plugin';
b1a6a5 35
MC 36
2d4bd4 37     var $postfix_config_dir = '/etc/postfix';
b1a6a5 38
392450 39     //* This function is called during ispconfig installation to determine
T 40     //  if a symlink shall be created for this plugin.
41     function onInstall() {
42         global $conf;
b1a6a5 43
392450 44         if($conf['services']['mail'] == true) {
T 45             return true;
46         } else {
47             return false;
48         }
b1a6a5 49
392450 50     }
b1a6a5 51
2d4bd4 52     /*
T 53          This function is called when the plugin is loaded
54     */
b1a6a5 55
2d4bd4 56     function onLoad() {
T 57         global $app;
b1a6a5 58
2d4bd4 59         /*
T 60         Register for the events
61         */
b1a6a5 62
MC 63         $app->plugins->registerEvent('mail_content_filter_insert', 'postfix_filter_plugin', 'insert');
64         $app->plugins->registerEvent('mail_content_filter_update', 'postfix_filter_plugin', 'update');
65         $app->plugins->registerEvent('mail_content_filter_delete', 'postfix_filter_plugin', 'delete');
66
67
68
2d4bd4 69     }
b1a6a5 70
MC 71     function insert($event_name, $data) {
2d4bd4 72         global $app, $conf;
b1a6a5 73
MC 74         $this->update($event_name, $data);
75
2d4bd4 76     }
b1a6a5 77
MC 78     function update($event_name, $data) {
2d4bd4 79         global $app, $conf;
b1a6a5 80
2d4bd4 81         $type = $data["new"]["type"];
T 82         if($type != '') {
8df4a3 83             $sql = "SELECT * FROM mail_content_filter WHERE server_id = ? AND type = ? AND active = 'y'";
cc7a82 84             $rules = $app->db->queryAllRecords($sql, $conf["server_id"], $type);
2d4bd4 85             $content = '';
T 86             foreach($rules as $rule) {
3cdb9a 87                 $content .= $rule["pattern"];
2d4bd4 88                 $content .= "  ".$rule["action"]." ".$rule["data"]."\n";
T 89             }
b1a6a5 90
2d4bd4 91             if($type == 'header') {
b1a6a5 92                 file_put_contents('/etc/postfix/header_checks', $content);
MC 93                 $app->log("Writing /etc/postfix/header_checks", LOGLEVEL_DEBUG);
2d4bd4 94             }
b1a6a5 95
2d4bd4 96             if($type == 'mime_header') {
b1a6a5 97                 file_put_contents('/etc/postfix/mime_header_checks', $content);
MC 98                 $app->log("Writing /etc/postfix/mime_header_checks", LOGLEVEL_DEBUG);
2d4bd4 99             }
b1a6a5 100
2d4bd4 101             if($type == 'nested_header') {
b1a6a5 102                 file_put_contents('/etc/postfix/nested_header_checks', $content);
MC 103                 $app->log("Writing /etc/postfix/nested_header_checks", LOGLEVEL_DEBUG);
2d4bd4 104             }
b1a6a5 105
2d4bd4 106             if($type == 'body') {
b1a6a5 107                 file_put_contents('/etc/postfix/body_checks', $content);
MC 108                 $app->log("Writing /etc/postfix/body_checks", LOGLEVEL_DEBUG);
2d4bd4 109             }
T 110         }
b1a6a5 111
2d4bd4 112         $type = $data["old"]["type"];
T 113         if($type != '') {
cc7a82 114             $sql = "SELECT * FROM mail_content_filter WHERE server_id = ? AND type = ? AND active = 'y'";
MC 115             $rules = $app->db->queryAllRecords($sql, $conf["server_id"], $type);
2d4bd4 116             $content = '';
T 117             foreach($rules as $rule) {
3cdb9a 118                 $content .= $rule["pattern"];
2d4bd4 119                 $content .= "  ".$rule["action"]." ".$rule["data"]."\n";
T 120             }
b1a6a5 121
2d4bd4 122             if($type == 'header') {
b1a6a5 123                 file_put_contents('/etc/postfix/header_checks', $content);
MC 124                 $app->log("Writing /etc/postfix/header_checks", LOGLEVEL_DEBUG);
2d4bd4 125             }
b1a6a5 126
2d4bd4 127             if($type == 'mime_header') {
b1a6a5 128                 file_put_contents('/etc/postfix/mime_header_checks', $content);
MC 129                 $app->log("Writing /etc/postfix/mime_header_checks", LOGLEVEL_DEBUG);
2d4bd4 130             }
b1a6a5 131
2d4bd4 132             if($type == 'nested_header') {
b1a6a5 133                 file_put_contents('/etc/postfix/nested_header_checks', $content);
MC 134                 $app->log("Writing /etc/postfix/nested_header_checks", LOGLEVEL_DEBUG);
2d4bd4 135             }
b1a6a5 136
2d4bd4 137             if($type == 'body') {
b1a6a5 138                 file_put_contents('/etc/postfix/body_checks', $content);
MC 139                 $app->log("Writing /etc/postfix/body_checks", LOGLEVEL_DEBUG);
2d4bd4 140             }
T 141         }
142     }
b1a6a5 143
MC 144     function delete($event_name, $data) {
2d4bd4 145         global $app, $conf;
b1a6a5 146
MC 147         $this->update($event_name, $data);
2d4bd4 148     }
b1a6a5 149
2d4bd4 150
T 151 } // end class
152
b1a6a5 153 ?>