Пример #1
0
void
ndsctl_json(int fd)
{
	t_client *client;
	int indx;
	unsigned long int now, durationsecs = 0;
	unsigned long long int download_bytes, upload_bytes;

	now = time(NULL);

	/* Update the client's counters so info is current */
	iptables_fw_counters_update();

	LOCK_CLIENT_LIST();

	cprintf(fd, "{\n\"client_length\": %d,\n", get_client_list_length());

	client = client_get_first_client();
	indx = 0;

	cprintf(fd, "\"clients\":{\n");

	while (client != NULL) {
		cprintf(fd, "\"%s\":{\n", client->mac);
		cprintf(fd, "\"client_id\":%d,\n", indx);
		cprintf(fd, "\"ip\":\"%s\",\n\"mac\":\"%s\",\n", client->ip, client->mac);
		cprintf(fd, "\"added\":%lld,\n", (long long) client->added_time);
		cprintf(fd, "\"active\":%lld,\n", (long long) client->counters.last_updated);
		cprintf(fd, "\"duration\":%lu,\n", now - client->added_time);
		cprintf(fd, "\"token\":\"%s\",\n", client->token ? client->token : "none");
		cprintf(fd, "\"state\":\"%s\",\n", fw_connection_state_as_string(client->fw_connection_state));

		durationsecs = now - client->added_time;
		download_bytes = client->counters.incoming;
		upload_bytes = client->counters.outgoing;

		cprintf(fd, "\"downloaded\":\"%llu\",\n\"avg_down_speed\":\"%.6g\",\n\"uploaded\":\"%llu\",\n\"avg_up_speed\":\"%.6g\"\n",
				download_bytes/1000, ((double)download_bytes)/125/durationsecs,
				upload_bytes/1000, ((double)upload_bytes)/125/durationsecs);

		indx++;
		client = client->next;

		cprintf(fd, "}");
		if(client) {
			cprintf(fd, ",\n");
		}
	}

	cprintf(fd, "}}" );

	UNLOCK_CLIENT_LIST();
}
Пример #2
0
void
ndsctl_clients(int fd)
{
	t_client *client;
	int indx;
	unsigned long int now, durationsecs = 0;
	unsigned long long int download_bytes, upload_bytes;

	now = time(NULL);

	/* Update the client's counters so info is current */
	iptables_fw_counters_update();

	LOCK_CLIENT_LIST();

	cprintf(fd, "%d\n", get_client_list_length());

	client = client_get_first_client();
	if(client) {
		cprintf(fd, "\n");
	}

	indx = 0;
	while (client != NULL) {
		cprintf(fd, "client_id=%d\n", indx);
		cprintf(fd, "ip=%s\nmac=%s\n", client->ip, client->mac);
		cprintf(fd, "added=%lld\n", (long long) client->added_time);
		cprintf(fd, "active=%lld\n", (long long) client->counters.last_updated);
		cprintf(fd, "duration=%lu\n", now - client->added_time);
		cprintf(fd, "token=%s\n", client->token ? client->token : "none");
		cprintf(fd, "state=%s\n", fw_connection_state_as_string(client->fw_connection_state));

		durationsecs = now - client->added_time;
		download_bytes = client->counters.incoming;
		upload_bytes = client->counters.outgoing;

		cprintf(fd, "downloaded=%llu\navg_down_speed=%.6g\nuploaded=%llu\navg_up_speed=%.6g\n\n",
				download_bytes/1000, ((double)download_bytes)/125/durationsecs,
				upload_bytes/1000, ((double)upload_bytes)/125/durationsecs);

		indx++;
		client = client->next;
	}

	UNLOCK_CLIENT_LIST();
}
Пример #3
0
/* Pipe the splash page from the splash page file,
 * or redirect to remote authenticator as required.
 */
