diff --git a/labadoor-log/src/lib.rs b/labadoor-log/src/lib.rs index a9da56b..a692ecf 100644 --- a/labadoor-log/src/lib.rs +++ b/labadoor-log/src/lib.rs @@ -37,6 +37,7 @@ pub fn log(cli: &cli::Cli, config: ConfigBuilder) -> Result<(), () cliargs.resource.clone(), cliargs.method.clone(), ); + ret = Ok(()); } }; } diff --git a/labadoor-open/src/lib.rs b/labadoor-open/src/lib.rs index d809f87..67d5a4c 100644 --- a/labadoor-open/src/lib.rs +++ b/labadoor-open/src/lib.rs @@ -6,6 +6,7 @@ pub type Binary = Vec; pub struct OpenArgs { pub auth: BTreeMap, pub hardware: BTreeMap, + pub log: Binary, pub method: String, pub identifier: String, pub resource_shortcut: i8, @@ -36,13 +37,27 @@ fn run_auth(args: &OpenArgs, bin: Binary) -> Result { ret } +fn run_log(args: &OpenArgs, identifier: String, resource: String) -> Result { + let a = labadoor_common::LogBinaryArgs { + time: "time.now()".to_string(), + method: args.method.clone(), + identifier: identifier, + resource: resource, + }; + labadoor_common::run_log(a, args.log.clone()) +} + pub fn open(args: OpenArgs) -> Result<(), ()> { let mut msg = "Not authorized!"; let mut ret = Err(()); + let mut identifier = args.identifier.clone(); + let mut resource = "Null".to_string(); for (method, binary) in args.auth.iter() { let output = run_auth(&args, binary.to_vec()); if let Ok(user) = output { + identifier = user.username; + resource = user.resource.clone(); let resource_bin = args.hardware.get(&user.resource).unwrap(); if let Ok(_) = labadoor_common::run_bin(resource_bin.to_vec()) { msg = "Open sesame!"; @@ -53,5 +68,6 @@ pub fn open(args: OpenArgs) -> Result<(), ()> { } } println!("{}", msg); + run_log(&args, identifier, resource).expect("Could not log event"); ret } diff --git a/labadoor/config.toml b/labadoor/config.toml index 1228c3e..0b46824 100644 --- a/labadoor/config.toml +++ b/labadoor/config.toml @@ -26,6 +26,9 @@ backends = ["csv"] [auth.csv] path = "./labadoor-csv" +[open] +log = [ "/usr/bin/labadoor", "log" ] + [open.auth] labadoor = [ "/usr/bin/labadoor", "auth" ] diff --git a/labadoor/src/cli.rs b/labadoor/src/cli.rs index a44e691..1a50262 100644 --- a/labadoor/src/cli.rs +++ b/labadoor/src/cli.rs @@ -68,6 +68,8 @@ pub struct Open { pub auth: BTreeMap>, #[clap(skip)] pub hardware: BTreeMap>, + #[clap(skip)] + pub log: Option>, pub method: String, pub identifier: String, pub resource_shortcut: i8,