]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-config.c
ui/ncurses: Validate URL field
[petitboot] / ui / ncurses / nc-config.c
index 1bc77e8ec44750b6385388fa902e3a83b552c5a6..5c0f23bd88d284ff962ed70aa4571c19d01bb215 100644 (file)
@@ -33,7 +33,7 @@
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS       44
+#define N_FIELDS       48
 
 extern struct help_text config_help_text;
 
@@ -84,7 +84,7 @@ struct config_screen {
 
                struct nc_widget_label          *ipmi_type_l;
                struct nc_widget_label          *ipmi_clear_l;
-               struct nc_widget_checkbox       *ipmi_clear_cb;
+               struct nc_widget_button         *ipmi_clear_b;
 
                struct nc_widget_label          *network_l;
                struct nc_widget_select         *network_f;
@@ -106,6 +106,10 @@ struct config_screen {
                struct nc_widget_textbox        *dns_f;
                struct nc_widget_label          *dns_dhcp_help_l;
                struct nc_widget_label          *dns_help_l;
+               struct nc_widget_label          *http_proxy_l;
+               struct nc_widget_textbox        *http_proxy_f;
+               struct nc_widget_label          *https_proxy_l;
+               struct nc_widget_textbox        *https_proxy_f;
 
                struct nc_widget_label          *allow_write_l;
                struct nc_widget_select         *allow_write_f;
@@ -199,7 +203,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;
@@ -214,8 +218,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,
@@ -252,11 +256,6 @@ static int screen_process_form(struct config_screen *screen)
                        config->autoboot_timeout_sec = x;
        }
 
-       if (screen->ipmi_override)
-               if (widget_checkbox_get_value(screen->widgets.ipmi_clear_cb))
-                       config->ipmi_bootdev = IPMI_BOOTDEV_INVALID;
-
-
        net_conf_type = widget_select_get_value(screen->widgets.network_f);
 
        /* if we don't have any network interfaces, prevent per-interface
@@ -335,6 +334,13 @@ static int screen_process_form(struct config_screen *screen)
                }
        }
 
+       talloc_free(config->http_proxy);
+       talloc_free(config->https_proxy);
+       str = widget_textbox_get_value(screen->widgets.http_proxy_f);
+       config->http_proxy = talloc_strdup(config, str);
+       str = widget_textbox_get_value(screen->widgets.https_proxy_f);
+       config->https_proxy = talloc_strdup(config, str);
+
        allow_write = widget_select_get_value(screen->widgets.allow_write_f);
        if (allow_write != config->allow_writes)
                config->allow_writes = allow_write;
@@ -387,6 +393,26 @@ static void cancel_click(void *arg)
        screen->exit = true;
 }
 
+static void ipmi_clear_click(void *arg)
+{
+       struct config_screen *screen = arg;
+       struct config *config;
+       int rc;
+
+       config = config_copy(screen, screen->cui->config);
+       config->ipmi_bootdev = IPMI_BOOTDEV_INVALID;
+       config->safe_mode = false;
+
+       rc = cui_send_config(screen->cui, config);
+       talloc_free(config);
+
+       if (rc)
+               pb_log("cui_send_config failed!\n");
+       else
+               pb_debug("config sent!\n");
+       screen->exit = true;
+}
+
 static int layout_pair(struct config_screen *screen, int y,
                struct nc_widget_label *label,
                struct nc_widget *field)
@@ -486,7 +512,7 @@ static void config_screen_layout_widgets(struct config_screen *screen)
                y += 1;
 
                wl = widget_label_base(screen->widgets.ipmi_clear_l);
-               wf = widget_checkbox_base(screen->widgets.ipmi_clear_cb);
+               wf = widget_button_base(screen->widgets.ipmi_clear_b);
                widget_set_visible(wl, true);
                widget_set_visible(wf, true);
                widget_move(wl, y, screen->label_x);
@@ -585,6 +611,13 @@ static void config_screen_layout_widgets(struct config_screen *screen)
                y += 1;
        }
 
+       wf = widget_textbox_base(screen->widgets.http_proxy_f);
+       layout_pair(screen, y, screen->widgets.http_proxy_l, wf);
+       y++;
+       wf = widget_textbox_base(screen->widgets.https_proxy_f);
+       layout_pair(screen, y, screen->widgets.https_proxy_l, wf);
+       y++;
+
        y += 1;
 
        layout_pair(screen, y, screen->widgets.allow_write_l,
@@ -913,14 +946,16 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                label = talloc_asprintf(screen,
                                _("%s IPMI boot option: %s"),
                                config->ipmi_bootdev_persistent ?
-                               "Persistent" : "Temporary",
+                               _("Persistent") : _("Temporary"),
                                ipmi_bootdev_display_name(config->ipmi_bootdev));
                screen->widgets.ipmi_type_l = widget_new_label(set, 0, 0,
                                                        label);
                screen->widgets.ipmi_clear_l = widget_new_label(set, 0, 0,
                                                        _("Clear option:"));
-               screen->widgets.ipmi_clear_cb = widget_new_checkbox(set, 0, 0,
-                                                       false);
+               screen->widgets.ipmi_clear_b = widget_new_button(set, 0, 0,
+                               strncols(_("Clear IPMI override now")) + 10,
+                               _("Clear IPMI override now"),
+                               ipmi_clear_click, screen);
                screen->ipmi_override = true;
        }
 
@@ -1007,6 +1042,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
        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://)"));
 
@@ -1028,6 +1064,15 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0,
                        _("(if not provided by DHCP server)"));
 
+       screen->widgets.http_proxy_l = widget_new_label(set, 0, 0,
+                                       _("HTTP Proxy:"));
+       screen->widgets.http_proxy_f = widget_new_textbox(set, 0, 0, 32,
+                                               config->http_proxy);
+       screen->widgets.https_proxy_l = widget_new_label(set, 0, 0,
+                                       _("HTTPS Proxy:"));
+       screen->widgets.https_proxy_f = widget_new_textbox(set, 0, 0, 32,
+                                               config->https_proxy);
+
        if (config->safe_mode)
                screen->widgets.safe_mode = widget_new_label(set, 0, 0,
                         _("Selecting 'OK' will exit safe mode"));