mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
better validation
This commit is contained in:
@@ -40,7 +40,7 @@ export const ipInSubnetValidator = (subnet: string | null = null) => {
|
||||
return { invalidIp: 'Not a valid IP Address' }
|
||||
}
|
||||
if (!ipnet) return null
|
||||
return ipnet.contains(ip)
|
||||
return ipnet.zero().cmp(ip) === -1 && ipnet.broadcast().cmp(ip) === 1
|
||||
? null
|
||||
: { notInSubnet: `Address is not part of ${subnet}` }
|
||||
}
|
||||
@@ -48,7 +48,7 @@ export const ipInSubnetValidator = (subnet: string | null = null) => {
|
||||
|
||||
export function getIp({ clients, range }: MappedSubnet) {
|
||||
const net = IpNet.parse(range)
|
||||
const last = net.last()
|
||||
const last = net.broadcast()
|
||||
|
||||
for (let ip = net.add(1); ip.cmp(last) === -1; ip.add(1)) {
|
||||
if (!clients[ip.address]) {
|
||||
|
||||
@@ -135,7 +135,7 @@ export default class Subnets {
|
||||
this.subnets()
|
||||
.map(s => utils.IpNet.parse(s.range))
|
||||
.sort((a, b) => -1 * a.cmp(b))[0] ?? utils.IpNet.parse('10.58.255.0/24')
|
||||
const next = utils.IpNet.fromIpPrefix(last.last().add(2), 24)
|
||||
const next = utils.IpNet.fromIpPrefix(last.broadcast().add(2), 24)
|
||||
if (!next.isPublic()) {
|
||||
return next.ipnet
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user