A. Täffner
2016-01-21 24bedeeac18b2d2092cf3ba4359123e975e26f2a
server/plugins-available/bind_plugin.inc.php
@@ -102,7 +102,7 @@
         $zone = $data['new'];
         $tpl->setVar($zone);
         $records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
         $records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ? AND active = 'Y'", $zone['id']);
         if(is_array($records) && !empty($records)){
            for($i=0;$i<sizeof($records);$i++){
               if($records[$i]['ttl'] == 0) $records[$i]['ttl'] = '';
@@ -133,7 +133,11 @@
         if($return_status === 0) {
            $app->log("Writing BIND domain file: ".$filename, LOGLEVEL_DEBUG);
         } else {
            $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), LOGLEVEL_WARN);
            if($dns_config['disable_bind_log'] === 'y') {
               $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), LOGLEVEL_DEBUG);
            } else {
               $app->log("Writing BIND domain file failed: ".$filename." ".implode(' ', $out), LOGLEVEL_WARN);
            }
            rename($filename, $filename.'.err');
         }
         unset($tpl);
@@ -141,7 +145,15 @@
         unset($records_out);
         unset($zone);
      }
      //* DNSSEC-Implementation
      if($data['old']['origin'] != $data['new']['origin']) {
         if (@$data['old']['dnssec_initialized'] == 'Y' && strlen(@$data['old']['origin']) > 3) exec('/usr/local/ispconfig/server/scripts/dnssec-delete.sh '.escapeshellcmd($data['old']['origin'])); //delete old keys
         if ($data['new']['dnssec_wanted'] == 'Y') exec('/usr/local/ispconfig/server/scripts/dnssec-create.sh '.escapeshellcmd($data['new']['origin'])); //Create new keys for new origin
      }
      if ($data['new']['dnssec_wanted'] == 'Y' AND $data['new']['dnssec_initialized'] == 'N') if ($data['new']['dnssec_wanted'] == 'Y') exec('/usr/local/ispconfig/server/scripts/dnssec-create.sh '.escapeshellcmd($data['new']['origin'])); //Create new keys for new origin
      else if ($data['old']['dnssec_wanted'] == 'Y') exec('/usr/local/ispconfig/server/scripts/dnssec-update.sh '.escapeshellcmd($data['new']['origin']));
      //* rebuild the named.conf file if the origin has changed or when the origin is inserted.
      //if($this->action == 'insert' || $data['old']['origin'] != $data['new']['origin']) {
      $this->write_named_conf($data, $dns_config);
@@ -159,8 +171,9 @@
         if(is_file($filename)) unlink($filename);
         if(is_file($filename.'.err')) unlink($filename.'.err');
      }
         if(is_file($filename.'.signed')) unlink($filename.'.signed');
       }
      //* Restart bind nameserver if update_acl is not empty, otherwise reload it
      if($data['new']['update_acl'] != '') {
         $app->services->restartServiceDelayed('bind', 'restart');
@@ -193,6 +206,9 @@
      if(is_file($zone_file_name.'.err')) unlink($zone_file_name.'.err');
      $app->log("Deleting BIND domain file: ".$zone_file_name, LOGLEVEL_DEBUG);
       //* DNSSEC-Implementation
       if ($data['old']['dnssec_initialized'] == 'Y') exec('/usr/local/ispconfig/server/scripts/dnssec-delete.sh '.$data['old']['origin']); //delete keys
      //* Reload bind nameserver
      $app->services->restartServiceDelayed('bind', 'reload');
@@ -281,7 +297,7 @@
      global $app, $conf;
      //* Get the data of the soa and call soa_update
      $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$data['new']['zone']);
      $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['new']['zone']);
      $data["new"] = $tmp;
      $data["old"] = $tmp;
      $this->action = 'update';
@@ -293,7 +309,7 @@
      global $app, $conf;
      //* Get the data of the soa and call soa_update
      $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$data['new']['zone']);
      $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['new']['zone']);
      $data["new"] = $tmp;
      $data["old"] = $tmp;
      $this->action = 'update';
@@ -305,7 +321,7 @@
      global $app, $conf;
      //* Get the data of the soa and call soa_update
      $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".intval($data['old']['zone']));
      $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $data['old']['zone']);
      $data["new"] = $tmp;
      $data["old"] = $tmp;
      $this->action = 'update';
@@ -319,18 +335,10 @@
      global $app, $conf;
      //* Only write the master file for the current server
      $tmps = $app->db->queryAllRecords("SELECT origin, xfer, also_notify, update_acl FROM dns_soa WHERE active = 'Y' AND server_id=".$conf["server_id"]);
      $tmps = $app->db->queryAllRecords("SELECT origin, xfer, also_notify, update_acl, dnssec_initialized FROM dns_soa WHERE active = 'Y' AND server_id=?", $conf["server_id"]);
      $zones = array();
      //* Check if the current zone that triggered this function has at least one NS record
      /* Has been replaced by a better zone check
      $rec_num = $app->db->queryOneRecord("SELECT count(id) as ns FROM dns_rr WHERE type = 'NS' AND zone = ".intval($data['new']['id'])." AND active = 'Y'");
      if($rec_num['ns'] == 0) {
         $exclude_zone = $data['new']['origin'];
      } else {
         $exclude_zone = '';
      }
      */
      //TODO : change this when distribution information has been integrated into server record
      if (file_exists('/etc/gentoo-release')) {
@@ -347,6 +355,7 @@
      foreach($tmps as $tmp) {
         $zone_file = $pri_zonefiles_path.str_replace("/", "_", substr($tmp['origin'], 0, -1));
         if ($tmp['dnssec_initialized'] == 'Y') $zone_file .= '.signed' //.signed is for DNSSEC-Implementation
         $options = '';
         if(trim($tmp['xfer']) != '') {
@@ -370,7 +379,7 @@
      $tpl->setLoop('zones', $zones);
      //* And loop through the secondary zones, but only for the current server
      $tmps_sec = $app->db->queryAllRecords("SELECT origin, xfer, ns FROM dns_slave WHERE active = 'Y' AND server_id=".$conf["server_id"]);
      $tmps_sec = $app->db->queryAllRecords("SELECT origin, xfer, ns FROM dns_slave WHERE active = 'Y' AND server_id=?", $conf["server_id"]);
      $zones_sec = array();
      foreach($tmps_sec as $tmp) {