Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

login_ui.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. /** @file
  20. *
  21. * Login UI
  22. *
  23. */
  24. #include <string.h>
  25. #include <errno.h>
  26. #include <curses.h>
  27. #include <ipxe/console.h>
  28. #include <ipxe/settings.h>
  29. #include <ipxe/editbox.h>
  30. #include <ipxe/keys.h>
  31. #include <ipxe/login_ui.h>
  32. /* Colour pairs */
  33. #define CPAIR_NORMAL 1
  34. #define CPAIR_LABEL 2
  35. #define CPAIR_EDITBOX 3
  36. /* Screen layout */
  37. #define USERNAME_LABEL_ROW 8
  38. #define USERNAME_ROW 10
  39. #define PASSWORD_LABEL_ROW 14
  40. #define PASSWORD_ROW 16
  41. #define LABEL_COL 36
  42. #define EDITBOX_COL 30
  43. #define EDITBOX_WIDTH 20
  44. int login_ui ( void ) {
  45. char username[64];
  46. char password[64];
  47. struct edit_box username_box;
  48. struct edit_box password_box;
  49. struct edit_box *current_box = &username_box;
  50. int key;
  51. int rc = -EINPROGRESS;
  52. /* Fetch current setting values */
  53. fetch_string_setting ( NULL, &username_setting, username,
  54. sizeof ( username ) );
  55. fetch_string_setting ( NULL, &password_setting, password,
  56. sizeof ( password ) );
  57. /* Initialise UI */
  58. initscr();
  59. start_color();
  60. init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLACK );
  61. init_pair ( CPAIR_LABEL, COLOR_WHITE, COLOR_BLACK );
  62. init_pair ( CPAIR_EDITBOX, COLOR_WHITE, COLOR_BLUE );
  63. init_editbox ( &username_box, username, sizeof ( username ), NULL,
  64. USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
  65. init_editbox ( &password_box, password, sizeof ( password ), NULL,
  66. PASSWORD_ROW, EDITBOX_COL, EDITBOX_WIDTH,
  67. EDITBOX_STARS );
  68. /* Draw initial UI */
  69. erase();
  70. color_set ( CPAIR_LABEL, NULL );
  71. mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
  72. mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
  73. color_set ( CPAIR_EDITBOX, NULL );
  74. draw_editbox ( &username_box );
  75. draw_editbox ( &password_box );
  76. /* Main loop */
  77. while ( rc == -EINPROGRESS ) {
  78. draw_editbox ( current_box );
  79. key = getkey ( 0 );
  80. switch ( key ) {
  81. case KEY_DOWN:
  82. current_box = &password_box;
  83. break;
  84. case KEY_UP:
  85. current_box = &username_box;
  86. break;
  87. case TAB:
  88. current_box = ( ( current_box == &username_box ) ?
  89. &password_box : &username_box );
  90. break;
  91. case KEY_ENTER:
  92. if ( current_box == &username_box ) {
  93. current_box = &password_box;
  94. } else {
  95. rc = 0;
  96. }
  97. break;
  98. case CTRL_C:
  99. case ESC:
  100. rc = -ECANCELED;
  101. break;
  102. default:
  103. edit_editbox ( current_box, key );
  104. break;
  105. }
  106. }
  107. /* Terminate UI */
  108. color_set ( CPAIR_NORMAL, NULL );
  109. erase();
  110. endwin();
  111. if ( rc != 0 )
  112. return rc;
  113. /* Store settings */
  114. if ( ( rc = store_setting ( NULL, &username_setting, username,
  115. strlen ( username ) ) ) != 0 )
  116. return rc;
  117. if ( ( rc = store_setting ( NULL, &password_setting, password,
  118. strlen ( password ) ) ) != 0 )
  119. return rc;
  120. return 0;
  121. }