[e16e8f2] | 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[17], pw2[17]; |
---|
| 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, 16 ); |
---|
| 48 | wmove( secret, 8, 12 ); |
---|
| 49 | wgetnstr( secret, pw2, 16 ); |
---|
| 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 | } |
---|