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 |
|
|
41 |
require_once('../../lib/config.inc.php'); |
|
42 |
require_once('../../lib/app.inc.php'); |
5190fe
|
43 |
require_once('tools.inc.php'); |
18341e
|
44 |
|
910093
|
45 |
//* Check permissions for module |
T |
46 |
$app->auth->check_module_permissions('sites'); |
18341e
|
47 |
|
T |
48 |
// Loading classes |
|
49 |
$app->uses('tpl,tform,tform_actions'); |
|
50 |
$app->load('tform_actions'); |
|
51 |
|
|
52 |
class page_action extends tform_actions { |
|
53 |
|
4fae7e
|
54 |
function onShowNew() { |
T |
55 |
global $app, $conf; |
|
56 |
|
|
57 |
// we will check only users, not admins |
|
58 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
|
59 |
|
|
60 |
// Get the limits of the client |
|
61 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
62 |
$client = $app->db->queryOneRecord("SELECT limit_ftp_user FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
|
63 |
|
af8f1b
|
64 |
// Check if the user may add another ftp user. |
4fae7e
|
65 |
if($client["limit_ftp_user"] >= 0) { |
T |
66 |
$tmp = $app->db->queryOneRecord("SELECT count(ftp_user_id) as number FROM ftp_user WHERE sys_groupid = $client_group_id"); |
|
67 |
if($tmp["number"] >= $client["limit_ftp_user"]) { |
|
68 |
$app->error($app->tform->wordbook["limit_ftp_user_txt"]); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
parent::onShowNew(); |
|
74 |
} |
5190fe
|
75 |
|
V |
76 |
function onShowEnd() { |
|
77 |
global $app, $conf, $interfaceConf; |
|
78 |
/* |
|
79 |
* If the names are restricted -> remove the restriction, so that the |
|
80 |
* data can be edited |
|
81 |
*/ |
db5aa6
|
82 |
|
T |
83 |
$app->uses('getconf'); |
|
84 |
$global_config = $app->getconf->get_global_config('sites'); |
|
85 |
$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); |
|
86 |
|
|
87 |
if ($this->dataRecord['username'] != ""){ |
|
88 |
/* REMOVE the restriction */ |
|
89 |
$app->tpl->setVar("username", str_replace($ftpuser_prefix , '', $this->dataRecord['username'])); |
|
90 |
} |
|
91 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
92 |
$app->tpl->setVar("username_prefix", $global_config['ftpuser_prefix']); |
|
93 |
} |
|
94 |
else { |
|
95 |
$app->tpl->setVar("username_prefix", $ftpuser_prefix); |
5190fe
|
96 |
} |
V |
97 |
|
|
98 |
parent::onShowEnd(); |
|
99 |
} |
18341e
|
100 |
|
e7d184
|
101 |
function onSubmit() { |
T |
102 |
global $app, $conf; |
|
103 |
|
|
104 |
// Get the record of the parent domain |
|
105 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"])); |
|
106 |
|
|
107 |
// Set a few fixed values |
|
108 |
$this->dataRecord["server_id"] = $parent_domain["server_id"]; |
|
109 |
|
|
110 |
parent::onSubmit(); |
|
111 |
} |
|
112 |
|
5190fe
|
113 |
function onBeforeInsert() { |
V |
114 |
global $app, $conf, $interfaceConf; |
db5aa6
|
115 |
|
T |
116 |
$app->uses('getconf'); |
|
117 |
$global_config = $app->getconf->get_global_config('sites'); |
|
118 |
$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); |
|
119 |
|
|
120 |
if ($app->tform->errorMessage == '') { |
|
121 |
$this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; |
5190fe
|
122 |
} |
db5aa6
|
123 |
|
5190fe
|
124 |
parent::onBeforeInsert(); |
V |
125 |
} |
|
126 |
|
|
127 |
function onAfterInsert() { |
b4c750
|
128 |
global $app, $conf; |
T |
129 |
|
|
130 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); |
|
131 |
$server_id = $web["server_id"]; |
|
132 |
$dir = $web["document_root"]; |
|
133 |
$uid = $web["system_user"]; |
|
134 |
$gid = $web["system_group"]; |
|
135 |
|
8e6584
|
136 |
// The FTP user shall be owned by the same group then the website |
T |
137 |
$sys_groupid = $web['sys_groupid']; |
|
138 |
|
|
139 |
$sql = "UPDATE ftp_user SET server_id = $server_id, dir = '$dir', uid = '$uid', gid = '$gid', sys_groupid = '$sys_groupid' WHERE ftp_user_id = ".$this->id; |
b4c750
|
140 |
$app->db->query($sql); |
T |
141 |
|
8e6584
|
142 |
|
b4c750
|
143 |
} |
5190fe
|
144 |
|
V |
145 |
function onBeforeUpdate() { |
|
146 |
global $app, $conf, $interfaceConf; |
|
147 |
|
|
148 |
/* |
|
149 |
* If the names should be restricted -> do it! |
|
150 |
*/ |
db5aa6
|
151 |
|
T |
152 |
$app->uses('getconf'); |
|
153 |
$global_config = $app->getconf->get_global_config('sites'); |
|
154 |
$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']); |
|
155 |
|
|
156 |
/* restrict the names */ |
|
157 |
if ($app->tform->errorMessage == '') { |
1ff13e
|
158 |
$this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; |
5190fe
|
159 |
} |
V |
160 |
} |
b4c750
|
161 |
|
T |
162 |
function onAfterUpdate() { |
|
163 |
global $app, $conf; |
|
164 |
|
|
165 |
|
|
166 |
} |
|
167 |
|
db5aa6
|
168 |
function getClientName() { |
T |
169 |
global $app, $conf; |
|
170 |
|
|
171 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
172 |
// Get the group-id of the user |
|
173 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
174 |
} else { |
|
175 |
// Get the group-id from the data itself |
fb06cc
|
176 |
$web = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".intval($this->dataRecord['parent_domain_id'])); |
T |
177 |
$client_group_id = $web['sys_groupid']; |
db5aa6
|
178 |
} |
T |
179 |
/* get the name of the client */ |
|
180 |
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); |
|
181 |
$clientName = $tmp['name']; |
|
182 |
if ($clientName == "") $clientName = 'default'; |
|
183 |
$clientName = convertClientName($clientName); |
df22a8
|
184 |
return $clientName; |
db5aa6
|
185 |
|
T |
186 |
} |
|
187 |
|
18341e
|
188 |
} |
T |
189 |
|
|
190 |
$page = new page_action; |
|
191 |
$page->onLoad(); |
|
192 |
|
|
193 |
?> |