commit | author | age
|
18341e
|
1 |
<?php |
T |
2 |
/* |
|
3 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
4 |
All rights reserved. |
|
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
|
7 |
are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
|
17 |
|
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
|
29 |
|
|
30 |
|
|
31 |
/****************************************** |
|
32 |
* Begin Form configuration |
|
33 |
******************************************/ |
|
34 |
|
|
35 |
$tform_def_file = "form/ftp_user.tform.php"; |
|
36 |
|
|
37 |
/****************************************** |
|
38 |
* End Form configuration |
|
39 |
******************************************/ |
|
40 |
|
7fe908
|
41 |
require_once '../../lib/config.inc.php'; |
MC |
42 |
require_once '../../lib/app.inc.php'; |
18341e
|
43 |
|
910093
|
44 |
//* Check permissions for module |
T |
45 |
$app->auth->check_module_permissions('sites'); |
18341e
|
46 |
|
T |
47 |
// Loading classes |
|
48 |
$app->uses('tpl,tform,tform_actions'); |
|
49 |
$app->load('tform_actions'); |
|
50 |
|
|
51 |
class page_action extends tform_actions { |
7fe908
|
52 |
|
4fae7e
|
53 |
function onShowNew() { |
T |
54 |
global $app, $conf; |
7fe908
|
55 |
|
4fae7e
|
56 |
// we will check only users, not admins |
T |
57 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
3cebc3
|
58 |
if(!$app->tform->checkClientLimit('limit_ftp_user')) { |
T |
59 |
$app->error($app->tform->wordbook["limit_ftp_user_txt"]); |
|
60 |
} |
|
61 |
if(!$app->tform->checkResellerLimit('limit_ftp_user')) { |
|
62 |
$app->error('Reseller: '.$app->tform->wordbook["limit_ftp_user_txt"]); |
4fae7e
|
63 |
} |
T |
64 |
} |
7fe908
|
65 |
|
4fae7e
|
66 |
parent::onShowNew(); |
T |
67 |
} |
5190fe
|
68 |
|
V |
69 |
function onShowEnd() { |
|
70 |
global $app, $conf, $interfaceConf; |
|
71 |
/* |
|
72 |
* If the names are restricted -> remove the restriction, so that the |
|
73 |
* data can be edited |
|
74 |
*/ |
7fe908
|
75 |
|
31f6ce
|
76 |
$app->uses('getconf,tools_sites'); |
db5aa6
|
77 |
$global_config = $app->getconf->get_global_config('sites'); |
31f6ce
|
78 |
$ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); |
7fe908
|
79 |
|
db5aa6
|
80 |
if ($this->dataRecord['username'] != ""){ |
T |
81 |
/* REMOVE the restriction */ |
10b4c8
|
82 |
$app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix)); |
db5aa6
|
83 |
} |
7fe908
|
84 |
|
ba18a8
|
85 |
if($this->dataRecord['username'] == "") { |
07c297
|
86 |
$app->tpl->setVar("username_prefix", $ftpuser_prefix); |
SC |
87 |
} else { |
|
88 |
$app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix'])); |
|
89 |
} |
5190fe
|
90 |
|
V |
91 |
parent::onShowEnd(); |
|
92 |
} |
7fe908
|
93 |
|
e7d184
|
94 |
function onSubmit() { |
T |
95 |
global $app, $conf; |
7fe908
|
96 |
|
e7d184
|
97 |
// Get the record of the parent domain |
7b47c0
|
98 |
if(isset($this->dataRecord["parent_domain_id"])) { |
2af58c
|
99 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]); |
7b47c0
|
100 |
if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); |
T |
101 |
} else { |
|
102 |
$tmp = $app->tform->getDataRecord($this->id); |
2af58c
|
103 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), $tmp["parent_domain_id"]); |
7b47c0
|
104 |
if(!$parent_domain) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); |
T |
105 |
unset($tmp); |
|
106 |
} |
7fe908
|
107 |
|
e7d184
|
108 |
// Set a few fixed values |
T |
109 |
$this->dataRecord["server_id"] = $parent_domain["server_id"]; |
7fe908
|
110 |
|
951880
|
111 |
//die(print_r($this->dataRecord)); |
7fe908
|
112 |
|
951880
|
113 |
if(isset($this->dataRecord['username']) && trim($this->dataRecord['username']) == '') $app->tform->errorMessage .= $app->tform->lng('username_error_empty').'<br />'; |
T |
114 |
if(isset($this->dataRecord['username']) && empty($this->dataRecord['parent_domain_id'])) $app->tform->errorMessage .= $app->tform->lng('parent_domain_id_error_empty').'<br />'; |
7fe908
|
115 |
if(isset($this->dataRecord['dir']) && stristr($this->dataRecord['dir'], '..')) $app->tform->errorMessage .= $app->tform->lng('dir_dot_error').'<br />'; |
MC |
116 |
if(isset($this->dataRecord['dir']) && stristr($this->dataRecord['dir'], './')) $app->tform->errorMessage .= $app->tform->lng('dir_slashdot_error').'<br />'; |
|
117 |
|
e7d184
|
118 |
parent::onSubmit(); |
T |
119 |
} |
7fe908
|
120 |
|
5190fe
|
121 |
function onBeforeInsert() { |
V |
122 |
global $app, $conf, $interfaceConf; |
7fe908
|
123 |
|
31f6ce
|
124 |
$app->uses('getconf,tools_sites'); |
db5aa6
|
125 |
$global_config = $app->getconf->get_global_config('sites'); |
31f6ce
|
126 |
$ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); |
10b4c8
|
127 |
|
7fe908
|
128 |
$this->dataRecord['username_prefix'] = $ftpuser_prefix; |
MC |
129 |
|
db5aa6
|
130 |
if ($app->tform->errorMessage == '') { |
T |
131 |
$this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; |
5190fe
|
132 |
} |
7fe908
|
133 |
|
5190fe
|
134 |
parent::onBeforeInsert(); |
V |
135 |
} |
|
136 |
|
7fe908
|
137 |
function onAfterInsert() { |
b4c750
|
138 |
global $app, $conf; |
7fe908
|
139 |
|
2af58c
|
140 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]); |
604c0c
|
141 |
$server_id = $app->functions->intval($web["server_id"]); |
2af58c
|
142 |
$dir = $web["document_root"]; |
MC |
143 |
$uid = $web["system_user"]; |
|
144 |
$gid = $web["system_group"]; |
f2fc77
|
145 |
|
TB |
146 |
// Check system user and group |
|
147 |
if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) { |
|
148 |
$app->error('Invalid system user or group'); |
|
149 |
} |
7fe908
|
150 |
|
8e6584
|
151 |
// The FTP user shall be owned by the same group then the website |
604c0c
|
152 |
$sys_groupid = $app->functions->intval($web['sys_groupid']); |
7fe908
|
153 |
|
2af58c
|
154 |
$sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?"; |
MC |
155 |
$app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id); |
7fe908
|
156 |
} |
5190fe
|
157 |
|
V |
158 |
function onBeforeUpdate() { |
|
159 |
global $app, $conf, $interfaceConf; |
f2fc77
|
160 |
|
5190fe
|
161 |
/* |
V |
162 |
* If the names should be restricted -> do it! |
|
163 |
*/ |
7fe908
|
164 |
|
31f6ce
|
165 |
$app->uses('getconf,tools_sites'); |
db5aa6
|
166 |
$global_config = $app->getconf->get_global_config('sites'); |
31f6ce
|
167 |
$ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); |
7fe908
|
168 |
|
MC |
169 |
$old_record = $app->tform->getDataRecord($this->id); |
|
170 |
$ftpuser_prefix = $app->tools_sites->getPrefix($old_record['username_prefix'], $ftpuser_prefix); |
|
171 |
$this->dataRecord['username_prefix'] = $ftpuser_prefix; |
|
172 |
|
db5aa6
|
173 |
/* restrict the names */ |
T |
174 |
if ($app->tform->errorMessage == '') { |
1ff13e
|
175 |
$this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; |
5190fe
|
176 |
} |
V |
177 |
} |
7fe908
|
178 |
|
b4c750
|
179 |
function onAfterUpdate() { |
T |
180 |
global $app, $conf; |
7fe908
|
181 |
|
92ada0
|
182 |
//* When the site of the FTP user has been changed |
378935
|
183 |
if(isset($this->dataRecord['parent_domain_id']) && $this->oldDataRecord['parent_domain_id'] != $this->dataRecord['parent_domain_id']) { |
2af58c
|
184 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]); |
604c0c
|
185 |
$server_id = $app->functions->intval($web["server_id"]); |
2af58c
|
186 |
$dir = $web["document_root"]; |
MC |
187 |
$uid = $web["system_user"]; |
|
188 |
$gid = $web["system_group"]; |
7fe908
|
189 |
|
92ada0
|
190 |
// The FTP user shall be owned by the same group then the website |
604c0c
|
191 |
$sys_groupid = $app->functions->intval($web['sys_groupid']); |
7fe908
|
192 |
|
2af58c
|
193 |
$sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?"; |
MC |
194 |
$app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id); |
92ada0
|
195 |
} |
7fe908
|
196 |
|
615a0a
|
197 |
//* 2. check to ensure that the FTP user path is not changed to a path outside of the docroot by a normal user |
T |
198 |
if(isset($this->dataRecord['dir']) && $this->dataRecord['dir'] != $this->oldDataRecord['dir'] && !$app->auth->is_admin()) { |
|
199 |
$vd = new validate_ftpuser; |
|
200 |
$error_message = $vd->ftp_dir('dir', $this->dataRecord['dir'], ''); |
|
201 |
//* This check should normally never be triggered |
|
202 |
//* Set the path to a safe path (web doc root). |
|
203 |
if($error_message != '') { |
2af58c
|
204 |
$ftp_data = $app->db->queryOneRecord("SELECT parent_domain_id FROM ftp_user WHERE ftp_user_id = ?", $app->tform->primary_id); |
MC |
205 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $ftp_data["parent_domain_id"]); |
|
206 |
$dir = $web["document_root"]; |
|
207 |
$sql = "UPDATE ftp_user SET dir = ? WHERE ftp_user_id = ?"; |
|
208 |
$app->db->query($sql, $dir, $this->id); |
615a0a
|
209 |
$app->log("Error in FTP path settings of FTP user ".$this->dataRecord['username'], 1); |
T |
210 |
} |
7fe908
|
211 |
|
615a0a
|
212 |
} |
7fe908
|
213 |
|
b4c750
|
214 |
} |
7fe908
|
215 |
|
18341e
|
216 |
} |
T |
217 |
|
|
218 |
$page = new page_action; |
|
219 |
$page->onLoad(); |
|
220 |
|
378935
|
221 |
?> |