forked from poz/sudo-parental-control
init
This commit is contained in:
commit
de545c9e4f
5 changed files with 1601 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
1550
Cargo.lock
generated
Normal file
1550
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
8
Cargo.toml
Normal file
8
Cargo.toml
Normal 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
2
Rocket.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[default]
|
||||||
|
log_level = "off"
|
40
src/main.rs
Normal file
40
src/main.rs
Normal 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])
|
||||||
|
}
|
Loading…
Reference in a new issue