Merge pull request #4355 from fufesou/fix/check_privacy_mode_on
Fix/check privacy mode on
This commit is contained in:
		
						commit
						c934bfbbf4
					
				@ -118,15 +118,6 @@ async fn accept_connection_(server: ServerPtr, socket: Stream, secure: bool) ->
 | 
				
			|||||||
    Ok(())
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async fn check_privacy_mode_on(stream: &mut Stream) -> ResultType<()> {
 | 
					 | 
				
			||||||
    if video_service::get_privacy_mode_conn_id() > 0 {
 | 
					 | 
				
			||||||
        let msg_out =
 | 
					 | 
				
			||||||
            crate::common::make_privacy_mode_msg(back_notification::PrivacyModeState::PrvOnByOther);
 | 
					 | 
				
			||||||
        timeout(CONNECT_TIMEOUT, stream.send(&msg_out)).await??;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    Ok(())
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub async fn create_tcp_connection(
 | 
					pub async fn create_tcp_connection(
 | 
				
			||||||
    server: ServerPtr,
 | 
					    server: ServerPtr,
 | 
				
			||||||
    stream: Stream,
 | 
					    stream: Stream,
 | 
				
			||||||
@ -134,8 +125,6 @@ pub async fn create_tcp_connection(
 | 
				
			|||||||
    secure: bool,
 | 
					    secure: bool,
 | 
				
			||||||
) -> ResultType<()> {
 | 
					) -> ResultType<()> {
 | 
				
			||||||
    let mut stream = stream;
 | 
					    let mut stream = stream;
 | 
				
			||||||
    check_privacy_mode_on(&mut stream).await?;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let id = {
 | 
					    let id = {
 | 
				
			||||||
        let mut w = server.write().unwrap();
 | 
					        let mut w = server.write().unwrap();
 | 
				
			||||||
        w.id_count += 1;
 | 
					        w.id_count += 1;
 | 
				
			||||||
 | 
				
			|||||||
@ -322,6 +322,7 @@ impl Connection {
 | 
				
			|||||||
            tx_desktop_ready: _tx_desktop_ready,
 | 
					            tx_desktop_ready: _tx_desktop_ready,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        if !conn.on_open(addr).await {
 | 
					        if !conn.on_open(addr).await {
 | 
				
			||||||
 | 
					            conn.sleep_to_ensure_msg_recved().await;
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        #[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
					        #[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
@ -793,8 +794,22 @@ impl Connection {
 | 
				
			|||||||
        self.send(msg_out).await;
 | 
					        self.send(msg_out).await;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async fn on_open(&mut self, addr: SocketAddr) -> bool {
 | 
					    #[inline]
 | 
				
			||||||
        log::debug!("#{} Connection opened from {}.", self.inner.id, addr);
 | 
					    async fn sleep_to_ensure_msg_recved() {
 | 
				
			||||||
 | 
					        sleep(1.).await;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async fn check_privacy_mode_on(&mut self) -> bool {
 | 
				
			||||||
 | 
					        if video_service::get_privacy_mode_conn_id() > 0 {
 | 
				
			||||||
 | 
					            self.send_login_error("Someone turns on privacy mode, exit")
 | 
				
			||||||
 | 
					                .await;
 | 
				
			||||||
 | 
					            false
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async fn check_whitelist(&mut self, addr: &SocketAddr) -> bool {
 | 
				
			||||||
        let whitelist: Vec<String> = Config::get_option("whitelist")
 | 
					        let whitelist: Vec<String> = Config::get_option("whitelist")
 | 
				
			||||||
            .split(",")
 | 
					            .split(",")
 | 
				
			||||||
            .filter(|x| !x.is_empty())
 | 
					            .filter(|x| !x.is_empty())
 | 
				
			||||||
@ -819,7 +834,17 @@ impl Connection {
 | 
				
			|||||||
                true,
 | 
					                true,
 | 
				
			||||||
                json!({ "ip":addr.ip() }),
 | 
					                json!({ "ip":addr.ip() }),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            sleep(1.).await;
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        true
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async fn on_open(&mut self, addr: SocketAddr) -> bool {
 | 
				
			||||||
 | 
					        log::debug!("#{} Connection opened from {}.", self.inner.id, addr);
 | 
				
			||||||
 | 
					        if !self.check_privacy_mode_on().await {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if !self.check_whitelist(&addr).await {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        self.ip = addr.ip().to_string();
 | 
					        self.ip = addr.ip().to_string();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user