|
@@ -164,19 +164,26 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
+ //static stuff
|
|
|
/* default page */
|
|
|
if(strstr(line, "GET / ")) {
|
|
|
netconn_write(conn, http_html_hdr, sizeof(http_html_hdr) - 1, NETCONN_NOCOPY);
|
|
|
netconn_write(conn, index_html_start, index_html_end - index_html_start, NETCONN_NOCOPY);
|
|
|
}
|
|
|
+ else if(strstr(line, "GET /code.js ")) {
|
|
|
+ netconn_write(conn, http_js_hdr, sizeof(http_js_hdr) - 1, NETCONN_NOCOPY);
|
|
|
+ netconn_write(conn, code_js_start, code_js_end - code_js_start, NETCONN_NOCOPY);
|
|
|
+ }
|
|
|
else if(strstr(line, "GET /jquery.js ")) {
|
|
|
netconn_write(conn, http_jquery_gz_hdr, sizeof(http_jquery_gz_hdr) - 1, NETCONN_NOCOPY);
|
|
|
netconn_write(conn, jquery_gz_start, jquery_gz_end - jquery_gz_start, NETCONN_NOCOPY);
|
|
|
}
|
|
|
- else if(strstr(line, "GET /code.js ")) {
|
|
|
- netconn_write(conn, http_js_hdr, sizeof(http_js_hdr) - 1, NETCONN_NOCOPY);
|
|
|
- netconn_write(conn, code_js_start, code_js_end - code_js_start, NETCONN_NOCOPY);
|
|
|
+ else if(strstr(line, "GET /style.css ")) {
|
|
|
+ netconn_write(conn, http_css_hdr, sizeof(http_css_hdr) - 1, NETCONN_NOCOPY);
|
|
|
+ netconn_write(conn, style_css_start, style_css_end - style_css_start, NETCONN_NOCOPY);
|
|
|
}
|
|
|
+
|
|
|
+ //dynamic stuff
|
|
|
else if(strstr(line, "GET /ap.json ")) {
|
|
|
/* if we can get the mutex, write the last version of the AP list */
|
|
|
ESP_LOGI(TAG,"Processing ap.json request");
|
|
@@ -194,29 +201,6 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|
|
ESP_LOGI(TAG,"Starting wifi scan");
|
|
|
wifi_manager_scan_async();
|
|
|
}
|
|
|
- else if(strstr(line, "GET /style.css ")) {
|
|
|
- netconn_write(conn, http_css_hdr, sizeof(http_css_hdr) - 1, NETCONN_NOCOPY);
|
|
|
- netconn_write(conn, style_css_start, style_css_end - style_css_start, NETCONN_NOCOPY);
|
|
|
- }
|
|
|
- else if(strstr(line, "GET /status.json ")){
|
|
|
- ESP_LOGI(TAG,"Serving status.json");
|
|
|
- if(wifi_manager_lock_json_buffer(( TickType_t ) 10)){
|
|
|
- char *buff = wifi_manager_get_ip_info_json();
|
|
|
- if(buff){
|
|
|
- netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
|
|
|
- netconn_write(conn, buff, strlen(buff), NETCONN_NOCOPY);
|
|
|
-
|
|
|
- wifi_manager_unlock_json_buffer();
|
|
|
- }
|
|
|
- else{
|
|
|
- netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
|
|
- ESP_LOGE(TAG, "http_server_netconn_serve: GET /status failed to obtain mutex");
|
|
|
- }
|
|
|
- }
|
|
|
else if(strstr(line, "GET /config.json ")){
|
|
|
ESP_LOGI(TAG,"Serving config.json");
|
|
|
char autoexec_name[21]={0};
|
|
@@ -271,9 +255,6 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- else if(strstr(line, "POST /factory.json ")){
|
|
|
- guided_factory();
|
|
|
- }
|
|
|
else if(strstr(line, "POST /config.json ")){
|
|
|
ESP_LOGI(TAG,"Serving POST config.json");
|
|
|
|
|
@@ -334,14 +315,7 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|
|
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
|
|
ESP_LOGE(TAG, "http_server_netconn_serve: GET /status failed to obtain mutex");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- else if(strstr(line, "DELETE /connect.json ")) {
|
|
|
- ESP_LOGI(TAG, "http_server_netconn_serve: DELETE /connect.json");
|
|
|
- /* request a disconnection from wifi and forget about it */
|
|
|
- wifi_manager_disconnect_async();
|
|
|
- netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
|
|
|
- }
|
|
|
+ }
|
|
|
else if(strstr(line, "POST /connect.json ")) {
|
|
|
ESP_LOGI(TAG, "http_server_netconn_serve: POST /connect.json");
|
|
|
bool found = false;
|
|
@@ -368,6 +342,37 @@ void http_server_netconn_serve(struct netconn *conn) {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ else if(strstr(line, "DELETE /connect.json ")) {
|
|
|
+ ESP_LOGI(TAG, "http_server_netconn_serve: DELETE /connect.json");
|
|
|
+ /* request a disconnection from wifi and forget about it */
|
|
|
+ wifi_manager_disconnect_async();
|
|
|
+ netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
|
|
|
+ }
|
|
|
+ else if(strstr(line, "POST /reboot.json ")){
|
|
|
+ esp_restart();
|
|
|
+ }
|
|
|
+ else if(strstr(line, "POST /recovery.json ")){
|
|
|
+ guided_factory();
|
|
|
+ }
|
|
|
+ else if(strstr(line, "GET /status.json ")){
|
|
|
+ ESP_LOGI(TAG,"Serving status.json");
|
|
|
+ if(wifi_manager_lock_json_buffer(( TickType_t ) 10)){
|
|
|
+ char *buff = wifi_manager_get_ip_info_json();
|
|
|
+ if(buff){
|
|
|
+ netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
|
|
|
+ netconn_write(conn, buff, strlen(buff), NETCONN_NOCOPY);
|
|
|
+
|
|
|
+ wifi_manager_unlock_json_buffer();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
|
|
|
+ ESP_LOGE(TAG, "http_server_netconn_serve: GET /status failed to obtain mutex");
|
|
|
+ }
|
|
|
+ }
|
|
|
else{
|
|
|
netconn_write(conn, http_400_hdr, sizeof(http_400_hdr) - 1, NETCONN_NOCOPY);
|
|
|
ESP_LOGE(TAG, "bad request");
|