Marius Cramer
2014-08-14 bfc771477f5a60509bf6318d6ee2a30e14412906
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 {
7fe908 38
532ae5 39     //* remote session timeout in seconds
L 40     private $session_timeout = 600;
7fe908 41
a93288 42     protected $server;
532ae5 43     public $oldDataRecord;
L 44     public $dataRecord;
45     public $id;
7fe908 46
532ae5 47     /*
7fe908 48     These variables shall stay global.
532ae5 49     Please do not make them private variables.
7fe908 50
532ae5 51     private $app;
L 52     private $conf;
53     */
54
7fe908 55     public function __construct()
MC 56     {
57         global $server;
58         $this->server = $server;
532ae5 59         /*
L 60         $this->app = $app;
61         $this->conf = $conf;
62         */
7fe908 63     }
532ae5 64
L 65     //* remote login function
66     public function login($username, $password)
7fe908 67     {
532ae5 68         global $app, $conf, $server;
7fe908 69
bf7d95 70         // Maintenance mode
F 71         $app->uses('ini_parser,getconf');
72         $server_config_array = $app->getconf->get_global_config('misc');
73         if($server_config_array['maintenance_mode'] == 'y'){
74             $this->server->fault('maintenance_mode', 'This ISPConfig installation is currently under maintenance. We should be back shortly. Thank you for your patience.');
75             return false;
76         }
7fe908 77
532ae5 78         if(empty($username)) {
bf7d95 79             $this->server->fault('login_username_empty', 'The login username is empty.');
532ae5 80             return false;
L 81         }
7fe908 82
532ae5 83         if(empty($password)) {
bf7d95 84             $this->server->fault('login_password_empty', 'The login password is empty.');
532ae5 85             return false;
L 86         }
7fe908 87
532ae5 88         //* Delete old remoting sessions
L 89         $sql = "DELETE FROM remote_session WHERE tstamp < ".time();
90         $app->db->query($sql);
7fe908 91
532ae5 92         $username = $app->db->quote($username);
L 93         $password = $app->db->quote($password);
7fe908 94
532ae5 95         $sql = "SELECT * FROM remote_user WHERE remote_username = '$username' and remote_password = md5('$password')";
L 96         $remote_user = $app->db->queryOneRecord($sql);
97         if($remote_user['remote_userid'] > 0) {
98             //* Create a remote user session
7fe908 99             srand((double)microtime()*1000000);
532ae5 100             $remote_session = md5(rand());
L 101             $remote_userid = $remote_user['remote_userid'];
102             $remote_functions = $remote_user['remote_functions'];
103             $tstamp = time() + $this->session_timeout;
104             $sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp'
7fe908 105                 .') VALUES ('
MC 106                 ." '$remote_session',$remote_userid,'$remote_functions',$tstamp)";
532ae5 107             $app->db->query($sql);
L 108             return $remote_session;
109         } else {
110             $this->server->fault('login_failed', 'The login failed. Username or password wrong.');
111             return false;
112         }
7fe908 113
532ae5 114     }
7fe908 115
532ae5 116     //* remote logout function
L 117     public function logout($session_id)
7fe908 118     {
532ae5 119         global $app;
7fe908 120
532ae5 121         if(empty($session_id)) {
L 122             $this->server->fault('session_id_empty', 'The SessionID is empty.');
123             return false;
124         }
7fe908 125
532ae5 126         $session_id = $app->db->quote($session_id);
7fe908 127
532ae5 128         $sql = "DELETE FROM remote_session WHERE remote_session = '$session_id'";
57aa5e 129         if($app->db->query($sql) != false) {
TB 130             return true;
131         } else {
132             return false;
133         }
532ae5 134     }
L 135
7fe908 136
MC 137     /**
138      Gets the server configuration
139      @param int session id
140      @param int server id
141      @param string  section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
ff58a5 142      @author Julio Montoya <gugli100@gmail.com> BeezNest 2010, extended by M. Cramer <m.cramer@pixcept.de> 2014
7fe908 143      */
MC 144
145
ff58a5 146     public function server_get($session_id, $server_id = null, $section ='') {
7fe908 147         global $app;
MC 148         if(!$this->checkPerm($session_id, 'server_get')) {
149             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
150             return false;
1ca823 151         }
ff58a5 152         if (!empty($session_id)) {
f266c3 153             $app->uses('remoting_lib , getconf');
ff58a5 154             if(!empty($server_id)) {
MC 155                 $section_config =  $app->getconf->get_server_config($server_id, $section);
156                 return $section_config;
157             } else {
158                 $servers = array();
159                 $sql = "SELECT server_id FROM server WHERE 1";
160                 $all = $app->db->queryAllRecords($sql);
161                 foreach($all as $s) {
162                     $servers[$s['server_id']] = $app->getconf->get_server_config($s['server_id'], $section);
163                 }
164                 unset($all);
165                 unset($s);
166                 return $servers;
167             }
168         } else {
169             return false;
170         }
171     }
172     
173     /**
174         Gets a list of all servers
175         @param int session_id
176         @param int server_name
177         @author Marius Cramer <m.cramer@pixcept.de> 2014
178     */
179     public function server_get_all($session_id)
180     {
181         global $app;
182         if(!$this->checkPerm($session_id, 'server_get')) {
183             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
184             return false;
185         }
186         if (!empty($session_id)) {
187             $sql = "SELECT server_id, server_name FROM server WHERE 1";
188             $servers = $app->db->queryAllRecords($sql);
189             return $servers;
7fe908 190         } else {
MC 191             return false;
192         }
1ca823 193     }
37fccb 194     
TB 195     /**
3ba564 196         Gets the server_id by server_name
TB 197         @param int session_id
198         @param int server_name
199         @author Sascha Bay <info@space2place.de> TheCry 2013
200     */
201     public function server_get_serverid_by_name($session_id, $server_name)
202     {
203         global $app;
37fccb 204         if(!$this->checkPerm($session_id, 'server_get')) {
3ba564 205             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
TB 206             return false;
207         }
208         if (!empty($session_id) && !empty($server_name)) {
209             $sql = "SELECT server_id FROM server WHERE server_name  = '$server_name' LIMIT 1 ";
210             $all = $app->db->queryAllRecords($sql);
211             return $all;
212         } else {
37fccb 213             return false;
TB 214         }
3ba564 215     }
TB 216     
217     /**
218         Gets the functions of a server by server_id
219         @param int session_id
220         @param int server_id
221         @author Sascha Bay <info@space2place.de> TheCry 2013
222     */
223     public function server_get_functions($session_id, $server_id)
224     {
225         global $app;
226         if(!$this->checkPerm($session_id, 'server_get')) {
227             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
228             return false;
229         }
230         if (!empty($session_id) && !empty($server_id)) { 
231             $sql = "SELECT mail_server, web_server, dns_server, file_server, db_server, vserver_server, proxy_server, firewall_server FROM server WHERE server_id  = '$server_id' LIMIT 1 ";
232             $all = $app->db->queryAllRecords($sql);
233             return $all;
234         } else {
235             return false;
236         }
237     }
238     
239     /**
4549a0 240      * set record permissions in any table
MC 241      * @param string session_id
242      * @param string index_field
243      * @param string index_value
244      * @param array permissions
245      * @author "ispcomm", improved by M. Cramer <m.cramer@pixcept.de>
246      */
247     public function update_record_permissions($tablename, $index_field, $index_value, $permissions) {
248         global $app;
249         
250         if(!$this->checkPerm($session_id, 'admin_record_permissions')) {
251             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
252             return false;
253         }
254         
255         foreach($permissions as $key => $value) {  // make sure only sys_ fields are updated
256             switch($key) {
257                 case 'sys_userid':
258                     // check if userid is valid
259                     $check = $app->db->queryOneRecord('SELECT userid FROM sys_user WHERE userid = ' . $app->functions->intval($value));
260                     if(!$check || !$check['userid']) {
261                         $this->server->fault('invalid parameters', $value . ' is no valid sys_userid.');
262                         return false;
263                     }
ad9557 264                     $permissions[$key] = $app->functions->intval($value);
4549a0 265                     break;
MC 266                 case 'sys_groupid':
267                     // check if groupid is valid
268                     $check = $app->db->queryOneRecord('SELECT groupid FROM sys_group WHERE groupid = ' . $app->functions->intval($value));
269                     if(!$check || !$check['groupid']) {
270                         $this->server->fault('invalid parameters', $value . ' is no valid sys_groupid.');
271                         return false;
272                     }
ad9557 273                     $permissions[$key] = $app->functions->intval($value);
4549a0 274                     break;
MC 275                 case 'sys_perm_user':
276                 case 'sys_perm_group':
277                     // check if permissions are valid
278                     $value = strtolower($value);
279                     if(!preg_match('/^[riud]+$/', $value)) {
280                         $this->server->fault('invalid parameters', $value . ' is no valid permission string.');
281                         return false;
282                     }
283                     
284                     $newvalue = '';
285                     if(strpos($value, 'r') !== false) $newvalue .= 'r';
286                     if(strpos($value, 'i') !== false) $newvalue .= 'i';
287                     if(strpos($value, 'u') !== false) $newvalue .= 'u';
288                     if(strpos($value, 'd') !== false) $newvalue .= 'd';
ad9557 289                     $permissions[$key] = $newvalue;
4549a0 290                     unset($newvalue);
MC 291                     
292                     break;
293                 default:
294                     $this->server->fault('invalid parameters', 'Only sys_userid, sys_groupid, sys_perm_user and sys_perm_group parameters can be changed with this function.');
295                     break;
296             }
297         }
298         
299         return $app->db->datalogUpdate( $tablename, $permissions, $index_field, $index_value ) ;
300     }
301     
302     /**
3ba564 303         Gets the ISPconfig version of the server
TB 304         @param int session_id
305         @author Sascha Bay <info@space2place.de> TheCry 2013
306     */
307     public function server_get_app_version($session_id)
308     {
309         global $app;
310         if(!$this->checkPerm($session_id, 'server_get')) {
311             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
312             return false;
313         }
37fccb 314         if (!empty($session_id)) { 
TB 315             $ispc_app_version = array('ispc_app_version' => ISPC_APP_VERSION);
316             return $ispc_app_version;
317         } else {
318             return false;
319         }
320     }
7fe908 321
MC 322     public function server_get_serverid_by_ip($session_id, $ipaddress)
323     {
324         global $app;
325         if(!$this->checkPerm($session_id, 'server_get_serverid_by_ip')) {
326             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
327             return false;
328         }
329         $sql = "SELECT server_id FROM server_ip WHERE ip_address  = '$ipaddress' LIMIT 1 ";
330         $all = $app->db->queryAllRecords($sql);
331         return $all;
332     }
333
ed7687 334     //* Get server ips
4193f4 335     public function server_ip_get($session_id, $primary_id)
MC 336     {
337         global $app;
338
339         if(!$this->checkPerm($session_id, 'server_ip_get')) {
340             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
341             return false;
342         }
343         $app->uses('remoting_lib');
344         $app->remoting_lib->loadFormDef('../admin/form/server_ip.tform.php');
345         return $app->remoting_lib->getDataRecord($primary_id);
4cd62d 346     }
FT 347     
b67344 348     //* Add a IP address record
T 349     public function server_ip_add($session_id, $client_id, $params)
7fe908 350     {
b67344 351         if(!$this->checkPerm($session_id, 'server_ip_add')) {
T 352             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
353             return false;
354         }
7fe908 355         return $this->insertQuery('../admin/form/server_ip.tform.php', $client_id, $params);
b67344 356     }
7fe908 357
b67344 358     //* Update IP address record
T 359     public function server_ip_update($session_id, $client_id, $ip_id, $params)
7fe908 360     {
b67344 361         if(!$this->checkPerm($session_id, 'server_ip_update')) {
T 362             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
363             return false;
364         }
7fe908 365         $affected_rows = $this->updateQuery('../admin/form/server_ip.tform.php', $client_id, $ip_id, $params);
b67344 366         return $affected_rows;
T 367     }
7fe908 368
b67344 369     //* Delete IP address record
T 370     public function server_ip_delete($session_id, $ip_id)
7fe908 371     {
b67344 372         if(!$this->checkPerm($session_id, 'server_ip_delete')) {
T 373             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
374             return false;
375         }
7fe908 376         $affected_rows = $this->deleteQuery('../admin/form/server_ip.tform.php', $ip_id);
b67344 377         return $affected_rows;
T 378     }
7fe908 379
532ae5 380     //* Get mail domain details
L 381     public function mail_domain_get($session_id, $primary_id)
7fe908 382     {
532ae5 383         global $app;
7fe908 384
532ae5 385         if(!$this->checkPerm($session_id, 'mail_domain_get')) {
L 386             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
387             return false;
388         }
389         $app->uses('remoting_lib');
390         $app->remoting_lib->loadFormDef('../mail/form/mail_domain.tform.php');
391         return $app->remoting_lib->getDataRecord($primary_id);
392     }
7fe908 393
532ae5 394     //* Add a mail domain
L 395     public function mail_domain_add($session_id, $client_id, $params)
7fe908 396     {
532ae5 397         if(!$this->checkPerm($session_id, 'mail_domain_add')) {
L 398             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
399             return false;
400         }
7fe908 401         $primary_id = $this->insertQuery('../mail/form/mail_domain.tform.php', $client_id, $params);
532ae5 402         return $primary_id;
L 403     }
7fe908 404
532ae5 405     //* Update a mail domain
L 406     public function mail_domain_update($session_id, $client_id, $primary_id, $params)
7fe908 407     {
532ae5 408         if(!$this->checkPerm($session_id, 'mail_domain_update')) {
L 409             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
410             return false;
411         }
412         $affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php', $client_id, $primary_id, $params);
413         return $affected_rows;
414     }
7fe908 415
532ae5 416     //* Delete a mail domain
L 417     public function mail_domain_delete($session_id, $primary_id)
7fe908 418     {
532ae5 419         if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
L 420             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
421             return false;
422         }
423         $affected_rows = $this->deleteQuery('../mail/form/mail_domain.tform.php', $primary_id);
424         return $affected_rows;
425     }
7fe908 426
10b4c8 427     //* Get alias details
T 428     public function mail_aliasdomain_get($session_id, $primary_id)
7fe908 429     {
10b4c8 430         global $app;
7fe908 431
10b4c8 432         if(!$this->checkPerm($session_id, 'mail_aliasdomain_get')) {
T 433             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
434             return false;
435         }
436         $app->uses('remoting_lib');
437         $app->remoting_lib->loadFormDef('../mail/form/mail_aliasdomain.tform.php');
438         return $app->remoting_lib->getDataRecord($primary_id);
439     }
7fe908 440
10b4c8 441     //* aliasy email
T 442     public function mail_aliasdomain_add($session_id, $client_id, $params)
443     {
444         if (!$this->checkPerm($session_id, 'mail_aliasdomain_add'))
445         {
7fe908 446             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
10b4c8 447             return false;
T 448         }
449         $affected_rows = $this->insertQuery('../mail/form/mail_aliasdomain.tform.php', $client_id, $params);
450         return $affected_rows;
451     }
452
453
454     public function mail_aliasdomain_update($session_id, $client_id, $primary_id, $params)
455     {
7fe908 456         if (!$this->checkPerm($session_id, 'mail_aliasdomain_update'))
MC 457         {
458             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
459             return false;
460         }
461         $affected_rows = $this->updateQuery('../mail/form/mail_aliasdomain.tform.php', $client_id, $primary_id, $params);
462         return $affected_rows;
10b4c8 463     }
T 464
465     public function mail_aliasdomain_delete($session_id, $primary_id)
466     {
7fe908 467         if (!$this->checkPerm($session_id, 'mail_aliasdomain_delete'))
MC 468         {
469             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
470             return false;
471         }
472         $affected_rows = $this->deleteQuery('../mail/form/mail_aliasdomain.tform.php', $primary_id);
473         return $affected_rows;
10b4c8 474     }
7fe908 475
04620b 476     //* Get mail mailinglist details
T 477     public function mail_mailinglist_get($session_id, $primary_id)
7fe908 478     {
04620b 479         global $app;
7fe908 480
04620b 481         if(!$this->checkPerm($session_id, 'mail_mailinglist_get')) {
T 482             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
483             return false;
484         }
485         $app->uses('remoting_lib');
486         $app->remoting_lib->loadFormDef('../mail/form/mail_mailinglist.tform.php');
487         return $app->remoting_lib->getDataRecord($primary_id);
488     }
7fe908 489
04620b 490     //* Add a mail mailinglist
T 491     public function mail_mailinglist_add($session_id, $client_id, $params)
7fe908 492     {
04620b 493         if(!$this->checkPerm($session_id, 'mail_mailinglist_add')) {
T 494             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
495             return false;
496         }
7fe908 497         $primary_id = $this->insertQuery('../mail/form/mail_mailinglist.tform.php', $client_id, $params);
04620b 498         return $primary_id;
T 499     }
7fe908 500
04620b 501     //* Update a mail mailinglist
T 502     public function mail_mailinglist_update($session_id, $client_id, $primary_id, $params)
7fe908 503     {
04620b 504         if(!$this->checkPerm($session_id, 'mail_mailinglist_update')) {
T 505             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
506             return false;
507         }
508         $affected_rows = $this->updateQuery('../mail/form/mail_mailinglist.tform.php', $client_id, $primary_id, $params);
509         return $affected_rows;
510     }
7fe908 511
04620b 512     //* Delete a mail mailinglist
T 513     public function mail_mailinglist_delete($session_id, $primary_id)
7fe908 514     {
04620b 515         if(!$this->checkPerm($session_id, 'mail_mailinglist_delete')) {
T 516             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
517             return false;
518         }
519         $affected_rows = $this->deleteQuery('../mail/form/mail_mailinglist.tform.php', $primary_id);
520         return $affected_rows;
521     }
7fe908 522
532ae5 523     //* Get mail user details
L 524     public function mail_user_get($session_id, $primary_id)
7fe908 525     {
532ae5 526         global $app;
7fe908 527
532ae5 528         if(!$this->checkPerm($session_id, 'mail_user_get')) {
L 529             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
530             return false;
531         }
532         $app->uses('remoting_lib');
533         $app->remoting_lib->loadFormDef('../mail/form/mail_user.tform.php');
534         return $app->remoting_lib->getDataRecord($primary_id);
535     }
7fe908 536
MC 537
bfcdef 538     //* Add mail domain
532ae5 539     public function mail_user_add($session_id, $client_id, $params){
bfcdef 540         global $app;
7fe908 541
532ae5 542         if (!$this->checkPerm($session_id, 'mail_user_add')){
7fe908 543             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 544             return false;
L 545         }
7fe908 546
bfcdef 547         //* Check if mail domain exists
7fe908 548         $email_parts = explode('@', $params['email']);
bfcdef 549         $tmp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain = '".$app->db->quote($email_parts[1])."'");
T 550         if($tmp['domain'] != $email_parts[1]) {
7fe908 551             $this->server->fault('mail_domain_does_not_exist', 'Mail domain - '.$email_parts[1].' - does not exist.');
bfcdef 552             return false;
T 553         }
7fe908 554
532ae5 555         $affected_rows = $this->insertQuery('../mail/form/mail_user.tform.php', $client_id, $params);
L 556         return $affected_rows;
557     }
558
7fe908 559     //* Update mail user
532ae5 560     public function mail_user_update($session_id, $client_id, $primary_id, $params)
L 561     {
bfcdef 562         global $app;
7fe908 563
532ae5 564         if (!$this->checkPerm($session_id, 'mail_user_update'))
L 565         {
7fe908 566             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 567             return false;
L 568         }
7fe908 569
bfcdef 570         //* Check if mail domain exists
7fe908 571         $email_parts = explode('@', $params['email']);
bfcdef 572         $tmp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain = '".$app->db->quote($email_parts[1])."'");
T 573         if($tmp['domain'] != $email_parts[1]) {
7fe908 574             $this->server->fault('mail_domain_does_not_exist', 'Mail domain - '.$email_parts[1].' - does not exist.');
bfcdef 575             return false;
T 576         }
7fe908 577
532ae5 578         $affected_rows = $this->updateQuery('../mail/form/mail_user.tform.php', $client_id, $primary_id, $params);
L 579         return $affected_rows;
580     }
581
7fe908 582
bfcdef 583     //* Delete mail user
532ae5 584     public function mail_user_delete($session_id, $primary_id)
L 585     {
586         if (!$this->checkPerm($session_id, 'mail_user_delete'))
587         {
7fe908 588             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 589             return false;
L 590         }
591         $affected_rows = $this->deleteQuery('../mail/form/mail_user.tform.php', $primary_id);
592         return $affected_rows;
593     }
7fe908 594
532ae5 595     //* Get mail user filter details
L 596     public function mail_user_filter_get($session_id, $primary_id)
7fe908 597     {
532ae5 598         global $app;
7fe908 599
532ae5 600         if(!$this->checkPerm($session_id, 'mail_user_filter_get')) {
L 601             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
602             return false;
603         }
604         $app->uses('remoting_lib');
605         $app->remoting_lib->loadFormDef('../mail/form/mail_user_filter.tform.php');
606         return $app->remoting_lib->getDataRecord($primary_id);
607     }
7fe908 608
532ae5 609     public function mail_user_filter_add($session_id, $client_id, $params)
L 610     {
611         global $app;
612         if (!$this->checkPerm($session_id, 'mail_user_filter_add')){
7fe908 613             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 614             return false;
L 615         }
7fe908 616         $affected_rows = $this->insertQuery('../mail/form/mail_user_filter.tform.php', $client_id, $params, 'mail:mail_user_filter:on_after_insert');
532ae5 617         // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_insert',$this);
L 618         return $affected_rows;
619     }
620
621     public function mail_user_filter_update($session_id, $client_id, $primary_id, $params)
622     {
623         global $app;
624         if (!$this->checkPerm($session_id, 'mail_user_filter_update'))
625         {
7fe908 626             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 627             return false;
L 628         }
7fe908 629         $affected_rows = $this->updateQuery('../mail/form/mail_user_filter.tform.php', $client_id, $primary_id, $params, 'mail:mail_user_filter:on_after_update');
532ae5 630         // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_update',$this);
L 631         return $affected_rows;
632     }
633
634     public function mail_user_filter_delete($session_id, $primary_id)
635     {
636         global $app;
637         if (!$this->checkPerm($session_id, 'mail_user_filter_delete'))
638         {
7fe908 639             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 640             return false;
L 641         }
7fe908 642         $affected_rows = $this->deleteQuery('../mail/form/mail_user_filter.tform.php', $primary_id, 'mail:mail_user_filter:on_after_delete');
355efb 643         // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_delete',$this);
532ae5 644         return $affected_rows;
L 645     }
646
647     //* Get alias details
648     public function mail_alias_get($session_id, $primary_id)
7fe908 649     {
532ae5 650         global $app;
7fe908 651
532ae5 652         if(!$this->checkPerm($session_id, 'mail_alias_get')) {
L 653             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
654             return false;
655         }
656         $app->uses('remoting_lib');
657         $app->remoting_lib->loadFormDef('../mail/form/mail_alias.tform.php');
658         return $app->remoting_lib->getDataRecord($primary_id);
659     }
7fe908 660
532ae5 661     //* aliasy email
L 662     public function mail_alias_add($session_id, $client_id, $params)
663     {
10b4c8 664         global $app;
7fe908 665
532ae5 666         if (!$this->checkPerm($session_id, 'mail_alias_add'))
L 667         {
7fe908 668             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
532ae5 669             return false;
L 670         }
7fe908 671
10b4c8 672         //* Check if there is no active mailbox with this address
T 673         $tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE postfix = 'y' AND email = '".$app->db->quote($params["source"])."'");
674         if($tmp['number'] > 0) {
7fe908 675             $this->server->fault('duplicate', 'There is already a mailbox with this email address.');
10b4c8 676         }
T 677         unset($tmp);
7fe908 678
532ae5 679         $affected_rows = $this->insertQuery('../mail/form/mail_alias.tform.php', $client_id, $params);
L 680         return $affected_rows;
681     }
682
683
684     public function mail_alias_update($session_id, $client_id, $primary_id, $params)
685     {
10b4c8 686         global $app;
7fe908 687
10b4c8 688         if (!$this->checkPerm($session_id, 'mail_alias_update'))
T 689         {
7fe908 690             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
10b4c8 691             return false;
T 692         }
7fe908 693
MC 694         //* Check if there is no active mailbox with this address
10b4c8 695         $tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE postfix = 'y' AND email = '".$app->db->quote($params["source"])."'");
T 696         if($tmp['number'] > 0) {
7fe908 697             $this->server->fault('duplicate', 'There is already a mailbox with this email address.');
10b4c8 698         }
T 699         unset($tmp);
7fe908 700
10b4c8 701         $affected_rows = $this->updateQuery('../mail/form/mail_alias.tform.php', $client_id, $primary_id, $params);
T 702         return $affected_rows;
532ae5 703     }
L 704
705     public function mail_alias_delete($session_id, $primary_id)
706     {
7fe908 707         if (!$this->checkPerm($session_id, 'mail_alias_delete'))
MC 708         {
709             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
710             return false;
711         }
712         $affected_rows = $this->deleteQuery('../mail/form/mail_alias.tform.php', $primary_id);
713         return $affected_rows;
532ae5 714     }
7fe908 715
532ae5 716     //* Get mail forwarding details
L 717     public function mail_forward_get($session_id, $primary_id)
7fe908 718     {
532ae5 719         global $app;
7fe908 720
532ae5 721         if(!$this->checkPerm($session_id, 'mail_forward_get')) {
L 722             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
723             return false;
724         }
725         $app->uses('remoting_lib');
726         $app->remoting_lib->loadFormDef('../mail/form/mail_forward.tform.php');
727         return $app->remoting_lib->getDataRecord($primary_id);
728     }
7fe908 729
MC 730     //* przekierowania email
532ae5 731     public function mail_forward_add($session_id, $client_id, $params)
L 732     {
7fe908 733         if (!$this->checkPerm($session_id, 'mail_forward_add'))
MC 734         {
735             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
736             return false;
737         }
738         $affected_rows = $this->insertQuery('../mail/form/mail_forward.tform.php', $client_id, $params);
739         return $affected_rows;
532ae5 740     }
L 741
742
743     public function mail_forward_update($session_id, $client_id, $primary_id, $params)
744     {
7fe908 745         if (!$this->checkPerm($session_id, 'mail_forward_update'))
MC 746         {
747             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
748             return false;
749         }
750         $affected_rows = $this->updateQuery('../mail/form/mail_forward.tform.php', $client_id, $primary_id, $params);
751         return $affected_rows;
532ae5 752     }
L 753
754
755     public function mail_forward_delete($session_id, $primary_id)
756     {
7fe908 757         if (!$this->checkPerm($session_id, 'mail_forward_delete'))
MC 758         {
759             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
760             return false;
761         }
762         $affected_rows = $this->deleteQuery('../mail/form/mail_forward.tform.php', $primary_id);
763         return $affected_rows;
532ae5 764     }
7fe908 765
532ae5 766     //* Get catchall details
L 767     public function mail_catchall_get($session_id, $primary_id)
7fe908 768     {
532ae5 769         global $app;
7fe908 770
532ae5 771         if(!$this->checkPerm($session_id, 'mail_catchall_get')) {
L 772             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
773             return false;
774         }
775         $app->uses('remoting_lib');
776         $app->remoting_lib->loadFormDef('../mail/form/mail_domain_catchall.tform.php');
777         return $app->remoting_lib->getDataRecord($primary_id);
778     }
779
780     //* catchall e-mail
7fe908 781     public function mail_catchall_add($session_id, $client_id, $params)
532ae5 782     {
7fe908 783         if (!$this->checkPerm($session_id, 'mail_catchall_add'))
MC 784         {
785             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
786             return false;
787         }
788         $affected_rows = $this->insertQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $params);
789         return $affected_rows;
532ae5 790     }
L 791
792     public function mail_catchall_update($session_id, $client_id, $primary_id, $params)
793     {
7fe908 794         if (!$this->checkPerm($session_id, 'mail_catchall_update'))
MC 795         {
796             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
797             return false;
798         }
799         $affected_rows = $this->updateQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $primary_id, $params);
800         return $affected_rows;
532ae5 801     }
L 802
803     public function mail_catchall_delete($session_id, $primary_id)
804     {
7fe908 805         if (!$this->checkPerm($session_id, 'mail_catchall_delete'))
MC 806         {
807             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
808             return false;
809         }
810         $affected_rows = $this->deleteQuery('../mail/form/mail_domain_catchall.tform.php', $primary_id);
811         return $affected_rows;
532ae5 812     }
7fe908 813
532ae5 814     //* Get transport details
L 815     public function mail_transport_get($session_id, $primary_id)
7fe908 816     {
532ae5 817         global $app;
7fe908 818
532ae5 819         if(!$this->checkPerm($session_id, 'mail_transport_get')) {
L 820             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
821             return false;
822         }
823         $app->uses('remoting_lib');
824         $app->remoting_lib->loadFormDef('../mail/form/mail_transport.tform.php');
825         return $app->remoting_lib->getDataRecord($primary_id);
826     }
7fe908 827
532ae5 828     //* przeniesienia e-mail
L 829     public function mail_transport_add($session_id, $client_id, $params)
830     {
7fe908 831         if (!$this->checkPerm($session_id, 'mail_transport_add'))
MC 832         {
833             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
834             return false;
835         }
836         $affected_rows = $this->insertQuery('../mail/form/mail_transport.tform.php', $client_id, $params);
837         return $affected_rows;
532ae5 838     }
L 839
840
841     public function mail_transport_update($session_id, $client_id, $primary_id, $params)
842     {
7fe908 843         if (!$this->checkPerm($session_id, 'mail_transport_update'))
MC 844         {
845             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
846             return false;
847         }
848         $affected_rows = $this->updateQuery('../mail/form/mail_transport.tform.php', $client_id, $primary_id, $params);
849         return $affected_rows;
532ae5 850     }
L 851
852
853     public function mail_transport_delete($session_id, $primary_id)
854     {
7fe908 855         if (!$this->checkPerm($session_id, 'mail_transport_delete'))
MC 856         {
857             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
858             return false;
859         }
860         $affected_rows = $this->deleteQuery('../mail/form/mail_transport.tform.php', $primary_id);
861         return $affected_rows;
532ae5 862     }
7fe908 863
d7e78a 864
MC 865     //* Get mail relay_recipient details
866     public function mail_relay_recipient_get($session_id, $primary_id)
867     {
868         global $app;
869
870         if(!$this->checkPerm($session_id, 'mail_relay_get')) {
871                 $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
872                 return false;
873         }
874         $app->uses('remoting_lib');
875         $app->remoting_lib->loadFormDef('../mail/form/mail_relay_recipient.tform.php');
876         return $app->remoting_lib->getDataRecord($primary_id);
877     }
878
879
880     //* relay recipient email
881     public function mail_relay_recipient_add($session_id, $client_id, $params)
882     {
883         if (!$this->checkPerm($session_id, 'mail_relay_add'))
884         {
885             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
886             return false;
887         }
888         $affected_rows = $this->insertQuery('../mail/form/mail_relay_recipient.tform.php', $client_id, $params);
889         return $affected_rows;
890     }
891
892
893     public function mail_relay_recipient_update($session_id, $client_id, $primary_id, $params)
894     {
895         if (!$this->checkPerm($session_id, 'mail_relay_update'))
896         {
897             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
898             return false;
899         }
900         $affected_rows = $this->updateQuery('../mail/form/mail_relay_recipient.tform.php', $client_id, $primary_id, $params);
901         return $affected_rows;
902     }
903
904
905     public function mail_relay_recipient_delete($session_id, $primary_id)
906     {
907         if (!$this->checkPerm($session_id, 'mail_relay_delete'))
908         {
909             $this->server->fault('permission_denied','You do not have the permissions to access this function.');
910             return false;
911         }
912         $affected_rows = $this->deleteQuery('../mail/form/mail_relay_recipient.tform.php', $primary_id);
913         return $affected_rows;
914     }
915
916
532ae5 917     //* Get spamfilter whitelist details
L 918     public function mail_spamfilter_whitelist_get($session_id, $primary_id)
7fe908 919     {
532ae5 920         global $app;
7fe908 921
532ae5 922         if(!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_get')) {
L 923             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
924             return false;
925         }
926         $app->uses('remoting_lib');
927         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_whitelist.tform.php');
928         return $app->remoting_lib->getDataRecord($primary_id);
929     }
930
7fe908 931     //* biaÅ‚a lista e-mail
532ae5 932     public function mail_spamfilter_whitelist_add($session_id, $client_id, $params)
L 933     {
7fe908 934         if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_add'))
MC 935         {
936             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
937             return false;
938         }
939         $affected_rows = $this->insertQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $params);
940         return $affected_rows;
532ae5 941     }
L 942
943
944     public function mail_spamfilter_whitelist_update($session_id, $client_id, $primary_id, $params)
945     {
7fe908 946         if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_update'))
MC 947         {
948             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
949             return false;
950         }
951         $affected_rows = $this->updateQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $primary_id, $params);
952         return $affected_rows;
532ae5 953     }
L 954
955
956     public function mail_spamfilter_whitelist_delete($session_id, $primary_id)
957     {
7fe908 958         if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_delete'))
MC 959         {
960             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
961             return false;
962         }
963         $affected_rows = $this->deleteQuery('../mail/form/spamfilter_whitelist.tform.php', $primary_id);
964         return $affected_rows;
532ae5 965     }
7fe908 966
532ae5 967     //* Get spamfilter blacklist details
L 968     public function mail_spamfilter_blacklist_get($session_id, $primary_id)
7fe908 969     {
532ae5 970         global $app;
7fe908 971
532ae5 972         if(!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_get')) {
L 973             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
974             return false;
975         }
976         $app->uses('remoting_lib');
977         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_blacklist.tform.php');
978         return $app->remoting_lib->getDataRecord($primary_id);
979     }
7fe908 980
MC 981     //* czarna lista e-mail
532ae5 982     public function mail_spamfilter_blacklist_add($session_id, $client_id, $params)
L 983     {
7fe908 984         if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_add'))
MC 985         {
986             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
987             return false;
988         }
989         $affected_rows = $this->insertQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $params);
990         return $affected_rows;
532ae5 991     }
L 992
993
994     public function mail_spamfilter_blacklist_update($session_id, $client_id, $primary_id, $params)
995     {
7fe908 996         if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_update'))
MC 997         {
998             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
999             return false;
1000         }
1001         $affected_rows = $this->updateQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $primary_id, $params);
1002         return $affected_rows;
532ae5 1003     }
L 1004
1005
1006     public function mail_spamfilter_blacklist_delete($session_id, $primary_id)
1007     {
7fe908 1008         if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_delete'))
MC 1009         {
1010             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1011             return false;
1012         }
1013         $affected_rows = $this->deleteQuery('../mail/form/spamfilter_blacklist.tform.php', $primary_id);
1014         return $affected_rows;
532ae5 1015     }
7fe908 1016
532ae5 1017     //* Get spamfilter user details
L 1018     public function mail_spamfilter_user_get($session_id, $primary_id)
7fe908 1019     {
532ae5 1020         global $app;
7fe908 1021
532ae5 1022         if(!$this->checkPerm($session_id, 'mail_spamfilter_user_get')) {
L 1023             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1024             return false;
1025         }
1026         $app->uses('remoting_lib');
1027         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_users.tform.php');
1028         return $app->remoting_lib->getDataRecord($primary_id);
1029     }
1030
1031     //* filtr spamu użytkowników e-mail
1032     public function mail_spamfilter_user_add($session_id, $client_id, $params)
1033     {
7fe908 1034         if (!$this->checkPerm($session_id, 'mail_spamfilter_user_add'))
MC 1035         {
1036             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1037             return false;
1038         }
1039         $affected_rows = $this->insertQuery('../mail/form/spamfilter_users.tform.php', $client_id, $params);
1040         return $affected_rows;
532ae5 1041     }
L 1042
1043
1044     public function mail_spamfilter_user_update($session_id, $client_id, $primary_id, $params)
1045     {
7fe908 1046         if (!$this->checkPerm($session_id, 'mail_spamfilter_user_update'))
MC 1047         {
1048             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1049             return false;
1050         }
1051         $affected_rows = $this->updateQuery('../mail/form/spamfilter_users.tform.php', $client_id, $primary_id, $params);
1052         return $affected_rows;
532ae5 1053     }
L 1054
1055
1056     public function mail_spamfilter_user_delete($session_id, $primary_id)
1057     {
7fe908 1058         if (!$this->checkPerm($session_id, 'mail_spamfilter_user_delete'))
MC 1059         {
1060             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1061             return false;
1062         }
1063         $affected_rows = $this->deleteQuery('../mail/form/spamfilter_users.tform.php', $primary_id);
1064         return $affected_rows;
532ae5 1065     }
7fe908 1066
532ae5 1067     //* Get policy details
L 1068     public function mail_policy_get($session_id, $primary_id)
7fe908 1069     {
532ae5 1070         global $app;
7fe908 1071
532ae5 1072         if(!$this->checkPerm($session_id, 'mail_policy_get')) {
L 1073             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1074             return false;
1075         }
1076         $app->uses('remoting_lib');
1077         $app->remoting_lib->loadFormDef('../mail/form/spamfilter_policy.tform.php');
1078         return $app->remoting_lib->getDataRecord($primary_id);
1079     }
7fe908 1080
MC 1081     //* polityki filtrów spamu e-mail
532ae5 1082     public function mail_policy_add($session_id, $client_id, $params)
L 1083     {
7fe908 1084         if (!$this->checkPerm($session_id, 'mail_policy_add'))
MC 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->insertQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $params);
1090         return $affected_rows;
532ae5 1091     }
L 1092
1093
1094     public function mail_policy_update($session_id, $client_id, $primary_id, $params)
1095     {
7fe908 1096         if (!$this->checkPerm($session_id, 'mail_policy_update'))
MC 1097         {
1098             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1099             return false;
1100         }
1101         $affected_rows = $this->updateQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $primary_id, $params);
1102         return $affected_rows;
532ae5 1103     }
L 1104
1105
1106     public function mail_policy_delete($session_id, $primary_id)
1107     {
7fe908 1108         if (!$this->checkPerm($session_id, 'mail_policy_delete'))
MC 1109         {
1110             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1111             return false;
1112         }
1113         $affected_rows = $this->deleteQuery('../mail/form/spamfilter_policy.tform.php', $primary_id);
1114         return $affected_rows;
532ae5 1115     }
7fe908 1116
532ae5 1117     //* Get fetchmail details
L 1118     public function mail_fetchmail_get($session_id, $primary_id)
7fe908 1119     {
532ae5 1120         global $app;
7fe908 1121
532ae5 1122         if(!$this->checkPerm($session_id, 'mail_fetchmail_get')) {
L 1123             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1124             return false;
1125         }
1126         $app->uses('remoting_lib');
1127         $app->remoting_lib->loadFormDef('../mail/form/mail_get.tform.php');
1128         return $app->remoting_lib->getDataRecord($primary_id);
1129     }
1130
7fe908 1131     //* fetchmail
532ae5 1132     public function mail_fetchmail_add($session_id, $client_id, $params)
L 1133     {
7fe908 1134         if (!$this->checkPerm($session_id, 'mail_fetchmail_add'))
MC 1135         {
1136             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1137             return false;
1138         }
1139         $affected_rows = $this->insertQuery('../mail/form/mail_get.tform.php', $client_id, $params);
1140         return $affected_rows;
532ae5 1141     }
L 1142
1143
1144     public function mail_fetchmail_update($session_id, $client_id, $primary_id, $params)
1145     {
7fe908 1146         if (!$this->checkPerm($session_id, 'mail_fetchmail_update'))
MC 1147         {
1148             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1149             return false;
1150         }
1151         $affected_rows = $this->updateQuery('../mail/form/mail_get.tform.php', $client_id, $primary_id, $params);
1152         return $affected_rows;
532ae5 1153     }
L 1154
1155
1156     public function mail_fetchmail_delete($session_id, $primary_id)
1157     {
7fe908 1158         if (!$this->checkPerm($session_id, 'mail_fetchmail_delete'))
MC 1159         {
1160             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1161             return false;
1162         }
1163         $affected_rows = $this->deleteQuery('../mail/form/mail_get.tform.php', $primary_id);
1164         return $affected_rows;
532ae5 1165     }
7fe908 1166
532ae5 1167     //* Get whitelist details
L 1168     public function mail_whitelist_get($session_id, $primary_id)
7fe908 1169     {
532ae5 1170         global $app;
7fe908 1171
532ae5 1172         if(!$this->checkPerm($session_id, 'mail_whitelist_get')) {
L 1173             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1174             return false;
1175         }
1176         $app->uses('remoting_lib');
1177         $app->remoting_lib->loadFormDef('../mail/form/mail_whitelist.tform.php');
1178         return $app->remoting_lib->getDataRecord($primary_id);
1179     }
7fe908 1180
532ae5 1181     //* wpisy biaÅ‚ej listy
L 1182     public function mail_whitelist_add($session_id, $client_id, $params)
1183     {
7fe908 1184         if (!$this->checkPerm($session_id, 'mail_whitelist_add'))
MC 1185         {
1186             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1187             return false;
1188         }
1189         $affected_rows = $this->insertQuery('../mail/form/mail_whitelist.tform.php', $client_id, $params);
1190         return $affected_rows;
532ae5 1191     }
L 1192
1193
1194     public function mail_whitelist_update($session_id, $client_id, $primary_id, $params)
1195     {
7fe908 1196         if (!$this->checkPerm($session_id, 'mail_whitelist_update'))
MC 1197         {
1198             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1199             return false;
1200         }
1201         $affected_rows = $this->updateQuery('../mail/form/mail_whitelist.tform.php', $client_id, $primary_id, $params);
1202         return $affected_rows;
532ae5 1203     }
L 1204
1205
1206     public function mail_whitelist_delete($session_id, $primary_id)
1207     {
7fe908 1208         if (!$this->checkPerm($session_id, 'mail_whitelist_delete'))
MC 1209         {
1210             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1211             return false;
1212         }
1213         $affected_rows = $this->deleteQuery('../mail/form/mail_whitelist.tform.php', $primary_id);
1214         return $affected_rows;
532ae5 1215     }
7fe908 1216
532ae5 1217     //* Get Blacklist details
L 1218     public function mail_blacklist_get($session_id, $primary_id)
7fe908 1219     {
532ae5 1220         global $app;
7fe908 1221
532ae5 1222         if(!$this->checkPerm($session_id, 'mail_blacklist_get')) {
L 1223             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1224             return false;
1225         }
1226         $app->uses('remoting_lib');
1227         $app->remoting_lib->loadFormDef('../mail/form/mail_blacklist.tform.php');
1228         return $app->remoting_lib->getDataRecord($primary_id);
1229     }
7fe908 1230
532ae5 1231     //* wpisy biaÅ‚ej listy
L 1232     public function mail_blacklist_add($session_id, $client_id, $params)
1233     {
7fe908 1234         if (!$this->checkPerm($session_id, 'mail_blacklist_add'))
MC 1235         {
1236             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1237             return false;
1238         }
1239         $affected_rows = $this->insertQuery('../mail/form/mail_blacklist.tform.php', $client_id, $params);
1240         return $affected_rows;
532ae5 1241     }
L 1242
1243
1244     public function mail_blacklist_update($session_id, $client_id, $primary_id, $params)
1245     {
7fe908 1246         if (!$this->checkPerm($session_id, 'mail_blacklist_update'))
MC 1247         {
1248             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1249             return false;
1250         }
1251         $affected_rows = $this->updateQuery('../mail/form/mail_blacklist.tform.php', $client_id, $primary_id, $params);
1252         return $affected_rows;
532ae5 1253     }
L 1254
1255
1256     public function mail_blacklist_delete($session_id, $primary_id)
1257     {
7fe908 1258         if (!$this->checkPerm($session_id, 'mail_blacklist_delete'))
MC 1259         {
1260             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1261             return false;
1262         }
1263         $affected_rows = $this->deleteQuery('../mail/form/mail_blacklist.tform.php', $primary_id);
1264         return $affected_rows;
532ae5 1265     }
7fe908 1266
532ae5 1267     //* Get filter details
L 1268     public function mail_filter_get($session_id, $primary_id)
7fe908 1269     {
532ae5 1270         global $app;
7fe908 1271
532ae5 1272         if(!$this->checkPerm($session_id, 'mail_filter_get')) {
L 1273             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1274             return false;
1275         }
1276         $app->uses('remoting_lib');
1277         $app->remoting_lib->loadFormDef('../mail/form/mail_content_filter.tform.php');
1278         return $app->remoting_lib->getDataRecord($primary_id);
1279     }
1280
1281     //* wpisy filtrow e-mail
1282     public function mail_filter_add($session_id, $client_id, $params)
1283     {
7fe908 1284         if (!$this->checkPerm($session_id, 'mail_filter_add'))
MC 1285         {
1286             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1287             return false;
1288         }
1289         $affected_rows = $this->insertQuery('../mail/form/mail_content_filter.tform.php', $client_id, $params);
1290         return $affected_rows;
532ae5 1291     }
L 1292
1293
1294     public function mail_filter_update($session_id, $client_id, $primary_id, $params)
1295     {
7fe908 1296         if (!$this->checkPerm($session_id, 'mail_filter_update'))
MC 1297         {
1298             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1299             return false;
1300         }
1301         $affected_rows = $this->updateQuery('../mail/form/mail_content_filter.tform.php', $client_id, $primary_id, $params);
1302         return $affected_rows;
532ae5 1303     }
L 1304
1305
1306     public function mail_filter_delete($session_id, $primary_id)
1307     {
7fe908 1308         if (!$this->checkPerm($session_id, 'mail_filter_delete'))
MC 1309         {
1310             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1311             return false;
1312         }
1313         $affected_rows = $this->deleteQuery('../mail/form/mail_content_filter.tform.php', $primary_id);
1314         return $affected_rows;
532ae5 1315     }
L 1316
1317
1318
1319
7fe908 1320     /*
MC 1321  *
1322  *
1323  *
532ae5 1324  *      * Client functions
7fe908 1325  *
MC 1326  *
532ae5 1327  */
L 1328     //* Get client details
1329     public function client_get($session_id, $client_id)
7fe908 1330     {
532ae5 1331         global $app;
7fe908 1332
532ae5 1333         if(!$this->checkPerm($session_id, 'client_get')) {
L 1334             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1335             return false;
1336         }
1337         $app->uses('remoting_lib');
1338         $app->remoting_lib->loadFormDef('../client/form/client.tform.php');
7b47c0 1339         $data = $app->remoting_lib->getDataRecord($client_id);
7fe908 1340
MC 1341         // we need to get the new-style templates for backwards-compatibility - maybe we remove this in a later version
1342         if(is_array($data) && count($data) > 0) {
1343             if(isset($data['client_id'])) {
1344                 // this is a single record
1345                 if($data['template_additional'] == '') {
1346                     $tpls = $app->db->queryAllRecords('SELECT CONCAT(`assigned_template_id`, \':\', `client_template_id`) as `item` FROM `client_template_assigned` WHERE `client_id` = ' . $data['client_id']);
1347                     $tpl_arr = array();
1348                     if($tpls) {
1349                         foreach($tpls as $tpl) $tpl_arr[] = $tpl['item'];
1350                     }
1351                     $data['template_additional'] = implode('/', $tpl_arr);
1352                     unset($tpl_arr);
1353                     unset($tpls);
1354                 }
1355             } elseif(isset($data[0]['client_id'])) {
1356                 // multiple client records
1357                 foreach($data as $index => $client) {
1358                     if($client['template_additional'] == '') {
1359                         $tpls = $app->db->queryAllRecords('SELECT CONCAT(`assigned_template_id`, \':\', `client_template_id`) as `item` FROM `client_template_assigned` WHERE `client_id` = ' . $client['client_id']);
1360                         $tpl_arr = array();
1361                         if($tpls) {
1362                             foreach($tpls as $tpl) $tpl_arr[] = $tpl['item'];
1363                         }
1364                         $data[$index]['template_additional'] = implode('/', $tpl_arr); // dont use the $client array here - changes would not be returned to soap
1365                     }
1366                     unset($tpl_arr);
1367                     unset($tpls);
1368                 }
1369             }
1370         }
1371
1372         return $data;
532ae5 1373     }
7fe908 1374
532ae5 1375     public function client_get_id($session_id, $sys_userid)
7fe908 1376     {
532ae5 1377         global $app;
L 1378         if(!$this->checkPerm($session_id, 'client_get_id')) {
1379             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1380             return false;
1381         }
7fe908 1382
65ea2e 1383         $sys_userid = $app->functions->intval($sys_userid);
7fe908 1384
532ae5 1385         $rec = $app->db->queryOneRecord("SELECT client_id FROM sys_user WHERE userid = ".$sys_userid);
L 1386         if(isset($rec['client_id'])) {
65ea2e 1387             return $app->functions->intval($rec['client_id']);
532ae5 1388         } else {
L 1389             $this->server->fault('no_client_found', 'There is no sysuser account for this client ID.');
1390             return false;
1391         }
7fe908 1392
532ae5 1393     }
7fe908 1394
b67344 1395     public function client_get_groupid($session_id, $client_id)
7fe908 1396     {
b67344 1397         global $app;
T 1398         if(!$this->checkPerm($session_id, 'client_get_id')) {
1399             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1400             return false;
1401         }
7fe908 1402
65ea2e 1403         $client_id = $app->functions->intval($client_id);
7fe908 1404
b67344 1405         $rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$client_id);
T 1406         if(isset($rec['groupid'])) {
65ea2e 1407             return $app->functions->intval($rec['groupid']);
b67344 1408         } else {
T 1409             $this->server->fault('no_group_found', 'There is no group for this client ID.');
1410             return false;
1411         }
7fe908 1412
b67344 1413     }
7fe908 1414
MC 1415
532ae5 1416     public function client_add($session_id, $reseller_id, $params)
L 1417     {
bfc771 1418         global $app;
MC 1419         
532ae5 1420         if (!$this->checkPerm($session_id, 'client_add'))
7fe908 1421         {
MC 1422             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1423             return false;
1424         }
1425         if(!isset($params['parent_client_id']) || $params['parent_client_id'] == 0) $params['parent_client_id'] = $reseller_id;
bfc771 1426         
MC 1427         if($params['parent_client_id']) {
1428             // check if this one is reseller
1429             $check = $app->db->queryOneRecord('SELECT `limit_client` FROM `client` WHERE `client_id` = ' . intval($client_id));
1430             if($check['limit_client'] == 0) {
1431                 $this->server->fault('Invalid reseller', 'Selected client is not a reseller.');
1432                 return false;
1433             }
1434             
1435             if(isset($params['limit_client']) && $params['limit_client'] != 0) {
1436                 $this->server->fault('Invalid reseller', 'Reseller cannot be client of another reseller.');
1437                 return false;
1438             }
1439         }
1440         
1441         $affected_rows = $this->klientadd('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php', $reseller_id, $params);
7fe908 1442         return $affected_rows;
MC 1443
532ae5 1444     }
7fe908 1445
532ae5 1446     public function client_update($session_id, $client_id, $reseller_id, $params)
L 1447     {
7fe908 1448         global $app;
7b47c0 1449
7fe908 1450         if (!$this->checkPerm($session_id, 'client_update'))
MC 1451         {
1452             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1453             return false;
1454         }
1455
1456         $app->uses('remoting_lib');
bfc771 1457         $app->remoting_lib->loadFormDef('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php');
7fe908 1458         $old_rec = $app->remoting_lib->getDataRecord($client_id);
bfc771 1459
MC 1460         if(!isset($params['parent_client_id']) || $params['parent_client_id'] == 0) $params['parent_client_id'] = $reseller_id;
1461
1462         if($params['parent_client_id']) {
1463             // check if this one is reseller
1464             $check = $app->db->queryOneRecord('SELECT `limit_client` FROM `client` WHERE `client_id` = ' . intval($client_id));
1465             if($check['limit_client'] == 0) {
1466                 $this->server->fault('Invalid reseller', 'Selected client is not a reseller.');
1467                 return false;
1468             }
1469             
1470             if(isset($params['limit_client']) && $params['limit_client'] != 0) {
1471                 $this->server->fault('Invalid reseller', 'Reseller cannot be client of another reseller.');
1472                 return false;
1473             }
1474         }
7fe908 1475
MC 1476         // we need the previuos templates assigned here
1477         $this->oldTemplatesAssigned = $app->db->queryAllRecords('SELECT * FROM `client_template_assigned` WHERE `client_id` = ' . $client_id);
1478         if(!is_array($this->oldTemplatesAssigned) || count($this->oldTemplatesAssigned) < 1) {
1479             // check previous type of storing templates
1480             $tpls = explode('/', $old_rec['template_additional']);
1481             $this->oldTemplatesAssigned = array();
1482             foreach($tpls as $item) {
1483                 $item = trim($item);
1484                 if(!$item) continue;
1485                 $this->oldTemplatesAssigned[] = array('assigned_template_id' => 0, 'client_template_id' => $item, 'client_id' => $client_id);
1486             }
1487             unset($tpls);
1488         }
1489         if(isset($params['template_additional'])) {
1490             $app->uses('client_templates');
1491             $templates = explode('/', $params['template_additional']);
1492             $params['template_additional'] = '';
1493             $app->client_templates->update_client_templates($client_id, $templates);
1494             unset($templates);
1495         }
1496
1497
bfc771 1498         $affected_rows = $this->updateQuery('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php', $reseller_id, $client_id, $params, 'client:' . ($params['parent_client_id'] ? 'reseller' : 'client') . ':on_after_update');
7fe908 1499
MC 1500         $app->remoting_lib->ispconfig_sysuser_update($params, $client_id);
1501
1502         return $affected_rows;
532ae5 1503     }
7fe908 1504
MC 1505     public function client_template_additional_get($session_id, $client_id) {
1506         global $app;
532ae5 1507
7b47c0 1508         if(!$this->checkPerm($session_id, 'client_get')) {
T 1509             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1510             return false;
1511         }
1512
7fe908 1513         if(@is_numeric($client_id)) {
MC 1514             $sql = "SELECT * FROM `client_template_assigned` WHERE `client_id` = ".$client_id;
1515             return $app->db->queryOneRecord($sql);
1516         } else {
1517             $this->server->fault('The ID must be an integer.');
1518             return array();
7b47c0 1519         }
532ae5 1520     }
7fe908 1521
MC 1522     private function _set_client_formdata($client_id) {
1523         global $app;
1524
1525         $this->id = $client_id;
1526         $this->dataRecord = $app->db->queryOneRecord('SELECT * FROM `client` WHERE `client_id` = ' . $client_id);
1527         $this->oldDataRecord = $this->dataRecord;
1528
1529         $this->oldTemplatesAssigned = $app->db->queryAllRecords('SELECT * FROM `client_template_assigned` WHERE `client_id` = ' . $client_id);
1530         if(!is_array($this->oldTemplatesAssigned) || count($this->oldTemplatesAssigned) < 1) {
1531             // check previous type of storing templates
1532             $tpls = explode('/', $this->oldDataRecord['template_additional']);
1533             $this->oldTemplatesAssigned = array();
1534             foreach($tpls as $item) {
1535                 $item = trim($item);
1536                 if(!$item) continue;
1537                 $this->oldTemplatesAssigned[] = array('assigned_template_id' => 0, 'client_template_id' => $item, 'client_id' => $client_id);
1538             }
1539             unset($tpls);
1ca823 1540         }
7fe908 1541     }
MC 1542
1543     public function client_template_additional_add($session_id, $client_id, $template_id) {
1544         global $app;
1545
1546         if(!$this->checkPerm($session_id, 'client_update')) {
1547             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1548             return false;
1549         }
1550
1551         if(@is_numeric($client_id) && @is_numeric($template_id)) {
1552             // check if client exists
1553             $check = $app->db->queryOneRecord('SELECT `client_id` FROM `client` WHERE `client_id` = ' . $client_id);
1554             if(!$check) {
1555                 $this->server->fault('Invalid client');
1556                 return false;
1557             }
1558             // check if template exists
1559             $check = $app->db->queryOneRecord('SELECT `template_id` FROM `client_template` WHERE `template_id` = ' . $template_id);
1560             if(!$check) {
1561                 $this->server->fault('Invalid template');
1562                 return false;
1563             }
1564
1565             // for the update event we have to cheat a bit
1566             $this->_set_client_formdata($client_id);
1567
1568             $sql = "INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (" . $client_id . ", " . $template_id . ")";
1569             $app->db->query($sql);
1570             $insert_id = $app->db->insertID();
1571
1572             $app->plugin->raiseEvent('client:client:on_after_update', $this);
1573
1574             return $insert_id;
1575         } else {
1576             $this->server->fault('The IDs must be of type integer.');
1577             return false;
1578         }
1579     }
1580
1581     public function client_template_additional_delete($session_id, $client_id, $assigned_template_id) {
1582         global $app;
1583
1584         if(!$this->checkPerm($session_id, 'client_update')) {
1585             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1586             return false;
1587         }
1588
1589         if(@is_numeric($client_id) && @is_numeric($template_id)) {
1590             // check if client exists
1591             $check = $app->db->queryOneRecord('SELECT `client_id` FROM `client` WHERE `client_id` = ' . $client_id);
1592             if(!$check) {
1593                 $this->server->fault('Invalid client');
1594                 return false;
1595             }
1596             // check if template exists
1597             $check = $app->db->queryOneRecord('SELECT `assigned_template_id` FROM `client_template_assigned` WHERE `assigned_template_id` = ' . $assigned_template_id);
1598             if(!$check) {
1599                 $this->server->fault('Invalid template');
1600                 return false;
1601             }
1602
1603             // for the update event we have to cheat a bit
1604             $this->_set_client_formdata($client_id);
1605
1606             $sql = "DELETE FROM `client_template_assigned` WHERE `assigned_template_id` = " . $template_id . " AND `client_id` = " . $client_id;
1607             $app->db->query($sql);
1608             $affected_rows = $app->db->affectedRows();
1609
1610             $app->plugin->raiseEvent('client:client:on_after_update', $this);
1611
1612             return $affected_rows;
1613         } else {
1614             $this->server->fault('The IDs must be of type integer.');
1615             return false;
1616         }
1617     }
1618
1619     public function client_delete($session_id, $client_id)
1620     {
1621         global $app;
1622
1623         if (!$this->checkPerm($session_id, 'client_delete'))
1624         {
1625             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1626             return false;
1627         }
1628         $affected_rows = $this->deleteQuery('../client/form/client.tform.php', $client_id);
1629
1630         $app->remoting_lib->ispconfig_sysuser_delete($client_id);
1631
1632         return $affected_rows;
1633     }
1634
1635     // -----------------------------------------------------------------------------------------------
1636
1637     public function client_delete_everything($session_id, $client_id)
1638     {
1639         global $app, $conf;
1640
1641         if(!$this->checkPerm($session_id, 'client_delete_everything')) {
1642             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1643             return false;
1644         }
1645
bfcdef 1646         $client_id = $app->functions->intval($client_id);
1ca823 1647
7fe908 1648         if($client_id > 0) {
bfcdef 1649             //* remove the group of the client from the resellers group
65ea2e 1650             $parent_client_id = $app->functions->intval($this->dataRecord['parent_client_id']);
1ca823 1651             $parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = $parent_client_id");
T 1652             $client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
7fe908 1653             $app->auth->remove_group_from_user($parent_user['userid'], $client_group['groupid']);
MC 1654
bfcdef 1655             //* delete the group of the client
1ca823 1656             $app->db->query("DELETE FROM sys_group WHERE client_id = $client_id");
7fe908 1657
bfcdef 1658             //* delete the sys user(s) of the client
1ca823 1659             $app->db->query("DELETE FROM sys_user WHERE client_id = $client_id");
7fe908 1660
bfcdef 1661             //* Delete all records (sub-clients, mail, web, etc....)  of this client.
ecb6b3 1662             $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_database_user,web_domain,web_traffic';
7fe908 1663             $tables_array = explode(',', $tables);
65ea2e 1664             $client_group_id = $app->functions->intval($client_group['groupid']);
7fe908 1665
1ca823 1666             if($client_group_id > 1) {
T 1667                 foreach($tables_array as $table) {
1668                     if($table != '') {
1669                         $records = $app->db->queryAllRecords("SELECT * FROM $table WHERE sys_groupid = ".$client_group_id);
bfcdef 1670                         //* find the primary ID of the table
1ca823 1671                         $table_info = $app->db->tableInfo($table);
T 1672                         $index_field = '';
1673                         foreach($table_info as $tmp) {
1674                             if($tmp['option'] == 'primary') $index_field = $tmp['name'];
1675                         }
bfcdef 1676
T 1677                         //* Delete the records
1ca823 1678                         if($index_field != '') {
T 1679                             if(is_array($records)) {
1680                                 foreach($records as $rec) {
1681                                     $app->db->datalogDelete($table, $index_field, $rec[$index_field]);
bfcdef 1682                                     //* Delete traffic records that dont have a sys_groupid column
T 1683                                     if($table == 'web_domain') {
1684                                         $app->db->query("DELETE FROM web_traffic WHERE hostname = '".$app->db->quote($rec['domain'])."'");
1685                                     }
1686                                     //* Delete mail_traffic records that dont have a sys_groupid
1687                                     if($table == 'mail_user') {
1688                                         $app->db->query("DELETE FROM mail_traffic WHERE mailuser_id = '".$app->db->quote($rec['mailuser_id'])."'");
1689                                     }
1ca823 1690                                 }
T 1691                             }
1692                         }
7fe908 1693
1ca823 1694                     }
T 1695                 }
1696             }
7fe908 1697
1ca823 1698         }
7fe908 1699
bfcdef 1700         if (!$this->checkPerm($session_id, 'client_delete')) {
7fe908 1701             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
bfcdef 1702             return false;
T 1703         }
7fe908 1704         $affected_rows = $this->deleteQuery('../client/form/client.tform.php', $client_id);
1ca823 1705
7fe908 1706         return $affected_rows;
1ca823 1707     }
7fe908 1708
532ae5 1709     // Website functions ---------------------------------------------------------------------------------------
7fe908 1710
532ae5 1711     //* Get cron details
L 1712     public function sites_cron_get($session_id, $cron_id)
7fe908 1713     {
532ae5 1714         global $app;
7fe908 1715
532ae5 1716         if(!$this->checkPerm($session_id, 'sites_cron_get')) {
L 1717             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1718             return false;
1719         }
1720         $app->uses('remoting_lib');
1721         $app->remoting_lib->loadFormDef('../sites/form/cron.tform.php');
1722         return $app->remoting_lib->getDataRecord($cron_id);
1723     }
7fe908 1724
532ae5 1725     //* Add a cron record
L 1726     public function sites_cron_add($session_id, $client_id, $params)
7fe908 1727     {
532ae5 1728         if(!$this->checkPerm($session_id, 'sites_cron_add')) {
L 1729             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1730             return false;
1731         }
7fe908 1732         return $this->insertQuery('../sites/form/cron.tform.php', $client_id, $params);
532ae5 1733     }
7fe908 1734
532ae5 1735     //* Update cron record
L 1736     public function sites_cron_update($session_id, $client_id, $cron_id, $params)
7fe908 1737     {
532ae5 1738         if(!$this->checkPerm($session_id, 'sites_cron_update')) {
L 1739             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1740             return false;
1741         }
7fe908 1742         $affected_rows = $this->updateQuery('../sites/form/cron.tform.php', $client_id, $cron_id, $params);
532ae5 1743         return $affected_rows;
L 1744     }
7fe908 1745
532ae5 1746     //* Delete cron record
L 1747     public function sites_cron_delete($session_id, $cron_id)
7fe908 1748     {
532ae5 1749         if(!$this->checkPerm($session_id, 'sites_cron_delete')) {
L 1750             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1751             return false;
1752         }
7fe908 1753         $affected_rows = $this->deleteQuery('../sites/form/cron.tform.php', $cron_id);
532ae5 1754         return $affected_rows;
L 1755     }
7fe908 1756
532ae5 1757     // ----------------------------------------------------------------------------------------------------------
7fe908 1758
532ae5 1759     //* Get record details
L 1760     public function sites_database_get($session_id, $primary_id)
7fe908 1761     {
532ae5 1762         global $app;
7fe908 1763
532ae5 1764         if(!$this->checkPerm($session_id, 'sites_database_get')) {
L 1765             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1766             return false;
1767         }
1768         $app->uses('remoting_lib');
1769         $app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
1770         return $app->remoting_lib->getDataRecord($primary_id);
1771     }
7fe908 1772
532ae5 1773     //* Add a record
L 1774     public function sites_database_add($session_id, $client_id, $params)
7fe908 1775     {
MC 1776         global $app;
1777
532ae5 1778         if(!$this->checkPerm($session_id, 'sites_database_add')) {
L 1779             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1780             return false;
1781         }
7fe908 1782
4bd960 1783         //* Check for duplicates
T 1784         $tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = '".$app->db->quote($params['database_name'])."' AND server_id = '".intval($params["server_id"])."'");
1785         if($tmp['dbnum'] > 0) {
1786             $this->server->fault('database_name_error_unique', 'There is already a database with that name on the same server.');
1787             return false;
1788         }
ecb6b3 1789
7fe908 1790         $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
MC 1791         if($sql !== false) {
1792             $app->uses('sites_database_plugin');
ecb6b3 1793
7fe908 1794             $this->id = 0;
MC 1795             $this->dataRecord = $params;
1796             $app->sites_database_plugin->processDatabaseInsert($this);
1797
d677ff 1798             $retval = $this->insertQueryExecute($sql, $params);
FT 1799             
1800             // set correct values for backup_interval and backup_copies
1801             if(isset($params['backup_interval']) || isset($params['backup_copies'])){
1802                 $sql_set = array();
1803                 if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
1804                 if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
1805                 //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
1806                 $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
1807             }
1808             
1809             return $retval;
7fe908 1810         }
MC 1811
1812         return false;
532ae5 1813     }
7fe908 1814
532ae5 1815     //* Update a record
L 1816     public function sites_database_update($session_id, $client_id, $primary_id, $params)
7fe908 1817     {
MC 1818         global $app;
1819
532ae5 1820         if(!$this->checkPerm($session_id, 'sites_database_update')) {
L 1821             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1822             return false;
1823         }
7fe908 1824
ecb6b3 1825         $sql = $this->updateQueryPrepare('../sites/form/database.tform.php', $client_id, $primary_id, $params);
7fe908 1826         if($sql !== false) {
MC 1827             $app->uses('sites_database_plugin');
1828
1829             $this->id = $primary_id;
1830             $this->dataRecord = $params;
1831             $app->sites_database_plugin->processDatabaseUpdate($this);
d677ff 1832             $retval = $this->updateQueryExecute($sql, $primary_id, $params);
FT 1833             
1834             // set correct values for backup_interval and backup_copies
1835             if(isset($params['backup_interval']) || isset($params['backup_copies'])){
1836                 $sql_set = array();
1837                 if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
1838                 if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
1839                 //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$primary_id);
1840                 $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$primary_id, $primary_id, $params);
1841             }
1842             
1843             return $retval;
7fe908 1844         }
MC 1845
1846         return false;
532ae5 1847     }
7fe908 1848
532ae5 1849     //* Delete a record
L 1850     public function sites_database_delete($session_id, $primary_id)
7fe908 1851     {
MC 1852         global $app;
532ae5 1853         if(!$this->checkPerm($session_id, 'sites_database_delete')) {
L 1854             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1855             return false;
1856         }
7fe908 1857
MC 1858         $app->uses('sites_database_plugin');
1859         $app->sites_database_plugin->processDatabaseDelete($primary_id);
1860
1861         $affected_rows = $this->deleteQuery('../sites/form/database.tform.php', $primary_id);
ecb6b3 1862         return $affected_rows;
M 1863     }
7fe908 1864
ecb6b3 1865     // ----------------------------------------------------------------------------------------------------------
7fe908 1866
ecb6b3 1867     //* Get record details
M 1868     public function sites_database_user_get($session_id, $primary_id)
7fe908 1869     {
ecb6b3 1870         global $app;
7fe908 1871
ecb6b3 1872         if(!$this->checkPerm($session_id, 'sites_database_user_get')) {
M 1873             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1874             return false;
1875         }
1876         $app->uses('remoting_lib');
1877         $app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php');
1878         return $app->remoting_lib->getDataRecord($primary_id);
1879     }
7fe908 1880
ecb6b3 1881     //* Add a record
M 1882     public function sites_database_user_add($session_id, $client_id, $params)
7fe908 1883     {
ecb6b3 1884         if(!$this->checkPerm($session_id, 'sites_database_user_add')) {
M 1885             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1886             return false;
1887         }
1888
7fe908 1889         return $this->insertQuery('../sites/form/database_user.tform.php', $client_id, $params);
ecb6b3 1890     }
7fe908 1891
ecb6b3 1892     //* Update a record
M 1893     public function sites_database_user_update($session_id, $client_id, $primary_id, $params)
7fe908 1894     {
MC 1895         global $app;
1896
ecb6b3 1897         if(!$this->checkPerm($session_id, 'sites_database_user_update')) {
M 1898             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1899             return false;
1900         }
10b4c8 1901         $app->uses('remoting_lib');
T 1902         $app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php');
7fe908 1903         $old_rec = $app->remoting_lib->getDataRecord($primary_id);
MC 1904
10b4c8 1905         $result = $this->updateQuery('../sites/form/database_user.tform.php', $client_id, $primary_id, $params);
7fe908 1906
MC 1907         $new_rec = $app->remoting_lib->getDataRecord($primary_id);
1908
1909         $records = $app->db->queryAllRecords("SELECT DISTINCT server_id FROM web_database WHERE database_user_id = '".$app->functions->intval($primary_id)."' UNION SELECT DISTINCT server_id FROM web_database WHERE database_ro_user_id = '".$app->functions->intval($primary_id)."'");
1910         foreach($records as $rec) {
1911             $tmp_rec = $new_rec;
1912             $tmp_rec['server_id'] = $rec['server_id'];
1913             $app->remoting_lib->datalogSave('UPDATE', $primary_id, $old_rec, $tmp_rec);
1914         }
1915         unset($new_rec);
1916         unset($old_rec);
1917         unset($records);
1918
1919         return $result;
1920     }
1921
ecb6b3 1922     //* Delete a record
M 1923     public function sites_database_user_delete($session_id, $primary_id)
7fe908 1924     {
MC 1925         global $app;
1926
ecb6b3 1927         if(!$this->checkPerm($session_id, 'sites_database_user_delete')) {
M 1928             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1929             return false;
1930         }
7fe908 1931
MC 1932         $app->db->datalogDelete('web_database_user', 'database_user_id', $primary_id);
1933         $affected_rows = $this->deleteQuery('../sites/form/database_user.tform.php', $primary_id);
1934
1935         $records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_user_id = '".$app->functions->intval($primary_id)."'");
1936         foreach($records as $rec) {
1937             $app->db->datalogUpdate('web_database', 'database_user_id=NULL', 'database_id', $rec['database_id']);
1938
1939         }
1940         $records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_ro_user_id = '".$app->functions->intval($primary_id)."'");
1941         foreach($records as $rec) {
1942             $app->db->datalogUpdate('web_database', 'database_ro_user_id=NULL', 'database_id', $rec['database_id']);
1943         }
1944
532ae5 1945         return $affected_rows;
L 1946     }
7fe908 1947
532ae5 1948     // ----------------------------------------------------------------------------------------------------------
7fe908 1949
532ae5 1950     //* Get record details
L 1951     public function sites_ftp_user_get($session_id, $primary_id)
7fe908 1952     {
532ae5 1953         global $app;
7fe908 1954
532ae5 1955         if(!$this->checkPerm($session_id, 'sites_ftp_user_get')) {
L 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('../sites/form/ftp_user.tform.php');
1961         return $app->remoting_lib->getDataRecord($primary_id);
1962     }
7fe908 1963
532ae5 1964     //* Add a record
L 1965     public function sites_ftp_user_add($session_id, $client_id, $params)
7fe908 1966     {
532ae5 1967         if(!$this->checkPerm($session_id, 'sites_ftp_user_add')) {
L 1968             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1969             return false;
1970         }
7fe908 1971         return $this->insertQuery('../sites/form/ftp_user.tform.php', $client_id, $params);
532ae5 1972     }
7fe908 1973
532ae5 1974     //* Update a record
L 1975     public function sites_ftp_user_update($session_id, $client_id, $primary_id, $params)
7fe908 1976     {
532ae5 1977         if(!$this->checkPerm($session_id, 'sites_ftp_user_update')) {
L 1978             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1979             return false;
1980         }
7fe908 1981         $affected_rows = $this->updateQuery('../sites/form/ftp_user.tform.php', $client_id, $primary_id, $params);
532ae5 1982         return $affected_rows;
L 1983     }
7fe908 1984
532ae5 1985     //* Delete a record
L 1986     public function sites_ftp_user_delete($session_id, $primary_id)
7fe908 1987     {
532ae5 1988         if(!$this->checkPerm($session_id, 'sites_ftp_user_delete')) {
L 1989             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1990             return false;
1991         }
7fe908 1992         $affected_rows = $this->deleteQuery('../sites/form/ftp_user.tform.php', $primary_id);
532ae5 1993         return $affected_rows;
L 1994     }
7fe908 1995
a79341 1996     //* Get server for an ftp user
M 1997     public function sites_ftp_user_server_get($session_id, $ftp_user)
7fe908 1998     {
a79341 1999         global $app;
7fe908 2000
a79341 2001         if(!$this->checkPerm($session_id, 'sites_ftp_user_server_get')) {
M 2002             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2003             return false;
2004         }
7fe908 2005
a79341 2006         $data = $app->db->queryOneRecord("SELECT server_id FROM ftp_user WHERE username = '".$app->db->quote($ftp_user)."'");
b349c0 2007         //file_put_contents('/tmp/test.txt', serialize($data));
7fe908 2008         if(!isset($data['server_id'])) return false;
MC 2009
2010         $server = $this->server_get($session_id, $data['server_id'], 'server');
2011         //file_put_contents('/tmp/test2.txt', serialize($server));
2012
a79341 2013         return $server;
M 2014     }
7fe908 2015
532ae5 2016     // ----------------------------------------------------------------------------------------------------------
7fe908 2017
532ae5 2018     //* Get record details
L 2019     public function sites_shell_user_get($session_id, $primary_id)
7fe908 2020     {
532ae5 2021         global $app;
7fe908 2022
532ae5 2023         if(!$this->checkPerm($session_id, 'sites_shell_user_get')) {
L 2024             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2025             return false;
2026         }
2027         $app->uses('remoting_lib');
2028         $app->remoting_lib->loadFormDef('../sites/form/shell_user.tform.php');
2029         return $app->remoting_lib->getDataRecord($primary_id);
2030     }
7fe908 2031
532ae5 2032     //* Add a record
L 2033     public function sites_shell_user_add($session_id, $client_id, $params)
7fe908 2034     {
532ae5 2035         if(!$this->checkPerm($session_id, 'sites_shell_user_add')) {
L 2036             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2037             return false;
2038         }
7fe908 2039         return $this->insertQuery('../sites/form/shell_user.tform.php', $client_id, $params);
532ae5 2040     }
7fe908 2041
532ae5 2042     //* Update a record
L 2043     public function sites_shell_user_update($session_id, $client_id, $primary_id, $params)
7fe908 2044     {
532ae5 2045         if(!$this->checkPerm($session_id, 'sites_shell_user_update')) {
L 2046             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2047             return false;
2048         }
7fe908 2049         $affected_rows = $this->updateQuery('../sites/form/shell_user.tform.php', $client_id, $primary_id, $params);
532ae5 2050         return $affected_rows;
L 2051     }
7fe908 2052
532ae5 2053     //* Delete a record
L 2054     public function sites_shell_user_delete($session_id, $primary_id)
7fe908 2055     {
532ae5 2056         if(!$this->checkPerm($session_id, 'sites_shell_user_delete')) {
L 2057             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2058             return false;
2059         }
7fe908 2060         $affected_rows = $this->deleteQuery('../sites/form/shell_user.tform.php', $primary_id);
532ae5 2061         return $affected_rows;
L 2062     }
7fe908 2063
532ae5 2064     // ----------------------------------------------------------------------------------------------------------
7fe908 2065
532ae5 2066     //* Get record details
L 2067     public function sites_web_domain_get($session_id, $primary_id)
7fe908 2068     {
532ae5 2069         global $app;
7fe908 2070
532ae5 2071         if(!$this->checkPerm($session_id, 'sites_web_domain_get')) {
L 2072             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2073             return false;
2074         }
2075         $app->uses('remoting_lib');
2076         $app->remoting_lib->loadFormDef('../sites/form/web_domain.tform.php');
2077         return $app->remoting_lib->getDataRecord($primary_id);
2078     }
7fe908 2079
532ae5 2080     //* Add a record
1ca823 2081     public function sites_web_domain_add($session_id, $client_id, $params, $readonly = false)
T 2082     {
2083         global $app;
532ae5 2084         if(!$this->checkPerm($session_id, 'sites_web_domain_add')) {
L 2085             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2086             return false;
2087         }
7fe908 2088
cdf6f0 2089         if(!isset($params['client_group_id']) or (isset($params['client_group_id']) && empty($params['client_group_id']))) {
65ea2e 2090             $rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($client_id));
cdf6f0 2091             $params['client_group_id'] = $rec['groupid'];
T 2092         }
7fe908 2093
cdf6f0 2094         //* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
T 2095         if($params['document_root'] == '') $params['document_root'] = '-';
2096         if($params['system_user'] == '') $params['system_user'] = '-';
2097         if($params['system_group'] == '') $params['system_group'] = '-';
7fe908 2098
8ab3cd 2099         //* Set a few defaults for nginx servers
T 2100         if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
2101         if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
2102         if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
2103         if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
7fe908 2104
MC 2105         $domain_id = $this->insertQuery('../sites/form/web_domain.tform.php', $client_id, $params, 'sites:web_domain:on_after_insert');
1ca823 2106         if ($readonly === true)
T 2107             $app->db->query("UPDATE web_domain SET `sys_userid` = '1' WHERE domain_id = ".$domain_id);
7fe908 2108         return $domain_id;
MC 2109     }
2110
532ae5 2111     //* Update a record
L 2112     public function sites_web_domain_update($session_id, $client_id, $primary_id, $params)
7fe908 2113     {
532ae5 2114         if(!$this->checkPerm($session_id, 'sites_web_domain_update')) {
L 2115             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2116             return false;
2117         }
7fe908 2118
edf806 2119         //* Set a few defaults for nginx servers
T 2120         if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
2121         if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
2122         if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
2123         if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
7fe908 2124
MC 2125         $affected_rows = $this->updateQuery('../sites/form/web_domain.tform.php', $client_id, $primary_id, $params);
532ae5 2126         return $affected_rows;
L 2127     }
7fe908 2128
532ae5 2129     //* Delete a record
L 2130     public function sites_web_domain_delete($session_id, $primary_id)
7fe908 2131     {
532ae5 2132         if(!$this->checkPerm($session_id, 'sites_web_domain_delete')) {
L 2133             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2134             return false;
2135         }
7fe908 2136         $affected_rows = $this->deleteQuery('../sites/form/web_domain.tform.php', $primary_id);
532ae5 2137         return $affected_rows;
L 2138     }
7fe908 2139
cb1aa5 2140     // ----------------------------------------------------------------------------------------------------------
7fe908 2141
cb1aa5 2142     //* Get record details
M 2143     public function sites_web_vhost_subdomain_get($session_id, $primary_id)
7fe908 2144     {
cb1aa5 2145         global $app;
7fe908 2146
cb1aa5 2147         if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
M 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('../sites/form/web_vhost_subdomain.tform.php');
2153         return $app->remoting_lib->getDataRecord($primary_id);
2154     }
7fe908 2155
cb1aa5 2156     //* Add a record
M 2157     public function sites_web_vhost_subdomain_add($session_id, $client_id, $params)
2158     {
2159         global $app;
2160         if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
2161             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2162             return false;
2163         }
7fe908 2164
cb1aa5 2165         //* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
M 2166         if($params['document_root'] == '') $params['document_root'] = '-';
2167         if($params['system_user'] == '') $params['system_user'] = '-';
2168         if($params['system_group'] == '') $params['system_group'] = '-';
7fe908 2169
cb1aa5 2170         //* Set a few defaults for nginx servers
M 2171         if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
2172         if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
2173         if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
2174         if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
7fe908 2175
MC 2176         $domain_id = $this->insertQuery('../sites/form/web_vhost_subdomain.tform.php', $client_id, $params, 'sites:web_vhost_subdomain:on_after_insert');
2177         return $domain_id;
2178     }
2179
cb1aa5 2180     //* Update a record
M 2181     public function sites_web_vhost_subdomain_update($session_id, $client_id, $primary_id, $params)
7fe908 2182     {
cb1aa5 2183         if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
M 2184             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2185             return false;
2186         }
7fe908 2187
cb1aa5 2188         //* Set a few defaults for nginx servers
M 2189         if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
2190         if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
2191         if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
2192         if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
7fe908 2193
MC 2194         $affected_rows = $this->updateQuery('../sites/form/web_vhost_subdomain.tform.php', $client_id, $primary_id, $params, 'sites:web_vhost_subdomain:on_after_insert');
cb1aa5 2195         return $affected_rows;
M 2196     }
7fe908 2197
cb1aa5 2198     //* Delete a record
M 2199     public function sites_web_vhost_subdomain_delete($session_id, $primary_id)
7fe908 2200     {
cb1aa5 2201         if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
M 2202             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2203             return false;
2204         }
7fe908 2205         $affected_rows = $this->deleteQuery('../sites/form/web_vhost_subdomain.tform.php', $primary_id);
cb1aa5 2206         return $affected_rows;
M 2207     }
7fe908 2208
1ca823 2209     // -----------------------------------------------------------------------------------------------
7fe908 2210
532ae5 2211     //* Get record details
L 2212     public function sites_web_aliasdomain_get($session_id, $primary_id)
7fe908 2213     {
532ae5 2214         global $app;
7fe908 2215
532ae5 2216         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_get')) {
L 2217             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2218             return false;
2219         }
2220         $app->uses('remoting_lib');
2221         $app->remoting_lib->loadFormDef('../sites/form/web_aliasdomain.tform.php');
2222         return $app->remoting_lib->getDataRecord($primary_id);
2223     }
7fe908 2224
532ae5 2225     //* Add a record
L 2226     public function sites_web_aliasdomain_add($session_id, $client_id, $params)
7fe908 2227     {
532ae5 2228         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
L 2229             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2230             return false;
2231         }
7fe908 2232         return $this->insertQuery('../sites/form/web_aliasdomain.tform.php', $client_id, $params);
532ae5 2233     }
7fe908 2234
532ae5 2235     //* Update a record
L 2236     public function sites_web_aliasdomain_update($session_id, $client_id, $primary_id, $params)
7fe908 2237     {
532ae5 2238         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
L 2239             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2240             return false;
2241         }
7fe908 2242         $affected_rows = $this->updateQuery('../sites/form/web_aliasdomain.tform.php', $client_id, $primary_id, $params);
532ae5 2243         return $affected_rows;
L 2244     }
7fe908 2245
532ae5 2246     //* Delete a record
L 2247     public function sites_web_aliasdomain_delete($session_id, $primary_id)
7fe908 2248     {
532ae5 2249         if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
L 2250             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2251             return false;
2252         }
7fe908 2253         $affected_rows = $this->deleteQuery('../sites/form/web_aliasdomain.tform.php', $primary_id);
532ae5 2254         return $affected_rows;
L 2255     }
7fe908 2256
532ae5 2257     // ----------------------------------------------------------------------------------------------------------
7fe908 2258
532ae5 2259     //* Get record details
L 2260     public function sites_web_subdomain_get($session_id, $primary_id)
7fe908 2261     {
532ae5 2262         global $app;
7fe908 2263
532ae5 2264         if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
L 2265             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2266             return false;
2267         }
2268         $app->uses('remoting_lib');
2269         $app->remoting_lib->loadFormDef('../sites/form/web_subdomain.tform.php');
2270         return $app->remoting_lib->getDataRecord($primary_id);
2271     }
7fe908 2272
532ae5 2273     //* Add a record
L 2274     public function sites_web_subdomain_add($session_id, $client_id, $params)
7fe908 2275     {
532ae5 2276         if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
L 2277             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2278             return false;
2279         }
7fe908 2280         return $this->insertQuery('../sites/form/web_subdomain.tform.php', $client_id, $params);
532ae5 2281     }
7fe908 2282
532ae5 2283     //* Update a record
L 2284     public function sites_web_subdomain_update($session_id, $client_id, $primary_id, $params)
7fe908 2285     {
532ae5 2286         if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
L 2287             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2288             return false;
2289         }
7fe908 2290         $affected_rows = $this->updateQuery('../sites/form/web_subdomain.tform.php', $client_id, $primary_id, $params);
532ae5 2291         return $affected_rows;
L 2292     }
7fe908 2293
532ae5 2294     //* Delete a record
L 2295     public function sites_web_subdomain_delete($session_id, $primary_id)
7fe908 2296     {
532ae5 2297         if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
L 2298             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2299             return false;
2300         }
7fe908 2301         $affected_rows = $this->deleteQuery('../sites/form/web_subdomain.tform.php', $primary_id);
532ae5 2302         return $affected_rows;
L 2303     }
7fe908 2304
5712a6 2305     // ----------------------------------------------------------------------------------------------------------
7fe908 2306
5712a6 2307     //* Get record details
M 2308     public function sites_web_folder_get($session_id, $primary_id)
7fe908 2309     {
5712a6 2310         global $app;
7fe908 2311
5712a6 2312         if(!$this->checkPerm($session_id, 'sites_web_folder_get')) {
M 2313             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2314             return false;
2315         }
2316         $app->uses('remoting_lib');
2317         $app->remoting_lib->loadFormDef('../sites/form/web_folder.tform.php');
2318         return $app->remoting_lib->getDataRecord($primary_id);
2319     }
7fe908 2320
5712a6 2321     //* Add a record
M 2322     public function sites_web_folder_add($session_id, $client_id, $params)
7fe908 2323     {
5712a6 2324         if(!$this->checkPerm($session_id, 'sites_web_folder_add')) {
M 2325             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2326             return false;
2327         }
7fe908 2328         return $this->insertQuery('../sites/form/web_folder.tform.php', $client_id, $params);
5712a6 2329     }
7fe908 2330
5712a6 2331     //* Update a record
M 2332     public function sites_web_folder_update($session_id, $client_id, $primary_id, $params)
7fe908 2333     {
5712a6 2334         if(!$this->checkPerm($session_id, 'sites_web_folder_update')) {
M 2335             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2336             return false;
2337         }
7fe908 2338         $affected_rows = $this->updateQuery('../sites/form/web_folder.tform.php', $client_id, $primary_id, $params);
5712a6 2339         return $affected_rows;
M 2340     }
7fe908 2341
5712a6 2342     //* Delete a record
M 2343     public function sites_web_folder_delete($session_id, $primary_id)
7fe908 2344     {
5712a6 2345         global $app;
M 2346         if(!$this->checkPerm($session_id, 'sites_web_folder_delete')) {
2347             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2348             return false;
2349         }
7fe908 2350
MC 2351         // Delete all users that belong to this folder. - taken from web_folder_delete.php
65ea2e 2352         $records = $app->db->queryAllRecords("SELECT web_folder_user_id FROM web_folder_user WHERE web_folder_id = '".$app->functions->intval($primary_id)."'");
5712a6 2353         foreach($records as $rec) {
7fe908 2354             $this->deleteQuery('../sites/form/web_folder_user.tform.php', $rec['web_folder_user_id']);
5712a6 2355             //$app->db->datalogDelete('web_folder_user','web_folder_user_id',$rec['web_folder_user_id']);
M 2356         }
2357         unset($records);
7fe908 2358
MC 2359         $affected_rows = $this->deleteQuery('../sites/form/web_folder.tform.php', $primary_id);
5712a6 2360         return $affected_rows;
M 2361     }
7fe908 2362
5712a6 2363     // -----------------------------------------------------------------------------------------------
7fe908 2364
5712a6 2365     //* Get record details
M 2366     public function sites_web_folder_user_get($session_id, $primary_id)
7fe908 2367     {
5712a6 2368         global $app;
7fe908 2369
5712a6 2370         if(!$this->checkPerm($session_id, 'sites_web_folder_user_get')) {
M 2371             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2372             return false;
2373         }
2374         $app->uses('remoting_lib');
2375         $app->remoting_lib->loadFormDef('../sites/form/web_folder_user.tform.php');
2376         return $app->remoting_lib->getDataRecord($primary_id);
2377     }
7fe908 2378
5712a6 2379     //* Add a record
M 2380     public function sites_web_folder_user_add($session_id, $client_id, $params)
7fe908 2381     {
5712a6 2382         if(!$this->checkPerm($session_id, 'sites_web_folder_user_add')) {
M 2383             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2384             return false;
2385         }
7fe908 2386         return $this->insertQuery('../sites/form/web_folder_user.tform.php', $client_id, $params);
5712a6 2387     }
7fe908 2388
5712a6 2389     //* Update a record
M 2390     public function sites_web_folder_user_update($session_id, $client_id, $primary_id, $params)
7fe908 2391     {
5712a6 2392         if(!$this->checkPerm($session_id, 'sites_web_folder_user_update')) {
M 2393             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2394             return false;
2395         }
7fe908 2396         $affected_rows = $this->updateQuery('../sites/form/web_folder_user.tform.php', $client_id, $primary_id, $params);
5712a6 2397         return $affected_rows;
M 2398     }
7fe908 2399
5712a6 2400     //* Delete a record
M 2401     public function sites_web_folder_user_delete($session_id, $primary_id)
7fe908 2402     {
5712a6 2403         if(!$this->checkPerm($session_id, 'sites_web_folder_user_delete')) {
M 2404             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2405             return false;
2406         }
7fe908 2407         $affected_rows = $this->deleteQuery('../sites/form/web_folder_user.tform.php', $primary_id);
5712a6 2408         return $affected_rows;
M 2409     }
7fe908 2410
532ae5 2411     // -----------------------------------------------------------------------------------------------
7fe908 2412
1ca823 2413     //* Get record details
T 2414     public function domains_domain_get($session_id, $primary_id)
7fe908 2415     {
1ca823 2416         global $app;
7fe908 2417
1ca823 2418         if(!$this->checkPerm($session_id, 'domains_domain_get')) {
T 2419             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2420             return false;
2421         }
2422         $app->uses('remoting_lib');
6f1cca 2423         $app->remoting_lib->loadFormDef('../client/form/domain.tform.php');
1ca823 2424         return $app->remoting_lib->getDataRecord($primary_id);
T 2425     }
2426
2427     //* Add a record
2428     public function domains_domain_add($session_id, $client_id, $params)
7fe908 2429     {
1ca823 2430         if(!$this->checkPerm($session_id, 'domains_domain_add')) {
T 2431             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2432             return false;
2433         }
7fe908 2434         return $this->insertQuery('../client/form/domain.tform.php', $client_id, $params);
1ca823 2435     }
T 2436
2437     //* Delete a record
2438     public function domains_domain_delete($session_id, $primary_id)
7fe908 2439     {
1ca823 2440         if(!$this->checkPerm($session_id, 'domains_domain_delete')) {
T 2441             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2442             return false;
2443         }
7fe908 2444         $affected_rows = $this->deleteQuery('../client/form/domain.tform.php', $primary_id);
1ca823 2445         return $affected_rows;
T 2446     }
2447
7fe908 2448     // -----------------------------------------------------------------------------------------------
1ca823 2449
T 2450     public function domains_get_all_by_user($session_id, $group_id)
7fe908 2451     {
MC 2452         global $app;
1ca823 2453         if(!$this->checkPerm($session_id, 'domains_get_all_by_user')) {
7fe908 2454             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
MC 2455             return false;
1ca823 2456         }
7fe908 2457         $group_id = $app->functions->intval($group_id);
MC 2458         $sql = "SELECT domain_id, domain FROM domain WHERE sys_groupid  = $group_id ";
2459         $all = $app->db->queryAllRecords($sql);
2460         return $all;
1ca823 2461     }
7fe908 2462
MC 2463
532ae5 2464     // DNS Function --------------------------------------------------------------------------------------------------
7fe908 2465
b67344 2466     //* Create Zone with Template
T 2467     public function dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email)
7fe908 2468     {
MC 2469         global $app, $conf;
b67344 2470         if(!$this->checkPerm($session_id, 'dns_templatezone_add')) {
7fe908 2471             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
MC 2472             return false;
b67344 2473         }
T 2474
65ea2e 2475         $client = $app->db->queryOneRecord("SELECT default_dnsserver FROM client WHERE client_id = ".$app->functions->intval($client_id));
b67344 2476         $server_id = $client["default_dnsserver"];
T 2477         $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = '$template_id'");
7fe908 2478         $fields = explode(',', $template_record['fields']);
b67344 2479         $tform_def_file = "../../web/dns/form/dns_soa.tform.php";
T 2480         $app->uses('tform');
2481         $app->tform->loadFormDef($tform_def_file);
2482         $app->uses('tpl,validate_dns');
7fe908 2483
b67344 2484         //* replace template placeholders
T 2485         $tpl_content = $template_record['template'];
7fe908 2486         if($domain != '') $tpl_content = str_replace('{DOMAIN}', $domain, $tpl_content);
MC 2487         if($ip != '') $tpl_content = str_replace('{IP}', $ip, $tpl_content);
2488         if($ns1 != '') $tpl_content = str_replace('{NS1}', $ns1, $tpl_content);
2489         if($ns2 != '') $tpl_content = str_replace('{NS2}', $ns2, $tpl_content);
2490         if($email != '') $tpl_content = str_replace('{EMAIL}', $email, $tpl_content);
2491
b67344 2492         //* Parse the template
7fe908 2493         $tpl_rows = explode("\n", $tpl_content);
b67344 2494         $section = '';
T 2495         $vars = array();
2496         $dns_rr = array();
2497         foreach($tpl_rows as $row) {
2498             $row = trim($row);
7fe908 2499             if(substr($row, 0, 1) == '[') {
b67344 2500                 if($row == '[ZONE]') {
T 2501                     $section = 'zone';
2502                 } elseif($row == '[DNS_RECORDS]') {
2503                     $section = 'dns_records';
2504                 } else {
2505                     die('Unknown section type');
2506                 }
2507             } else {
2508                 if($row != '') {
2509                     //* Handle zone section
2510                     if($section == 'zone') {
7fe908 2511                         $parts = explode('=', $row);
b67344 2512                         $key = trim($parts[0]);
T 2513                         $val = trim($parts[1]);
2514                         if($key != '') $vars[$key] = $val;
2515                     }
2516                     //* Handle DNS Record rows
2517                     if($section == 'dns_records') {
7fe908 2518                         $parts = explode('|', $row);
b67344 2519                         $dns_rr[] = array(
T 2520                             'name' => $app->db->quote($parts[1]),
2521                             'type' => $app->db->quote($parts[0]),
2522                             'data' => $app->db->quote($parts[2]),
2523                             'aux'  => $app->db->quote($parts[3]),
2524                             'ttl'  => $app->db->quote($parts[4])
2525                         );
2526                     }
2527                 }
7fe908 2528             }
b67344 2529         } // end foreach
7fe908 2530
b67344 2531         if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').'<br />';
T 2532         if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').'<br />';
2533         if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').'<br />';
2534         if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').'<br />';
2535         if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').'<br />';
2536         if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').'<br />';
2537         if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').'<br />';
7fe908 2538         if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').'<br />';
MC 2539
b67344 2540         if($error == '') {
T 2541             // Insert the soa record
65ea2e 2542             $tmp = $app->db->queryOneRecord("SELECT userid,default_group FROM sys_user WHERE client_id = ".$app->functions->intval($client_id));
b67344 2543             $sys_userid = $tmp['userid'];
T 2544             $sys_groupid = $tmp['default_group'];
2545             unset($tmp);
2546             $origin = $app->db->quote($vars['origin']);
2547             $ns = $app->db->quote($vars['ns']);
7fe908 2548             $mbox = $app->db->quote(str_replace('@', '.', $vars['mbox']));
b67344 2549             $refresh = $app->db->quote($vars['refresh']);
T 2550             $retry = $app->db->quote($vars['retry']);
2551             $expire = $app->db->quote($vars['expire']);
2552             $minimum = $app->db->quote($vars['minimum']);
2553             $ttl = $app->db->quote($vars['ttl']);
2554             $xfer = $app->db->quote($vars['xfer']);
2555             $also_notify = $app->db->quote($vars['also_notify']);
2556             $update_acl = $app->db->quote($vars['update_acl']);
7fe908 2557             $serial = $app->validate_dns->increase_serial(0);
MC 2558             $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
b67344 2559             ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '$xfer', '$also_notify', '$update_acl')";
7fe908 2560             $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
b67344 2561             // Insert the dns_rr records
T 2562             if(is_array($dns_rr) && $dns_soa_id > 0) {
2563                 foreach($dns_rr as $rr) {
7fe908 2564                     $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
b67344 2565                     ('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')";
T 2566                     $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
2567                 }
2568             }
2569             exit;
2570         } else {
2571             $this->server->fault('permission_denied', $error);
2572         }
2573     }
7fe908 2574
MC 2575
532ae5 2576     //* Get record details
L 2577     public function dns_zone_get($session_id, $primary_id)
7fe908 2578     {
532ae5 2579         global $app;
7fe908 2580
532ae5 2581         if(!$this->checkPerm($session_id, 'dns_zone_get')) {
L 2582             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2583             return false;
2584         }
2585         $app->uses('remoting_lib');
2586         $app->remoting_lib->loadFormDef('../dns/form/dns_soa.tform.php');
2587         return $app->remoting_lib->getDataRecord($primary_id);
2588     }
854444 2589
7fe908 2590     //* Get record id by origin
MC 2591     public function dns_zone_get_id($session_id, $origin)
2592     {
2593         global $app;
2594
2595         if(!$this->checkPerm($session_id, 'dns_zone_get_id')) {
2596             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2597             return false;
2598         }
2599
2600         if(!preg_match('/^[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/i', $origin)){
2601             $this->server->fault('no_domain_found', 'Invalid domain name.');
2602             return false;
2603         }
2604
2605         $rec = $app->db->queryOneRecord("SELECT id FROM dns_soa WHERE origin like '".$origin."%'");
2606         if(isset($rec['id'])) {
2607             return $app->functions->intval($rec['id']);
2608         } else {
2609             $this->server->fault('no_domain_found', 'There is no domain ID with informed domain name.');
2610             return false;
2611         }
2612     }
2613
532ae5 2614     //* Add a record
L 2615     public function dns_zone_add($session_id, $client_id, $params)
7fe908 2616     {
532ae5 2617         if(!$this->checkPerm($session_id, 'dns_zone_add')) {
L 2618             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2619             return false;
2620         }
7fe908 2621         return $this->insertQuery('../dns/form/dns_soa.tform.php', $client_id, $params);
532ae5 2622     }
7fe908 2623
532ae5 2624     //* Update a record
L 2625     public function dns_zone_update($session_id, $client_id, $primary_id, $params)
7fe908 2626     {
532ae5 2627         if(!$this->checkPerm($session_id, 'dns_zone_update')) {
L 2628             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2629             return false;
2630         }
7fe908 2631         $affected_rows = $this->updateQuery('../dns/form/dns_soa.tform.php', $client_id, $primary_id, $params);
532ae5 2632         return $affected_rows;
L 2633     }
7fe908 2634
532ae5 2635     //* Delete a record
L 2636     public function dns_zone_delete($session_id, $primary_id)
7fe908 2637     {
532ae5 2638         if(!$this->checkPerm($session_id, 'dns_zone_delete')) {
L 2639             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2640             return false;
2641         }
7fe908 2642         $affected_rows = $this->deleteQuery('../dns/form/dns_soa.tform.php', $primary_id);
532ae5 2643         return $affected_rows;
L 2644     }
7fe908 2645
532ae5 2646     // ----------------------------------------------------------------------------------------------------------------
7fe908 2647
532ae5 2648     //* Get record details
L 2649     public function dns_aaaa_get($session_id, $primary_id)
7fe908 2650     {
532ae5 2651         global $app;
7fe908 2652
532ae5 2653         if(!$this->checkPerm($session_id, 'dns_aaaa_get')) {
L 2654             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2655             return false;
2656         }
2657         $app->uses('remoting_lib');
2658         $app->remoting_lib->loadFormDef('../dns/form/dns_aaaa.tform.php');
2659         return $app->remoting_lib->getDataRecord($primary_id);
2660     }
7fe908 2661
532ae5 2662     //* Add a record
L 2663     public function dns_aaaa_add($session_id, $client_id, $params)
7fe908 2664     {
532ae5 2665         if(!$this->checkPerm($session_id, 'dns_aaaa_add')) {
L 2666             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2667             return false;
2668         }
7fe908 2669         return $this->insertQuery('../dns/form/dns_aaaa.tform.php', $client_id, $params);
532ae5 2670     }
7fe908 2671
532ae5 2672     //* Update a record
L 2673     public function dns_aaaa_update($session_id, $client_id, $primary_id, $params)
7fe908 2674     {
532ae5 2675         if(!$this->checkPerm($session_id, 'dns_aaaa_update')) {
L 2676             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2677             return false;
2678         }
7fe908 2679         $affected_rows = $this->updateQuery('../dns/form/dns_aaaa.tform.php', $client_id, $primary_id, $params);
532ae5 2680         return $affected_rows;
L 2681     }
7fe908 2682
532ae5 2683     //* Delete a record
L 2684     public function dns_aaaa_delete($session_id, $primary_id)
7fe908 2685     {
532ae5 2686         if(!$this->checkPerm($session_id, 'dns_aaaa_delete')) {
L 2687             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2688             return false;
2689         }
7fe908 2690         $affected_rows = $this->deleteQuery('../dns/form/dns_aaaa.tform.php', $primary_id);
532ae5 2691         return $affected_rows;
L 2692     }
2693
2694     // ----------------------------------------------------------------------------------------------------------------
7fe908 2695
532ae5 2696     //* Get record details
L 2697     public function dns_a_get($session_id, $primary_id)
7fe908 2698     {
532ae5 2699         global $app;
7fe908 2700
532ae5 2701         if(!$this->checkPerm($session_id, 'dns_a_get')) {
L 2702             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2703             return false;
2704         }
2705         $app->uses('remoting_lib');
2706         $app->remoting_lib->loadFormDef('../dns/form/dns_a.tform.php');
2707         return $app->remoting_lib->getDataRecord($primary_id);
2708     }
7fe908 2709
532ae5 2710     //* Add a record
L 2711     public function dns_a_add($session_id, $client_id, $params)
7fe908 2712     {
532ae5 2713         if(!$this->checkPerm($session_id, 'dns_a_add')) {
L 2714             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2715             return false;
2716         }
7fe908 2717         return $this->insertQuery('../dns/form/dns_a.tform.php', $client_id, $params);
532ae5 2718     }
7fe908 2719
532ae5 2720     //* Update a record
L 2721     public function dns_a_update($session_id, $client_id, $primary_id, $params)
7fe908 2722     {
532ae5 2723         if(!$this->checkPerm($session_id, 'dns_a_update')) {
L 2724             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2725             return false;
2726         }
7fe908 2727         $affected_rows = $this->updateQuery('../dns/form/dns_a.tform.php', $client_id, $primary_id, $params);
532ae5 2728         return $affected_rows;
L 2729     }
7fe908 2730
532ae5 2731     //* Delete a record
L 2732     public function dns_a_delete($session_id, $primary_id)
7fe908 2733     {
532ae5 2734         if(!$this->checkPerm($session_id, 'dns_a_delete')) {
L 2735             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2736             return false;
2737         }
7fe908 2738         $affected_rows = $this->deleteQuery('../dns/form/dns_a.tform.php', $primary_id);
532ae5 2739         return $affected_rows;
L 2740     }
7fe908 2741
532ae5 2742     // ----------------------------------------------------------------------------------------------------------------
7fe908 2743
532ae5 2744     //* Get record details
L 2745     public function dns_alias_get($session_id, $primary_id)
7fe908 2746     {
532ae5 2747         global $app;
7fe908 2748
532ae5 2749         if(!$this->checkPerm($session_id, 'dns_alias_get')) {
L 2750             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2751             return false;
2752         }
2753         $app->uses('remoting_lib');
2754         $app->remoting_lib->loadFormDef('../dns/form/dns_alias.tform.php');
2755         return $app->remoting_lib->getDataRecord($primary_id);
2756     }
7fe908 2757
532ae5 2758     //* Add a record
L 2759     public function dns_alias_add($session_id, $client_id, $params)
7fe908 2760     {
532ae5 2761         if(!$this->checkPerm($session_id, 'dns_alias_add')) {
L 2762             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2763             return false;
2764         }
7fe908 2765         return $this->insertQuery('../dns/form/dns_alias.tform.php', $client_id, $params);
532ae5 2766     }
7fe908 2767
532ae5 2768     //* Update a record
L 2769     public function dns_alias_update($session_id, $client_id, $primary_id, $params)
7fe908 2770     {
532ae5 2771         if(!$this->checkPerm($session_id, 'dns_alias_update')) {
L 2772             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2773             return false;
2774         }
7fe908 2775         $affected_rows = $this->updateQuery('../dns/form/dns_alias.tform.php', $client_id, $primary_id, $params);
532ae5 2776         return $affected_rows;
L 2777     }
7fe908 2778
532ae5 2779     //* Delete a record
L 2780     public function dns_alias_delete($session_id, $primary_id)
7fe908 2781     {
532ae5 2782         if(!$this->checkPerm($session_id, 'dns_alias_delete')) {
L 2783             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2784             return false;
2785         }
7fe908 2786         $affected_rows = $this->deleteQuery('../dns/form/dns_alias.tform.php', $primary_id);
532ae5 2787         return $affected_rows;
L 2788     }
7fe908 2789
532ae5 2790     // ----------------------------------------------------------------------------------------------------------------
7fe908 2791
532ae5 2792     //* Get record details
L 2793     public function dns_cname_get($session_id, $primary_id)
7fe908 2794     {
532ae5 2795         global $app;
7fe908 2796
532ae5 2797         if(!$this->checkPerm($session_id, 'dns_cname_get')) {
L 2798             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2799             return false;
2800         }
2801         $app->uses('remoting_lib');
2802         $app->remoting_lib->loadFormDef('../dns/form/dns_cname.tform.php');
2803         return $app->remoting_lib->getDataRecord($primary_id);
2804     }
7fe908 2805
532ae5 2806     //* Add a record
L 2807     public function dns_cname_add($session_id, $client_id, $params)
7fe908 2808     {
532ae5 2809         if(!$this->checkPerm($session_id, 'dns_cname_add')) {
L 2810             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2811             return false;
2812         }
7fe908 2813         return $this->insertQuery('../dns/form/dns_cname.tform.php', $client_id, $params);
532ae5 2814     }
7fe908 2815
532ae5 2816     //* Update a record
L 2817     public function dns_cname_update($session_id, $client_id, $primary_id, $params)
7fe908 2818     {
532ae5 2819         if(!$this->checkPerm($session_id, 'dns_cname_update')) {
L 2820             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2821             return false;
2822         }
7fe908 2823         $affected_rows = $this->updateQuery('../dns/form/dns_cname.tform.php', $client_id, $primary_id, $params);
532ae5 2824         return $affected_rows;
L 2825     }
7fe908 2826
532ae5 2827     //* Delete a record
L 2828     public function dns_cname_delete($session_id, $primary_id)
7fe908 2829     {
532ae5 2830         if(!$this->checkPerm($session_id, 'dns_cname_delete')) {
L 2831             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2832             return false;
2833         }
7fe908 2834         $affected_rows = $this->deleteQuery('../dns/form/dns_cname.tform.php', $primary_id);
532ae5 2835         return $affected_rows;
L 2836     }
7fe908 2837
532ae5 2838     // ----------------------------------------------------------------------------------------------------------------
7fe908 2839
532ae5 2840     //* Get record details
L 2841     public function dns_hinfo_get($session_id, $primary_id)
7fe908 2842     {
532ae5 2843         global $app;
7fe908 2844
532ae5 2845         if(!$this->checkPerm($session_id, 'dns_hinfo_get')) {
L 2846             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2847             return false;
2848         }
2849         $app->uses('remoting_lib');
2850         $app->remoting_lib->loadFormDef('../dns/form/dns_hinfo.tform.php');
2851         return $app->remoting_lib->getDataRecord($primary_id);
2852     }
7fe908 2853
532ae5 2854     //* Add a record
L 2855     public function dns_hinfo_add($session_id, $client_id, $params)
7fe908 2856     {
532ae5 2857         if(!$this->checkPerm($session_id, 'dns_hinfo_add')) {
L 2858             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2859             return false;
2860         }
7fe908 2861         return $this->insertQuery('../dns/form/dns_hinfo.tform.php', $client_id, $params);
532ae5 2862     }
7fe908 2863
532ae5 2864     //* Update a record
L 2865     public function dns_hinfo_update($session_id, $client_id, $primary_id, $params)
7fe908 2866     {
532ae5 2867         if(!$this->checkPerm($session_id, 'dns_hinfo_update')) {
L 2868             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2869             return false;
2870         }
7fe908 2871         $affected_rows = $this->updateQuery('../dns/form/dns_hinfo.tform.php', $client_id, $primary_id, $params);
532ae5 2872         return $affected_rows;
L 2873     }
7fe908 2874
532ae5 2875     //* Delete a record
L 2876     public function dns_hinfo_delete($session_id, $primary_id)
7fe908 2877     {
532ae5 2878         if(!$this->checkPerm($session_id, 'dns_hinfo_delete')) {
L 2879             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2880             return false;
2881         }
7fe908 2882         $affected_rows = $this->deleteQuery('../dns/form/dns_hinfo.tform.php', $primary_id);
532ae5 2883         return $affected_rows;
L 2884     }
7fe908 2885
532ae5 2886     // ----------------------------------------------------------------------------------------------------------------
7fe908 2887
532ae5 2888     //* Get record details
L 2889     public function dns_mx_get($session_id, $primary_id)
7fe908 2890     {
532ae5 2891         global $app;
7fe908 2892
532ae5 2893         if(!$this->checkPerm($session_id, 'dns_mx_get')) {
L 2894             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2895             return false;
2896         }
2897         $app->uses('remoting_lib');
2898         $app->remoting_lib->loadFormDef('../dns/form/dns_mx.tform.php');
2899         return $app->remoting_lib->getDataRecord($primary_id);
2900     }
7fe908 2901
532ae5 2902     //* Add a record
L 2903     public function dns_mx_add($session_id, $client_id, $params)
7fe908 2904     {
532ae5 2905         if(!$this->checkPerm($session_id, 'dns_mx_add')) {
L 2906             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2907             return false;
2908         }
7fe908 2909         return $this->insertQuery('../dns/form/dns_mx.tform.php', $client_id, $params);
532ae5 2910     }
7fe908 2911
532ae5 2912     //* Update a record
L 2913     public function dns_mx_update($session_id, $client_id, $primary_id, $params)
7fe908 2914     {
532ae5 2915         if(!$this->checkPerm($session_id, 'dns_mx_update')) {
L 2916             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2917             return false;
2918         }
7fe908 2919         $affected_rows = $this->updateQuery('../dns/form/dns_mx.tform.php', $client_id, $primary_id, $params);
532ae5 2920         return $affected_rows;
L 2921     }
7fe908 2922
532ae5 2923     //* Delete a record
L 2924     public function dns_mx_delete($session_id, $primary_id)
7fe908 2925     {
532ae5 2926         if(!$this->checkPerm($session_id, 'dns_mx_delete')) {
L 2927             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2928             return false;
2929         }
7fe908 2930         $affected_rows = $this->deleteQuery('../dns/form/dns_mx.tform.php', $primary_id);
532ae5 2931         return $affected_rows;
L 2932     }
7fe908 2933
532ae5 2934     // ----------------------------------------------------------------------------------------------------------------
7fe908 2935
532ae5 2936     //* Get record details
L 2937     public function dns_ns_get($session_id, $primary_id)
7fe908 2938     {
532ae5 2939         global $app;
7fe908 2940
532ae5 2941         if(!$this->checkPerm($session_id, 'dns_ns_get')) {
L 2942             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2943             return false;
2944         }
2945         $app->uses('remoting_lib');
2946         $app->remoting_lib->loadFormDef('../dns/form/dns_ns.tform.php');
2947         return $app->remoting_lib->getDataRecord($primary_id);
2948     }
7fe908 2949
532ae5 2950     //* Add a record
L 2951     public function dns_ns_add($session_id, $client_id, $params)
7fe908 2952     {
532ae5 2953         if(!$this->checkPerm($session_id, 'dns_ns_add')) {
L 2954             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2955             return false;
2956         }
7fe908 2957         return $this->insertQuery('../dns/form/dns_ns.tform.php', $client_id, $params);
532ae5 2958     }
7fe908 2959
532ae5 2960     //* Update a record
L 2961     public function dns_ns_update($session_id, $client_id, $primary_id, $params)
7fe908 2962     {
532ae5 2963         if(!$this->checkPerm($session_id, 'dns_ns_update')) {
L 2964             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2965             return false;
2966         }
7fe908 2967         $affected_rows = $this->updateQuery('../dns/form/dns_ns.tform.php', $client_id, $primary_id, $params);
532ae5 2968         return $affected_rows;
L 2969     }
7fe908 2970
532ae5 2971     //* Delete a record
L 2972     public function dns_ns_delete($session_id, $primary_id)
7fe908 2973     {
532ae5 2974         if(!$this->checkPerm($session_id, 'dns_ns_delete')) {
L 2975             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2976             return false;
2977         }
7fe908 2978         $affected_rows = $this->deleteQuery('../dns/form/dns_ns.tform.php', $primary_id);
532ae5 2979         return $affected_rows;
L 2980     }
7fe908 2981
532ae5 2982     // ----------------------------------------------------------------------------------------------------------------
7fe908 2983
532ae5 2984     //* Get record details
L 2985     public function dns_ptr_get($session_id, $primary_id)
7fe908 2986     {
532ae5 2987         global $app;
7fe908 2988
532ae5 2989         if(!$this->checkPerm($session_id, 'dns_ptr_get')) {
L 2990             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2991             return false;
2992         }
2993         $app->uses('remoting_lib');
2994         $app->remoting_lib->loadFormDef('../dns/form/dns_ptr.tform.php');
2995         return $app->remoting_lib->getDataRecord($primary_id);
2996     }
7fe908 2997
532ae5 2998     //* Add a record
L 2999     public function dns_ptr_add($session_id, $client_id, $params)
7fe908 3000     {
532ae5 3001         if(!$this->checkPerm($session_id, 'dns_ptr_add')) {
L 3002             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3003             return false;
3004         }
7fe908 3005         return $this->insertQuery('../dns/form/dns_ptr.tform.php', $client_id, $params);
532ae5 3006     }
7fe908 3007
532ae5 3008     //* Update a record
L 3009     public function dns_ptr_update($session_id, $client_id, $primary_id, $params)
7fe908 3010     {
532ae5 3011         if(!$this->checkPerm($session_id, 'dns_ptr_update')) {
L 3012             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3013             return false;
3014         }
7fe908 3015         $affected_rows = $this->updateQuery('../dns/form/dns_ptr.tform.php', $client_id, $primary_id, $params);
532ae5 3016         return $affected_rows;
L 3017     }
7fe908 3018
532ae5 3019     //* Delete a record
L 3020     public function dns_ptr_delete($session_id, $primary_id)
7fe908 3021     {
532ae5 3022         if(!$this->checkPerm($session_id, 'dns_ptr_delete')) {
L 3023             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3024             return false;
3025         }
7fe908 3026         $affected_rows = $this->deleteQuery('../dns/form/dns_ptr.tform.php', $primary_id);
532ae5 3027         return $affected_rows;
L 3028     }
7fe908 3029
532ae5 3030     // ----------------------------------------------------------------------------------------------------------------
7fe908 3031
532ae5 3032     //* Get record details
L 3033     public function dns_rp_get($session_id, $primary_id)
7fe908 3034     {
532ae5 3035         global $app;
7fe908 3036
532ae5 3037         if(!$this->checkPerm($session_id, 'dns_rp_get')) {
L 3038             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3039             return false;
3040         }
3041         $app->uses('remoting_lib');
3042         $app->remoting_lib->loadFormDef('../dns/form/dns_rp.tform.php');
3043         return $app->remoting_lib->getDataRecord($primary_id);
3044     }
7fe908 3045
532ae5 3046     //* Add a record
L 3047     public function dns_rp_add($session_id, $client_id, $params)
7fe908 3048     {
532ae5 3049         if(!$this->checkPerm($session_id, 'dns_rp_add')) {
L 3050             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3051             return false;
3052         }
7fe908 3053         return $this->insertQuery('../dns/form/dns_rp.tform.php', $client_id, $params);
532ae5 3054     }
7fe908 3055
532ae5 3056     //* Update a record
L 3057     public function dns_rp_update($session_id, $client_id, $primary_id, $params)
7fe908 3058     {
532ae5 3059         if(!$this->checkPerm($session_id, 'dns_rp_update')) {
L 3060             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3061             return false;
3062         }
7fe908 3063         $affected_rows = $this->updateQuery('../dns/form/dns_rp.tform.php', $client_id, $primary_id, $params);
532ae5 3064         return $affected_rows;
L 3065     }
7fe908 3066
532ae5 3067     //* Delete a record
L 3068     public function dns_rp_delete($session_id, $primary_id)
7fe908 3069     {
532ae5 3070         if(!$this->checkPerm($session_id, 'dns_rp_delete')) {
L 3071             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3072             return false;
3073         }
7fe908 3074         $affected_rows = $this->deleteQuery('../dns/form/dns_rp.tform.php', $primary_id);
532ae5 3075         return $affected_rows;
L 3076     }
7fe908 3077
532ae5 3078     // ----------------------------------------------------------------------------------------------------------------
7fe908 3079
532ae5 3080     //* Get record details
L 3081     public function dns_srv_get($session_id, $primary_id)
7fe908 3082     {
532ae5 3083         global $app;
7fe908 3084
532ae5 3085         if(!$this->checkPerm($session_id, 'dns_srv_get')) {
L 3086             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3087             return false;
3088         }
3089         $app->uses('remoting_lib');
3090         $app->remoting_lib->loadFormDef('../dns/form/dns_srv.tform.php');
3091         return $app->remoting_lib->getDataRecord($primary_id);
3092     }
7fe908 3093
532ae5 3094     //* Add a record
L 3095     public function dns_srv_add($session_id, $client_id, $params)
7fe908 3096     {
532ae5 3097         if(!$this->checkPerm($session_id, 'dns_srv_add')) {
L 3098             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3099             return false;
3100         }
7fe908 3101         return $this->insertQuery('../dns/form/dns_srv.tform.php', $client_id, $params);
532ae5 3102     }
7fe908 3103
532ae5 3104     //* Update a record
L 3105     public function dns_srv_update($session_id, $client_id, $primary_id, $params)
7fe908 3106     {
532ae5 3107         if(!$this->checkPerm($session_id, 'dns_srv_update')) {
L 3108             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3109             return false;
3110         }
7fe908 3111         $affected_rows = $this->updateQuery('../dns/form/dns_srv.tform.php', $client_id, $primary_id, $params);
532ae5 3112         return $affected_rows;
L 3113     }
7fe908 3114
532ae5 3115     //* Delete a record
L 3116     public function dns_srv_delete($session_id, $primary_id)
7fe908 3117     {
532ae5 3118         if(!$this->checkPerm($session_id, 'dns_srv_delete')) {
L 3119             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3120             return false;
3121         }
7fe908 3122         $affected_rows = $this->deleteQuery('../dns/form/dns_srv.tform.php', $primary_id);
532ae5 3123         return $affected_rows;
L 3124     }
7fe908 3125
532ae5 3126     // ----------------------------------------------------------------------------------------------------------------
7fe908 3127
532ae5 3128     //* Get record details
L 3129     public function dns_txt_get($session_id, $primary_id)
7fe908 3130     {
532ae5 3131         global $app;
7fe908 3132
532ae5 3133         if(!$this->checkPerm($session_id, 'dns_txt_get')) {
L 3134             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3135             return false;
3136         }
3137         $app->uses('remoting_lib');
3138         $app->remoting_lib->loadFormDef('../dns/form/dns_txt.tform.php');
3139         return $app->remoting_lib->getDataRecord($primary_id);
3140     }
7fe908 3141
532ae5 3142     //* Add a record
L 3143     public function dns_txt_add($session_id, $client_id, $params)
7fe908 3144     {
532ae5 3145         if(!$this->checkPerm($session_id, 'dns_txt_add')) {
L 3146             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3147             return false;
3148         }
7fe908 3149         return $this->insertQuery('../dns/form/dns_txt.tform.php', $client_id, $params);
532ae5 3150     }
7fe908 3151
532ae5 3152     //* Update a record
L 3153     public function dns_txt_update($session_id, $client_id, $primary_id, $params)
7fe908 3154     {
532ae5 3155         if(!$this->checkPerm($session_id, 'dns_txt_update')) {
L 3156             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3157             return false;
3158         }
7fe908 3159         $affected_rows = $this->updateQuery('../dns/form/dns_txt.tform.php', $client_id, $primary_id, $params);
532ae5 3160         return $affected_rows;
L 3161     }
7fe908 3162
532ae5 3163     //* Delete a record
L 3164     public function dns_txt_delete($session_id, $primary_id)
7fe908 3165     {
532ae5 3166         if(!$this->checkPerm($session_id, 'dns_txt_delete')) {
L 3167             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3168             return false;
3169         }
7fe908 3170         $affected_rows = $this->deleteQuery('../dns/form/dns_txt.tform.php', $primary_id);
532ae5 3171         return $affected_rows;
L 3172     }
7fe908 3173
MC 3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
532ae5 3184
L 3185
031054 3186     //** protected functions -----------------------------------------------------------------------------------
7fe908 3187
MC 3188
532ae5 3189
L 3190
031054 3191     protected function klientadd($formdef_file, $reseller_id, $params)
7fe908 3192     {
ecb6b3 3193         global $app;
532ae5 3194         $app->uses('remoting_lib');
7fe908 3195
532ae5 3196         //* Load the form definition
L 3197         $app->remoting_lib->loadFormDef($formdef_file);
7fe908 3198
532ae5 3199         //* load the user profile of the client
L 3200         $app->remoting_lib->loadUserProfile($reseller_id);
7fe908 3201
532ae5 3202         //* Get the SQL query
7fe908 3203         $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);
MC 3204
8cf78b 3205         //* Check if no system user with that username exists
T 3206         $username = $app->db->quote($params["username"]);
355efb 3207         $tmp = $app->db->queryOneRecord("SELECT count(userid) as number FROM sys_user WHERE username = '$username'");
8cf78b 3208         if($tmp['number'] > 0) $app->remoting_lib->errorMessage .= "Duplicate username<br />";
7fe908 3209
355efb 3210         //* Stop on error while preparing the sql query
532ae5 3211         if($app->remoting_lib->errorMessage != '') {
L 3212             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
3213             return false;
3214         }
7fe908 3215
355efb 3216         //* Execute the SQL query
T 3217         $app->db->query($sql);
c8f203 3218         $insert_id = $app->db->insertID();
7fe908 3219
MC 3220
355efb 3221         //* Stop on error while executing the sql query
T 3222         if($app->remoting_lib->errorMessage != '') {
3223             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
3224             return false;
3225         }
7fe908 3226
c8f203 3227         $this->id = $insert_id;
T 3228         $this->dataRecord = $params;
7fe908 3229
bfc771 3230         $app->plugin->raiseEvent('client:' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . ':on_after_insert', $this);
7fe908 3231
c8f203 3232         /*
532ae5 3233         if($app->db->errorMessage != '') {
L 3234             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
3235             return false;
3236         }
c8f203 3237         */
7fe908 3238
MC 3239         /* copied from the client_edit php */
54f158 3240         exec('ssh-keygen -t rsa -C '.$username.'-rsa-key-'.time().' -f /tmp/id_rsa -N ""');
M 3241         $app->db->query("UPDATE client SET created_at = ".time().", id_rsa = '".$app->db->quote(@file_get_contents('/tmp/id_rsa'))."', ssh_rsa = '".$app->db->quote(@file_get_contents('/tmp/id_rsa.pub'))."' WHERE client_id = ".$this->id);
3242         exec('rm -f /tmp/id_rsa /tmp/id_rsa.pub');
7fe908 3243
MC 3244
3245
532ae5 3246         //$app->uses('tform');
L 3247         //* Save changes to Datalog
3248         if($app->remoting_lib->formDef["db_history"] == 'yes') {
3249             $new_rec = $app->remoting_lib->getDataRecord($insert_id);
7fe908 3250             $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec);
MC 3251             $app->remoting_lib->ispconfig_sysuser_add($params, $insert_id);
532ae5 3252
7fe908 3253             if($reseller_id) {
MC 3254                 $client_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = ".$insert_id);
3255                 $reseller_user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE client_id = ".$reseller_id);
3256                 $app->auth->add_group_to_user($reseller_user['userid'], $client_group['groupid']);
3257                 $app->db->query("UPDATE client SET parent_client_id = ".$reseller_id." WHERE client_id = ".$insert_id);
3258             }
532ae5 3259
L 3260         }
3261         return $insert_id;
3262     }
3263
7fe908 3264     protected function insertQuery($formdef_file, $client_id, $params, $event_identifier = '')
MC 3265     {
3266         $sql = $this->insertQueryPrepare($formdef_file, $client_id, $params);
3267         if($sql !== false) return $this->insertQueryExecute($sql, $params, $event_identifier);
3268         else return false;
3269     }
ecb6b3 3270
M 3271     protected function insertQueryPrepare($formdef_file, $client_id, $params)
7fe908 3272     {
ecb6b3 3273         global $app;
7fe908 3274
532ae5 3275         $app->uses('remoting_lib');
7fe908 3276
532ae5 3277         //* load the user profile of the client
L 3278         $app->remoting_lib->loadUserProfile($client_id);
7fe908 3279
532ae5 3280         //* Load the form definition
L 3281         $app->remoting_lib->loadFormDef($formdef_file);
7fe908 3282
532ae5 3283         //* Get the SQL query
7fe908 3284         $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);
532ae5 3285         if($app->remoting_lib->errorMessage != '') {
L 3286             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
3287             return false;
3288         }
864ba9 3289         $app->log('Executed insertQueryPrepare', LOGLEVEL_DEBUG);
7fe908 3290         return $sql;
ecb6b3 3291     }
7fe908 3292
MC 3293     protected function insertQueryExecute($sql, $params, $event_identifier = '')
3294     {
ecb6b3 3295         global $app;
7fe908 3296
ecb6b3 3297         $app->uses('remoting_lib');
7fe908 3298
532ae5 3299         $app->db->query($sql);
7fe908 3300
532ae5 3301         if($app->db->errorMessage != '') {
L 3302             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
3303             return false;
3304         }
7fe908 3305
532ae5 3306         $insert_id = $app->db->insertID();
7fe908 3307
532ae5 3308         // set a few values for compatibility with tform actions, mostly used by plugins
L 3309         $this->id = $insert_id;
3310         $this->dataRecord = $params;
864ba9 3311         $app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
7fe908 3312         if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this);
MC 3313
532ae5 3314         //$app->uses('tform');
L 3315         //* Save changes to Datalog
3316         if($app->remoting_lib->formDef["db_history"] == 'yes') {
3317             $new_rec = $app->remoting_lib->getDataRecord($insert_id);
7fe908 3318             $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec);
MC 3319         }
532ae5 3320         return $insert_id;
L 3321     }
7fe908 3322
031054 3323     protected function updateQuery($formdef_file, $client_id, $primary_id, $params, $event_identifier = '')
7fe908 3324     {
ecb6b3 3325         global $app;
7fe908 3326
ecb6b3 3327         $sql = $this->updateQueryPrepare($formdef_file, $client_id, $primary_id, $params);
7fe908 3328         if($sql !== false) return $this->updateQueryExecute($sql, $primary_id, $params, $event_identifier);
MC 3329         else return false;
ecb6b3 3330     }
7fe908 3331
ecb6b3 3332     protected function updateQueryPrepare($formdef_file, $client_id, $primary_id, $params)
7fe908 3333     {
532ae5 3334         global $app;
7fe908 3335
532ae5 3336         $app->uses('remoting_lib');
7fe908 3337
532ae5 3338         //* load the user profile of the client
L 3339         $app->remoting_lib->loadUserProfile($client_id);
7fe908 3340
532ae5 3341         //* Load the form definition
L 3342         $app->remoting_lib->loadFormDef($formdef_file);
7fe908 3343
532ae5 3344         //* Get the SQL query
7fe908 3345         $sql = $app->remoting_lib->getSQL($params, 'UPDATE', $primary_id);
26c0fc 3346         // $this->server->fault('debug', $sql);
532ae5 3347         if($app->remoting_lib->errorMessage != '') {
L 3348             $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
3349             return false;
3350         }
7fe908 3351
MC 3352         return $sql;
ecb6b3 3353     }
M 3354
3355     protected function updateQueryExecute($sql, $primary_id, $params, $event_identifier = '')
7fe908 3356     {
ecb6b3 3357         global $app;
7fe908 3358
ecb6b3 3359         $app->uses('remoting_lib');
7fe908 3360
532ae5 3361         $old_rec = $app->remoting_lib->getDataRecord($primary_id);
7fe908 3362
532ae5 3363         // set a few values for compatibility with tform actions, mostly used by plugins
L 3364         $this->oldDataRecord = $old_rec;
3365         $this->id = $primary_id;
3366         $this->dataRecord = $params;
7fe908 3367
532ae5 3368         $app->db->query($sql);
7fe908 3369
532ae5 3370         if($app->db->errorMessage != '') {
L 3371             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
3372             return false;
3373         }
7fe908 3374
532ae5 3375         $affected_rows = $app->db->affectedRows();
753da5 3376         $app->log('Executed updateQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
7fe908 3377
MC 3378         if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this);
3379
532ae5 3380         //* Save changes to Datalog
L 3381         if($app->remoting_lib->formDef["db_history"] == 'yes') {
3382             $new_rec = $app->remoting_lib->getDataRecord($primary_id);
7fe908 3383             $app->remoting_lib->datalogSave('UPDATE', $primary_id, $old_rec, $new_rec);
532ae5 3384         }
7fe908 3385
532ae5 3386         return $affected_rows;
L 3387     }
ecb6b3 3388
031054 3389     protected function deleteQuery($formdef_file, $primary_id, $event_identifier = '')
7fe908 3390     {
532ae5 3391         global $app;
7fe908 3392
532ae5 3393         $app->uses('remoting_lib');
7fe908 3394
532ae5 3395         //* load the user profile of the client
L 3396         $app->remoting_lib->loadUserProfile(0);
7fe908 3397
532ae5 3398         //* Load the form definition
L 3399         $app->remoting_lib->loadFormDef($formdef_file);
7fe908 3400
532ae5 3401         $old_rec = $app->remoting_lib->getDataRecord($primary_id);
7fe908 3402
532ae5 3403         // set a few values for compatibility with tform actions, mostly used by plugins
L 3404         $this->oldDataRecord = $old_rec;
3405         $this->id = $primary_id;
355efb 3406         $this->dataRecord = $old_rec;
28ade6 3407         $app->log('Executed deleteQuery, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
355efb 3408         //$this->dataRecord = $params;
7fe908 3409
532ae5 3410         //* Get the SQL query
L 3411         $sql = $app->remoting_lib->getDeleteSQL($primary_id);
355efb 3412         $app->db->errorMessage = '';
532ae5 3413         $app->db->query($sql);
355efb 3414         $affected_rows = $app->db->affectedRows();
7fe908 3415
532ae5 3416         if($app->db->errorMessage != '') {
L 3417             $this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
3418             return false;
3419         }
7fe908 3420
355efb 3421         if($event_identifier != '') {
7fe908 3422             $app->plugin->raiseEvent($event_identifier, $this);
355efb 3423         }
7fe908 3424
532ae5 3425         //* Save changes to Datalog
L 3426         if($app->remoting_lib->formDef["db_history"] == 'yes') {
7fe908 3427             $app->remoting_lib->datalogSave('DELETE', $primary_id, $old_rec, array());
532ae5 3428         }
7fe908 3429
MC 3430
532ae5 3431         return $affected_rows;
L 3432     }
7fe908 3433
MC 3434
031054 3435     protected function checkPerm($session_id, $function_name)
7fe908 3436     {
MC 3437         global $app;
3438         $dobre=array();
3439         $session = $this->getSession($session_id);
3440         if(!$session){
3441             return false;
3442         }
3443
3444         $dobre= str_replace(';', ',', $session['remote_functions']);
ecf891 3445         $check = in_array($function_name, explode(',', $dobre) );
N 3446         if(!$check) {
7fe908 3447             $app->log("REMOTE-LIB DENY: ".$session_id ." /". $function_name, LOGLEVEL_WARN);
ecf891 3448         }
N 3449         return $check;
532ae5 3450     }
7fe908 3451
MC 3452
031054 3453     protected function getSession($session_id)
7fe908 3454     {
532ae5 3455         global $app;
7fe908 3456
532ae5 3457         if(empty($session_id)) {
7fe908 3458             $this->server->fault('session_id_empty', 'The SessionID is empty.');
532ae5 3459             return false;
L 3460         }
7fe908 3461
532ae5 3462         $session_id = $app->db->quote($session_id);
7fe908 3463
532ae5 3464         $now = time();
L 3465         $sql = "SELECT * FROM remote_session WHERE remote_session = '$session_id' AND tstamp >= $now";
3466         $session = $app->db->queryOneRecord($sql);
3467         if($session['remote_userid'] > 0) {
3468             return $session;
3469         } else {
7fe908 3470             $this->server->fault('session_does_not_exist', 'The Session is expired or does not exist.');
532ae5 3471             return false;
L 3472         }
3473     }
7fe908 3474
532ae5 3475     //---
7fe908 3476
MC 3477
532ae5 3478     /**
L 3479      * Gets sites by $sys_userid & $sys_groupid
7fe908 3480      * @param int  session id
MC 3481      * @param int  user id
3482      * @param array list of groups
3483      * @return mixed array with sites by user
3484      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
532ae5 3485      */
L 3486     public function client_get_sites_by_user($session_id, $sys_userid, $sys_groupid) {
7fe908 3487         global $app;
MC 3488         if(!$this->checkPerm($session_id, 'client_get_sites_by_user')) {
3489             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3490             return false;
3491         }
3492         $sys_userid  = $app->functions->intval($sys_userid);
3493         $sys_groupid = explode(',', $sys_groupid);
3494         $new_group = array();
3495         foreach($sys_groupid as $group_id) {
65ea2e 3496             $new_group[] = $app->functions->intval( $group_id);
7fe908 3497         }
MC 3498         $group_list = implode(',', $new_group);
532ae5 3499         $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'";
7fe908 3500         $result = $app->db->queryAllRecords($sql);
MC 3501         if(isset($result)) {
532ae5 3502             return $result;
7fe908 3503         } else {
532ae5 3504             $this->server->fault('no_client_found', 'There is no site for this user');
L 3505             return false;
7fe908 3506         }
MC 3507     }
3508
3509
3510
3511     /**
3512      * Change domains status
3513      * @param int  session id
3514      * @param int  site id
3515      * @param string active or inactive string
3516      * @return mixed false if error
3517      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
532ae5 3518      */
7fe908 3519     public function sites_web_domain_set_status($session_id, $primary_id, $status) {
MC 3520         global $app;
3521         if(!$this->checkPerm($session_id, 'sites_web_domain_set_status')) {
3522             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3523             return false;
3524         }
df1d52 3525         $app->uses('remoting_lib');
MC 3526         
7fe908 3527         if(in_array($status, array('active', 'inactive'))) {
MC 3528             if ($status == 'active') {
3529                 $status = 'y';
3530             } else {
3531                 $status = 'n';
3532             }
df1d52 3533             $app->remoting_lib->loadFormDef('../sites/form/web_domain.tform.php');
MC 3534             $params = $app->remoting_lib->getDataRecord($primary_id);
3535             $params['active'] = $status;
3536             
e6e9e7 3537             $affected_rows = $this->updateQuery('../sites/form/web_domain.tform.php', 0, $primary_id, $params);
df1d52 3538             return $affected_rows;
7fe908 3539         } else {
532ae5 3540             $this->server->fault('status_undefined', 'The status is not available');
L 3541             return false;
7fe908 3542         }
532ae5 3543     }
7fe908 3544
MC 3545
3546
532ae5 3547     /**
L 3548      * Get sys_user information by username
7fe908 3549      * @param int  session id
MC 3550      * @param string user's name
3551      * @return mixed false if error
3552      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
532ae5 3553      */
L 3554     public function client_get_by_username($session_id, $username) {
7fe908 3555         global $app;
MC 3556         if(!$this->checkPerm($session_id, 'client_get_by_username')) {
532ae5 3557             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
L 3558             return false;
7fe908 3559         }
MC 3560         $username = $app->db->quote($username);
3561         $rec = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE username = '".$username."'");
3562         if (isset($rec)) {
532ae5 3563             return $rec;
7fe908 3564         } else {
532ae5 3565             $this->server->fault('no_client_found', 'There is no user account for this user name.');
L 3566             return false;
7fe908 3567         }
ecf891 3568     }
532ae5 3569
7fe908 3570     /**
MC 3571      * Get All client_id's from database
3572      * @param int session_id
3573      * @return Array of all client_id's
3574      */
3575     public function client_get_all($session_id) {
3576         global $app;
3577         if(!$this->checkPerm($session_id, 'client_get_all')) {
532ae5 3578             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
7fe908 3579             return false;
MC 3580         }
3581         $result = $app->db->queryAllRecords("SELECT client_id FROM client WHERE 1");
3582         if(!$result) {
3583             return false;
3584         }
3585         foreach( $result as $record) {
3586             $rarrary[] = $record['client_id'];
3587         }
3588         return $rarrary;
3589     }
3590
3591     /**
3592      * Changes client password
3593      *
3594      * @param int  session id
3595      * @param int  client id
3596      * @param string new password
3597      * @return bool true if success
3598      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
3599      *
3600      */
3601     public function client_change_password($session_id, $client_id, $new_password) {
3602         global $app;
3603
3604         if(!$this->checkPerm($session_id, 'client_change_password')) {
3605             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3606             return false;
3607         }
3608         $client_id = $app->functions->intval($client_id);
3609         $client = $app->db->queryOneRecord("SELECT client_id FROM client WHERE client_id = ".$client_id);
3610         if($client['client_id'] > 0) {
3611             $new_password = $app->db->quote($new_password);
3612             $sql = "UPDATE client SET password = md5('".($new_password)."')     WHERE client_id = ".$client_id;
3613             $app->db->query($sql);
3614             $sql = "UPDATE sys_user SET passwort = md5('".($new_password)."')     WHERE client_id = ".$client_id;
3615             $app->db->query($sql);
3616             return true;
3617         } else {
532ae5 3618             $this->server->fault('no_client_found', 'There is no user account for this client_id');
L 3619             return false;
7fe908 3620         }
MC 3621     }
9e0f11 3622
532ae5 3623     /**
7fe908 3624      * Fetch the mail_domain record for the provided domain.
MC 3625      * @param int session_id
3626      * @param string the fully qualified domain (or subdomain)
3627      * @return array array of arrays corresponding to the mail_domain table's records
3628      * @author till, benlake
3629      */
3630     public function mail_domain_get_by_domain($session_id, $domain) {
3631         global $app;
3632         if(!$this->checkPerm($session_id, 'mail_domain_get_by_domain')) {
532ae5 3633             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
L 3634             return false;
3635         }
7fe908 3636         if (!empty($domain)) {
MC 3637             $domain       = $app->db->quote($domain);
3638             $sql            = "SELECT * FROM mail_domain WHERE domain = '$domain'";
3639             $result         = $app->db->queryAllRecords($sql);
3640             return          $result;
3641         }
3642         return false;
532ae5 3643     }
7fe908 3644
532ae5 3645     /**
7fe908 3646      * Get a list of functions
MC 3647      * @param  int  session id
3648      * @return mixed array of the available functions
3649      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
3650      */
3651     public function get_function_list($session_id)
3652     {
3653         if(!$this->checkPerm($session_id, 'get_function_list')) {
3654             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3655             return false;
3656         }
3657         return get_class_methods($this);
3658     }
3659
3660
3661
3662     /**
3663      * Get all databases by user
3664      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
3665      */
3666     public function sites_database_get_all_by_user($session_id, $client_id)
3667     {
3668         global $app;
3669         if(!$this->checkPerm($session_id, 'sites_database_get')) {
3670             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3671             return false;
3672         }
3673         $client_id = $app->functions->intval($client_id);
3674         $sql = "SELECT d.database_id, d.database_name, d.database_user_id, d.database_ro_user_id, du.database_user, du.database_password FROM web_database d LEFT JOIN web_database_user du ON (du.database_user_id = d.database_user_id) INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = $client_id";
3675         $all = $app->db->queryAllRecords($sql);
3676         return $all;
3677     }
3678
3679
3680
3681     /**
3682      *  Get all client templates
3683      * @param  int  session id
3684      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
532ae5 3685      */
L 3686     public function client_templates_get_all($session_id) {
3687         global $app;
3688         if(!$this->checkPerm($session_id, 'client_templates_get_all')) {
3689             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
7fe908 3690             return false;
MC 3691         }
3692         $sql    = "SELECT * FROM client_template";
3693         $result = $app->db->queryAllRecords($sql);
3694         return $result;
3695     }
3696
3697
3698
159828 3699     /**
7fe908 3700      * Get all DNS zone by user
MC 3701      *@author Julio Montoya <gugli100@gmail.com> BeezNest 2010
3702      */
3703     public function dns_zone_get_by_user($session_id, $client_id, $server_id) {
3704         global $app;
3705         if(!$this->checkPerm($session_id, 'dns_zone_get')) {
3706             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3707             return false;
3708         }
3709         if (!empty($client_id) && !empty($server_id)) {
3710             $server_id      = $app->functions->intval($server_id);
3711             $client_id      = $app->functions->intval($client_id);
3712             $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";
3713             $result         = $app->db->queryAllRecords($sql);
3714             return          $result;
3715         }
3716         return false;
3717     }
3718
3719
3720
3721     /**
3722      *  Get all dns records for a zone
3723      * @param  int  session id
3724      * @param  int  dns zone id
3725      * @author Sebastian Mogilowski <sebastian@mogilowski.net> 2011
159828 3726      */
S 3727     public function dns_rr_get_all_by_zone($session_id, $zone_id) {
3728         global $app;
3729         if(!$this->checkPerm($session_id, 'dns_zone_get')) {
7fe908 3730             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
MC 3731             return false;
159828 3732         }
7fe908 3733         $sql    = "SELECT * FROM dns_rr WHERE zone = ".$app->functions->intval($zone_id);;
159828 3734         $result = $app->db->queryAllRecords($sql);
7fe908 3735         return $result;
MC 3736     }
159828 3737
532ae5 3738     /**
7fe908 3739      * Changes DNS zone status
MC 3740      * @param  int  session id
3741      * @param int  dns soa id
3742      * @param string status active or inactive string
3743      * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
532ae5 3744      */
7fe908 3745     public function dns_zone_set_status($session_id, $primary_id, $status) {
MC 3746         global $app;
3747         if(!$this->checkPerm($session_id, 'dns_zone_set_status')) {
3748             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3749             return false;
3750         }
3751         if(in_array($status, array('active', 'inactive'))) {
3752             if ($status == 'active') {
3753                 $status = 'Y';
3754             } else {
3755                 $status = 'N';
3756             }
3757             $sql = "UPDATE dns_soa SET active = '$status' WHERE id = ".$app->functions->intval($primary_id);
3758             $app->db->query($sql);
3759             $result = $app->db->affectedRows();
3760             return $result;
3761         } else {
532ae5 3762             $this->server->fault('status_undefined', 'The status is not available');
L 3763             return false;
7fe908 3764         }
MC 3765     }
3766
3767     public function mail_domain_set_status($session_id, $primary_id, $status) {
3768         global $app;
3769         if(!$this->checkPerm($session_id, 'mail_domain_set_status')) {
3770             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3771             return false;
3772         }
3773         if(in_array($status, array('active', 'inactive'))) {
3774             if ($status == 'active') {
3775                 $status = 'y';
3776             } else {
3777                 $status = 'n';
3778             }
3779             $sql = "UPDATE mail_domain SET active = '$status' WHERE domain_id = ".$app->functions->intval($primary_id);
3780             $app->db->query($sql);
3781             $result = $app->db->affectedRows();
3782             return $result;
3783         } else {
532ae5 3784             $this->server->fault('status_undefined', 'The status is not available');
L 3785             return false;
7fe908 3786         }
MC 3787     }
3788
077c27 3789     //* Functions for virtual machine management
7fe908 3790
077c27 3791     //* Get OpenVZ OStemplate details
T 3792     public function openvz_ostemplate_get($session_id, $ostemplate_id)
7fe908 3793     {
077c27 3794         global $app;
7fe908 3795
077c27 3796         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3797             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3798             return false;
3799         }
3800         $app->uses('remoting_lib');
3801         $app->remoting_lib->loadFormDef('../vm/form/openvz_ostemplate.tform.php');
3802         return $app->remoting_lib->getDataRecord($ostemplate_id);
3803     }
7fe908 3804
077c27 3805     //* Add a openvz ostemplate record
T 3806     public function openvz_ostemplate_add($session_id, $client_id, $params)
7fe908 3807     {
077c27 3808         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3809             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3810             return false;
3811         }
7fe908 3812         return $this->insertQuery('../vm/form/openvz_ostemplate.tform.php', $client_id, $params);
077c27 3813     }
7fe908 3814
077c27 3815     //* Update openvz ostemplate record
T 3816     public function openvz_ostemplate_update($session_id, $client_id, $ostemplate_id, $params)
7fe908 3817     {
077c27 3818         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3819             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3820             return false;
3821         }
7fe908 3822         $affected_rows = $this->updateQuery('../vm/form/openvz_ostemplate.tform.php', $client_id, $ostemplate_id, $params);
077c27 3823         return $affected_rows;
T 3824     }
7fe908 3825
077c27 3826     //* Delete openvz ostemplate record
T 3827     public function openvz_ostemplate_delete($session_id, $ostemplate_id)
7fe908 3828     {
077c27 3829         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3830             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3831             return false;
3832         }
7fe908 3833         $affected_rows = $this->deleteQuery('../vm/form/openvz_ostemplate.tform.php', $ostemplate_id);
077c27 3834         return $affected_rows;
T 3835     }
7fe908 3836
077c27 3837     //* Get OpenVZ template details
T 3838     public function openvz_template_get($session_id, $template_id)
7fe908 3839     {
077c27 3840         global $app;
7fe908 3841
077c27 3842         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3843             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3844             return false;
3845         }
3846         $app->uses('remoting_lib');
3847         $app->remoting_lib->loadFormDef('../vm/form/openvz_template.tform.php');
3848         return $app->remoting_lib->getDataRecord($template_id);
3849     }
7fe908 3850
077c27 3851     //* Add a openvz template record
T 3852     public function openvz_template_add($session_id, $client_id, $params)
7fe908 3853     {
077c27 3854         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3855             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3856             return false;
3857         }
7fe908 3858         return $this->insertQuery('../vm/form/openvz_template.tform.php', $client_id, $params);
077c27 3859     }
7fe908 3860
077c27 3861     //* Update openvz template record
T 3862     public function openvz_template_update($session_id, $client_id, $template_id, $params)
7fe908 3863     {
077c27 3864         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3865             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3866             return false;
3867         }
7fe908 3868         $affected_rows = $this->updateQuery('../vm/form/openvz_template.tform.php', $client_id, $template_id, $params);
077c27 3869         return $affected_rows;
T 3870     }
7fe908 3871
077c27 3872     //* Delete openvz template record
T 3873     public function openvz_template_delete($session_id, $template_id)
7fe908 3874     {
077c27 3875         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3876             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3877             return false;
3878         }
7fe908 3879         $affected_rows = $this->deleteQuery('../vm/form/openvz_template.tform.php', $template_id);
077c27 3880         return $affected_rows;
T 3881     }
7fe908 3882
077c27 3883     //* Get OpenVZ ip details
T 3884     public function openvz_ip_get($session_id, $ip_id)
7fe908 3885     {
077c27 3886         global $app;
7fe908 3887
077c27 3888         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3889             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3890             return false;
3891         }
3892         $app->uses('remoting_lib');
3893         $app->remoting_lib->loadFormDef('../vm/form/openvz_ip.tform.php');
3894         return $app->remoting_lib->getDataRecord($ip_id);
3895     }
7fe908 3896
077c27 3897     //* Get OpenVZ a free IP address
T 3898     public function openvz_get_free_ip($session_id, $server_id = 0)
7fe908 3899     {
077c27 3900         global $app;
7fe908 3901
077c27 3902         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3903             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3904             return false;
3905         }
65ea2e 3906         $server_id = $app->functions->intval($server_id);
7fe908 3907
077c27 3908         if($server_id > 0) {
T 3909             $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");
3910         } else {
3911             $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");
3912         }
7fe908 3913
077c27 3914         if(count($tmp) > 0) {
T 3915             return $tmp;
3916         } else {
3917             $this->server->fault('no_free_ip', 'There is no free IP available.');
3918         }
3919     }
7fe908 3920
077c27 3921     //* Add a openvz ip record
T 3922     public function openvz_ip_add($session_id, $client_id, $params)
7fe908 3923     {
077c27 3924         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3925             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3926             return false;
3927         }
7fe908 3928         return $this->insertQuery('../vm/form/openvz_ip.tform.php', $client_id, $params);
077c27 3929     }
7fe908 3930
077c27 3931     //* Update openvz ip record
T 3932     public function openvz_ip_update($session_id, $client_id, $ip_id, $params)
7fe908 3933     {
077c27 3934         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3935             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3936             return false;
3937         }
7fe908 3938         $affected_rows = $this->updateQuery('../vm/form/openvz_ip.tform.php', $client_id, $ip_id, $params);
077c27 3939         return $affected_rows;
T 3940     }
7fe908 3941
077c27 3942     //* Delete openvz ip record
T 3943     public function openvz_ip_delete($session_id, $ip_id)
7fe908 3944     {
077c27 3945         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3946             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3947             return false;
3948         }
7fe908 3949         $affected_rows = $this->deleteQuery('../vm/form/openvz_ip.tform.php', $ip_id);
077c27 3950         return $affected_rows;
T 3951     }
7fe908 3952
077c27 3953     //* Get OpenVZ vm details
T 3954     public function openvz_vm_get($session_id, $vm_id)
7fe908 3955     {
077c27 3956         global $app;
7fe908 3957
077c27 3958         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3959             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3960             return false;
3961         }
3962         $app->uses('remoting_lib');
3963         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
3964         return $app->remoting_lib->getDataRecord($vm_id);
3965     }
7fe908 3966
c161ea 3967     //* Get OpenVZ list
T 3968     public function openvz_vm_get_by_client($session_id, $client_id)
7fe908 3969     {
c161ea 3970         global $app;
7fe908 3971
c161ea 3972         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3973             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3974             return false;
3975         }
7fe908 3976
c161ea 3977         if (!empty($client_id)) {
7fe908 3978             $client_id      = $app->functions->intval($client_id);
MC 3979             $tmp    = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
3980             $sql            = "SELECT * FROM openvz_vm WHERE sys_groupid = ".$app->functions->intval($tmp['groupid']);
3981             $result         = $app->db->queryAllRecords($sql);
3982             return          $result;
3983         }
3984         return false;
c161ea 3985     }
7fe908 3986
077c27 3987     //* Add a openvz vm record
T 3988     public function openvz_vm_add($session_id, $client_id, $params)
7fe908 3989     {
077c27 3990         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 3991             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
3992             return false;
3993         }
7fe908 3994         return $this->insertQuery('../vm/form/openvz_vm.tform.php', $client_id, $params);
077c27 3995     }
7fe908 3996
077c27 3997     //* Add a openvz vm record from template
T 3998     public function openvz_vm_add_from_template($session_id, $client_id, $ostemplate_id, $template_id, $override_params = array())
7fe908 3999     {
077c27 4000         global $app;
7fe908 4001
077c27 4002         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 4003             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
4004             return false;
4005         }
7fe908 4006
MC 4007
65ea2e 4008         $template_id = $app->functions->intval($template_id);
M 4009         $ostemplate_id = $app->functions->intval($ostemplate_id);
7fe908 4010
077c27 4011         //* Verify parameters
T 4012         if($template_id == 0) {
4013             $this->server->fault('template_id_error', 'Template ID must be > 0.');
4014             return false;
4015         }
4016         if($ostemplate_id == 0) {
4017             $this->server->fault('ostemplate_id_error', 'OSTemplate ID must be > 0.');
4018             return false;
4019         }
7fe908 4020
077c27 4021         // Verify if template and ostemplate exist
T 4022         $tmp = $app->db->queryOneRecord("SELECT template_id FROM openvz_template WHERE template_id = $template_id");
4023         if(!is_array($tmp)) {
4024             $this->server->fault('template_id_error', 'Template does not exist.');
4025             return false;
4026         }
4027         $tmp = $app->db->queryOneRecord("SELECT ostemplate_id FROM openvz_ostemplate WHERE ostemplate_id = $ostemplate_id");
4028         if(!is_array($tmp)) {
4029             $this->server->fault('ostemplate_id_error', 'OSTemplate does not exist.');
4030             return false;
4031         }
7fe908 4032
077c27 4033         //* Get the template
T 4034         $vtpl = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = $template_id");
7fe908 4035
077c27 4036         //* Get the IP address and server_id
T 4037         if($override_params['server_id'] > 0) {
4038             $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");
4039         } else {
4040             $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");
4041         }
4042         if(!is_array($vmip)) {
4043             $this->server->fault('vm_ip_error', 'Unable to get a free VM IP.');
4044             return false;
4045         }
7fe908 4046
077c27 4047         //* Build the $params array
T 4048         $params = array();
4049         $params['server_id'] = $vmip['server_id'];
4050         $params['ostemplate_id'] = $ostemplate_id;
4051         $params['template_id'] = $template_id;
4052         $params['ip_address'] = $vmip['ip_address'];
4053         $params['hostname'] = (isset($override_params['hostname']))?$override_params['hostname']:$vtpl['hostname'];
4054         $params['vm_password'] = (isset($override_params['vm_password']))?$override_params['vm_password']:$app->auth->get_random_password(10);
4055         $params['start_boot'] = (isset($override_params['start_boot']))?$override_params['start_boot']:'y';
4056         $params['active'] = (isset($override_params['active']))?$override_params['active']:'y';
4057         $params['active_until_date'] = (isset($override_params['active_until_date']))?$override_params['active_until_date']:'0000-00-00';
4058         $params['description'] = (isset($override_params['description']))?$override_params['description']:'';
7fe908 4059
MC 4060         //* The next params get filled with pseudo values, as the get replaced
077c27 4061         //* by the openvz event plugin anyway with values from the template
T 4062         $params['veid'] = 1;
4063         $params['diskspace'] = 1;
4064         $params['ram'] = 1;
4065         $params['ram_burst'] = 1;
4066         $params['cpu_units'] = 1;
4067         $params['cpu_num'] = 1;
4068         $params['cpu_limit'] = 1;
4069         $params['io_priority'] = 1;
4070         $params['nameserver'] = '8.8.8.8 8.8.4.4';
4071         $params['create_dns'] = 'n';
4072         $params['capability'] = '';
7fe908 4073
MC 4074         return $this->insertQuery('../vm/form/openvz_vm.tform.php', $client_id, $params, 'vm:openvz_vm:on_after_insert');
077c27 4075     }
7fe908 4076
077c27 4077     //* Update openvz vm record
T 4078     public function openvz_vm_update($session_id, $client_id, $vm_id, $params)
7fe908 4079     {
077c27 4080         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 4081             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
4082             return false;
4083         }
7fe908 4084         $affected_rows = $this->updateQuery('../vm/form/openvz_vm.tform.php', $client_id, $vm_id, $params, 'vm:openvz_vm:on_after_update');
077c27 4085         return $affected_rows;
T 4086     }
7fe908 4087
077c27 4088     //* Delete openvz vm record
T 4089     public function openvz_vm_delete($session_id, $vm_id)
7fe908 4090     {
077c27 4091         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 4092             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
4093             return false;
4094         }
7fe908 4095         $affected_rows = $this->deleteQuery('../vm/form/openvz_vm.tform.php', $vm_id, 'vm:openvz_vm:on_after_delete');
077c27 4096         return $affected_rows;
T 4097     }
7fe908 4098
6882ab 4099     //* Start VM
T 4100     public function openvz_vm_start($session_id, $vm_id)
7fe908 4101     {
6882ab 4102         global $app;
7fe908 4103
6882ab 4104         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 4105             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
4106             return false;
4107         }
7fe908 4108
6882ab 4109         $app->uses('remoting_lib');
T 4110         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
4111         $vm = $app->remoting_lib->getDataRecord($vm_id);
7fe908 4112
6882ab 4113         if(!is_array($vm)) {
T 4114             $this->server->fault('action_pending', 'No VM with this ID available.');
4115             return false;
4116         }
7fe908 4117
6882ab 4118         if($vm['active'] == 'n') {
T 4119             $this->server->fault('action_pending', 'VM is not in active state.');
4120             return false;
4121         }
7fe908 4122
6882ab 4123         $action = 'openvz_start_vm';
7fe908 4124
MC 4125         $tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
4126                 WHERE server_id = '".$vm['server_id']."'
6882ab 4127                 AND action_type = '$action'
T 4128                 AND action_param = '".$vm['veid']."'
4129                 AND action_state = 'pending'");
7fe908 4130
6882ab 4131         if($tmp['actions'] > 0) {
T 4132             $this->server->fault('action_pending', 'There is already a action pending for this VM.');
4133             return false;
4134         } else {
4135             $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
7fe908 4136                 "VALUES (".
MC 4137                 (int)$vm['server_id'] . ", ".
4138                 time() . ", ".
4139                 "'".$action."', ".
4140                 $vm['veid'].", ".
4141                 "'pending', ".
4142                 "''".
4143                 ")";
6882ab 4144             $app->db->query($sql);
T 4145         }
4146     }
7fe908 4147
6882ab 4148     //* Stop VM
T 4149     public function openvz_vm_stop($session_id, $vm_id)
7fe908 4150     {
6882ab 4151         global $app;
7fe908 4152
6882ab 4153         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 4154             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
4155             return false;
4156         }
7fe908 4157
6882ab 4158         $app->uses('remoting_lib');
T 4159         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
4160         $vm = $app->remoting_lib->getDataRecord($vm_id);
7fe908 4161
6882ab 4162         if(!is_array($vm)) {
T 4163             $this->server->fault('action_pending', 'No VM with this ID available.');
4164             return false;
4165         }
7fe908 4166
6882ab 4167         if($vm['active'] == 'n') {
T 4168             $this->server->fault('action_pending', 'VM is not in active state.');
4169             return false;
4170         }
7fe908 4171
6882ab 4172         $action = 'openvz_stop_vm';
7fe908 4173
MC 4174         $tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
4175                 WHERE server_id = '".$vm['server_id']."'
6882ab 4176                 AND action_type = '$action'
T 4177                 AND action_param = '".$vm['veid']."'
4178                 AND action_state = 'pending'");
7fe908 4179
6882ab 4180         if($tmp['actions'] > 0) {
T 4181             $this->server->fault('action_pending', 'There is already a action pending for this VM.');
4182             return false;
4183         } else {
4184             $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
7fe908 4185                 "VALUES (".
MC 4186                 (int)$vm['server_id'] . ", ".
4187                 time() . ", ".
4188                 "'".$action."', ".
4189                 $vm['veid'].", ".
4190                 "'pending', ".
4191                 "''".
4192                 ")";
6882ab 4193             $app->db->query($sql);
T 4194         }
4195     }
7fe908 4196
6882ab 4197     //* Restart VM
T 4198     public function openvz_vm_restart($session_id, $vm_id)
7fe908 4199     {
6882ab 4200         global $app;
7fe908 4201
6882ab 4202         if(!$this->checkPerm($session_id, 'vm_openvz')) {
T 4203             $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
4204             return false;
4205         }
7fe908 4206
6882ab 4207         $app->uses('remoting_lib');
T 4208         $app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
4209         $vm = $app->remoting_lib->getDataRecord($vm_id);
7fe908 4210
6882ab 4211         if(!is_array($vm)) {
T 4212             $this->server->fault('action_pending', 'No VM with this ID available.');
4213             return false;
4214         }
7fe908 4215
6882ab 4216         if($vm['active'] == 'n') {
T 4217             $this->server->fault('action_pending', 'VM is not in active state.');
4218             return false;
4219         }
7fe908 4220
6882ab 4221         $action = 'openvz_restart_vm';
7fe908 4222
MC 4223         $tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
4224                 WHERE server_id = '".$vm['server_id']."'
6882ab 4225                 AND action_type = '$action'
T 4226                 AND action_param = '".$vm['veid']."'
4227                 AND action_state = 'pending'");
7fe908 4228
6882ab 4229         if($tmp['actions'] > 0) {
T 4230             $this->server->fault('action_pending', 'There is already a action pending for this VM.');
4231             return false;
4232         } else {
4233             $sql =  "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
7fe908 4234                 "VALUES (".
MC 4235                 (int)$vm['server_id'] . ", ".
4236                 time() . ", ".
4237                 "'".$action."', ".
4238                 $vm['veid'].", ".
4239                 "'pending', ".
4240                 "''".
4241                 ")";
6882ab 4242             $app->db->query($sql);
T 4243         }
4244     }
7fe908 4245
MC 4246
4247
4248
532ae5 4249 }
7fe908 4250
ecf891 4251 ?>