Преглед на файлове

[login] Add "login" command and UI

tags/v0.9.7
Michael Brown преди 15 години
родител
ревизия
6de4db5da0
променени са 6 файла, в които са добавени 179 реда и са изтрити 0 реда
  1. 1
    0
      src/config/general.h
  2. 3
    0
      src/core/config.c
  3. 27
    0
      src/hci/commands/login_cmd.c
  4. 135
    0
      src/hci/tui/login_ui.c
  5. 1
    0
      src/include/gpxe/errfile.h
  6. 12
    0
      src/include/gpxe/login_ui.h

+ 1
- 0
src/config/general.h Целия файл

@@ -100,6 +100,7 @@
100 100
 #define IMAGE_CMD		/* Image management commands */
101 101
 #define DHCP_CMD		/* DHCP management commands */
102 102
 #define SANBOOT_CMD		/* SAN boot commands */
103
+#define LOGIN_CMD		/* Login command */
103 104
 
104 105
 /*
105 106
  * Obscure configuration options

+ 3
- 0
src/core/config.c Целия файл

@@ -193,6 +193,9 @@ REQUIRE_OBJECT ( dhcp_cmd );
193 193
 #ifdef SANBOOT_CMD
194 194
 REQUIRE_OBJECT ( sanboot_cmd );
195 195
 #endif
196
+#ifdef LOGIN_CMD
197
+REQUIRE_OBJECT ( login_cmd );
198
+#endif
196 199
 
197 200
 /*
198 201
  * Drag in miscellaneous objects

+ 27
- 0
src/hci/commands/login_cmd.c Целия файл

@@ -0,0 +1,27 @@
1
+#include <string.h>
2
+#include <stdio.h>
3
+#include <gpxe/command.h>
4
+#include <gpxe/login_ui.h>
5
+
6
+static int login_exec ( int argc, char **argv ) {
7
+	int rc;
8
+
9
+	if ( argc > 1 ) {
10
+		printf ( "Usage: %s\n"
11
+			 "Prompt for login credentials\n", argv[0] );
12
+		return 1;
13
+	}
14
+
15
+	if ( ( rc = login_ui() ) != 0 ) {
16
+		printf ( "Could not set credentials: %s\n",
17
+			 strerror ( rc ) );
18
+		return 1;
19
+	}
20
+
21
+	return 0;
22
+}
23
+
24
+struct command login_command __command = {
25
+	.name = "login",
26
+	.exec = login_exec,
27
+};

+ 135
- 0
src/hci/tui/login_ui.c Целия файл

@@ -0,0 +1,135 @@
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
+
19
+/** @file
20
+ *
21
+ * Login UI
22
+ *
23
+ */
24
+
25
+#include <string.h>
26
+#include <errno.h>
27
+#include <curses.h>
28
+#include <console.h>
29
+#include <gpxe/settings.h>
30
+#include <gpxe/editbox.h>
31
+#include <gpxe/keys.h>
32
+#include <gpxe/login_ui.h>
33
+
34
+/* Colour pairs */
35
+#define CPAIR_NORMAL		1
36
+#define CPAIR_LABEL		2
37
+#define CPAIR_EDITBOX		3
38
+
39
+/* Screen layout */
40
+#define USERNAME_LABEL_ROW	8
41
+#define USERNAME_ROW		10
42
+#define PASSWORD_LABEL_ROW	14
43
+#define PASSWORD_ROW		16
44
+#define LABEL_COL		36
45
+#define EDITBOX_COL		30
46
+#define EDITBOX_WIDTH		20
47
+
48
+int login_ui ( void ) {
49
+	char username[64];
50
+	char password[64];
51
+	struct edit_box username_box;
52
+	struct edit_box password_box;
53
+	struct edit_box *current_box = &username_box;
54
+	int key;
55
+	int rc = -EINPROGRESS;
56
+
57
+	/* Fetch current setting values */
58
+	fetch_string_setting ( NULL, &username_setting, username,
59
+			       sizeof ( username ) );
60
+	fetch_string_setting ( NULL, &password_setting, password,
61
+			       sizeof ( password ) );
62
+
63
+	/* Initialise UI */
64
+	initscr();
65
+	start_color();
66
+	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLACK );
67
+	init_pair ( CPAIR_LABEL, COLOR_WHITE, COLOR_BLACK );
68
+	init_pair ( CPAIR_EDITBOX, COLOR_WHITE, COLOR_BLUE );
69
+	init_editbox ( &username_box, username, sizeof ( username ), NULL,
70
+		       USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
71
+	init_editbox ( &password_box, password, sizeof ( password ), NULL,
72
+		       PASSWORD_ROW, EDITBOX_COL, EDITBOX_WIDTH,
73
+		       EDITBOX_STARS );
74
+
75
+	/* Draw initial UI */
76
+	erase();
77
+	color_set ( CPAIR_LABEL, NULL );
78
+	mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
79
+	mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
80
+	color_set ( CPAIR_EDITBOX, NULL );
81
+	draw_editbox ( &username_box );
82
+	draw_editbox ( &password_box );
83
+
84
+	/* Main loop */
85
+	while ( rc == -EINPROGRESS ) {
86
+
87
+		draw_editbox ( current_box );
88
+
89
+		key = getkey();
90
+		switch ( key ) {
91
+		case KEY_DOWN:
92
+			current_box = &password_box;
93
+			break;
94
+		case KEY_UP:
95
+			current_box = &username_box;
96
+			break;
97
+		case TAB:
98
+			current_box = ( ( current_box == &username_box ) ?
99
+					&password_box : &username_box );
100
+			break;
101
+		case KEY_ENTER:
102
+			if ( current_box == &username_box ) {
103
+				current_box = &password_box;
104
+			} else {
105
+				rc = 0;
106
+			}
107
+			break;
108
+		case CTRL_C:
109
+		case ESC:
110
+			rc = -ECANCELED;
111
+			break;
112
+		default:
113
+			edit_editbox ( current_box, key );
114
+			break;
115
+		}
116
+	}
117
+
118
+	/* Terminate UI */
119
+	color_set ( CPAIR_NORMAL, NULL );
120
+	erase();
121
+	endwin();
122
+
123
+	if ( rc != 0 )
124
+		return rc;
125
+
126
+	/* Store settings */
127
+	if ( ( rc = store_setting ( NULL, &username_setting, username,
128
+				    strlen ( username ) ) ) != 0 )
129
+		return rc;
130
+	if ( ( rc = store_setting ( NULL, &password_setting, password,
131
+				    strlen ( password ) ) ) != 0 )
132
+		return rc;
133
+
134
+	return 0;
135
+}

+ 1
- 0
src/include/gpxe/errfile.h Целия файл

@@ -171,6 +171,7 @@
171 171
 #define ERRFILE_efi_smbios	      ( ERRFILE_OTHER | 0x00140000 )
172 172
 #define ERRFILE_pxemenu		      ( ERRFILE_OTHER | 0x00150000 )
173 173
 #define ERRFILE_x509		      ( ERRFILE_OTHER | 0x00160000 )
174
+#define ERRFILE_login_ui	      ( ERRFILE_OTHER | 0x00170000 )
174 175
 
175 176
 /** @} */
176 177
 

+ 12
- 0
src/include/gpxe/login_ui.h Целия файл

@@ -0,0 +1,12 @@
1
+#ifndef _GPXE_LOGIN_UI_H
2
+#define _GPXE_LOGIN_UI_H
3
+
4
+/** @file
5
+ *
6
+ * Login UI
7
+ *
8
+ */
9
+
10
+extern int login_ui ( void );
11
+
12
+#endif /* _GPXE_LOGIN_UI_H */

Loading…
Отказ
Запис