User web page

This commit is contained in:
Martin Ger
2018-11-09 12:55:44 +01:00
parent 6a67a3d314
commit 998b50a5ab
5 changed files with 58 additions and 2 deletions
+3
View File
@@ -156,6 +156,9 @@ uint32_t reg0, reg1, reg3;
os_sprintf(config->ota_host,"%s", "none");
config->ota_port = 80;
#endif
#if WEB_ALT_PAGE
config->alt_web[0] = '\0'; // default none
#endif
}
int ICACHE_FLASH_ATTR config_load(sysconfig_p config)
+3
View File
@@ -135,6 +135,9 @@ typedef struct {
uint8_t ota_host[64];
uint16_t ota_port;
#endif
#if WEB_ALT_PAGE
uint8_t alt_web[256]; // user defined body of web page
#endif
} sysconfig_t, *sysconfig_p;
int config_load(sysconfig_p config);
+5 -1
View File
@@ -77,6 +77,10 @@
//
#define WEB_CONFIG 1
#define WEB_CONFIG_PORT 80
//
// Define this to 1 if you want to be able to display a user defined web page.
//
#define WEB_ALT_PAGE 1
//
// Define this to 1 if you want to have ACLs for the SoftAP.
@@ -140,7 +144,7 @@
// Define this to 1 to support an ENC28J60 Ethernet interface
// Experimental feature - not yet stable
//
#define HAVE_ENC28J60 1
#define HAVE_ENC28J60 0
//
// Define this to 1 to support ENC28J60 DHCP server
+36 -1
View File
@@ -2063,6 +2063,20 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn)
os_sprintf(response, "Web port set to %d\r\n", config.web_port);
goto command_handled;
}
#if WEB_ALT_PAGE
if (strcmp(tokens[1], "alt_web") == 0)
{
if (strcmp(tokens[2],"none") == 0) {
config.alt_web[0] = '\0';
os_sprintf_flash(response, "Alternative web page cleared\r\n");
goto command_handled;
}
os_strncpy(config.alt_web, tokens[2], sizeof(config.alt_web)-1);
config.alt_web[sizeof(config.alt_web)-1] = '\0';
os_sprintf_flash(response, "Alternative web page set\r\n");
goto command_handled;
}
#endif
#endif
#if DAILY_LIMIT
if (strcmp(tokens[1],"daily_limit") == 0)
@@ -2712,7 +2726,28 @@ static void ICACHE_FLASH_ATTR web_config_client_connected_cb(void *arg)
ringbuf_reset(console_rx_buffer);
ringbuf_reset(console_tx_buffer);
if (!config.locked) {
#if WEB_ALT_PAGE
if (config.alt_web[0] != '\0') {
static const uint8_t alt_page_str[] ICACHE_RODATA_ATTR STORE_ATTR = ALT_PAGE;
uint32_t slen = (sizeof(alt_page_str) + 4) & ~3;
uint8_t *alt_page = (char *)os_malloc(slen);
if (alt_page == NULL)
return;
os_memcpy(alt_page, alt_page_str, slen);
uint8_t *page_buf = (char *)os_malloc(slen+sizeof(config.alt_web));
if (page_buf == NULL)
return;
os_sprintf(page_buf, alt_page, config.alt_web);
os_free(alt_page);
espconn_send(pespconn, page_buf, os_strlen(page_buf));
os_free(page_buf);
}
else
#endif
if (!config.locked) {
static const uint8_t config_page_str[] ICACHE_RODATA_ATTR STORE_ATTR = CONFIG_PAGE;
uint32_t slen = (sizeof(config_page_str) + 4) & ~3;
uint8_t *config_page = (char *)os_malloc(slen);
+11
View File
@@ -133,3 +133,14 @@ setTimeout(\"location.href = '/'\",1000);\
</body>\
</html>\
"
#if WEB_ALT_PAGE
#define ALT_PAGE "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n\
<html>\
<head></head>\
<body>\
%s\
</body>\
</html>\
"
#endif