| 63 | | |
|---|
| 64 | | memset(tmp_url, 0, sizeof(tmp_url)); |
|---|
| 65 | | snprintf(tmp_url, (sizeof(tmp_url) - 1), "http://%s%s", |
|---|
| 66 | | r->request.host, |
|---|
| 67 | | r->request.path); |
|---|
| 68 | | url = httpdUrlEncode(tmp_url); |
|---|
| 69 | | |
|---|
| 70 | | if (config->auth_servers == NULL) { |
|---|
| 71 | | /* Redirect to splash page, no authentication servers exist */ |
|---|
| 72 | | |
|---|
| 73 | | safe_asprintf(&newlocation, "Location: http://%s:%d/wifidog/splash", |
|---|
| 74 | | config->gw_address, |
|---|
| 75 | | config->gw_port); |
|---|
| 76 | | |
|---|
| 77 | | httpdSetResponse(r, "307 Please visit here\n"); |
|---|
| 78 | | httpdAddHeader(r, newlocation); |
|---|
| 79 | | http_wifidog_header(r, "Redirection"); |
|---|
| 80 | | httpdPrintf(r, "Please <a href='http://%s:%d/wifidog/splash'>click here</a> to login", |
|---|
| 81 | | config->gw_address, |
|---|
| 82 | | config->gw_port); |
|---|
| 83 | | http_wifidog_footer(r); |
|---|
| 84 | | debug(LOG_INFO, "Captured %s requesting [%s] and re-directed them to splash page", r->clientAddr, url); |
|---|
| 85 | | free(newlocation); |
|---|
| 86 | | |
|---|
| 87 | | http_wifidog_footer(r); |
|---|
| 88 | | debug(LOG_INFO, "Sent %s the splash page", r->clientAddr); |
|---|
| 89 | | } else { |
|---|
| 90 | | |
|---|
| 91 | | t_auth_serv *auth_server = get_auth_server(); |
|---|
| 92 | | |
|---|
| 93 | | if (auth_server->authserv_use_ssl) { |
|---|
| 94 | | protocol = "https"; |
|---|
| 95 | | port = auth_server->authserv_ssl_port; |
|---|
| 96 | | } else { |
|---|
| 97 | | protocol = "http"; |
|---|
| 98 | | port = auth_server->authserv_http_port; |
|---|
| 99 | | } |
|---|
| 100 | | |
|---|
| 101 | | if (!is_online()) { |
|---|
| 102 | | /* The internet connection is down at the moment - apologize and do not redirect anywhere */ |
|---|
| 103 | | http_wifidog_header(r, "<h3>Internet access unavailable</h3>"); |
|---|
| 104 | | httpdOutput(r, "<p>We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable.</p>"); |
|---|
| 105 | | httpdOutput(r, "<p>If at all possible, please notify the owners of this hotspot that the internet connection is out of service.</p>"); |
|---|
| 106 | | httpdOutput(r, "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>"); |
|---|
| 107 | | httpdPrintf(r, "<p>In a while please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); |
|---|
| 108 | | http_wifidog_footer(r); |
|---|
| 109 | | debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr); |
|---|
| 110 | | } |
|---|
| 111 | | else if (!is_auth_online()) { |
|---|
| 112 | | /* The auth server is down at the moment - apologize and do not redirect anywhere */ |
|---|
| 113 | | http_wifidog_header(r, "<h3>Login screen unavailable</h3>"); |
|---|
| 114 | | httpdOutput(r, "<p>We apologize, but it seems that we are currently unable to re-direct you to the login screen.</p>"); |
|---|
| 115 | | httpdOutput(r, "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>"); |
|---|
| 116 | | httpdPrintf(r, "<p>In a couple of minutes please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); |
|---|
| 117 | | http_wifidog_footer(r); |
|---|
| 118 | | debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr); |
|---|
| 119 | | } |
|---|
| 120 | | else { |
|---|
| 121 | | /* Re-direct them to auth server */ |
|---|
| 122 | | safe_asprintf(&newlocation, "Location: %s://%s:%d%slogin?gw_address=%s&gw_port=%d&gw_id=%s&url=%s", |
|---|
| 123 | | protocol, |
|---|
| 124 | | auth_server->authserv_hostname, |
|---|
| 125 | | port, |
|---|
| 126 | | auth_server->authserv_path, |
|---|
| 127 | | config->gw_address, |
|---|
| 128 | | config->gw_port, |
|---|
| 129 | | config->gw_id, |
|---|
| 130 | | url); |
|---|
| 131 | | httpdSetResponse(r, "307 Please authenticate yourself here\n"); |
|---|
| 132 | | httpdAddHeader(r, newlocation); |
|---|
| 133 | | http_wifidog_header(r, "Redirection"); |
|---|
| 134 | | httpdPrintf(r, "Please <a href='%s://%s:%d%slogin?gw_address=%s&gw_port=%d&gw_id=%s&url=%s'>click here</a> to login", |
|---|
| 135 | | protocol, |
|---|
| 136 | | auth_server->authserv_hostname, |
|---|
| 137 | | port, |
|---|
| 138 | | auth_server->authserv_path, |
|---|
| 139 | | config->gw_address, |
|---|
| 140 | | config->gw_port, |
|---|
| 141 | | config->gw_id, |
|---|
| 142 | | url); |
|---|
| 143 | | http_wifidog_footer(r); |
|---|
| 144 | | debug(LOG_INFO, "Captured %s requesting [%s] and re-directed them to login page", r->clientAddr, url); |
|---|
| 145 | | free(newlocation); |
|---|
| 146 | | } |
|---|
| 147 | | |
|---|
| 148 | | free(url); |
|---|
| 149 | | } |
|---|
| | 63 | t_auth_serv *auth_server = get_auth_server(); |
|---|
| | 64 | |
|---|
| | 65 | if (auth_server->authserv_use_ssl) { |
|---|
| | 66 | protocol = "https"; |
|---|
| | 67 | port = auth_server->authserv_ssl_port; |
|---|
| | 68 | } else { |
|---|
| | 69 | protocol = "http"; |
|---|
| | 70 | port = auth_server->authserv_http_port; |
|---|
| | 71 | } |
|---|
| | 72 | |
|---|
| | 73 | memset(tmp_url, 0, sizeof(tmp_url)); |
|---|
| | 74 | snprintf(tmp_url, (sizeof(tmp_url) - 1), "http://%s%s", |
|---|
| | 75 | r->request.host, |
|---|
| | 76 | r->request.path); |
|---|
| | 77 | url = httpdUrlEncode(tmp_url); |
|---|
| | 78 | |
|---|
| | 79 | if (!is_online()) { |
|---|
| | 80 | /* The internet connection is down at the moment - apologize and do not redirect anywhere */ |
|---|
| | 81 | http_wifidog_header(r, "<h2>Uh oh! Internet access unavailable</h2>"); |
|---|
| | 82 | httpdOutput(r, "<p>We apologize, but it seems that the internet connection that powers this hotspot is temporarily unavailable.</p>"); |
|---|
| | 83 | httpdOutput(r, "<p>If at all possible, please notify the owners of this hotspot that the internet connection is out of service.</p>"); |
|---|
| | 84 | httpdOutput(r, "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>"); |
|---|
| | 85 | httpdPrintf(r, "<p>In a while please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); |
|---|
| | 86 | http_wifidog_footer(r); |
|---|
| | 87 | debug(LOG_INFO, "Sent %s an apology since I am not online - no point sending them to auth server", r->clientAddr); |
|---|
| | 88 | } |
|---|
| | 89 | else if (!is_auth_online()) { |
|---|
| | 90 | /* The auth server is down at the moment - apologize and do not redirect anywhere */ |
|---|
| | 91 | http_wifidog_header(r, "<h2>Uh oh! Login screen unavailable</h2>"); |
|---|
| | 92 | httpdOutput(r, "<p>We apologize, but it seems that we are currently unable to re-direct you to the login screen.</p>"); |
|---|
| | 93 | httpdOutput(r, "<p>The maintainers of this network are aware of this disruption. We hope that this situation will be resolved soon.</p>"); |
|---|
| | 94 | httpdPrintf(r, "<p>In a couple of minutes please <a href='%s'>click here</a> to try your request again.</p>", tmp_url); |
|---|
| | 95 | http_wifidog_footer(r); |
|---|
| | 96 | debug(LOG_INFO, "Sent %s an apology since auth server not online - no point sending them to auth server", r->clientAddr); |
|---|
| | 97 | } |
|---|
| | 98 | else { |
|---|
| | 99 | /* Re-direct them to auth server */ |
|---|
| | 100 | safe_asprintf(&newlocation, "Location: %s://%s:%d%slogin?gw_address=%s&gw_port=%d&gw_id=%s&url=%s", |
|---|
| | 101 | protocol, |
|---|
| | 102 | auth_server->authserv_hostname, |
|---|
| | 103 | port, |
|---|
| | 104 | auth_server->authserv_path, |
|---|
| | 105 | config->gw_address, |
|---|
| | 106 | config->gw_port, |
|---|
| | 107 | config->gw_id, |
|---|
| | 108 | url); |
|---|
| | 109 | httpdSetResponse(r, "307 Please authenticate yourself here\n"); |
|---|
| | 110 | httpdAddHeader(r, newlocation); |
|---|
| | 111 | http_wifidog_header(r, "Redirection"); |
|---|
| | 112 | httpdPrintf(r, "Please <a href='%s://%s:%d%slogin?gw_address=%s&gw_port=%d&gw_id=%s&url=%s'>click here</a> to login", |
|---|
| | 113 | protocol, |
|---|
| | 114 | auth_server->authserv_hostname, |
|---|
| | 115 | port, |
|---|
| | 116 | auth_server->authserv_path, |
|---|
| | 117 | config->gw_address, |
|---|
| | 118 | config->gw_port, |
|---|
| | 119 | config->gw_id, |
|---|
| | 120 | url); |
|---|
| | 121 | http_wifidog_footer(r); |
|---|
| | 122 | debug(LOG_INFO, "Captured %s requesting [%s] and re-directed them to login page", r->clientAddr, url); |
|---|
| | 123 | free(newlocation); |
|---|
| | 124 | } |
|---|
| | 125 | |
|---|
| | 126 | free(url); |
|---|
| 181 | | void |
|---|
| 182 | | http_callback_splash(httpd *webserver, request *r) |
|---|
| 183 | | { |
|---|
| 184 | | char * status = NULL; |
|---|
| 185 | | httpVar * url; |
|---|
| 186 | | |
|---|
| 187 | | status = get_status_text(); |
|---|
| 188 | | http_wifidog_header(r, "Disclaimer"); |
|---|
| 189 | | httpdOutput(r, "<p>This hotspot offers Free internet access!</p>"); |
|---|
| 190 | | httpdOutput(r, "<p>By clicking ACCEPT, you agree that you will respect these WiFi Do's and Don'ts:</p>"); |
|---|
| 191 | | httpdOutput(r, "<ul>\n"); |
|---|
| 192 | | httpdOutput(r, "<li>Respect the venue's bandwidth. Don't download too many large files.\n"); |
|---|
| 193 | | httpdOutput(r, "<li>Make Purchases and Tip.\n"); |
|---|
| 194 | | httpdOutput(r, "<li>If it's a busy place, don't take up too much space.\n"); |
|---|
| 195 | | httpdOutput(r, "<li>Turn down your sound or use headphones.\n"); |
|---|
| 196 | | httpdOutput(r, "<li>Share a table.\n"); |
|---|
| 197 | | httpdOutput(r, "<li>Thank the staff or management - let them know you appreciate the WiFi.\n"); |
|---|
| 198 | | httpdOutput(r, "<li>If it's busy - don't overstay your welcome.\n"); |
|---|
| 199 | | httpdOutput(r, "<li>Help others who are having trouble getting on the network.\n"); |
|---|
| 200 | | httpdOutput(r, "<li>Remember that the WiFi is complimentary. If it doesn't work, let the staff know. Be patient.\n"); |
|---|
| 201 | | httpdOutput(r, "</ul>\n"); |
|---|
| 202 | | if ((url = httpdGetVariableByName(r, "url"))) { |
|---|
| 203 | | httpdPrintf(r, "<a href=\"/wifidog/auth?url=%s\">ACCEPT</a>", url->value); |
|---|
| 204 | | } else { |
|---|
| 205 | | httpdOutput(r, "<a href=\"/wifidog/auth\">ACCEPT</a>"); |
|---|
| 206 | | } |
|---|
| 207 | | |
|---|
| 208 | | http_wifidog_footer(r); |
|---|
| 209 | | free(status); |
|---|
| 210 | | } |
|---|
| 211 | | |
|---|
| 212 | | void |
|---|
| 213 | | http_callback_portal(httpd *webserver, request *r) |
|---|
| 214 | | { |
|---|
| 215 | | char * status = NULL; |
|---|
| 216 | | |
|---|
| 217 | | status = get_status_text(); |
|---|
| 218 | | http_wifidog_header(r, "Enjoy!"); |
|---|
| 219 | | httpdOutput(r, "<p>Don't forget, socialize and discuss with others! (you're not at home, enjoy the place and people!)</p>"); |
|---|
| 220 | | http_wifidog_footer(r); |
|---|
| 221 | | free(status); |
|---|
| 222 | | } |
|---|
| 223 | | |
|---|
| 258 | | } else if (config->auth_servers == NULL) { |
|---|
| 259 | | /* No authentication server is configured, we do not expect a token |
|---|
| 260 | | * auth right away */ |
|---|
| 261 | | if (!(mac = arp_get(r->clientAddr))) { |
|---|
| 262 | | /* We could not get their MAC address */ |
|---|
| 263 | | debug(LOG_ERR, "Failed to retrieve MAC address for ip %s", r->clientAddr); |
|---|
| 264 | | http_wifidog_header(r, "WiFiDog Error"); |
|---|
| 265 | | httpdOutput(r, "Failed to retrieve your MAC address"); |
|---|
| 266 | | http_wifidog_footer(r); |
|---|
| 267 | | } else { |
|---|
| 268 | | /* We have their MAC address */ |
|---|
| 269 | | |
|---|
| 270 | | LOCK_CLIENT_LIST(); |
|---|
| 271 | | |
|---|
| 272 | | if ((client = client_list_find(r->clientAddr, mac)) == NULL) { |
|---|
| 273 | | debug(LOG_DEBUG, "New client ip=%s mac=%s", r->clientAddr, mac); |
|---|
| 274 | | client_list_append(r->clientAddr, mac, "SpLaShOnLy"); |
|---|
| 275 | | } else { |
|---|
| 276 | | debug(LOG_DEBUG, "Node for %s already exists", client->ip); |
|---|
| 277 | | } |
|---|
| 278 | | |
|---|
| 279 | | /* Find the client in the list once it's created (not very useful) */ |
|---|
| 280 | | client = client_list_find(r->clientAddr, mac); |
|---|
| 281 | | |
|---|
| 282 | | debug(LOG_INFO, "ALLOWING %s [%s], the user clicked the accept button", client->ip, client->mac); |
|---|
| 283 | | client->fw_connection_state = FW_MARK_KNOWN; |
|---|
| 284 | | fw_allow(client->ip, client->mac, FW_MARK_KNOWN); |
|---|
| 285 | | |
|---|
| 286 | | UNLOCK_CLIENT_LIST(); |
|---|
| 287 | | |
|---|
| 288 | | free(mac); |
|---|
| 289 | | |
|---|
| 290 | | httpdSetResponse(r, "307 Redirect to portal\n"); |
|---|
| 291 | | /* If we have a portal url specified in the configuration, |
|---|
| 292 | | forward to it, otherwise forward to /wifidog/portal */ |
|---|
| 293 | | if (config->portal && strncmp(config->portal, "http://", strlen("http://")) == 0) { |
|---|
| 294 | | debug(LOG_INFO, "Redirecting to portal at %s", config->portal); |
|---|
| 295 | | safe_asprintf(&newlocation, "Location: %s", |
|---|
| 296 | | config->portal |
|---|
| 297 | | ); |
|---|
| 298 | | |
|---|
| 299 | | httpdAddHeader(r, newlocation); |
|---|
| 300 | | http_wifidog_header(r, "Redirection"); |
|---|
| 301 | | |
|---|
| 302 | | httpdPrintf(r, "Please <a href='%s'>click here</a> for the portal", |
|---|
| 303 | | config->portal); |
|---|
| 304 | | } else { |
|---|
| 305 | | safe_asprintf(&newlocation, "Location: http://%s:%d/wifidog/portal", |
|---|
| 306 | | config->gw_address, |
|---|
| 307 | | config->gw_port); |
|---|
| 308 | | debug(LOG_INFO, "Redirecting to local portal"); |
|---|
| 309 | | |
|---|
| 310 | | httpdAddHeader(r, newlocation); |
|---|
| 311 | | http_wifidog_header(r, "Redirection"); |
|---|
| 312 | | |
|---|
| 313 | | httpdPrintf(r, "Please <a href='http://%s:%d/wifidog/portal'>click here</a> for the portal", |
|---|
| 314 | | config->gw_address, |
|---|
| 315 | | config->gw_port); |
|---|
| 316 | | } |
|---|
| 317 | | |
|---|
| 318 | | http_wifidog_footer(r); |
|---|
| 319 | | free(newlocation); |
|---|
| 320 | | } |
|---|