Exemplo n.º 1
0
 public boolean isConfigured() {
   if (m_dnsServerConfigIP4 != null
       && m_dnsServerConfigIP4.getForwarders() != null
       && m_dnsServerConfigIP4.getForwarders().size() > 0
       && m_dnsServerConfigIP4.getAllowedNetworks() != null
       && m_dnsServerConfigIP4.getAllowedNetworks().size() > 0) {
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 2
0
  private String getForwardingNamedFile() {
    StringBuilder sb =
        new StringBuilder()
            .append("// Forwarding and Caching Name Server Configuration\n")
            .append("options {\n")
            .append("\tdirectory \"/var/named\";\n")
            .append("\tversion \"not currently available\";\n")
            .append("\tforwarders {");
    Set<IP4Address> forwarders = m_dnsServerConfigIP4.getForwarders();
    for (IP4Address forwarder : forwarders) {
      sb.append(forwarder.getHostAddress()).append(";");
    }
    sb.append("};\n");

    sb.append("\tforward only;\n")
        .append("\tallow-transfer{\"none\";};\n")
        .append("\tallow-query {");
    Set<NetworkPair<IP4Address>> allowedNetworks = m_dnsServerConfigIP4.getAllowedNetworks();
    for (NetworkPair<IP4Address> pair : allowedNetworks) {
      sb.append(pair.getIpAddress().getHostAddress())
          .append("/")
          .append(pair.getPrefix())
          .append(";");
    }
    sb.append("};\n");
    sb.append("\tmax-cache-ttl 30;\n");
    sb.append("\tmax-ncache-ttl 30;\n");
    sb.append("};\n")
        .append("logging{\n")
        .append("\tchannel named_log {\n")
        .append("\t\tfile \"")
        .append(s_logFileName)
        .append("\" versions 3;\n")
        .append("\t\tseverity info;\n")
        .append("\t\tprint-severity yes;\n")
        .append("\t\tprint-time yes;\n")
        .append("\t\tprint-category yes;\n")
        .append("\t};\n")
        .append("\tcategory default{\n")
        .append("\t\tnamed_log;\n")
        .append("\t};\n")
        .append("};\n")
        .append("zone \".\" IN {\n")
        .append("\ttype hint;\n")
        .append("\tfile \"named.ca\";\n")
        .append("};\n")
        .append("include \"")
        .append(s_rfc1912ZonesFilename)
        .append("\";\n");

    return sb.toString();
  }
Exemplo n.º 3
0
  public boolean enable() throws KuraException {
    // write config happened during 'set config' step

    try {
      // Check if named is running
      int pid = LinuxProcessUtil.getPid(s_procString);
      if (pid > -1) {
        // If so, disable it
        s_logger.error("DNS server is already running, bringing it down...");
        disable();
      }
      // Start named
      int result = -1;
      if (OS_VERSION.equals(
          KuraConstants.Mini_Gateway.getImageName()
              + "_"
              + KuraConstants.Mini_Gateway.getImageVersion())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind start");
      } else if (OS_VERSION.equals(
          KuraConstants.ReliaGATE_10_05.getImageName()
              + "_"
              + KuraConstants.ReliaGATE_10_05.getImageVersion())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind start");
      } else if (OS_VERSION.equals(KuraConstants.Raspberry_Pi.getImageName())
          || OS_VERSION.equals(KuraConstants.BeagleBone.getImageName())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind9 start");
      } else if (OS_VERSION.equals(
          KuraConstants.Intel_Edison.getImageName()
              + "_"
              + KuraConstants.Intel_Edison.getImageVersion()
              + "_"
              + KuraConstants.Intel_Edison.getTargetName())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind start");
      } else if (OS_VERSION.equals(
          KuraConstants.ReliaGATE_50_21_Ubuntu.getImageName()
              + "_"
              + KuraConstants.ReliaGATE_50_21_Ubuntu.getImageVersion())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind9 start");
      } else {
        s_logger.info("Linux named enable fallback");
        result = LinuxProcessUtil.start("/etc/init.d/named start");
      }
      if (result == 0) {
        s_logger.debug("DNS server started.");
        s_logger.trace(m_dnsServerConfigIP4.toString());
        return true;
      }
    } catch (Exception e) {
      throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
    }

    return false;
  }
Exemplo n.º 4
0
  public boolean disable() throws KuraException {
    try {
      int result = -1;
      // If so, stop it.
      if (OS_VERSION.equals(
          KuraConstants.Mini_Gateway.getImageName()
              + "_"
              + KuraConstants.Mini_Gateway.getImageVersion())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind stop");
      } else if (OS_VERSION.equals(KuraConstants.Raspberry_Pi.getImageName())
          || OS_VERSION.equals(KuraConstants.BeagleBone.getImageName())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind9 stop");
      } else if (OS_VERSION.equals(
          KuraConstants.Intel_Edison.getImageName()
              + "_"
              + KuraConstants.Intel_Edison.getImageVersion()
              + "_"
              + KuraConstants.Intel_Edison.getTargetName())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind stop");
      } else if (OS_VERSION.equals(
          KuraConstants.ReliaGATE_50_21_Ubuntu.getImageName()
              + "_"
              + KuraConstants.ReliaGATE_50_21_Ubuntu.getImageVersion())) {
        result = LinuxProcessUtil.start("/etc/init.d/bind9 stop");
      } else {
        result = LinuxProcessUtil.start("/etc/init.d/named stop");
      }

      if (result == 0) {
        s_logger.debug("DNS server stopped.");
        s_logger.trace(m_dnsServerConfigIP4.toString());
        return true;
      } else {
        s_logger.debug("tried to kill DNS server for interface but it is not running");
      }
    } catch (Exception e) {
      throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
    }

    return true;
  }
Exemplo n.º 5
0
  private void writeConfig() throws KuraException {
    try {
      FileOutputStream fos = new FileOutputStream(s_persistentConfigFileName);
      PrintWriter pw = new PrintWriter(fos);

      // build up the file
      if (m_dnsServerConfigIP4 == null
          || m_dnsServerConfigIP4.getForwarders() == null
          || m_dnsServerConfigIP4.getAllowedNetworks() == null
          || m_dnsServerConfigIP4.getForwarders().size() == 0
          || m_dnsServerConfigIP4.getAllowedNetworks().size() == 0) {
        s_logger.debug(
            "writing default named.conf to "
                + s_persistentConfigFileName
                + " with: "
                + m_dnsServerConfigIP4.toString());
        pw.print(getDefaultNamedFile());
      } else {
        s_logger.debug(
            "writing custom named.conf to "
                + s_persistentConfigFileName
                + " with: "
                + m_dnsServerConfigIP4.toString());
        pw.print(getForwardingNamedFile());
      }

      pw.flush();
      fos.getFD().sync();
      pw.close();
      fos.close();
    } catch (Exception e) {
      e.printStackTrace();
      throw new KuraException(
          KuraErrorCode.CONFIGURATION_ERROR,
          "error while building up new configuration files for dns servers: " + e.getMessage());
    }
  }