Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
086696 1 <?php
M 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 ftpuser_base_plugin {
7fe908 32
086696 33     var $plugin_name = 'ftpuser_base_plugin';
M 34     var $class_name = 'ftpuser_base_plugin';
7fe908 35
086696 36     //* This function is called during ispconfig installation to determine
M 37     //  if a symlink shall be created for this plugin.
38     function onInstall() {
39         global $conf;
7fe908 40
086696 41         if($conf['services']['web'] == true) {
M 42             return true;
43         } else {
44             return false;
45         }
7fe908 46
086696 47     }
7fe908 48
MC 49
086696 50     /*
M 51          This function is called when the plugin is loaded
52     */
7fe908 53
086696 54     function onLoad() {
M 55         global $app;
7fe908 56
086696 57         /*
M 58         Register for the events
59         */
60
7fe908 61         $app->plugins->registerEvent('ftp_user_insert', $this->plugin_name, 'insert');
MC 62         $app->plugins->registerEvent('ftp_user_update', $this->plugin_name, 'update');
63         $app->plugins->registerEvent('ftp_user_delete', $this->plugin_name, 'delete');
615a0a 64
7fe908 65
086696 66     }
7fe908 67
MC 68
69     function insert($event_name, $data) {
086696 70         global $app, $conf;
7fe908 71
MC 72         $app->uses('system');
73
74         if(!is_dir($data['new']['dir'])) {
75             $app->log("FTP User directory '".$data['new']['dir']."' does not exist. Creating it now.", LOGLEVEL_DEBUG);
76
cc7a82 77             $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $data['new']['parent_domain_id']);
7fe908 78
MC 79             //* Check if the resulting path is inside the docroot
80             if(substr($data['new']['dir'], 0, strlen($web['document_root'])) != $web['document_root']) {
81                 $app->log('User dir is outside of docroot.', LOGLEVEL_WARN);
82                 return false;
83             }
84
85             $app->system->web_folder_protection($web['document_root'], false);
86             exec('mkdir -p '.escapeshellcmd($data['new']['dir']));
87             exec('chown '.escapeshellcmd($web["system_user"]).':'.escapeshellcmd($web['system_group']).' '.$data['new']['dir']);
88             $app->system->web_folder_protection($web['document_root'], true);
89
90             $app->log("Added ftpuser_dir: ".$data['new']['dir'], LOGLEVEL_DEBUG);
91         }
92
086696 93     }
7fe908 94
MC 95     function update($event_name, $data) {
96         global $app, $conf;
97
98         $app->uses('system');
99
100         if(!is_dir($data['new']['dir'])) {
101             $app->log("FTP User directory '".$data['new']['dir']."' does not exist. Creating it now.", LOGLEVEL_DEBUG);
102
cc7a82 103             $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $data['new']['parent_domain_id']);
7fe908 104
MC 105             //* Check if the resulting path is inside the docroot
106             if(substr($data['new']['dir'], 0, strlen($web['document_root'])) != $web['document_root']) {
107                 $app->log('User dir is outside of docroot.', LOGLEVEL_WARN);
108                 return false;
109             }
110
111             $app->system->web_folder_protection($web['document_root'], false);
112             exec('mkdir -p '.escapeshellcmd($data['new']['dir']));
113             exec('chown '.escapeshellcmd($web["system_user"]).':'.escapeshellcmd($web['system_group']).' '.$data['new']['dir']);
114             $app->system->web_folder_protection($web['document_root'], true);
4887d4 115             
TB 116             
7fe908 117
MC 118             $app->log("Added ftpuser_dir: ".$data['new']['dir'], LOGLEVEL_DEBUG);
119         }
4887d4 120         
TB 121         // When the directory has changed, delete the old .ftpquota file
122         if($data['old']['dir'] != '' && $data['old']['dir'] != $data['new']['dir']) {
123             if(is_file($data['old']['dir'].'/.ftpquota')) unlink($data['old']['dir'].'/.ftpquota');
124         }
125         
7fe908 126     }
MC 127
128     function delete($event_name, $data) {
129         global $app, $conf;
4887d4 130         
TB 131         // Delete the .ftpquota file
132         if(is_file($data['old']['dir'].'/.ftpquota')) unlink($data['old']['dir'].'/.ftpquota');
7fe908 133
MC 134         $app->log("Ftpuser:".$data['new']['username']." deleted.", LOGLEVEL_DEBUG);
135
136     }
137
138
139
086696 140
M 141 } // end class
142
7fe908 143 ?>