How to use the haraka-tld.split_hostname function in haraka-tld

To help you get started, we’ve selected a few haraka-tld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github haraka / Haraka / plugins / greylist.js View on Github external
}

    if (!connection.results.has('fcrdns', 'pass', 'fcrdns')) // FcrDNS failed
        return chsit(null, 'FcrDNS failed');

    if (connection.results.get('fcrdns').ptr_names.length > 1) // multiple PTR returned
        return chsit(null, 'multiple PTR returned');

    if (connection.results.has('fcrdns', 'fail', /^is_generic/)) // generic/dynamic rDNS record
        return chsit(null, 'rDNS is a generic record');

    if (connection.results.has('fcrdns', 'fail', /^valid_tld/)) // invalid org domain in rDNS
        return chsit(null, 'invalid org domain in rDNS');

    // strip first label up until the tld boundary.
    const decoupled = tlds.split_hostname(rdns, 3);
    const vardom = decoupled[0]; // "variable" portion of domain
    const dom = decoupled[1]; // "static" portion of domain

    // we check for special cases where rdns looks custom/static, but really is dynamic
    const special_case_info = plugin.check_rdns_for_special_cases(rdns, vardom);
    if (special_case_info) {
        return chsit(null, special_case_info.why);
    }

    let stripped_dom = dom;

    if (vardom) {

        // check for decimal IP in rDNS
        if (vardom.match(String(net_utils.ip_to_long(ip))))
            return chsit(null, 'decimal IP');
github haraka / Haraka / net_utils.js View on Github external
exports.is_ip_in_str = function (ip, str) {
    if (!str) { return false; }
    if (!ip) { return false; }
    if (!net.isIPv4(ip)) {
        return false;   // IPv4 only, for now
    }

    var host_part = (tlds.split_hostname(str,1))[0].toString();
    var octets = ip.split('.');
    // See if the 3rd and 4th octets appear in the string
    if (this.octets_in_string(host_part, octets[2], octets[3])) {
        return true;
    }
    // then the 1st and 2nd octets
    if (this.octets_in_string(host_part, octets[0], octets[1])) {
        return true;
    }

    // Whole IP in hex
    var host_part_copy = host_part;
    var ip_hex = this.dec_to_hex(this.ip_to_long(ip));
    for (var i=0; i<4; i++) {
        var part = host_part_copy.indexOf(ip_hex.substring(i*2, (i*2)+2));
        if (part === -1) break;
github haraka / Haraka / plugins / data.uribl.js View on Github external
if (net.isIPv6(host)) {
                if (/^(?:1|true|yes|enabled|on)$/i.test(lists[zone].not_ipv6_compatible) || /^(?:1|true|yes|enabled|on)$/i.test(lists[zone].no_ip_lookups)) {
                    results.add(plugin, {skip: `IP (${host}) not supported for ${zone}` });
                    continue;
                }
                // Skip any private IPs
                if (net_utils.is_private_ip(host)) {
                    results.add(plugin, {skip: 'private IP' });
                    continue;
                }
                // Reverse IP for lookup
                lookup = net_utils.ipv6_reverse(host);
            }
            // Handle zones that require host to be stripped to a domain boundary
            else if (/^(?:1|true|yes|enabled|on)$/i.test(lists[zone].strip_to_domain)) {
                lookup = (tlds.split_hostname(host, 3))[1];
            }
            // Anything else..
            else {
                lookup = host;
            }
            if (!lookup) continue;
            if (!queries[zone]) queries[zone] = {};
            if (Object.keys(queries[zone]).length > lists.main.max_uris_per_list) {
                connection.logwarn(plugin, `discarding lookup ${lookup} for zone ${zone} maximum query limit reached`);
                results.add(plugin, {skip: `max query limit for ${zone}` });
                continue;
            }
            queries[zone][lookup] = 1;
        }
    }

haraka-tld

Haraka TLD utilities

MIT
Latest version published 1 month ago

Package Health Score

76 / 100
Full package analysis