commit | author | age
|
af8f1b
|
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/shell_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'); |
af8f1b
|
44 |
|
910093
|
45 |
//* Check permissions for module |
T |
46 |
$app->auth->check_module_permissions('sites'); |
af8f1b
|
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 |
|
|
54 |
function onShowNew() { |
|
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"]; |
12ac51
|
62 |
$client = $app->db->queryOneRecord("SELECT limit_shell_user FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
af8f1b
|
63 |
|
T |
64 |
// Check if the user may add another shell user. |
|
65 |
if($client["limit_shell_user"] >= 0) { |
|
66 |
$tmp = $app->db->queryOneRecord("SELECT count(shell_user_id) as number FROM shell_user WHERE sys_groupid = $client_group_id"); |
|
67 |
if($tmp["number"] >= $client["limit_shell_user"]) { |
|
68 |
$app->error($app->tform->wordbook["limit_shell_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 |
$shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); |
|
86 |
|
|
87 |
if ($this->dataRecord['username'] != ""){ |
|
88 |
/* REMOVE the restriction */ |
|
89 |
$app->tpl->setVar("username", str_replace($shelluser_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['shelluser_prefix']); |
|
93 |
} else { |
|
94 |
$app->tpl->setVar("username_prefix", $shelluser_prefix); |
5190fe
|
95 |
} |
V |
96 |
|
|
97 |
parent::onShowEnd(); |
|
98 |
} |
af8f1b
|
99 |
|
e7d184
|
100 |
function onSubmit() { |
T |
101 |
global $app, $conf; |
|
102 |
|
|
103 |
// Get the record of the parent domain |
|
104 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"])); |
|
105 |
|
|
106 |
// Set a few fixed values |
|
107 |
$this->dataRecord["server_id"] = $parent_domain["server_id"]; |
|
108 |
|
|
109 |
parent::onSubmit(); |
|
110 |
} |
|
111 |
|
253e87
|
112 |
function onBeforeInsert() { |
5190fe
|
113 |
global $app, $conf, $interfaceConf; |
V |
114 |
|
253e87
|
115 |
// check if the username is not blacklisted |
T |
116 |
$blacklist = file(ISPC_LIB_PATH.'/shelluser_blacklist'); |
|
117 |
foreach($blacklist as $line) { |
5190fe
|
118 |
if(strtolower(trim($line)) == strtolower(trim($this->dataRecord['username']))){ |
V |
119 |
$app->tform->errorMessage .= 'The username is not allowed.'; |
|
120 |
} |
253e87
|
121 |
} |
T |
122 |
unset($blacklist); |
5190fe
|
123 |
|
V |
124 |
/* |
|
125 |
* If the names should be restricted -> do it! |
|
126 |
*/ |
db5aa6
|
127 |
if ($app->tform->errorMessage == ''){ |
T |
128 |
|
|
129 |
$app->uses('getconf'); |
|
130 |
$global_config = $app->getconf->get_global_config('sites'); |
|
131 |
$shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); |
5190fe
|
132 |
|
db5aa6
|
133 |
/* restrict the names */ |
T |
134 |
$this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; |
5190fe
|
135 |
} |
V |
136 |
parent::onBeforeInsert(); |
253e87
|
137 |
} |
T |
138 |
|
af8f1b
|
139 |
function onAfterInsert() { |
T |
140 |
global $app, $conf; |
|
141 |
|
|
142 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); |
|
143 |
$server_id = $web["server_id"]; |
|
144 |
$dir = $web["document_root"]; |
026b48
|
145 |
$puser = $web["system_user"]; |
T |
146 |
$pgroup = $web["system_group"]; |
af8f1b
|
147 |
|
8e6584
|
148 |
// The FTP user shall be owned by the same group then the website |
T |
149 |
$sys_groupid = $web['sys_groupid']; |
|
150 |
|
|
151 |
$sql = "UPDATE shell_user SET server_id = $server_id, dir = '$dir', puser = '$puser', pgroup = '$pgroup', sys_groupid = '$sys_groupid' WHERE shell_user_id = ".$this->id; |
af8f1b
|
152 |
$app->db->query($sql); |
T |
153 |
|
|
154 |
} |
|
155 |
|
253e87
|
156 |
function onBeforeUpdate() { |
5190fe
|
157 |
global $app, $conf, $interfaceConf; |
253e87
|
158 |
|
T |
159 |
// check if the username is not blacklisted |
|
160 |
$blacklist = file(ISPC_LIB_PATH.'/shelluser_blacklist'); |
|
161 |
foreach($blacklist as $line) { |
5190fe
|
162 |
if(strtolower(trim($line)) == strtolower(trim($this->dataRecord['username']))){ |
V |
163 |
$app->tform->errorMessage .= 'The username is not allowed.'; |
|
164 |
} |
253e87
|
165 |
} |
T |
166 |
unset($blacklist); |
5190fe
|
167 |
|
V |
168 |
/* |
|
169 |
* If the names should be restricted -> do it! |
|
170 |
*/ |
db5aa6
|
171 |
if ($app->tform->errorMessage == '') { |
5190fe
|
172 |
/* |
V |
173 |
* If the names should be restricted -> do it! |
|
174 |
*/ |
db5aa6
|
175 |
$app->uses('getconf'); |
T |
176 |
$global_config = $app->getconf->get_global_config('sites'); |
|
177 |
$shelluser_prefix = ($global_config['shelluser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['shelluser_prefix']); |
|
178 |
|
|
179 |
/* restrict the names */ |
|
180 |
$this->dataRecord['username'] = $shelluser_prefix . $this->dataRecord['username']; |
5190fe
|
181 |
} |
253e87
|
182 |
} |
T |
183 |
|
af8f1b
|
184 |
function onAfterUpdate() { |
T |
185 |
global $app, $conf; |
|
186 |
|
|
187 |
|
|
188 |
} |
|
189 |
|
db5aa6
|
190 |
function getClientName() { |
T |
191 |
global $app, $conf; |
|
192 |
|
|
193 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
194 |
// Get the group-id of the user |
|
195 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
196 |
} else { |
|
197 |
// Get the group-id from the data itself |
|
198 |
$client_group_id = $this->dataRecord['client_group_id']; |
|
199 |
} |
|
200 |
/* get the name of the client */ |
|
201 |
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); |
|
202 |
$clientName = $tmp['name']; |
|
203 |
if ($clientName == "") $clientName = 'default'; |
|
204 |
$clientName = convertClientName($clientName); |
df22a8
|
205 |
|
T |
206 |
return $clientName; |
db5aa6
|
207 |
|
T |
208 |
} |
|
209 |
|
af8f1b
|
210 |
} |
T |
211 |
|
|
212 |
$page = new page_action; |
|
213 |
$page->onLoad(); |
|
214 |
|
|
215 |
?> |