Skip to content

Commit

Permalink
ws add tmp_pass by auth server
Browse files Browse the repository at this point in the history
Signed-off-by: staylightblow8 <[email protected]>
  • Loading branch information
liudf0716 committed Feb 24, 2024
1 parent aa0654a commit 210ef99
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ws_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ process_ws_msg(const char *msg)
json_object *token = json_object_object_get(jobj, "token");
json_object *client_ip = json_object_object_get(jobj, "client_ip");
json_object *client_mac = json_object_object_get(jobj, "client_mac");
json_object *client_name = json_object_object_get(jobj, "client_name");
if(token == NULL || client_ip == NULL || client_mac == NULL){
debug(LOG_ERR, "parse json data failed\n");
debug(LOG_ERR, "auth: parse json data failed\n");
json_object_put(jobj);
return;
}
Expand All @@ -71,10 +72,27 @@ process_ws_msg(const char *msg)
if (client_list_find(client_ip_str, client_mac_str) == NULL) {
t_client *client = client_list_add(client_ip_str, client_mac_str, token_str);
fw_allow(client, FW_MARK_KNOWN);
if (client_name != NULL) {
client->name = strdup(json_object_get_string(client_name));
}
debug(LOG_DEBUG, "fw_allow client: token %s, client_ip %s, client_mac %s\n", token_str, client_ip_str, client_mac_str);
} else {
debug(LOG_DEBUG, "client already exists: token %s, client_ip %s, client_mac %s\n", token_str, client_ip_str, client_mac_str);
}
} else if (strcmp(type_str, "tmp_pass")) {
json_object *client_mac = json_object_object_get(jobj, "client_mac");
json_object *timeout = json_object_object_get(jobj, "timeout");
if (client_mac == NULL) {
debug(LOG_ERR, "temp_pass: parse json data failed\n");
json_object_put(jobj);
return;
}
const char *client_mac_str = json_object_get_string(client_mac);
uint32_t timeout_value = 5*60;
if (timeout != NULL) {
timeout_value = json_object_get_int(timeout);
}
fw_set_mac_temporary(client_mac_str, timeout_value);
} else {
debug(LOG_ERR, "unknown type %s\n", type_str);
}
Expand Down

0 comments on commit 210ef99

Please sign in to comment.