Skip to content

Create a allow|white-list for hosts #72

@mStirner

Description

@mStirner

Allow to define a (white|allow)-list, which a connector should bridge connection requests to.
Draft:

const { BlockList } = require("net");
const dns = require("dns");
const { readFileSync } = require("fs");


const allowlist = new BlockList();

const ALLOWS = JSON.parse(readFileSync("./allowlist.json"));


ALLOWS.forEach((host) => {
    if (host.includes("/")) {

        let [net, prefix] = host.split("/");
        allowlist.addSubnet(net, parseInt(prefix));

    } else {

        dns.resolve(host, (err, records) => {

            if (err) {
                return console.error(err);
            }

            records.forEach((ip) => {
                allowlist.addAddress(ip);
            });

        });

    }
});




setTimeout(async () => {

    console.log("Allowlist", allowlist)
    const host = "192.168.2.1";


    const allow = await new Promise((resolve, reject) => {
        if (ALLOWS.includes(host)) {

            resolve(true);

        } else {

            dns.resolve(host, (err, addresses) => {
                if (err) {

                    reject(err);

                } else {

                    if(addresses.length <= 0){
                        return resolve(false);
                    }

                    resolve(allowlist.check(addresses[0]));

                }
            });

        }
    });


    console.log("Allow:", `${host} = ${allow}`);

}, 100);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions