update
This commit is contained in:
@@ -437,6 +437,7 @@ def reset_server_hostname(profile_id):
|
|||||||
print("⚠️Reseting Server Hostname connection ")
|
print("⚠️Reseting Server Hostname connection ")
|
||||||
http_reset_success = False # Default fallback
|
http_reset_success = False # Default fallback
|
||||||
|
|
||||||
|
#Pour AirCarto
|
||||||
if profile_id == 0:
|
if profile_id == 0:
|
||||||
print('<span style="color: orange;font-weight: bold;">🔧 Resetting AirCarto HTTP Profile</span>')
|
print('<span style="color: orange;font-weight: bold;">🔧 Resetting AirCarto HTTP Profile</span>')
|
||||||
command = f'AT+UHTTP={profile_id},1,"data.nebuleair.fr"\r'
|
command = f'AT+UHTTP={profile_id},1,"data.nebuleair.fr"\r'
|
||||||
@@ -447,8 +448,130 @@ def reset_server_hostname(profile_id):
|
|||||||
http_reset_success = response_SARA_5 is not None and "OK" in response_SARA_5
|
http_reset_success = response_SARA_5 is not None and "OK" in response_SARA_5
|
||||||
if not http_reset_success:
|
if not http_reset_success:
|
||||||
print("⚠️ AirCarto HTTP profile reset failed")
|
print("⚠️ AirCarto HTTP profile reset failed")
|
||||||
|
#Pour uSpot
|
||||||
elif profile_id ==1:
|
elif profile_id ==1:
|
||||||
pass # TODO: implement handling for profile 1
|
pass #on utilise la fonction reset_server_hostname_https pour uSpot
|
||||||
|
else:
|
||||||
|
print(f"❌ Unsupported profile ID: {profile_id}")
|
||||||
|
http_reset_success = False
|
||||||
|
return http_reset_success
|
||||||
|
|
||||||
|
def reset_server_hostname_https(profile_id):
|
||||||
|
"""
|
||||||
|
Function that reset server hostname (URL) connection for the SARA R5
|
||||||
|
returns true or false
|
||||||
|
"""
|
||||||
|
print("⚠️Reseting Server Hostname HTTS secure connection ")
|
||||||
|
http_reset_success = False # Default fallback
|
||||||
|
|
||||||
|
#Pour uSpot
|
||||||
|
if profile_id == 1:
|
||||||
|
print('<span style="color: orange;font-weight: bold;">🔧 Resetting uSpot HTTPs Profile</span>')
|
||||||
|
uSpot_url="api-prod.uspot.probesys.net"
|
||||||
|
security_profile_id = 1
|
||||||
|
|
||||||
|
#step 1: import the certificate
|
||||||
|
print("➡️ import certificate")
|
||||||
|
certificate_name = "e6"
|
||||||
|
with open("/var/www/nebuleair_pro_4g/SARA/SSL/certificate/e6.pem", "rb") as cert_file:
|
||||||
|
certificate = cert_file.read()
|
||||||
|
size_of_string = len(certificate)
|
||||||
|
|
||||||
|
# AT+USECMNG=0,<type>,<internal_name>,<data_size>
|
||||||
|
# type-> 0 -> trusted root CA
|
||||||
|
command = f'AT+USECMNG=0,0,"{certificate_name}",{size_of_string}\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=[">"])
|
||||||
|
print(response_SARA_1)
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
print("➡️ add certificate")
|
||||||
|
ser_sara.write(certificate)
|
||||||
|
response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_2)
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
# op_code: 0 -> certificate validation level
|
||||||
|
# param_val : 0 -> Level 0 No validation; 1-> Level 1 Root certificate validation
|
||||||
|
print("➡️Set the security profile (params)")
|
||||||
|
certification_level=0
|
||||||
|
command = f'AT+USECPRF={security_profile_id},0,{certification_level}\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_5b = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5b)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
# op_code: 1 -> minimum SSL/TLS version
|
||||||
|
# param_val : 0 -> any; server can use any version for the connection; 1-> LSv1.0; 2->TLSv1.1; 3->TLSv1.2;
|
||||||
|
print("➡️Set the security profile (params)")
|
||||||
|
minimum_SSL_version = 0
|
||||||
|
command = f'AT+USECPRF={security_profile_id},1,{minimum_SSL_version}\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_5bb = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5bb)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
#op_code: 2 -> legacy cipher suite selection
|
||||||
|
# 0 (factory-programmed value): a list of default cipher suites is proposed at the beginning of handshake process, and a cipher suite will be negotiated among the cipher suites proposed in the list.
|
||||||
|
print("➡️Set cipher")
|
||||||
|
cipher_suite = 0
|
||||||
|
command = f'AT+USECPRF={security_profile_id},2,{cipher_suite}\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_5cc = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5cc)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
# op_code: 3 -> trusted root certificate internal name
|
||||||
|
print("➡️Set the security profile (choose cert)")
|
||||||
|
command = f'AT+USECPRF={security_profile_id},3,"{certificate_name}"\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_5c = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5c)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
# op_code: 10 -> SNI (server name indication)
|
||||||
|
print("➡️Set the SNI")
|
||||||
|
command = f'AT+USECPRF={security_profile_id},10,"{uSpot_url}"\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_5cf = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5cf)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
#step 4: set url (op_code = 1)
|
||||||
|
print("➡️SET URL")
|
||||||
|
command = f'AT+UHTTP={profile_id},1,"{uSpot_url}"\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_5 = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
#step 4: set PORT (op_code = 5)
|
||||||
|
print("➡️SET PORT")
|
||||||
|
port = 443
|
||||||
|
command = f'AT+UHTTP={profile_id},5,{port}\r'
|
||||||
|
ser_sara.write((command + '\r').encode('utf-8'))
|
||||||
|
response_SARA_55 = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_55)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
#step 4: set url to SSL (op_code = 6) (http_secure = 1 for HTTPS)(USECMNG_PROFILE = 2)
|
||||||
|
print("➡️SET SSL")
|
||||||
|
http_secure = 1
|
||||||
|
command = f'AT+UHTTP={profile_id},6,{http_secure},{security_profile_id}\r'
|
||||||
|
|
||||||
|
ser_sara.write(command.encode('utf-8'))
|
||||||
|
response_SARA_5fg = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
print(response_SARA_5fg)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
http_reset_success = response_SARA_5 is not None and "OK" in response_SARA_5
|
||||||
|
if not http_reset_success:
|
||||||
|
print("⚠️ AirCarto HTTP profile reset failed")
|
||||||
|
#Pour uSpot
|
||||||
|
elif profile_id ==1:
|
||||||
|
pass #on utilise la fonction reset_server_hostname_https pour uSpot
|
||||||
else:
|
else:
|
||||||
print(f"❌ Unsupported profile ID: {profile_id}")
|
print(f"❌ Unsupported profile ID: {profile_id}")
|
||||||
http_reset_success = False
|
http_reset_success = False
|
||||||
@@ -1381,9 +1504,16 @@ try:
|
|||||||
# Display interpretation based on error code
|
# Display interpretation based on error code
|
||||||
if error_code == 0:
|
if error_code == 0:
|
||||||
print('<p class="text-success">No error detected</p>')
|
print('<p class="text-success">No error detected</p>')
|
||||||
|
# INVALID SERVER HOSTNAME
|
||||||
elif error_code == 4:
|
elif error_code == 4:
|
||||||
print('<p class="text-danger">Error 4: Invalid server Hostname</p>', end="")
|
print('<p class="text-danger">Error 4: Invalid server Hostname</p>', end="")
|
||||||
send_error_notification(device_id, "UHTTPER (4) uSpot Invalid server Hostname")
|
send_error_notification(device_id, "UHTTPER (4) uSpot Invalid server Hostname")
|
||||||
|
server_hostname_resets = reset_server_hostname_https(uSpot_profile_id)
|
||||||
|
if server_hostname_resets:
|
||||||
|
print("✅server hostname reset successfully")
|
||||||
|
else:
|
||||||
|
print("⛔There were issues with the modem server hostname reinitialize process")
|
||||||
|
# SERVER CONNECTION ERROR
|
||||||
elif error_code == 11:
|
elif error_code == 11:
|
||||||
print('<p class="text-danger">Error 11: Server connection error</p>', end="")
|
print('<p class="text-danger">Error 11: Server connection error</p>', end="")
|
||||||
elif error_code == 22:
|
elif error_code == 22:
|
||||||
@@ -1444,7 +1574,14 @@ try:
|
|||||||
print(f"HTTP response code: {http_response_code}")
|
print(f"HTTP response code: {http_response_code}")
|
||||||
if http_response_code == 201:
|
if http_response_code == 201:
|
||||||
print('<span style="font-weight: bold;">✅✅HTTP 201 ressource created.</span>')
|
print('<span style="font-weight: bold;">✅✅HTTP 201 ressource created.</span>')
|
||||||
|
elif http_response_code == 308:
|
||||||
|
print('<span style="font-weight: bold;"> ⚠️⚠️HTTP 308 Redirect, need to set up HTTPS.</span>')
|
||||||
|
server_hostname_resets = reset_server_hostname_https(uSpot_profile_id)
|
||||||
|
if server_hostname_resets:
|
||||||
|
print("✅server hostname reset successfully")
|
||||||
|
else:
|
||||||
|
print("⛔There were issues with the modem server hostname reinitialize process")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# If any error occurs during parsing, keep the default value
|
# If any error occurs during parsing, keep the default value
|
||||||
print(f"Error parsing HTTP code: {e}")
|
print(f"Error parsing HTTP code: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user