diff options
Diffstat (limited to 'main/tollgate_api.c')
| -rw-r--r-- | main/tollgate_api.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/main/tollgate_api.c b/main/tollgate_api.c index af91093..5ac0543 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c | |||
| @@ -5,6 +5,11 @@ | |||
| 5 | #include "session.h" | 5 | #include "session.h" |
| 6 | #include "captive_portal.h" | 6 | #include "captive_portal.h" |
| 7 | #include "firewall.h" | 7 | #include "firewall.h" |
| 8 | #include "lwip/dns.h" | ||
| 9 | #include "lwip/netdb.h" | ||
| 10 | #include "esp_http_client.h" | ||
| 11 | #include "esp_crt_bundle.h" | ||
| 12 | #include "esp_heap_caps.h" | ||
| 8 | #include "nucula_wallet.h" | 13 | #include "nucula_wallet.h" |
| 9 | #include "mint_health.h" | 14 | #include "mint_health.h" |
| 10 | #include "market.h" | 15 | #include "market.h" |
| @@ -510,6 +515,12 @@ static esp_err_t api_get_mints(httpd_req_t *req) | |||
| 510 | cJSON *obj = cJSON_CreateObject(); | 515 | cJSON *obj = cJSON_CreateObject(); |
| 511 | cJSON_AddStringToObject(obj, "url", mints[i].url); | 516 | cJSON_AddStringToObject(obj, "url", mints[i].url); |
| 512 | cJSON_AddBoolToObject(obj, "reachable", mints[i].reachable); | 517 | cJSON_AddBoolToObject(obj, "reachable", mints[i].reachable); |
| 518 | cJSON_AddNumberToObject(obj, "status", mints[i].last_http_status); | ||
| 519 | if (mints[i].last_err) { | ||
| 520 | char errbuf[16]; | ||
| 521 | snprintf(errbuf, sizeof(errbuf), "0x%x", mints[i].last_err); | ||
| 522 | cJSON_AddStringToObject(obj, "last_err", errbuf); | ||
| 523 | } | ||
| 513 | cJSON_AddItemToArray(arr, obj); | 524 | cJSON_AddItemToArray(arr, obj); |
| 514 | } | 525 | } |
| 515 | char *json = cJSON_PrintUnformatted(arr); | 526 | char *json = cJSON_PrintUnformatted(arr); |
| @@ -686,6 +697,8 @@ extern bool s_start_services_called; | |||
| 686 | extern bool s_start_ap_services_called; | 697 | extern bool s_start_ap_services_called; |
| 687 | extern bool s_sta_got_ip; | 698 | extern bool s_sta_got_ip; |
| 688 | extern bool s_ap_started; | 699 | extern bool s_ap_started; |
| 700 | extern esp_ip4_addr_t s_sta_ip; | ||
| 701 | extern esp_ip4_addr_t s_sta_gw; | ||
| 689 | 702 | ||
| 690 | static esp_err_t api_get_debug(httpd_req_t *req) | 703 | static esp_err_t api_get_debug(httpd_req_t *req) |
| 691 | { | 704 | { |
| @@ -700,6 +713,40 @@ static esp_err_t api_get_debug(httpd_req_t *req) | |||
| 700 | cJSON_AddBoolToObject(root, "ap_started", s_ap_started); | 713 | cJSON_AddBoolToObject(root, "ap_started", s_ap_started); |
| 701 | cJSON_AddNumberToObject(root, "free_heap", (double)esp_get_free_heap_size()); | 714 | cJSON_AddNumberToObject(root, "free_heap", (double)esp_get_free_heap_size()); |
| 702 | cJSON_AddNumberToObject(root, "min_free_heap", (double)esp_get_minimum_free_heap_size()); | 715 | cJSON_AddNumberToObject(root, "min_free_heap", (double)esp_get_minimum_free_heap_size()); |
| 716 | cJSON_AddNumberToObject(root, "free_internal", (double)heap_caps_get_free_size(MALLOC_CAP_INTERNAL)); | ||
| 717 | cJSON_AddNumberToObject(root, "largest_internal", (double)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL)); | ||
| 718 | cJSON_AddNumberToObject(root, "free_spiram", (double)heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); | ||
| 719 | |||
| 720 | char dns0[16], dns1[16], dns2[16]; | ||
| 721 | const ip_addr_t *d0 = dns_getserver(0); | ||
| 722 | const ip_addr_t *d1 = dns_getserver(1); | ||
| 723 | const ip_addr_t *d2 = dns_getserver(2); | ||
| 724 | snprintf(dns0, sizeof(dns0), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=d0->addr})); | ||
| 725 | snprintf(dns1, sizeof(dns1), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=d1->addr})); | ||
| 726 | snprintf(dns2, sizeof(dns2), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=d2->addr})); | ||
| 727 | cJSON_AddStringToObject(root, "dns0", dns0); | ||
| 728 | cJSON_AddStringToObject(root, "dns1", dns1); | ||
| 729 | cJSON_AddStringToObject(root, "dns2", dns2); | ||
| 730 | |||
| 731 | char sta_ip_str[16], sta_gw_str[16]; | ||
| 732 | snprintf(sta_ip_str, sizeof(sta_ip_str), IPSTR, IP2STR(&s_sta_ip)); | ||
| 733 | snprintf(sta_gw_str, sizeof(sta_gw_str), IPSTR, IP2STR(&s_sta_gw)); | ||
| 734 | cJSON_AddStringToObject(root, "sta_ip", sta_ip_str); | ||
| 735 | cJSON_AddStringToObject(root, "sta_gw", sta_gw_str); | ||
| 736 | |||
| 737 | struct addrinfo hints = {0}, *res = NULL; | ||
| 738 | hints.ai_family = AF_INET; | ||
| 739 | int dns_rc = getaddrinfo("testnut-compat.mints.orangesync.tech", NULL, &hints, &res); | ||
| 740 | if (dns_rc == 0 && res) { | ||
| 741 | struct sockaddr_in *addr = (struct sockaddr_in *)res->ai_addr; | ||
| 742 | char resolved[16]; | ||
| 743 | snprintf(resolved, sizeof(resolved), IPSTR, IP2STR(&(esp_ip4_addr_t){.addr=addr->sin_addr.s_addr})); | ||
| 744 | cJSON_AddStringToObject(root, "dns_resolve", resolved); | ||
| 745 | } else { | ||
| 746 | cJSON_AddStringToObject(root, "dns_resolve", dns_rc == 0 ? "no-addr" : "FAIL"); | ||
| 747 | } | ||
| 748 | if (res) freeaddrinfo(res); | ||
| 749 | |||
| 703 | char *json = cJSON_PrintUnformatted(root); | 750 | char *json = cJSON_PrintUnformatted(root); |
| 704 | httpd_resp_set_type(req, "application/json"); | 751 | httpd_resp_set_type(req, "application/json"); |
| 705 | httpd_resp_sendstr(req, json); | 752 | httpd_resp_sendstr(req, json); |