void
http_nodogsplash_serve_splash(request *r, t_auth_target *authtarget, t_client *client, const char error_msg[])
{
	char *tmpstr;
	char line [MAX_BUF];
	char *splashfilename;
	FILE *fd;
	s_config	*config;

	config = config_get_config();

	if(config->remote_auth_action) {
		/* Redirect to remote auth server instead of serving local splash page */
		http_nodogsplash_redirect_remote_auth(r, authtarget);
		return;
	}

	/* Set variables; these can be interpolated in the splash page text. */
	if (error_msg)
		httpdAddVariable(r,"error_msg", error_msg);
	else
		httpdAddVariable(r,"error_msg", "");
	httpdAddVariable(r,"gatewayname",config->gw_name);
	httpdAddVariable(r,"tok",authtarget->token);
	httpdAddVariable(r,"redir",authtarget->redir);
	httpdAddVariable(r,"authaction",authtarget->authaction);
	httpdAddVariable(r,"denyaction",authtarget->denyaction);
	httpdAddVariable(r,"authtarget",authtarget->authtarget);
	httpdAddVariable(r,"clientip",client->ip);
	httpdAddVariable(r,"clientmac",client->mac);
	httpdAddVariable(r,"gatewaymac",config->gw_mac);
	safe_asprintf(&tmpstr, "%d", get_client_list_length());
	httpdAddVariable(r,"nclients",tmpstr);
	free(tmpstr);
	safe_asprintf(&tmpstr, "%d", config->maxclients);
	httpdAddVariable(r,"maxclients",tmpstr);
	free(tmpstr);
	tmpstr = get_uptime_string();
	httpdAddVariable(r,"uptime",tmpstr);
	free(tmpstr);
	/* We need to have imagesdir and pagesdir appear in the page
	   as absolute paths, so they work no matter what the
	   initial user request URL was  */
	safe_asprintf(&tmpstr, "/%s", config->imagesdir);
	httpdAddVariable(r,"imagesdir",tmpstr);
	free(tmpstr);
	safe_asprintf(&tmpstr, "/%s", config->pagesdir);
	httpdAddVariable(r,"pagesdir",tmpstr);
	free(tmpstr);


	/* Pipe the splash page from its file */
	safe_asprintf(&splashfilename, "%s/%s", config->webroot, config->splashpage );
	debug(LOG_INFO,"Serving splash page %s to %s",
		  splashfilename,r->clientAddr);
	if (!(fd = fopen(splashfilename, "r"))) {
		debug(LOG_ERR, "Could not open splash page file '%s'", splashfilename);
		http_nodogsplash_serve_info(r, "Nodogsplash Error",
									"Failed to open splash page");
	} else {
		while (fgets(line, MAX_BUF, fd)) {
			httpdOutput(r,line);
		}
		fclose(fd);
	}

	free(splashfilename);
}
Пример #4
0
/*
 * @return A string containing json clients list.
 */
char *
get_clients_json(void)
{
	char buffer[STATUS_BUF_SIZ];
	ssize_t len;
	t_client *client;
	int	   indx;
	unsigned long int now, durationsecs = 0;
	unsigned long long int download_bytes, upload_bytes;

	now = time(NULL);
	len = 0;

	/* Update the client's counters so info is current */
	iptables_fw_counters_update();

	LOCK_CLIENT_LIST();

	snprintf((buffer + len), (sizeof(buffer) - len), "{\n\"client_length\": %d,\n", get_client_list_length());
	len = strlen(buffer);

	client = client_get_first_client();
	indx = 0;

	snprintf((buffer + len), (sizeof(buffer) - len), "\"clients\":{\n");
	len = strlen(buffer);
	
	while (client != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\"%s\":{\n", client->mac);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"client_id\":%d,\n", indx);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"ip\":\"%s\",\n\"mac\":\"%s\",\n", client->ip, client->mac);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"added\":%lld,\n", (long long) client->added_time);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"active\":%lld,\n", (long long) client->counters.last_updated);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"duration\":%lu,\n", now - client->added_time);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"token\":\"%s\",\n", client->token ? client->token : "none");
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "\"state\":\"%s\",\n",
				 fw_connection_state_as_string(client->fw_connection_state));
		len = strlen(buffer);

		durationsecs = now - client->added_time;
		download_bytes = client->counters.incoming;
		upload_bytes = client->counters.outgoing;

		snprintf((buffer + len), (sizeof(buffer) - len),
				 "\"downloaded\":\"%llu\",\n\"avg_down_speed\":\"%.6g\",\n\"uploaded\":\"%llu\",\n\"avg_up_speed\":\"%.6g\"\n",
				 download_bytes/1000, ((double)download_bytes)/125/durationsecs,
				 upload_bytes/1000, ((double)upload_bytes)/125/durationsecs);
		len = strlen(buffer);

		indx++;
		client = client->next;

		snprintf((buffer + len), (sizeof(buffer) - len), "}");
		len = strlen(buffer);

		if(client) {
			snprintf((buffer + len), (sizeof(buffer) - len), ",\n");
			len = strlen(buffer);
		}

	}

	snprintf((buffer + len), (sizeof(buffer) - len), "}}" );
	len = strlen(buffer);

	UNLOCK_CLIENT_LIST();

	return safe_strdup(buffer);
}
Пример #5
0
/*
 * @return A string containing human-readable status text.
 * MUST BE free()d by caller
 */
