Skip to content

Allow the creation of DNS RPZ zones to allow URLs being blocked

Notifications You must be signed in to change notification settings

rnhc1000/dnsBlockURL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DNS RPZ - URL Blocked by DNS - @Ricardo Ferreira

In order to meet brazilian authorities requirements to block URLs being used to circumvent the legal brazilian regulatory system, this is a way of automate the creation of DNS Zones using BIND 9 and superior in sync with the Anatel ( Regulatory Agency ) guidance and data available at a public API. The goal here is to allow Internet Service Providers that have BIND as their DNS Engines to be fully compliant with the legal and justice requirements near real-time with the authorities request.

Tools

  • Java 17
  • IntelliJ Community Edition
  • Spring Boot
  • MongoDB
  • ReactJS
  • HTML
  • CSS
  • TypeScript

Table of contents

Screenshot

Links

  • Live Site URL: []

Built with

My Skills

What I practiced

package br.dev.ferreiras.bloqueioanatel;


import java.io.*;
import java.util.*;

public class BlockedSites {


  public static Set<String> readBlockedSites() {
    String line = null;
    String pathOne = "/home/rferreira/dev/src/dns/primario/rpz/sites.csv";
    String pathTwo = "/home/rferreira/dev/src/dns/primario/rpz/rpz.txt";
    List<String> blockedSitesOne = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new FileReader(pathOne))) {
      while ((line = br.readLine()) != null) {
        String[] lines = line.split("\\s");
        blockedSitesOne.add(lines[0]);
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    List<String> blockedSitesTwo = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new FileReader(pathTwo))) {
      while ((line = br.readLine()) != null) {
        String[] lines = line.split("\\s");
        blockedSitesTwo.add(lines[0]);
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    Set<String> set = new TreeSet<>();
    set.addAll(blockedSitesOne);
    set.addAll(blockedSitesTwo);

    return set;
  }

  public static boolean fileExists(String filePath, String fileName) throws IOException {
    String fileToBeProcessed = filePath.concat(fileName);
    try {
      File handler = new File(fileToBeProcessed);
      if (handler.createNewFile()) {
        System.out.println("File created!");
      }
    } catch (IOException ex) {
      throw new IOException("File could not be created! " + ex.getMessage());
    }

    return true;
  }

  public static void writeBlockedSites(Set<String> blockedSites) throws IOException {
    String filePath = "/home/rferreira/dev/pakTelecom/src/dns/primario/rpz/";
    String fileName = "ascendingBlockedSites.txt";
    boolean OK = fileExists(filePath, fileName);
    int count = 0;

    if (OK) {
      try (FileWriter fw = new FileWriter(filePath.concat(fileName))) {
        List<String> sortedList = new ArrayList<>();

        for (String sites : blockedSites) {
          sortedList.add(sites.concat("\s\s\s\sIN\s\s\s\sCNAME\s\s\s\s."));
        }
        System.out.println(blockedSites.size());
        for (String sites : sortedList) {
          fw.write(sites);
          fw.write("\n");
          count++;
        }

      } catch (IOException ex) {
        throw new IOException("File not accessible! " + ex.getMessage());
      }
    }
    
  }

  public static Set<String> mergeFiles(List<String> listOne, List<String> listTwo) {

    Set<String> set = new LinkedHashSet<>();
    set.addAll(listOne);
    set.addAll(listTwo);

    return set;
  }
}

Continued development

  • Application still being developed

Useful resources

Author

Acknowledgments

About

Allow the creation of DNS RPZ zones to allow URLs being blocked

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published