From fbd3afe00a7ca3aee38eafc27df824c6e245861e Mon Sep 17 00:00:00 2001 From: lucasbutzke Date: Thu, 10 Jul 2025 14:35:27 -0400 Subject: [PATCH] [RTOP-24] Minor fix --- webserver/credentials.py | 3 --- webserver/webserver.py | 27 +++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/webserver/credentials.py b/webserver/credentials.py index e00609b..6f147ac 100644 --- a/webserver/credentials.py +++ b/webserver/credentials.py @@ -80,10 +80,7 @@ class CertGen(): print(f"Certificate saved to {cert_file}") print(f"Private key saved to {key_file}") - # TODO update certificate on cliente before expiration # TODO add a function to update the certificate on the client before expiration - # TODO add a function to check if the certificate is valid (not expired and not yet valid) - # TODO add a function to check if the certificate is already generated def is_certificate_valid(self, cert_file): """ Checks if a certificate is valid (not expired and not yet valid). diff --git a/webserver/webserver.py b/webserver/webserver.py index f7632df..b2fff65 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -2595,9 +2595,19 @@ def run_https(): # Credentials already created else: print("Credentials already generated!") - - context = ('/etc/ssl/certs/certOPENPLC.pem', '/etc/ssl/private/keyOPENPLC.pem') - app_restapi.run(debug=False, host='0.0.0.0', threaded=True, port=8443, ssl_context=context) + + try: + context = ('/etc/ssl/certs/certOPENPLC.pem', '/etc/ssl/private/keyOPENPLC.pem') + app_restapi.run(debug=False, host='0.0.0.0', threaded=True, port=8443, ssl_context=context) + except KeyboardInterrupt as e: + print(f"Exiting OpenPLC Webserver...{e}") + openplc_runtime.stop_runtime() + except Exception as e: + print(f"An error occurred: {e}") + openplc_runtime.stop_runtime() + except: + print("An unexpected error occurred.") + # TODO handle file error except FileNotFoundError as e: print(f"Could not find SSL credentials! {e}") @@ -2638,7 +2648,16 @@ def run_http(): configure_runtime() monitor.parse_st(openplc_runtime.project_file) - app.run(debug=False, host='0.0.0.0', threaded=True, port=8080) + try: + app.run(debug=False, host='0.0.0.0', threaded=True, port=8080) + except KeyboardInterrupt as e: + print(f"Exiting OpenPLC Webserver...{e}") + openplc_runtime.stop_runtime() + except Exception as e: + print(f"An error occurred: {e}") + openplc_runtime.stop_runtime() + except: + print("An unexpected error occurred.") except Error as e: print("error connecting to the database" + str(e))