support CIDR for whitelist
Signed-off-by: Xerxes-2 <dspxue@gmail.com>
This commit is contained in:
parent
1591e0cfe7
commit
cf721e9bb3
5 changed files with 39 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ use crate::video_service;
|
|||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
use crate::{common::DEVICE_NAME, flutter::connection_manager::start_channel};
|
||||
use crate::{ipc, VERSION};
|
||||
use cidr_utils::cidr::IpCidr;
|
||||
use hbb_common::{
|
||||
config::Config,
|
||||
fs,
|
||||
|
|
@ -631,7 +632,10 @@ impl Connection {
|
|||
.is_none()
|
||||
&& whitelist
|
||||
.iter()
|
||||
.filter(|x| x.parse() == Ok(addr.ip()))
|
||||
.filter(|x| match IpCidr::from_str(x) {
|
||||
Ok(cidr) => cidr.contains(addr.ip()),
|
||||
Err(_) => false,
|
||||
})
|
||||
.next()
|
||||
.is_none()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ class MyIdMenu: Reactor.Component {
|
|||
if (value) {
|
||||
var values = value.split(/[\s,;\n]+/g);
|
||||
for (var ip in values) {
|
||||
if (!ip.match(/^\d+\.\d+\.\d+\.\d+$/)) {
|
||||
if (!ip.match(/^\d+\.\d+\.\d+\.\d+(\/\d+)?$/)) {
|
||||
return translate("Invalid IP") + ": " + ip;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue