| 
						
						
						
					 | 
					 | 
					@ -1,6 +1,7 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					use crate::db::UDB; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use crate::handlers::Endpoints; | 
					 | 
					 | 
					 | 
					use crate::handlers::Endpoints; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use serde::de::DeserializeOwned; | 
					 | 
					 | 
					 | 
					use serde::de::DeserializeOwned; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use std::env; | 
					 | 
					 | 
					 | 
					use std::path::PathBuf; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use u_lib::{ | 
					 | 
					 | 
					 | 
					use u_lib::{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    messaging::{AsMsg, BaseMessage, Reportable}, | 
					 | 
					 | 
					 | 
					    messaging::{AsMsg, BaseMessage, Reportable}, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    models::*, | 
					 | 
					 | 
					 | 
					    models::*, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -15,7 +16,9 @@ where | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    body::content_length_limit(1024 * 64).and(body::json::<BaseMessage<M>>()) | 
					 | 
					 | 
					 | 
					    body::content_length_limit(1024 * 64).and(body::json::<BaseMessage<M>>()) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					pub fn make_filters() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone { | 
					 | 
					 | 
					 | 
					pub fn init_filters( | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    auth_token: &str, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let infallible_none = |_| async { Ok::<(Option<Uuid>,), std::convert::Infallible>((None,)) }; | 
					 | 
					 | 
					 | 
					    let infallible_none = |_| async { Ok::<(Option<Uuid>,), std::convert::Infallible>((None,)) }; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let get_agents = warp::get() | 
					 | 
					 | 
					 | 
					    let get_agents = warp::get() | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -70,11 +73,7 @@ pub fn make_filters() -> impl Filter<Extract = (impl Reply,), Error = Rejection> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        .and(warp::path("report")) | 
					 | 
					 | 
					 | 
					        .and(warp::path("report")) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        .and(get_content::<Vec<Reportable>>().and_then(Endpoints::report)); | 
					 | 
					 | 
					 | 
					        .and(get_content::<Vec<Reportable>>().and_then(Endpoints::report)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let auth_token = format!( | 
					 | 
					 | 
					 | 
					    let auth_token = format!("Bearer {auth_token}",).into_boxed_str(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        "Bearer {}", | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        env::var("ADMIN_AUTH_TOKEN").expect("No auth token provided") | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    ) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    .into_boxed_str(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let auth_header = warp::header::exact("authorization", Box::leak(auth_token)); | 
					 | 
					 | 
					 | 
					    let auth_header = warp::header::exact("authorization", Box::leak(auth_token)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    let auth_zone = (get_agents | 
					 | 
					 | 
					 | 
					    let auth_zone = (get_agents | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -89,3 +88,32 @@ pub fn make_filters() -> impl Filter<Extract = (impl Reply,), Error = Rejection> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    auth_zone.or(agent_zone) | 
					 | 
					 | 
					 | 
					    auth_zone.or(agent_zone) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					pub fn prefill_jobs() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    let agent_hello = JobMeta::builder() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .with_type(misc::JobType::Manage) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .with_alias("agent_hello") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .build() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .unwrap(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    UDB::lock_db().insert_jobs(&[agent_hello]).unwrap(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					pub fn init_logger() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    use simplelog::*; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    use std::fs::OpenOptions; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    let log_cfg = ConfigBuilder::new() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .set_time_format_str("%x %X") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .set_time_to_local(true) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .build(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    let logfile = OpenOptions::new() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .append(true) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .create(true) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .open(PathBuf::from("logs").join("u_server.log")) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        .unwrap(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    let level = LevelFilter::Info; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    let loggers = vec![ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        WriteLogger::new(level, log_cfg.clone(), logfile) as Box<dyn SharedLogger>, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        TermLogger::new(level, log_cfg, TerminalMode::Stderr, ColorChoice::Auto), | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    ]; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    CombinedLogger::init(loggers).unwrap(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					} |