Header, made captive portal optional

pull/30/head
Jeroen Domburg 9 years ago
parent 0b393512fc
commit 7aa2d227a7
  1. 21
      user/captdns.c
  2. 11
      user/user_main.c

@ -1,5 +1,22 @@
#include <esp8266.h>
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/
/*
This is a 'captive portal' DNS server: it basically replies with a fixed IP for any and all DNS
queries. This can be used to send mobile phones, tablets etc which connect to the ESP in
AP mode directly to the internal webserver.
*/
typedef struct __attribute__ ((packed)) {
uint16_t id;
uint8_t flags;
@ -72,7 +89,7 @@ static void ICACHE_FLASH_ATTR setn32(void *pp, int32_t n) {
*p++=(n&0xff);
}
static uint16_t ntohs(uint16_t *in) {
static uint16_t ICACHE_FLASH_ATTR ntohs(uint16_t *in) {
char *p=(char*)in;
return ((p[0]<<8)&0xff00)|(p[1]&0xff);
}
@ -111,7 +128,7 @@ static char* ICACHE_FLASH_ATTR labelToStr(char *packet, char *labelPtr, int pack
}
char *strToLabel(char *str, char *label, int maxLen) {
static char ICACHE_FLASH_ATTR *strToLabel(char *str, char *label, int maxLen) {
char *len=label; //ptr to len byte
char *p=label+1; //ptr to next label byte to be written
while (1) {

@ -22,8 +22,13 @@
#include "espfs.h"
#include "captdns.h"
//The example can print out the heap use every 3 seconds. You can use this to catch memory leaks.
//#define SHOW_HEAP_USE
//The example can act as a captive portal, that is, if someone connects their phone to the access
//point, it will automatically
#define CAPTIVE_PORTAL
//Function that tells the authentication system what users/passwords live on the system.
//This is disabled in the default build; if you want to try it, enable the authBasic line in
//the builtInUrls below.
@ -53,7 +58,9 @@ general ones. Authorization things (like authBasic) act as a 'barrier' and
should be placed above the URLs they protect.
*/
HttpdBuiltInUrl builtInUrls[]={
#ifdef CAPTIVE_PORTAL
{"*", cgiCheckHostname, "esp8266.local"},
#endif
{"/", cgiRedirect, "/index.tpl"},
{"/flash.bin", cgiReadFlash, NULL},
{"/led.tpl", cgiEspFsTemplate, tplLed},
@ -91,8 +98,10 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) {
void user_init(void) {
stdoutInit();
ioInit();
captdnsInit();
#ifdef CAPTIVE_PORTAL
captdnsInit();
#endif
// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
// where image is written in flash that is defined in Makefile.

Loading…
Cancel
Save