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