Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Julien David
rdos
Commits
3c921e5f
Commit
3c921e5f
authored
Sep 17, 2020
by
Ismail Moumni
Browse files
edit server_conn
parent
3d1c11a9
Pipeline
#706
failed with stage
in 13 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
3c921e5f
...
...
@@ -21,3 +21,4 @@ tests/__pycache__/__init__.cpython-38.pyc
tests/__pycache__/test_query_valid.cpython-38-pytest-6.0.2.pyc
tests/__pycache__/test_mail.cpython-38-pytest-6.0.2.pyc
softwares/mailer/__init__.py
softwares/server/__init__.py
softwares/server/server.py
View file @
3c921e5f
...
...
@@ -25,22 +25,26 @@ class RdosServer:
serv
.
listen
(
5
)
# accepting the connection from client and getting client IP
conn
,
addr
=
serv
.
accept
()
with
conn
:
print
(
'Connexion acceptee depuis l IP : '
,
addr
)
# Receiving Data from Client
data
=
conn
.
recv
(
4096
)
query
=
(
json
.
loads
(
data
.
decode
(
'utf-8'
)))
print
(
query
)
if
query_valid
(
query
):
Tool
=
__RDOS_Tool__
dt_js
=
json
.
dumps
(
send_param_client
(
__RDOS_Dict__
,
Tool
))
print
(
dt_js
)
conn
.
send
(
bytes
((
dt_js
),
"utf-8"
))
while
True
:
if
conn
:
print
(
'Connexion acceptee depuis l IP : '
,
addr
)
# Receiving Data from Client
data
=
conn
.
recv
(
4096
)
query
=
(
json
.
loads
(
data
.
decode
(
'utf-8'
)))
print
(
query
)
if
query_valid
(
query
):
match
=
verif_param
(
query
)
if
match
==
query
:
print
(
"ok"
)
conn
.
send
(
bytes
(
json
.
dumps
(
match
),
"utf-8"
))
else
:
print
(
'Erreur query : '
)
conn
.
send
(
bytes
(
json
.
dumps
(
match
),
"utf-8"
))
# Function query_valwid matches the query send from client side
# with the the parameter dict
# Function input diction
n
ary from client
# Function input dictionary from client
# Function output boolean true if match else False
def
query_valid
(
data
:
dict
):
if
'parameters'
in
data
:
...
...
@@ -52,8 +56,8 @@ def query_valid(data: dict):
# Function send_param_client send a Dict containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes diction
n
ary and a list of tools
# Function output returns a new diction
n
ary containing arguments
# Function input takes dictionary and a list of tools
# Function output returns a new dictionary containing arguments
# # for db query and list of tools
def
send_param_client
(
__RDOS_Dict__
:
dict
,
__RDOS_Tools__
:
list
):
# req = db.getParameters()
...
...
@@ -61,20 +65,23 @@ def send_param_client(__RDOS_Dict__: dict, __RDOS_Tools__: list):
# Function json_loads changes a json file into a Dict
# Function json_loads returns a
D
icti
n
nary
# Function json_loads returns a
d
icti
o
nary
def
json_to_dict
(
js
):
data
=
json
.
loads
(
js
)
return
data
# Function db_req sends a request to get parameters of tools from database
# Function takes a diction
n
ary for input
# Function takes a dictionary for input
# Function return a Dict containing tool parameters and default parameters
def
db_req
(
tool
:
dict
):
tool_dict
=
db
.
getParameters
(
tool
)
return
tool_dict
# Function match_query_dict matches two dictionaries
# Function input takes 2 dictionaries to match
# Function output return trur if dictionaries matches else raise a value error exception
def
match_query_dict
(
biblio
:
dict
,
data
:
dict
):
if
biblio
is
not
None
and
data
is
not
None
:
return
biblio
.
keys
()
==
data
.
keys
()
...
...
@@ -82,9 +89,9 @@ def match_query_dict(biblio: dict, data: dict):
raise
ValueError
(
"Error Dict Values "
)
# Function match_generator_dict Matches
D
iction
n
ary with a list
# Function input 2 arguments
D
iction
n
ary and query from Server
# Function output true if diction
n
ary keys match list elements else false
# Function match_generator_dict Matches
d
ictionary with a list
# Function input 2 arguments
d
ictionary and query from Server
# Function output true if dictionary keys match list elements else false
def
match_generator_dict
(
biblio
:
dict
,
Genereator
:
list
):
for
a
in
Genereator
:
for
b
in
biblio
.
keys
():
...
...
@@ -93,6 +100,9 @@ def match_generator_dict(biblio: dict, Genereator: list):
return
True
# Function verif_param verifies json send from client to server by matching it with database query
# Function input takes a dictionary
# Function output returns query if it matches with database query keys if not it raises an error
def
verif_param
(
data
:
dict
):
tool
=
data
.
keys
().
strip
(
'[]'
)
s
=
db
.
getParameters
(
data
[
'tool'
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment