Explorar el Código

- first check-in for mucurses_test.c

- added mucurses_test.c build targets
tags/v0.9.3
Dan Lynch hace 18 años
padre
commit
2b15084388
Se han modificado 2 ficheros con 71 adiciones y 2 borrados
  1. 8
    2
      src/util/Makefile
  2. 63
    0
      src/util/mucurses_test.c

+ 8
- 2
src/util/Makefile Ver fichero

@@ -1,7 +1,7 @@
1 1
 BLIB = ../bin/blib.a
2 2
 CFLAGS = -Os
3 3
 
4
-all : hijack prototester
4
+all : hijack prototester mucurses_test
5 5
 
6 6
 hijack : hijack.c
7 7
 	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wall -lpcap -o $@ $<
@@ -12,5 +12,11 @@ prototester.o : prototester.c
12 12
 prototester : prototester.o $(BLIB)
13 13
 	$(CC) -o $@ $< -lc $(BLIB)
14 14
 
15
+mucurses_test.o : mucurses_test.c
16
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wall -o $@ -c $<
17
+
18
+mucurses_test : mucurses_test.o $(BLIB)
19
+	$(CC) -o $@ $< -lc $(BLIB)
20
+
15 21
 clean :
16
-	rm -f hijack prototester *.o
22
+	rm -f hijack prototester mucurses_test *.o

+ 63
- 0
src/util/mucurses_test.c Ver fichero

@@ -0,0 +1,63 @@
1
+#include "../include/curses.h"
2
+#include <string.h>
3
+#include <unistd.h>
4
+#include <stdlib.h>
5
+
6
+void get_iscsi_chap_secret( char * );
7
+void mdelay( int msecs );
8
+
9
+int main ( void ) {
10
+	char secret[16];
11
+	initscr();
12
+	echo();
13
+	werase(stdscr);
14
+	box( stdscr, '|', '-' );
15
+	get_iscsi_chap_secret(secret);
16
+
17
+	mvwprintw( stdscr, 3, 5, "password is \"%s\"", secret );
18
+	mdelay(2500);
19
+
20
+	stdscr->scr->exit(stdscr->scr);
21
+
22
+	return 0;
23
+}
24
+
25
+void get_iscsi_chap_secret( char *sec ) {
26
+	char 	*title = "Set new iSCSI CHAP secret",
27
+		*msg = "Configure the iSCSI access secret",
28
+		pw1[16], pw2[16];
29
+	WINDOW *secret;
30
+
31
+	secret = newwin( stdscr->height / 2,
32
+			 stdscr->width / 2,
33
+			 stdscr->height / 4,
34
+			 stdscr->width / 4 );
35
+
36
+	wborder( secret, '|', '|', '-', '-', '+', '+', '+', '+' );
37
+	mvwprintw( secret, 1, 2, "%s", title );
38
+	mvwhline( secret, 2, 1, '-' | secret->attrs, secret->width - 2 );
39
+	mvwprintw( secret, 4, 2, "%s", msg );
40
+	mvwprintw( secret, 6, 3, "secret" );
41
+	mvwprintw( secret, 8, 3, "confirm" );
42
+ start:
43
+	mvwhline( secret, 6, 12, '_' | secret->attrs, 16 );
44
+	mvwhline( secret, 8, 12, '_' | secret->attrs, 16 );
45
+
46
+	wmove( secret, 6, 12 );
47
+	wgetnstr( secret, pw1, 12 );
48
+	wmove( secret, 8, 12 );
49
+	wgetnstr( secret, pw2, 12 );
50
+
51
+	if ( strcmp( pw1, pw2 ) == 0 ) {
52
+		strcpy( sec, pw1 );
53
+		werase( secret );
54
+	}
55
+	else {
56
+		mvwprintw( secret, 10, 3, "Passwords do not match" );
57
+		goto start;
58
+	}
59
+}
60
+
61
+void mdelay ( int msecs ) {
62
+	usleep( msecs * 1000 );
63
+}

Loading…
Cancelar
Guardar