Removed partial password feature
This commit is contained in:
parent
20b1290821
commit
3342de6067
29
src/main.rs
29
src/main.rs
@ -115,8 +115,7 @@ fn main() -> ExitCode {
|
|||||||
let address = args.next();
|
let address = args.next();
|
||||||
let address = address.as_deref().unwrap_or("127.0.0.1:8080");
|
let address = address.as_deref().unwrap_or("127.0.0.1:8080");
|
||||||
let password = args.next();
|
let password = args.next();
|
||||||
let partial_password = args.next();
|
start_server(path, address, password);
|
||||||
start_server(path, address, password, partial_password);
|
|
||||||
ExitCode::FAILURE
|
ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,12 +125,7 @@ fn get_thread_pool_size() -> usize {
|
|||||||
.unwrap_or(4)
|
.unwrap_or(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_server(
|
fn start_server(path: PathBuf, address: &str, password: Option<String>) {
|
||||||
path: PathBuf,
|
|
||||||
address: &str,
|
|
||||||
password: Option<String>,
|
|
||||||
partial_password: Option<String>,
|
|
||||||
) {
|
|
||||||
let Ok(listener) = TcpListener::bind(address) else {
|
let Ok(listener) = TcpListener::bind(address) else {
|
||||||
eprintln!("Invalid bind address {address:?}!");
|
eprintln!("Invalid bind address {address:?}!");
|
||||||
return;
|
return;
|
||||||
@ -160,16 +154,7 @@ fn start_server(
|
|||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
let password = password.clone();
|
let password = password.clone();
|
||||||
let hidden_password = partial_password.clone();
|
pool.execute(move || handle_connection(context, path, stream, password.as_deref()));
|
||||||
pool.execute(move || {
|
|
||||||
handle_connection(
|
|
||||||
context,
|
|
||||||
path,
|
|
||||||
stream,
|
|
||||||
password.as_deref(),
|
|
||||||
hidden_password.as_deref(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +168,6 @@ fn handle_connection(
|
|||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
mut stream: TcpStream,
|
mut stream: TcpStream,
|
||||||
password: Option<&str>,
|
password: Option<&str>,
|
||||||
partial_password: Option<&str>,
|
|
||||||
) {
|
) {
|
||||||
let Some(request) = Request::from(&stream) else {
|
let Some(request) = Request::from(&stream) else {
|
||||||
eprintln!("Invalid request!");
|
eprintln!("Invalid request!");
|
||||||
@ -205,7 +189,6 @@ fn handle_connection(
|
|||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
enum Access {
|
enum Access {
|
||||||
None,
|
None,
|
||||||
Partial,
|
|
||||||
Full,
|
Full,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,9 +206,6 @@ fn handle_connection(
|
|||||||
if input == password {
|
if input == password {
|
||||||
access = Access::Full;
|
access = Access::Full;
|
||||||
cookie = Some(password);
|
cookie = Some(password);
|
||||||
} else if Some(input) == partial_password {
|
|
||||||
access = Access::Partial;
|
|
||||||
cookie = partial_password;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -254,9 +234,6 @@ fn handle_connection(
|
|||||||
if state == password {
|
if state == password {
|
||||||
access = Access::Full;
|
access = Access::Full;
|
||||||
break;
|
break;
|
||||||
} else if Some(state) == partial_password {
|
|
||||||
access = Access::Partial;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user