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 e05a6b80
authored
2020-07-11 14:40:36 -0300
by
Tu Nombre
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
agregado el estado de mails
1 parent
7f882c16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
3 deletions
Wpp1State.py
deploy.py
Wpp1State.py
View file @
e05a6b8
import
requests
,
json
,
config
,
datetime
import
requests
,
json
,
config
,
datetime
,
smtplib
class
StatePhoneWs
():
"""Esta clase consulta el estado de los telefonos y los cachea
...
...
@@ -40,3 +40,52 @@ class StatePhoneWs():
return
(
cel
[
"estado"
])
return
(
False
)
class
StateMail
():
"""Esta clase consulta el estado de los mail server y los cachea
la consulta tiene 60 segundos de valides, para mejorar la perfrmance"""
def
__init__
(
self
):
self
.
Consultas
=
{}
#{MailUSer-pass-host-str(port):{"hora": datetime.datetime.now, "estado": self.chequear_stado_WB(telefono)},}
def
chequear_stado_Server
(
self
,
User
,
Pass
,
Port
,
Host
):
try
:
self
.
SMTPcliente
(
User
,
Pass
,
Port
,
Host
)
consulta
=
True
except
:
consulta
=
False
return
(
consulta
)
def
ChequearMailServer
(
self
,
User
,
Pass
,
Port
,
Host
):
"""Chequea estado es el server remoto si esta conectado se almasena la
respuesta en cache durante 60 segundos para mejorar performance y si no esta
disponible no se almasena y la proxima respuesta debera hacerse contra el server
remoto para asegurarme de q se solucione el problema"""
test
=
self
.
revisarCache
(
User
,
Pass
,
Port
,
Host
)
if
not
test
==
"Vencido"
:
return
(
test
)
W
=
self
.
chequear_stado_Server
(
User
,
Pass
,
Port
,
Host
)
#if False == W:#si hay algun error no actualiso el estado en cache
# return(W)
hora
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
seconds
=
120
)
self
.
Consultas
[
self
.
_GenerarKey
(
User
,
Pass
,
Port
,
Host
)]
=
{
"hora"
:
hora
,
"estado"
:
W
}
return
(
W
)
def
revisarCache
(
self
,
User
,
Pass
,
Port
,
Host
):
if
not
self
.
_GenerarKey
(
User
,
Pass
,
Port
,
Host
)
in
self
.
Consultas
.
keys
():
return
(
"Vencido"
)
cache
=
self
.
Consultas
[
self
.
_GenerarKey
(
User
,
Pass
,
Port
,
Host
)]
if
datetime
.
datetime
.
now
()
<
cache
[
"hora"
]:
return
(
cache
[
"estado"
])
return
(
"Vencido"
)
def
_GenerarKey
(
self
,
User
,
Pass
,
Port
,
Host
):
base
=
"""{}-{}-{}-{}"""
completo
=
base
.
format
(
User
,
Pass
,
str
(
Port
),
Host
)
return
(
completo
)
def
SMTPcliente
(
self
,
User
,
Pass
,
Port
,
Host
):
dg
=
smtplib
.
SMTP
(
host
=
Host
,
port
=
Port
,
timeout
=
10
)
dg
.
starttls
()
dg
.
login
(
User
,
Pass
)
dg
.
quit
()
deploy.py
View file @
e05a6b8
#-*- coding: utf-8 -*-
from
flask
import
Flask
,
render_template
,
json
,
request
,
url_for
from
flask
import
Flask
,
render_template
,
json
,
request
,
url_for
,
jsonify
from
werkzeug.datastructures
import
FileStorage
from
process
import
Process
from
python_arptable
import
get_arp_table
from
enums
import
States
,
Table
from
Wpp1State
import
StatePhoneWs
from
Wpp1State
import
StatePhoneWs
,
StateMail
import
os
,
ipdb
,
time
,
threading
,
random
,
datetime
,
config
...
...
@@ -28,6 +28,7 @@ operation_timer = 86400
process
=
Process
(
"messages.db"
)
#Cache de estado de telefonos
TelState
=
StatePhoneWs
()
MailState
=
StateMail
()
@app.route
(
'/'
)
def
main
():
...
...
@@ -49,6 +50,13 @@ def estadoWabox(tel):
xi
=
TelState
.
ChequearTelefono
(
tel
)
return
(
xi
)
@app.route
(
"/state/mail"
,
methods
=
[
'POST'
])
def
estadoMail
():
datos
=
request
.
json
#print(datos)
test
=
MailState
.
ChequearMailServer
(
datos
[
"user"
],
datos
[
"pass"
],
int
(
datos
[
"port"
]),
datos
[
"host"
])
return
(
str
(
test
))
# Guarda archivos del emisor en una nueva carpeta (desencriptados)
# Pide guardar en base de datos una preinstancia del mensaje
@app.route
(
'/data'
,
methods
=
[
'POST'
])
...
...
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