Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const mask = util.getstrprop(`${ifacePrefix}.mask`);
const gateway = util.getstrprop(`${ifacePrefix}.gateway`);
const domain = util.getstrprop(`${ifacePrefix}.domain`, 'localdomain');
log.info(`DHCP configuration:\n` +
`interface: ${iface}\n` +
`ipaddress: ${ipaddress}/${mask}\n` +
`dns: ${String(dns)}\n` +
`gateway: ${gateway}\n` +
`domain: ${domain}`);
if (!ipaddress) {
throw new Error(`dhcpd has not given us an address yet`);
}
const block = new Netmask(ipaddress, mask);
const baseMask = block.base + '/' + block.bitmask;
log.info(`base: ${baseMask}`);
// Add basic routing table and DNS
await execThrowOnNonZeroCode(
'ndc',
['network', 'destroy', '100'],
abortPromise,
);
await execThrowOnNonZeroCode(
'ndc',
['network', 'create', '100'],
abortPromise,
);
await execThrowOnNonZeroCode(
whitelist.forEach((entry) => {
if ((entry.indexOf('/') !== -1) || (entry.split('.').length !== 4)) return authorizedBlocks.push(new Netmask(entry))
authorizedAddrs.push(entry)
})
}
export function splitCIDR (cidrToSplitStr, numberOfNetworks) {
const cidrToSplit = new Netmask(cidrToSplitStr)
const numberOfSplits = Math.ceil(Math.log(numberOfNetworks) / Math.log(2))
const newBitmask = cidrToSplit.bitmask + numberOfSplits
if (newBitmask > 32) {
throw new Error(`Could not split CIDR into ${numberOfNetworks} networks: Not enough bits available`)
}
const newCidrBlock = new Netmask(`${cidrToSplit.base}/${newBitmask}`)
const cidrArray = []
for (var i = 0; i < numberOfNetworks; i++) {
cidrArray.push(newCidrBlock.next(i).toString())
}
return cidrArray
}
render() {
var details = new Netmask(this.getPretty());
return (
<div>
<div>
{[...Array(4)].map((x, octet) => (
<span>
<input value="{this.state.octets[octet]}" data-octet="{octet}" type="text">
<span>{octet == '3' ? '/' : '.'}</span>
</span></div></div>
getHosts() {
if ((this.getValidationStateSubnet() === 'success') && (this.getValidationStateMask() === 'success')) {
const hosts = new Netmask(`${this.state.subnet}/${this.state.mask}`);
return hosts.size;
}
}
function findTunInterface() {
ifaces = os.networkInterfaces()
for (k in ifaces) {
for (let addrObj of ifaces[k]) {
cidr = addrObj['cidr']
if (addrObj['family'] == 'IPv4' && !addrObj['internal'] && cidr !== undefined) {
block = new Netmask(cidr)
if (block.contains(tunGw)) {
return {address: addrObj['address'], interface: k}
}
}
}
}
return null
}
getNetworkAddress() {
if ((this.getValidationStateSubnet() === 'success') && (this.getValidationStateMask() === 'success')) {
const networkAddress = new Netmask(`${this.state.subnet}/${this.state.mask}`);
return networkAddress.base;
}
}
const get_random_ip = ()=>{
if (!last_ip)
last_ip = new Netmask('1.1.1.1');
else
last_ip = last_ip.next();
return last_ip.base;
};
const get_ip = (session={})=>{
getNetmask() {
if ((this.getValidationStateSubnet() === 'success') && (this.getValidationStateMask() === 'success')) {
const netMask = new Netmask(`${this.state.subnet}/${this.state.mask}`);
return netMask.mask;
}
}