1
0
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:
2021-10-16 21:55:29 +02:00
parent c782f64602
commit 36bfe8e24e
4 changed files with 34 additions and 3 deletions

View File

@ -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;

View 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
}