This file is indexed.

/usr/share/gosa/plugins/admin/systems/services/dns/class_servDNSeditZoneEntries.inc is in gosa-plugin-dns 2.7.4+reloaded2-1+deb8u2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
<?php

class servDNSeditZoneEntries extends plugin
{
    /* attribute list for save action */
    var $ignore_account     = TRUE;
    var $attributes         = array();
    var $objectclasses      = array("whatever");

    var $Devices            = array();

    var $zoneName           = "";   // ZoneName of currently edited Zone
    var $reverseName        = "";   // ReverseZone of the currently edited Zone

    var $RecordTypes        = array();  // Possible record type.
    var $acl                = "";
    var $disableDialog      = false; // Dialog will be disabled, if this zone is new 


    function servDNSeditZoneEntries (&$config,$dn, &$zoneObject)
    {
        plugin::plugin ($config, $dn);

        /* Initialise class
         */
        $this->RecordTypes  = DNS::getDnsRecordTypes();
        $this->dn           = "zoneName=".$zoneObject['InitialzoneName'].",".$dn; 
        $this->zoneName     = $zoneObject['InitialzoneName'];
        $this->reverseName  = $zoneObject['InitialReverseZone'];

        /* Remove nSRecord from listed types */
        if(isset($this->RecordTypes['nSRecord'])){
            unset($this->RecordTypes['nSRecord']);
        }
        /* Remove nSRecord from listed types */
        if(isset($this->RecordTypes['pTRRecord'])){
            unset($this->RecordTypes['pTRRecord']);
        }

        /* Get ldap connection 
         */
        $ldap = $this->config->get_ldap_link();
        $ldap->cd($this->config->current['BASE']);

        /* Get zone content
         */
        $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$this->dn,array("relativeDomainName"));

        while($attrs = $ldap->fetch()){
            $this->Devices[$attrs['relativeDomainName'][0]] = DNS::getDNSHostEntries($config,$attrs['relativeDomainName'][0],true);
            $this->Devices[$attrs['relativeDomainName'][0]]['OrigCn'] = $attrs['relativeDomainName'][0];
        }

        $ldap->cat($this->dn,array("objectClass"));

