コード例 #1
0
ファイル: LinuxNamed.java プロジェクト: PisalPrasad123/kura
 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;
   }
 }
コード例 #2
0
ファイル: LinuxNamed.java プロジェクト: PisalPrasad123/kura
  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();
  }
コード例 #3
0
ファイル: LinuxNamed.java プロジェクト: PisalPrasad123/kura
  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());
    }
  }