Skip to content

Commit

Permalink
Merge pull request #486 from nodogsplash/4.3.4beta
Browse files Browse the repository at this point in the history
Implement unescape callback for MHD (libmicrohttpd)
  • Loading branch information
bluewavenet committed Jan 1, 2020
2 parents 41c8752 + 36f94f4 commit b7216b3
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ install:
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/libs/unescape.sh $(DESTDIR)/usr/lib/nodogsplash/
cp forward_authentication_service/fas-aes/fas-aes.php $(DESTDIR)/etc/nodogsplash/

checkastyle:
Expand Down
4 changes: 2 additions & 2 deletions forward_authentication_service/PreAuth/demo-preauth.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#Copyright (C) The Nodogsplash Contributors 2004-2019
#Copyright (C) Blue Wave Projects and Services 2015-2019
#Copyright (C) The Nodogsplash Contributors 2004-2020
#Copyright (C) Blue Wave Projects and Services 2015-2020
#This software is released under the GNU GPL license.

# functions:
Expand Down
14 changes: 14 additions & 0 deletions forward_authentication_service/libs/unescape.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
#Copyright (C) The Nodogsplash Contributors 2004-2020
#Copyright (C) Blue Wave Projects and Services 2015-2020
#This software is released under the GNU GPL license.

option="$1"
inputstr="$2"

if [ "$option" == "-url" ]; then
printf "${inputstr//%/\\x}"
else
echo "Invalid option"
exit 1
fi
1 change: 1 addition & 0 deletions openwrt/nodogsplash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ define Package/nodogsplash/install
$(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/libs/unescape.sh $(1)/usr/lib/nodogsplash/
$(CP) $(PKG_BUILD_DIR)/forward_authentication_service/fas-aes/fas-aes.php $(1)/etc/nodogsplash/
endef

Expand Down
2 changes: 1 addition & 1 deletion openwrt/nodogsplash/files/etc/config/nodogsplash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ config nodogsplash
# Both modes may be customised or a full custom system can be developed using FAS and BinAuth
# See documentation at: https://nodogsplashdocs.readthedocs.io/
#
#option login_option_enabled '1'
option login_option_enabled '0'

# WebRoot
# Default: /etc/nodogsplash/htdocs
Expand Down
2 changes: 1 addition & 1 deletion resources/nodogsplash.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GatewayInterface br-lan
# Both modes may be customised or a full custom system can be developed using FAS and BinAuth
# See documentation at: https://nodogsplashdocs.readthedocs.io/
#
#login_option_enabled 1
login_option_enabled 0


# Option: WebRoot
Expand Down
17 changes: 17 additions & 0 deletions src/http_microhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,20 @@ static int serve_file(struct MHD_Connection *connection, t_client *client, const

return ret;
}

size_t unescape(void * cls, struct MHD_Connection *c, char *src)
{
char unescapecmd[QUERYMAXLEN] = {0};
char msg[QUERYMAXLEN] = {0};

debug(LOG_INFO, "Escaped string=%s\n", src);
snprintf(unescapecmd, QUERYMAXLEN, "/usr/lib/nodogsplash/./unescape.sh -url \"%s\"", src);
debug(LOG_DEBUG, "unescapecmd=%s\n", unescapecmd);

if (execute_ret_url_encoded(msg, sizeof(msg) - 1, unescapecmd) == 0) {
debug(LOG_INFO, "Unescaped string=%s\n", msg);
strcpy(src, msg);
}

return strlen(src);
}
3 changes: 3 additions & 0 deletions src/http_microhttpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define NDS_MICROHTTPD_H

#include <stdio.h>
#include <string.h>

struct MHD_Connection;

Expand All @@ -17,4 +18,6 @@ int libmicrohttpd_cb (void *cls,
const char *upload_data, size_t *upload_data_size, void **ptr);


size_t unescape(void * cls, struct MHD_Connection *c, char *src);

#endif // NDS_MICROHTTPD_H
17 changes: 9 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#include "common.h"
#include "http_microhttpd.h"
#include "http_microhttpd_utils.h"
#include "safe.h"
#include "debug.h"
#include "conf.h"
Expand Down Expand Up @@ -266,14 +267,14 @@ main_loop(void)
debug(LOG_NOTICE, "Detected gateway %s at %s (%s)", config->gw_interface, config->gw_ip, config->gw_mac);

/* Initializes the web server */
if ((webserver = MHD_start_daemon(
MHD_USE_EPOLL_INTERNALLY | MHD_USE_TCP_FASTOPEN,
config->gw_port,
NULL, NULL,
libmicrohttpd_cb, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_LISTENING_ADDRESS_REUSE, 1,
MHD_OPTION_END)) == NULL) {
if ((webserver = MHD_start_daemon(MHD_USE_EPOLL_INTERNALLY | MHD_USE_TCP_FASTOPEN,
config->gw_port,
NULL, NULL,
libmicrohttpd_cb, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_LISTENING_ADDRESS_REUSE, 1,
MHD_OPTION_UNESCAPE_CALLBACK, unescape,
MHD_OPTION_END)) == NULL) {
debug(LOG_ERR, "Could not create web server: %s", strerror(errno));
exit(1);
}
Expand Down

0 comments on commit b7216b3

Please sign in to comment.