Skip to content
Snippets Groups Projects
Commit df296006 authored by leo.muff's avatar leo.muff
Browse files

more frontend :(

parent 1ae1d7f3
No related branches found
No related tags found
1 merge request!3Unsafe
......@@ -206,7 +206,6 @@ dependencies = [
"rocket_sync_db_pools",
"serde",
"sharedlib",
"tera",
]
[[package]]
......
......@@ -9,7 +9,7 @@ edition = "2021"
sharedlib = {path= "../sharedlib"}
rocket = { version = "=0.5.0-rc.3", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
tera = "1.0"
[dependencies.rocket_sync_db_pools]
version = "=0.1.0-rc.3"
......
use rocket::form::Form;
use rocket::response::Redirect;
use rocket::{get, post, uri};
use rocket::{get, post};
use rocket::{State, http::Status, serde::json::Json, response::status};
use std::sync::Mutex;
use crate::backup::DataFile;
use crate::server::{DbConnection , ApiClient, CommandForm, decrypt_bytes, ClientUri};
use crate::server::{DbConnection , ApiClient, CommandForm, decrypt_bytes};
use sharedlib::models::{ApiId, Keys, KeysData, SysInfoData, Command, CommandModel, EncryptedResult};
use rocket_dyn_templates::{Template, context};
use crate::db::*;
......@@ -78,11 +77,11 @@ pub async fn post_systeminfo(db_conn:DbConnection, auth:ApiClient, sysinfo: Json
}
#[post("/newcommand", data="<command>")]
pub async fn post_new_command(db_conn:DbConnection, command : Form<CommandForm>, request_uri: ClientUri) -> Result<Redirect,status::Custom<String>> {
pub async fn post_new_command(db_conn:DbConnection, command : Form<CommandForm>) -> Result<(),status::Custom<String>> {
add_command(&db_conn, command.into_inner()).await?;
Ok(Redirect::to(request_uri.0))
Ok(())
}
#[get("/newcommand/<id>")]
......@@ -109,7 +108,7 @@ pub async fn post_command(db_conn:DbConnection, mut result: Json<EncryptedResult
}
#[get("/deletecommand/<id>")]
pub async fn get_delete_command(db_conn:DbConnection, id:i32, request_uri: ClientUri) -> Result<Redirect,status::Custom<String>> {
pub async fn get_delete_command(db_conn:DbConnection, id:i32) -> Result<(),status::Custom<String>> {
delete_command_by_id(&db_conn, id).await?;
Ok(Redirect::to(request_uri.0))
Ok(())
}
\ No newline at end of file
......@@ -15,15 +15,6 @@ pub struct ApiClient{
pub socketaddr:SocketAddr
}
pub struct ClientUri(pub String);
#[rocket::async_trait]
impl<'r> FromRequest<'r> for ClientUri {
type Error = ApiAuthError;
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error> {
Outcome::Success(ClientUri(req.uri().path().to_string()))
}
}
#[derive(Debug)]
pub enum ApiAuthError {
......
......@@ -40,10 +40,12 @@
</div>
</div>
</div>
<h3 class="mt-5" style="text-align:center">Data sent</h3>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#keys" aria-expanded="false" aria-controls="keys">
<div class="mt-4" style="text-align:center">
<h3 class="mt-5">Data sent</h3>
<button class="btn btn-outline-dark mb-5" type="button" data-bs-toggle="collapse" data-bs-target="#keys" aria-expanded="false" aria-controls="keys">
Show keys
</button>
</div>
<div class="w-75 mx-auto mt-2 collapse" id="keys">
<table class="table" id="data">
<thead>
......
{% extends "base" %}
{% block content %}
<h3> Send commands </h3>
<form action="/newcommand" method="post">
<h3 class="mt-4" style="text-align:center"> Send commands </h3>
<form id="form" action="#" method="post" class="mt-3" style="text-align:center">
<label for="command">Choose a command :</label>
<select id="command" name="command">
{% for c in commands %}
......@@ -10,15 +10,19 @@
</select>
<input type="text" placeholder="Option" name=option id="option" />
<input name="client_id" type="hidden" value={{id}} />
<input type="submit" />
<input type="submit" id="submit" />
<div id="errorMsg" style="display:none;" class="alert alert-danger w-25 mx-auto mt-3" role="alert">
Error sending command
</div>
</form>
<h3> Pending commands </h3>
<table class="table">
<h3 class="mt-4" style="text-align:center"> Pending commands </h3>
<table class="table w-50 border mx-auto mt-3">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Command</th>
<th scope="col">Option</th>
<th></th>
</tr>
</thead>
<tbody>
......@@ -27,13 +31,17 @@
<th scope="row">{{loop.index}}</th>
<td class="mw-20">{{commands[command.command]}}</td>
<td>{{command.option}}</td>
<td><a class="m-2 mb-4 text-center btn btn-secondary active" href="/deletecommand/{{command.id}}"> Delete Command </a></td>
<td>
<div style="text-align:right">
<button class="m-2 mb-4 text-center btn btn-secondary active" value="{{command.id}}" id="delete"> Delete Command </button>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<h3> Commands results </h3>
<table class="table">
<h3 class="mt-4" style="text-align:center"> Commands results </h3>
<table class="table w-75 border mx-auto mt-3">
<thead>
<tr>
<th scope="col">Id</th>
......@@ -52,3 +60,38 @@
</tbody>
</table>
{% endblock content %}
{% block scripts %}
<script src="/static/jquery/jquery-3.7.0.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$('#form').submit(function(e){
e.preventDefault();
$.ajax({
url: '/newcommand',
type : 'post',
data : $('#form').serialize(),
success : function(){
location.reload(true);
},
error : function(){
$("#errorMsg").show();
}
});
});
$('#delete').click(function(e){
e.preventDefault();
$.ajax({
url: '/deletecommand/'+ document.querySelector('#delete').value,
type: 'get',
success:function(){
location.reload(true);
}
});
});
});
</script>
{% endblock scripts %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment