Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Check keypad codes + unicode check for user/password #488

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ Examples:

### Result of attempted keypad code changes

The result of the last configuration change action will be published to the `configuration/commandResultJson` MQTT topic.<br>
The result of the last keypad change action will be published to the `keypad/commandResultJson` MQTT topic.<br>
Possible values are "noValidPinSet", "keypadControlDisabled", "keypadNotAvailable", "keypadDisabled", "invalidConfig", "invalidJson", "noActionSet", "invalidAction", "noExistingCodeIdSet", "noNameSet", "noValidCodeSet", "noCodeSet", "invalidAllowedFrom", "invalidAllowedUntil", "invalidAllowedFromTime", "invalidAllowedUntilTime", "success", "failed", "timeOut", "working", "notPaired", "error" and "undefined".<br>

## Keypad control (alternative, optional)
Expand Down
2 changes: 1 addition & 1 deletion src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define NUKI_HUB_VERSION "9.02"
#define NUKI_HUB_BUILD "unknownbuildnr"
#define NUKI_HUB_DATE "2024-10-13"
#define NUKI_HUB_DATE "2024-10-15"

#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
Expand Down
615 changes: 336 additions & 279 deletions src/NukiOpenerWrapper.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/NukiOpenerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ class NukiOpenerWrapper : public NukiOpener::SmartlockEventHandler
bool _publishAuthData = false;
bool _clearAuthData = false;
bool _disableNonJSON = false;
bool _checkKeypadCodes = false;
int _nrOfRetries = 0;
int _retryDelay = 0;
int _retryConfigCount = 0;
int _retryLockstateCount = 0;
int64_t _nextRetryTs = 0;
int64_t _invalidCount = 0;
int64_t _lastCodeCheck = 0;
std::vector<uint16_t> _keypadCodeIds;
std::vector<uint32_t> _keypadCodes;
std::vector<uint8_t> _timeControlIds;
std::vector<uint32_t> _authIds;

Expand Down
615 changes: 335 additions & 280 deletions src/NukiWrapper.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/NukiWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ class NukiWrapper : public Nuki::SmartlockEventHandler
int _restartBeaconTimeout = 0; // seconds
bool _publishAuthData = false;
bool _clearAuthData = false;
bool _checkKeypadCodes = false;
int64_t _invalidCount = 0;
int64_t _lastCodeCheck = 0;
std::vector<uint16_t> _keypadCodeIds;
std::vector<uint32_t> _keypadCodes;
std::vector<uint8_t> _timeControlIds;
std::vector<uint32_t> _authIds;

Expand Down
5 changes: 3 additions & 2 deletions src/PreferencesKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#define preference_recon_netw_on_mqtt_discon (char*)"recNtwMqttDis"
#define preference_official_hybrid_actions (char*)"hybridAct"
#define preference_official_hybrid_retry (char*)"hybridRtry"
#define preference_keypad_check_code_enabled (char*)"kpChkEna"

