MeterLogger
httpd_user_init.c
Go to the documentation of this file.
1 
2 
3 /*
4  * ----------------------------------------------------------------------------
5  * "THE BEER-WARE LICENSE" (Revision 42):
6  * Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
7  * this notice you can do whatever you want with this stuff. If we meet some day,
8  * and you think this stuff is worth it, you can buy me a beer in return.
9  * ----------------------------------------------------------------------------
10  */
11 
12 
13 #include <esp8266.h>
14 
15 #include "httpd.h"
16 #include "httpdespfs.h"
17 #include "cgiwifi.h"
18 #include "auth.h"
19 #include "debug.h"
20 
21 //Function that tells the authentication system what users/passwords live on the system.
22 //This is disabled in the default build; if you want to try it, enable the authBasic line in
23 //the builtInUrls below.
24 int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen) {
25  if (no==0) {
26  os_strcpy(user, "admin");
27  os_strcpy(pass, "s3cr3t");
28  return 1;
29 //Add more users this way. Check against incrementing no for each user added.
30 // } else if (no==1) {
31 // os_strcpy(user, "user1");
32 // os_strcpy(pass, "something");
33 // return 1;
34  }
35  return 0;
36 }
37 
38 
39 /*
40 This is the main url->function dispatching data struct.
41 In short, it's a struct with various URLs plus their handlers. The handlers can
42 be 'standard' CGI functions you wrote, or 'special' CGIs requiring an argument.
43 They can also be auth-functions. An asterisk will match any url starting with
44 everything before the asterisks; "*" matches everything. The list will be
45 handled top-down, so make sure to put more specific rules above the more
46 general ones. Authorization things (like authBasic) act as a 'barrier' and
47 should be placed above the URLs they protect.
48 */
50 //Routines to make the /wifi URL and everything beneath it work.
51 #ifdef IMPULSE
52  {"/generate_204", cgiRedirect, "/wifi/impulse_meter_wifi_setup.tpl"}, // iOS captive portal pop up web config
53  {"/hotspot-detect.html", cgiRedirect, "/wifi/impulse_meter_wifi_setup.tpl"}, // android captive portal pop up web config
54  {"/", cgiRedirect, "/wifi/impulse_meter_wifi_setup.tpl"},
55  {"/wifi", cgiRedirect, "/wifi/impulse_meter_wifi_setup.tpl"},
56  {"/wifi/", cgiRedirect, "/wifi/impulse_meter_wifi_setup.tpl"},
57  {"/wifi/impulse_meter_wifi_setup.tpl", cgiEspFsTemplate, tplSetup},
58 #else
59  {"/generate_204", cgiRedirect, "/wifi/wifi_setup.tpl"}, // iOS captive portal pop up web config
60  {"/hotspot-detect.html", cgiRedirect, "/wifi/wifi_setup.tpl"}, // android captive portal pop up web config
61  {"/", cgiRedirect, "/wifi/wifi_setup.tpl"},
62  {"/wifi", cgiRedirect, "/wifi/wifi_setup.tpl"},
63  {"/wifi/", cgiRedirect, "/wifi/wifi_setup.tpl"},
64  {"/wifi/wifi_setup.tpl", cgiEspFsTemplate, tplSetup},
65 #endif
66  {"/wifi/setup.cgi", cgiSetup, NULL},
67  {"/wifi/wifiscan.cgi", cgiWiFiScan, NULL},
68 
69  {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem
70  {NULL, NULL, NULL}
71 };
72 
73 
74 //Main routine. Initialize stdout, the I/O and the webserver and we're done.
75 void httpd_user_init(void) {
76  httpdInit(builtInUrls, 80);
77  INFO("\nReady\n");
78 }
int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
HttpdBuiltInUrl builtInUrls[]
void ICACHE_FLASH_ATTR tplSetup(HttpdConnData *connData, char *token, void **arg)
Definition: cgiwifi.c:247
#define NULL
Definition: def.h:47
int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData)
Definition: httpdespfs.c:39
int ICACHE_FLASH_ATTR cgiSetup(HttpdConnData *connData)
Definition: cgiwifi.c:168
ICACHE_FLASH_ATTR void httpdInit(HttpdBuiltInUrl *fixedUrls, int port)
Definition: httpd.c:509
int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData)
Definition: httpdespfs.c:88
int ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData)
Definition: cgiwifi.c:108
ICACHE_FLASH_ATTR int cgiRedirect(HttpdConnData *connData)
Definition: httpd.c:256
#define os_strcpy
Definition: osapi.h:42
static HttpdConnData connData[MAX_CONN]
Definition: httpd.c:63
#define INFO(...)
Definition: debug.h:17
void httpd_user_init(void)