summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-12-18 13:06:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-12-18 13:43:49 +0800
commitb49d86901dcdf0a6ddddba7c90d67b62c4acf2f8 (patch)
tree56b354ec05e1ed46d8f3a8b539f020fcec564a35 /ui
parent90cc2a11507462e9c40f2494165741561729bdfb (diff)
downloadtalos-petitboot-b49d86901dcdf0a6ddddba7c90d67b62c4acf2f8.tar.gz
talos-petitboot-b49d86901dcdf0a6ddddba7c90d67b62c4acf2f8.zip
ui/ncurses/nc-config: Add validation for network settings
Use the new widget validators, plus a bit of whole-form logic, to implement some basic validation on the config UI. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/ncurses/nc-config.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c
index 78e8e9e..6b29a66 100644
--- a/ui/ncurses/nc-config.c
+++ b/ui/ncurses/nc-config.c
@@ -202,15 +202,23 @@ static int screen_process_form(struct config_screen *screen)
}
if (net_conf_type == NET_CONF_TYPE_STATIC) {
+ char *ip, *mask, *gateway;
+
+ ip = widget_textbox_get_value(screen->widgets.ip_addr_f);
+ mask = widget_textbox_get_value(screen->widgets.ip_mask_f);
+ gateway = widget_textbox_get_value(screen->widgets.gateway_f);
+
+ if (!ip || !*ip || !mask || !*mask) {
+ screen->scr.frame.status =
+ "No IP / mask values are set";
+ nc_scr_frame_draw(&screen->scr);
+ return -1;
+ }
+
iface->method = CONFIG_METHOD_STATIC;
iface->static_config.address = talloc_asprintf(iface, "%s/%s",
- widget_textbox_get_value(
- screen->widgets.ip_addr_f),
- widget_textbox_get_value(
- screen->widgets.ip_mask_f));
- iface->static_config.gateway = talloc_strdup(iface,
- widget_textbox_get_value(
- screen->widgets.gateway_f));
+ ip, mask);
+ iface->static_config.gateway = talloc_strdup(iface, gateway);
}
str = widget_textbox_get_value(screen->widgets.dns_f);
@@ -250,8 +258,12 @@ static int screen_process_form(struct config_screen *screen)
static void ok_click(void *arg)
{
struct config_screen *screen = arg;
- screen_process_form(screen);
- screen->exit = true;
+ 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;
}
static void cancel_click(void *arg)
@@ -452,6 +464,8 @@ static void config_screen_setup_widgets(struct config_screen *screen,
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_validator_integer(screen->widgets.timeout_f, 0, 999);
+
screen->widgets.network_l = widget_new_label(set, 0, 0, "Network");
screen->widgets.network_f = widget_new_select(set, 0, 0, 50);
@@ -512,11 +526,16 @@ static void config_screen_setup_widgets(struct config_screen *screen,
screen->widgets.ip_addr_mask_help_l =
widget_new_label(set, 0, 0, "(eg. 192.168.0.10 / 24)");
+ widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f);
+ widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 31);
+
screen->widgets.gateway_l = widget_new_label(set, 0, 0, "Gateway:");
screen->widgets.gateway_f = widget_new_textbox(set, 0, 0, 16, gw);
screen->widgets.gateway_help_l =
widget_new_label(set, 0, 0, "(eg. 192.168.0.1)");
+ widget_textbox_set_validator_ipv4(screen->widgets.gateway_f);
+
str = talloc_strdup(screen, "");
for (i = 0; i < config->network.n_dns_servers; i++) {
str = talloc_asprintf_append(str, "%s%s",
@@ -529,6 +548,8 @@ 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);
+
screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0,
"(if not provided by DHCP server)");
OpenPOWER on IntegriCloud