123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- mod mgrsh;
- use std::io;
- use easy_repl::{command, CommandStatus, Repl};
- use crate::{cfg, logger, syscall};
- use crate::reaper;
- pub fn shell_wait_enter() {
- let stdin = io::stdin();
- let mut sbuf = String::new();
- let _ = stdin.read_line(&mut sbuf);
- }
- pub fn shell_repl() {
- println!("---- yukari maintenance shell ----");
- let repl_bresult = Repl::builder()
- .description(" -- yukari maintenance shell --")
- .prompt("< Maintenance Shell > ")
- .add("print", command! {
- "print what input",
- (msg: String) => |msg:String| {
- println!("{}", msg.as_str());
- Ok(CommandStatus::Done)
- }
- })
- .add("reboot", command! {
- "reboot system",
- () => || {
- syscall::power::safe_reboot();
- }
- })
- .add("shutdown", command! {
- "shutdown system",
- () => || {
- syscall::power::safe_shutdown();
- }
- })
- .add("debug-on", command! {
- "turn on debug printing for yukari",
- () => || {
- logger::set_debug_mode(true);
- Ok(CommandStatus::Done)
- }
- })
- .add("debug-off", command! {
- "turn off debug printing for yukari",
- () => || {
- logger::set_debug_mode(false);
- Ok(CommandStatus::Done)
- }
- })
- .add("get-reaper-counter", command! {
- "print the zombie child reaper working counter",
- () => || {
- println!("{} zombie child reaped.", reaper::get_count());
- Ok(CommandStatus::Done)
- }
- })
- .add("login", command! {
- "login to admin shell",
- (password: String) => |password:String| {
- let bhash = cfg::CFG.blocking_get().get_etc_cfg().secure.bcrypt_password.clone();
- let res = bcrypt::verify(password, &bhash);
- match res {
- Ok(b) => {
- if b {
- mgrsh::mgr_shell();
- }else{
- println!("incorrect password.")
- }
- }
- Err(err) => {
- println!("failed verify password: {:?}", err)
- }
- }
- Ok(CommandStatus::Done)
- }
- })
- .build();
- let mut repl = match repl_bresult {
- Ok(t) => t,
- Err(err) => {
- println!("Maintenance Shell Init Fatal Error: {:?}", err);
- return;
- }
- };
- loop {
- let repl_run_result = repl.run();
- match repl_run_result {
- Ok(_) => {
- println!("[WARN] shouldn't quit this shell");
- println!("shell will restart");
- }
- Err(err) => {
- println!("[ERROR] shell crash by error: {:?}", err);
- println!("shell will restart");
- }
- };
- }
- }
|