Skip to content

Commit

Permalink
Merge pull request #519 from nodogsplash/4.4.1beta
Browse files Browse the repository at this point in the history
Htmlencode gatewayname at startup and cosmetic updates
  • Loading branch information
bluewavenet committed Feb 8, 2020
2 parents 5ec9e8b + dd3d33c commit cfe13c7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion forward_authentication_service/fas-aes/fas-aes.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}
$client_zone_r=explode(" ",trim($clientif));

if ($client_zone_r[1] == "") {
if ( ! isset($client_zone_r[1])) {
$client_zone="LocalZone:".$client_zone_r[0];
} else {
$client_zone="MeshZone:".str_replace(":","",$client_zone_r[1]);
Expand Down Expand Up @@ -160,6 +160,8 @@
#footer
if (isset($gatewayaddress)) {
$image="<img style=\"float:left; width:7em; height:7em;\" src=\"".$imagepath."\">";
} else {
$image="";
}

$footer="<hr>
Expand Down
1 change: 1 addition & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ config_init(void)
config.debuglevel = DEFAULT_DEBUGLEVEL;
config.maxclients = DEFAULT_MAXCLIENTS;
config.gw_name = safe_strdup(DEFAULT_GATEWAYNAME);
config.http_encoded_gw_name = NULL;
config.gw_interface = NULL;
config.gw_iprange = safe_strdup(DEFAULT_GATEWAY_IPRANGE);
config.gw_address = NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ typedef struct {
int daemon; /**< @brief if daemon > 0, use daemon mode */
int debuglevel; /**< @brief Debug information verbosity */
int maxclients; /**< @brief Maximum number of clients allowed */
char *gw_name; /**< @brief Name of the gateway; e.g. its SSID */
char *gw_name; /**< @brief Name of the gateway; e.g. its SSID or a unique identifier for use in a remote FAS */
char *http_encoded_gw_name; /**< @brief http encoded name of the gateway, used as a templated variable in splash.htm */
char *gw_interface; /**< @brief Interface we will manage */
char *gw_iprange; /**< @brief IP range on gw_interface we will manage */
char *gw_ip; /**< @brief Internal IP (v4 or v6) for our web server */
Expand Down
5 changes: 1 addition & 4 deletions src/http_microhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,6 @@ static void replace_variables(
char *denyaction = NULL;
char *authaction = NULL;
char *authtarget = NULL;
char htmlencoded[64] = {0};

sprintf(clientupload, "%llu", client->counters.outgoing);
sprintf(clientdownload, "%llu", client->counters.incoming);
Expand All @@ -1249,8 +1248,6 @@ static void replace_variables(
safe_asprintf(&authtarget, "http://%s/%s/?tok=%s&amp;redir=%s",
config->gw_address, config->authdir, client->token, redirect_url);

htmlentityencode(htmlencoded, sizeof(htmlencoded), config->gw_name, strlen(config->gw_name));

struct template vars[] = {
{"authaction", authaction},
{"denyaction", denyaction},
Expand All @@ -1260,7 +1257,7 @@ static void replace_variables(
{"clientupload", clientupload},
{"clientdownload", clientdownload},
{"gatewaymac", config->gw_mac},
{"gatewayname", htmlencoded},
{"gatewayname", config->http_encoded_gw_name},
{"maxclients", maxclients},
{"nclients", nclients},
{"redir", redirect_url},
Expand Down
10 changes: 9 additions & 1 deletion src/http_microhttpd_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ int htmlentityencode(char *buf, int blen, const char *src, int slen)
{
int i;
int len = 0;
static const char hex[] = "0123456789abcdef";

for (i = 0; (i < slen) && (len < blen); i++) {

if ((len+5) <= blen) {

if (src[i] == '"') {
buf[len++] = '&';
buf[len++] = '#';
Expand Down Expand Up @@ -68,9 +68,12 @@ int htmlentityencode(char *buf, int blen, const char *src, int slen)
buf[len++] = ';';

} else {

buf[len++] = src[i];
}

} else {

len = -1;
debug(LOG_ERR, "Buffer overflow in htmlentityencode");
break;
Expand All @@ -96,6 +99,7 @@ int uh_urldecode(char *buf, int blen, const char *src, int slen)
((x) - 'a' + 10)))

for (i = 0; (i < slen) && (len < blen); i++) {

if (src[i] != '%') {
buf[len++] = src[i];
continue;
Expand All @@ -107,6 +111,7 @@ int uh_urldecode(char *buf, int blen, const char *src, int slen)
buf[len++] = (char)(16 * hex(src[i+1]) + hex(src[i+2]));
i += 2;
}

buf[len] = 0;

return (i == slen) ? len : -1;
Expand All @@ -122,13 +127,16 @@ int uh_urlencode(char *buf, int blen, const char *src, int slen)
static const char hex[] = "0123456789abcdef";

for (i = 0; (i < slen) && (len < blen); i++) {

if (isalnum(src[i]) || (src[i] == '-') || (src[i] == '_') ||
(src[i] == '.') || (src[i] == '~')) {
buf[len++] = src[i];

} else if ((len+3) <= blen) {
buf[len++] = '%';
buf[len++] = hex[(src[i] >> 4) & 15];
buf[len++] = hex[ src[i] & 15];

} else {
len = -1;
debug(LOG_ERR, "Buffer overflow in uh_urlencode");
Expand Down
10 changes: 7 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,14 @@ main_loop(void)
char *preauth_dir = NULL;
struct stat sb;
char loginscript[] = "/usr/lib/nodogsplash/login.sh";
char http_encoded[64] = {0};
time_t sysuptime;

config = config_get_config();

htmlentityencode(http_encoded, sizeof(http_encoded), config->gw_name, strlen(config->gw_name));
config->http_encoded_gw_name = http_encoded;

sysuptime = get_system_uptime ();
debug(LOG_INFO, "main: System Uptime is %li seconds", sysuptime);

Expand Down Expand Up @@ -267,9 +271,9 @@ 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 (config->unescape_callback_enabled == 0) {
debug(LOG_NOTICE, "MHD Unescape Callback is Disabled");

if ((webserver = MHD_start_daemon(MHD_USE_EPOLL_INTERNALLY | MHD_USE_TCP_FASTOPEN,
config->gw_port,
NULL, NULL,
Expand All @@ -283,6 +287,7 @@ main_loop(void)

} else {
debug(LOG_NOTICE, "MHD Unescape Callback is Enabled");

if ((webserver = MHD_start_daemon(MHD_USE_EPOLL_INTERNALLY | MHD_USE_TCP_FASTOPEN,
config->gw_port,
NULL, NULL,
Expand All @@ -299,10 +304,9 @@ main_loop(void)
/* TODO: set listening socket */
debug(LOG_NOTICE, "Created web server on %s", config->gw_address);



if (config->login_option_enabled > 0) {
debug(LOG_NOTICE, "Login option is Enabled.\n");

if (!((stat(loginscript, &sb) == 0) && S_ISREG(sb.st_mode) && (sb.st_mode & S_IXUSR))) {
debug(LOG_ERR, "Login script does not exist or is not executeable: %s", loginscript);
debug(LOG_ERR, "Exiting...");
Expand Down

0 comments on commit cfe13c7

Please sign in to comment.