root/trunk/gui/include/ispcp-functions.php

Revision 1327, 10.2 kB (checked in by rats, 4 months ago)

* Fixed: --scan-knownbad-files and --check-deleted are no longer supported by rkhunter
* Fixed #1471: chkrootkit should be in lenny / hardy
* Updated Chinese (simplified)
* Updated German
* Fixed #1475: typo on installation (ispcp-setup)
* Fixed: default user for rkhunter.log

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 function check_for_lock_file($wait_lock_timeout = 500000) {
22
23     set_time_limit(0);
24     // @ prevents the Warning:
25     // File(/var/log/chkrootkit.log) is not within the allowed path(s)
26     while(@file_exists(Config::get('MR_LOCK_FILE'))) {
27
28         usleep($wait_lock_timeout);
29         clearstatcache();
30         // and send header to keep connection
31         header( "Cache-Control: no-store, no-cache, must-revalidate" );
32     }
33 }
34
35 function read_line(&$socket) {
36     $ch = '';
37     $line = '';
38     do {
39         $ch = socket_read($socket,1);
40         $line = $line . $ch;
41     } while($ch != "\r" && $ch != "\n");
42     return $line;
43 }
44
45 function send_request() {
46
47     global $Version;
48
49     $code = 999;
50
51     @$socket = socket_create (AF_INET, SOCK_STREAM, 0);
52     if ($socket < 0) {
53         $errno "socket_create() failed.\n";
54         return $errno;
55     }
56
57     @$result = socket_connect ($socket, '127.0.0.1', 9876);
58     if ($result == FALSE) {
59         $errno "socket_connect() failed.\n";
60         return $errno;
61     }
62
63     /* read one line with welcome string */
64     $out = read_line($socket);
65
66     list($code) = explode(' ', $out);
67     if ($code == 999) {
68         return $out;
69     }
70
71     /* send hello query */
72     $query = "helo  $Version\r\n";
73     socket_write ($socket, $query, strlen ($query));
74
75     /* read one line with helo answer */
76     $out = read_line($socket);
77
78     list($code) = explode(' ', $out);
79     if ($code == 999) {
80         return $out;
81     }
82
83     /* send reg check query */
84     $query = "execute query\r\n";
85     socket_write ($socket, $query, strlen ($query));
86     /* read one line key replay */
87     $execute_reply = read_line($socket);
88
89     list($code) = explode(' ', $execute_reply);
90     if ($code == 999) {
91         return $out;
92     }
93
94     /* send quit query */
95     $quit_query = "bye\r\n";
96     socket_write ($socket, $quit_query, strlen ($quit_query));
97     /* read quit answer */
98     $quit_reply = read_line($socket);
99
100     list($code) = explode(' ', $quit_reply);
101     if ($code == 999) {
102         return $out;
103     }
104
105     list($answer) = explode(' ', $execute_reply);
106
107     socket_close ($socket);
108
109     return $answer;
110
111 }
112
113
114 function update_user_props ( $user_id, $props ) {
115
116     $sql = Database::getInstance();
117
118     list (
119            $sub_current, $sub_max,
120            $als_current, $als_max,
121            $mail_current, $mail_max,
122            $ftp_current, $ftp_max,
123            $sql_db_current, $sql_db_max,
124            $sql_user_current, $sql_user_max,
125            $traff_max, $disk_max,
126            $domain_php, $domain_cgi) = explode (";", $props);
127            //$domain_ip_id, $domain_php, $domain_cgi) = explode (";", $props);
128
129          //have to check if PHP and/or CGI and/or IP change
130          $domain_last_modified time();
131
132     $query = <<<SQL_QUERY
133         select
134             domain_name
135         from
136             domain
137         where
138             domain_id  = ?
139           and
140             domain_php = ?
141           and
142             domain_cgi = ?
143 SQL_QUERY;
144
145     $rs = exec_query($sql, $query, array($user_id, $domain_php, $domain_cgi));
146
147     if ($rs -> RecordCount() == 0) {
148         // mama mia, we have to rebuild the system entry for this domain
149         // and also all domain alias and subdomains
150
151         $update_status = Config::get('ITEM_CHANGE_STATUS');
152
153         // check if we have to wait some system update
154         check_for_lock_file();
155         // ... and go update
156
157         // update the domain
158         $query = <<<SQL_QUERY
159         update
160             domain
161         set
162             domain_last_modified = ?,
163             domain_mailacc_limit = ?,
164             domain_ftpacc_limit = ?,
165             domain_traffic_limit = ?,
166             domain_sqld_limit = ?,
167             domain_sqlu_limit = ?,
168             domain_status = ?,
169             domain_alias_limit = ?,
170             domain_subd_limit = ?,
171             domain_disk_limit = ?,
172             domain_php = ?,
173             domain_cgi = ?
174         where
175             domain_id  = ?
176 SQL_QUERY;
177
178         $rs = exec_query($sql, $query, array($domain_last_modified,
179                                          $mail_max,
180                                          $ftp_max,
181                                          $traff_max,
182                                          $sql_db_max,
183                                          $sql_user_max,
184                                          $update_status,
185                                          $als_max,
186                                          $sub_max,
187                                          $disk_max,
188                                          $domain_php,
189                                          $domain_cgi,
190                                          $user_id));
191
192         // lets update all alias domains for this domain
193
194     $query = <<<SQL_QUERY
195         update
196             domain_aliasses
197         set
198             alias_status = ?
199         where
200             domain_id  = ?
201 SQL_QUERY;
202
203     $rs = exec_query($sql, $query, array($update_status, $user_id));
204
205     while (!$rs -> EOF) {
206             $rs -> MoveNext();
207         }
208
209         // lets update all subdomains for this domain
210
211     $query = <<<SQL_QUERY
212         update
213             subdomain
214         set
215             subdomain_status = ?
216         where
217             domain_id  = ?
218 SQL_QUERY;
219
220         $rs = exec_query($sql, $query, array($update_status, $user_id));
221         while (!$rs -> EOF) {
222             $rs -> MoveNext();
223         }
224
225         // and now we start the daemon
226         send_request();
227
228
229     } else {
230
231         // we do not have IP and/or PHP and/or CGI changes
232         // we have to update only the domain props and not
233         // to rebuild system entries
234
235          $query = <<<SQL_QUERY
236         update
237             domain
238         set
239             domain_subd_limit = ?,
240             domain_alias_limit = ?,
241             domain_mailacc_limit = ?,
242             domain_ftpacc_limit = ?,
243             domain_sqld_limit = ?,
244             domain_sqlu_limit = ?,
245             domain_traffic_limit = ?,
246             domain_disk_limit = ?
247         where
248             domain_id = ?
249
250 SQL_QUERY;
251
252         $rs = exec_query($sql, $query, array($sub_max,
253                                            $als_max,
254                                            $mail_max,
255                                            $ftp_max,
256                                            $sql_db_max,
257                                            $sql_user_max,
258                                            $traff_max,
259                                            $disk_max,
260                                            $user_id));
261   }
262
263 }
264
265 /* end */
266
267 function escape_user_data ( $data ) {
268
269     $res_one = preg_replace("/\\\\/", "", $data);
270
271     $res = preg_replace("/'/", "\\\'", $res_one);
272
273     return $res;
274
275 }
276
277 function array_decode_idna($arr, $asPath = false) {
278     if ($asPath && !is_array($arr)) {
279         return implode('/', array_decode_idna(explode('/', $arr)));
280     }
281
282     foreach ($arr as $k => $v) {
283         $arr[$k] = decode_idna($v);
284     }
285     return $arr;
286 }
287
288 function array_encode_idna($arr, $asPath = false) {
289
290     if ($asPath && !is_array($arr)) {
291         return implode('/', array_encode_idna(explode('/', $arr)));
292     }
293
294     foreach ($arr as $k => $v) {
295         $arr[$k] = encode_idna($v);
296     }
297     return $arr;
298 }
299
300 function decode_idna($input)
301 {
302     if (function_exists('idn_to_unicode')) {
303         return idn_to_unicode($input, 'utf-8');
304     }
305
306     $IDN = new idna_convert();
307     $output = $IDN->decode($input);
308
309     if ($output == FALSE){
310         return $input;
311     } else {
312         return $output;
313     }
314 }
315
316 function encode_idna($input)
317 {
318     if (function_exists('idn_to_ascii')) {
319         return idn_to_ascii($input, 'utf-8');
320     }
321
322     $IDN = new idna_convert();
323     $output = $IDN->encode($input);
324     return $output;
325 }
326
327 function strip_html($input)
328 {
329     $output = htmlspecialchars($input, ENT_QUOTES, "UTF-8");
330     return $output;
331 }
332
333 function is_number($integer) {
334     if (preg_match('/^[0-9]+$/D', $integer)) {
335         return true;
336     }
337     return false;
338 }
339
340 function is_basicString($sting) {
341     if (preg_match('/^[a-zA-Z0-9_-]+$/D', $sting)) {
342         return true;
343     }
344     return false;
345 }
346
347 function unset_messages () {
348
349     $glToUnset = array();
350     $glToUnset[] = 'user_page_message';
351     $glToUnset[] = 'user_updated';
352     $glToUnset[] = 'user_updated';
353     $glToUnset[] = 'dmn_tpl';
354     $glToUnset[] = 'chtpl';
355     $glToUnset[] = 'step_one';
356     $glToUnset[] = 'step_two_data';
357     $glToUnset[] = 'ch_hpprops';
358     $glToUnset[] = 'user_add3_added';
359     $glToUnset[] = 'user_has_domain';
360     $glToUnset[] = 'local_data';
361     $glToUnset[] = 'reseller_added';
362     $glToUnset[] = 'user_added';
363     $glToUnset[] = 'aladd';
364     $glToUnset[] = 'edit_ID';
365     $glToUnset[] = 'hp_added';
366     $glToUnset[] = 'aldel';
367     $glToUnset[] = 'hpid';
368     $glToUnset[] = 'user_deleted';
369     $glToUnset[] = 'hdomain';
370     $glToUnset[] = 'aledit';
371     $glToUnset[] = 'acreated_by';
372     $glToUnset[] = 'dhavesub';
373     $glToUnset[] = 'ddel';
374     $glToUnset[] = 'dhavealias';
375     $glToUnset[] = 'dhavealias';
376     $glToUnset[] = 'dadel';
377     $glToUnset[] = 'local_data';
378
379     foreach ($glToUnset as $toUnset) {
380         if (array_key_exists($toUnset,$GLOBALS))
381             unset($GLOBALS[$toUnset]);
382     }
383
384     $sessToUnset = array();
385     $sessToUnset[] = 'reseller_added';
386     $sessToUnset[] = 'dmn_name';
387     $sessToUnset[] = 'dmn_tpl';
388     $sessToUnset[] = 'chtpl';
389     $sessToUnset[] = 'step_one';
390     $sessToUnset[] = 'step_two_data';
391     $sessToUnset[] = 'ch_hpprops';
392     $sessToUnset[] = 'user_add3_added';
393     $sessToUnset[] = 'user_has_domain';
394     $sessToUnset[] = 'user_added';
395     $sessToUnset[] = 'aladd';
396     $sessToUnset[] = 'edit_ID';
397     $sessToUnset[] = 'hp_added';
398     $sessToUnset[] = 'aldel';
399     $sessToUnset[] = 'hpid';
400     $sessToUnset[] = 'user_deleted';
401     $sessToUnset[] = 'hdomain';
402     $sessToUnset[] = 'aledit';
403     $sessToUnset[] = 'acreated_by';
404     $sessToUnset[] = 'dhavesub';
405     $sessToUnset[] = 'ddel';
406     $sessToUnset[] = 'dhavealias';
407     $sessToUnset[] = 'dadel';
408     $sessToUnset[] = 'local_data';
409
410     foreach ($sessToUnset as $toUnset) {
411         if (array_key_exists($toUnset,$_SESSION))
412             unset($_SESSION[$toUnset]);
413     }
414 }
415
416 ?>
Note: See TracBrowser for help on using the browser.