This commit is contained in:
jacekpoz 2024-04-24 22:00:06 +02:00
commit de545c9e4f
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
5 changed files with 1601 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1550
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "sudo-parental-control"
version = "0.1.0"
edition = "2021"
[dependencies]
rocket = { version = "0.5.0", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }

2
Rocket.toml Normal file
View file

@ -0,0 +1,2 @@
[default]
log_level = "off"

40
src/main.rs Normal file
View file

@ -0,0 +1,40 @@
use std::io::Write;
use rocket::serde::{Deserialize, json::Json};
#[macro_use] extern crate rocket;
#[derive(Deserialize)]
struct SudoRequest {
command: String,
username: String,
}
#[post("/", data = "<sudo_request>")]
fn index(sudo_request: Json<SudoRequest>) -> String {
println!("======================WARNING======================");
println!("child {} wants to run the following command with sudo:", sudo_request.username);
println!("{}", sudo_request.command);
println!("======================WARNING======================");
print!("allow child to run command? [y/N] ");
let mut response = String::new();
_ = std::io::stdout().flush();
_ = std::io::stdin().read_line(&mut response);
if response.to_lowercase().starts_with("y") {
return "ok".to_string();
}
print!("give child a reason for the denial: ");
response.clear();
_ = std::io::stdout().flush();
_ = std::io::stdin().read_line(&mut response);
response
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}