char *
get_status_text()
{
	char buffer[STATUS_BUF_SIZ];
	char timebuf[32];
	char * str;
	ssize_t len;
	s_config *config;
	t_client *client;
	int	   indx;
	unsigned long int now, uptimesecs, durationsecs = 0;
	unsigned long long int download_bytes, upload_bytes;
	t_MAC *trust_mac;
	t_MAC *allow_mac;
	t_MAC *block_mac;

	config = config_get_config();

	len = 0;
	snprintf(buffer, (sizeof(buffer) - len), "==================\nNoDogSplash Status\n====\n");
	len = strlen(buffer);

	now = time(NULL);
	uptimesecs = now - started_time;

	snprintf((buffer + len), (sizeof(buffer) - len), "Version: " VERSION "\n");
	len = strlen(buffer);

	str = format_time(uptimesecs);
	snprintf((buffer + len), (sizeof(buffer) - len), "Uptime: %s\n", str);
	len = strlen(buffer);
	free(str);

	snprintf((buffer + len), (sizeof(buffer) - len), "Gateway Name: %s\n", config->gw_name);
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Managed interface: %s\n", config->gw_interface);
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Managed IP range: %s\n", config->gw_iprange);
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Server listening: %s:%d\n",
			 config->gw_address, config->gw_port);
	len = strlen(buffer);

	if(config->authenticate_immediately) {
		snprintf((buffer + len), (sizeof(buffer) - len), "Authenticate immediately: yes\n");
		len = strlen(buffer);

	} else {
		snprintf((buffer + len), (sizeof(buffer) - len), "Splashpage: %s/%s\n",
				 config->webroot, config->splashpage);
		len = strlen(buffer);
	}

	if(config->redirectURL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "Redirect URL: %s\n",
				 config->redirectURL);
		len = strlen(buffer);
	}

	if(config->passwordauth) {
		snprintf((buffer + len), (sizeof(buffer) - len), "Gateway password: %s\n",
				 config->password);
		len = strlen(buffer);
	}

	if(config->usernameauth) {
		snprintf((buffer + len), (sizeof(buffer) - len), "Gateway username: %s\n",
				 config->username);
		len = strlen(buffer);
	}

	snprintf((buffer + len), (sizeof(buffer) - len), "Traffic control: %s\n", config->traffic_control ? "yes" : "no");
	len = strlen(buffer);

	if(config->traffic_control) {
		if(config->download_limit > 0) {
			snprintf((buffer + len), (sizeof(buffer) - len), "Download rate limit: %d kbit/s\n", config->download_limit);
			len = strlen(buffer);
		} else {
			snprintf((buffer + len), (sizeof(buffer) - len), "Download rate limit: none\n");
			len = strlen(buffer);
		}
		if(config->upload_limit > 0) {
			snprintf((buffer + len), (sizeof(buffer) - len), "Upload rate limit: %d kbit/s\n", config->upload_limit);
			len = strlen(buffer);
		} else {
			snprintf((buffer + len), (sizeof(buffer) - len), "Upload rate limit: none\n");
			len = strlen(buffer);
		}
	}

	download_bytes = iptables_fw_total_download();
	snprintf((buffer + len), (sizeof(buffer) - len), "Total download: %llu kByte", download_bytes/1000);
	len = strlen(buffer);
	snprintf((buffer + len), (sizeof(buffer) - len), "; avg: %.6g kbit/s\n", ((double) download_bytes) / 125 / uptimesecs);
	len = strlen(buffer);

	upload_bytes = iptables_fw_total_upload();
	snprintf((buffer + len), (sizeof(buffer) - len), "Total upload: %llu kByte", upload_bytes/1000);
	len = strlen(buffer);
	snprintf((buffer + len), (sizeof(buffer) - len), "; avg: %.6g kbit/s\n", ((double) upload_bytes) / 125 / uptimesecs);
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "====\n");
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Client authentications since start: %u\n", authenticated_since_start);
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Httpd request threads created/current: %d/%d\n", created_httpd_threads, current_httpd_threads);
	len = strlen(buffer);

	if(config->decongest_httpd_threads) {
		snprintf((buffer + len), (sizeof(buffer) - len), "Httpd thread decongest threshold: %d threads\n", config->httpd_thread_threshold);
		len = strlen(buffer);
		snprintf((buffer + len), (sizeof(buffer) - len), "Httpd thread decongest delay: %d ms\n", config->httpd_thread_delay_ms);
		len = strlen(buffer);
	}

	/* Update the client's counters so info is current */
	iptables_fw_counters_update();

	LOCK_CLIENT_LIST();

	snprintf((buffer + len), (sizeof(buffer) - len), "Current clients: %d\n", get_client_list_length());
	len = strlen(buffer);

	client = client_get_first_client();
	if(client) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\n");
		len = strlen(buffer);
	}
	indx = 0;
	while (client != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "Client %d\n", indx);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "  IP: %s MAC: %s\n", client->ip, client->mac);
		len = strlen(buffer);

		ctime_r(&(client->added_time),timebuf);
		snprintf((buffer + len), (sizeof(buffer) - len), "  Added:   %s", timebuf);
		len = strlen(buffer);

		ctime_r(&(client->counters.last_updated),timebuf);
		snprintf((buffer + len), (sizeof(buffer) - len), "  Active:  %s", timebuf);
		len = strlen(buffer);

		str = format_time(client->counters.last_updated - client->added_time);
		snprintf((buffer + len), (sizeof(buffer) - len), "  Active duration: %s\n", str);
		len = strlen(buffer);
		free(str);

		durationsecs = now - client->added_time;

		str = format_time(durationsecs);
		snprintf((buffer + len), (sizeof(buffer) - len), "  Added duration:  %s\n", str);
		len = strlen(buffer);
		free(str);

		snprintf((buffer + len), (sizeof(buffer) - len), "  Token: %s\n", client->token ? client->token : "none");
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "  State: %s\n",
				 fw_connection_state_as_string(client->fw_connection_state));
		len = strlen(buffer);

		download_bytes = client->counters.incoming;
		upload_bytes = client->counters.outgoing;

		snprintf((buffer + len), (sizeof(buffer) - len),
				 "  Download: %llu kByte; avg: %.6g kbit/s\n  Upload:   %llu kByte; avg: %.6g kbit/s\n\n",
				 download_bytes/1000, ((double)download_bytes)/125/durationsecs,
				 upload_bytes/1000, ((double)upload_bytes)/125/durationsecs);
		len = strlen(buffer);

		indx++;
		client = client->next;
	}

	UNLOCK_CLIENT_LIST();

	snprintf((buffer + len), (sizeof(buffer) - len), "====\n");
	len = strlen(buffer);

	snprintf((buffer + len), (sizeof(buffer) - len), "Blocked MAC addresses:");
	len = strlen(buffer);

	if(config->macmechanism == MAC_ALLOW) {
		snprintf((buffer + len), (sizeof(buffer) - len), " N/A\n");
		len = strlen(buffer);
	} else  if (config->blockedmaclist != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\n");
		len = strlen(buffer);
		for (block_mac = config->blockedmaclist; block_mac != NULL; block_mac = block_mac->next) {
			snprintf((buffer + len), (sizeof(buffer) - len), "  %s\n", block_mac->mac);
			len = strlen(buffer);
		}
	} else {
		snprintf((buffer + len), (sizeof(buffer) - len), " none\n");
		len = strlen(buffer);
	}

	snprintf((buffer + len), (sizeof(buffer) - len), "Allowed MAC addresses:");
	len = strlen(buffer);

	if(config->macmechanism == MAC_BLOCK) {
		snprintf((buffer + len), (sizeof(buffer) - len), " N/A\n");
		len = strlen(buffer);
	} else  if (config->allowedmaclist != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\n");
		len = strlen(buffer);
		for (allow_mac = config->allowedmaclist; allow_mac != NULL; allow_mac = allow_mac->next) {
			snprintf((buffer + len), (sizeof(buffer) - len), "  %s\n", allow_mac->mac);
			len = strlen(buffer);
		}
	} else {
		snprintf((buffer + len), (sizeof(buffer) - len), " none\n");
		len = strlen(buffer);
	}

	snprintf((buffer + len), (sizeof(buffer) - len), "Trusted MAC addresses:");
	len = strlen(buffer);

	if (config->trustedmaclist != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\n");
		len = strlen(buffer);
		for (trust_mac = config->trustedmaclist; trust_mac != NULL; trust_mac = trust_mac->next) {
			snprintf((buffer + len), (sizeof(buffer) - len), "  %s\n", trust_mac->mac);
			len = strlen(buffer);
		}
	} else {
		snprintf((buffer + len), (sizeof(buffer) - len), " none\n");
		len = strlen(buffer);
	}

	snprintf((buffer + len), (sizeof(buffer) - len), "========\n");
	len = strlen(buffer);

	return safe_strdup(buffer);
}
Пример #6
0
/*
 * @return A string containing machine-readable clients list.
 * MUST BE free()d by caller
 */
