Skip to content

Commit 98a7c0b

Browse files
committed
feat: switching hardcoded HTML to sd-card stored .html
1 parent 385b505 commit 98a7c0b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

components/Applications/wifi/evil_twin.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,42 @@ static int password_count = 0;
2828
// =================================================================
2929
// HTML do Portal Cativo e Páginas
3030
// =================================================================
31+
//
32+
// Le arquivo como string
33+
static const char *getHtmlBuffer(void) {
34+
int lineCount = 0;
35+
if (sd_count_lines(path, &lineCount) != 0 | lineCount <= 0) {
36+
ESP_LOGE(TAG_ET, "Error to count line of empty file");
37+
return NULL;
38+
}
39+
40+
const size_t predictLineSize = 80;
41+
site_t predictTotalFileSize = lineCount * PredictLineSize;
42+
43+
char *buffer = (char *)malloc(predictTotalFileSize);
44+
if (!buffer) {
45+
ESP_LOGE(TAG_ET, "Error to allocate bytes");
46+
return NULL;
47+
}
48+
49+
int result = sd_read_string(path, buffer, sizeof(buffer + 1));
50+
51+
if (result != 0) {
52+
ESP_LOGE(TAG_ET, "Error to read file <file> codigo: <code>");
53+
free(buffer);
54+
return NULL;
55+
}
56+
57+
size_t realSize = strlen(buffer);
58+
char *finalBuffer = (char *)realloc(buffer, realSize + 1);
59+
if (finalBuffer) {
60+
buffer = finalBuffer;
61+
}
62+
63+
ESP_LOGI(TAG_ET, "Success Buffer Retrieved: <tam> bytes", realSize);
64+
return buffer;
65+
}
66+
3167
static const char *captive_portal_html =
3268
"<!DOCTYPE html><html><head><title>Wi-Fi Login</title><meta "
3369
"name='viewport' content='width=device-width, "

0 commit comments

Comments
 (0)