X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ui%2Fncurses%2Fnc-config.c;h=d345c853b23a4e2f1a70b6bfcbecf63d14dac412;hb=5d955dcc4f9a699bc84fe25ff337d51103f845ac;hp=64d0619b66c66703dc64c9d08c9b50e07dfc3903;hpb=8c60755607cbade935b1f763dffbf9ee1c38f97a;p=petitboot diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c index 64d0619..d345c85 100644 --- a/ui/ncurses/nc-config.c +++ b/ui/ncurses/nc-config.c @@ -32,10 +32,16 @@ #include "nc-config.h" #include "nc-widgets.h" -#define N_FIELDS 24 +#define N_FIELDS 25 extern const char *config_help_text; +enum autoboot_type { + AUTOBOOT_ANY, + AUTOBOOT_ONE, + AUTOBOOT_DISABLED, +}; + enum net_conf_type { NET_CONF_TYPE_DHCP_ALL, NET_CONF_TYPE_DHCP_ONE, @@ -59,10 +65,12 @@ struct config_screen { int network_config_y; enum net_conf_type net_conf_type; + enum autoboot_type autoboot_type; struct { - struct nc_widget_checkbox *autoboot_f; + struct nc_widget_select *autoboot_f; struct nc_widget_label *autoboot_l; + struct nc_widget_select *boot_device_f; struct nc_widget_textbox *timeout_f; struct nc_widget_label *timeout_l; struct nc_widget_label *timeout_help_l; @@ -180,13 +188,38 @@ static int screen_process_form(struct config_screen *screen) struct interface_config *iface; struct config *config; char *str, *end; - int rc; + int rc, idx; config = config_copy(screen, screen->cui->config); - config->autoboot_enabled = - widget_checkbox_get_value(screen->widgets.autoboot_f); + screen->autoboot_type = + widget_select_get_value(screen->widgets.autoboot_f); + + config->autoboot_enabled = screen->autoboot_type != AUTOBOOT_DISABLED; + + if (screen->autoboot_type == AUTOBOOT_ONE) { + char mac[20], *uuid = NULL; + + /* if idx is -1 here, we have an unknown UUID selected. + * Otherwise, it's a blockdev index (idx <= n_blockdevs) or an + * interface index. + */ + idx = widget_select_get_value(screen->widgets.boot_device_f); + if (idx >= (int)sysinfo->n_blockdevs) { + struct interface_info *info = sysinfo-> + interfaces[idx - sysinfo->n_blockdevs]; + mac_str(info->hwaddr, info->hwaddr_size, + mac, sizeof(mac)); + uuid = mac; + } else if (idx != -1) { + uuid = sysinfo->blockdevs[idx]->uuid; + } + if (uuid) { + talloc_free(config->boot_device); + config->boot_device = talloc_strdup(config, uuid); + } + } str = widget_textbox_get_value(screen->widgets.timeout_f); if (str) { @@ -208,8 +241,6 @@ static int screen_process_form(struct config_screen *screen) config->network.n_interfaces = 0; } else { - int idx; - iface = talloc_zero(config, struct interface_config); config->network.n_interfaces = 1; config->network.interfaces = talloc_array(config, @@ -249,6 +280,10 @@ static int screen_process_form(struct config_screen *screen) } str = widget_textbox_get_value(screen->widgets.dns_f); + talloc_free(config->network.dns_servers); + config->network.dns_servers = NULL; + config->network.n_dns_servers = 0; + if (str && strlen(str)) { char *dns, *tmp; int i; @@ -315,8 +350,7 @@ static int layout_pair(struct config_screen *screen, int y, return max(widget_height(label_w), widget_height(field)); } -static void config_screen_layout_widgets(struct config_screen *screen, - enum net_conf_type net_conf) +static void config_screen_layout_widgets(struct config_screen *screen) { struct nc_widget *wl, *wf, *wh; int y, x, help_x; @@ -327,16 +361,35 @@ static void config_screen_layout_widgets(struct config_screen *screen, widget_width(widget_textbox_base(screen->widgets.dns_f)); y += layout_pair(screen, y, screen->widgets.autoboot_l, - widget_checkbox_base(screen->widgets.autoboot_f)); + widget_select_base(screen->widgets.autoboot_f)); - wf = widget_textbox_base(screen->widgets.timeout_f); - widget_move(widget_label_base(screen->widgets.timeout_l), - y, screen->label_x); - widget_move(wf, y, screen->field_x); - widget_move(widget_label_base(screen->widgets.timeout_help_l), - y, screen->field_x + widget_width(wf) + 1); + wf = widget_select_base(screen->widgets.boot_device_f); + if (screen->autoboot_type == AUTOBOOT_ONE) { + widget_set_visible(wf, true); + widget_move(wf, y, screen->field_x + 3); + y += widget_height(wf); + } else { + widget_set_visible(wf, false); + } + + y += 1; - y += 2; + wf = widget_textbox_base(screen->widgets.timeout_f); + wl = widget_label_base(screen->widgets.timeout_l); + wh = widget_label_base(screen->widgets.timeout_help_l); + if (screen->autoboot_type != AUTOBOOT_DISABLED) { + widget_set_visible(wl, true); + widget_set_visible(wf, true); + widget_set_visible(wh, true); + widget_move(wl, y, screen->label_x); + widget_move(wf, y, screen->field_x); + widget_move(wh, y, screen->field_x + widget_width(wf) + 1); + y += 2; + } else { + widget_set_visible(wl, false); + widget_set_visible(wf, false); + widget_set_visible(wh, false); + } y += layout_pair(screen, y, screen->widgets.network_l, widget_select_base(screen->widgets.network_f)); @@ -347,8 +400,8 @@ static void config_screen_layout_widgets(struct config_screen *screen, wl = widget_label_base(screen->widgets.iface_l); wf = widget_select_base(screen->widgets.iface_f); - show = net_conf == NET_CONF_TYPE_DHCP_ONE || - net_conf == NET_CONF_TYPE_STATIC; + show = screen->net_conf_type == NET_CONF_TYPE_DHCP_ONE || + screen->net_conf_type == NET_CONF_TYPE_STATIC; widget_set_visible(wl, show); widget_set_visible(wf, show); @@ -357,7 +410,7 @@ static void config_screen_layout_widgets(struct config_screen *screen, y += layout_pair(screen, y, screen->widgets.iface_l, wf) + 1; /* conditionally show static IP params */ - show = net_conf == NET_CONF_TYPE_STATIC; + show = screen->net_conf_type == NET_CONF_TYPE_STATIC; wl = widget_label_base(screen->widgets.ip_addr_l); wf = widget_textbox_base(screen->widgets.ip_addr_f); @@ -406,7 +459,7 @@ static void config_screen_layout_widgets(struct config_screen *screen, y++; /* we show the DNS/DHCP help if we're configuring DHCP */ - show = net_conf != NET_CONF_TYPE_STATIC; + show = screen->net_conf_type != NET_CONF_TYPE_STATIC; wl = widget_label_base(screen->widgets.dns_dhcp_help_l); widget_set_visible(wl, show); if (show) { @@ -429,7 +482,16 @@ static void config_screen_network_change(void *arg, int value) struct config_screen *screen = arg; screen->net_conf_type = value; widgetset_unpost(screen->widgetset); - config_screen_layout_widgets(screen, value); + config_screen_layout_widgets(screen); + widgetset_post(screen->widgetset); +} + +static void config_screen_autoboot_change(void *arg, int value) +{ + struct config_screen *screen = arg; + screen->autoboot_type = value; + widgetset_unpost(screen->widgetset); + config_screen_layout_widgets(screen); widgetset_post(screen->widgetset); } @@ -483,6 +545,7 @@ static void config_screen_setup_widgets(struct config_screen *screen, char *str, *ip, *mask, *gw; enum net_conf_type type; unsigned int i; + bool found; build_assert(sizeof(screen->widgets) / sizeof(struct widget *) == N_FIELDS); @@ -491,17 +554,87 @@ static void config_screen_setup_widgets(struct config_screen *screen, ifcfg = first_active_interface(config); screen->widgets.autoboot_l = widget_new_label(set, 0, 0, "Autoboot:"); - screen->widgets.autoboot_f = widget_new_checkbox(set, 0, 0, - config->autoboot_enabled); + screen->widgets.autoboot_f = widget_new_select(set, 0, 0, 55); + + widget_select_on_change(screen->widgets.autoboot_f, + config_screen_autoboot_change, screen); + + screen->widgets.boot_device_f = widget_new_select(set, 0, 0, 55); + + widget_select_add_option(screen->widgets.autoboot_f, + AUTOBOOT_DISABLED, + "Don't autoboot", + screen->autoboot_type == + AUTOBOOT_DISABLED); + widget_select_add_option(screen->widgets.autoboot_f, + AUTOBOOT_ANY, + "Autoboot from any disk/network device", + screen->autoboot_type == + AUTOBOOT_ANY); + widget_select_add_option(screen->widgets.autoboot_f, + AUTOBOOT_ONE, + "Only autoboot from a specific " + "disk/network device", + screen->autoboot_type == + AUTOBOOT_ONE); + + found = false; + + for (i = 0; i < sysinfo->n_blockdevs; i++) { + struct blockdev_info *bd = sysinfo->blockdevs[i]; + bool selected; + char *label; + + selected = config->boot_device && + !strcmp(config->boot_device, bd->uuid); + if (selected) + found = true; + + label = talloc_asprintf(screen, "disk: %s [uuid: %s]", + bd->name, bd->uuid); + + widget_select_add_option(screen->widgets.boot_device_f, i, + label, selected); + } + + for (i = 0; i < sysinfo->n_interfaces; i++) { + struct interface_info *info = sysinfo->interfaces[i]; + char *label, mac[20]; + bool selected; + + mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac)); + selected = config->boot_device && + !strcmp(config->boot_device, mac); + if (selected) + found = true; + + label = talloc_asprintf(screen, "net: %s [mac: %s]", + info->name, mac); + + widget_select_add_option(screen->widgets.boot_device_f, + i + sysinfo->n_blockdevs, + label, selected); + } + + if (screen->autoboot_type == AUTOBOOT_ONE && !found) { + char *label; + + label = talloc_asprintf(screen, "Unknown UUID: %s", + config->boot_device); + + widget_select_add_option(screen->widgets.boot_device_f, -1, + label, true); + } str = talloc_asprintf(screen, "%d", config->autoboot_timeout_sec); screen->widgets.timeout_l = widget_new_label(set, 0, 0, "Timeout:"); screen->widgets.timeout_f = widget_new_textbox(set, 0, 0, 5, str); screen->widgets.timeout_help_l = widget_new_label(set, 0, 0, "seconds"); + widget_textbox_set_fixed_size(screen->widgets.timeout_f); widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999); - screen->widgets.network_l = widget_new_label(set, 0, 0, "Network"); + screen->widgets.network_l = widget_new_label(set, 0, 0, "Network:"); screen->widgets.network_f = widget_new_select(set, 0, 0, 50); widget_select_add_option(screen->widgets.network_f, @@ -557,10 +690,12 @@ static void config_screen_setup_widgets(struct config_screen *screen, screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, "IP/mask:"); screen->widgets.ip_addr_f = widget_new_textbox(set, 0, 0, 16, ip); screen->widgets.ip_mask_l = widget_new_label(set, 0, 0, "/"); - screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 4, mask); + screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 3, mask); screen->widgets.ip_addr_mask_help_l = widget_new_label(set, 0, 0, "(eg. 192.168.0.10 / 24)"); + 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); @@ -569,6 +704,7 @@ static void config_screen_setup_widgets(struct config_screen *screen, screen->widgets.gateway_help_l = 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); str = talloc_strdup(screen, ""); @@ -654,9 +790,14 @@ static void config_screen_draw(struct config_screen *screen, config_screen_setup_empty(screen); } else { screen->net_conf_type = find_net_conf_type(config); + if (!config->autoboot_enabled) + screen->autoboot_type = AUTOBOOT_DISABLED; + else + screen->autoboot_type = config->boot_device ? + AUTOBOOT_ONE : AUTOBOOT_ANY; config_screen_setup_widgets(screen, config, sysinfo); - config_screen_layout_widgets(screen, screen->net_conf_type); + config_screen_layout_widgets(screen); } if (repost)