コード例 #1
0
ファイル: http.c プロジェクト: ivasilchev/nodogsplash
/** Respond to attempted access from a preauthenticated client.
 *  Add the client to the client list and serves the splash page.
 */
void
http_nodogsplash_custom_request(httpd *webserver, request *r)
{
	debug(LOG_NOTICE, "Processing custom request... %s:%s", r->request.path, r->clientAddr);

    httpdAddVariable(r,"test","default");
    httpdAddVariable(r,"hidden","default");
    httpdAddVariable(r,"survey_results","");

    httpVar *var;
    var = httpdGetVariableByName(r,"test");
	if(var && var->value) {
		debug(LOG_NOTICE, "Var test is : %s", var->value);
	}

	char message[] = "HIIIIII\n";

	httpdSetResponse(r, "200 OK");

    //httpdPrintf(r, message);

    sendfile(r, "post.html");

    httpdDumpVariables(r);

   debug(LOG_NOTICE, "Custom request requested. Query: %s", r->request.query);

}
コード例 #2
0
ファイル: http.c プロジェクト: awaysoft/apfree_wifidog
void
http_send_apple_redirect(request *r, const char *redir_url)
{
	char *url = _get_full_url(redir_url);
    httpdAddVariable(r, "redir_url", url);
    httpdOutput(r, apple_redirect_msg);
	_httpd_closeSocket(r);
	free(url);
}
コード例 #3
0
ファイル: http.c プロジェクト: siva307/wifidog_gateway
void
send_http_page(request * r, const char *title, const char *message)
{
    s_config *config = config_get_config();
    char *buffer;
    struct stat stat_info;
    int fd;
    ssize_t written;

    fd = open(config->htmlmsgfile, O_RDONLY);
    if (fd == -1) {
        debug(LOG_CRIT, "Failed to open HTML message file %s: %s", config->htmlmsgfile, strerror(errno));
        return;
    }

    if (fstat(fd, &stat_info) == -1) {
        debug(LOG_CRIT, "Failed to stat HTML message file: %s", strerror(errno));
        close(fd);
        return;
    }
    // Cast from long to unsigned int
    buffer = (char *)safe_malloc((size_t) stat_info.st_size + 1);
    written = read(fd, buffer, (size_t) stat_info.st_size);
    if (written == -1) {
        debug(LOG_CRIT, "Failed to read HTML message file: %s", strerror(errno));
        free(buffer);
        close(fd);
        return;
    }
    close(fd);

    buffer[written] = 0;
    httpdAddVariable(r, "title", title);
    httpdAddVariable(r, "message", message);
    httpdAddVariable(r, "nodeID", config->gw_id);
    if (r->ssl_conn) {
	httpsOutput(r, buffer);
    } else {
	httpdOutput(r, buffer);
    }
    free(buffer);
}
コード例 #4
0
ファイル: http.c プロジェクト: awaysoft/apfree_wifidog
void
http_send_js_redirect_ex(request *r, const char *redir_url)
{

    char *url = _get_full_url(redir_url);
	
	if(redirect_html == NULL) {	
		s_config *config = config_get_config();
    	int fd;
    	ssize_t written;
    	char *buffer;
    	struct stat stat_info;
	
		fd = open(config->htmlredirfile, O_RDONLY);
    	if (fd == -1) {
        	debug(LOG_CRIT, "Failed to open HTML message file %s: %s", strerror(errno), 
				config->htmlredirfile);
			free(url);
        	return;
    	}

    	if (fstat(fd, &stat_info) == -1) {
        	debug(LOG_CRIT, "Failed to stat HTML message file: %s", strerror(errno));
			free(url);
        	close(fd);
        	return;
    	}
    	// Cast from long to unsigned int
    	buffer = (char *)safe_malloc((size_t) stat_info.st_size + 1);
    	written = read(fd, buffer, (size_t) stat_info.st_size);
    	if (written == -1) {
        	debug(LOG_CRIT, "Failed to read HTML message file: %s", strerror(errno));
        	free(buffer);
			free(url);
        	close(fd);
        	return;
    	}
    	close(fd);

    	buffer[written] = 0;
		redirect_html = buffer;
	}
    httpdAddVariable(r, "redir_url", url);
    httpdOutput(r, redirect_html);
	_httpd_closeSocket(r);
	free(url);
}
コード例 #5
0
ファイル: http.c プロジェクト: bluecliff/wifi-cat
/* Pipe the info page from the info skeleton page file.
 */
void
http_nodogsplash_serve_info(request *r, const char title[], const char content[]) 
{
	char *abspath;
	char line [MAX_BUF];
	char *infoskelfilename;
	FILE *fd;
	s_config	*config;

	config = config_get_config();

	/* Set variables; these can be interpolated in the info page text. */
	httpdAddVariable(r,"gatewayname",config->gw_name);
	httpdAddVariable(r,"version",VERSION);
	httpdAddVariable(r,"title",title);
	httpdAddVariable(r,"content",content);
	/* 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  */
	debug(LOG_DEBUG,"errmsg:%s,%s,%s,%s",config->gw_name,VERSION,title,content);
	safe_asprintf(&abspath, "/%s", config->imagesdir);
	debug(LOG_DEBUG,"errmsg:%s,%s,%s,%s,%s",config->gw_name,VERSION,title,content,abspath);
	httpdAddVariable(r,"imagesdir",abspath);
	free(abspath);
	safe_asprintf(&abspath, "/%s", config->pagesdir);
	httpdAddVariable(r,"pagesdir",abspath);
	free(abspath);

	/* Pipe the page from its file */
	safe_asprintf(&infoskelfilename, "%s/%s",
				  config->webroot,
				  config->infoskelpage );
	debug(LOG_INFO,"Serving info page %s title %s to %s",
		  infoskelfilename,r->clientAddr);
	if (!(fd = fopen(infoskelfilename, "r"))) {
		debug(LOG_ERR, "Could not open info skel file '%s'", infoskelfilename);
	} else {
		while (fgets(line, MAX_BUF, fd)) {
			httpdOutput(r,line);
		}
		fclose(fd);
	}
	free(infoskelfilename);
}
コード例 #6
0
ファイル: http.c プロジェクト: ArtMartin89/nodog
/* 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);
}