commit | author | age
|
76a100
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
436ed8
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
76a100
|
5 |
All rights reserved. |
T |
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 validate_client { |
b1a6a5
|
32 |
|
76a100
|
33 |
/* |
T |
34 |
Validator function to check if a username is unique. |
|
35 |
*/ |
|
36 |
function username_unique($field_name, $field_value, $validator) { |
|
37 |
global $app; |
b1a6a5
|
38 |
|
79c08d
|
39 |
if(isset($app->remoting_lib->primary_id)) { |
T |
40 |
$client_id = $app->remoting_lib->primary_id; |
|
41 |
} else { |
|
42 |
$client_id = $app->tform->primary_id; |
|
43 |
} |
b1a6a5
|
44 |
|
79c08d
|
45 |
if($client_id == 0) { |
b1a6a5
|
46 |
$num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM sys_user WHERE username = '".$app->db->quote($field_value)."'"); |
76a100
|
47 |
if($num_rec["number"] > 0) { |
b1a6a5
|
48 |
$errmsg = $validator['errmsg']; |
MC |
49 |
if(isset($app->tform->wordbook[$errmsg])) { |
|
50 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
|
51 |
} else { |
|
52 |
return $errmsg."<br>\r\n"; |
|
53 |
} |
|
54 |
} |
|
55 |
} else { |
35509d
|
56 |
$num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM sys_user WHERE username = '".$app->db->quote($field_value)."' AND client_id != ".$app->functions->intval($client_id)); |
b1a6a5
|
57 |
if($num_rec["number"] > 0) { |
MC |
58 |
$errmsg = $validator['errmsg']; |
|
59 |
if(isset($app->tform->wordbook[$errmsg])) { |
|
60 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
76a100
|
61 |
} else { |
T |
62 |
return $errmsg."<br>\r\n"; |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
66 |
} |
b1a6a5
|
67 |
|
e94a9f
|
68 |
function username_collision($field_name, $field_value, $validator) { |
T |
69 |
global $app; |
b1a6a5
|
70 |
|
e94a9f
|
71 |
if(isset($app->remoting_lib->primary_id)) { |
T |
72 |
$client_id = $app->remoting_lib->primary_id; |
|
73 |
} else { |
|
74 |
$client_id = $app->tform->primary_id; |
|
75 |
} |
b1a6a5
|
76 |
|
e94a9f
|
77 |
$app->uses('getconf'); |
T |
78 |
$global_config = $app->getconf->get_global_config('sites'); |
b1a6a5
|
79 |
|
MC |
80 |
if((trim($field_value) == 'web' || preg_match('/^web[0-9]/', $field_value)) && |
|
81 |
($global_config['ftpuser_prefix'] == '[CLIENTNAME]' || |
|
82 |
$global_config['ftpuser_prefix'] == '' || |
|
83 |
$global_config['shelluser_prefix'] == '[CLIENTNAME]' || |
|
84 |
$global_config['shelluser_prefix'] == '' ) && |
|
85 |
$global_config['client_username_web_check_disabled'] == 'n') { |
e94a9f
|
86 |
$errmsg = $validator['errmsg']; |
T |
87 |
if(isset($app->tform->wordbook[$errmsg])) { |
|
88 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
|
89 |
} else { |
|
90 |
return $errmsg."<br>\r\n"; |
|
91 |
} |
|
92 |
} |
b1a6a5
|
93 |
|
MC |
94 |
|
|
95 |
|
|
96 |
|
e94a9f
|
97 |
} |
b1a6a5
|
98 |
|
bd6659
|
99 |
function check_used_servers($field_name, $field_value, $validator) |
SJ |
100 |
{ |
|
101 |
global $app; |
|
102 |
|
|
103 |
if (is_array($field_value)) |
|
104 |
{ |
|
105 |
$client_id = intval($_POST['id']); |
|
106 |
$used_servers = null; |
|
107 |
|
015dff
|
108 |
switch ($field_name) |
bd6659
|
109 |
{ |
015dff
|
110 |
case 'web_servers': |
MC |
111 |
$used_servers = $app->db->queryAllRecords('SELECT domain_id FROM web_domain INNER JOIN sys_user ON web_domain.sys_userid = sys_user.userid WHERE client_id = ' . $client_id . ' AND server_id NOT IN (' . implode(', ', $field_value) . ');'); |
|
112 |
break; |
bd6659
|
113 |
|
015dff
|
114 |
case 'dns_servers': |
MC |
115 |
$used_servers = $app->db->queryAllRecords('SELECT id FROM dns_rr INNER JOIN sys_user ON dns_rr.sys_userid = sys_user.userid WHERE client_id = ' . $client_id . ' AND server_id NOT IN (' . implode(', ', $field_value) . ');'); |
|
116 |
break; |
bd6659
|
117 |
|
015dff
|
118 |
case 'db_servers': |
MC |
119 |
$used_servers = $app->db->queryAllRecords('SELECT database_id FROM web_database INNER JOIN sys_user ON web_database.sys_userid = sys_user.userid WHERE client_id = ' . $client_id . ' AND server_id NOT IN (' . implode(', ', $field_value) . ');'); |
|
120 |
break; |
bd6659
|
121 |
|
015dff
|
122 |
case 'mail_servers': |
MC |
123 |
$used_servers = $app->db->queryAllRecords('SELECT domain_id FROM mail_domain INNER JOIN sys_user ON mail_domain.sys_userid = sys_user.userid WHERE client_id = ' . $client_id . ' AND server_id NOT IN (' . implode(', ', $field_value) . ');'); |
|
124 |
break; |
bd6659
|
125 |
} |
SJ |
126 |
|
015dff
|
127 |
if ($used_servers === null || count($used_servers)) |
MC |
128 |
{ |
bd6659
|
129 |
$errmsg = $validator['errmsg']; |
015dff
|
130 |
if(isset($app->tform->wordbook[$errmsg])) { |
bd6659
|
131 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
SJ |
132 |
} else { |
|
133 |
return $errmsg."<br>\r\n"; |
|
134 |
} |
015dff
|
135 |
} |
bd6659
|
136 |
} |
SJ |
137 |
} |
015dff
|
138 |
|
b1a6a5
|
139 |
|
MC |
140 |
|
|
141 |
|
|
142 |
} |