Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Multiple fixes - now charts and other functions are working properly.…
Browse files Browse the repository at this point in the history
… Added small icon and favicon.

Signed-off-by: thomasfire <[email protected]>
  • Loading branch information
thomasfire committed Jan 9, 2022
1 parent d170fe7 commit 69efffa
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webify"
version = "0.6.0-dev"
version = "0.6.0-beta"
authors = ["thomasfire <[email protected]>"]
edition = "2018"

Expand Down
8 changes: 6 additions & 2 deletions src/autoban_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
Expand Down
18 changes: 12 additions & 6 deletions src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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(),
};

Expand Down Expand Up @@ -234,7 +234,10 @@ pub async fn dashboard_page(id: Identity, info: web::Path<String>, 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)),
Expand Down Expand Up @@ -268,7 +271,7 @@ pub async fn dashboard_page_req(id: Identity, info: web::Path<String>,
}

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) {
Expand All @@ -279,7 +282,10 @@ pub async fn dashboard_page_req(id: Identity, info: web::Path<String>,
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)),
Expand Down Expand Up @@ -319,7 +325,7 @@ pub async fn file_sender(id: Identity, info: web::Path<String>, 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")); }
}
}
};
Expand Down
5 changes: 4 additions & 1 deletion src/file_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ impl FileDevice {
fn get_list(&self, username: &str, payload: &str) -> Result<jsVal, String> {
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());
Expand Down
2 changes: 1 addition & 1 deletion src/printer_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl DeviceRead for PrinterDevice {
}

fn read_status(&self, query: &QCommand) -> Result<jsVal, String> {
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());
}

Expand Down
21 changes: 19 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ fn get_static_file(info: &str, mdata: web::Data<FileCache>) -> Result<HttpRespon
Ok(HttpResponse::Ok().body(format!("{}", static_str)))
}

fn get_static_file_raw(info: &str, mdata: web::Data<FileCache>) -> Result<HttpResponse, Error> {
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<String>, mdata: web::Data<FileCache>) -> Result<HttpResponse, Error> {
get_static_file_raw(&info.0, mdata)
}

