tbrehm
2008-07-10 37d7556980539287f08c8640bf0bb55523c55b69
commit | author | age
b5a23a 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 mail_plugin {
32     
33     var $plugin_name = 'mail_plugin';
34     var $class_name  = 'mail_plugin';
35     
36         
37     /*
38          This function is called when the plugin is loaded
39     */
40     
41     function onLoad() {
42         global $app;
43         
44         /*
45         Register for the events
46         */
47         
4585cf 48         //* Mailboxes
b5a23a 49         $app->plugins->registerEvent('mail_user_insert',$this->plugin_name,'user_insert');
T 50         $app->plugins->registerEvent('mail_user_update',$this->plugin_name,'user_update');
51         $app->plugins->registerEvent('mail_user_delete',$this->plugin_name,'user_delete');
958705 52         
4585cf 53         //* Mail Domains
T 54         //$app->plugins->registerEvent('mail_domain_insert',$this->plugin_name,'domain_insert');
55         //$app->plugins->registerEvent('mail_domain_update',$this->plugin_name,'domain_update');
56         //$app->plugins->registerEvent('mail_domain_delete',$this->plugin_name,'domain_delete');
b5a23a 57         
T 58     }
59     
60     
61     function user_insert($event_name,$data) {
62         global $app, $conf;
63         
3845f1 64         // get the config
T 65         $app->uses("getconf");
66         $mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail');
67         
b5a23a 68         // Create the maildir, if it does not exist
be40ba 69         if(!is_dir($data['new']['maildir'])) {
d49675 70             exec("su -c 'mkdir -p ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
T 71             exec("su -c 'maildirmake ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
72             //exec('maildirmake '.escapeshellcmd($data['new']['maildir']));
73             exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
b5a23a 74             $app->log('Created Maildir: '.$data['new']['maildir'],LOGLEVEL_DEBUG);
T 75         }
76     }
77     
78     function user_update($event_name,$data) {
79         global $app, $conf;
80         
81         // get the config
82         $app->uses("getconf");
83         $mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail');
84         
85         // Create the maildir, if it does not exist
be40ba 86         if(!is_dir($data['new']['maildir'])) {
958705 87             exec('mkdir -p '.escapeshellcmd($data['new']['maildir']));
b5a23a 88             exec('chown '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
T 89             $app->log('Created Maildir: '.$data['new']['maildir'],LOGLEVEL_DEBUG);
90         }
91         
92         // Move mailbox, if domain has changed and delete old mailbox
93         if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) {
958705 94             exec('mv -f '.escapeshellcmd($data['old']['maildir']).'* '.escapeshellcmd($data['new']['maildir']));
T 95             if(is_file($data['old']['maildir'].'.ispconfig_mailsize'))exec('mv -f '.escapeshellcmd($data['old']['maildir']).'.ispconfig_mailsize '.escapeshellcmd($data['new']['maildir']));
96             rmdir($data['old']['maildir']);
b5a23a 97             $app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'],LOGLEVEL_DEBUG);
T 98         }
99     }
100     
101     function user_delete($event_name,$data) {
102         global $app, $conf;
103         
104         $old_maildir_path = escapeshellcmd($data['old']['maildir']);
105         if(!stristr($old_maildir_path,'..') && !stristr($old_maildir_path,'*') && strlen($old_maildir_path) >= 10) {
958705 106             exec('rm -rf '.escapeshellcmd($old_maildir_path));
b5a23a 107             $app->log('Deleted the Maildir: '.$data['old']['maildir'],LOGLEVEL_DEBUG);
T 108         } else {
109             $app->log('Possible security violation when deleting the maildir: '.$data['old']['maildir'],LOGLEVEL_ERROR);
110         }
111     }
112     
113     
114     
115
116 } // end class
117
118 ?>