char * get_clients_text()
{
	char buffer[STATUS_BUF_SIZ];
	ssize_t len;
	t_client *client;
	int	   indx;
	unsigned long int now, durationsecs = 0;
	unsigned long long int download_bytes, upload_bytes;

	now = time(NULL);
	len = 0;

	/* Update the client's counters so info is current */
	iptables_fw_counters_update();

	LOCK_CLIENT_LIST();

	snprintf((buffer + len), (sizeof(buffer) - len), "%d\n", get_client_list_length());
	len = strlen(buffer);

	client = client_get_first_client();
	if(client) {
		snprintf((buffer + len), (sizeof(buffer) - len), "\n");
		len = strlen(buffer);
	}
	indx = 0;
	while (client != NULL) {
		snprintf((buffer + len), (sizeof(buffer) - len), "client_id=%d\n", indx);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "ip=%s\nmac=%s\n", client->ip, client->mac);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "added=%d\n", client->added_time);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "active=%d\n", client->counters.last_updated);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "duration=%d\n", now - client->added_time);
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "token=%s\n", client->token ? client->token : "none");
		len = strlen(buffer);

		snprintf((buffer + len), (sizeof(buffer) - len), "state=%s\n",
				 fw_connection_state_as_string(client->fw_connection_state));
		len = strlen(buffer);

		durationsecs = now - client->added_time;
		download_bytes = client->counters.incoming;
		upload_bytes = client->counters.outgoing;

		snprintf((buffer + len), (sizeof(buffer) - len),
				 "downloaded=%llu\navg_down_speed=%.6g\nuploaded=%llu\navg_up_speed=%.6g\n\n",
				 download_bytes/1000, ((double)download_bytes)/125/durationsecs,
				 upload_bytes/1000, ((double)upload_bytes)/125/durationsecs);
		len = strlen(buffer);

		indx++;
		client = client->next;
	}

	UNLOCK_CLIENT_LIST();

	return safe_strdup(buffer);
}
Пример #7
0
/**
 * @brief show_splashpage is called when the client clicked on Ok as well when the client doesn't know us yet.
 * @param connection
 * @param client
 * @return
 */