async fn responce_static_file(info: web::Path<String>, mdata: web::Data<FileCache>) -> Result<HttpResponse, Error> {
get_static_file(&info.0, mdata)
}
Expand All @@ -39,7 +55,7 @@ async fn responce_static_file(info: web::Path<String>, mdata: web::Data<FileCach
#[derive(Deserialize)]
struct LoginInfo {
username: String,
password: SecStr,
password: String,
}


Expand All @@ -48,7 +64,7 @@ async fn login_handler(form: web::Form<LoginInfo>, 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,
Expand Down Expand Up @@ -161,6 +177,7 @@ pub async fn run_server(a_config: Arc<Mutex<Config>>) {
.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}")
Expand Down
7 changes: 4 additions & 3 deletions src/stat_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RedisPool = r2d2_red::Pool<RedisConnectionManager>;
#[derive(Clone)]
pub struct StatDevice {
redis_pool: RedisPool,
database: Database
database: Database,
}

pub const STAT_CHARTS: [&'static str; 3] = [
Expand All @@ -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<jsVal, String> {
Expand Down Expand Up @@ -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
}))
}
}
Expand Down
Binary file added static/favicon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/favicon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions static/login.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="/static/styles.css" media="screen" />
<link rel="icon" type="image/png" sizes="32x32" href="/rstatic/favicon32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/rstatic/favicon16.png">
<head>
<title>Webify Main</title>
</head>
<body>
<img src="/rstatic/webify.png" height="64" width="64">
<div class="login_form">
<form action="/get_logged_in" method="post" >
<div class="text_field">
Expand Down
2 changes: 2 additions & 0 deletions static/login_success.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="/static/lite.css" media="screen" />
<link rel="icon" type="image/png" sizes="32x32" href="/rstatic/favicon32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/rstatic/favicon16.png">
<head>
<title>Webify Main</title>
</head>
Expand Down
3 changes: 3 additions & 0 deletions static/main.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="/static/styles.css" media="screen" />
<link rel="icon" type="image/png" sizes="32x32" href="/rstatic/favicon32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/rstatic/favicon16.png">
<head>
<title>Webify Main</title>
</head>
<body>
<img src="/rstatic/webify.png" height="64" width="64">
<div class="login_btn">
<a href="/login">Log In</a>
</div>
Expand Down
Binary file added static/webify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/dashboard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
<head>
<title>Webify Dashboard</title>
<link rel="stylesheet" type="text/css" href="/static/dashboard.css" media="screen"/>
<link rel="icon" type="image/png" sizes="32x32" href="/rstatic/favicon32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/rstatic/favicon16.png">
</head>
<body>
<div class="dashboard">
<h2>Dashboard</h2>
<div class="devices">
<div class="devrow">
<div class="devcell">
<img src="/rstatic/webify.png" height="64" width="64"><br>
Available devices: <br>
<ul class="devlist">
{{#each devices as |dev|}}
Expand Down
10 changes: 5 additions & 5 deletions templates/json/chart_cmd_cross_user.hjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const data = {
labels: [{{#each labels as |label|}}{{label}},{{/each}}],
labels: [{{#each labels as |label|}}"{{label}}",{{/each}}],
datasets: [{
label: 'Chart by commands per user',
label: "Chart by commands per user",
data: [{{#each data_values as |dval|}}{{dval}},{{/each}}],
backgroundColor: [
{{#each alpha_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderColor: [
{{#each simple_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderWidth: 1
}]
};
const config = {
type: 'bar',
type: "bar",
data: data,
options: {
scales: {
Expand Down
10 changes: 5 additions & 5 deletions templates/json/chart_command.hjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const data = {
labels: [{{#each labels as |label|}}{{label}},{{/each}}],
labels: [{{#each labels as |label|}}"{{label}}",{{/each}}],
datasets: [{
label: 'Chart by commands',
label: "Chart by commands",
data: [{{#each data_values as |dval|}}{{dval}},{{/each}}],
backgroundColor: [
{{#each alpha_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderColor: [
{{#each simple_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderWidth: 1
}]
};
const config = {
type: 'bar',
type: "bar",
data: data,
options: {
scales: {
Expand Down
10 changes: 5 additions & 5 deletions templates/json/chart_device.hjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const data = {
labels: [{{#each labels as |label|}}{{label}},{{/each}}],
labels: [{{#each labels as |label|}}"{{label}}", {{/each}}],
datasets: [{
label: 'Chart by devices',
label: "Chart by devices",
data: [{{#each data_values as |dval|}}{{dval}},{{/each}}],
backgroundColor: [
{{#each alpha_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderColor: [
{{#each simple_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderWidth: 1
}]
};
const config = {
type: 'bar',
type: "bar",
data: data,
options: {
scales: {
Expand Down
10 changes: 5 additions & 5 deletions templates/json/chart_device_cross_user.hjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const data = {
labels: [{{#each labels as |label|}}{{label}},{{/each}}],
labels: [{{#each labels as |label|}}"{{label}}",{{/each}}],
datasets: [{
label: 'Chart by devices for user',
label: "Chart by devices for user",
data: [{{#each data_values as |dval|}}{{dval}},{{/each}}],
backgroundColor: [
{{#each alpha_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderColor: [
{{#each simple_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderWidth: 1
}]
};
const config = {
type: 'bar',
type: "bar",
data: data,
options: {
scales: {
Expand Down
10 changes: 5 additions & 5 deletions templates/json/chart_user.hjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const data = {
labels: [{{#each labels as |label|}}{{label}},{{/each}}],
labels: [{{#each labels as |label|}}"{{label}}",{{/each}}],
datasets: [{
label: 'Chart by user',
label: "Chart by user",
data: [{{#each data_values as |dval|}}{{dval}},{{/each}}],
backgroundColor: [
{{#each alpha_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderColor: [
{{#each simple_colors as |color|}}
{{color}},
"{{color}}",
{{/each}}
],
borderWidth: 1
}]
};
const config = {
type: 'bar',
type: "bar",
data: data,
options: {
scales: {
Expand Down
Loading

0 comments on commit 69efffa

Please sign in to comment.