Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
server/plugins-available/bind_plugin.inc.php
@@ -102,17 +102,22 @@
         $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'] = '';
               if($records[$i]['name'] == '') $records[$i]['name'] = '@';
               //* Split TXT records, if nescessary
               if($records[$i]['type'] == 'TXT' && strlen($records[$i]['data']) > 255) {
                  $records[$i]['data'] = implode('" "',str_split( $records[$i]['data'], 255));
               }
            }
         }
         $tpl->setLoop('zones', $records);
         //TODO : change this when distribution information has been integrated into server record
         if (file_exists('/etc/gentoo-release')) {
            $filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($zone['origin'], 0, -1)));
            $filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri/'.str_replace("/", "_", substr($zone['origin'], 0, -1)));
         }
         else {
            $filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($zone['origin'], 0, -1)));
@@ -128,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);
@@ -146,7 +155,7 @@
      if($data['old']['origin'] != $data['new']['origin']) {
         //TODO : change this when distribution information has been integrated into server record
         if (file_exists('/etc/gentoo-release')) {
            $filename = $dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($data['old']['origin'], 0, -1));
            $filename = $dns_config['bind_zonefiles_dir'].'/pri/'.str_replace("/", "_", substr($data['old']['origin'], 0, -1));
         }
         else {
            $filename = $dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($data['old']['origin'], 0, -1));
@@ -156,8 +165,12 @@
         if(is_file($filename.'.err')) unlink($filename.'.err');
      }
      //* Reload bind nameserver
      $app->services->restartServiceDelayed('bind', 'reload');
      //* Restart bind nameserver if update_acl is not empty, otherwise reload it
      if($data['new']['update_acl'] != '') {
         $app->services->restartServiceDelayed('bind', 'restart');
      } else {
         $app->services->restartServiceDelayed('bind', 'reload');
      }
   }
@@ -272,7 +285,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';
@@ -284,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';
@@ -296,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 = ".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';
@@ -310,18 +323,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 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')) {
@@ -361,7 +366,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) {