From 69efffaa7734dd6187fed368cab73da695d7545d Mon Sep 17 00:00:00 2001 From: thomasfire Date: Sun, 9 Jan 2022 03:28:05 +0300 Subject: [PATCH] Multiple fixes - now charts and other functions are working properly. Added small icon and favicon. Signed-off-by: thomasfire --- Cargo.toml | 2 +- src/autoban_service.rs | 8 ++++++-- src/dashboard.rs | 18 ++++++++++++------ src/file_device.rs | 5 ++++- src/printer_device.rs | 2 +- src/server.rs | 21 +++++++++++++++++++-- src/stat_device.rs | 7 ++++--- static/favicon16.png | Bin 0 -> 1547 bytes static/favicon32.png | Bin 0 -> 2412 bytes static/login.html | 3 +++ static/login_success.html | 2 ++ static/main.html | 3 +++ static/webify.png | Bin 0 -> 5851 bytes templates/dashboard.hbs | 3 +++ templates/json/chart_cmd_cross_user.hjs | 10 +++++----- templates/json/chart_command.hjs | 10 +++++----- templates/json/chart_device.hjs | 10 +++++----- templates/json/chart_device_cross_user.hjs | 10 +++++----- templates/json/chart_user.hjs | 10 +++++----- templates/stat_chart.hbs | 4 ++-- templates/stat_cross_chart.hbs | 4 ++-- templates/stat_status.hbs | 10 +++++----- templates/upload.hbs | 2 ++ 23 files changed, 94 insertions(+), 50 deletions(-) create mode 100644 static/favicon16.png create mode 100644 static/favicon32.png create mode 100644 static/webify.png diff --git a/Cargo.toml b/Cargo.toml index f5c152a..9e23415 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "webify" -version = "0.6.0-dev" +version = "0.6.0-beta" authors = ["thomasfire "] edition = "2018" diff --git a/src/autoban_service.rs b/src/autoban_service.rs index d02dd8d..53456fe 100644 --- a/src/autoban_service.rs +++ b/src/autoban_service.rs @@ -23,7 +23,11 @@ fn perform_autoban(database: &Database, period_to_view: u32, anomaly_f: f64) -> debug!("Attempting to ban: `{}`", to_ban.join(", ")); - database.update_users_ban(&to_ban) + if to_ban.len() > 0 { + database.update_users_ban(&to_ban) + } else { + Ok(()) + } } pub fn run_autoban_svc(database: &Database, config: &Config) { @@ -40,7 +44,7 @@ pub fn run_autoban_svc(database: &Database, config: &Config) { let res = perform_autoban(&db_copy, period_view, anomaly_f); match res { Ok(_) => info!("Autoban successfully made a round"), - Err(err) => error!("Error occured in autoban: {}", err) + Err(err) => error!("Error occurred in autoban: {}", err) }; thread::sleep(Duration::from_secs(period as u64)); } diff --git a/src/dashboard.rs b/src/dashboard.rs index 8237c0b..325414f 100644 --- a/src/dashboard.rs +++ b/src/dashboard.rs @@ -80,7 +80,7 @@ impl Dispatch { file_device: filer, root_device: RootDev::new(database), blog_device: BlogDevice::new(&config.redis_config, database, config.use_scraper), - stat_device: StatDevice::new(database, config) + stat_device: StatDevice::new(database, config), } } @@ -180,7 +180,7 @@ fn get_available_info(dasher: &DashBoard<'_>, username: &str, device: &str) -> j qtype: "S".to_string(), group: "rstatus".to_string(), username: username.to_string(), - command: "".to_string(), + command: "rstatus".to_string(), payload: "".to_string(), }; @@ -234,7 +234,10 @@ pub async fn dashboard_page(id: Identity, info: web::Path, mdata: web::D match mdata.templater.render_template("dashboard.hbs", &json!({ "devices": mdata.database.get_user_devices(&user).unwrap_or(vec![]), - "err": match &inner_template{Ok(_) => "", Err(err) => err}, + "err": match inner_info.get("err") { + Some(v) => v.as_str().unwrap_or(""), + None => match &inner_template{Ok(_) => "", Err(err) => err} + }, "subpage": match &inner_template{Ok(data) => data, Err(_) => ""} })) { Ok(data) => Ok(HttpResponse::Ok().content_type("text/html; charset=utf-8").body(data)), @@ -268,7 +271,7 @@ pub async fn dashboard_page_req(id: Identity, info: web::Path, } let (inner_info, reject) = match mdata.dispatch(&user, info.as_str(), form.0.clone()) { - Ok(d) => (d, RejectReason::Ok as i32) , + Ok(d) => (d, RejectReason::Ok as i32), Err(e) => (json!({"err": format!("Error on getting the available info: {}", e)}), RejectReason::NoAuth as i32) }; match mdata.database.insert_history(&user, info.as_str(), &form.0.command, &form.0.qtype, reject) { @@ -279,7 +282,10 @@ pub async fn dashboard_page_req(id: Identity, info: web::Path, match mdata.templater.render_template("dashboard.hbs", &json!({ "devices": mdata.database.get_user_devices(&user).unwrap_or(vec![]), - "err": match &inner_template{Ok(_) => "", Err(err) => err}, + "err": match inner_info.get("err") { + Some(v) => v.as_str().unwrap_or(""), + None => match &inner_template{Ok(_) => "", Err(err) => err} + }, "subpage": match &inner_template{Ok(data) => data, Err(_) => ""} })) { Ok(data) => Ok(HttpResponse::Ok().content_type("text/html; charset=utf-8").body(data)), @@ -319,7 +325,7 @@ pub async fn file_sender(id: Identity, info: web::Path, mdata: web::Data Ok(htmld) => return Ok(HttpResponse::BadRequest().body(htmld)), Err(err) => { error!("Error on rendering template: {}", err); - return Ok(HttpResponse::InternalServerError().body("Internal error")) } + return Ok(HttpResponse::InternalServerError().body("Internal error")); } } } }; diff --git a/src/file_device.rs b/src/file_device.rs index a26177e..5079af3 100644 --- a/src/file_device.rs +++ b/src/file_device.rs @@ -148,7 +148,10 @@ impl FileDevice { fn get_list(&self, username: &str, payload: &str) -> Result { let filepath = format!("{}/{}", &self.storage, username); if !exists(&filepath) { - return Err("No container was found".to_string()); + match fs::create_dir(&filepath) { + Ok(_) => (), + Err(err) => return Err(format!("No container was found and couldn't create new: {:?}", err)) + }; } if payload.contains("..") { return Err("Bad request".to_string()); diff --git a/src/printer_device.rs b/src/printer_device.rs index ae9cf13..b475202 100644 --- a/src/printer_device.rs +++ b/src/printer_device.rs @@ -216,7 +216,7 @@ impl DeviceRead for PrinterDevice { } fn read_status(&self, query: &QCommand) -> Result { - if &query.group != "rstatus" { + if &query.group != DEV_GROUPS[Devices::Zero as usize][Groups::RStatus as usize].unwrap() { return Err("Error: wrong permission".to_string()); } diff --git a/src/server.rs b/src/server.rs index 4c152bb..ce126d0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -31,6 +31,22 @@ fn get_static_file(info: &str, mdata: web::Data) -> Result) -> Result { + let static_bytes = match mdata.get_ref().clone().get_byte_file(info) { + Ok(res) => res, + Err(err) => { + error!("Error on reading static file: {}", err); + return Ok(HttpResponse::InternalServerError().body(format!("Error on loading raw file"))); + } + }; + + Ok(HttpResponse::Ok().body(static_bytes)) +} + +async fn responce_static_file_raw(info: web::Path, mdata: web::Data) -> Result { + get_static_file_raw(&info.0, mdata) +} + async fn responce_static_file(info: web::Path, mdata: web::Data) -> Result { get_static_file(&info.0, mdata) } @@ -39,7 +55,7 @@ async fn responce_static_file(info: web::Path, mdata: web::Data, id: Identity, mdata: web::Dat debug!("login_handler: {:?}", id.identity()); let nick = form.username.clone(); - let password = form.password.clone(); + let password = SecStr::from(form.password.as_str()); let validated = match mdata.database.validate_user(&nick, &password) { Ok(data) => data, @@ -161,6 +177,7 @@ pub async fn run_server(a_config: Arc>) { .route(web::get().to(dashboard_page))) .service(web::resource("/dashboard/{device}").to(dashboard_page)) .service(web::resource("/static/{path}").to(responce_static_file)) + .service(web::resource("/rstatic/{path}").to(responce_static_file_raw)) .service(web::resource("/download/{path}").to(file_sender)) .service( web::resource("/upload/{path}") diff --git a/src/stat_device.rs b/src/stat_device.rs index 7d6fbce..f23a26f 100644 --- a/src/stat_device.rs +++ b/src/stat_device.rs @@ -17,7 +17,7 @@ type RedisPool = r2d2_red::Pool; #[derive(Clone)] pub struct StatDevice { redis_pool: RedisPool, - database: Database + database: Database, } pub const STAT_CHARTS: [&'static str; 3] = [ @@ -37,7 +37,7 @@ impl StatDevice { let pool = RedisPool::builder().build(manager).unwrap(); run_stat_service(&pool, database, config); run_autoban_svc(database, config); - StatDevice {redis_pool: pool, database: database.clone()} + StatDevice { redis_pool: pool, database: database.clone() } } fn get_chart_data(&self, username: &str, chart_name: &str) -> Result { @@ -98,7 +98,8 @@ impl DeviceRead for StatDevice { return Err("No access to this action".to_string()); } Ok(json!({ - "template": "stat_status.hbs" + "template": "stat_status.hbs", + "username": query.username })) } } diff --git a/static/favicon16.png b/static/favicon16.png new file mode 100644 index 0000000000000000000000000000000000000000..f913ec49269907a4f2fd05635332c6c26a47fa53 GIT binary patch literal 1547 zcmZ{kcTiJV6viK2k+Mh$7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