Skip to content

Commit

Permalink
added dialogue for selecting a portal (#41)
Browse files Browse the repository at this point in the history
* added dialogue for selecting a portal

* default formatting

* allow seeing current logs without portal reset

* format

---------

Co-authored-by: NIK\nickw <nyczdesignz@gmail.com>
Co-authored-by: bigbrodude6119 <138256922+bigbrodude6119@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 17, 2023
1 parent 51eaaa9 commit 790a75e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
11 changes: 6 additions & 5 deletions evil_portal_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ Evil_PortalApp *evil_portal_app_alloc() {
app->sent_html = false;
app->sent_ap = false;
app->sent_reset = false;
app->has_command_queue = false;
app->has_command_queue = false;
app->command_index = 0;
app->portal_logs = furi_string_alloc();

app->gui = furi_record_open(RECORD_GUI);
app->dialogs = furi_record_open(RECORD_DIALOGS);

app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&evil_portal_scene_handlers, app);
Expand Down Expand Up @@ -70,8 +71,7 @@ Evil_PortalApp *evil_portal_app_alloc() {
return app;
}

void evil_portal_app_free(Evil_PortalApp *app) {

void evil_portal_app_free(Evil_PortalApp *app) {
// save latest logs
if (furi_string_utf8_length(app->portal_logs) > 0) {
write_logs(app->portal_logs);
Expand Down Expand Up @@ -101,17 +101,18 @@ void evil_portal_app_free(Evil_PortalApp *app) {

// Close records
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_DIALOGS);

free(app);
}

int32_t evil_portal_app(void *p) {
int32_t evil_portal_app(void *p) {
UNUSED(p);
Evil_PortalApp *evil_portal_app = evil_portal_app_alloc();

evil_portal_app->uart = evil_portal_uart_init(evil_portal_app);

view_dispatcher_run(evil_portal_app->view_dispatcher);
view_dispatcher_run(evil_portal_app->view_dispatcher);

evil_portal_app_free(evil_portal_app);

Expand Down
9 changes: 8 additions & 1 deletion evil_portal_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>

#include <assets_icons.h>
#include <dialogs/dialogs.h>

#define NUM_MENU_ITEMS (4)

#define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
Expand All @@ -20,12 +23,16 @@
#define SET_AP_CMD "setap"
#define RESET_CMD "reset"

#define EVIL_PORTAL_INDEX_EXTENSION ".html"
#define EVIL_PORTAL_BASE_FOLDER "/apps_data/evil_portal/"

struct Evil_PortalApp {
Gui *gui;
ViewDispatcher *view_dispatcher;
SceneManager *scene_manager;
DialogsApp *dialogs;

FuriString* portal_logs;
FuriString *portal_logs;
const char *command_queue[1];
int command_index;
bool has_command_queue;
Expand Down
28 changes: 23 additions & 5 deletions helpers/evil_portal_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@ static Storage *evil_portal_open_storage() {

static void evil_portal_close_storage() { furi_record_close(RECORD_STORAGE); }

void evil_portal_read_index_html(void *context) {
bool evil_portal_read_index_html(void *context) {
FuriString *file_path = furi_string_alloc();

DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options,
EVIL_PORTAL_INDEX_EXTENSION,
NULL); // TODO configure icon
browser_options.base_path = EVIL_PORTAL_BASE_FOLDER;

Evil_PortalApp *app = context;
bool res = dialog_file_browser_show(app->dialogs, file_path, file_path,
&browser_options);

if (!res) {
furi_string_free(file_path);
return false;
}

Storage *storage = evil_portal_open_storage();
FileInfo fi;

if (storage_common_stat(storage, EVIL_PORTAL_INDEX_SAVE_PATH, &fi) ==
if (storage_common_stat(storage, furi_string_get_cstr(file_path), &fi) ==
FSE_OK) {
File *index_html = storage_file_alloc(storage);
if (storage_file_open(index_html, EVIL_PORTAL_INDEX_SAVE_PATH, FSAM_READ,
FSOM_OPEN_EXISTING)) {
if (storage_file_open(index_html, furi_string_get_cstr(file_path),
FSAM_READ, FSOM_OPEN_EXISTING)) {
app->index_html = malloc((size_t)fi.size);
uint8_t *buf_ptr = app->index_html;
size_t read = 0;
Expand All @@ -31,6 +46,7 @@ void evil_portal_read_index_html(void *context) {
}
free(buf_ptr);
}
furi_string_free(file_path);
storage_file_close(index_html);
storage_file_free(index_html);
} else {
Expand All @@ -43,6 +59,7 @@ void evil_portal_read_index_html(void *context) {
}

evil_portal_close_storage();
return true;
}

void evil_portal_read_ap_name(void *context) {
Expand Down Expand Up @@ -110,7 +127,8 @@ void write_logs(FuriString *portal_logs) {
File *file = storage_file_alloc(storage);

if (storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
storage_file_write(file, furi_string_get_cstr(portal_logs), furi_string_utf8_length(portal_logs));
storage_file_write(file, furi_string_get_cstr(portal_logs),
furi_string_utf8_length(portal_logs));
}
storage_file_close(file);
storage_file_free(file);
Expand Down
5 changes: 3 additions & 2 deletions helpers/evil_portal_storage.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../evil_portal_app_i.h"
#include <dialogs/dialogs.h>
#include <flipper_format/flipper_format_i.h>
#include <lib/toolbox/stream/file_stream.h>
#include <stdlib.h>
Expand All @@ -10,8 +11,8 @@
#define EVIL_PORTAL_AP_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/ap.config.txt"
#define EVIL_PORTAL_LOG_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/logs"

void evil_portal_read_index_html(void *context);
bool evil_portal_read_index_html(void *context);
void evil_portal_read_ap_name(void *context);
void write_logs(FuriString* portal_logs);
void write_logs(FuriString *portal_logs);
char *sequential_file_resolve_path(Storage *storage, const char *dir,
const char *prefix, const char *extension);
39 changes: 30 additions & 9 deletions scenes/evil_portal_scene_console_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ void evil_portal_console_output_handle_rx_data_cb(uint8_t *buf, size_t len,
void evil_portal_scene_console_output_on_enter(void *context) {
Evil_PortalApp *app = context;

bool portal_file_set = false;

TextBox *text_box = app->text_box;
text_box_reset(app->text_box);
text_box_set_font(text_box, TextBoxFontText);
Expand Down Expand Up @@ -67,14 +69,26 @@ void evil_portal_scene_console_output_on_enter(void *context) {

if (0 ==
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
app->command_queue[0] = SET_AP_CMD;
app->has_command_queue = true;
app->command_index = 0;
if (app->show_stopscan_tip) {
const char *msg =
"Starting portal\nIf no response press\nBACK to return\n";
furi_string_cat_str(app->text_box_store, msg);
app->text_box_store_strlen += strlen(msg);

portal_file_set = evil_portal_read_index_html(context);

if (portal_file_set) {
app->command_queue[0] = SET_AP_CMD;
app->has_command_queue = true;
app->command_index = 0;
if (app->show_stopscan_tip) {
const char *msg =
"Starting portal\nIf no response press\nBACK to return\n";
furi_string_cat_str(app->text_box_store, msg);
app->text_box_store_strlen += strlen(msg);
}
} else {
if (app->show_stopscan_tip) {
const char *msg = "No portal selected\nShowing current logs\nPress "
"BACK to return\n";
furi_string_cat_str(app->text_box_store, msg);
app->text_box_store_strlen += strlen(msg);
}
}
}

Expand Down Expand Up @@ -102,7 +116,14 @@ void evil_portal_scene_console_output_on_enter(void *context) {
if (app->is_command && app->selected_tx_string) {
if (0 ==
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
evil_portal_read_index_html(context);

if (!portal_file_set) {
scene_manager_set_scene_state(app->scene_manager,
Evil_PortalSceneConsoleOutput, 0);
view_dispatcher_switch_to_view(app->view_dispatcher,
Evil_PortalAppViewConsoleOutput);
return;
}

FuriString *data = furi_string_alloc();
furi_string_cat(data, "sethtml=");
Expand Down

0 comments on commit 790a75e

Please sign in to comment.