Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
<?php
 
/*
Copyright (c) 2007 - 2013, Till Brehm, projektfarm Gmbh
All rights reserved.
 
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
 
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
--UPDATED 08.2009--
Full SOAP support for ISPConfig 3.1.4 b
Updated by Arkadiusz Roch & Artur Edelman
Copyright (c) Tri-Plex technology
 
--UPDATED 08.2013--
Migrated into new remote classes system
by Marius Cramer <m.cramer@pixcept.de>
 
*/
 
class remoting_dns extends remoting {
    // DNS Function --------------------------------------------------------------------------------------------------
 
    //* Create Zone with Template
    public function dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email)
    {
        global $app, $conf;
        if(!$this->checkPerm($session_id, 'dns_templatezone_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
 
        $client = $app->db->queryOneRecord("SELECT default_dnsserver FROM client WHERE client_id = ?", $client_id);
        $server_id = $client["default_dnsserver"];
        $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $template_id);
        $fields = explode(',', $template_record['fields']);
        $tform_def_file = "../../web/dns/form/dns_soa.tform.php";
        $app->uses('tform');
        $app->tform->loadFormDef($tform_def_file);
        $app->uses('tpl,validate_dns');
 
        //* replace template placeholders
        $tpl_content = $template_record['template'];
        if($domain != '') $tpl_content = str_replace('{DOMAIN}', $domain, $tpl_content);
        if($ip != '') $tpl_content = str_replace('{IP}', $ip, $tpl_content);
        if($ns1 != '') $tpl_content = str_replace('{NS1}', $ns1, $tpl_content);
        if($ns2 != '') $tpl_content = str_replace('{NS2}', $ns2, $tpl_content);
        if($email != '') $tpl_content = str_replace('{EMAIL}', $email, $tpl_content);
 
        //* Parse the template
        $tpl_rows = explode("\n", $tpl_content);
        $section = '';
        $vars = array();
        $dns_rr = array();
        foreach($tpl_rows as $row) {
            $row = trim($row);
            if(substr($row, 0, 1) == '[') {
                if($row == '[ZONE]') {
                    $section = 'zone';
                } elseif($row == '[DNS_RECORDS]') {
                    $section = 'dns_records';
                } else {
                    die('Unknown section type');
                }
            } else {
                if($row != '') {
                    //* Handle zone section
                    if($section == 'zone') {
                        $parts = explode('=', $row);
                        $key = trim($parts[0]);
                        $val = trim($parts[1]);
                        if($key != '') $vars[$key] = $val;
                    }
                    //* Handle DNS Record rows
                    if($section == 'dns_records') {
                        $parts = explode('|', $row);
                        $dns_rr[] = array(
                            'name' => $parts[1],
                            'type' => $parts[0],
                            'data' => $parts[2],
                            'aux'  => $parts[3],
                            'ttl'  => $parts[4]
                        );
                    }
                }
            }
        } // end foreach
 
        if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').'<br />';
        if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').'<br />';
        if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').'<br />';
        if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').'<br />';
        if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').'<br />';
        if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').'<br />';
        if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').'<br />';
        if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').'<br />';
 
        if($error == '') {
            // Insert the soa record
            $tmp = $app->db->queryOneRecord("SELECT userid,default_group FROM sys_user WHERE client_id = ?", $client_id);
            $sys_userid = $tmp['userid'];
            $sys_groupid = $tmp['default_group'];
            unset($tmp);
            $origin = $vars['origin'];
            $ns = $vars['ns'];
            $mbox = str_replace('@', '.', $vars['mbox']);
            $refresh = $vars['refresh'];
            $retry = $vars['retry'];
            $expire = $vars['expire'];
            $minimum = $vars['minimum'];
            $ttl = $vars['ttl'];
            $xfer = $vars['xfer'];
            $also_notify = $vars['also_notify'];
            $update_acl = $vars['update_acl'];
            $serial = $app->validate_dns->increase_serial(0);
            $insert_data = array(
                "sys_userid" => $sys_userid,
                "sys_groupid" => $sys_groupid,
                "sys_perm_user" => 'riud',
                "sys_perm_group" => 'riud',
                "sys_perm_other" => '',
                "server_id" => $server_id,
                "origin" => $origin,
                "ns" => $ns,
                "mbox" => $mbox,
                "serial" => $serial,
                "refresh" => $refresh,
                "retry" => $retry,
                "expire" => $expire,
                "minimum" => $minimum,
                "ttl" => $ttl,
                "active" => 'Y',
                "xfer" => $xfer,
                "also_notify" => $also_notify,
                "update_acl" => $update_acl
            );
            $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
            // Insert the dns_rr records
            if(is_array($dns_rr) && $dns_soa_id > 0) {
                foreach($dns_rr as $rr) {
                    $insert_data = array(
                        "sys_userid" => $sys_userid,
                        "sys_groupid" => $sys_groupid,
                        "sys_perm_user" => 'riud',
                        "sys_perm_group" => 'riud',
                        "sys_perm_other" => '',
                        "server_id" => $server_id,
                        "zone" => $dns_soa_id,
                        "name" => $rr['name'],
                        "type" => $rr['type'],
                        "data" => $rr['data'],
                        "aux" => $rr['aux'],
                        "ttl" => $rr['ttl'],
                        "active" => 'Y'
                    );
                    $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
                }
            }
            exit;
        } else {
            throw new SoapFault('permission_denied', $error);
        }
    }
 
 
    //* Get record details
    public function dns_zone_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_zone_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_soa.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Get record id by origin
    public function dns_zone_get_id($session_id, $origin)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_zone_get_id')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
 
        if(!preg_match('/^[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/i', $origin)){
            throw new SoapFault('no_domain_found', 'Invalid domain name.');
            return false;
        }
 
        $rec = $app->db->queryOneRecord("SELECT id FROM dns_soa WHERE origin like ?", $origin."%");
        if(isset($rec['id'])) {
            return $app->functions->intval($rec['id']);
        } else {
            throw new SoapFault('no_domain_found', 'There is no domain ID with informed domain name.');
            return false;
        }
    }
 
    //* Add a record
    public function dns_zone_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_zone_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_soa.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_zone_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_zone_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_soa.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_zone_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_zone_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_soa.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_aaaa_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_aaaa_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_aaaa.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_aaaa_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_aaaa_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_aaaa.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_aaaa_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_aaaa_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_aaaa.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_aaaa_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_aaaa_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_aaaa.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_a_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_a_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_a.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_a_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_a_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_a.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_a_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_a_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_a.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_a_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_a_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_a.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_alias_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_alias_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_alias.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_alias_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_alias_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_alias.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_alias_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_alias_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_alias.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_alias_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_alias_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_alias.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_cname_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_cname_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_cname.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_cname_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_cname_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_cname.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_cname_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_cname_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_cname.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_cname_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_cname_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_cname.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_hinfo_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_hinfo_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_hinfo.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_hinfo_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_hinfo_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_hinfo.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_hinfo_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_hinfo_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_hinfo.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_hinfo_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_hinfo_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_hinfo.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_mx_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_mx_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_mx.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_mx_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_mx_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_mx.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_mx_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_mx_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_mx.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_mx_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_mx_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_mx.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_ns_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_ns_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_ns.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_ns_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_ns_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_ns.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_ns_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_ns_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_ns.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_ns_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_ns_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_ns.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_ptr_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_ptr_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_ptr.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_ptr_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_ptr_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_ptr.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_ptr_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_ptr_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_ptr.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_ptr_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_ptr_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_ptr.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_rp_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_rp_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_rp.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_rp_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_rp_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_rp.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_rp_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_rp_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_rp.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_rp_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_rp_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_rp.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_srv_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_srv_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_srv.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_srv_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_srv_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_srv.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_srv_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_srv_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_srv.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_srv_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_srv_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_srv.tform.php', $primary_id);
        return $affected_rows;
    }
 
    // ----------------------------------------------------------------------------------------------------------------
 
    //* Get record details
    public function dns_txt_get($session_id, $primary_id)
    {
        global $app;
 
        if(!$this->checkPerm($session_id, 'dns_txt_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $app->uses('remoting_lib');
        $app->remoting_lib->loadFormDef('../dns/form/dns_txt.tform.php');
        return $app->remoting_lib->getDataRecord($primary_id);
    }
 
    //* Add a record
    public function dns_txt_add($session_id, $client_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_txt_add')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        return $this->insertQuery('../dns/form/dns_txt.tform.php', $client_id, $params);
    }
 
    //* Update a record
    public function dns_txt_update($session_id, $client_id, $primary_id, $params)
    {
        if(!$this->checkPerm($session_id, 'dns_txt_update')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->updateQuery('../dns/form/dns_txt.tform.php', $client_id, $primary_id, $params);
        return $affected_rows;
    }
 
    //* Delete a record
    public function dns_txt_delete($session_id, $primary_id)
    {
        if(!$this->checkPerm($session_id, 'dns_txt_delete')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $affected_rows = $this->deleteQuery('../dns/form/dns_txt.tform.php', $primary_id);
        return $affected_rows;
    }
 
    /**
     * Get all DNS zone by user
     *@author Julio Montoya <gugli100@gmail.com> BeezNest 2010
     */
 
 
    public function dns_zone_get_by_user($session_id, $client_id, $server_id) {
        global $app;
        if(!$this->checkPerm($session_id, 'dns_zone_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        if (!empty($client_id) && !empty($server_id)) {
            $server_id      = $app->functions->intval($server_id);
            $client_id      = $app->functions->intval($client_id);
            $sql            = "SELECT id, origin FROM dns_soa d INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = ? AND server_id = ?";
            $result         = $app->db->queryAllRecords($sql, $client_id, $server_id);
            return          $result;
        }
        return false;
    }
 
 
 
    /**
     *  Get all dns records for a zone
     * @param  int  session id
     * @param  int  dns zone id
     * @author Sebastian Mogilowski <sebastian@mogilowski.net> 2011
     */
    public function dns_rr_get_all_by_zone($session_id, $zone_id) {
        global $app;
        if(!$this->checkPerm($session_id, 'dns_zone_get')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        $sql    = "SELECT * FROM dns_rr WHERE zone = ?";
        $result = $app->db->queryAllRecords($sql, $zone_id);
        return $result;
    }
 
    /**
     * Changes DNS zone status
     * @param  int  session id
     * @param int  dns soa id
     * @param string status active or inactive string
     * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
     */
    public function dns_zone_set_status($session_id, $primary_id, $status) {
        global $app;
        if(!$this->checkPerm($session_id, 'dns_zone_set_status')) {
            throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
            return false;
        }
        if(in_array($status, array('active', 'inactive'))) {
            if ($status == 'active') {
                $status = 'Y';
            } else {
                $status = 'N';
            }
            $sql = "UPDATE dns_soa SET active = ? WHERE id = ?";
            $app->db->query($sql, $status, $primary_id);
            $result = $app->db->affectedRows();
            return $result;
        } else {
            throw new SoapFault('status_undefined', 'The status is not available');
            return false;
        }
    }
 
}
 
?>