added Wifi-Settings to WebUI and Config
This commit is contained in:
@@ -492,6 +492,78 @@ uint32_t ConfigSanityCheck(bool autocorrect)
|
||||
if (autocorrect)
|
||||
LubeConfig.CANSource = LubeConfig_defaults.CANSource;
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_ap_ssid, sizeof(LubeConfig.wifi_ap_ssid)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 14);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_ap_ssid, LubeConfig_defaults.wifi_ap_ssid, sizeof(LubeConfig.wifi_ap_ssid));
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_ap_password, sizeof(LubeConfig.wifi_ap_password)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 15);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_ap_password, LubeConfig_defaults.wifi_ap_password, sizeof(LubeConfig.wifi_ap_password));
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_client_ssid, sizeof(LubeConfig.wifi_client_ssid)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 16);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_client_ssid, LubeConfig_defaults.wifi_client_ssid, sizeof(LubeConfig.wifi_client_ssid));
|
||||
}
|
||||
|
||||
if (!validateWiFiString(LubeConfig.wifi_client_password, sizeof(LubeConfig.wifi_client_password)))
|
||||
{
|
||||
SET_BIT(setting_reset_bits, 17);
|
||||
if (autocorrect)
|
||||
strncpy(LubeConfig.wifi_client_password, LubeConfig_defaults.wifi_client_password, sizeof(LubeConfig.wifi_client_password));
|
||||
}
|
||||
// Return the bitmask indicating which settings need to be reset
|
||||
return setting_reset_bits;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Validates whether a given string contains only characters allowed in WiFi SSIDs and passwords.
|
||||
*
|
||||
* This function checks each character in the provided string to ensure
|
||||
* that it contains only characters allowed in WiFi SSIDs and passwords.
|
||||
* It considers characters from 'A' to 'Z', 'a' to 'z', '0' to '9', as well as
|
||||
* the following special characters: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
|
||||
*
|
||||
* @param string Pointer to the string to be validated.
|
||||
* @param size Size of the string including the null-terminator.
|
||||
* @return true if the string contains only allowed characters or is NULL,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool validateWiFiString(char *string, size_t size)
|
||||
{
|
||||
if (string == NULL)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
char c = string[i];
|
||||
if (c == '\0')
|
||||
{
|
||||
// Reached the end of the string, all characters were valid WiFi characters.
|
||||
return true;
|
||||
}
|
||||
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
|
||||
(c >= '0' && c <= '9') || c == '!' || c == '"' || c == '#' ||
|
||||
c == '$' || c == '%' || c == '&' || c == '\'' || c == '(' ||
|
||||
c == ')' || c == '*' || c == '+' || c == ',' || c == '-' ||
|
||||
c == '.' || c == '/' || c == ':' || c == ';' || c == '<' ||
|
||||
c == '=' || c == '>' || c == '?' || c == '@' || c == '[' ||
|
||||
c == '\\' || c == ']' || c == '^' || c == '_' || c == '`' ||
|
||||
c == '{' || c == '|' || c == '}' || c == '~'))
|
||||
{
|
||||
// Found a character that is not a valid WiFi character.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// If the loop completes without finding a null terminator, the string is invalid.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user