        $this->disableDialog = true;
        if(count($this->Devices)|| $ldap->count()){
            $this->disableDialog = false;
        }
    }

    function execute()
    {
        plugin::execute();

        /* Fill templating stuff */
        $smarty= get_smarty();
        $display= "";

        $table = "";
        foreach($this->Devices as $key => $dev){
            $table .= $this->generateRecordConfigurationRow($key);
        }

        $smarty->assign("acl",$this->acl);
        $smarty->assign("disableDialog",$this->disableDialog);
        $smarty->assign("table",$table);;
        $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE, dirname(__FILE__)));
        return($display);
    }


    function save_object()
    {
        /* Check posts for operations ...  
         */
        $once = true;
        $ptr_updates = array();
        if(!preg_match("/w/",$this->acl)) return;

        foreach($_POST as $name => $value){

            /* Extract informations out of post name 
             */
            $tmp    = preg_replace("/^[^_]*_/","\\1",$name);
            $tmp2   = explode("|",postDecode($tmp));      

            /* Add new host entry
             */
            if((preg_match("/^UserRecord_?/",$name)) && ($once)){
                $once = false;
                $entry = DNS::getDNSHostEntries($this->config,"",true);     
                $entry['exists']    = true;
                $entry['zoneName']  = strtoupper($this->attrs['cn'][0])."/".$this->zoneName; 
                $entry['RECORDS'][] = array("type" => "aRecord" , "value"=>"");
                $this->Devices[_("New entry")] = $entry;
            }

            if(count($tmp2) != 2) continue;

            $Name     = $tmp2[0];
            $RecordID = $tmp2[1];

            /* Add new REcord
             */
            if((preg_match("/^AddRecord_/",$name)) && ($once)){
                $once = false;
                $this->Devices[$Name]['RECORDS'][] = $this->Devices[$Name]['RECORDS'][$RecordID];
            }

            /* Remove record from given dn
             */
            if((preg_match("/^RemoveRecord_/",$name)) && ($once)){
                $once   = false;
                if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
                    unset($this->Devices[$Name]['RECORDS'][$RecordID]);
                }

                /* Check if there is at least one visible record. Else remove complete entry */
                $visible = false;
                foreach($this->Devices[$Name]['RECORDS'] as $rec){
                    if(in_array_strict($rec['type'],$this->RecordTypes)){
                        $visible = true;  
                        break;
                    }
                }
                if(!$visible && isset($this->Devices[$Name]['RECORDS'])){
                    $this->Devices[$Name]['RECORDS'] = array();
                }
            }
        }

        /* Possible attributes posted 
         */
        foreach($_POST as $name => $value){

            $value = get_post($name);

            /* Extract informations out of post name 
             */
            $tmp    = preg_replace("/^[^_]*_/","\\1",$name);
            $tmp2   = explode("|",postDecode($tmp));      

            if(count($tmp2) != 2) continue;

            $Name     = $tmp2[0];
            $RecordID = $tmp2[1];

            /* Check for value change 
             */          
            if(preg_match("/ValueSelection_/",$name)){
                if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){

                    /* Update value */ 
                    $old = $this->Devices[$Name]['RECORDS'][$RecordID]['value'];
                    $this->Devices[$Name]['RECORDS'][$RecordID]['value'] = get_post($name);

                    /* Handle pTRRecord */
                    if(!isset($ptr_updates[$Name]) && $this->Devices[$Name]['RECORDS'][$RecordID]['type'] == "aRecord"){

                        $found = false;
                        $ip = $value;
                        $match = preg_replace("/^[^\/]*+\//","",$this->reverseName);
                        $ip = preg_replace("/^".preg_quote($match)."/","",$ip);
                        $ip = preg_replace("/^\./","",$ip);

                        foreach($this->Devices[$Name]['RECORDS'] as $key => $dev){
                            if($dev['type'] == "pTRRecord"){
                                $ptr_updates[$Name] = $Name;
                                $this->Devices[$Name]['RECORDS'][$key]['value'] = $ip;
                                $found = true;
                                break;
                            }
                        }
                        if(!$found){
                            $dev = array('type'=> 'pTRRecord', 'value' => $ip);
                            $this->Devices[$Name]['RECORDS'][] = $dev;
                        }
                    }
                }
            }

            /* record type changed
             */        
            if(preg_match("/^RecordTypeSelection_/",$name)){
                if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
                    $this->Devices[$Name]['RECORDS'][$RecordID]['type'] = $value;
                }  
            }   
        }

        /* check for renamed entries 
         */ 
        foreach($_POST as $name => $value){

        
            $value = get_post($name);

            /* Extract informations out of post name 
             */
            $tmp    = preg_replace("/^[^_]*_/","\\1",$name);
            $tmp2   = explode("|",postDecode($tmp));      

            if(count($tmp2) != 2) continue;

            $Name     = $tmp2[0];
            $RecordID = $tmp2[1];

            /* Host renamed
             */
            if(preg_match("/RenameHost_/",$name)){
                if((isset($this->Devices[$Name])) && ($Name != $value)){

                    if(isset($this->Devices[$value])){
                        msg_dialog::display(_("Error"), sprintf(_("Cannot rename '%s' to '%s'. Name is already in use!"), $Name, $value), ERROR_DIALOG);
                    }else{
                        $this->Devices[$value] = $this->Devices[$Name];
                        unset($this->Devices[$Name]);
                    }
                }
            }
        }
    }


    /*  check something 
     */
    function check()
    {
        /* Call common method to give check the hook */
        $message= plugin::check();

        if(!preg_match("/w/",$this->acl)) return($message);

        $ldap = $this->config->get_ldap_link();
        $ldap->cd($this->config->current['BASE']);

        $names = array();

        foreach($this->Devices as $DevName => $device){

            /* Don't need to check empty values ... */
            if(!count($device['RECORDS'])) continue;

            /* Checking entry name
             */
            if(!preg_match("/^[a-z0-9_\.-]+$/i", $DevName) || (empty($DevName))){
                $message[] = msgPool::invalid(_("Name"),$DevName,"/[a-z0-9_\.-]/i");
            }      

            /* Renaming check for existing devices 
             */
            if(isset($device['OrigCn'])  && ($DevName != $device['OrigCn'] )){
                $ldap->cd($this->config->current['BASE']);
                $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName"));
                if($ldap->count()){
                    $message[] = sprintf(_("Cannot rename '%s' to '%s'. Entry is already in use."),$device['OrigCn'],$DevName);
                }
            }elseif(!isset($device['OrigCn'])){
                $ldap->cd($this->config->current['BASE']);
                $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName"));
                if($ldap->count()){
                    $message[] = sprintf(_("Cannot create '%s'. Entry is already in use."),$DevName);
                }
            }

            /* Check names 
             */
            if(!isset($names[$DevName])){
                $names[$DevName] = "";
            }else{
                $message[] = sprintf(_("Entry '%s' is used more than once."),$DevName);
            }

            /* Names should be written in lowercase
             */
#      if(strtolower($DevName) != $DevName){
#        $message[] = sprintf(_("The host name '%s' should be written in lowercase."), $DevName);
#      }

            /* Check records
             */                 
            $singleEntries = array("pTRRecord");

            $tmp  = array();
            $tmp2 = array();
            foreach($device['RECORDS'] as $Num => $Rec){

                /* Check values */
                $message += $this->checkRecordType($DevName, $Rec['type'], $Rec['value']);

                /* Check for multiple use of unique record types
                 */
                if(in_array_strict($Rec['type'],$singleEntries)){
                    if(!isset($tmp[$Rec['type']])){
                        $tmp[$Rec['type']] = "";
                    }else{
                        $message[] = sprintf(_("%s records cannot be used more than once."),$Rec['type']);
                    }
                }

                /* Check for empty / duplicate entries in record array 
                 */
                if(empty($Rec['value'])){
                    $message[] = sprintf(_("Please fix the empty %s record for entry '%s'."),$Rec['type'],$DevName);
                }

                /* Check for duplicate record entries 
                 */
                if(!isset($tmp[$Rec['type']][$Rec['value']])){
                    $tmp[$Rec['type']][$Rec['value']] = "";
                }else{
                    $message[] = sprintf(_("Please fix the duplicate %s record for entry '%s'."),$Rec['type'],$DevName); 
                }
            }
        }
        return ($message);
    }


    function save()
    {
        if($this->disableDialog || !preg_match("/w/",$this->acl)) return;

        $todo = array(); 



        /* Create todolist
         */
        foreach($this->Devices as $name => $dev){
            if(isset($dev['OrigCn'])){
                if(count($dev['RECORDS'])){
                    $todo[] = DNS::getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
                }else{
                    $dev['exists'] = false;
                    $todo[] = DNS::getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
                }
            }else{
                if(count($dev['RECORDS'])){
                    $todo[] = DNS::getDNSHostEntriesDiff($this->config,"",$dev,$name);
                }else{
                    $dev['exists'] = false;
                    $todo[] = DNS::getDNSHostEntriesDiff($this->config,"",$dev,$name);
                }
            }
        }

        $tmp = array();
        $tmp['del']   = array();
        $tmp['add']   = array();
        $tmp['move']  = array();
        foreach($todo as $to){
            foreach($to as $type => $entries){
                $tmp[$type] = array_merge($tmp[$type],$entries);
            }
        }

        /* Get ldap link
         */
        $ldap = $this->config->get_ldap_link();
        $ldap->cd ($this->config->current['BASE']);

        /* move follwoing entries
         */
        foreach($tmp['move'] as $src => $dst){
            $this->recursive_move($src,$dst);
        }

        /* Delete dns */
        foreach($tmp['del'] as $dn => $del){
            $ldap->cd($dn);
            $ldap->rmdir_recursive($dn);
            if(is_object($this->parent->parent)){
                $this->parent->parent->handle_post_events("remove",array("dn" => $dn));
            }
        }

        /* Add || Update new DNS entries
         */
        foreach($tmp['add'] as $dn => $attrs){
            $ldap->cd($dn);
            $ldap->cat($dn, array('dn'));
            if(count($ldap->fetch())){
                $ldap->cd($dn);
                $ldap->modify ($attrs);
                if(is_object($this->parent->parent)){
                    $this->parent->parent->handle_post_events("modify",array("dn" => $dn));
                }
            }else{
                $ldap->cd($dn);
                $ldap->add($attrs);
                if(is_object($this->parent->parent)){
                    $this->parent->parent->handle_post_events("add",array("dn" => $dn));
                }
            }
        }
    }


    /* Create html table out of given entry 
     */
    function generateRecordConfigurationRow($objKey){

        /* Get some basic informations 
         */
        $obj        = $this->Devices[$objKey];
        $objectName = $objKey;

        $dis = "";
        if(!preg_match("/w/",$this->acl)){
            $dis = " disabled ";
        }

        /* Abort if emtpy
         */
        if(count($obj['RECORDS']) == 0) return "";

        /* Set title 
         */
        $str= "<br>";

        $hostNameOnce = true;

        /* Walk through all defined records 
         */
        $str.= "<table summary=''>";
        foreach($obj['RECORDS'] as $id => $record){

            /* Skip not selectable entries */
            if(!isset($this->RecordTypes [$record['type']])) {
                continue;
            }

            /* Create unique post name
             */
            $name = postEncode($objKey."|".$id);

            /* Only first host entry name should be editable
             */
            if($hostNameOnce){
                $hostNameOnce = false;  
                $field1 ="<input $dis type='text' style='width:250px;' name='RenameHost_".$name."' value='".set_post($objectName)."'>\n";
            }else{
                $field1 = "";
            }
            $field2 = $this->createRecordTypeSelection($record['type'],$name);
            $field3 = "<input type='text' $dis value='".set_post($record['value'])."' name='ValueSelection_".$name."' style='width:250px;'>";
            if(preg_match("/w/",$this->acl)){
                $acl = image('images/lists/element.png[new]',"AddRecord_".$name,_("Add"));
                $acl.= image('images/lists/trash.png',"RemoveRecord_".$name,_("Remove"));
            }

            /* Display settings backwards for CNAMERecords 
             */
            if($record['type'] == "cNAMERecord"){
                $str .= "
                    <tr>
                    <td style='width:250px;text-align:right;'>".$field3."</td>
                    <td style='width:90px;'>".$field2."</td>
                    <td>".$objectName."</td>
                    <td>".$acl."</td>
                    </tr>";
            }else{ 
                $str .= "
                    <tr>
                    <td style='width:75px;text-align:right;'>".$field1."</td>
                    <td style='width:90px;'>".$field2."</td>
                    <td>".$field3."</td>
                    <td>".$acl."</td>
                    </tr>";
            }
        }
        $str .="</table>";
        return($str); 
    }


    /* Create selectbox with all available option types 
     */
    function createRecordTypeSelection($id,$refID){

        if(preg_match("/w/",$this->acl)){
            $str = "\n<select name='RecordTypeSelection_".$refID."' onChange='document.mainform.submit();'>";
            foreach($this->RecordTypes as $type => $atr) {
                if($id == $type){
                    $str .="\n<option value='".$type."' selected >".strtoupper(preg_replace("/record/i","",$type))."</option>";
                }else{
                    $str .="\n<option value='".$type."'>".strtoupper(preg_replace("/record/i","",$type))."</option>";
                }
            }
            $str.= "\n</select>";
        }else{
            $str = "&nbsp;".strtoupper(preg_replace("/record/i","",$id));
        }
        return($str);
    }


    /* Check record types for strange inputs */
    function checkRecordType($name, $type, $value)
    {
        $template = _("The syntax of entry %s (record type %s, value %s) is invalid!")." %s<br><br><i>"._("Example").":</i> %s";

        $message = Array();
        switch($type) {
            case 'aAAARecord': // RFC 3596
                if(!tests::is_dns_name($name)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Entry should be a DNS name."), "example");
                }
                if(!tests::is_ipv6($value)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be an IPv6 address."), "1fff:0000:0a88:85a3:0000:0000:ac1f:8001");
                }
                break;
            case 'aRecord': // RFC 1035
                if(!tests::is_dns_name($name)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Entry should be a DNS name."), "example");
                }
                if(!tests::is_ip($value)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be an IPv4 address."), "192.168.1.10");
                }
                break;
            case 'cNAMERecord': // RFC 1035
                if(!tests::is_dns_name($name)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Entry should be a DNS name."), "example");
                }
                if(!tests::is_dns_name($value)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be a DNS name."), "example");
                }
                break;
            case 'mXRecord': // RFC 1035
                //value: preference target
                if(preg_match('/^(\S+)\s+(\S+)$/', $value, $matches)) {
                    if(!tests::is_id($matches[1])) {
                        $message[] = sprintf($template, $name, $type, $value, _("Value 1 should be a number."), "10 example");
                    }
                    if(!tests::is_dns_name($matches[2])) {
                        $message[] = sprintf($template, $name, $type, $value, _("Value 2 should be a DNS name."), "10 example");
                    }
                } else {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be composed of 'preference target'."), "10 example");
                }
                break;
            case 'nSRecord': // RFC 1035
                if(!tests::is_dns_name($value)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be a DNS name."), "example");
                }
                break;
            case 'pTRRecord': // RFC 1035
                if(!tests::is_dns_name($value)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be a DNS name."), "example");
                }
                break;
            case 'sRVRecord': // RFC 2782
                if(!tests::is_dns_name($name)) {
                    $message[] = sprintf($template, $name, $type, $value, _("Entry should be a DNS name."), "example");
                }
                //value: priority weight port target
                if(preg_match('/^([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(\S+)$/', $value, $matches)) {
                    if(!tests::is_id($matches[1])) {
                        $message[] = sprintf($template, $name, $type, $value, _("Value 1 (priority) should be a number."), "0 5 5060 example");
                    }
                    if(!tests::is_id($matches[2])) {
                        $message[] = sprintf($template, $name, $type, $value, _("Value 2 (weight) should be a number."), "0 5 5060 example");
                    }
                    if(!tests::is_id($matches[3])) {
                        $message[] = sprintf($template, $name, $type, $value, _("Value 3 (port) should be a number."), "0 5 5060 example");
                    }
                    if(!tests::is_dns_name($matches[4])) {
                        $message[] = sprintf($template, $name, $type, $value, _("Value 4 (target) should be a DNS name."), "0 5 5060 example");
                    }
                } else {
                    $message[] = sprintf($template, $name, $type, $value, _("Value should be composed of 'priority weight port target'."), "0 5 5060 example");
                }
                break;
        }
        return $message;
    }


    function remove_from_parent()
    {
    }

}

// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>