Server vuln improovements

dev-linux
robo-bo 2 years ago
parent b68d1afe2d
commit 0a9a62087d

@ -79,7 +79,7 @@ def ActivityListExecute(inGSettings, inActivityList):
#gSettings #gSettings
lGSettingsDictKey = lActivityItem.pop("ArgGSettings",None) lGSettingsDictKey = lActivityItem.pop("ArgGSettings",None)
# # Prepare arg dict - gSettings # # Prepare arg dict - gSettings
if type(lGSettingsDictKey) is str and lGSettingsDictKey is not "": # check if gSetting key is in ArgDict 13.02.2021 - Fix when ArgGSettings is "" if type(lGSettingsDictKey) is str and lGSettingsDictKey != "": # check if gSetting key is in ArgDict 13.02.2021 - Fix when ArgGSettings is ""
lActivityItem["ArgDict"][lGSettingsDictKey] = inGSettings # Set the gSettings in dict lActivityItem["ArgDict"][lGSettingsDictKey] = inGSettings # Set the gSettings in dict
# # Prepare arg list # # Prepare arg list
elif type(lGSettingsDictKey) is int: # check if gSetting key is in ArgDict elif type(lGSettingsDictKey) is int: # check if gSetting key is in ArgDict
@ -87,7 +87,7 @@ def ActivityListExecute(inGSettings, inActivityList):
#Logger #Logger
lLoggerDictKey = lActivityItem.pop("ArgLogger",None) lLoggerDictKey = lActivityItem.pop("ArgLogger",None)
# # Prepare arg dict - Logger # # Prepare arg dict - Logger
if type(lLoggerDictKey) is str and lLoggerDictKey is not "": # check if gSetting key is in ArgDict 13.02.2021 - Fix when ArgLogger is "" if type(lLoggerDictKey) is str and lLoggerDictKey != "": # check if gSetting key is in ArgDict 13.02.2021 - Fix when ArgLogger is ""
lActivityItem["ArgDict"][lLoggerDictKey] = lL # Set the lLogger in dict lActivityItem["ArgDict"][lLoggerDictKey] = lL # Set the lLogger in dict
# # Prepare arg list # # Prepare arg list
elif type(lLoggerDictKey) is int: # check if gSetting key is in ArgDict elif type(lLoggerDictKey) is int: # check if gSetting key is in ArgDict

@ -506,9 +506,12 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
self.send_response(403) self.send_response(403)
# Send headers # Send headers
self.end_headers() self.end_headers()
except BrokenPipeError as e:
lL = gSettingsDict["Logger"]
if lL: lL.warning(f"Сервер (do_GET): Возникла ошибка сети - BrokenPipeError: [Errno 32] Broken pipe. Сервер продолжает работу")
except Exception as e: except Exception as e:
lL = gSettingsDict["Logger"] lL = gSettingsDict["Logger"]
if lL: lL.exception(f"Server.do_GET: Global error handler - look traceback below.") if lL: lL.exception(f"Сервер (do_GET): Неопознанная ошибка сети - см. текст ошибки. Сервер продолжает работу")
# POST # POST
def do_POST(self): def do_POST(self):
try: try:
@ -608,20 +611,34 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
# Send headers # Send headers
self.end_headers() self.end_headers()
return return
except BrokenPipeError as e:
lL = gSettingsDict["Logger"]
if lL: lL.warning(f"Сервер (do_POST): Возникла ошибка сети - BrokenPipeError: [Errno 32] Broken pipe. Сервер продолжает работу")
except Exception as e: except Exception as e:
lL = gSettingsDict["Logger"] lL = gSettingsDict["Logger"]
if lL: lL.exception(f"Server.do_POST: Global error handler - look traceback below.") if lL: lL.exception(f"Сервер (do_POST): Неопознанная ошибка сети - см. текст ошибки. Сервер продолжает работу")
#Logging #Logging
#!Turn it on to stop print in console #!Turn it on to stop print in console
#def log_message(self, format, *args): #def log_message(self, format, *args):
# return # return
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
daemon_threads = True daemon_threads = True
"""Handle requests in a separate thread.""" """Handle requests in a separate thread."""
def finish_request(self, request, client_address): def finish_request(self, request, client_address):
try:
request.settimeout(gSettingsDict["ServerDict"]["RequestTimeoutSecFloat"]) request.settimeout(gSettingsDict["ServerDict"]["RequestTimeoutSecFloat"])
# "super" can not be used because BaseServer is not created from object # "super" can not be used because BaseServer is not created from object
HTTPServer.finish_request(self, request, client_address) HTTPServer.finish_request(self, request, client_address)
except ConnectionResetError as e:
lL = gSettingsDict["Logger"]
if lL: lL.warning(f"Сервер (finish_request): Возникла ошибка сети - ConnectionResetError: [Errno 104] Connection reset by peer. Сервер продолжает работу")
except Exception as e:
lL = gSettingsDict["Logger"]
if lL: lL.exception(f"Сервер (finish_request): Неопознанная ошибка сети - см. текст ошибки. Сервер продолжает работу")
#inGlobalDict #inGlobalDict
# "JSONConfigurationDict":<JSON> # "JSONConfigurationDict":<JSON>
import ssl import ssl

Loading…
Cancel
Save