//NOT USER CHANGABLE
#define preference_updater_version (char*)"updVer"
Expand Down Expand Up @@ -284,7 +285,7 @@ class DebugPreferences
preference_network_custom_mdc, preference_network_custom_clk, preference_network_custom_phy, preference_network_custom_addr, preference_network_custom_irq,
preference_network_custom_rst, preference_network_custom_cs, preference_network_custom_sck, preference_network_custom_miso, preference_network_custom_mosi,
preference_network_custom_pwr, preference_network_custom_mdio, preference_ntw_reconfigure, preference_lock_max_auth_entry_count, preference_opener_max_auth_entry_count,
preference_auth_control_enabled, preference_auth_topic_per_entry, preference_auth_info_enabled, preference_auth_max_entries,
preference_auth_control_enabled, preference_auth_topic_per_entry, preference_auth_info_enabled, preference_auth_max_entries, preference_keypad_check_code_enabled
};
std::vector<char*> _redact =
{
Expand All @@ -300,7 +301,7 @@ class DebugPreferences
preference_publish_authdata, preference_publish_debug_info, preference_network_wifi_fallback_disabled, preference_official_hybrid_enabled,
preference_official_hybrid_actions, preference_official_hybrid_retry, preference_conf_info_enabled, preference_disable_non_json, preference_update_from_mqtt,
preference_auth_control_enabled, preference_auth_topic_per_entry, preference_auth_info_enabled, preference_recon_netw_on_mqtt_discon, preference_webserial_enabled,
preference_ntw_reconfigure
preference_ntw_reconfigure, preference_keypad_check_code_enabled
};
std::vector<char*> _bytePrefs =
{
Expand Down
21 changes: 17 additions & 4 deletions src/WebCfgServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,16 @@ bool WebCfgServer::processArgs(AsyncWebServerRequest *request, String& message)
//configChanged = true;
}
}
else if(key == "KPCHECK")
{
if(_preferences->getBool(preference_keypad_check_code_enabled, false) != (value == "1"))
{
_preferences->putBool(preference_keypad_check_code_enabled, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
//configChanged = true;
}
}
else if(key == "KPENA")
{
if(_preferences->getBool(preference_keypad_control_enabled, false) != (value == "1"))
Expand Down Expand Up @@ -2639,15 +2649,15 @@ void WebCfgServer::buildCredHtml(AsyncWebServerRequest *request)
{
_response = "";
buildHtmlHeader();
_response.concat("<form class=\"adapt\" method=\"post\" action=\"savecfg\">");
_response.concat("<form id=\"credfrm\" class=\"adapt\" onsubmit=\"return testcreds();\" method=\"post\" action=\"savecfg\">");
_response.concat("<h3>Credentials</h3>");
_response.concat("<table>");
printInputField("CREDUSER", "User (# to clear)", _preferences->getString(preference_cred_user).c_str(), 30, "", false, true);
printInputField("CREDPASS", "Password", "*", 30, "", true, true);
printInputField("CREDUSER", "User (# to clear)", _preferences->getString(preference_cred_user).c_str(), 30, "id=\"inputuser\"", false, true);
printInputField("CREDPASS", "Password", "*", 30, "id=\"inputpass\"", true, true);
printInputField("CREDPASSRE", "Retype password", "*", 30, "", true);
_response.concat("</table>");
_response.concat("<br><input type=\"submit\" name=\"submit\" value=\"Save\">");
_response.concat("</form>");
_response.concat("</form><script>function testcreds() { var input_user = document.getElementById(\"inputuser\").value; var input_pass = document.getElementById(\"inputpass\").value; var pattern = /^[ -~]*$/; if(!pattern.test(input_user) || !pattern.test(input_pass)) { alert('Only non unicode characters are allowed in username and password'); return false;} else { return true; } }</script>");
if(_nuki != nullptr)
{
_response.concat("<br><br><form class=\"adapt\" method=\"post\" action=\"savecfg\">");
Expand Down Expand Up @@ -2919,6 +2929,7 @@ void WebCfgServer::buildAccLvlHtml(AsyncWebServerRequest *request)
printCheckBox("KPPUB", "Publish keypad entries information", _preferences->getBool(preference_keypad_info_enabled), "");
printCheckBox("KPPER", "Publish a topic per keypad entry and create HA sensor", _preferences->getBool(preference_keypad_topic_per_entry), "");
printCheckBox("KPCODE", "Also publish keypad codes (<span class=\"warning\">Disadvised for security reasons</span>)", _preferences->getBool(preference_keypad_publish_code, false), "");
printCheckBox("KPCHECK", "Allow checking if keypad codes are valid (<span class=\"warning\">Disadvised for security reasons</span>)", _preferences->getBool(preference_keypad_check_code_enabled, false), "");
printCheckBox("KPENA", "Add, modify and delete keypad codes", _preferences->getBool(preference_keypad_control_enabled), "");
}
printCheckBox("TCPUB", "Publish time control entries information", _preferences->getBool(preference_timecontrol_info_enabled), "");
Expand Down Expand Up @@ -3386,6 +3397,8 @@ void WebCfgServer::buildInfoHtml(AsyncWebServerRequest *request)
_response.concat(_preferences->getBool(preference_keypad_topic_per_entry, false) ? "Yes" : "No");
_response.concat("\nPublish Keypad codes: ");
_response.concat(_preferences->getBool(preference_keypad_publish_code, false) ? "Yes" : "No");
_response.concat("\nAllow checking Keypad codes: ");
_response.concat(_preferences->getBool(preference_keypad_check_code_enabled, false) ? "Yes" : "No");
_response.concat("\nMax keypad entries to retrieve: ");
_response.concat(_preferences->getInt(preference_keypad_max_entries, MAX_KEYPAD));
_response.concat("\nPublish timecontrol info: ");
Expand Down