Skip to content

Commit

Permalink
Merge pull request #484 from nodogsplash/4.3.4beta
Browse files Browse the repository at this point in the history
fas: get the client interface connections.
  • Loading branch information
bluewavenet committed Dec 29, 2019
2 parents 19d669b + 423e328 commit 41c8752
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ install:
cp resources/splash.jpg $(DESTDIR)/etc/nodogsplash/htdocs/images/
mkdir -p $(DESTDIR)/usr/lib/nodogsplash
cp forward_authentication_service/PreAuth/demo-preauth.sh $(DESTDIR)/usr/lib/nodogsplash/login.sh
cp forward_authentication_service/libs/get_client_interface.sh $(DESTDIR)/usr/lib/nodogsplash/
cp forward_authentication_service/fas-aes/fas-aes.php $(DESTDIR)/etc/nodogsplash/

checkastyle:
Expand Down
19 changes: 11 additions & 8 deletions forward_authentication_service/libs/get_client_interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ fi

# Get default interface
# This will be the interface NDS is bound to eg. br-lan
clientif=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' ")>0 {printf $3}')
clientlocalif=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' ")>0 {printf $3}')

if [ -z $clientif ]; then
if [ -z $clientlocalif ]; then
# The client has gone offline eg battery saving or switched to another ssid
echo "Client $mac is not online" | logger -p "daemon.info" -s -t "NDS-Library[$pid]"
exit 1
Expand All @@ -57,17 +57,20 @@ interface_list=$(iw dev | awk -F 'Interface ' 'NF>1{printf $2" "}')

# Scan the wireless interfaces on this device for the client mac
for interface in $interface_list; do
macscan=$(iw dev $interface station dump | awk -F " " 'match($s, "'"$mac"'")>0{print $2}')
meshmac=$(iw dev $interface mpp dump | awk -F "$mac " 'NF>1{print $2}')
macscan=$(iw dev $interface station dump | awk -F " " 'match($s, "'"$mac"'")>0{printf $2}')
meshmac=$(iw dev $interface mpp dump | awk -F "$mac " 'NF>1{printf $2}')

if [ ! -z $macscan ]; then
clientif=$interface
break
if [ ! -z "$macscan" ]; then
clientlocalif=$interface
fi

if [ ! -z "$meshmac" ]; then
clientmeshif=$meshmac
fi
done

# Return the local interface the client is using, the mesh node mac address and the local mesh interface
echo "$clientif $meshmac"
echo "$clientlocalif $clientmeshif"

exit 0

1 change: 1 addition & 0 deletions openwrt/nodogsplash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ define Package/nodogsplash/install
$(CP) $(PKG_BUILD_DIR)/openwrt/nodogsplash/files/etc/uci-defaults/40_nodogsplash $(1)/etc/uci-defaults/
$(CP) $(PKG_BUILD_DIR)/openwrt/nodogsplash/files/usr/lib/nodogsplash/restart.sh $(1)/usr/lib/nodogsplash/
$(CP) $(PKG_BUILD_DIR)/forward_authentication_service/PreAuth/demo-preauth.sh $(1)/usr/lib/nodogsplash/login.sh
$(CP) $(PKG_BUILD_DIR)/forward_authentication_service/libs/get_client_interface.sh $(1)/usr/lib/nodogsplash/
$(CP) $(PKG_BUILD_DIR)/forward_authentication_service/fas-aes/fas-aes.php $(1)/etc/nodogsplash/
endef

Expand Down
7 changes: 5 additions & 2 deletions src/http_microhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ static int redirect_to_splashpage(struct MHD_Connection *connection, t_client *c
static char *construct_querystring(t_client *client, char *originurl, char *querystr ) {

char hash[128] = {0};
char clientif[64] = {0};

s_config *config = config_get_config();

Expand All @@ -899,15 +900,17 @@ static char *construct_querystring(t_client *client, char *originurl, char *quer
}

} else if (config->fas_secure_enabled == 2) {
get_client_interface(clientif, sizeof(clientif), client->mac);
snprintf(querystr, QUERYMAXLEN,
"clientip=%s%sclientmac=%s%sgatewayname=%s%stok=%s%sgatewayaddress=%s%sauthdir=%s%soriginurl=%s",
"clientip=%s%sclientmac=%s%sgatewayname=%s%stok=%s%sgatewayaddress=%s%sauthdir=%s%soriginurl=%s%sclientif=%s",
client->ip, QUERYSEPARATOR,
client->mac, QUERYSEPARATOR,
config->gw_name, QUERYSEPARATOR,
client->token, QUERYSEPARATOR,
config->gw_address, QUERYSEPARATOR,
config->authdir, QUERYSEPARATOR,
originurl);
originurl, QUERYSEPARATOR,
clientif);

} else {
snprintf(querystr, QUERYMAXLEN, "?clientip=%s&gatewayname=%s", client->ip, config->gw_name);
Expand Down
18 changes: 18 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ extern unsigned int authenticated_since_start;
extern int created_httpd_threads;
extern int current_httpd_threads;

int get_client_interface(char* clientif, int clientif_len, const char *climac)
{
char *clifcmd = NULL;

safe_asprintf(&clifcmd, "/usr/lib/nodogsplash/./get_client_interface.sh %s", climac);

if (execute_ret_url_encoded(clientif, clientif_len - 1, clifcmd) == 0) {
debug(LOG_DEBUG, "Client Mac Address: %s", climac);
debug(LOG_DEBUG, "Client Connection(s) [localif] [remotemeshnodemac] [localmeshif]: %s", clientif);
} else {
debug(LOG_ERR, "Failed to get client connections - client probably offline");
free (clifcmd);
return -1;
}
free (clifcmd);
return 0;
}


int hash_str(char* hash, int hash_len, const char *src)
{
Expand Down
6 changes: 6 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ time_t get_system_uptime();
/* @brief Returns the hash of a string */
int hash_str(char *buf, int hash_len, const char *src);

/* @brief Returns the client local interface,
* meshnode mac address (null if mesh not present) and
* local mesh interface (null if mesh not present)
*/
int get_client_interface(char* clientif, int clientif_len, const char *climac);

/*
* @brief Mallocs and returns nodogsplash uptime string
*/
Expand Down

0 comments on commit 41c8752

Please sign in to comment.