1+ <?php
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 {
32+
33+ var $ plugin_name = 'postfix_filter_plugin ' ;
34+ var $ class_name = 'postfix_filter_plugin ' ;
35+
36+
37+ var $ postfix_config_dir = '/etc/postfix ' ;
38+
39+ /*
40+ This function is called when the plugin is loaded
41+ */
42+
43+ function onLoad () {
44+ global $ app ;
45+
46+ /*
47+ Register for the events
48+ */
49+
50+ $ app ->plugins ->registerEvent ('mail_content_filter_insert ' ,'postfix_filter_plugin ' ,'insert ' );
51+ $ app ->plugins ->registerEvent ('mail_content_filter_update ' ,'postfix_filter_plugin ' ,'update ' );
52+ $ app ->plugins ->registerEvent ('mail_content_filter_delete ' ,'postfix_filter_plugin ' ,'delete ' );
53+
54+
55+
56+ }
57+
58+ function insert ($ event_name ,$ data ) {
59+ global $ app , $ conf ;
60+
61+ $ this ->update ($ event_name ,$ data );
62+
63+ }
64+
65+ function update ($ event_name ,$ data ) {
66+ global $ app , $ conf ;
67+
68+ $ type = $ data ["new " ]["type " ];
69+ if ($ type != '' ) {
70+ $ sql = "SELECT * FROM mail_content_filter WHERE server_id = " .intval ($ conf ["server_id " ])." AND type = ' " .$ app ->db ->quote ($ type )."' AND active = 'y' " ;
71+ $ rules = $ app ->db ->queryAllRecords ($ sql );
72+ $ content = '' ;
73+ foreach ($ rules as $ rule ) {
74+ $ content .= $ rule ["pattern " ]."\n" ;
75+ $ content .= " " .$ rule ["action " ]." " .$ rule ["data " ]."\n" ;
76+ }
77+
78+ if ($ type == 'header ' ) {
79+ file_put_contents ('/etc/postfix/header_checks ' ,$ content );
80+ $ app ->log ("Writing /etc/postfix/header_checks " ,LOGLEVEL_DEBUG );
81+ }
82+
83+ if ($ type == 'mime_header ' ) {
84+ file_put_contents ('/etc/postfix/mime_header_checks ' ,$ content );
85+ $ app ->log ("Writing /etc/postfix/mime_header_checks " ,LOGLEVEL_DEBUG );
86+ }
87+
88+ if ($ type == 'nested_header ' ) {
89+ file_put_contents ('/etc/postfix/nested_header_checks ' ,$ content );
90+ $ app ->log ("Writing /etc/postfix/nested_header_checks " ,LOGLEVEL_DEBUG );
91+ }
92+
93+ if ($ type == 'body ' ) {
94+ file_put_contents ('/etc/postfix/body_checks ' ,$ content );
95+ $ app ->log ("Writing /etc/postfix/body_checks " ,LOGLEVEL_DEBUG );
96+ }
97+ }
98+
99+ $ type = $ data ["old " ]["type " ];
100+ if ($ type != '' ) {
101+ $ sql = "SELECT * FROM mail_content_filter WHERE server_id = " .intval ($ conf ["server_id " ])." AND type = ' " .$ app ->db ->quote ($ type )."' AND active = 'y' " ;
102+ $ rules = $ app ->db ->queryAllRecords ($ sql );
103+ $ content = '' ;
104+ foreach ($ rules as $ rule ) {
105+ $ content .= $ rule ["pattern " ]."\n" ;
106+ $ content .= " " .$ rule ["action " ]." " .$ rule ["data " ]."\n" ;
107+ }
108+
109+ if ($ type == 'header ' ) {
110+ file_put_contents ('/etc/postfix/header_checks ' ,$ content );
111+ $ app ->log ("Writing /etc/postfix/header_checks " ,LOGLEVEL_DEBUG );
112+ }
113+
114+ if ($ type == 'mime_header ' ) {
115+ file_put_contents ('/etc/postfix/mime_header_checks ' ,$ content );
116+ $ app ->log ("Writing /etc/postfix/mime_header_checks " ,LOGLEVEL_DEBUG );
117+ }
118+
119+ if ($ type == 'nested_header ' ) {
120+ file_put_contents ('/etc/postfix/nested_header_checks ' ,$ content );
121+ $ app ->log ("Writing /etc/postfix/nested_header_checks " ,LOGLEVEL_DEBUG );
122+ }
123+
124+ if ($ type == 'body ' ) {
125+ file_put_contents ('/etc/postfix/body_checks ' ,$ content );
126+ $ app ->log ("Writing /etc/postfix/body_checks " ,LOGLEVEL_DEBUG );
127+ }
128+ }
129+ }
130+
131+ function delete ($ event_name ,$ data ) {
132+ global $ app , $ conf ;
133+
134+ $ this ->update ($ event_name ,$ data );
135+ }
136+
137+
138+ } // end class
139+
140+ ?>
0 commit comments