X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fnc-config.c;h=4685fa5d0db1988661503115163ddf30c9a7a552;hp=58bae290c23d03686b27d116a70a6d4eb1c7d577;hb=07f6db7fc29a93fae3213af18371cccb17e0276a;hpb=af51ccb8b8664eb9462aa4a6e7e2a9f52430647f diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c index 58bae29..4685fa5 100644 --- a/ui/ncurses/nc-config.c +++ b/ui/ncurses/nc-config.c @@ -29,11 +29,12 @@ #include #include +#include "ui/common/discover-client.h" #include "nc-cui.h" #include "nc-config.h" #include "nc-widgets.h" -#define N_FIELDS 48 +#define N_FIELDS 49 extern struct help_text config_help_text; @@ -51,7 +52,6 @@ struct config_screen { bool exit; bool show_help; - bool show_subset; bool need_redraw; bool need_update; @@ -118,6 +118,8 @@ struct config_screen { struct nc_widget_label *manual_console_l; struct nc_widget_label *current_console_l; + struct nc_widget_button *update_password_l; + struct nc_widget_label *net_override_l; struct nc_widget_label *safe_mode; struct nc_widget_button *ok_b; @@ -175,7 +177,7 @@ static void config_screen_process_key(struct nc_scr *scr, int key) cui_show_help(screen->cui, _("System Configuration"), &config_help_text); - } else if (handled && !screen->show_subset) { + } else if (handled && (screen->cui->current == scr)) { pad_refresh(screen); } } @@ -203,7 +205,7 @@ static int screen_process_form(struct config_screen *screen) const struct system_info *sysinfo = screen->cui->sysinfo; enum net_conf_type net_conf_type; struct interface_config *iface; - bool allow_write, autoboot; + bool allow_write; char *str, *end; struct config *config; int i, n_boot_opts, rc; @@ -218,8 +220,8 @@ static int screen_process_form(struct config_screen *screen) n_boot_opts = widget_subset_get_order(config, &order, screen->widgets.boot_order_f); - autoboot = widget_select_get_value(screen->widgets.autoboot_f); - config->autoboot_enabled = autoboot && n_boot_opts; + config->autoboot_enabled = widget_select_get_value( + screen->widgets.autoboot_f); config->n_autoboot_opts = n_boot_opts; config->autoboot_opts = talloc_array(config, struct autoboot_option, @@ -370,15 +372,39 @@ static int screen_process_form(struct config_screen *screen) return 0; } +static void config_screen_config_cb(struct nc_scr *scr) +{ + struct config_screen *screen = config_screen_from_scr(scr); + + if (!screen_process_form(screen)) + screen->exit = true; +} + +#ifdef CRYPT_SUPPORT +static void password_click(void *arg) +{ + struct config_screen *screen = arg; + + screen->need_update = true; + cui_show_auth(screen->cui, screen->scr.main_ncw, true, NULL); +} +#endif + static void ok_click(void *arg) { struct config_screen *screen = arg; - if (screen_process_form(screen)) - /* errors are written to the status line, so we'll need - * to refresh */ - wrefresh(screen->scr.main_ncw); - else - screen->exit = true; + + if (discover_client_authenticated(screen->cui->client)) { + if (screen_process_form(screen)) + /* errors are written to the status line, so we'll need + * to refresh */ + wrefresh(screen->scr.main_ncw); + else + screen->exit = true; + } else { + cui_show_auth(screen->cui, screen->scr.main_ncw, false, + config_screen_config_cb); + } } static void help_click(void *arg) @@ -650,6 +676,12 @@ static void config_screen_layout_widgets(struct config_screen *screen) screen->widgets.current_console_l), false); } +#ifdef CRYPT_SUPPORT + widget_move(widget_button_base(screen->widgets.update_password_l), + y, screen->field_x); + y += 2; +#endif + if (screen->net_override) { widget_move(widget_label_base(screen->widgets.net_override_l), y, screen->label_x); @@ -705,7 +737,6 @@ static void config_screen_add_device(void *arg) { struct config_screen *screen = arg; - screen->show_subset = true; cui_show_subset(screen->cui, _("Select a boot device to add"), screen->widgets.boot_order_f); } @@ -1029,8 +1060,8 @@ static void config_screen_setup_widgets(struct config_screen *screen, widget_textbox_set_fixed_size(screen->widgets.ip_addr_f); widget_textbox_set_fixed_size(screen->widgets.ip_mask_f); - widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f); - widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 31); + widget_textbox_set_validator_ip(screen->widgets.ip_addr_f); + widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 127); screen->widgets.gateway_l = widget_new_label(set, 0, 0, _("Gateway:")); screen->widgets.gateway_f = widget_new_textbox(set, 0, 0, 16, gw); @@ -1038,10 +1069,11 @@ static void config_screen_setup_widgets(struct config_screen *screen, widget_new_label(set, 0, 0, _("(eg. 192.168.0.1)")); widget_textbox_set_fixed_size(screen->widgets.gateway_f); - widget_textbox_set_validator_ipv4(screen->widgets.gateway_f); + widget_textbox_set_validator_ip(screen->widgets.gateway_f); screen->widgets.url_l = widget_new_label(set, 0, 0, _("URL:")); screen->widgets.url_f = widget_new_textbox(set, 0, 0, 32, url); + widget_textbox_set_validator_url(screen->widgets.url_f); screen->widgets.url_help_l = widget_new_label(set, 0, 0, _("(eg. tftp://)")); @@ -1058,7 +1090,7 @@ static void config_screen_setup_widgets(struct config_screen *screen, screen->widgets.dns_help_l = widget_new_label(set, 0, 0, _("(eg. 192.168.0.2)")); - widget_textbox_set_validator_ipv4_multi(screen->widgets.dns_f); + widget_textbox_set_validator_ip_multi(screen->widgets.dns_f); screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0, _("(if not provided by DHCP server)")); @@ -1112,6 +1144,11 @@ static void config_screen_setup_widgets(struct config_screen *screen, ttyname(STDIN_FILENO)); screen->widgets.current_console_l = widget_new_label(set, 0 , 0, tty); +#ifdef CRYPT_SUPPORT + screen->widgets.update_password_l = widget_new_button(set, 0, 0, 30, + _("Update system password"), password_click, screen); +#endif + screen->widgets.ok_b = widget_new_button(set, 0, 0, 10, _("OK"), ok_click, screen); screen->widgets.help_b = widget_new_button(set, 0, 0, 10, _("Help"), @@ -1211,7 +1248,12 @@ void config_screen_update(struct config_screen *screen, static int config_screen_post(struct nc_scr *scr) { struct config_screen *screen = config_screen_from_scr(scr); - screen->show_subset = false; + + /* We may have been posted after an auth action completed */ + if (screen->exit) { + screen->on_exit(screen->cui); + return 0; + } if (screen->need_update) { config_screen_draw(screen, screen->cui->config, @@ -1261,7 +1303,6 @@ struct config_screen *config_screen_init(struct cui *cui, screen->field_x = 17; screen->ipmi_override = false; - screen->show_subset = false; screen->scr.frame.ltitle = talloc_strdup(screen, _("Petitboot System Configuration"));