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) { |
cc7a82
|
46 |
$num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM sys_user WHERE username = ?", $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 { |
cc7a82
|
56 |
$num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM sys_user WHERE username = ? AND client_id != ?", $field_value, $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': |
cc7a82
|
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 = ? AND server_id NOT IN ?', $client_id, $field_value); |
015dff
|
112 |
break; |
bd6659
|
113 |
|
015dff
|
114 |
case 'dns_servers': |
cc7a82
|
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 = ? AND server_id NOT IN ?', $client_id, $field_value); |
015dff
|
116 |
break; |
bd6659
|
117 |
|
015dff
|
118 |
case 'db_servers': |
cc7a82
|
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 = ? AND server_id NOT IN ?', $client_id, $field_value); |
015dff
|
120 |
break; |
bd6659
|
121 |
|
015dff
|
122 |
case 'mail_servers': |
cc7a82
|
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 = ? AND server_id NOT IN ?', $client_id, $field_value); |
015dff
|
124 |
break; |
36c8a2
|
125 |
|
MF |
126 |
case 'xmpp_servers': |
cc7a82
|
127 |
$used_servers = $app->db->queryAllRecords('SELECT domain_id FROM xmpp_domain INNER JOIN sys_user ON xmpp_domain.sys_userid = sys_user.userid WHERE client_id = ? AND server_id NOT IN ?', $client_id, $field_value); |
36c8a2
|
128 |
break; |
bd6659
|
129 |
} |
SJ |
130 |
|
015dff
|
131 |
if ($used_servers === null || count($used_servers)) |
MC |
132 |
{ |
bd6659
|
133 |
$errmsg = $validator['errmsg']; |
015dff
|
134 |
if(isset($app->tform->wordbook[$errmsg])) { |
bd6659
|
135 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
SJ |
136 |
} else { |
|
137 |
return $errmsg."<br>\r\n"; |
|
138 |
} |
015dff
|
139 |
} |
bd6659
|
140 |
} |
SJ |
141 |
} |
015dff
|
142 |
|
12e147
|
143 |
function check_vat_id ($field_name, $field_value, $validator){ |
FT |
144 |
global $app, $page; |
|
145 |
|
|
146 |
$vatid = trim($field_value); |
|
147 |
if(isset($app->remoting_lib->primary_id)) { |
|
148 |
$country = $app->remoting_lib->dataRecord['country']; |
|
149 |
} else { |
|
150 |
$country = $page->dataRecord['country']; |
|
151 |
} |
|
152 |
|
|
153 |
// check if country is member of EU |
cc7a82
|
154 |
$country_details = $app->db->queryOneRecord("SELECT * FROM country WHERE iso = ?", $country); |
12e147
|
155 |
if($country_details['eu'] == 'y' && $vatid != ''){ |
FT |
156 |
|
|
157 |
$vatid = preg_replace('/\s+/', '', $vatid); |
|
158 |
$vatid = str_replace(array('.', '-', ','), '', $vatid); |
|
159 |
$cc = substr($vatid, 0, 2); |
|
160 |
$vn = substr($vatid, 2); |
b1a6a5
|
161 |
|
12e147
|
162 |
// Test if the country of the VAT-ID matches the country of the customer |
FT |
163 |
if($country != ''){ |
ccccf1
|
164 |
// Greece |
MC |
165 |
if($country == 'GR') $country = 'EL'; |
12e147
|
166 |
if(strtoupper($cc) != $country){ |
FT |
167 |
$errmsg = $validator['errmsg']; |
|
168 |
if(isset($app->tform->wordbook[$errmsg])) { |
|
169 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
|
170 |
} else { |
|
171 |
return $errmsg."<br>\r\n"; |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"); |
|
177 |
|
|
178 |
if($client){ |
|
179 |
$params = array('countryCode' => $cc, 'vatNumber' => $vn); |
|
180 |
try{ |
|
181 |
$r = $client->checkVat($params); |
|
182 |
if($r->valid == true){ |
|
183 |
} else { |
|
184 |
$errmsg = $validator['errmsg']; |
|
185 |
if(isset($app->tform->wordbook[$errmsg])) { |
|
186 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
|
187 |
} else { |
|
188 |
return $errmsg."<br>\r\n"; |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
// This foreach shows every single line of the returned information |
|
193 |
/* |
|
194 |
foreach($r as $k=>$prop){ |
|
195 |
echo $k . ': ' . $prop; |
|
196 |
} |
|
197 |
*/ |
|
198 |
|
|
199 |
} catch(SoapFault $e) { |
|
200 |
//echo 'Error, see message: '.$e->faultstring; |
|
201 |
switch ($e->faultstring) { |
|
202 |
case 'INVALID_INPUT': |
|
203 |
$errmsg = $validator['errmsg']; |
|
204 |
if(isset($app->tform->wordbook[$errmsg])) { |
|
205 |
return $app->tform->wordbook[$errmsg]."<br>\r\n"; |
|
206 |
} else { |
|
207 |
return $errmsg."<br>\r\n"; |
|
208 |
} |
|
209 |
break; |
|
210 |
// the following cases shouldn't be the user's fault, so we return no error |
|
211 |
case 'SERVICE_UNAVAILABLE': |
|
212 |
case 'MS_UNAVAILABLE': |
|
213 |
case 'TIMEOUT': |
|
214 |
case 'SERVER_BUSY': |
|
215 |
break; |
|
216 |
} |
|
217 |
} |
|
218 |
} else { |
|
219 |
// Connection to host not possible, europe.eu down? |
|
220 |
// this shouldn't be the user's fault, so we return no error |
|
221 |
} |
|
222 |
} |
|
223 |
} |
b1a6a5
|
224 |
|
MC |
225 |
|
|
226 |
} |