summaryrefslogtreecommitdiffstats
path: root/src/hci/tui/login_ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hci/tui/login_ui.c')
-rw-r--r--src/hci/tui/login_ui.c152
1 files changed, 46 insertions, 106 deletions
diff --git a/src/hci/tui/login_ui.c b/src/hci/tui/login_ui.c
index 56fc2fa97..e265f81b0 100644
--- a/src/hci/tui/login_ui.c
+++ b/src/hci/tui/login_ui.c
@@ -22,6 +22,7 @@
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+FILE_SECBOOT ( PERMITTED );
/** @file
*
@@ -29,117 +30,56 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
*/
-#include <string.h>
-#include <errno.h>
-#include <curses.h>
-#include <ipxe/console.h>
-#include <ipxe/settings.h>
-#include <ipxe/editbox.h>
-#include <ipxe/keys.h>
-#include <ipxe/ansicol.h>
+#include <ipxe/dynui.h>
#include <ipxe/login_ui.h>
-/* Screen layout */
-#define USERNAME_LABEL_ROW ( ( LINES / 2U ) - 4U )
-#define USERNAME_ROW ( ( LINES / 2U ) - 2U )
-#define PASSWORD_LABEL_ROW ( ( LINES / 2U ) + 2U )
-#define PASSWORD_ROW ( ( LINES / 2U ) + 4U )
-#define LABEL_COL ( ( COLS / 2U ) - 4U )
-#define EDITBOX_COL ( ( COLS / 2U ) - 10U )
-#define EDITBOX_WIDTH 20U
+static struct dynamic_item username;
+static struct dynamic_item password;
-int login_ui ( int nouser ) {
- char username[64];
- char password[64];
- struct edit_box username_box;
- struct edit_box password_box;
- struct edit_box *current_box = nouser ? &password_box : &username_box;
- int key;
- int rc = -EINPROGRESS;
-
- /* Fetch current setting values */
- fetch_string_setting ( NULL, &username_setting, username,
- sizeof ( username ) );
- fetch_string_setting ( NULL, &password_setting, password,
- sizeof ( password ) );
-
- /* Initialise UI */
- initscr();
- start_color();
- init_editbox ( &username_box, username, sizeof ( username ), NULL,
- USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
- init_editbox ( &password_box, password, sizeof ( password ), NULL,
- PASSWORD_ROW, EDITBOX_COL, EDITBOX_WIDTH,
- EDITBOX_STARS );
-
- /* Draw initial UI */
- color_set ( CPAIR_NORMAL, NULL );
- erase();
- attron ( A_BOLD );
- if ( ! nouser ) {
- mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
- }
- mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
- attroff ( A_BOLD );
- color_set ( CPAIR_EDIT, NULL );
- if ( ! nouser ) {
- draw_editbox ( &username_box );
- }
- draw_editbox ( &password_box );
+static struct dynamic_ui login = {
+ .items = {
+ .prev = &password.list,
+ .next = &username.list,
+ },
+ .hidden_items = {
+ .prev = &login.hidden_items,
+ .next = &login.hidden_items,
+ },
+ .count = 2,
+};
- /* Main loop */
- while ( rc == -EINPROGRESS ) {
+static struct dynamic_item username = {
+ .list = {
+ .prev = &login.items,
+ .next = &password.list,
+ },
+ .name = "username",
+ .text = "Username",
+ .index = 0,
+};
- draw_editbox ( current_box );
+static struct dynamic_item password = {
+ .list = {
+ .prev = &username.list,
+ .next = &login.items,
+ },
+ .name = "password",
+ .text = "Password",
+ .index = 1,
+ .flags = DYNUI_SECRET,
+};
- key = getkey ( 0 );
- switch ( key ) {
- case KEY_DOWN:
- current_box = &password_box;
- break;
- case KEY_UP:
- if ( ! nouser ) {
- current_box = &username_box;
- }
- break;
- case TAB:
- if ( ! nouser ) {
- current_box = ( ( current_box == &username_box ) ?
- &password_box : &username_box );
- }
- break;
- case KEY_ENTER:
- if ( current_box == &username_box ) {
- current_box = &password_box;
- } else {
- rc = 0;
- }
- break;
- case CTRL_C:
- case ESC:
- rc = -ECANCELED;
- break;
- default:
- edit_editbox ( current_box, key );
- break;
- }
+int login_ui ( int nouser ) {
+ if ( nouser ) {
+ password.index = 0;
+ password.list.prev = &login.items;
+ login.count = 1;
+ login.items.next = &password.list;
+ } else {
+ password.index = 1;
+ password.list.prev = &username.list;
+ login.count = 2;
+ login.items.next = &username.list;
}
-
- /* Terminate UI */
- color_set ( CPAIR_NORMAL, NULL );
- erase();
- endwin();
-
- if ( rc != 0 )
- return rc;
-
- /* Store settings */
- if ( ( rc = store_setting ( NULL, &username_setting, username,
- strlen ( username ) ) ) != 0 )
- return rc;
- if ( ( rc = store_setting ( NULL, &password_setting, password,
- strlen ( password ) ) ) != 0 )
- return rc;
-
- return 0;
+ return show_form ( &login );
}