tbrehm
2009-11-18 80e7b0d7d17b0e9581fa56be484b8772d82261de
commit | author | age
80e7b0 1 <?php
T 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
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     
44     /*
45     These variables shall stay global. 
46     Please do not make them private variables.
47     
48     private $app;
49     private $conf;
50     */
51
52     public function __construct()
53     {
54         global $server;
55         $this->server = $server;
56         /*
57         $this->app = $app;
58         $this->conf = $conf;
59         */
60     }
61
62     //* remote login function
63     public function login($username, $password)
64     {
65         global $app, $conf, $server;
66         
67         if(empty($username)) {
68             $this->server->fault('login_username_empty', 'The login username is empty');
69             return false;
70         }
71         
72         if(empty($password)) {
73             $this->server->fault('login_password_empty', 'The login password is empty');
74             return false;
75         }
76         
77         //* Delete old remoting sessions
78         $sql = "DELETE FROM remote_session WHERE tstamp < ".time();
79         $app->db->query($sql);
80         
81         $username = $app->db->quote($username);
82         $password = $app->db->quote($password);
83         
84         $sql = "SELECT * FROM remote_user WHERE remote_username = '$username' and remote_password = md5('$password')";
85         $remote_user = $app->db->queryOneRecord($sql);
86         if($remote_user['remote_userid'] > 0) {
87             //* Create a remote user session
88             srand ((double)microtime()*1000000);
89             $remote_session = md5(rand());
90             $remote_userid = $remote_user['remote_userid'];
91             $remote_functions = $remote_user['remote_functions'];
92             $tstamp = time() + $this->session_timeout;
93             $sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp'
94                    .') VALUES ('
95                    ." '$remote_session',$remote_userid,'$remote_functions',$tstamp)";
96             $app->db->query($sql);
97             return $remote_session;
98         } else {
99             $this->server->fault('login_failed', 'The login failed. Username or password wrong.');
100             return false;
101         }
102         
103     }
104     
105     //* remote logout function
106     public function logout($session_id)
107     {        
108         global $app;
109         
110         if(empty($session_id)) {
111             $this->server->fault('session_id_empty', 'The SessionID is empty.');
112             return false;
113         }
114         
115         $session_id = $app->db->quote($session_id);
116         
117         $sql = "DELETE FROM remote_session WHERE remote_session = '$session_id'";
118         $app->db->query($sql);
119         return ($app->db->affectedRows() == 1);
120     }
121     
122     //* Get mail domain details
123     public function mail_domain_get($session_id, $domain_id)
124     {
125         global $app;
126         
127         if(!$this->checkPerm($session_id, 'mail_domain_get')) {
128             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
129             return false;
130         }
131         $app->uses('remoting_lib');
132         $app->remoting_lib->loadFormDef('../mail/form/mail_domain.tform.php');
133         return $app->remoting_lib->getDataRecord($domain_id);
134     }
135     
136     //* Add a mail domain
137     public function mail_domain_add($session_id, $client_id, $params)
138     {
139         if(!$this->checkPerm($session_id, 'mail_domain_add')) {
140             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
141             return false;
142         }
143         $domain_id = $this->insertQuery('../mail/form/mail_domain.tform.php',$client_id,$params);
144         return $domain_id;
145     }
146     
147     //* Update a mail domain
148     public function mail_domain_update($session_id, $client_id, $domain_id, $params)
149     {
150         if(!$this->checkPerm($session_id, 'mail_domain_update')) {
151             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
152             return false;
153         }
154         $affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php',$client_id,$domain_id,$params);
155         return $affected_rows;
156     }
157     
158     //* Delete a mail domain
159     public function mail_domain_delete($session_id, $domain_id)
160     {
161         if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
162             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
163             return false;
164         }
165         $affected_rows = $this->deleteQuery('../mail/form/mail_domain.tform.php',$domain_id);
166         return $affected_rows;
167     }
168     
169     //* Get mail user details
170     public function mail_user_get($session_id, $primary_id)
171     {
172         global $app;
173         
174         if(!$this->checkPerm($session_id, 'mail_user_get')) {
175             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
176             return false;
177         }
178         $app->uses('remoting_lib');
179         $app->remoting_lib->loadFormDef('../mail/form/mail_user.tform.php');
180         return $app->remoting_lib->getDataRecord($primary_id);
181     }
182     
183     
184     //* dodanie uzytkownika email
185     public function mail_user_add($session_id,$domain_id, $client_id, $params){
186         if (!$this->checkPerm($session_id, 'mail_user_add')){
187             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
188             return false;
189         }
190         $affected_rows = $this->insertQuery('../mail/form/mail_user.tform.php',$domain_id, $client_id, $params);
191         return $affected_rows;
192     }
193
194     //* edycja uzytkownika email    
195     public function mail_user_update($session_id, $client_id, $domain_id, $params)
196     {
197         if (!$this->checkPerm($session_id, 'mail_user_update'))
198         {
199             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
200             return false;
201         }
202         $affected_rows = $this->updateQuery('../mail/form/mail_user.tform.php', $client_id, $domain_id, $params);
203         return $affected_rows;
204     }
205
206     
207     //*usuniecie uzytkownika emial
208     public function mail_user_delete($session_id,$domain_id)
209     {
210         if (!$this->checkPerm($session_id, 'mail_user_delete'))
211         {
212             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
213             return false;
214         }
215         $affected_rows = $this->deleteQuery('../mail/form/mail_user.tform.php',$domain_id);
216         return $affected_rows;
217     }
218     
219     //* Get mail user filter details
220     public function mail_user_filter_get($session_id, $primary_id)
221     {
222         global $app;
223         
224         if(!$this->checkPerm($session_id, 'mail_user_filter_get')) {
225             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
226             return false;
227         }
228         $app->uses('remoting_lib');
229         $app->remoting_lib->loadFormDef('../mail/form/mail_user_filter.tform.php');
230         return $app->remoting_lib->getDataRecord($primary_id);
231     }
232     
233     public function mail_user_filter_add($session_id, $client_id, $params)
234     {
235         if (!$this->checkPerm($session_id, 'mail_user_filter_add')){
236             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
237             return false;
238         }
239         $affected_rows = $this->insertQuery('../mail/form/mail_user_filter.tform.php', $client_id, $params);
240         return $affected_rows;
241     }
242
243     public function mail_user_filter_update($session_id, $client_id, $primary_id, $params)
244     {
245         if (!$this->checkPerm($session_id, 'mail_user_filter_update'))
246         {
247             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
248             return false;
249         }
250         $affected_rows = $this->updateQuery('../mail/form/mail_user_filter.tform.php', $client_id, $primary_id, $params);
251         return $affected_rows;
252     }
253
254     public function mail_user_filter_delete($session_id,$domain_id)
255     {
256         if (!$this->checkPerm($session_id, 'mail_user_filter_delete'))
257         {
258             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
259             return false;
260         }
261         $affected_rows = $this->deleteQuery('../mail/form/mail_user_filter.tform.php',$domain_id);
262         return $affected_rows;
263     }
264
265     //* Get alias details
266     public function mail_alias_get($session_id, $primary_id)
267     {
268         global $app;
269         
270         if(!$this->checkPerm($session_id, 'mail_alias_get')) {
271             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
272             return false;
273         }
274         $app->uses('remoting_lib');
275         $app->remoting_lib->loadFormDef('../mail/form/mail_alias.tform.php');
276         return $app->remoting_lib->getDataRecord($primary_id);
277     }
278     
279     //* aliasy email
280     public function mail_alias_add($session_id,$domain_id, $client_id, $params)
281     {
282         if (!$this->checkPerm($session_id, 'mail_alias_add'))
283         {
284             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
285             return false;
286         }
287         $affected_rows = $this->insertQuery('../mail/form/mail_alias.tform.php', $domain_id,  $client_id, $params);
288         return $affected_rows;
289     }
290
291
292     public function mail_alias_update($session_id, $domain_id, $client_id, $params)
293     {
294             if (!$this->checkPerm($session_id, 'mail_alias_update'))
295             {
296                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
297                     return false;
298             }
299             $affected_rows = $this->updateQuery('../mail/form/mail_alias.tform.php', $client_id, $domain_id, $params);
300             return $affected_rows;
301     }
302
303     public function mail_alias_delete($session_id,$domain_id)
304     {
305             if (!$this->checkPerm($session_id, 'mail_alias_delete'))
306             {
307                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
308                     return false;
309             }
310             $affected_rows = $this->deleteQuery('../mail/form/mail_alias.tform.php',$domain_id);
311             return $affected_rows;
312     }
313     
314     //* Get mail forwarding details
315     public function mail_forward_get($session_id, $primary_id)
316     {
317         global $app;
318         
319         if(!$this->checkPerm($session_id, 'mail_forward_get')) {
320             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
321             return false;
322         }
323         $app->uses('remoting_lib');
324         $app->remoting_lib->loadFormDef('../mail/form/mail_forward.tform.php');
325         return $app->remoting_lib->getDataRecord($primary_id);
326     }
327     
328      //* przekierowania email
329     public function mail_forward_add($session_id,$domain_id, $client_id, $params)
330     {
331             if (!$this->checkPerm($session_id, 'mail_forward_add'))
332             {
333                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
334                     return false;
335             }
336             $affected_rows = $this->insertQuery('../mail/form/mail_forward.tform.php', $domain_id,  $client_id, $params);
337             return $affected_rows;
338     }
339
340
341     public function mail_forward_update($session_id, $domain_id, $client_id, $params)
342     {
343             if (!$this->checkPerm($session_id, 'mail_forward_update'))
344             {
345                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
346                     return false;
347             }
348             $affected_rows = $this->updateQuery('../mail/form/mail_forward.tform.php', $client_id, $domain_id, $params);
349             return $affected_rows;
350     }
351
352
353     public function mail_forward_delete($session_id,$domain_id)
354     {
355             if (!$this->checkPerm($session_id, 'mail_forward_delete'))
356             {
357                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
358                     return false;
359             }
360             $affected_rows = $this->deleteQuery('../mail/form/mail_forward.tform.php',$domain_id);
361             return $affected_rows;
362     }
363     
364     //* Get catchall details
365     public function mail_catchall_get($session_id, $primary_id)
366     {
367         global $app;
368         
369         if(!$this->checkPerm($session_id, 'mail_catchall_get')) {
370             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
371             return false;
372         }
373         $app->uses('remoting_lib');
374         $app->remoting_lib->loadFormDef('../mail/form/mail_domain_catchall.tform.php');
375         return $app->remoting_lib->getDataRecord($primary_id);
376     }
377
378     //* catchall e-mail
379      public function mail_catchall_add($session_id,$domain_id, $client_id, $params)
380     {
381             if (!$this->checkPerm($session_id, 'mail_catchall_add'))
382             {
383                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
384                     return false;
385             }
386             $affected_rows = $this->insertQuery('../mail/form/mail_domain_catchall.tform.php', $domain_id,  $client_id, $params);
387             return $affected_rows;
388     }
389
390     public function mail_catchall_update($session_id, $domain_id, $client_id, $params)
391     {
392             if (!$this->checkPerm($session_id, 'mail_catchall_update'))
393             {
394                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
395                     return false;
396             }
397             $affected_rows = $this->updateQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $domain_id, $params);
398             return $affected_rows;
399     }
400
401     public function mail_catchall_delete($session_id,$domain_id)
402     {
403             if (!$this->checkPerm($session_id, 'mail_catchall_delete'))
404             {
405                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
406                     return false;
407             }
408             $affected_rows = $this->deleteQuery('../mail/form/mail_domain_catchall.tform.php',$domain_id);
409             return $affected_rows;
410     }
411     
412     //* Get transport details
413     public function mail_transport_get($session_id, $primary_id)
414     {
415         global $app;
416         
417         if(!$this->checkPerm($session_id, 'mail_transport_get')) {
418             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
419             return false;
420         }
421         $app->uses('remoting_lib');
422         $app->remoting_lib->loadFormDef('../mail/form/mail_transport.tform.php');
423         return $app->remoting_lib->getDataRecord($primary_id);
424     }
425     
426     //* przeniesienia e-mail
427     public function mail_transport_add($session_id,$domain_id, $client_id, $params)
428     {
429             if (!$this->checkPerm($session_id, 'mail_transport_add'))
430             {
431                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
432                     return false;
433             }
434             $affected_rows = $this->insertQuery('../mail/form/mail_transport.tform.php', $domain_id,  $client_id, $params);
435             return $affected_rows;
436     }
437
438
439     public function mail_transport_update($session_id, $domain_id, $client_id, $params)
440     {
441             if (!$this->checkPerm($session_id, 'mail_transport_update'))
442             {
443                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
444                     return false;
445             }
446             $affected_rows = $this->updateQuery('../mail/form/mail_transport.tform.php', $client_id, $domain_id, $params);
447             return $affected_rows;
448     }
449
450
451     public function mail_transport_delete($session_id,$domain_id)
452     {
453             if (!$this->checkPerm($session_id, 'mail_transport_delete'))
454             {
455                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
456                     return false;
457             }
458             $affected_rows = $this->deleteQuery('../mail/form/mail_transport.tform.php',$domain_id);
459             return $affected_rows;
460     }
461     
462     //* Get spamfilter whitelist details
463     public function mail_spamfilter_whitelist_get($session_id, $primary_id)
464     {
465         global $app;
466         
467         if(!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_get')) {
468             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
469             return false;
470         }
471         $app->uses('remoting_lib');
472         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_whitelist.tform.php');
473         return $app->remoting_lib->getDataRecord($primary_id);
474     }
475
476      //* biaÅ‚a lista e-mail
477     public function mail_spamfilter_whitelist_add($session_id,$domain_id, $client_id, $params)
478     {
479             if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_add'))
480             {
481                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
482                     return false;
483             }
484             $affected_rows = $this->insertQuery('../mail/form/spamfilter_whitelist.tform.php', $domain_id,  $client_id, $params);
485             return $affected_rows;
486     }
487
488
489     public function mail_spamfilter_whitelist_update($session_id, $domain_id, $client_id, $params)
490     {
491             if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_update'))
492             {
493                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
494                     return false;
495             }
496             $affected_rows = $this->updateQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $domain_id, $params);
497             return $affected_rows;
498     }
499
500
501     public function mail_spamfilter_whitelist_delete($session_id,$domain_id)
502     {
503             if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_delete'))
504             {
505                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
506                     return false;
507             }
508             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_whitelist.tform.php',$domain_id);
509             return $affected_rows;
510     }
511     
512     //* Get spamfilter blacklist details
513     public function mail_spamfilter_blacklist_get($session_id, $primary_id)
514     {
515         global $app;
516         
517         if(!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_get')) {
518             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
519             return false;
520         }
521         $app->uses('remoting_lib');
522         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_blacklist.tform.php');
523         return $app->remoting_lib->getDataRecord($primary_id);
524     }
525     
526      //* czarna lista e-mail
527     public function mail_spamfilter_blacklist_add($session_id,$domain_id, $client_id, $params)
528     {
529             if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_add'))
530             {
531                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
532                     return false;
533             }
534             $affected_rows = $this->insertQuery('../mail/form/spamfilter_blacklist.tform.php', $domain_id,  $client_id, $params);
535             return $affected_rows;
536     }
537
538
539     public function mail_spamfilter_blacklist_update($session_id, $domain_id, $client_id, $params)
540     {
541             if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_update'))
542             {
543                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
544                     return false;
545             }
546             $affected_rows = $this->updateQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $domain_id, $params);
547             return $affected_rows;
548     }
549
550
551     public function mail_spamfilter_blacklist_delete($session_id,$domain_id)
552     {
553             if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_delete'))
554             {
555                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
556                     return false;
557             }
558             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_blacklist.tform.php',$domain_id);
559             return $affected_rows;
560     }
561     
562     //* Get spamfilter user details
563     public function mail_spamfilter_user_get($session_id, $primary_id)
564     {
565         global $app;
566         
567         if(!$this->checkPerm($session_id, 'mail_spamfilter_user_get')) {
568             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
569             return false;
570         }
571         $app->uses('remoting_lib');
572         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_users.tform.php');
573         return $app->remoting_lib->getDataRecord($primary_id);
574     }
575
576     //* filtr spamu użytkowników e-mail
577     public function mail_spamfilter_user_add($session_id,$domain_id, $client_id, $params)
578     {
579             if (!$this->checkPerm($session_id, 'mail_spamfilter_user_add'))
580             {
581                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
582                     return false;
583             }
584             $affected_rows = $this->insertQuery('../mail/form/spamfilter_users.tform.php', $domain_id,  $client_id, $params);
585             return $affected_rows;
586     }
587
588
589     public function mail_spamfilter_user_update($session_id, $domain_id, $client_id, $params)
590     {
591             if (!$this->checkPerm($session_id, 'mail_spamfilter_user_update'))
592             {
593                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
594                     return false;
595             }
596             $affected_rows = $this->updateQuery('../mail/form/spamfilter_users.tform.php', $client_id, $domain_id, $params);
597             return $affected_rows;
598     }
599
600
601     public function mail_spamfilter_user_delete($session_id,$domain_id)
602     {
603             if (!$this->checkPerm($session_id, 'mail_spamfilter_user_delete'))
604             {
605                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
606                     return false;
607             }
608             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_users.tform.php',$domain_id);
609             return $affected_rows;
610     }
611     
612     //* Get policy details
613     public function mail_policy_get($session_id, $primary_id)
614     {
615         global $app;
616         
617         if(!$this->checkPerm($session_id, 'mail_policy_get')) {
618             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
619             return false;
620         }
621         $app->uses('remoting_lib');
622         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_policy.tform.php');
623         return $app->remoting_lib->getDataRecord($primary_id);
624     }
625     
626      //* polityki filtrów spamu e-mail
627     public function mail_policy_add($session_id,$domain_id, $client_id, $params)
628     {
629             if (!$this->checkPerm($session_id, 'mail_policy_add'))
630             {
631                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
632                     return false;
633             }
634             $affected_rows = $this->insertQuery('../mail/form/spamfilter_policy.tform.php', $domain_id,  $client_id, $params);
635             return $affected_rows;
636     }
637
638
639     public function mail_policy_update($session_id, $domain_id, $client_id, $params)
640     {
641             if (!$this->checkPerm($session_id, 'mail_policy_update'))
642             {
643                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
644                     return false;
645             }
646             $affected_rows = $this->updateQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $domain_id, $params);
647             return $affected_rows;
648     }
649
650
651     public function mail_policy_delete($session_id,$domain_id)
652     {
653             if (!$this->checkPerm($session_id, 'mail_policy_delete'))
654             {
655                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
656                     return false;
657             }
658             $affected_rows = $this->deleteQuery('../mail/form/spamfilter_policy.tform.php',$domain_id);
659             return $affected_rows;
660     }
661     
662     //* Get fetchmail details
663     public function mail_fetchmail_get($session_id, $primary_id)
664     {
665         global $app;
666         
667         if(!$this->checkPerm($session_id, 'mail_fetchmail_get')) {
668             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
669             return false;
670         }
671         $app->uses('remoting_lib');
672         $app->remoting_lib->loadFormDef('../mail/form/mail_get.tform.php');
673         return $app->remoting_lib->getDataRecord($primary_id);
674     }
675
676      //* fetchmail
677     public function mail_fetchmail_add($session_id,$domain_id, $client_id, $params)
678     {
679             if (!$this->checkPerm($session_id, 'mail_fetchmail_add'))
680             {
681                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
682                     return false;
683             }
684             $affected_rows = $this->insertQuery('../mail/form/mail_get.tform.php', $domain_id,  $client_id, $params);
685             return $affected_rows;
686     }
687
688
689     public function mail_fetchmail_update($session_id, $domain_id, $client_id, $params)
690     {
691             if (!$this->checkPerm($session_id, 'mail_fetchmail_update'))
692             {
693                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
694                     return false;
695             }
696             $affected_rows = $this->updateQuery('../mail/form/mail_get.tform.php', $client_id, $domain_id, $params);
697             return $affected_rows;
698     }
699
700
701     public function mail_fetchmail_delete($session_id,$domain_id)
702     {
703             if (!$this->checkPerm($session_id, 'mail_fetchmail_delete'))
704             {
705                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
706                     return false;
707             }
708             $affected_rows = $this->deleteQuery('../mail/form/mail_get.tform.php',$domain_id);
709             return $affected_rows;
710     }
711     
712     //* Get whitelist details
713     public function mail_whitelist_get($session_id, $primary_id)
714     {
715         global $app;
716         
717         if(!$this->checkPerm($session_id, 'mail_whitelist_get')) {
718             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
719             return false;
720         }
721         $app->uses('remoting_lib');
722         $app->remoting_lib->loadFormDef('../mail/form/mail_whitelist.tform.php');
723         return $app->remoting_lib->getDataRecord($primary_id);
724     }
725     
726     //* wpisy biaÅ‚ej listy
727     public function mail_whitelist_add($session_id,$domain_id, $client_id, $params)
728     {
729             if (!$this->checkPerm($session_id, 'mail_whitelist_add'))
730             {
731                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
732                     return false;
733             }
734             $affected_rows = $this->insertQuery('../mail/form/mail_whitelist.tform.php', $domain_id,  $client_id, $params);
735             return $affected_rows;
736     }
737
738
739     public function mail_whitelist_update($session_id, $domain_id, $client_id, $params)
740     {
741             if (!$this->checkPerm($session_id, 'mail_whitelist_update'))
742             {
743                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
744                     return false;
745             }
746             $affected_rows = $this->updateQuery('../mail/form/mail_whitelist.tform.php', $client_id, $domain_id, $params);
747             return $affected_rows;
748     }
749
750
751     public function mail_whitelist_delete($session_id,$domain_id)
752     {
753             if (!$this->checkPerm($session_id, 'mail_whitelist_delete'))
754             {
755                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
756                     return false;
757             }
758             $affected_rows = $this->deleteQuery('../mail/form/mail_whitelist.tform.php',$domain_id);
759             return $affected_rows;
760     }
761     
762     //* Get Blacklist details
763     public function mail_blacklist_get($session_id, $primary_id)
764     {
765         global $app;
766         
767         if(!$this->checkPerm($session_id, 'mail_blacklist_get')) {
768             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
769             return false;
770         }
771         $app->uses('remoting_lib');
772         $app->remoting_lib->loadFormDef('../mail/form/mail_blacklist.tform.php');
773         return $app->remoting_lib->getDataRecord($primary_id);
774     }
775     
776     //* wpisy biaÅ‚ej listy
777     public function mail_blacklist_add($session_id,$domain_id, $client_id, $params)
778     {
779             if (!$this->checkPerm($session_id, 'mail_blacklist_add'))
780             {
781                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
782                     return false;
783             }
784             $affected_rows = $this->insertQuery('../mail/form/mail_blacklist.tform.php', $domain_id,  $client_id, $params);
785             return $affected_rows;
786     }
787
788
789     public function mail_blacklist_update($session_id, $domain_id, $client_id, $params)
790     {
791             if (!$this->checkPerm($session_id, 'mail_blacklist_update'))
792             {
793                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
794                     return false;
795             }
796             $affected_rows = $this->updateQuery('../mail/form/mail_blacklist.tform.php', $client_id, $domain_id, $params);
797             return $affected_rows;
798     }
799
800
801     public function mail_blacklist_delete($session_id,$domain_id)
802     {
803             if (!$this->checkPerm($session_id, 'mail_blacklist_delete'))
804             {
805                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
806                     return false;
807             }
808             $affected_rows = $this->deleteQuery('../mail/form/mail_blacklist.tform.php',$domain_id);
809             return $affected_rows;
810     }
811     
812     //* Get filter details
813     public function mail_filter_get($session_id, $primary_id)
814     {
815         global $app;
816         
817         if(!$this->checkPerm($session_id, 'mail_filter_get')) {
818             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
819             return false;
820         }
821         $app->uses('remoting_lib');
822         $app->remoting_lib->loadFormDef('../mail/form/mail_content_filter.tform.php');
823         return $app->remoting_lib->getDataRecord($primary_id);
824     }
825
826     //* wpisy filtrow e-mail
827     public function mail_filter_add($session_id,$domain_id, $client_id, $params)
828     {
829             if (!$this->checkPerm($session_id, 'mail_filter_add'))
830             {
831                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
832                     return false;
833             }
834             $affected_rows = $this->insertQuery('../mail/form/mail_content_filter.tform.php', $domain_id,  $client_id, $params);
835             return $affected_rows;
836     }
837
838
839     public function mail_filter_update($session_id, $domain_id, $client_id, $params)
840     {
841             if (!$this->checkPerm($session_id, 'mail_filter_update'))
842             {
843                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
844                     return false;
845             }
846             $affected_rows = $this->updateQuery('../mail/form/mail_content_filter.tform.php', $client_id, $domain_id, $params);
847             return $affected_rows;
848     }
849
850
851     public function mail_filter_delete($session_id,$domain_id)
852     {
853             if (!$this->checkPerm($session_id, 'mail_filter_delete'))
854             {
855                     $this->server->fault('permission_denied','You do not have the permissions to access this function.');
856                     return false;
857             }
858             $affected_rows = $this->deleteQuery('../mail/form/mail_content_filter.tform.php',$domain_id);
859             return $affected_rows;
860     }
861
862
863
864
865 /* 
866  * 
867  * 
868  * 
869  *      * klient add :)
870  * 
871  * 
872  */
873
874     public function client_add($session_id,$domain_id, $client_id, $params)
875     {
876         if (!$this->checkPerm($session_id, 'client_add'))
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->klientadd('../client/form/client.tform.php',$domain_id, $client_id, $params);
882         return $affected_rows;  
883                   
884     }
885
886
887         
888
889
890     //** private functions -----------------------------------------------------------------------------------
891     
892     
893
894
895     private function klientadd($formdef_file, $client_id, $params)
896     {
897         global $app, $tform, $remoting_lib;
898         $app->uses('remoting_lib');
899             
900         //* Load the form definition
901         $app->remoting_lib->loadFormDef($formdef_file);
902         
903         //* load the user profile of the client
904         $app->remoting_lib->loadUserProfile($client_id);        
905         
906         //* Get the SQL query
907         $sql = $app->remoting_lib->getSQL($params,'INSERT',0);
908         if($app->remoting_lib->errorMessage != '') {
909             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
910             return false;
911         }
912         
913         $app->db->query($sql);
914         
915         if($app->db->errorMessage != '') {
916             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
917             return false;
918         }
919         
920                     
921         
922         $insert_id = $app->db->insertID();    
923         //$app->uses('tform');
924         //* Save changes to Datalog
925         if($app->remoting_lib->formDef["db_history"] == 'yes') {
926             $new_rec = $app->remoting_lib->getDataRecord($insert_id);
927             $app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);
928             
929         $app->remoting_lib->dodaj_usera($params,$insert_id);
930
931         }
932         
933         
934         
935         
936         return $insert_id;
937     }
938
939
940
941
942     private function insertQuery($formdef_file, $client_id, $params)
943     {
944         global $app, $tform, $remoting_lib;
945         
946         $app->uses('remoting_lib');
947         
948         //* Load the form definition
949         $app->remoting_lib->loadFormDef($formdef_file);
950         
951         //* load the user profile of the client
952         $app->remoting_lib->loadUserProfile($client_id);
953         
954         //* Get the SQL query
955         $sql = $app->remoting_lib->getSQL($params,'INSERT',0);
956         if($app->remoting_lib->errorMessage != '') {
957             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
958             return false;
959         }
960         
961         $app->db->query($sql);
962         
963         if($app->db->errorMessage != '') {
964             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
965             return false;
966         }
967         
968         $insert_id = $app->db->insertID();
969         
970         
971     
972         //$app->uses('tform');
973         //* Save changes to Datalog
974         if($app->remoting_lib->formDef["db_history"] == 'yes') {
975             $new_rec = $app->remoting_lib->getDataRecord($insert_id);
976             $app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);
977             
978         }
979         
980         
981         
982         
983         return $insert_id;
984     }
985     
986     
987     private function updateQuery($formdef_file, $client_id, $primary_id, $params)
988     {
989         global $app;
990         
991         $app->uses('remoting_lib');
992         
993         //* Load the form definition
994         $app->remoting_lib->loadFormDef($formdef_file);
995         
996         //* load the user profile of the client
997         $app->remoting_lib->loadUserProfile($client_id);
998         
999         //* Get the SQL query
1000         $sql = $app->remoting_lib->getSQL($params,'UPDATE',$primary_id);
1001         if($app->remoting_lib->errorMessage != '') {
1002             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
1003             return false;
1004         }
1005         
1006         $old_rec = $app->remoting_lib->getDataRecord($primary_id);
1007         
1008         $app->db->query($sql);
1009         
1010         if($app->db->errorMessage != '') {
1011             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
1012             return false;
1013         }
1014         
1015         $affected_rows = $app->db->affectedRows();
1016         
1017         //* Save changes to Datalog
1018         if($app->remoting_lib->formDef["db_history"] == 'yes') {
1019             $new_rec = $app->remoting_lib->getDataRecord($primary_id);
1020             $app->remoting_lib->datalogSave('UPDATE',$primary_id,$old_rec,$new_rec);
1021         }
1022         
1023         
1024         
1025         return $affected_rows;
1026     }
1027     
1028     private function deleteQuery($formdef_file, $primary_id)
1029     {
1030         global $app;
1031         
1032         $app->uses('remoting_lib');
1033         
1034         //* Load the form definition
1035         $app->remoting_lib->loadFormDef($formdef_file);
1036         
1037         //* Get the SQL query
1038         $sql = $app->remoting_lib->getDeleteSQL($primary_id);
1039         
1040         $app->db->query($sql);
1041         
1042         if($app->db->errorMessage != '') {
1043             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
1044             return false;
1045         }
1046         
1047         $affected_rows = $app->db->affectedRows();
1048         
1049         //* Save changes to Datalog
1050         if($app->remoting_lib->formDef["db_history"] == 'yes') {
1051             $rec = $app->remoting_lib->getDataRecord($primary_id);
1052             $app->remoting_lib->datalogSave('DELETE',$primary_id,$rec,array());
1053         }
1054         
1055         
1056         return $affected_rows;
1057     }
1058     
1059     
1060     private function checkPerm($session_id, $function_name)
1061     {
1062     $dobre=Array();
1063     $session = $this->getSession($session_id);
1064         if(!$session){
1065             return false;
1066         }
1067         
1068         $dobre= str_replace(';',',',$session['remote_functions']);
1069         return in_array($function_name, explode(',', $dobre) );
1070     }
1071     
1072     
1073     private function getSession($session_id)
1074     {    
1075         global $app;
1076         
1077         if(empty($session_id)) {
1078             $this->server->fault('session_id_empty','The SessionID is empty.');
1079             return false;
1080         }
1081         
1082         $session_id = $app->db->quote($session_id);
1083         
1084         $now = time();
1085         $sql = "SELECT * FROM remote_session WHERE remote_session = '$session_id' AND tstamp >= $now";
1086         $session = $app->db->queryOneRecord($sql);
1087         if($session['remote_userid'] > 0) {
1088             return $session;
1089         } else {
1090             $this->server->fault('session_does_not_exist','The Session is expired or does not exist.');
1091             return false;
1092         }
1093     }
1094 }
1095
1096 ?>