mcramer
2012-06-18 a932880cc9dcd6da7e42f5a69534322c79f75953
commit | author | age
532ae5 1 <?php
L 2
3 /*
077c27 4 Copyright (c) 2007 - 2011, Till Brehm, projektfarm Gmbh
532ae5 5 All rights reserved.
L 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 --UPDATED 08.2009--
31 Full SOAP support for ISPConfig 3.1.4 b
32 Updated by Arkadiusz Roch & Artur Edelman
33 Copyright (c) Tri-Plex technology
34
35 */
36
37 class remoting {
38     
39     //* remote session timeout in seconds
40     private $session_timeout = 600;
41     
a93288 42     protected $server;
532ae5 43     public $oldDataRecord;
L 44     public $dataRecord;
45     public $id;
46     
47     /*
48     These variables shall stay global. 
49     Please do not make them private variables.
50     
51     private $app;
52     private $conf;
53     */
54
55     public function __construct()
56     {
57         global $server;
58         $this->server = $server;
59         /*
60         $this->app = $app;
61         $this->conf = $conf;
62         */
63     }
64
65     //* remote login function
66     public function login($username, $password)
67     {
68         global $app, $conf, $server;
69         
bf7d95 70         // Maintenance mode
F 71         $app->uses('ini_parser,getconf');
72         $server_config_array = $app->getconf->get_global_config('misc');
73         if($server_config_array['maintenance_mode'] == 'y'){
74             $this->server->fault('maintenance_mode', 'This ISPConfig installation is currently under maintenance. We should be back shortly. Thank you for your patience.');
75             return false;
76         }
77         
532ae5 78         if(empty($username)) {
bf7d95 79             $this->server->fault('login_username_empty', 'The login username is empty.');
532ae5 80             return false;
L 81         }
82         
83         if(empty($password)) {
bf7d95 84             $this->server->fault('login_password_empty', 'The login password is empty.');
532ae5 85             return false;
L 86         }
87         
88         //* Delete old remoting sessions
89         $sql = "DELETE FROM remote_session WHERE tstamp < ".time();
90         $app->db->query($sql);
91         
92         $username = $app->db->quote($username);
93         $password = $app->db->quote($password);
94         
95         $sql = "SELECT * FROM remote_user WHERE remote_username = '$username' and remote_password = md5('$password')";
96         $remote_user = $app->db->queryOneRecord($sql);
97         if($remote_user['remote_userid'] > 0) {
98             //* Create a remote user session
99             srand ((double)microtime()*1000000);
100             $remote_session = md5(rand());
101             $remote_userid = $remote_user['remote_userid'];
102             $remote_functions = $remote_user['remote_functions'];
103             $tstamp = time() + $this->session_timeout;
104             $sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp'
105                    .') VALUES ('
106                    ." '$remote_session',$remote_userid,'$remote_functions',$tstamp)";
107             $app->db->query($sql);
108             return $remote_session;
109         } else {
110             $this->server->fault('login_failed', 'The login failed. Username or password wrong.');
111             return false;
112         }
113         
114     }
115     
116     //* remote logout function
117     public function logout($session_id)
118     {        
119         global $app;
120         
121         if(empty($session_id)) {
122             $this->server->fault('session_id_empty', 'The SessionID is empty.');
123             return false;
124         }
125         
126         $session_id = $app->db->quote($session_id);
127         
128         $sql = "DELETE FROM remote_session WHERE remote_session = '$session_id'";
129         $app->db->query($sql);
130         return ($app->db->affectedRows() == 1);
131     }
132     
133
134     /**
135         Gets the server configuration
136         @param int session id
137         @param int server id
138         @param string  section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
139         @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
140     */
141     public function server_get($session_id, $server_id, $section ='') {
142         global $app;        
143         if(!$this->checkPerm($session_id, 'server_get')) {
144             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
145             return false;
146         }
147         if (!empty($session_id) && !empty($server_id)) {    
148             $app->uses('remoting_lib , getconf');        
149             $section_config =  $app->getconf->get_server_config($server_id,$section);        
150             return $section_config;
151         } else {
152             return false;
153         }
154     }
155     
1ca823 156     public function server_get_serverid_by_ip($session_id, $ipaddress)
T 157     {
158         global $app;
159         if(!$this->checkPerm($session_id, 'server_get_serverid_by_ip')) {
160             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
161             return false;
162         }
163         $sql = "SELECT server_id FROM server_ip WHERE ip_address  = '$ipaddress' LIMIT 1 ";
164         $all = $app->db->queryAllRecords($sql);
165         return $all;
166     }
167     
b67344 168     //* Add a IP address record
T 169     public function server_ip_add($session_id, $client_id, $params)
170     {
171         if(!$this->checkPerm($session_id, 'server_ip_add')) {
172             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
173             return false;
174         }
175         return $this->insertQuery('../admin/form/server_ip.tform.php',$client_id,$params);
176     }
177     
178     //* Update IP address record
179     public function server_ip_update($session_id, $client_id, $ip_id, $params)
180     {
181         if(!$this->checkPerm($session_id, 'server_ip_update')) {
182             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
183             return false;
184         }
185         $affected_rows = $this->updateQuery('../admin/form/server_ip.tform.php',$client_id,$ip_id,$params);
186         return $affected_rows;
187     }
188     
189     //* Delete IP address record
190     public function server_ip_delete($session_id, $ip_id)
191     {
192         if(!$this->checkPerm($session_id, 'server_ip_delete')) {
193             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
194             return false;
195         }
196         $affected_rows = $this->deleteQuery('../admin/form/server_ip.tform.php',$ip_id);
197         return $affected_rows;
198     }
199     
532ae5 200     //* Get mail domain details
L 201     public function mail_domain_get($session_id, $primary_id)
202     {
203         global $app;
204         
205         if(!$this->checkPerm($session_id, 'mail_domain_get')) {
206             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
207             return false;
208         }
209         $app->uses('remoting_lib');
210         $app->remoting_lib->loadFormDef('../mail/form/mail_domain.tform.php');
211         return $app->remoting_lib->getDataRecord($primary_id);
212     }
213     
214     //* Add a mail domain
215     public function mail_domain_add($session_id, $client_id, $params)
216     {
217         if(!$this->checkPerm($session_id, 'mail_domain_add')) {
218             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
219             return false;
220         }
221         $primary_id = $this->insertQuery('../mail/form/mail_domain.tform.php',$client_id,$params);
222         return $primary_id;
223     }
224     
225     //* Update a mail domain
226     public function mail_domain_update($session_id, $client_id, $primary_id, $params)
227     {
228         if(!$this->checkPerm($session_id, 'mail_domain_update')) {
229             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
230             return false;
231         }
232         $affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php', $client_id, $primary_id, $params);
233         return $affected_rows;
234     }
235     
236     //* Delete a mail domain
237     public function mail_domain_delete($session_id, $primary_id)
238     {
239         if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
240             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
241             return false;
242         }
243         $affected_rows = $this->deleteQuery('../mail/form/mail_domain.tform.php', $primary_id);
244         return $affected_rows;
245     }
246     
04620b 247     //* Get mail mailinglist details
T 248     public function mail_mailinglist_get($session_id, $primary_id)
249     {
250         global $app;
251         
252         if(!$this->checkPerm($session_id, 'mail_mailinglist_get')) {
253             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
254             return false;
255         }
256         $app->uses('remoting_lib');
257         $app->remoting_lib->loadFormDef('../mail/form/mail_mailinglist.tform.php');
258         return $app->remoting_lib->getDataRecord($primary_id);
259     }
260     
261     //* Add a mail mailinglist
262     public function mail_mailinglist_add($session_id, $client_id, $params)
263     {
264         if(!$this->checkPerm($session_id, 'mail_mailinglist_add')) {
265             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
266             return false;
267         }
268         $primary_id = $this->insertQuery('../mail/form/mail_mailinglist.tform.php',$client_id,$params);
269         return $primary_id;
270     }
271     
272     //* Update a mail mailinglist
273     public function mail_mailinglist_update($session_id, $client_id, $primary_id, $params)
274     {
275         if(!$this->checkPerm($session_id, 'mail_mailinglist_update')) {
276             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
277             return false;
278         }
279         $affected_rows = $this->updateQuery('../mail/form/mail_mailinglist.tform.php', $client_id, $primary_id, $params);
280         return $affected_rows;
281     }
282     
283     //* Delete a mail mailinglist
284     public function mail_mailinglist_delete($session_id, $primary_id)
285     {
286         if(!$this->checkPerm($session_id, 'mail_mailinglist_delete')) {
287             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
288             return false;
289         }
290         $affected_rows = $this->deleteQuery('../mail/form/mail_mailinglist.tform.php', $primary_id);
291         return $affected_rows;
292     }
293     
532ae5 294     //* Get mail user details
L 295     public function mail_user_get($session_id, $primary_id)
296     {
297         global $app;
298         
299         if(!$this->checkPerm($session_id, 'mail_user_get')) {
300             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
301             return false;
302         }
303         $app->uses('remoting_lib');
304         $app->remoting_lib->loadFormDef('../mail/form/mail_user.tform.php');
305         return $app->remoting_lib->getDataRecord($primary_id);
306     }
307     
308     
309     //* dodanie uzytkownika email
310     public function mail_user_add($session_id, $client_id, $params){
311         if (!$this->checkPerm($session_id, 'mail_user_add')){
312             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
313             return false;
314         }
315         $affected_rows = $this->insertQuery('../mail/form/mail_user.tform.php', $client_id, $params);
316         return $affected_rows;
317     }
318
319     //* edycja uzytkownika email    
320     public function mail_user_update($session_id, $client_id, $primary_id, $params)
321     {
322         if (!$this->checkPerm($session_id, 'mail_user_update'))
323         {
324             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
325             return false;
326         }
327         $affected_rows = $this->updateQuery('../mail/form/mail_user.tform.php', $client_id, $primary_id, $params);
328         return $affected_rows;
329     }
330
331     
332     //*usuniecie uzytkownika emial
333     public function mail_user_delete($session_id, $primary_id)
334     {
335         if (!$this->checkPerm($session_id, 'mail_user_delete'))
336         {
337             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
338             return false;
339         }
340         $affected_rows = $this->deleteQuery('../mail/form/mail_user.tform.php', $primary_id);
341         return $affected_rows;
342     }
343     
344     //* Get mail user filter details
345     public function mail_user_filter_get($session_id, $primary_id)
346     {
347         global $app;
348         
349         if(!$this->checkPerm($session_id, 'mail_user_filter_get')) {
350             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
351             return false;
352         }
353         $app->uses('remoting_lib');
354         $app->remoting_lib->loadFormDef('../mail/form/mail_user_filter.tform.php');
355         return $app->remoting_lib->getDataRecord($primary_id);
356     }
357     
358     public function mail_user_filter_add($session_id, $client_id, $params)
359     {
360         global $app;
361         if (!$this->checkPerm($session_id, 'mail_user_filter_add')){
362             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
363             return false;
364         }
365         $affected_rows = $this->insertQuery('../mail/form/mail_user_filter.tform.php', $client_id, $params,'mail:mail_user_filter:on_after_insert');
366         // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_insert',$this);
367         return $affected_rows;
368     }
369
370     public function mail_user_filter_update($session_id, $client_id, $primary_id, $params)
371     {
372         global $app;
373         if (!$this->checkPerm($session_id, 'mail_user_filter_update'))
374         {
375             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
376             return false;
377         }
378         $affected_rows = $this->updateQuery('../mail/form/mail_user_filter.tform.php', $client_id, $primary_id, $params,'mail:mail_user_filter:on_after_update');
379         // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_update',$this);
380         return $affected_rows;
381     }
382
383     public function mail_user_filter_delete($session_id, $primary_id)
384     {
385         global $app;
386         if (!$this->checkPerm($session_id, 'mail_user_filter_delete'))
387         {
388             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
389             return false;
390         }
355efb 391         $affected_rows = $this->deleteQuery('../mail/form/mail_user_filter.tform.php', $primary_id,'mail:mail_user_filter:on_after_delete');
T 392         // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_delete',$this);
532ae5 393         return $affected_rows;
L 394     }
395
396     //* Get alias details
397     public function mail_alias_get($session_id, $primary_id)
398     {
399         global $app;
400         
401         if(!$this->checkPerm($session_id, 'mail_alias_get')) {
402             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
403             return false;
404         }
405         $app->uses('remoting_lib');
406         $app->remoting_lib->loadFormDef('../mail/form/mail_alias.tform.php');
407         return $app->remoting_lib->getDataRecord($primary_id);
408     }
409     
410     //* aliasy email
411     public function mail_alias_add($session_id, $client_id, $params)
412     {
413         if (!$this->checkPerm($session_id, 'mail_alias_add'))
414         {
415             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
416             return false;
417         }
418         $affected_rows = $this->insertQuery('../mail/form/mail_alias.tform.php', $client_id, $params);
419         return $affected_rows;
420     }
421
422
423     public function mail_alias_update($session_id, $client_id, $primary_id, $params)
424     {
425             if (!$this->checkPerm($session_id, 'mail_alias_update'))
426             {
427                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
428                     return false;
429             }
430             $affected_rows = $this->updateQuery('../mail/form/mail_alias.tform.php', $client_id, $primary_id, $params);
431             return $affected_rows;
432     }
433
434     public function mail_alias_delete($session_id, $primary_id)
435     {
436             if (!$this->checkPerm($session_id, 'mail_alias_delete'))
437             {
438                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
439                     return false;
440             }
441             $affected_rows = $this->deleteQuery('../mail/form/mail_alias.tform.php', $primary_id);
442             return $affected_rows;
443     }
444     
445     //* Get mail forwarding details
446     public function mail_forward_get($session_id, $primary_id)
447     {
448         global $app;
449         
450         if(!$this->checkPerm($session_id, 'mail_forward_get')) {
451             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
452             return false;
453         }
454         $app->uses('remoting_lib');
455         $app->remoting_lib->loadFormDef('../mail/form/mail_forward.tform.php');
456         return $app->remoting_lib->getDataRecord($primary_id);
457     }
458     
459      //* przekierowania email
460     public function mail_forward_add($session_id, $client_id, $params)
461     {
462             if (!$this->checkPerm($session_id, 'mail_forward_add'))
463             {
464                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
465                     return false;
466             }
467             $affected_rows = $this->insertQuery('../mail/form/mail_forward.tform.php', $client_id, $params);
468             return $affected_rows;
469     }
470
471
472     public function mail_forward_update($session_id, $client_id, $primary_id, $params)
473     {
474             if (!$this->checkPerm($session_id, 'mail_forward_update'))
475             {
476                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
477                     return false;
478             }
479             $affected_rows = $this->updateQuery('../mail/form/mail_forward.tform.php', $client_id, $primary_id, $params);
480             return $affected_rows;
481     }
482
483
484     public function mail_forward_delete($session_id, $primary_id)
485     {
486             if (!$this->checkPerm($session_id, 'mail_forward_delete'))
487             {
488                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
489                     return false;
490             }
491             $affected_rows = $this->deleteQuery('../mail/form/mail_forward.tform.php', $primary_id);
492             return $affected_rows;
493     }
494     
495     //* Get catchall details
496     public function mail_catchall_get($session_id, $primary_id)
497     {
498         global $app;
499         
500         if(!$this->checkPerm($session_id, 'mail_catchall_get')) {
501             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
502             return false;
503         }
504         $app->uses('remoting_lib');
505         $app->remoting_lib->loadFormDef('../mail/form/mail_domain_catchall.tform.php');
506         return $app->remoting_lib->getDataRecord($primary_id);
507     }
508
509     //* catchall e-mail
510      public function mail_catchall_add($session_id, $client_id, $params)
511     {
512             if (!$this->checkPerm($session_id, 'mail_catchall_add'))
513             {
514                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
515                     return false;
516             }
517             $affected_rows = $this->insertQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $params);
518             return $affected_rows;
519     }
520
521     public function mail_catchall_update($session_id, $client_id, $primary_id, $params)
522     {
523             if (!$this->checkPerm($session_id, 'mail_catchall_update'))
524             {
525                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
526                     return false;
527             }
528             $affected_rows = $this->updateQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $primary_id, $params);
529             return $affected_rows;
530     }
531
532     public function mail_catchall_delete($session_id, $primary_id)
533     {
534             if (!$this->checkPerm($session_id, 'mail_catchall_delete'))
535             {
536                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
537                     return false;
538             }
539             $affected_rows = $this->deleteQuery('../mail/form/mail_domain_catchall.tform.php', $primary_id);
540             return $affected_rows;
541     }
542     
543     //* Get transport details
544     public function mail_transport_get($session_id, $primary_id)
545     {
546         global $app;
547         
548         if(!$this->checkPerm($session_id, 'mail_transport_get')) {
549             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
550             return false;
551         }
552         $app->uses('remoting_lib');
553         $app->remoting_lib->loadFormDef('../mail/form/mail_transport.tform.php');
554         return $app->remoting_lib->getDataRecord($primary_id);
555     }
556     
557     //* przeniesienia e-mail
558     public function mail_transport_add($session_id, $client_id, $params)
559     {
560             if (!$this->checkPerm($session_id, 'mail_transport_add'))
561             {
562                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
563                     return false;
564             }
565             $affected_rows = $this->insertQuery('../mail/form/mail_transport.tform.php', $client_id, $params);
566             return $affected_rows;
567     }
568
569
570     public function mail_transport_update($session_id, $client_id, $primary_id, $params)
571     {
572             if (!$this->checkPerm($session_id, 'mail_transport_update'))
573             {
574                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
575                     return false;
576             }
577             $affected_rows = $this->updateQuery('../mail/form/mail_transport.tform.php', $client_id, $primary_id, $params);
578             return $affected_rows;
579     }
580
581
582     public function mail_transport_delete($session_id, $primary_id)
583     {
584             if (!$this->checkPerm($session_id, 'mail_transport_delete'))
585             {
586                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
587                     return false;
588             }
589             $affected_rows = $this->deleteQuery('../mail/form/mail_transport.tform.php', $primary_id);
590             return $affected_rows;
591     }
592     
593     //* Get spamfilter whitelist details
594     public function mail_spamfilter_whitelist_get($session_id, $primary_id)
595     {
596         global $app;
597         
598         if(!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_get')) {
599             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
600             return false;
601         }
602         $app->uses('remoting_lib');
603         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_whitelist.tform.php');
604         return $app->remoting_lib->getDataRecord($primary_id);
605     }
606
607      //* biaÅ‚a lista e-mail
608     public function mail_spamfilter_whitelist_add($session_id, $client_id, $params)
609     {
610             if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_add'))
611             {
612                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
613                     return false;
614             }
615             $affected_rows = $this->insertQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $params);
616             return $affected_rows;
617     }
618
619
620     public function mail_spamfilter_whitelist_update($session_id, $client_id, $primary_id, $params)
621     {
622             if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_update'))
623             {
624                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
625                     return false;
626             }
627             $affected_rows = $this->updateQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $primary_id, $params);
628             return $affected_rows;
629     }
630
631
632     public function mail_spamfilter_whitelist_delete($session_id, $primary_id)
633     {
634             if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_delete'))
635             {
636                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
637                     return false;
638             }
639             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_whitelist.tform.php', $primary_id);
640             return $affected_rows;
641     }
642     
643     //* Get spamfilter blacklist details
644     public function mail_spamfilter_blacklist_get($session_id, $primary_id)
645     {
646         global $app;
647         
648         if(!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_get')) {
649             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
650             return false;
651         }
652         $app->uses('remoting_lib');
653         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_blacklist.tform.php');
654         return $app->remoting_lib->getDataRecord($primary_id);
655     }
656     
657      //* czarna lista e-mail
658     public function mail_spamfilter_blacklist_add($session_id, $client_id, $params)
659     {
660             if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_add'))
661             {
662                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
663                     return false;
664             }
665             $affected_rows = $this->insertQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $params);
666             return $affected_rows;
667     }
668
669
670     public function mail_spamfilter_blacklist_update($session_id, $client_id, $primary_id, $params)
671     {
672             if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_update'))
673             {
674                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
675                     return false;
676             }
677             $affected_rows = $this->updateQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $primary_id, $params);
678             return $affected_rows;
679     }
680
681
682     public function mail_spamfilter_blacklist_delete($session_id, $primary_id)
683     {
684             if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_delete'))
685             {
686                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
687                     return false;
688             }
689             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_blacklist.tform.php', $primary_id);
690             return $affected_rows;
691     }
692     
693     //* Get spamfilter user details
694     public function mail_spamfilter_user_get($session_id, $primary_id)
695     {
696         global $app;
697         
698         if(!$this->checkPerm($session_id, 'mail_spamfilter_user_get')) {
699             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
700             return false;
701         }
702         $app->uses('remoting_lib');
703         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_users.tform.php');
704         return $app->remoting_lib->getDataRecord($primary_id);
705     }
706
707     //* filtr spamu użytkowników e-mail
708     public function mail_spamfilter_user_add($session_id, $client_id, $params)
709     {
710             if (!$this->checkPerm($session_id, 'mail_spamfilter_user_add'))
711             {
712                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
713                     return false;
714             }
715             $affected_rows = $this->insertQuery('../mail/form/spamfilter_users.tform.php', $client_id, $params);
716             return $affected_rows;
717     }
718
719
720     public function mail_spamfilter_user_update($session_id, $client_id, $primary_id, $params)
721     {
722             if (!$this->checkPerm($session_id, 'mail_spamfilter_user_update'))
723             {
724                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
725                     return false;
726             }
727             $affected_rows = $this->updateQuery('../mail/form/spamfilter_users.tform.php', $client_id, $primary_id, $params);
728             return $affected_rows;
729     }
730
731
732     public function mail_spamfilter_user_delete($session_id, $primary_id)
733     {
734             if (!$this->checkPerm($session_id, 'mail_spamfilter_user_delete'))
735             {
736                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
737                     return false;
738             }
739             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_users.tform.php', $primary_id);
740             return $affected_rows;
741     }
742     
743     //* Get policy details
744     public function mail_policy_get($session_id, $primary_id)
745     {
746         global $app;
747         
748         if(!$this->checkPerm($session_id, 'mail_policy_get')) {
749             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
750             return false;
751         }
752         $app->uses('remoting_lib');
753         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_policy.tform.php');
754         return $app->remoting_lib->getDataRecord($primary_id);
755     }
756     
757      //* polityki filtrów spamu e-mail
758     public function mail_policy_add($session_id, $client_id, $params)
759     {
760             if (!$this->checkPerm($session_id, 'mail_policy_add'))
761             {
762                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
763                     return false;
764             }
765             $affected_rows = $this->insertQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $params);
766             return $affected_rows;
767     }
768
769
770     public function mail_policy_update($session_id, $client_id, $primary_id, $params)
771     {
772             if (!$this->checkPerm($session_id, 'mail_policy_update'))
773             {
774                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
775                     return false;
776             }
777             $affected_rows = $this->updateQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $primary_id, $params);
778             return $affected_rows;
779     }
780
781
782     public function mail_policy_delete($session_id, $primary_id)
783     {
784             if (!$this->checkPerm($session_id, 'mail_policy_delete'))
785             {
786                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
787                     return false;
788             }
789             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_policy.tform.php', $primary_id);
790             return $affected_rows;
791     }
792     
793     //* Get fetchmail details
794     public function mail_fetchmail_get($session_id, $primary_id)
795     {
796         global $app;
797         
798         if(!$this->checkPerm($session_id, 'mail_fetchmail_get')) {
799             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
800             return false;
801         }
802         $app->uses('remoting_lib');
803         $app->remoting_lib->loadFormDef('../mail/form/mail_get.tform.php');
804         return $app->remoting_lib->getDataRecord($primary_id);
805     }
806
807      //* fetchmail
808     public function mail_fetchmail_add($session_id, $client_id, $params)
809     {
810             if (!$this->checkPerm($session_id, 'mail_fetchmail_add'))
811             {
812                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
813                     return false;
814             }
815             $affected_rows = $this->insertQuery('../mail/form/mail_get.tform.php', $client_id, $params);
816             return $affected_rows;
817     }
818
819
820     public function mail_fetchmail_update($session_id, $client_id, $primary_id, $params)
821     {
822             if (!$this->checkPerm($session_id, 'mail_fetchmail_update'))
823             {
824                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
825                     return false;
826             }
827             $affected_rows = $this->updateQuery('../mail/form/mail_get.tform.php', $client_id, $primary_id, $params);
828             return $affected_rows;
829     }
830
831
832     public function mail_fetchmail_delete($session_id, $primary_id)
833     {
834             if (!$this->checkPerm($session_id, 'mail_fetchmail_delete'))
835             {
836                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
837                     return false;
838             }
839             $affected_rows = $this->deleteQuery('../mail/form/mail_get.tform.php', $primary_id);
840             return $affected_rows;
841     }
842     
843     //* Get whitelist details
844     public function mail_whitelist_get($session_id, $primary_id)
845     {
846         global $app;
847         
848         if(!$this->checkPerm($session_id, 'mail_whitelist_get')) {
849             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
850             return false;
851         }
852         $app->uses('remoting_lib');
853         $app->remoting_lib->loadFormDef('../mail/form/mail_whitelist.tform.php');
854         return $app->remoting_lib->getDataRecord($primary_id);
855     }
856     
857     //* wpisy biaÅ‚ej listy
858     public function mail_whitelist_add($session_id, $client_id, $params)
859     {
860             if (!$this->checkPerm($session_id, 'mail_whitelist_add'))
861             {
862                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
863                     return false;
864             }
865             $affected_rows = $this->insertQuery('../mail/form/mail_whitelist.tform.php', $client_id, $params);
866             return $affected_rows;
867     }
868
869
870     public function mail_whitelist_update($session_id, $client_id, $primary_id, $params)
871     {
872             if (!$this->checkPerm($session_id, 'mail_whitelist_update'))
873             {
874                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
875                     return false;
876             }
877             $affected_rows = $this->updateQuery('../mail/form/mail_whitelist.tform.php', $client_id, $primary_id, $params);
878             return $affected_rows;
879     }
880
881
882     public function mail_whitelist_delete($session_id, $primary_id)
883     {
884             if (!$this->checkPerm($session_id, 'mail_whitelist_delete'))
885             {
886                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
887                     return false;
888             }
889             $affected_rows = $this->deleteQuery('../mail/form/mail_whitelist.tform.php', $primary_id);
890             return $affected_rows;
891     }
892     
893     //* Get Blacklist details
894     public function mail_blacklist_get($session_id, $primary_id)
895     {
896         global $app;
897         
898         if(!$this->checkPerm($session_id, 'mail_blacklist_get')) {
899             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
900             return false;
901         }
902         $app->uses('remoting_lib');
903         $app->remoting_lib->loadFormDef('../mail/form/mail_blacklist.tform.php');
904         return $app->remoting_lib->getDataRecord($primary_id);
905     }
906     
907     //* wpisy biaÅ‚ej listy
908     public function mail_blacklist_add($session_id, $client_id, $params)
909     {
910             if (!$this->checkPerm($session_id, 'mail_blacklist_add'))
911             {
912                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
913                     return false;
914             }
915             $affected_rows = $this->insertQuery('../mail/form/mail_blacklist.tform.php', $client_id, $params);
916             return $affected_rows;
917     }
918
919
920     public function mail_blacklist_update($session_id, $client_id, $primary_id, $params)
921     {
922             if (!$this->checkPerm($session_id, 'mail_blacklist_update'))
923             {
924                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
925                     return false;
926             }
927             $affected_rows = $this->updateQuery('../mail/form/mail_blacklist.tform.php', $client_id, $primary_id, $params);
928             return $affected_rows;
929     }
930
931
932     public function mail_blacklist_delete($session_id, $primary_id)
933     {
934             if (!$this->checkPerm($session_id, 'mail_blacklist_delete'))
935             {
936                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
937                     return false;
938             }
939             $affected_rows = $this->deleteQuery('../mail/form/mail_blacklist.tform.php', $primary_id);
940             return $affected_rows;
941     }
942     
943     //* Get filter details
944     public function mail_filter_get($session_id, $primary_id)
945     {
946         global $app;
947         
948         if(!$this->checkPerm($session_id, 'mail_filter_get')) {
949             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
950             return false;
951         }
952         $app->uses('remoting_lib');
953         $app->remoting_lib->loadFormDef('../mail/form/mail_content_filter.tform.php');
954         return $app->remoting_lib->getDataRecord($primary_id);
955     }
956
957     //* wpisy filtrow e-mail
958     public function mail_filter_add($session_id, $client_id, $params)
959     {
960             if (!$this->checkPerm($session_id, 'mail_filter_add'))
961             {
962                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
963                     return false;
964             }
965             $affected_rows = $this->insertQuery('../mail/form/mail_content_filter.tform.php', $client_id, $params);
966             return $affected_rows;
967     }
968
969
970     public function mail_filter_update($session_id, $client_id, $primary_id, $params)
971     {
972             if (!$this->checkPerm($session_id, 'mail_filter_update'))
973             {
974                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
975                     return false;
976             }
977             $affected_rows = $this->updateQuery('../mail/form/mail_content_filter.tform.php', $client_id, $primary_id, $params);
978             return $affected_rows;
979     }
980
981
982     public function mail_filter_delete($session_id, $primary_id)
983     {
984             if (!$this->checkPerm($session_id, 'mail_filter_delete'))
985             {
986                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
987                     return false;
988             }
989             $affected_rows = $this->deleteQuery('../mail/form/mail_content_filter.tform.php', $primary_id);
990             return $affected_rows;
991     }
992
993
994
995
996 /* 
997  * 
998  * 
999  * 
1000  *      * Client functions
1001  * 
1002  * 
1003  */
1004     //* Get client details
1005     public function client_get($session_id, $client_id)
1006     {
1007         global $app;
1008         
1009         if(!$this->checkPerm($session_id, 'client_get')) {
1010             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1011             return false;
1012         }
1013         $app->uses('remoting_lib');
1014         $app->remoting_lib->loadFormDef('../client/form/client.tform.php');
1015         return $app->remoting_lib->getDataRecord($client_id);
1016     }
1017     
1018     public function client_get_id($session_id, $sys_userid)
1019     {
1020         global $app;
1021         if(!$this->checkPerm($session_id, 'client_get_id')) {
1022             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1023             return false;
1024         }
1025         
1026         $sys_userid = intval($sys_userid);
1027         
1028         $rec = $app->db->queryOneRecord("SELECT client_id FROM sys_user WHERE userid = ".$sys_userid);
1029         if(isset($rec['client_id'])) {
1030             return intval($rec['client_id']);
1031         } else {
1032             $this->server->fault('no_client_found', 'There is no sysuser account for this client ID.');
1033             return false;
1034         }
1035         
1036     }
1037     
b67344 1038     public function client_get_groupid($session_id, $client_id)
T 1039     {
1040         global $app;
1041         if(!$this->checkPerm($session_id, 'client_get_id')) {
1042             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1043             return false;
1044         }
1045         
1046         $client_id = intval($client_id);
1047         
1048         $rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$client_id);
1049         if(isset($rec['groupid'])) {
1050             return intval($rec['groupid']);
1051         } else {
1052             $this->server->fault('no_group_found', 'There is no group for this client ID.');
1053             return false;
1054         }
1055         
1056     }
1057     
532ae5 1058     
L 1059     public function client_add($session_id, $reseller_id, $params)
1060     {
1061         if (!$this->checkPerm($session_id, 'client_add'))
1062             {
1063                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
1064                     return false;
1065             }
1066         $affected_rows = $this->klientadd('../client/form/client.tform.php',$reseller_id, $params);
1067         return $affected_rows;  
1068                   
1069     }
1070     
1071     public function client_update($session_id, $client_id, $reseller_id, $params)
1072     {
1073             global $app;
1074             
1075             if (!$this->checkPerm($session_id, 'client_update'))
1076             {
1077                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
1078                     return false;
1079             }
04620b 1080             $affected_rows = $this->updateQuery('../client/form/client.tform.php', $reseller_id, $client_id, $params);
532ae5 1081             
L 1082             $app->remoting_lib->ispconfig_sysuser_update($params,$client_id);
1083             
1084             return $affected_rows;
1085     }
1086
1087
1088     public function client_delete($session_id,$client_id)
1089     {
1090             global $app;
1091             
1092             if (!$this->checkPerm($session_id, 'client_delete'))
1093             {
1094                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
1095                     return false;
1096             }
1097             $affected_rows = $this->deleteQuery('../client/form/client.tform.php',$client_id);
1098             
1099             $app->remoting_lib->ispconfig_sysuser_delete($client_id);
1100             
1101             return $affected_rows;
1102     }
1103     
1ca823 1104     // -----------------------------------------------------------------------------------------------
T 1105     
1106     public function client_delete_everything($session_id, $client_id)
1107     {
1108         global $app, $conf;
1109         if(!$this->checkPerm($session_id, 'client_delete_everything')) {
1110             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1111             return false;
1112         }
1113         $client_id = intval($client_id);
1114     $client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
1115
1116     $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_domain,web_traffic';
1117         $tables_array = explode(',',$tables);
1118         $client_group_id = intval($client_group['groupid']);
1119         
1120         $table_list = array();
1121         if($client_group_id > 1) {
1122             foreach($tables_array as $table) {
1123                 if($table != '') {
1124                     $records = $app->db->queryAllRecords("SELECT * FROM $table WHERE sys_groupid = ".$client_group_id);
1125                     $number = count($records);
1126                     if($number > 0) $table_list[] = array('table' => $table."(".$number.")");
1127                 }
1128             }
1129         }
1130
1131
1132     if($client_id > 0) {            
1133             // remove the group of the client from the resellers group
1134             $parent_client_id = intval($this->dataRecord['parent_client_id']);
1135             $parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = $parent_client_id");
1136             $client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
1137             $app->auth->remove_group_from_user($parent_user['userid'],$client_group['groupid']);
1138             
1139             // delete the group of the client
1140             $app->db->query("DELETE FROM sys_group WHERE client_id = $client_id");
1141             
1142             // delete the sys user(s) of the client
1143             $app->db->query("DELETE FROM sys_user WHERE client_id = $client_id");
1144             
1145             // Delete all records (sub-clients, mail, web, etc....)  of this client.
1146             $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_domain,web_traffic';
1147             $tables_array = explode(',',$tables);
1148             $client_group_id = intval($client_group['groupid']);
1149             if($client_group_id > 1) {
1150                 foreach($tables_array as $table) {
1151                     if($table != '') {
1152                         $records = $app->db->queryAllRecords("SELECT * FROM $table WHERE sys_groupid = ".$client_group_id);
1153                         // find the primary ID of the table
1154                         $table_info = $app->db->tableInfo($table);
1155                         $index_field = '';
1156                         foreach($table_info as $tmp) {
1157                             if($tmp['option'] == 'primary') $index_field = $tmp['name'];
1158                         }
1159                         // Delete the records
1160                         if($index_field != '') {
1161                             if(is_array($records)) {
1162                                 foreach($records as $rec) {
1163                                     $app->db->datalogDelete($table, $index_field, $rec[$index_field]);
1164                                 }
1165                             }
1166                         }
1167                         
1168                     }
1169                 }
1170             }
1171             
1172             
1173             
1174         }
1175         
1176         if (!$this->checkPerm($session_id, 'client_delete'))
1177             {
1178                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
1179                     return false;
1180             }
1181             $affected_rows = $this->deleteQuery('../client/form/client.tform.php',$client_id);
1182             
1183             // $app->remoting_lib->ispconfig_sysuser_delete($client_id);
1184
1185
1186         return false;
1187     }
1188     
532ae5 1189     // Website functions ---------------------------------------------------------------------------------------
L 1190     
1191     //* Get cron details
1192     public function sites_cron_get($session_id, $cron_id)
1193     {
1194         global $app;
1195         
1196         if(!$this->checkPerm($session_id, 'sites_cron_get')) {
1197             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1198             return false;
1199         }
1200         $app->uses('remoting_lib');
1201         $app->remoting_lib->loadFormDef('../sites/form/cron.tform.php');
1202         return $app->remoting_lib->getDataRecord($cron_id);
1203     }
1204     
1205     //* Add a cron record
1206     public function sites_cron_add($session_id, $client_id, $params)
1207     {
1208         if(!$this->checkPerm($session_id, 'sites_cron_add')) {
1209             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1210             return false;
1211         }
1212         return $this->insertQuery('../sites/form/cron.tform.php',$client_id,$params);
1213     }
1214     
1215     //* Update cron record
1216     public function sites_cron_update($session_id, $client_id, $cron_id, $params)
1217     {
1218         if(!$this->checkPerm($session_id, 'sites_cron_update')) {
1219             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1220             return false;
1221         }
1222         $affected_rows = $this->updateQuery('../sites/form/cron.tform.php',$client_id,$cron_id,$params);
1223         return $affected_rows;
1224     }
1225     
1226     //* Delete cron record
1227     public function sites_cron_delete($session_id, $cron_id)
1228     {
1229         if(!$this->checkPerm($session_id, 'sites_cron_delete')) {
1230             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1231             return false;
1232         }
1233         $affected_rows = $this->deleteQuery('../sites/form/cron.tform.php',$cron_id);
1234         return $affected_rows;
1235     }
1236     
1237     // ----------------------------------------------------------------------------------------------------------
1238     
1239     //* Get record details
1240     public function sites_database_get($session_id, $primary_id)
1241     {
1242         global $app;
1243         
1244         if(!$this->checkPerm($session_id, 'sites_database_get')) {
1245             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1246             return false;
1247         }
1248         $app->uses('remoting_lib');
1249         $app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
1250         return $app->remoting_lib->getDataRecord($primary_id);
1251     }
1252     
1253     //* Add a record
1254     public function sites_database_add($session_id, $client_id, $params)
1255     {
1256         if(!$this->checkPerm($session_id, 'sites_database_add')) {
1257             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1258             return false;
1259         }
1260         return $this->insertQuery('../sites/form/database.tform.php',$client_id,$params);
1261     }
1262     
1263     //* Update a record
1264     public function sites_database_update($session_id, $client_id, $primary_id, $params)
1265     {
1266         if(!$this->checkPerm($session_id, 'sites_database_update')) {
1267             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1268             return false;
1269         }
1270         $affected_rows = $this->updateQuery('../sites/form/database.tform.php',$client_id,$primary_id,$params);
1271         return $affected_rows;
1272     }
1273     
1274     //* Delete a record
1275     public function sites_database_delete($session_id, $primary_id)
1276     {
1277         if(!$this->checkPerm($session_id, 'sites_database_delete')) {
1278             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1279             return false;
1280         }
1281         $affected_rows = $this->deleteQuery('../sites/form/database.tform.php',$primary_id);
1282         return $affected_rows;
1283     }
1284     
1285     // ----------------------------------------------------------------------------------------------------------
1286     
1287     //* Get record details
1288     public function sites_ftp_user_get($session_id, $primary_id)
1289     {
1290         global $app;
1291         
1292         if(!$this->checkPerm($session_id, 'sites_ftp_user_get')) {
1293             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1294             return false;
1295         }
1296         $app->uses('remoting_lib');
1297         $app->remoting_lib->loadFormDef('../sites/form/ftp_user.tform.php');
1298         return $app->remoting_lib->getDataRecord($primary_id);
1299     }
1300     
1301     //* Add a record
1302     public function sites_ftp_user_add($session_id, $client_id, $params)
1303     {
1304         if(!$this->checkPerm($session_id, 'sites_ftp_user_add')) {
1305             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1306             return false;
1307         }
1308         return $this->insertQuery('../sites/form/ftp_user.tform.php',$client_id,$params);
1309     }
1310     
1311     //* Update a record
1312     public function sites_ftp_user_update($session_id, $client_id, $primary_id, $params)
1313     {
1314         if(!$this->checkPerm($session_id, 'sites_ftp_user_update')) {
1315             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1316             return false;
1317         }
1318         $affected_rows = $this->updateQuery('../sites/form/ftp_user.tform.php',$client_id,$primary_id,$params);
1319         return $affected_rows;
1320     }
1321     
1322     //* Delete a record
1323     public function sites_ftp_user_delete($session_id, $primary_id)
1324     {
1325         if(!$this->checkPerm($session_id, 'sites_ftp_user_delete')) {
1326             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1327             return false;
1328         }
1329         $affected_rows = $this->deleteQuery('../sites/form/ftp_user.tform.php',$primary_id);
1330         return $affected_rows;
1331     }
1332     
1333     // ----------------------------------------------------------------------------------------------------------
1334     
1335     //* Get record details
1336     public function sites_shell_user_get($session_id, $primary_id)
1337     {
1338         global $app;
1339         
1340         if(!$this->checkPerm($session_id, 'sites_shell_user_get')) {
1341             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1342             return false;
1343         }
1344         $app->uses('remoting_lib');
1345         $app->remoting_lib->loadFormDef('../sites/form/shell_user.tform.php');
1346         return $app->remoting_lib->getDataRecord($primary_id);
1347     }
1348     
1349     //* Add a record
1350     public function sites_shell_user_add($session_id, $client_id, $params)
1351     {
1352         if(!$this->checkPerm($session_id, 'sites_shell_user_add')) {
1353             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1354             return false;
1355         }
1356         return $this->insertQuery('../sites/form/shell_user.tform.php',$client_id,$params);
1357     }
1358     
1359     //* Update a record
1360     public function sites_shell_user_update($session_id, $client_id, $primary_id, $params)
1361     {
1362         if(!$this->checkPerm($session_id, 'sites_shell_user_update')) {
1363             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1364             return false;
1365         }
1366         $affected_rows = $this->updateQuery('../sites/form/shell_user.tform.php',$client_id,$primary_id,$params);
1367         return $affected_rows;
1368     }
1369     
1370     //* Delete a record
1371     public function sites_shell_user_delete($session_id, $primary_id)
1372     {
1373         if(!$this->checkPerm($session_id, 'sites_shell_user_delete')) {
1374             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1375             return false;
1376         }
1377         $affected_rows = $this->deleteQuery('../sites/form/shell_user.tform.php',$primary_id);
1378         return $affected_rows;
1379     }
1380     
1381     // ----------------------------------------------------------------------------------------------------------
1382     
1383     //* Get record details
1384     public function sites_web_domain_get($session_id, $primary_id)
1385     {
1386         global $app;
1387         
1388         if(!$this->checkPerm($session_id, 'sites_web_domain_get')) {
1389             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1390             return false;
1391         }
1392         $app->uses('remoting_lib');
1393         $app->remoting_lib->loadFormDef('../sites/form/web_domain.tform.php');
1394         return $app->remoting_lib->getDataRecord($primary_id);
1395     }
1396     
1397     //* Add a record
1ca823 1398     public function sites_web_domain_add($session_id, $client_id, $params, $readonly = false)
T 1399     {
1400         global $app;
532ae5 1401         if(!$this->checkPerm($session_id, 'sites_web_domain_add')) {
L 1402             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1403             return false;
1404         }
cdf6f0 1405         
T 1406         if(!isset($params['client_group_id']) or (isset($params['client_group_id']) && empty($params['client_group_id']))) {
1407             $rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".intval($client_id));
1408             $params['client_group_id'] = $rec['groupid'];
1409         }
1410         
1411         //* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
1412         if($params['document_root'] == '') $params['document_root'] = '-';
1413         if($params['system_user'] == '') $params['system_user'] = '-';
1414         if($params['system_group'] == '') $params['system_group'] = '-';
1415         
8ab3cd 1416         //* Set a few defaults for nginx servers
T 1417         if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
1418         if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
1419         if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
1420         if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
1421         
1ca823 1422         $domain_id = $this->insertQuery('../sites/form/web_domain.tform.php',$client_id,$params, 'sites:web_domain:on_after_insert');
T 1423         if ($readonly === true)
1424             $app->db->query("UPDATE web_domain SET `sys_userid` = '1' WHERE domain_id = ".$domain_id);
1425             return $domain_id;
1426         }
1427     
532ae5 1428     //* Update a record
L 1429     public function sites_web_domain_update($session_id, $client_id, $primary_id, $params)
1430     {
1431         if(!$this->checkPerm($session_id, 'sites_web_domain_update')) {
1432             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1433             return false;
1434         }
edf806 1435         
T 1436         //* Set a few defaults for nginx servers
1437         if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
1438         if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
1439         if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
1440         if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
1441         
532ae5 1442         $affected_rows = $this->updateQuery('../sites/form/web_domain.tform.php',$client_id,$primary_id,$params);
L 1443         return $affected_rows;
1444     }
1445     
1446     //* Delete a record
1447     public function sites_web_domain_delete($session_id, $primary_id)
1448     {
1449         if(!$this->checkPerm($session_id, 'sites_web_domain_delete')) {
1450             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1451             return false;
1452         }
1453         $affected_rows = $this->deleteQuery('../sites/form/web_domain.tform.php',$primary_id);
1454         return $affected_rows;
1455     }
1456     
1ca823 1457     // -----------------------------------------------------------------------------------------------
532ae5 1458     
L 1459     //* Get record details
1460     public function sites_web_aliasdomain_get($session_id, $primary_id)
1461     {
1462         global $app;
1463         
1464         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_get')) {
1465             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1466             return false;
1467         }
1468         $app->uses('remoting_lib');
1469         $app->remoting_lib->loadFormDef('../sites/form/web_aliasdomain.tform.php');
1470         return $app->remoting_lib->getDataRecord($primary_id);
1471     }
1472     
1473     //* Add a record
1474     public function sites_web_aliasdomain_add($session_id, $client_id, $params)
1475     {
1476         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
1477             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1478             return false;
1479         }
1480         return $this->insertQuery('../sites/form/web_aliasdomain.tform.php',$client_id,$params);
1481     }
1482     
1483     //* Update a record
1484     public function sites_web_aliasdomain_update($session_id, $client_id, $primary_id, $params)
1485     {
1486         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
1487             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1488             return false;
1489         }
1490         $affected_rows = $this->updateQuery('../sites/form/web_aliasdomain.tform.php',$client_id,$primary_id,$params);
1491         return $affected_rows;
1492     }
1493     
1494     //* Delete a record
1495     public function sites_web_aliasdomain_delete($session_id, $primary_id)
1496     {
1497         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
1498             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1499             return false;
1500         }
1501         $affected_rows = $this->deleteQuery('../sites/form/web_aliasdomain.tform.php',$primary_id);
1502         return $affected_rows;
1503     }
1504     
1505     // ----------------------------------------------------------------------------------------------------------
1506     
1507     //* Get record details
1508     public function sites_web_subdomain_get($session_id, $primary_id)
1509     {
1510         global $app;
1511         
1512         if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
1513             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1514             return false;
1515         }
1516         $app->uses('remoting_lib');
1517         $app->remoting_lib->loadFormDef('../sites/form/web_subdomain.tform.php');
1518         return $app->remoting_lib->getDataRecord($primary_id);
1519     }
1520     
1521     //* Add a record
1522     public function sites_web_subdomain_add($session_id, $client_id, $params)
1523     {
1524         if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
1525             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1526             return false;
1527         }
1528         return $this->insertQuery('../sites/form/web_subdomain.tform.php',$client_id,$params);
1529     }
1530     
1531     //* Update a record
1532     public function sites_web_subdomain_update($session_id, $client_id, $primary_id, $params)
1533     {
1534         if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
1535             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1536             return false;
1537         }
1538         $affected_rows = $this->updateQuery('../sites/form/web_subdomain.tform.php',$client_id,$primary_id,$params);
1539         return $affected_rows;
1540     }
1541     
1542     //* Delete a record
1543     public function sites_web_subdomain_delete($session_id, $primary_id)
1544     {
1545         if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
1546             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1547             return false;
1548         }
1549         $affected_rows = $this->deleteQuery('../sites/form/web_subdomain.tform.php',$primary_id);
1550         return $affected_rows;
1551     }
1552     
1553     // -----------------------------------------------------------------------------------------------
1554     
1ca823 1555     //* Get record details
T 1556     public function domains_domain_get($session_id, $primary_id)
1557     {
1558         global $app;
1559         
1560         if(!$this->checkPerm($session_id, 'domains_domain_get')) {
1561             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1562             return false;
1563         }
1564         $app->uses('remoting_lib');
1565         $app->remoting_lib->loadFormDef('../domain/form/domain.tform.php');
1566         return $app->remoting_lib->getDataRecord($primary_id);
1567     }
1568
1569     //* Add a record
1570     public function domains_domain_add($session_id, $client_id, $params)
1571     {
1572         if(!$this->checkPerm($session_id, 'domains_domain_add')) {
1573             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1574             return false;
1575         }
1576         return $this->insertQuery('../domain/form/domain.tform.php',$client_id,$params);
1577     }
1578
1579     //* Delete a record
1580     public function domains_domain_delete($session_id, $primary_id)
1581     {
1582         if(!$this->checkPerm($session_id, 'domains_domain_delete')) {
1583             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1584             return false;
1585         }
1586         $affected_rows = $this->deleteQuery('../domain/form/domain.tform.php',$primary_id);
1587         return $affected_rows;
1588     }
1589
1590 // -----------------------------------------------------------------------------------------------
1591
1592     public function domains_get_all_by_user($session_id, $group_id)
1593     {
1594         global $app;
1595         if(!$this->checkPerm($session_id, 'domains_get_all_by_user')) {
1596             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1597             return false;
1598         }
1599         $group_id = intval($group_id);
1600         $sql = "SELECT domain_id, domain FROM domain WHERE sys_groupid  = $group_id ";
1601         $all = $app->db->queryAllRecords($sql);
1602         return $all;
1603     }
1604     
1605     
532ae5 1606     // DNS Function --------------------------------------------------------------------------------------------------
L 1607     
b67344 1608     //* Create Zone with Template
T 1609     public function dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email)
1610     {
1611         global $app, $conf;
1612         if(!$this->checkPerm($session_id, 'dns_templatezone_add')) {
1613             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1614             return false;
1615         }
1616
1617         $client = $app->db->queryOneRecord("SELECT default_dnsserver FROM client WHERE client_id = ".intval($client_id));
1618         $server_id = $client["default_dnsserver"];
1619         $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = '$template_id'");
1620         $fields = explode(',',$template_record['fields']);
1621         $tform_def_file = "../../web/dns/form/dns_soa.tform.php";
1622         $app->uses('tform');
1623         $app->tform->loadFormDef($tform_def_file);
1624         $app->uses('tpl,validate_dns');
1625         
1626         //* replace template placeholders
1627         $tpl_content = $template_record['template'];
1628         if($domain != '') $tpl_content = str_replace('{DOMAIN}',$domain,$tpl_content);
1629         if($ip != '') $tpl_content = str_replace('{IP}',$ip,$tpl_content);
1630         if($ns1 != '') $tpl_content = str_replace('{NS1}',$ns1,$tpl_content);
1631         if($ns2 != '') $tpl_content = str_replace('{NS2}',$ns2,$tpl_content);
1632         if($email != '') $tpl_content = str_replace('{EMAIL}',$email,$tpl_content);
1633         
1634         //* Parse the template
1635         $tpl_rows = explode("\n",$tpl_content);
1636         $section = '';
1637         $vars = array();
1638         $dns_rr = array();
1639         foreach($tpl_rows as $row) {
1640             $row = trim($row);
1641             if(substr($row,0,1) == '[') {
1642                 if($row == '[ZONE]') {
1643                     $section = 'zone';
1644                 } elseif($row == '[DNS_RECORDS]') {
1645                     $section = 'dns_records';
1646                 } else {
1647                     die('Unknown section type');
1648                 }
1649             } else {
1650                 if($row != '') {
1651                     //* Handle zone section
1652                     if($section == 'zone') {
1653                         $parts = explode('=',$row);
1654                         $key = trim($parts[0]);
1655                         $val = trim($parts[1]);
1656                         if($key != '') $vars[$key] = $val;
1657                     }
1658                     //* Handle DNS Record rows
1659                     if($section == 'dns_records') {
1660                         $parts = explode('|',$row);
1661                         $dns_rr[] = array(
1662                             'name' => $app->db->quote($parts[1]),
1663                             'type' => $app->db->quote($parts[0]),
1664                             'data' => $app->db->quote($parts[2]),
1665                             'aux'  => $app->db->quote($parts[3]),
1666                             'ttl'  => $app->db->quote($parts[4])
1667                         );
1668                     }
1669                 }
1670             }        
1671         } // end foreach
1672         
1673         if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').'<br />';
1674         if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').'<br />';
1675         if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').'<br />';
1676         if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').'<br />';
1677         if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').'<br />';
1678         if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').'<br />';
1679         if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').'<br />';
1680         if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').'<br />';    
1681         
1682         if($error == '') {
1683             // Insert the soa record
1684             $tmp = $app->db->queryOneRecord("SELECT userid,default_group FROM sys_user WHERE client_id = ".intval($client_id));
1685             $sys_userid = $tmp['userid'];
1686             $sys_groupid = $tmp['default_group'];
1687             unset($tmp);
1688             $origin = $app->db->quote($vars['origin']);
1689             $ns = $app->db->quote($vars['ns']);
1690             $mbox = $app->db->quote(str_replace('@','.',$vars['mbox']));
1691             $refresh = $app->db->quote($vars['refresh']);
1692             $retry = $app->db->quote($vars['retry']);
1693             $expire = $app->db->quote($vars['expire']);
1694             $minimum = $app->db->quote($vars['minimum']);
1695             $ttl = $app->db->quote($vars['ttl']);
1696             $xfer = $app->db->quote($vars['xfer']);
1697             $also_notify = $app->db->quote($vars['also_notify']);
1698             $update_acl = $app->db->quote($vars['update_acl']);
1699             $serial = $app->validate_dns->increase_serial(0);        
1700             $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `origin`, `ns`, `mbox`, `serial`, `refresh`, `retry`, `expire`, `minimum`, `ttl`, `active`, `xfer`, `also_notify`, `update_acl`) VALUES 
1701             ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '$xfer', '$also_notify', '$update_acl')";
1702             $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');    
1703             // Insert the dns_rr records
1704             if(is_array($dns_rr) && $dns_soa_id > 0) {
1705                 foreach($dns_rr as $rr) {
1706                     $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `zone`, `name`, `type`, `data`, `aux`, `ttl`, `active`) VALUES 
1707                     ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')";
1708                     $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
1709                 }
1710             }
1711             exit;
1712         } else {
1713             $this->server->fault('permission_denied', $error);
1714         }
1715     }
1716     
1717     
532ae5 1718     //* Get record details
L 1719     public function dns_zone_get($session_id, $primary_id)
1720     {
1721         global $app;
1722         
1723         if(!$this->checkPerm($session_id, 'dns_zone_get')) {
1724             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1725             return false;
1726         }
1727         $app->uses('remoting_lib');
1728         $app->remoting_lib->loadFormDef('../dns/form/dns_soa.tform.php');
1729         return $app->remoting_lib->getDataRecord($primary_id);
1730     }
854444 1731     
M 1732     //* Get record id by origin
1733     public function dns_zone_get_id($session_id, $origin)
1734     {
1735         global $app;
1736         
1737         if(!$this->checkPerm($session_id, 'dns_zone_get_id')) {
1738             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1739             return false;
1740         }
1741         
1742         if (preg_match('/^[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/i', $origin)) {
1743             $this->server->fault('no_domain_found', 'Invalid domain name.');
1744             return false;
1745         }
1746
1747         $rec = $app->db->queryOneRecord("SELECT id FROM dns_soa WHERE origin like '".$origin.'%');
1748         if(isset($rec['id'])) {
1749             return intval($rec['id']);
1750         } else {
1751             $this->server->fault('no_domain_found', 'There is no domain ID with informed domain name.');
1752             return false;
1753         }
1754     }
532ae5 1755     
L 1756     //* Add a record
1757     public function dns_zone_add($session_id, $client_id, $params)
1758     {
1759         if(!$this->checkPerm($session_id, 'dns_zone_add')) {
1760             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1761             return false;
1762         }
1763         return $this->insertQuery('../dns/form/dns_soa.tform.php',$client_id,$params);
1764     }
1765     
1766     //* Update a record
1767     public function dns_zone_update($session_id, $client_id, $primary_id, $params)
1768     {
1769         if(!$this->checkPerm($session_id, 'dns_zone_update')) {
1770             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1771             return false;
1772         }
1773         $affected_rows = $this->updateQuery('../dns/form/dns_soa.tform.php',$client_id,$primary_id,$params);
1774         return $affected_rows;
1775     }
1776     
1777     //* Delete a record
1778     public function dns_zone_delete($session_id, $primary_id)
1779     {
1780         if(!$this->checkPerm($session_id, 'dns_zone_delete')) {
1781             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1782             return false;
1783         }
1784         $affected_rows = $this->deleteQuery('../dns/form/dns_soa.tform.php',$primary_id);
1785         return $affected_rows;
1786     }
1787     
1788     // ----------------------------------------------------------------------------------------------------------------
1789     
1790     //* Get record details
1791     public function dns_aaaa_get($session_id, $primary_id)
1792     {
1793         global $app;
1794         
1795         if(!$this->checkPerm($session_id, 'dns_aaaa_get')) {
1796             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1797             return false;
1798         }
1799         $app->uses('remoting_lib');
1800         $app->remoting_lib->loadFormDef('../dns/form/dns_aaaa.tform.php');
1801         return $app->remoting_lib->getDataRecord($primary_id);
1802     }
1803     
1804     //* Add a record
1805     public function dns_aaaa_add($session_id, $client_id, $params)
1806     {
1807         if(!$this->checkPerm($session_id, 'dns_aaaa_add')) {
1808             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1809             return false;
1810         }
1811         return $this->insertQuery('../dns/form/dns_aaaa.tform.php',$client_id,$params);
1812     }
1813     
1814     //* Update a record
1815     public function dns_aaaa_update($session_id, $client_id, $primary_id, $params)
1816     {
1817         if(!$this->checkPerm($session_id, 'dns_aaaa_update')) {
1818             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1819             return false;
1820         }
1821         $affected_rows = $this->updateQuery('../dns/form/dns_aaaa.tform.php',$client_id,$primary_id,$params);
1822         return $affected_rows;
1823     }
1824     
1825     //* Delete a record
1826     public function dns_aaaa_delete($session_id, $primary_id)
1827     {
1828         if(!$this->checkPerm($session_id, 'dns_aaaa_delete')) {
1829             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1830             return false;
1831         }
1832         $affected_rows = $this->deleteQuery('../dns/form/dns_aaaa.tform.php',$primary_id);
1833         return $affected_rows;
1834     }
1835
1836     // ----------------------------------------------------------------------------------------------------------------
1837     
1838     //* Get record details
1839     public function dns_a_get($session_id, $primary_id)
1840     {
1841         global $app;
1842         
1843         if(!$this->checkPerm($session_id, 'dns_a_get')) {
1844             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1845             return false;
1846         }
1847         $app->uses('remoting_lib');
1848         $app->remoting_lib->loadFormDef('../dns/form/dns_a.tform.php');
1849         return $app->remoting_lib->getDataRecord($primary_id);
1850     }
1851     
1852     //* Add a record
1853     public function dns_a_add($session_id, $client_id, $params)
1854     {
1855         if(!$this->checkPerm($session_id, 'dns_a_add')) {
1856             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1857             return false;
1858         }
1859         return $this->insertQuery('../dns/form/dns_a.tform.php',$client_id,$params);
1860     }
1861     
1862     //* Update a record
1863     public function dns_a_update($session_id, $client_id, $primary_id, $params)
1864     {
1865         if(!$this->checkPerm($session_id, 'dns_a_update')) {
1866             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1867             return false;
1868         }
1869         $affected_rows = $this->updateQuery('../dns/form/dns_a.tform.php',$client_id,$primary_id,$params);
1870         return $affected_rows;
1871     }
1872     
1873     //* Delete a record
1874     public function dns_a_delete($session_id, $primary_id)
1875     {
1876         if(!$this->checkPerm($session_id, 'dns_a_delete')) {
1877             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1878             return false;
1879         }
1880         $affected_rows = $this->deleteQuery('../dns/form/dns_a.tform.php',$primary_id);
1881         return $affected_rows;
1882     }
1883     
1884     // ----------------------------------------------------------------------------------------------------------------
1885     
1886     //* Get record details
1887     public function dns_alias_get($session_id, $primary_id)
1888     {
1889         global $app;
1890         
1891         if(!$this->checkPerm($session_id, 'dns_alias_get')) {
1892             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1893             return false;
1894         }
1895         $app->uses('remoting_lib');
1896         $app->remoting_lib->loadFormDef('../dns/form/dns_alias.tform.php');
1897         return $app->remoting_lib->getDataRecord($primary_id);
1898     }
1899     
1900     //* Add a record
1901     public function dns_alias_add($session_id, $client_id, $params)
1902     {
1903         if(!$this->checkPerm($session_id, 'dns_alias_add')) {
1904             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1905             return false;
1906         }
1907         return $this->insertQuery('../dns/form/dns_alias.tform.php',$client_id,$params);
1908     }
1909     
1910     //* Update a record
1911     public function dns_alias_update($session_id, $client_id, $primary_id, $params)
1912     {
1913         if(!$this->checkPerm($session_id, 'dns_alias_update')) {
1914             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1915             return false;
1916         }
1917         $affected_rows = $this->updateQuery('../dns/form/dns_alias.tform.php',$client_id,$primary_id,$params);
1918         return $affected_rows;
1919     }
1920     
1921     //* Delete a record
1922     public function dns_alias_delete($session_id, $primary_id)
1923     {
1924         if(!$this->checkPerm($session_id, 'dns_alias_delete')) {
1925             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1926             return false;
1927         }
1928         $affected_rows = $this->deleteQuery('../dns/form/dns_alias.tform.php',$primary_id);
1929         return $affected_rows;
1930     }
1931     
1932     // ----------------------------------------------------------------------------------------------------------------
1933     
1934     //* Get record details
1935     public function dns_cname_get($session_id, $primary_id)
1936     {
1937         global $app;
1938         
1939         if(!$this->checkPerm($session_id, 'dns_cname_get')) {
1940             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1941             return false;
1942         }
1943         $app->uses('remoting_lib');
1944         $app->remoting_lib->loadFormDef('../dns/form/dns_cname.tform.php');
1945         return $app->remoting_lib->getDataRecord($primary_id);
1946     }
1947     
1948     //* Add a record
1949     public function dns_cname_add($session_id, $client_id, $params)
1950     {
1951         if(!$this->checkPerm($session_id, 'dns_cname_add')) {
1952             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1953             return false;
1954         }
1955         return $this->insertQuery('../dns/form/dns_cname.tform.php',$client_id,$params);
1956     }
1957     
1958     //* Update a record
1959     public function dns_cname_update($session_id, $client_id, $primary_id, $params)
1960     {
1961         if(!$this->checkPerm($session_id, 'dns_cname_update')) {
1962             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1963             return false;
1964         }
1965         $affected_rows = $this->updateQuery('../dns/form/dns_cname.tform.php',$client_id,$primary_id,$params);
1966         return $affected_rows;
1967     }
1968     
1969     //* Delete a record
1970     public function dns_cname_delete($session_id, $primary_id)
1971     {
1972         if(!$this->checkPerm($session_id, 'dns_cname_delete')) {
1973             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1974             return false;
1975         }
1976         $affected_rows = $this->deleteQuery('../dns/form/dns_cname.tform.php',$primary_id);
1977         return $affected_rows;
1978     }
1979     
1980     // ----------------------------------------------------------------------------------------------------------------
1981     
1982     //* Get record details
1983     public function dns_hinfo_get($session_id, $primary_id)
1984     {
1985         global $app;
1986         
1987         if(!$this->checkPerm($session_id, 'dns_hinfo_get')) {
1988             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1989             return false;
1990         }
1991         $app->uses('remoting_lib');
1992         $app->remoting_lib->loadFormDef('../dns/form/dns_hinfo.tform.php');
1993         return $app->remoting_lib->getDataRecord($primary_id);
1994     }
1995     
1996     //* Add a record
1997     public function dns_hinfo_add($session_id, $client_id, $params)
1998     {
1999         if(!$this->checkPerm($session_id, 'dns_hinfo_add')) {
2000             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2001             return false;
2002         }
2003         return $this->insertQuery('../dns/form/dns_hinfo.tform.php',$client_id,$params);
2004     }
2005     
2006     //* Update a record
2007     public function dns_hinfo_update($session_id, $client_id, $primary_id, $params)
2008     {
2009         if(!$this->checkPerm($session_id, 'dns_hinfo_update')) {
2010             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2011             return false;
2012         }
2013         $affected_rows = $this->updateQuery('../dns/form/dns_hinfo.tform.php',$client_id,$primary_id,$params);
2014         return $affected_rows;
2015     }
2016     
2017     //* Delete a record
2018     public function dns_hinfo_delete($session_id, $primary_id)
2019     {
2020         if(!$this->checkPerm($session_id, 'dns_hinfo_delete')) {
2021             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2022             return false;
2023         }
2024         $affected_rows = $this->deleteQuery('../dns/form/dns_hinfo.tform.php',$primary_id);
2025         return $affected_rows;
2026     }
2027     
2028     // ----------------------------------------------------------------------------------------------------------------
2029     
2030     //* Get record details
2031     public function dns_mx_get($session_id, $primary_id)
2032     {
2033         global $app;
2034         
2035         if(!$this->checkPerm($session_id, 'dns_mx_get')) {
2036             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2037             return false;
2038         }
2039         $app->uses('remoting_lib');
2040         $app->remoting_lib->loadFormDef('../dns/form/dns_mx.tform.php');
2041         return $app->remoting_lib->getDataRecord($primary_id);
2042     }
2043     
2044     //* Add a record
2045     public function dns_mx_add($session_id, $client_id, $params)
2046     {
2047         if(!$this->checkPerm($session_id, 'dns_mx_add')) {
2048             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2049             return false;
2050         }
2051         return $this->insertQuery('../dns/form/dns_mx.tform.php',$client_id,$params);
2052     }
2053     
2054     //* Update a record
2055     public function dns_mx_update($session_id, $client_id, $primary_id, $params)
2056     {
2057         if(!$this->checkPerm($session_id, 'dns_mx_update')) {
2058             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2059             return false;
2060         }
2061         $affected_rows = $this->updateQuery('../dns/form/dns_mx.tform.php',$client_id,$primary_id,$params);
2062         return $affected_rows;
2063     }
2064     
2065     //* Delete a record
2066     public function dns_mx_delete($session_id, $primary_id)
2067     {
2068         if(!$this->checkPerm($session_id, 'dns_mx_delete')) {
2069             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2070             return false;
2071         }
2072         $affected_rows = $this->deleteQuery('../dns/form/dns_mx.tform.php',$primary_id);
2073         return $affected_rows;
2074     }
2075     
2076     // ----------------------------------------------------------------------------------------------------------------
2077     
2078     //* Get record details
2079     public function dns_ns_get($session_id, $primary_id)
2080     {
2081         global $app;
2082         
2083         if(!$this->checkPerm($session_id, 'dns_ns_get')) {
2084             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2085             return false;
2086         }
2087         $app->uses('remoting_lib');
2088         $app->remoting_lib->loadFormDef('../dns/form/dns_ns.tform.php');
2089         return $app->remoting_lib->getDataRecord($primary_id);
2090     }
2091     
2092     //* Add a record
2093     public function dns_ns_add($session_id, $client_id, $params)
2094     {
2095         if(!$this->checkPerm($session_id, 'dns_ns_add')) {
2096             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2097             return false;
2098         }
2099         return $this->insertQuery('../dns/form/dns_ns.tform.php',$client_id,$params);
2100     }
2101     
2102     //* Update a record
2103     public function dns_ns_update($session_id, $client_id, $primary_id, $params)
2104     {
2105         if(!$this->checkPerm($session_id, 'dns_ns_update')) {
2106             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2107             return false;
2108         }
2109         $affected_rows = $this->updateQuery('../dns/form/dns_ns.tform.php',$client_id,$primary_id,$params);
2110         return $affected_rows;
2111     }
2112     
2113     //* Delete a record
2114     public function dns_ns_delete($session_id, $primary_id)
2115     {
2116         if(!$this->checkPerm($session_id, 'dns_ns_delete')) {
2117             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2118             return false;
2119         }
2120         $affected_rows = $this->deleteQuery('../dns/form/dns_ns.tform.php',$primary_id);
2121         return $affected_rows;
2122     }
2123     
2124     // ----------------------------------------------------------------------------------------------------------------
2125     
2126     //* Get record details
2127     public function dns_ptr_get($session_id, $primary_id)
2128     {
2129         global $app;
2130         
2131         if(!$this->checkPerm($session_id, 'dns_ptr_get')) {
2132             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2133             return false;
2134         }
2135         $app->uses('remoting_lib');
2136         $app->remoting_lib->loadFormDef('../dns/form/dns_ptr.tform.php');
2137         return $app->remoting_lib->getDataRecord($primary_id);
2138     }
2139     
2140     //* Add a record
2141     public function dns_ptr_add($session_id, $client_id, $params)
2142     {
2143         if(!$this->checkPerm($session_id, 'dns_ptr_add')) {
2144             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2145             return false;
2146         }
2147         return $this->insertQuery('../dns/form/dns_ptr.tform.php',$client_id,$params);
2148     }
2149     
2150     //* Update a record
2151     public function dns_ptr_update($session_id, $client_id, $primary_id, $params)
2152     {
2153         if(!$this->checkPerm($session_id, 'dns_ptr_update')) {
2154             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2155             return false;
2156         }
2157         $affected_rows = $this->updateQuery('../dns/form/dns_ptr.tform.php',$client_id,$primary_id,$params);
2158         return $affected_rows;
2159     }
2160     
2161     //* Delete a record
2162     public function dns_ptr_delete($session_id, $primary_id)
2163     {
2164         if(!$this->checkPerm($session_id, 'dns_ptr_delete')) {
2165             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2166             return false;
2167         }
2168         $affected_rows = $this->deleteQuery('../dns/form/dns_ptr.tform.php',$primary_id);
2169         return $affected_rows;
2170     }
2171     
2172     // ----------------------------------------------------------------------------------------------------------------
2173     
2174     //* Get record details
2175     public function dns_rp_get($session_id, $primary_id)
2176     {
2177         global $app;
2178         
2179         if(!$this->checkPerm($session_id, 'dns_rp_get')) {
2180             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2181             return false;
2182         }
2183         $app->uses('remoting_lib');
2184         $app->remoting_lib->loadFormDef('../dns/form/dns_rp.tform.php');
2185         return $app->remoting_lib->getDataRecord($primary_id);
2186     }
2187     
2188     //* Add a record
2189     public function dns_rp_add($session_id, $client_id, $params)
2190     {
2191         if(!$this->checkPerm($session_id, 'dns_rp_add')) {
2192             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2193             return false;
2194         }
2195         return $this->insertQuery('../dns/form/dns_rp.tform.php',$client_id,$params);
2196     }
2197     
2198     //* Update a record
2199     public function dns_rp_update($session_id, $client_id, $primary_id, $params)
2200     {
2201         if(!$this->checkPerm($session_id, 'dns_rp_update')) {
2202             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2203             return false;
2204         }
2205         $affected_rows = $this->updateQuery('../dns/form/dns_rp.tform.php',$client_id,$primary_id,$params);
2206         return $affected_rows;
2207     }
2208     
2209     //* Delete a record
2210     public function dns_rp_delete($session_id, $primary_id)
2211     {
2212         if(!$this->checkPerm($session_id, 'dns_rp_delete')) {
2213             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2214             return false;
2215         }
2216         $affected_rows = $this->deleteQuery('../dns/form/dns_rp.tform.php',$primary_id);
2217         return $affected_rows;
2218     }
2219     
2220     // ----------------------------------------------------------------------------------------------------------------
2221     
2222     //* Get record details
2223     public function dns_srv_get($session_id, $primary_id)
2224     {
2225         global $app;
2226         
2227         if(!$this->checkPerm($session_id, 'dns_srv_get')) {
2228             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2229             return false;
2230         }
2231         $app->uses('remoting_lib');
2232         $app->remoting_lib->loadFormDef('../dns/form/dns_srv.tform.php');
2233         return $app->remoting_lib->getDataRecord($primary_id);
2234     }
2235     
2236     //* Add a record
2237     public function dns_srv_add($session_id, $client_id, $params)
2238     {
2239         if(!$this->checkPerm($session_id, 'dns_srv_add')) {
2240             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2241             return false;
2242         }
2243         return $this->insertQuery('../dns/form/dns_srv.tform.php',$client_id,$params);
2244     }
2245     
2246     //* Update a record
2247     public function dns_srv_update($session_id, $client_id, $primary_id, $params)
2248     {
2249         if(!$this->checkPerm($session_id, 'dns_srv_update')) {
2250             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2251             return false;
2252         }
2253         $affected_rows = $this->updateQuery('../dns/form/dns_srv.tform.php',$client_id,$primary_id,$params);
2254         return $affected_rows;
2255     }
2256     
2257     //* Delete a record
2258     public function dns_srv_delete($session_id, $primary_id)
2259     {
2260         if(!$this->checkPerm($session_id, 'dns_srv_delete')) {
2261             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2262             return false;
2263         }
2264         $affected_rows = $this->deleteQuery('../dns/form/dns_srv.tform.php',$primary_id);
2265         return $affected_rows;
2266     }
2267     
2268     // ----------------------------------------------------------------------------------------------------------------
2269     
2270     //* Get record details
2271     public function dns_txt_get($session_id, $primary_id)
2272     {
2273         global $app;
2274         
2275         if(!$this->checkPerm($session_id, 'dns_txt_get')) {
2276             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2277             return false;
2278         }
2279         $app->uses('remoting_lib');
2280         $app->remoting_lib->loadFormDef('../dns/form/dns_txt.tform.php');
2281         return $app->remoting_lib->getDataRecord($primary_id);
2282     }
2283     
2284     //* Add a record
2285     public function dns_txt_add($session_id, $client_id, $params)
2286     {
2287         if(!$this->checkPerm($session_id, 'dns_txt_add')) {
2288             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2289             return false;
2290         }
2291         return $this->insertQuery('../dns/form/dns_txt.tform.php',$client_id,$params);
2292     }
2293     
2294     //* Update a record
2295     public function dns_txt_update($session_id, $client_id, $primary_id, $params)
2296     {
2297         if(!$this->checkPerm($session_id, 'dns_txt_update')) {
2298             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2299             return false;
2300         }
2301         $affected_rows = $this->updateQuery('../dns/form/dns_txt.tform.php',$client_id,$primary_id,$params);
2302         return $affected_rows;
2303     }
2304     
2305     //* Delete a record
2306     public function dns_txt_delete($session_id, $primary_id)
2307     {
2308         if(!$this->checkPerm($session_id, 'dns_txt_delete')) {
2309             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2310             return false;
2311         }
2312         $affected_rows = $this->deleteQuery('../dns/form/dns_txt.tform.php',$primary_id);
2313         return $affected_rows;
2314     }
2315     
2316     
2317     
2318     
2319     
2320     
2321     
2322     
2323     
2324     
2325         
2326
2327
031054 2328     //** protected functions -----------------------------------------------------------------------------------
532ae5 2329     
L 2330     
2331
2332
031054 2333     protected function klientadd($formdef_file, $reseller_id, $params)
532ae5 2334     {
L 2335         global $app, $tform, $remoting_lib;
2336         $app->uses('remoting_lib');
2337             
2338         //* Load the form definition
2339         $app->remoting_lib->loadFormDef($formdef_file);
2340         
2341         //* load the user profile of the client
2342         $app->remoting_lib->loadUserProfile($reseller_id);
2343         
2344         //* load the client template
2345         if(isset($params['template_master']) and $params['template_master'] > 0)
2346         {
2347             $template=$app->db->queryOneRecord("SELECT * FROM client_template WHERE template_id=".intval($params['template_master']));
c161ea 2348             if(is_array($template)) $params=array_merge($params,$template);
532ae5 2349         }
L 2350         
2351         //* Get the SQL query
2352         $sql = $app->remoting_lib->getSQL($params,'INSERT',0);
c8f203 2353         
8cf78b 2354         //* Check if no system user with that username exists
T 2355         $username = $app->db->quote($params["username"]);
355efb 2356         $tmp = $app->db->queryOneRecord("SELECT count(userid) as number FROM sys_user WHERE username = '$username'");
8cf78b 2357         if($tmp['number'] > 0) $app->remoting_lib->errorMessage .= "Duplicate username<br />";
T 2358         
355efb 2359         //* Stop on error while preparing the sql query
532ae5 2360         if($app->remoting_lib->errorMessage != '') {
L 2361             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
2362             return false;
2363         }
2364         
355efb 2365         //* Execute the SQL query
T 2366         $app->db->query($sql);
c8f203 2367         $insert_id = $app->db->insertID();
355efb 2368         
T 2369         
2370         //* Stop on error while executing the sql query
2371         if($app->remoting_lib->errorMessage != '') {
2372             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
2373             return false;
2374         }
c8f203 2375         
T 2376         $this->id = $insert_id;
2377         $this->dataRecord = $params;
532ae5 2378         
343845 2379         $app->plugin->raiseEvent('client:client:on_after_insert',$this);
T 2380         
c8f203 2381         /*
532ae5 2382         if($app->db->errorMessage != '') {
L 2383             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
2384             return false;
2385         }
c8f203 2386         */
532ae5 2387         
c8f203 2388             
532ae5 2389         //$app->uses('tform');
L 2390         //* Save changes to Datalog
2391         if($app->remoting_lib->formDef["db_history"] == 'yes') {
2392             $new_rec = $app->remoting_lib->getDataRecord($insert_id);
2393             $app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);            
2394             $app->remoting_lib->ispconfig_sysuser_add($params,$insert_id);
2395
2396             if($reseller_id) {
2397                 $client_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = ".$insert_id);
2398                 $reseller_user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE client_id = ".$reseller_id);
2399                 $app->auth->add_group_to_user($reseller_user['userid'], $client_group['groupid']);
2400                 $app->db->query("UPDATE client SET parent_client_id = ".$reseller_id." WHERE client_id = ".$insert_id);
2401             }   
2402
2403         }
2404         return $insert_id;
2405     }
2406
031054 2407     protected function insertQuery($formdef_file, $client_id, $params,$event_identifier = '')
532ae5 2408     {
L 2409         global $app, $tform, $remoting_lib;
2410         
2411         $app->uses('remoting_lib');
2412         
2413         //* load the user profile of the client
2414         $app->remoting_lib->loadUserProfile($client_id);
2415         
2416         //* Load the form definition
2417         $app->remoting_lib->loadFormDef($formdef_file);
2418         
2419         //* Get the SQL query
2420         $sql = $app->remoting_lib->getSQL($params,'INSERT',0);
2421         if($app->remoting_lib->errorMessage != '') {
2422             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
2423             return false;
2424         }
2425         
2426         $app->db->query($sql);
2427         
2428         if($app->db->errorMessage != '') {
2429             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
2430             return false;
2431         }
2432         
2433         $insert_id = $app->db->insertID();
2434         
2435         // set a few values for compatibility with tform actions, mostly used by plugins
2436         $this->id = $insert_id;
2437         $this->dataRecord = $params;
2438         
2439         if($event_identifier != '') $app->plugin->raiseEvent($event_identifier,$this);
2440     
2441         //$app->uses('tform');
2442         //* Save changes to Datalog
2443         if($app->remoting_lib->formDef["db_history"] == 'yes') {
2444             $new_rec = $app->remoting_lib->getDataRecord($insert_id);
2445             $app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);            
2446         }        
2447         return $insert_id;
2448     }
2449     
2450     
031054 2451     protected function updateQuery($formdef_file, $client_id, $primary_id, $params, $event_identifier = '')
532ae5 2452     {
L 2453         global $app;
2454         
2455         $app->uses('remoting_lib');
2456         
2457         //* load the user profile of the client
2458         $app->remoting_lib->loadUserProfile($client_id);
2459         
2460         //* Load the form definition
2461         $app->remoting_lib->loadFormDef($formdef_file);
2462         
2463         //* Get the SQL query
2464         $sql = $app->remoting_lib->getSQL($params,'UPDATE',$primary_id);
26c0fc 2465         // $this->server->fault('debug', $sql);
532ae5 2466         if($app->remoting_lib->errorMessage != '') {
L 2467             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
2468             return false;
2469         }
2470         
2471         $old_rec = $app->remoting_lib->getDataRecord($primary_id);
2472         
2473         // set a few values for compatibility with tform actions, mostly used by plugins
2474         $this->oldDataRecord = $old_rec;
2475         $this->id = $primary_id;
2476         $this->dataRecord = $params;
2477         
2478         $app->db->query($sql);
2479         
2480         if($app->db->errorMessage != '') {
2481             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
2482             return false;
2483         }
2484         
2485         $affected_rows = $app->db->affectedRows();
2486         
2487         if($event_identifier != '') $app->plugin->raiseEvent($event_identifier,$this);
2488         
2489         //* Save changes to Datalog
2490         if($app->remoting_lib->formDef["db_history"] == 'yes') {
2491             $new_rec = $app->remoting_lib->getDataRecord($primary_id);
2492             $app->remoting_lib->datalogSave('UPDATE',$primary_id,$old_rec,$new_rec);
2493         }
2494         
2495         return $affected_rows;
2496     }
2497     
031054 2498     protected function deleteQuery($formdef_file, $primary_id, $event_identifier = '')
532ae5 2499     {
L 2500         global $app;
2501         
2502         $app->uses('remoting_lib');
2503         
2504         //* load the user profile of the client
2505         $app->remoting_lib->loadUserProfile(0);
2506         
2507         //* Load the form definition
2508         $app->remoting_lib->loadFormDef($formdef_file);
2509         
2510         $old_rec = $app->remoting_lib->getDataRecord($primary_id);
2511         
2512         // set a few values for compatibility with tform actions, mostly used by plugins
2513         $this->oldDataRecord = $old_rec;
2514         $this->id = $primary_id;
355efb 2515         $this->dataRecord = $old_rec;
T 2516         //$this->dataRecord = $params;
532ae5 2517         
L 2518         //* Get the SQL query
2519         $sql = $app->remoting_lib->getDeleteSQL($primary_id);
355efb 2520         $app->db->errorMessage = '';
532ae5 2521         $app->db->query($sql);
355efb 2522         $affected_rows = $app->db->affectedRows();
532ae5 2523         
L 2524         if($app->db->errorMessage != '') {
2525             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
2526             return false;
2527         }
2528         
355efb 2529         if($event_identifier != '') {
T 2530             $app->plugin->raiseEvent($event_identifier,$this);
2531         }
532ae5 2532         
L 2533         //* Save changes to Datalog
2534         if($app->remoting_lib->formDef["db_history"] == 'yes') {
2535             $app->remoting_lib->datalogSave('DELETE',$primary_id,$old_rec,array());
2536         }
2537         
2538         
2539         return $affected_rows;
2540     }
2541     
2542     
031054 2543     protected function checkPerm($session_id, $function_name)
532ae5 2544     {
ecf891 2545         global $app;
532ae5 2546     $dobre=array();
L 2547     $session = $this->getSession($session_id);
2548         if(!$session){
2549             return false;
2550         }
2551         
2552         $dobre= str_replace(';',',',$session['remote_functions']);
ecf891 2553         $check = in_array($function_name, explode(',', $dobre) );
N 2554         if(!$check) {
2555           $app->log("REMOTE-LIB DENY: ".$session_id ." /". $function_name, LOGLEVEL_WARN);
2556         }
2557         return $check;
532ae5 2558     }
L 2559     
2560     
031054 2561     protected function getSession($session_id)
532ae5 2562     {    
L 2563         global $app;
2564         
2565         if(empty($session_id)) {
2566             $this->server->fault('session_id_empty','The SessionID is empty.');
2567             return false;
2568         }
2569         
2570         $session_id = $app->db->quote($session_id);
2571         
2572         $now = time();
2573         $sql = "SELECT * FROM remote_session WHERE remote_session = '$session_id' AND tstamp >= $now";
2574         $session = $app->db->queryOneRecord($sql);
2575         if($session['remote_userid'] > 0) {
2576             return $session;
2577         } else {
2578             $this->server->fault('session_does_not_exist','The Session is expired or does not exist.');
2579             return false;
2580         }
2581     }
2582     
2583     //---
2584     
2585     
2586     /**
2587      * Gets sites by $sys_userid & $sys_groupid
2588      * @param    int        session id
2589      * @param    int        user id
2590      * @param    array    list of groups
2591      * @return    mixed    array with sites by user
2592      * @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2593      */
2594     public function client_get_sites_by_user($session_id, $sys_userid, $sys_groupid) {
2595         global $app;
2596         if(!$this->checkPerm($session_id, 'client_get_sites_by_user')) {
2597               $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2598               return false;
2599         }
2600         $sys_userid  = intval($sys_userid);        
2601         $sys_groupid = explode(',', $sys_groupid);
2602         $new_group = array();
2603         foreach($sys_groupid as $group_id) {
2604             $new_group[] = intval( $group_id);
2605         }
2606         $group_list = implode(',', $new_group);
2607         $sql ="SELECT domain, domain_id, document_root, active FROM web_domain WHERE ( (sys_userid = $sys_userid  AND sys_perm_user LIKE '%r%') OR (sys_groupid IN ($group_list) AND sys_perm_group LIKE '%r%') OR  sys_perm_other LIKE '%r%') AND type = 'vhost'";
2608         $result = $app->db->queryAllRecords($sql);
2609         if(isset($result)) {
2610             return $result;
2611         } else {
2612             $this->server->fault('no_client_found', 'There is no site for this user');
2613             return false;
2614         }
2615     }
2616     
2617     /**
2618      * Change domains status
2619      * @param    int        session id
2620      * @param    int        site id
2621      * @param    string    active or inactive string 
2622      * @return    mixed    false if error
2623      * @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2624      */
2625      
2626     public function sites_web_domain_set_status($session_id, $primary_id, $status) {
2627         global $app;
2628         if(!$this->checkPerm($session_id, 'sites_web_domain_set_status')) {
2629             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2630             return false;
2631         }        
2632         if(in_array($status, array('active', 'inactive'))) {                    
2633             if ($status == 'active') {
2634                 $status = 'y';
2635             } else {
2636                 $status = 'n';
2637             }
2638             $sql = "UPDATE web_domain SET active = '$status' WHERE domain_id = ".intval($primary_id);            
2639             $app->db->query($sql);
2640             $result = $app->db->affectedRows();    
2641              return $result;
2642         } else {
2643             $this->server->fault('status_undefined', 'The status is not available');
2644             return false;
2645         }      
2646     }
2647     
2648     /**
2649      * Get sys_user information by username
2650      * @param    int        session id
2651      * @param    string    user's name  
2652      * @return    mixed    false if error
2653      * @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2654      */
2655     public function client_get_by_username($session_id, $username) {
2656         global $app;
2657         if(!$this->checkPerm($session_id, 'client_get_by_username')) {
2658             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2659             return false;
2660         }
2661         $username = $app->db->quote($username);
2662         $rec = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE username = '".$username."'");
2663         if (isset($rec)) {
2664             return $rec;
2665         } else {
2666             $this->server->fault('no_client_found', 'There is no user account for this user name.');
2667             return false;
2668         }
2669     }
ecf891 2670       /**
N 2671        * Get All client_id's from database
2672        * @param int    session_id
2673        * @return Array of all client_id's
2674        */
2675     public function client_get_all($session_id) {
2676       global $app;
2677       if(!$this->checkPerm($session_id, 'client_get_all')) {
2678         $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2679         return false;
2680       }
2681       $result = $app->db->queryAllRecords("SELECT client_id FROM client WHERE 1");
2682       if(!$result) {
2683         return false;
2684       }
2685       foreach( $result as $record) {
2686         $rarrary[] = $record['client_id'];
2687       }
2688       return $rarrary;
2689     }
532ae5 2690
L 2691     /**
2692      * Changes client password
2693      * 
2694        * @param    int        session id
2695        * @param    int        client    id
2696        * @param    string    new password
2697        * @return    bool    true if success 
2698      * @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2699      * 
2700      */
2701     public function client_change_password($session_id, $client_id, $new_password) {
2702         global $app;
2703
2704         if(!$this->checkPerm($session_id, 'client_change_password')) {
2705             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2706             return false;
2707         }
2708         $client_id = intval($client_id);
2709         $client = $app->db->queryOneRecord("SELECT client_id FROM client WHERE client_id = ".$client_id);
2710         if($client['client_id'] > 0) {
2711             $new_password = $app->db->quote($new_password);
2712             $sql = "UPDATE client SET password = md5('".($new_password)."')     WHERE client_id = ".$client_id;
2713             $app->db->query($sql);            
2714             $sql = "UPDATE sys_user SET passwort = md5('".($new_password)."')     WHERE client_id = ".$client_id;
2715             $app->db->query($sql);            
2716             return true;
2717         } else {
2718             $this->server->fault('no_client_found', 'There is no user account for this client_id');
2719             return false;
2720         }
2721     }
9e0f11 2722
L 2723     /**
2724     * Fetch the mail_domain record for the provided domain.
2725     * @param int session_id
2726     * @param string the fully qualified domain (or subdomain)
2727     * @return array array of arrays corresponding to the mail_domain table's records
2728     * @author till, benlake
2729     */
532ae5 2730     public function mail_domain_get_by_domain($session_id, $domain) {
L 2731         global $app;
2732         if(!$this->checkPerm($session_id, 'mail_domain_get_by_domain')) {
2733             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2734             return false;
2735         }        
9e0f11 2736         if (!empty($domain)) {
532ae5 2737             $domain          = $app->db->quote($domain);            
9e0f11 2738             $sql            = "SELECT * FROM mail_domain WHERE domain = '$domain'";
532ae5 2739             $result         = $app->db->queryAllRecords($sql);
L 2740             return          $result;
2741         }
2742         return false;
2743     }
9e0f11 2744
532ae5 2745     /**
L 2746        * Get a list of functions
2747        * @param     int        session id
2748        * @return    mixed    array of the available functions
2749     * @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2750     */
2751     public function get_function_list($session_id) 
2752     {
2753         if(!$this->checkPerm($session_id, 'get_function_list')) {
2754             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2755             return false;
2756         }
2757         return get_class_methods($this);
2758     }
2759     
2760     /**
2761      * Get all databases by user
2762      * @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2763      */
2764     public function sites_database_get_all_by_user($session_id, $client_id)
2765     {
2766         global $app;
92991d 2767         if(!$this->checkPerm($session_id, 'sites_database_get')) {
532ae5 2768             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
L 2769             return false;
2770         }
2771         $client_id = intval($client_id);
8ab3cd 2772         $sql = "SELECT d.database_id, d.database_name, d.database_user, d.database_password FROM web_database d INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = $client_id";
T 2773         $all = $app->db->queryAllRecords($sql);
532ae5 2774         return $all;
L 2775     }
2776     
2777     /**
2778      *     Get all client templates
2779      *    @param     int        session id
2780      *    @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2781      */
2782     public function client_templates_get_all($session_id) {
2783         global $app;
2784         if(!$this->checkPerm($session_id, 'client_templates_get_all')) {
2785              $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2786             return false;
2787         }
2788         $sql    = "SELECT * FROM client_template";
2789         $result = $app->db->queryAllRecords($sql);
2790         return $result;
2791    }
2792     
2793     /**
2794      * Get all DNS zone by user 
2795      *@author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2796      */     
2797     public function dns_zone_get_by_user($session_id, $client_id, $server_id) {
2798         global $app;
2799         if(!$this->checkPerm($session_id, 'dns_zone_get')) {
2800             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2801             return false;
2802         }        
2803         if (!empty($client_id) && !empty($server_id)) {
2804             $server_id      = intval($server_id);
2805             $client_id      = intval($client_id);
2806             $sql            = "SELECT id, origin FROM dns_soa d INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = $client_id AND server_id = $server_id";
2807             $result         = $app->db->queryAllRecords($sql);
2808             return          $result;
2809         }
2810         return false;
2811     }
2812     
159828 2813     /**
S 2814      *     Get all dns records for a zone
2815      *    @param     int        session id
2816      *    @param     int        dns zone id
2817      *    @author    Sebastian Mogilowski <sebastian@mogilowski.net> 2011
2818      */
2819     public function dns_rr_get_all_by_zone($session_id, $zone_id) {
2820         global $app;
2821         if(!$this->checkPerm($session_id, 'dns_zone_get')) {
2822              $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2823             return false;
2824         }
2825         $sql    = "SELECT * FROM dns_rr WHERE zone = ".intval($zone_id);;
2826         $result = $app->db->queryAllRecords($sql);
2827         return $result;
2828    }
2829
532ae5 2830     /**
L 2831      * Changes DNS zone status 
2832      *    @param     int        session id
2833      *    @param    int        dns soa id
2834      *    @param    string    status active or inactive string
2835      *    @author    Julio Montoya <gugli100@gmail.com> BeezNest 2010
2836      */
2837      
2838     public function dns_zone_set_status($session_id, $primary_id, $status) {
2839         global $app;
2840         if(!$this->checkPerm($session_id, 'dns_zone_set_status')) {
2841               $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2842                return false;
2843         }        
2844         if(in_array($status, array('active', 'inactive'))) {                        
2845             if ($status == 'active') {
2846                 $status = 'Y';
2847             } else {
2848                 $status = 'N';
2849             }
2850             $sql = "UPDATE dns_soa SET active = '$status' WHERE id = ".intval($primary_id);
2851             $app->db->query($sql);
2852             $result = $app->db->affectedRows();
2853             return $result;
2854         } else {
2855             $this->server->fault('status_undefined', 'The status is not available');
2856             return false;
2857         }  
2858     }
2859     
2860     public function mail_domain_set_status($session_id, $primary_id, $status) {
2861         global $app;
2862         if(!$this->checkPerm($session_id, 'mail_domain_set_status')) {
2863               $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2864                return false;
2865         }        
2866         if(in_array($status, array('active', 'inactive'))) {                        
2867             if ($status == 'active') {
2868                 $status = 'y';
2869             } else {
2870                 $status = 'n';
2871             }
2872             $sql = "UPDATE mail_domain SET active = '$status' WHERE domain_id = ".intval($primary_id);
2873             $app->db->query($sql);
2874             $result = $app->db->affectedRows();
2875             return $result;
2876         } else {
2877             $this->server->fault('status_undefined', 'The status is not available');
2878             return false;
2879         }  
2880     }
077c27 2881     
T 2882     //* Functions for virtual machine management
2883     
2884     //* Get OpenVZ OStemplate details
2885     public function openvz_ostemplate_get($session_id, $ostemplate_id)
2886     {
2887         global $app;
2888         
2889         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2890             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2891             return false;
2892         }
2893         $app->uses('remoting_lib');
2894         $app->remoting_lib->loadFormDef('../vm/form/openvz_ostemplate.tform.php');
2895         return $app->remoting_lib->getDataRecord($ostemplate_id);
2896     }
2897     
2898     //* Add a openvz ostemplate record
2899     public function openvz_ostemplate_add($session_id, $client_id, $params)
2900     {
2901         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2902             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2903             return false;
2904         }
2905         return $this->insertQuery('../vm/form/openvz_ostemplate.tform.php',$client_id,$params);
2906     }
2907     
2908     //* Update openvz ostemplate record
2909     public function openvz_ostemplate_update($session_id, $client_id, $ostemplate_id, $params)
2910     {
2911         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2912             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2913             return false;
2914         }
2915         $affected_rows = $this->updateQuery('../vm/form/openvz_ostemplate.tform.php',$client_id,$ostemplate_id,$params);
2916         return $affected_rows;
2917     }
2918     
2919     //* Delete openvz ostemplate record
2920     public function openvz_ostemplate_delete($session_id, $ostemplate_id)
2921     {
2922         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2923             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2924             return false;
2925         }
2926         $affected_rows = $this->deleteQuery('../vm/form/openvz_ostemplate.tform.php',$ostemplate_id);
2927         return $affected_rows;
2928     }
2929     
2930     //* Get OpenVZ template details
2931     public function openvz_template_get($session_id, $template_id)
2932     {
2933         global $app;
2934         
2935         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2936             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2937             return false;
2938         }
2939         $app->uses('remoting_lib');
2940         $app->remoting_lib->loadFormDef('../vm/form/openvz_template.tform.php');
2941         return $app->remoting_lib->getDataRecord($template_id);
2942     }
2943     
2944     //* Add a openvz template record
2945     public function openvz_template_add($session_id, $client_id, $params)
2946     {
2947         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2948             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2949             return false;
2950         }
2951         return $this->insertQuery('../vm/form/openvz_template.tform.php',$client_id,$params);
2952     }
2953     
2954     //* Update openvz template record
2955     public function openvz_template_update($session_id, $client_id, $template_id, $params)
2956     {
2957         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2958             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2959             return false;
2960         }
2961         $affected_rows = $this->updateQuery('../vm/form/openvz_template.tform.php',$client_id,$template_id,$params);
2962         return $affected_rows;
2963     }
2964     
2965     //* Delete openvz template record
2966     public function openvz_template_delete($session_id, $template_id)
2967     {
2968         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2969             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2970             return false;
2971         }
2972         $affected_rows = $this->deleteQuery('../vm/form/openvz_template.tform.php',$template_id);
2973         return $affected_rows;
2974     }
2975     
2976     //* Get OpenVZ ip details
2977     public function openvz_ip_get($session_id, $ip_id)
2978     {
2979         global $app;
2980         
2981         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2982             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2983             return false;
2984         }
2985         $app->uses('remoting_lib');
2986         $app->remoting_lib->loadFormDef('../vm/form/openvz_ip.tform.php');
2987         return $app->remoting_lib->getDataRecord($ip_id);
2988     }
2989     
2990     //* Get OpenVZ a free IP address
2991     public function openvz_get_free_ip($session_id, $server_id = 0)
2992     {
2993         global $app;
2994         
2995         if(!$this->checkPerm($session_id, 'vm_openvz')) {
2996             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2997             return false;
2998         }
2999         $server_id = intval($server_id);
3000         
3001         if($server_id > 0) {
3002             $tmp = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 AND server_id = $server_id LIMIT 0,1");
3003         } else {
3004             $tmp = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 LIMIT 0,1");
3005         }
3006         
3007         if(count($tmp) > 0) {
3008             return $tmp;
3009         } else {
3010             $this->server->fault('no_free_ip', 'There is no free IP available.');
3011         }
3012     }
3013     
3014     //* Add a openvz ip record
3015     public function openvz_ip_add($session_id, $client_id, $params)
3016     {
3017         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3018             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3019             return false;
3020         }
3021         return $this->insertQuery('../vm/form/openvz_ip.tform.php',$client_id,$params);
3022     }
3023     
3024     //* Update openvz ip record
3025     public function openvz_ip_update($session_id, $client_id, $ip_id, $params)
3026     {
3027         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3028             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3029             return false;
3030         }
3031         $affected_rows = $this->updateQuery('../vm/form/openvz_ip.tform.php',$client_id,$ip_id,$params);
3032         return $affected_rows;
3033     }
3034     
3035     //* Delete openvz ip record
3036     public function openvz_ip_delete($session_id, $ip_id)
3037     {
3038         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3039             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3040             return false;
3041         }
3042         $affected_rows = $this->deleteQuery('../vm/form/openvz_ip.tform.php',$ip_id);
3043         return $affected_rows;
3044     }
3045     
3046     //* Get OpenVZ vm details
3047     public function openvz_vm_get($session_id, $vm_id)
3048     {
3049         global $app;
3050         
3051         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3052             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3053             return false;
3054         }
3055         $app->uses('remoting_lib');
3056         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
3057         return $app->remoting_lib->getDataRecord($vm_id);
3058     }
3059     
c161ea 3060     //* Get OpenVZ list
T 3061     public function openvz_vm_get_by_client($session_id, $client_id)
3062     {
3063         global $app;
3064         
3065         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3066             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3067             return false;
3068         }
3069         
3070         if (!empty($client_id)) {
3071             $client_id      = intval($client_id);
3072             $tmp             = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
3073             $sql            = "SELECT * FROM openvz_vm WHERE sys_groupid = ".intval($tmp['groupid']);
3074             $result         = $app->db->queryAllRecords($sql);
3075             return          $result;
3076         }
3077         return false;
3078     }
3079     
077c27 3080     //* Add a openvz vm record
T 3081     public function openvz_vm_add($session_id, $client_id, $params)
3082     {
3083         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3084             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3085             return false;
3086         }
3087         return $this->insertQuery('../vm/form/openvz_vm.tform.php',$client_id,$params);
3088     }
3089     
3090     //* Add a openvz vm record from template
3091     public function openvz_vm_add_from_template($session_id, $client_id, $ostemplate_id, $template_id, $override_params = array())
3092     {
3093         global $app;
3094         
3095         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3096             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3097             return false;
3098         }
3099         
3100         
3101         $template_id = intval($template_id);
3102         $ostemplate_id = intval($ostemplate_id);
3103         
3104         //* Verify parameters
3105         if($template_id == 0) {
3106             $this->server->fault('template_id_error', 'Template ID must be > 0.');
3107             return false;
3108         }
3109         if($ostemplate_id == 0) {
3110             $this->server->fault('ostemplate_id_error', 'OSTemplate ID must be > 0.');
3111             return false;
3112         }
3113         
3114         // Verify if template and ostemplate exist
3115         $tmp = $app->db->queryOneRecord("SELECT template_id FROM openvz_template WHERE template_id = $template_id");
3116         if(!is_array($tmp)) {
3117             $this->server->fault('template_id_error', 'Template does not exist.');
3118             return false;
3119         }
3120         $tmp = $app->db->queryOneRecord("SELECT ostemplate_id FROM openvz_ostemplate WHERE ostemplate_id = $ostemplate_id");
3121         if(!is_array($tmp)) {
3122             $this->server->fault('ostemplate_id_error', 'OSTemplate does not exist.');
3123             return false;
3124         }
3125         
3126         //* Get the template
3127         $vtpl = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = $template_id");
3128         
3129         //* Get the IP address and server_id
3130         if($override_params['server_id'] > 0) {
3131             $vmip = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 AND server_id = ".$override_params['server_id']." LIMIT 0,1");
3132         } else {
3133             $vmip = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 LIMIT 0,1");
3134         }
3135         if(!is_array($vmip)) {
3136             $this->server->fault('vm_ip_error', 'Unable to get a free VM IP.');
3137             return false;
3138         }
3139         
3140         //* Build the $params array
3141         $params = array();
3142         $params['server_id'] = $vmip['server_id'];
3143         $params['ostemplate_id'] = $ostemplate_id;
3144         $params['template_id'] = $template_id;
3145         $params['ip_address'] = $vmip['ip_address'];
3146         $params['hostname'] = (isset($override_params['hostname']))?$override_params['hostname']:$vtpl['hostname'];
3147         $params['vm_password'] = (isset($override_params['vm_password']))?$override_params['vm_password']:$app->auth->get_random_password(10);
3148         $params['start_boot'] = (isset($override_params['start_boot']))?$override_params['start_boot']:'y';
3149         $params['active'] = (isset($override_params['active']))?$override_params['active']:'y';
3150         $params['active_until_date'] = (isset($override_params['active_until_date']))?$override_params['active_until_date']:'0000-00-00';
3151         $params['description'] = (isset($override_params['description']))?$override_params['description']:'';
3152         
3153         //* The next params get filled with pseudo values, as the get replaced 
3154         //* by the openvz event plugin anyway with values from the template
3155         $params['veid'] = 1;
3156         $params['diskspace'] = 1;
3157         $params['ram'] = 1;
3158         $params['ram_burst'] = 1;
3159         $params['cpu_units'] = 1;
3160         $params['cpu_num'] = 1;
3161         $params['cpu_limit'] = 1;
3162         $params['io_priority'] = 1;
3163         $params['nameserver'] = '8.8.8.8 8.8.4.4';
3164         $params['create_dns'] = 'n';
3165         $params['capability'] = '';
3166         
3167         return $this->insertQuery('../vm/form/openvz_vm.tform.php',$client_id,$params,'vm:openvz_vm:on_after_insert');
3168     }
3169     
3170     //* Update openvz vm record
3171     public function openvz_vm_update($session_id, $client_id, $vm_id, $params)
3172     {
3173         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3174             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3175             return false;
3176         }
3177         $affected_rows = $this->updateQuery('../vm/form/openvz_vm.tform.php',$client_id,$vm_id,$params,'vm:openvz_vm:on_after_update');
3178         return $affected_rows;
3179     }
3180     
3181     //* Delete openvz vm record
3182     public function openvz_vm_delete($session_id, $vm_id)
3183     {
3184         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3185             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3186             return false;
3187         }
3188         $affected_rows = $this->deleteQuery('../vm/form/openvz_vm.tform.php',$vm_id,'vm:openvz_vm:on_after_delete');
3189         return $affected_rows;
3190     }
3191     
6882ab 3192     //* Start VM
T 3193     public function openvz_vm_start($session_id, $vm_id)
3194     {
3195         global $app;
3196         
3197         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3198             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3199             return false;
3200         }
3201         
3202         $app->uses('remoting_lib');
3203         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
3204         $vm = $app->remoting_lib->getDataRecord($vm_id);
3205         
3206         if(!is_array($vm)) {
3207             $this->server->fault('action_pending', 'No VM with this ID available.');
3208             return false;
3209         }
3210         
3211         if($vm['active'] == 'n') {
3212             $this->server->fault('action_pending', 'VM is not in active state.');
3213             return false;
3214         }
3215         
3216         $action = 'openvz_start_vm';
3217         
3218         $tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction 
3219                 WHERE server_id = '".$vm['server_id']."' 
3220                 AND action_type = '$action'
3221                 AND action_param = '".$vm['veid']."'
3222                 AND action_state = 'pending'");
3223         
3224         if($tmp['actions'] > 0) {
3225             $this->server->fault('action_pending', 'There is already a action pending for this VM.');
3226             return false;
3227         } else {
3228             $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
3229                     "VALUES (".
3230                     (int)$vm['server_id'] . ", ".
3231                     time() . ", ".
3232                     "'".$action."', ".
3233                     $vm['veid'].", ".
3234                     "'pending', ".
3235                     "''".
3236                     ")";
3237             $app->db->query($sql);
3238         }
3239     }
077c27 3240     
6882ab 3241     //* Stop VM
T 3242     public function openvz_vm_stop($session_id, $vm_id)
3243     {
3244         global $app;
3245         
3246         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3247             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3248             return false;
3249         }
3250         
3251         $app->uses('remoting_lib');
3252         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
3253         $vm = $app->remoting_lib->getDataRecord($vm_id);
3254         
3255         if(!is_array($vm)) {
3256             $this->server->fault('action_pending', 'No VM with this ID available.');
3257             return false;
3258         }
3259         
3260         if($vm['active'] == 'n') {
3261             $this->server->fault('action_pending', 'VM is not in active state.');
3262             return false;
3263         }
3264         
3265         $action = 'openvz_stop_vm';
3266         
3267         $tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction 
3268                 WHERE server_id = '".$vm['server_id']."' 
3269                 AND action_type = '$action'
3270                 AND action_param = '".$vm['veid']."'
3271                 AND action_state = 'pending'");
3272         
3273         if($tmp['actions'] > 0) {
3274             $this->server->fault('action_pending', 'There is already a action pending for this VM.');
3275             return false;
3276         } else {
3277             $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
3278                     "VALUES (".
3279                     (int)$vm['server_id'] . ", ".
3280                     time() . ", ".
3281                     "'".$action."', ".
3282                     $vm['veid'].", ".
3283                     "'pending', ".
3284                     "''".
3285                     ")";
3286             $app->db->query($sql);
3287         }
3288     }
077c27 3289     
6882ab 3290     //* Restart VM
T 3291     public function openvz_vm_restart($session_id, $vm_id)
3292     {
3293         global $app;
3294         
3295         if(!$this->checkPerm($session_id, 'vm_openvz')) {
3296             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3297             return false;
3298         }
3299         
3300         $app->uses('remoting_lib');
3301         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
3302         $vm = $app->remoting_lib->getDataRecord($vm_id);
3303         
3304         if(!is_array($vm)) {
3305             $this->server->fault('action_pending', 'No VM with this ID available.');
3306             return false;
3307         }
3308         
3309         if($vm['active'] == 'n') {
3310             $this->server->fault('action_pending', 'VM is not in active state.');
3311             return false;
3312         }
3313         
3314         $action = 'openvz_restart_vm';
3315         
3316         $tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction 
3317                 WHERE server_id = '".$vm['server_id']."' 
3318                 AND action_type = '$action'
3319                 AND action_param = '".$vm['veid']."'
3320                 AND action_state = 'pending'");
3321         
3322         if($tmp['actions'] > 0) {
3323             $this->server->fault('action_pending', 'There is already a action pending for this VM.');
3324             return false;
3325         } else {
3326             $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
3327                     "VALUES (".
3328                     (int)$vm['server_id'] . ", ".
3329                     time() . ", ".
3330                     "'".$action."', ".
3331                     $vm['veid'].", ".
3332                     "'pending', ".
3333                     "''".
3334                     ")";
3335             $app->db->query($sql);
3336         }
3337     }
077c27 3338     
T 3339     
3340     
3341     
532ae5 3342 }
ecf891 3343 ?>