// liudf added 20160421 void http_callback_temporary_pass(httpd * webserver, request * r) { const s_config *config = config_get_config(); httpVar *mac = httpdGetVariableByName(r, "mac"); if (config->httpdusername && (strcmp(config->httpdusername, r->request.authUser) || strcmp(config->httpdpassword, r->request.authPassword))) { debug(LOG_INFO, "Disconnect requested, forcing authentication"); httpdForceAuthenticate(r, config->httpdrealm); return; } if(mac) { debug(LOG_INFO, "Temporary passed %s", mac->value); fw_set_mac_temporary(mac->value, 0); httpdOutput(r, "startWeChatAuth();"); } else { debug(LOG_INFO, "Temporary pass called without MAC given"); httpdOutput(r, "MAC need to be specified"); return; } return; }
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); }
void http_callback_disconnect(httpd * webserver, request * r) { const s_config *config = config_get_config(); /* XXX How do you change the status code for the response?? */ httpVar *token = httpdGetVariableByName(r, "token"); httpVar *mac = httpdGetVariableByName(r, "mac"); if (config->httpdusername && (strcmp(config->httpdusername, r->request.authUser) || strcmp(config->httpdpassword, r->request.authPassword))) { debug(LOG_INFO, "Disconnect requested, forcing authentication"); httpdForceAuthenticate(r, config->httpdrealm); return; } if (token && mac) { t_client *client; LOCK_CLIENT_LIST(); client = client_list_find_by_mac(mac->value); if (!client || strcmp(client->token, token->value)) { UNLOCK_CLIENT_LIST(); debug(LOG_INFO, "Disconnect %s with incorrect token %s", mac->value, token->value); httpdOutput(r, "Invalid token for MAC"); return; } /* TODO: get current firewall counters */ logout_client(client); UNLOCK_CLIENT_LIST(); } else { debug(LOG_INFO, "Disconnect called without both token and MAC given"); httpdOutput(r, "Both the token and MAC need to be specified"); return; } return; }
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); }
/* 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); }
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); }
/* 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); }
void http_relay_wisper(request *r) { httpdOutput(r, apple_wisper); _httpd_closeSocket(r); }