]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-cui.c
ui/ncurses: Allow IPv6 addresses in address fields
[petitboot] / ui / ncurses / nc-cui.c
index 72a056d2c6f93707fd867170a9d21e723b772480..87d2503d94a4042c2b63f41f5ecc69d71619a245 100644 (file)
@@ -24,6 +24,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <locale.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/reboot.h>
@@ -58,12 +59,37 @@ static struct pmenu *plugin_menu_init(struct cui *cui);
 
 static void cui_cancel_autoboot_on_exit(struct cui *cui);
 
+static struct {
+       int key;
+       struct autoboot_option opt;
+} autoboot_override_keys[] = {
+       { KEY_F(10), {
+                       .boot_type = BOOT_DEVICE_TYPE,
+                       .type = DEVICE_TYPE_DISK,
+               },
+       },
+       { KEY_F(11), {
+                       .boot_type = BOOT_DEVICE_TYPE,
+                       .type = DEVICE_TYPE_USB,
+               },
+       },
+       { KEY_F(12), {
+                       .boot_type = BOOT_DEVICE_TYPE,
+                       .type = DEVICE_TYPE_NETWORK,
+               },
+       },
+};
+
 static bool lockdown_active(void)
 {
+#if defined(SIGNED_BOOT) && defined(HARD_LOCKDOWN)
+       return true;
+#else
        bool lockdown = false;
        if (access(LOCKDOWN_FILE, F_OK) != -1)
                lockdown = true;
        return lockdown;
+#endif
 }
 
 static void cui_start(void)
@@ -522,14 +548,50 @@ struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr)
        return old;
 }
 
+static bool set_temp_autoboot_opt(struct cui *cui, struct autoboot_option *opt)
+{
+       cui->autoboot_opt = opt;
+       if (cui->client)
+               discover_client_send_temp_autoboot(cui->client, opt);
+
+       return true;
+}
+
+static bool key_cancels_boot(int key)
+{
+       unsigned int i;
+
+       if (key == 0xc)
+               return false;
+
+       for (i = 0; i < ARRAY_SIZE(autoboot_override_keys); i++)
+               if (key == autoboot_override_keys[i].key)
+                       return false;
+
+       return true;
+}
+
 static bool process_global_keys(struct cui *cui, int key)
 {
+       unsigned int i;
+
        switch (key) {
        case 0xc:
                if (cui->current && cui->current->main_ncw)
                        wrefresh(curscr);
                return true;
        }
+
+       /* check for autoboot override keys */
+       for (i = 0; i < ARRAY_SIZE(autoboot_override_keys); i++) {
+               if (key != autoboot_override_keys[i].key)
+                       continue;
+
+               pb_log("Sending temporary autoboot override\n");
+               set_temp_autoboot_opt(cui, &autoboot_override_keys[i].opt);
+               return true;
+       }
+
        return false;
 }
 
@@ -577,7 +639,7 @@ static int cui_process_key(void *arg)
                        }
                }
 
-               if (!cui->has_input) {
+               if (!cui->has_input && key_cancels_boot(c)) {
                        cui->has_input = true;
                        if (cui->client) {
                                pb_log("UI input received (key = %d), aborting "
@@ -963,8 +1025,8 @@ fallback:
         * If this option was faked above move the context under
         * the item so it is cleaned up later in cui_plugins_remove().
         */
-       if (strncmp(cod->opt->id, "dummy", strlen("dummy") == 0 &&
-                               cod->dev->type == DEVICE_TYPE_UNKNOWN)) {
+       if (strcmp(cod->opt->id, "dummy") == 0 &&
+                       cod->dev->type == DEVICE_TYPE_UNKNOWN) {
                talloc_steal(item, cod->dev);
                talloc_steal(item, cod->opt);
        }
@@ -1242,6 +1304,14 @@ static struct pmenu *main_menu_init(struct cui *cui)
                return NULL;
        }
 
+       m->n_hot_keys = 1;
+       m->hot_keys = talloc_array(m, hot_key_fn, m->n_hot_keys);
+       if (!m->hot_keys) {
+               pb_log("%s: failed to allocate hot_keys\n", __func__);
+               talloc_free(m);
+               return NULL;
+       }
+       m->hot_keys[0] = pmenu_main_hot_keys;
        m->on_new = cui_item_new;
 
        m->scr.frame.ltitle = talloc_asprintf(m,
@@ -1325,9 +1395,8 @@ static struct pmenu *plugin_menu_init(struct cui *cui)
        int result;
 
        m = pmenu_init(cui, 2, cui_plugin_menu_exit);
-       m->on_new = cui_item_new;
        m->scr.frame.ltitle = talloc_asprintf(m, _("Petitboot Plugins"));
-       m->scr.frame.rtitle = talloc_asprintf(m, NULL);
+       m->scr.frame.rtitle = talloc_asprintf(m, "%s", "");
        m->scr.frame.help = talloc_strdup(m,
                _("Enter=install, e=details, x=exit, h=help"));
        m->scr.frame.status = talloc_asprintf(m,
@@ -1408,6 +1477,12 @@ static int cui_server_wait(void *arg)
                        pb_log("Aborting default boot on pb-discover connect\n");
                        discover_client_cancel_default(cui->client);
                }
+
+               if (cui->autoboot_opt) {
+                       pb_log("Sending autoboot override on pb-discover connect\n");
+                       discover_client_send_temp_autoboot(cui->client,
+                                       cui->autoboot_opt);
+               }
        }
 
        return 0;
@@ -1566,7 +1641,8 @@ static void cui_cancel_autoboot_on_exit(struct cui *cui)
 
 int cui_run(struct cui *cui)
 {
-       assert(main);
+       assert(cui);
+       assert(cui->main);
 
        cui->current = &cui->main->scr;
        cui->default_item = 0;