setstatus.py, statusd.py: timeouts added, change output messages
This commit is contained in:
parent
028f7ae2de
commit
6dc2f04037
2 changed files with 16 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# file: setstatus.py.py
|
# file: setstatus.py
|
||||||
# date: 26.07.2019
|
# date: 26.07.2019
|
||||||
# email: berhsi@web.de
|
# email: berhsi@web.de
|
||||||
|
|
||||||
|
@ -87,13 +87,16 @@ def main(*status):
|
||||||
conn = context.wrap_socket(mySocket, server_side = False, \
|
conn = context.wrap_socket(mySocket, server_side = False, \
|
||||||
server_hostname = SERVER_NAME)
|
server_hostname = SERVER_NAME)
|
||||||
print('Connection wrapped with ssl.context')
|
print('Connection wrapped with ssl.context')
|
||||||
|
conn.settimeout(5.0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Context wrapper failed: [}'.format(e))
|
print('Context wrapper failed: [}'.format(e))
|
||||||
try:
|
try:
|
||||||
conn.connect((HOST, PORT))
|
conn.connect((HOST, PORT))
|
||||||
print('SSL established: {}'.format(conn.getpeercert()))
|
print('Connection established: {}'.format(conn.getpeercert()))
|
||||||
|
except socket.timeout:
|
||||||
|
print('Connection timeout')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('SSL handshake failed: {}'.format(e))
|
print('Connection failed: {}'.format(e))
|
||||||
exit(1)
|
exit(1)
|
||||||
try:
|
try:
|
||||||
print('Send new status: {}'.format(STATUS))
|
print('Send new status: {}'.format(STATUS))
|
||||||
|
|
15
statusd.py
15
statusd.py
|
@ -291,12 +291,17 @@ def main():
|
||||||
fromSocket.settimeout(3.0)
|
fromSocket.settimeout(3.0)
|
||||||
try:
|
try:
|
||||||
conn = context.wrap_socket(fromSocket, server_side = True)
|
conn = context.wrap_socket(fromSocket, server_side = True)
|
||||||
|
conn.settimeout(3.0)
|
||||||
# display_peercert(conn.getpeercert())
|
# display_peercert(conn.getpeercert())
|
||||||
logging.info('SSL connection established')
|
logging.debug('Connection established')
|
||||||
logging.info('commonName: {}'.format(conn.getpeercert()['subject'][5][0][1]))
|
logging.debug('Peer certificate commonName: {}'.format \
|
||||||
logging.info('serialNumber: {}'.format(conn.getpeercert()['serialNumber']))
|
(conn.getpeercert()['subject'][5][0][1]))
|
||||||
|
logging.debug('Peer certificate serialNumber: {}'.format \
|
||||||
|
(conn.getpeercert()['serialNumber']))
|
||||||
|
except socket.timeout:
|
||||||
|
logging.error('Socket timeout')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('SSL handshake failed: {}'.format(e))
|
logging.error('Connection failed: {}'.format(e))
|
||||||
raw_data = conn.recv(1)
|
raw_data = conn.recv(1)
|
||||||
if receive_buffer_is_valid(raw_data) == True:
|
if receive_buffer_is_valid(raw_data) == True:
|
||||||
if change_status(raw_data, CONFIG['API']) == True:
|
if change_status(raw_data, CONFIG['API']) == True:
|
||||||
|
@ -309,7 +314,7 @@ def main():
|
||||||
conn.send(b'\x03')
|
conn.send(b'\x03')
|
||||||
# recive_handle returns false:
|
# recive_handle returns false:
|
||||||
else:
|
else:
|
||||||
logging.info('Inalid argument recived: {}'.format(raw_data))
|
logging.info('Invalid argument recived: {}'.format(raw_data))
|
||||||
logging.debug('Send {} back'.format(b'\x03'))
|
logging.debug('Send {} back'.format(b'\x03'))
|
||||||
if conn:
|
if conn:
|
||||||
conn.send(b'\x03')
|
conn.send(b'\x03')
|
||||||
|
|
Loading…
Reference in a new issue