static int show_splashpage(struct MHD_Connection *connection, t_client *client)
{
	struct MHD_Response *response;
	struct templater templor;
	s_config *config = config_get_config();
	int ret = -1;
	char filename[PATH_MAX];
	const char *mimetype;
	int size = 0, bytes = 0;
	int splashpage_fd;
	char *splashpage_result;
	char *splashpage_tmpl;

	snprintf(filename, PATH_MAX, "%s/%s",config->webroot ,config->splashpage);

	splashpage_fd = open(filename, O_RDONLY);
	if (splashpage_fd < 0)
		return send_error(connection, 404);

	mimetype = lookup_mimetype(filename);

	/* input size */
	size = lseek(splashpage_fd, 0, SEEK_END);
	lseek(splashpage_fd, 0, SEEK_SET);

	/* we TMPLVAR_SIZE for template variables */
	splashpage_tmpl = calloc(1, size);
	splashpage_result = calloc(1, size + TMPLVAR_SIZE);

	while (bytes < size) {
		ret = read(splashpage_fd, splashpage_tmpl+bytes, size-bytes);
		if (ret < 0) {
			free(splashpage_result);
			free(splashpage_tmpl);
			close(splashpage_fd);
			return send_error(connection, 503);
		}
		bytes += ret;
	}

	char *uptime = get_uptime_string();
	char *nclients = NULL;
	char *maxclients = NULL;
	char *denyaction = NULL;
	char *authaction = NULL;
	char *authtarget = NULL;
	const char *redirect_url = NULL;
	char redirect_url_encoded[2048];
	char *imagesdir = NULL;
	char *pagesdir = NULL;

	memset(redirect_url_encoded, 0, sizeof(redirect_url_encoded));
	redirect_url = get_redirect_url(connection);
	if (redirect_url) {
		uh_urlencode(redirect_url_encoded, sizeof(redirect_url_encoded), redirect_url, strlen(redirect_url));
	}

	safe_asprintf(&nclients, "%d", get_client_list_length());
	safe_asprintf(&maxclients, "%d", config->maxclients);
	safe_asprintf(&denyaction, "http://%s:%d/%s/", config->gw_address, config->gw_port, config->denydir);
	safe_asprintf(&authaction, "http://%s:%d/%s/", config->gw_address, config->gw_port, config->authdir);
	safe_asprintf(&authtarget, "http://%s:%d/%s/?token=%s&redir=%s", config->gw_address, config->gw_port, config->authdir, client->token, redirect_url_encoded);
	safe_asprintf(&authaction, "http://%s:%d/%s/", config->gw_address, config->gw_port, config->authdir);
	safe_asprintf(&pagesdir, "/%s", config->pagesdir);
	safe_asprintf(&imagesdir, "/%s", config->imagesdir);

	tmpl_init_templor(&templor);
	tmpl_set_variable(&templor, "authaction", authaction);
	tmpl_set_variable(&templor, "authtarget", authtarget);
	tmpl_set_variable(&templor, "clientip", client->ip);
	tmpl_set_variable(&templor, "clientmac", client->mac);
	//	tmpl_set_variable(&templor, "content", VERSION);
	tmpl_set_variable(&templor, "denyaction", denyaction);
	tmpl_set_variable(&templor, "error_msg", "");

	tmpl_set_variable(&templor, "gatewaymac", config->gw_mac);
	tmpl_set_variable(&templor, "gatewayname", config->gw_name);

	tmpl_set_variable(&templor, "imagesdir", imagesdir);
	tmpl_set_variable(&templor, "pagesdir", pagesdir);

	tmpl_set_variable(&templor, "maxclients", maxclients);
	tmpl_set_variable(&templor, "nclients", nclients);

	tmpl_set_variable(&templor, "redir", redirect_url);
	tmpl_set_variable(&templor, "tok", client->token);
	tmpl_set_variable(&templor, "uptime", uptime);
	tmpl_set_variable(&templor, "version", VERSION);

	tmpl_parse(&templor, splashpage_result, size + TMPLVAR_SIZE, splashpage_tmpl, size);
	free(authaction);
	free(denyaction);
	free(maxclients);
	free(nclients);
	free(uptime);
	free(splashpage_tmpl);
	free(imagesdir);

	response = MHD_create_response_from_buffer(strlen(splashpage_result), (void *)splashpage_result, MHD_RESPMEM_MUST_FREE);
	if (!response) {
		close(splashpage_fd);
		return send_error(connection, 503);
	}

	MHD_add_response_header(response, "Content-Type", mimetype);
	ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
	MHD_destroy_response(response);

	close(splashpage_fd);

	return ret;
}