mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 00:15:17 +00:00
Accept wider range of IP for proxies and RTC relay
This commit is contained in:
@ -11,4 +11,5 @@ pub mod pdf_utils;
|
||||
pub mod mp3_utils;
|
||||
pub mod mp4_utils;
|
||||
pub mod zip_utils;
|
||||
pub mod webpage_utils;
|
||||
pub mod webpage_utils;
|
||||
pub mod network_utils;
|
28
src/utils/network_utils.rs
Normal file
28
src/utils/network_utils.rs
Normal file
@ -0,0 +1,28 @@
|
||||
//! # Network utilities
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
/// Check whether an IP address matches a given pattern. Pattern can be either:
|
||||
/// * An IP address
|
||||
/// * An IP mask ending with a star (*)
|
||||
///
|
||||
/// ```
|
||||
/// use comunic_server::utils::network_utils::match_ip;
|
||||
///
|
||||
/// assert!(match_ip("127.0.0.1", "127.0.0.1"));
|
||||
/// assert!(!match_ip("127.0.0.1", "127.0.0.2"));
|
||||
/// assert!(match_ip("127.0.0.*", "127.0.0.2"));
|
||||
/// assert!(!match_ip("127.0.0.*", "187.0.0.2"));
|
||||
/// ```
|
||||
///
|
||||
pub fn match_ip(pattern: &str, ip: &str) -> bool {
|
||||
if pattern.eq(ip) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if pattern.ends_with("*") && ip.starts_with(&pattern.replace("*", "")){
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
Reference in New Issue
Block a user