Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Luciano Barletta
/
message-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 005ad490
authored
2019-09-25 14:31:37 +0000
by
Luciano Barletta
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added cleaner for unsended messages
1 parent
5fe66ea1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
deploy.py
process.py
deploy.py
View file @
005ad49
...
@@ -8,9 +8,11 @@ import time, threading
...
@@ -8,9 +8,11 @@ import time, threading
from
python_arptable
import
get_arp_table
from
python_arptable
import
get_arp_table
import
random
import
random
from
enums
import
States
,
Table
from
enums
import
States
,
Table
import
datetime
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
retry_timer
=
10
retry_timer
=
10
clean_timer
=
20
prefix_lenght
=
16
prefix_lenght
=
16
filename
=
{}
filename
=
{}
...
@@ -32,6 +34,8 @@ def data():
...
@@ -32,6 +34,8 @@ def data():
if
key
!=
None
:
if
key
!=
None
:
key
.
save
(
prefix
+
"_key.enc"
)
key
.
save
(
prefix
+
"_key.enc"
)
request
.
files
[
'data'
]
.
save
(
prefix
+
".enc"
)
request
.
files
[
'data'
]
.
save
(
prefix
+
".enc"
)
else
:
request
.
files
[
'data'
]
.
save
(
prefix
)
filename
[
prefix
]
=
request
.
files
[
'data'
]
.
filename
filename
[
prefix
]
=
request
.
files
[
'data'
]
.
filename
return
prefix
return
prefix
...
@@ -94,10 +98,46 @@ def attempt():
...
@@ -94,10 +98,46 @@ def attempt():
process
.
send
()
process
.
send
()
threading
.
Timer
(
retry_timer
,
attempt
)
.
start
()
threading
.
Timer
(
retry_timer
,
attempt
)
.
start
()
def
clean
():
process
=
Process
(
'messages.db'
)
paths
=
process
.
paths
()
now
=
datetime
.
datetime
.
now
()
# in database (after /msg)
for
file
in
paths
:
mtime
=
os
.
path
.
getmtime
(
file
)
# if the file exists for more than a 23 hs, erase it
if
int
(
now
.
strftime
(
"
%
Y
%
m
%
d
%
H"
))
-
int
(
time
.
strftime
(
"
%
Y
%
m
%
d
%
H"
))
>
23
:
os
.
system
(
"rm "
+
file
)
# in prefixes dictionary (after /data)
for
file
in
filename
:
# not encrypted
if
os
.
path
.
exists
(
file
):
mtime
=
os
.
path
.
getmtime
(
file
)
# if the file exists for more than a 23 hs, erase it
if
int
(
now
.
strftime
(
"
%
Y
%
m
%
d
%
H"
))
-
int
(
time
.
strftime
(
"
%
Y
%
m
%
d
%
H"
))
>
23
:
os
.
system
(
"rm "
+
file
)
filename
.
pop
(
file
)
# encrypted
elif
os
.
path
.
exists
(
file
+
".enc"
):
mtime
=
os
.
path
.
getmtime
(
file
+
".enc"
)
# if the file exists for more than a 23 hs, erase it
if
int
(
now
.
strftime
(
"
%
Y
%
m
%
d
%
H"
))
-
int
(
time
.
strftime
(
"
%
Y
%
m
%
d
%
H"
))
>
23
:
os
.
system
(
"rm "
+
file
+
".enc"
)
os
.
system
(
"rm "
+
file
+
"_key"
)
filename
.
pop
(
file
)
threading
.
Timer
(
clean_timer
,
clean
)
.
start
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# generate keys
# generate keys
os
.
system
(
"openssl genrsa -out rsa_key.pri 4096"
)
# private key
os
.
system
(
"openssl genrsa -out rsa_key.pri 4096"
)
# private key
os
.
system
(
"openssl rsa -in rsa_key.pri -out rsa_key.pub -outform PEM -pubout"
)
# public key
os
.
system
(
"openssl rsa -in rsa_key.pri -out rsa_key.pub -outform PEM -pubout"
)
# public key
# starts attempt daemon
# starts attempt daemon
attempt
()
attempt
()
# starts cleaning daemon
clean
()
app
.
run
(
"0.0.0.0"
)
app
.
run
(
"0.0.0.0"
)
\ No newline at end of file
\ No newline at end of file
process.py
View file @
005ad49
...
@@ -63,3 +63,10 @@ class Process:
...
@@ -63,3 +63,10 @@ class Process:
}
}
self
.
conn
.
insert
(
"history"
,
entities
)
self
.
conn
.
insert
(
"history"
,
entities
)
return
row
return
row
def
paths
(
self
):
rows
=
self
.
conn
.
query
(
"SELECT path FROM msg"
)
paths
=
[]
for
row
in
rows
:
paths
.
append
(
row
[
0
])
return
paths
\ No newline at end of file
\ No newline at end of file
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment