]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-config.c
4685fa5d0db1988661503115163ddf30c9a7a552
[petitboot] / ui / ncurses / nc-config.c
1 /*
2  *  Copyright (C) 2013 IBM Corporation
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <pb-config/pb-config.h>
27 #include <talloc/talloc.h>
28 #include <types/types.h>
29 #include <log/log.h>
30 #include <i18n/i18n.h>
31
32 #include "ui/common/discover-client.h"
33 #include "nc-cui.h"
34 #include "nc-config.h"
35 #include "nc-widgets.h"
36
37 #define N_FIELDS        49
38
39 extern struct help_text config_help_text;
40
41 enum net_conf_type {
42         NET_CONF_TYPE_DHCP_ALL,
43         NET_CONF_TYPE_DHCP_ONE,
44         NET_CONF_TYPE_STATIC,
45 };
46
47 struct config_screen {
48         struct nc_scr           scr;
49         struct cui              *cui;
50         struct nc_widgetset     *widgetset;
51         WINDOW                  *pad;
52
53         bool                    exit;
54         bool                    show_help;
55         bool                    need_redraw;
56         bool                    need_update;
57
58         void                    (*on_exit)(struct cui *);
59
60         int                     scroll_y;
61
62         int                     label_x;
63         int                     field_x;
64         int                     network_config_y;
65
66         enum net_conf_type      net_conf_type;
67
68         bool                    autoboot_enabled;
69         bool                    ipmi_override;
70         bool                    net_override;
71
72         struct {
73                 struct nc_widget_label          *autoboot_l;
74                 struct nc_widget_select         *autoboot_f;
75                 struct nc_widget_label          *boot_order_l;
76                 struct nc_widget_subset         *boot_order_f;
77                 struct nc_widget_label          *boot_empty_l;
78                 struct nc_widget_button         *boot_add_b;
79                 struct nc_widget_button         *boot_none_b;
80                 struct nc_widget_button         *boot_any_b;
81                 struct nc_widget_textbox        *timeout_f;
82                 struct nc_widget_label          *timeout_l;
83                 struct nc_widget_label          *timeout_help_l;
84
85                 struct nc_widget_label          *ipmi_type_l;
86                 struct nc_widget_label          *ipmi_clear_l;
87                 struct nc_widget_button         *ipmi_clear_b;
88
89                 struct nc_widget_label          *network_l;
90                 struct nc_widget_select         *network_f;
91
92                 struct nc_widget_label          *iface_l;
93                 struct nc_widget_select         *iface_f;
94                 struct nc_widget_label          *ip_addr_l;
95                 struct nc_widget_textbox        *ip_addr_f;
96                 struct nc_widget_label          *ip_mask_l;
97                 struct nc_widget_textbox        *ip_mask_f;
98                 struct nc_widget_label          *ip_addr_mask_help_l;
99                 struct nc_widget_label          *gateway_l;
100                 struct nc_widget_textbox        *gateway_f;
101                 struct nc_widget_label          *gateway_help_l;
102                 struct nc_widget_label          *url_l;
103                 struct nc_widget_textbox        *url_f;
104                 struct nc_widget_label          *url_help_l;
105                 struct nc_widget_label          *dns_l;
106                 struct nc_widget_textbox        *dns_f;
107                 struct nc_widget_label          *dns_dhcp_help_l;
108                 struct nc_widget_label          *dns_help_l;
109                 struct nc_widget_label          *http_proxy_l;
110                 struct nc_widget_textbox        *http_proxy_f;
111                 struct nc_widget_label          *https_proxy_l;
112                 struct nc_widget_textbox        *https_proxy_f;
113
114                 struct nc_widget_label          *allow_write_l;
115                 struct nc_widget_select         *allow_write_f;
116                 struct nc_widget_label          *boot_console_l;
117                 struct nc_widget_select         *boot_console_f;
118                 struct nc_widget_label          *manual_console_l;
119                 struct nc_widget_label          *current_console_l;
120
121                 struct nc_widget_button         *update_password_l;
122
123                 struct nc_widget_label          *net_override_l;
124                 struct nc_widget_label          *safe_mode;
125                 struct nc_widget_button         *ok_b;
126                 struct nc_widget_button         *help_b;
127                 struct nc_widget_button         *cancel_b;
128         } widgets;
129 };
130
131 static struct config_screen *config_screen_from_scr(struct nc_scr *scr)
132 {
133         struct config_screen *config_screen;
134
135         assert(scr->sig == pb_config_screen_sig);
136         config_screen = (struct config_screen *)
137                 ((char *)scr - (size_t)&((struct config_screen *)0)->scr);
138         assert(config_screen->scr.sig == pb_config_screen_sig);
139         return config_screen;
140 }
141
142 static void pad_refresh(struct config_screen *screen)
143 {
144         int y, x, rows, cols;
145
146         getmaxyx(screen->scr.sub_ncw, rows, cols);
147         getbegyx(screen->scr.sub_ncw, y, x);
148
149         prefresh(screen->pad, screen->scroll_y, 0, y, x, rows, cols);
150 }
151
152 static void config_screen_process_key(struct nc_scr *scr, int key)
153 {
154         struct config_screen *screen = config_screen_from_scr(scr);
155         bool handled;
156
157         handled = widgetset_process_key(screen->widgetset, key);
158
159         if (!handled) {
160                 switch (key) {
161                 case 'x':
162                 case 27: /* esc */
163                         screen->exit = true;
164                         break;
165                 case 'h':
166                         screen->show_help = true;
167                         break;
168                 }
169         }
170
171         if (screen->exit) {
172                 screen->on_exit(screen->cui);
173
174         } else if (screen->show_help) {
175                 screen->show_help = false;
176                 screen->need_redraw = true;
177                 cui_show_help(screen->cui, _("System Configuration"),
178                                 &config_help_text);
179
180         } else if (handled && (screen->cui->current == scr)) {
181                 pad_refresh(screen);
182         }
183 }
184
185 static void config_screen_resize(struct nc_scr *scr)
186 {
187         struct config_screen *screen = config_screen_from_scr(scr);
188         (void)screen;
189 }
190
191 static int config_screen_unpost(struct nc_scr *scr)
192 {
193         struct config_screen *screen = config_screen_from_scr(scr);
194         widgetset_unpost(screen->widgetset);
195         return 0;
196 }
197
198 struct nc_scr *config_screen_scr(struct config_screen *screen)
199 {
200         return &screen->scr;
201 }
202
203 static int screen_process_form(struct config_screen *screen)
204 {
205         const struct system_info *sysinfo = screen->cui->sysinfo;
206         enum net_conf_type net_conf_type;
207         struct interface_config *iface;
208         bool allow_write;
209         char *str, *end;
210         struct config *config;
211         int i, n_boot_opts, rc;
212         unsigned int *order, idx;
213         char mac[20];
214
215         config = config_copy(screen, screen->cui->config);
216
217         talloc_free(config->autoboot_opts);
218         config->n_autoboot_opts = 0;
219
220         n_boot_opts = widget_subset_get_order(config, &order,
221                                               screen->widgets.boot_order_f);
222
223         config->autoboot_enabled = widget_select_get_value(
224                                                 screen->widgets.autoboot_f);
225
226         config->n_autoboot_opts = n_boot_opts;
227         config->autoboot_opts = talloc_array(config, struct autoboot_option,
228                                              n_boot_opts);
229
230         for (i = 0; i < n_boot_opts; i++) {
231                 if (order[i] < sysinfo->n_blockdevs) {
232                         /* disk uuid */
233                         config->autoboot_opts[i].boot_type = BOOT_DEVICE_UUID;
234                         config->autoboot_opts[i].uuid = talloc_strdup(config,
235                                                         sysinfo->blockdevs[order[i]]->uuid);
236                 } else if(order[i] < (sysinfo->n_blockdevs + sysinfo->n_interfaces)) {
237                         /* net uuid */
238                         order[i] -= sysinfo->n_blockdevs;
239                         config->autoboot_opts[i].boot_type = BOOT_DEVICE_UUID;
240                         mac_str(sysinfo->interfaces[order[i]]->hwaddr,
241                                 sysinfo->interfaces[order[i]]->hwaddr_size,
242                                 mac, sizeof(mac));
243                         config->autoboot_opts[i].uuid = talloc_strdup(config, mac);
244                 } else {
245                         /* device type */
246                         order[i] -= (sysinfo->n_blockdevs + sysinfo->n_interfaces);
247                         config->autoboot_opts[i].boot_type = BOOT_DEVICE_TYPE;
248                         config->autoboot_opts[i].type = order[i];
249                 }
250         }
251
252         str = widget_textbox_get_value(screen->widgets.timeout_f);
253         if (str) {
254                 unsigned long x;
255                 errno = 0;
256                 x = strtoul(str, &end, 10);
257                 if (!errno && end != str)
258                         config->autoboot_timeout_sec = x;
259         }
260
261         net_conf_type = widget_select_get_value(screen->widgets.network_f);
262
263         /* if we don't have any network interfaces, prevent per-interface
264          * configuration */
265         if (sysinfo->n_interfaces == 0)
266                 net_conf_type = NET_CONF_TYPE_DHCP_ALL;
267
268         if (net_conf_type == NET_CONF_TYPE_DHCP_ALL) {
269                 config->network.n_interfaces = 0;
270
271         } else {
272                 iface = talloc_zero(config, struct interface_config);
273                 config->network.n_interfaces = 1;
274                 config->network.interfaces = talloc_array(config,
275                                 struct interface_config *, 1);
276                 config->network.interfaces[0] = iface;
277
278                 /* copy hwaddr (from the sysinfo interface data) to
279                  * the configuration */
280                 idx = widget_select_get_value(screen->widgets.iface_f);
281                 memcpy(iface->hwaddr, sysinfo->interfaces[idx]->hwaddr,
282                                 sizeof(iface->hwaddr));
283         }
284
285         if (net_conf_type == NET_CONF_TYPE_DHCP_ONE) {
286                 iface->method = CONFIG_METHOD_DHCP;
287         }
288
289         if (net_conf_type == NET_CONF_TYPE_STATIC) {
290                 char *ip, *mask, *gateway, *url;
291
292                 ip = widget_textbox_get_value(screen->widgets.ip_addr_f);
293                 mask = widget_textbox_get_value(screen->widgets.ip_mask_f);
294                 gateway = widget_textbox_get_value(screen->widgets.gateway_f);
295                 url = widget_textbox_get_value(screen->widgets.url_f);
296
297                 if (!ip || !*ip || !mask || !*mask) {
298                         screen->scr.frame.status =
299                                 _("No IP / mask values are set");
300                         nc_scr_frame_draw(&screen->scr);
301                         talloc_free(config);
302                         return -1;
303                 }
304
305                 iface->method = CONFIG_METHOD_STATIC;
306                 iface->static_config.address = talloc_asprintf(iface, "%s/%s",
307                                 ip, mask);
308                 iface->static_config.gateway = talloc_strdup(iface, gateway);
309                 iface->static_config.url = talloc_strdup(iface, url);
310         }
311
312         str = widget_textbox_get_value(screen->widgets.dns_f);
313         talloc_free(config->network.dns_servers);
314         config->network.dns_servers = NULL;
315         config->network.n_dns_servers = 0;
316
317         if (str && strlen(str)) {
318                 char *dns, *tmp;
319                 int i;
320
321                 for (;;) {
322                         dns = strtok_r(str, " \t", &tmp);
323
324                         if (!dns)
325                                 break;
326
327                         i = config->network.n_dns_servers++;
328                         config->network.dns_servers = talloc_realloc(config,
329                                         config->network.dns_servers,
330                                         const char *,
331                                         config->network.n_dns_servers);
332                         config->network.dns_servers[i] =
333                                 talloc_strdup(config, dns);
334
335                         str = NULL;
336                 }
337         }
338
339         talloc_free(config->http_proxy);
340         talloc_free(config->https_proxy);
341         str = widget_textbox_get_value(screen->widgets.http_proxy_f);
342         config->http_proxy = talloc_strdup(config, str);
343         str = widget_textbox_get_value(screen->widgets.https_proxy_f);
344         config->https_proxy = talloc_strdup(config, str);
345
346         allow_write = widget_select_get_value(screen->widgets.allow_write_f);
347         if (allow_write != config->allow_writes)
348                 config->allow_writes = allow_write;
349
350         if (config->n_consoles && !config->manual_console) {
351                 idx = widget_select_get_value(screen->widgets.boot_console_f);
352                 if (!config->boot_console) {
353                         config->boot_console = talloc_strdup(config,
354                                                         config->consoles[idx]);
355                 } else if (strncmp(config->boot_console, config->consoles[idx],
356                                 strlen(config->boot_console)) != 0) {
357                         talloc_free(config->boot_console);
358                         config->boot_console = talloc_strdup(config,
359                                                         config->consoles[idx]);
360                 }
361         }
362
363         config->safe_mode = false;
364         rc = cui_send_config(screen->cui, config);
365         talloc_free(config);
366
367         if (rc)
368                 pb_log("cui_send_config failed!\n");
369         else
370                 pb_debug("config sent!\n");
371
372         return 0;
373 }
374
375 static void config_screen_config_cb(struct nc_scr *scr)
376 {
377         struct config_screen *screen = config_screen_from_scr(scr);
378
379         if (!screen_process_form(screen))
380                 screen->exit = true;
381 }
382
383 #ifdef CRYPT_SUPPORT
384 static void password_click(void *arg)
385 {
386         struct config_screen *screen = arg;
387
388         screen->need_update = true;
389         cui_show_auth(screen->cui, screen->scr.main_ncw, true, NULL);
390 }
391 #endif
392
393 static void ok_click(void *arg)
394 {
395         struct config_screen *screen = arg;
396
397         if (discover_client_authenticated(screen->cui->client)) {
398                 if (screen_process_form(screen))
399                         /* errors are written to the status line, so we'll need
400                          * to refresh */
401                         wrefresh(screen->scr.main_ncw);
402                 else
403                         screen->exit = true;
404         } else {
405                 cui_show_auth(screen->cui, screen->scr.main_ncw, false,
406                                 config_screen_config_cb);
407         }
408 }
409
410 static void help_click(void *arg)
411 {
412         struct config_screen *screen = arg;
413         screen->show_help = true;
414 }
415
416 static void cancel_click(void *arg)
417 {
418         struct config_screen *screen = arg;
419         screen->exit = true;
420 }
421
422 static void ipmi_clear_click(void *arg)
423 {
424         struct config_screen *screen = arg;
425         struct config *config;
426         int rc;
427
428         config = config_copy(screen, screen->cui->config);
429         config->ipmi_bootdev = IPMI_BOOTDEV_INVALID;
430         config->safe_mode = false;
431
432         rc = cui_send_config(screen->cui, config);
433         talloc_free(config);
434
435         if (rc)
436                 pb_log("cui_send_config failed!\n");
437         else
438                 pb_debug("config sent!\n");
439         screen->exit = true;
440 }
441
442 static int layout_pair(struct config_screen *screen, int y,
443                 struct nc_widget_label *label,
444                 struct nc_widget *field)
445 {
446         struct nc_widget *label_w = widget_label_base(label);
447         widget_move(label_w, y, screen->label_x);
448         widget_move(field, y, screen->field_x);
449         return max(widget_height(label_w), widget_height(field));
450 }
451
452 static void config_screen_layout_widgets(struct config_screen *screen)
453 {
454         struct nc_widget *wl, *wf, *wh;
455         int y, x, help_x;
456         bool show;
457
458         y = 1;
459         /* currently, the longest label we have is the DNS-servers
460          * widget, so layout our screen based on that */
461         help_x = screen->field_x + 2 +
462                 widget_width(widget_textbox_base(screen->widgets.dns_f));
463
464         wl = widget_label_base(screen->widgets.autoboot_l);
465         widget_set_visible(wl, true);
466         widget_move(wl, y, screen->label_x);
467
468         wf = widget_select_base(screen->widgets.autoboot_f);
469         widget_set_visible(wf, true);
470         widget_move(wf, y, screen->field_x);
471         y += widget_height(wf);
472
473         show = screen->autoboot_enabled;
474
475         if (show)
476                 y += 1;
477
478         wl = widget_label_base(screen->widgets.boot_order_l);
479         widget_set_visible(wl, show);
480         widget_move(wl, y, screen->label_x);
481
482         wf = widget_subset_base(screen->widgets.boot_order_f);
483         widget_move(wf, y, screen->field_x);
484         wl = widget_label_base(screen->widgets.boot_empty_l);
485         widget_move(wl, y, screen->field_x);
486
487         if (widget_subset_height(screen->widgets.boot_order_f)) {
488                 widget_set_visible(wl, false);
489                 widget_set_visible(wf, show);
490                 y += show ? widget_height(wf) : 0;
491         } else {
492                 widget_set_visible(wl, show);
493                 widget_set_visible(wf, false);
494                 y += show ? 1 : 0;
495         }
496
497         if (show) {
498                 y += 1;
499                 widget_move(widget_button_base(screen->widgets.boot_add_b),
500                                 y++, screen->field_x);
501                 widget_move(widget_button_base(screen->widgets.boot_any_b),
502                                 y++, screen->field_x);
503                 widget_move(widget_button_base(screen->widgets.boot_none_b),
504                                 y, screen->field_x);
505         }
506
507         wf = widget_button_base(screen->widgets.boot_add_b);
508         if (widget_subset_n_inactive(screen->widgets.boot_order_f) && show)
509                 widget_set_visible(wf, true);
510         else
511                 widget_set_visible(wf, false);
512
513         if (show)
514                 y += 2;
515
516         widget_set_visible(widget_button_base(screen->widgets.boot_any_b), show);
517         widget_set_visible(widget_button_base(screen->widgets.boot_none_b), show);
518
519         wf = widget_textbox_base(screen->widgets.timeout_f);
520         wl = widget_label_base(screen->widgets.timeout_l);
521         wh = widget_label_base(screen->widgets.timeout_help_l);
522         widget_set_visible(wl, screen->autoboot_enabled);
523         widget_set_visible(wf, screen->autoboot_enabled);
524         widget_set_visible(wh, screen->autoboot_enabled);
525         if (screen->autoboot_enabled) {
526                 widget_set_visible(wh, screen->autoboot_enabled);
527                 widget_move(wl, y, screen->label_x);
528                 widget_move(wf, y, screen->field_x);
529                 widget_move(wh, y, screen->field_x + widget_width(wf) + 1);
530                 y += 2;
531         } else
532                 y += 1;
533
534         if (screen->ipmi_override) {
535                 wl = widget_label_base(screen->widgets.ipmi_type_l);
536                 widget_set_visible(wl, true);
537                 widget_move(wl, y, screen->label_x);
538                 y += 1;
539
540                 wl = widget_label_base(screen->widgets.ipmi_clear_l);
541                 wf = widget_button_base(screen->widgets.ipmi_clear_b);
542                 widget_set_visible(wl, true);
543                 widget_set_visible(wf, true);
544                 widget_move(wl, y, screen->label_x);
545                 widget_move(wf, y, screen->field_x);
546                 y += 1;
547         }
548
549         y += 1;
550
551         y += layout_pair(screen, y, screen->widgets.network_l,
552                         widget_select_base(screen->widgets.network_f));
553
554         y += 1;
555
556         /* conditionally show iface select */
557         wl = widget_label_base(screen->widgets.iface_l);
558         wf = widget_select_base(screen->widgets.iface_f);
559
560         show = screen->net_conf_type == NET_CONF_TYPE_DHCP_ONE ||
561                 screen->net_conf_type == NET_CONF_TYPE_STATIC;
562
563         widget_set_visible(wl, show);
564         widget_set_visible(wf, show);
565
566         if (show)
567                 y += layout_pair(screen, y, screen->widgets.iface_l, wf) + 1;
568
569         /* conditionally show static IP params */
570         show = screen->net_conf_type == NET_CONF_TYPE_STATIC;
571
572         wl = widget_label_base(screen->widgets.ip_addr_l);
573         wf = widget_textbox_base(screen->widgets.ip_addr_f);
574         widget_set_visible(wl, show);
575         widget_set_visible(wf, show);
576         x = screen->field_x + widget_width(wf) + 1;
577
578         if (show)
579                 layout_pair(screen, y, screen->widgets.ip_addr_l, wf);
580
581         wl = widget_label_base(screen->widgets.ip_mask_l);
582         wf = widget_textbox_base(screen->widgets.ip_mask_f);
583         widget_set_visible(wl, show);
584         widget_set_visible(wf, show);
585
586         if (show) {
587                 widget_move(wl, y, x);
588                 widget_move(wf, y, x + 2);
589         }
590
591         /* help for IP/mask */
592         wh = widget_label_base(screen->widgets.ip_addr_mask_help_l);
593         widget_set_visible(wh, show);
594         if (show) {
595                 widget_move(wh, y, help_x);
596                 y++;
597         }
598
599         wl = widget_label_base(screen->widgets.gateway_l);
600         wf = widget_textbox_base(screen->widgets.gateway_f);
601         wh = widget_label_base(screen->widgets.gateway_help_l);
602         widget_set_visible(wl, show);
603         widget_set_visible(wf, show);
604         widget_set_visible(wh, show);
605
606         if (show) {
607                 layout_pair(screen, y, screen->widgets.gateway_l, wf);
608                 widget_move(wh, y, help_x);
609                 y++;
610         }
611
612         wl = widget_label_base(screen->widgets.url_l);
613         wf = widget_textbox_base(screen->widgets.url_f);
614         wh = widget_label_base(screen->widgets.url_help_l);
615         widget_set_visible(wl, show);
616         widget_set_visible(wf, show);
617         widget_set_visible(wh, show);
618
619         if (show) {
620                 layout_pair(screen, y, screen->widgets.url_l, wf);
621                 widget_move(wh, y, help_x);
622                 y++;
623         }
624
625         wh = widget_label_base(screen->widgets.dns_help_l);
626         layout_pair(screen, y, screen->widgets.dns_l,
627                         widget_textbox_base(screen->widgets.dns_f));
628         widget_move(wh, y, help_x);
629         y++;
630
631         /* we show the DNS/DHCP help if we're configuring DHCP */
632         show = screen->net_conf_type != NET_CONF_TYPE_STATIC;
633         wl = widget_label_base(screen->widgets.dns_dhcp_help_l);
634         widget_set_visible(wl, show);
635         if (show) {
636                 widget_move(wl, y, screen->field_x);
637                 y += 1;
638         }
639
640         wf = widget_textbox_base(screen->widgets.http_proxy_f);
641         layout_pair(screen, y, screen->widgets.http_proxy_l, wf);
642         y++;
643         wf = widget_textbox_base(screen->widgets.https_proxy_f);
644         layout_pair(screen, y, screen->widgets.https_proxy_l, wf);
645         y++;
646
647         y += 1;
648
649         layout_pair(screen, y, screen->widgets.allow_write_l,
650                     widget_select_base(screen->widgets.allow_write_f));
651         y += widget_height(widget_select_base(screen->widgets.allow_write_f));
652
653         y += 1;
654
655         if (screen->widgets.manual_console_l) {
656                 layout_pair(screen, y++, screen->widgets.boot_console_l,
657                         widget_label_base(screen->widgets.manual_console_l));
658                 widget_move(widget_label_base(screen->widgets.current_console_l),
659                         y, screen->field_x);
660                 widget_set_visible(widget_select_base(
661                         screen->widgets.boot_console_f), false);
662                 y += 2;
663         } else if (widget_height(widget_select_base(screen->widgets.boot_console_f))) {
664                 layout_pair(screen, y, screen->widgets.boot_console_l,
665                             widget_select_base(screen->widgets.boot_console_f));
666                 y += widget_height(widget_select_base(screen->widgets.boot_console_f));
667                 widget_move(widget_label_base(screen->widgets.current_console_l),
668                         y, screen->field_x);
669                 y += 2;
670         } else {
671                 widget_set_visible(widget_label_base(
672                                         screen->widgets.boot_console_l), false);
673                 widget_set_visible(widget_select_base(
674                                         screen->widgets.boot_console_f), false);
675                 widget_set_visible(widget_label_base(
676                                         screen->widgets.current_console_l), false);
677         }
678
679 #ifdef CRYPT_SUPPORT
680         widget_move(widget_button_base(screen->widgets.update_password_l),
681                         y, screen->field_x);
682         y += 2;
683 #endif
684
685         if (screen->net_override) {
686                 widget_move(widget_label_base(screen->widgets.net_override_l),
687                                 y, screen->label_x);
688                 widget_set_visible(widget_label_base(screen->widgets.net_override_l),
689                                         true);
690                 y += 1;
691         }
692
693         if (screen->cui->config->safe_mode) {
694                 widget_move(widget_label_base(screen->widgets.safe_mode),
695                         y, screen->label_x);
696                 widget_set_visible(widget_label_base(screen->widgets.safe_mode),
697                                         true);
698                 y += 1;
699         }
700
701         widget_move(widget_button_base(screen->widgets.ok_b),
702                         y, screen->field_x);
703         widget_move(widget_button_base(screen->widgets.help_b),
704                         y, screen->field_x + 14);
705         widget_move(widget_button_base(screen->widgets.cancel_b),
706                         y, screen->field_x + 28);
707 }
708
709 static void config_screen_network_change(void *arg, int value)
710 {
711         struct config_screen *screen = arg;
712         screen->net_conf_type = value;
713         widgetset_unpost(screen->widgetset);
714         config_screen_layout_widgets(screen);
715         widgetset_post(screen->widgetset);
716 }
717
718 static void config_screen_boot_order_change(void *arg, int value)
719 {
720         (void)value;
721         struct config_screen *screen = arg;
722         widgetset_unpost(screen->widgetset);
723         config_screen_layout_widgets(screen);
724         widgetset_post(screen->widgetset);
725 }
726
727 static void config_screen_autoboot_change(void *arg, int value)
728 {
729         struct config_screen *screen = arg;
730         screen->autoboot_enabled = !!value;
731         widgetset_unpost(screen->widgetset);
732         config_screen_layout_widgets(screen);
733         widgetset_post(screen->widgetset);
734 }
735
736 static void config_screen_add_device(void *arg)
737 {
738         struct config_screen *screen = arg;
739
740         cui_show_subset(screen->cui, _("Select a boot device to add"),
741                         screen->widgets.boot_order_f);
742 }
743
744 static void config_screen_autoboot_none(void *arg)
745 {
746         struct config_screen *screen = arg;
747         struct nc_widget_subset *subset = screen->widgets.boot_order_f;
748
749         widget_subset_clear_active(subset);
750
751         widgetset_unpost(screen->widgetset);
752         config_screen_layout_widgets(screen);
753         widgetset_post(screen->widgetset);
754 }
755
756 static void config_screen_autoboot_any(void *arg)
757 {
758         struct config_screen *screen = arg;
759         const struct system_info *sysinfo = screen->cui->sysinfo;
760         struct nc_widget_subset *subset = screen->widgets.boot_order_f;
761         int idx;
762
763         widget_subset_clear_active(subset);
764
765         idx = sysinfo->n_blockdevs + sysinfo->n_interfaces + DEVICE_TYPE_ANY;
766
767         widget_subset_make_active(screen->widgets.boot_order_f, idx);
768
769         screen->autoboot_enabled = true;
770
771         widgetset_unpost(screen->widgetset);
772         config_screen_layout_widgets(screen);
773         widgetset_post(screen->widgetset);
774 }
775
776 static void config_screen_update_subset(void *arg,
777                         struct nc_widget_subset *subset, int idx)
778 {
779         struct config_screen *screen = arg;
780
781         if (idx >= 0)
782                 widget_subset_make_active(subset, idx);
783         if (!screen->autoboot_enabled)
784                 screen->autoboot_enabled = true;
785         config_screen_layout_widgets(screen);
786 }
787
788 static struct interface_config *first_active_interface(
789                 const struct config *config)
790 {
791         unsigned int i;
792
793         for (i = 0; i < config->network.n_interfaces; i++) {
794                 if (config->network.interfaces[i]->ignore)
795                         continue;
796                 return config->network.interfaces[i];
797         }
798         return NULL;
799 }
800
801 static enum net_conf_type find_net_conf_type(const struct config *config)
802 {
803         struct interface_config *ifcfg;
804
805         ifcfg = first_active_interface(config);
806
807         if (!ifcfg)
808                 return NET_CONF_TYPE_DHCP_ALL;
809
810         else if (ifcfg->method == CONFIG_METHOD_DHCP)
811                 return NET_CONF_TYPE_DHCP_ONE;
812
813         else if (ifcfg->method == CONFIG_METHOD_STATIC)
814                 return NET_CONF_TYPE_STATIC;
815
816         assert(0);
817         return NET_CONF_TYPE_DHCP_ALL;
818 }
819
820 static void config_screen_setup_empty(struct config_screen *screen)
821 {
822         widget_new_label(screen->widgetset, 2, screen->field_x,
823                         _("Waiting for configuration data..."));
824         screen->widgets.cancel_b = widget_new_button(screen->widgetset,
825                         4, screen->field_x, 9, _("Cancel"),
826                         cancel_click, screen);
827 }
828
829 static int find_autoboot_idx(const struct system_info *sysinfo,
830                 struct autoboot_option *opt)
831 {
832         unsigned int i;
833
834         if (opt->boot_type == BOOT_DEVICE_TYPE)
835                 return sysinfo->n_blockdevs + sysinfo->n_interfaces + opt->type;
836
837         for (i = 0; i < sysinfo->n_blockdevs; i++) {
838                 if (!strcmp(sysinfo->blockdevs[i]->uuid, opt->uuid))
839                         return i;
840         }
841
842         for (i = 0; i < sysinfo->n_interfaces; i++) {
843                 struct interface_info *info = sysinfo->interfaces[i];
844                 char mac[20];
845
846                 mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
847
848                 if (!strcmp(mac, opt->uuid))
849                         return sysinfo->n_blockdevs + i;
850         }
851
852         return -1;
853 }
854
855 static void config_screen_setup_widgets(struct config_screen *screen,
856                 const struct config *config,
857                 const struct system_info *sysinfo)
858 {
859         struct nc_widgetset *set = screen->widgetset;
860         struct interface_config *ifcfg;
861         char *str, *ip, *mask, *gw, *url, *tty, *label;
862         enum net_conf_type type;
863         unsigned int i;
864         int add_len, clear_len, any_len, min_len = 20;
865         bool found;
866
867         build_assert(sizeof(screen->widgets) / sizeof(struct widget *)
868                         == N_FIELDS);
869
870         type = screen->net_conf_type;
871         ifcfg = first_active_interface(config);
872
873         screen->autoboot_enabled = config->autoboot_enabled;
874
875         screen->widgets.autoboot_l = widget_new_label(set, 0, 0,
876                                         _("Autoboot:"));
877         screen->widgets.autoboot_f = widget_new_select(set, 0, 0,
878                                         COLS - screen->field_x - 1);
879
880         widget_select_add_option(screen->widgets.autoboot_f, 0, _("Disabled"),
881                                  !screen->autoboot_enabled);
882         widget_select_add_option(screen->widgets.autoboot_f, 1, _("Enabled"),
883                                  screen->autoboot_enabled);
884
885         widget_select_on_change(screen->widgets.autoboot_f,
886                         config_screen_autoboot_change, screen);
887
888         add_len = max(min_len, strncols(_("Add Device")));
889         clear_len = max(min_len, strncols(_("Clear")));
890         any_len = max(min_len, strncols(_("Clear & Boot Any")));
891
892         screen->widgets.boot_add_b = widget_new_button(set, 0, 0, add_len,
893                                         _("Add Device"),
894                                         config_screen_add_device, screen);
895
896         screen->widgets.boot_none_b = widget_new_button(set, 0, 0, clear_len,
897                                         _("Clear"),
898                                         config_screen_autoboot_none, screen);
899
900         screen->widgets.boot_any_b = widget_new_button(set, 0, 0, any_len,
901                                         _("Clear & Boot Any"),
902                                         config_screen_autoboot_any, screen);
903
904         screen->widgets.boot_order_l = widget_new_label(set, 0, 0,
905                                         _("Boot Order:"));
906         screen->widgets.boot_order_f = widget_new_subset(set, 0, 0,
907                                         COLS - screen->field_x,
908                                         config_screen_update_subset);
909         screen->widgets.boot_empty_l = widget_new_label(set, 0, 0,
910                                         _("(None)"));
911
912         widget_subset_on_change(screen->widgets.boot_order_f,
913                         config_screen_boot_order_change, screen);
914
915         for (i = 0; i < sysinfo->n_blockdevs; i++) {
916                 struct blockdev_info *bd = sysinfo->blockdevs[i];
917
918                 label = talloc_asprintf(screen, _("disk: %s [uuid: %s]"),
919                                 bd->name, bd->uuid);
920
921                 widget_subset_add_option(screen->widgets.boot_order_f, label);
922         }
923
924         for (i = 0; i < sysinfo->n_interfaces; i++) {
925                 struct interface_info *info = sysinfo->interfaces[i];
926                 char mac[20];
927
928                 mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
929
930                 label = talloc_asprintf(screen, _("net:  %s [mac: %s]"),
931                                 info->name, mac);
932
933                 widget_subset_add_option(screen->widgets.boot_order_f, label);
934         }
935
936         for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_UNKNOWN; i++) {
937
938                 if (i == DEVICE_TYPE_ANY)
939                         label = talloc_asprintf(screen, _("Any Device"));
940                 else
941                         label = talloc_asprintf(screen, _("Any %s device"),
942                                                 device_type_display_name(i));
943
944                 widget_subset_add_option(screen->widgets.boot_order_f, label);
945         }
946
947         for (i = 0; i < config->n_autoboot_opts; i++) {
948                 struct autoboot_option *opt = &config->autoboot_opts[i];
949                 int idx;
950
951                 idx = find_autoboot_idx(sysinfo, opt);
952
953                 if (idx >= 0) {
954                         widget_subset_make_active(screen->widgets.boot_order_f,
955                                                   idx);
956                 } else {
957                         if (opt->boot_type == BOOT_DEVICE_TYPE)
958                                 pb_log("%s: Unknown autoboot option: %d\n",
959                                        __func__, opt->type);
960                         else
961                                 pb_log("%s: Unknown autoboot UUID: %s\n",
962                                        __func__, opt->uuid);
963                 }
964         }
965
966
967         str = talloc_asprintf(screen, "%d", config->autoboot_timeout_sec);
968         screen->widgets.timeout_l = widget_new_label(set, 0, 0, _("Timeout:"));
969         screen->widgets.timeout_f = widget_new_textbox(set, 0, 0, 5, str);
970         screen->widgets.timeout_help_l = widget_new_label(set, 0, 0,
971                                         _("seconds"));
972
973         widget_textbox_set_fixed_size(screen->widgets.timeout_f);
974         widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999);
975
976         if (config->ipmi_bootdev) {
977                 label = talloc_asprintf(screen,
978                                 _("%s IPMI boot option: %s"),
979                                 config->ipmi_bootdev_persistent ?
980                                 _("Persistent") : _("Temporary"),
981                                 ipmi_bootdev_display_name(config->ipmi_bootdev));
982                 screen->widgets.ipmi_type_l = widget_new_label(set, 0, 0,
983                                                         label);
984                 screen->widgets.ipmi_clear_l = widget_new_label(set, 0, 0,
985                                                         _("Clear option:"));
986                 screen->widgets.ipmi_clear_b = widget_new_button(set, 0, 0,
987                                 strncols(_("Clear IPMI override now")) + 10,
988                                 _("Clear IPMI override now"),
989                                 ipmi_clear_click, screen);
990                 screen->ipmi_override = true;
991         }
992
993         screen->widgets.network_l = widget_new_label(set, 0, 0, _("Network:"));
994         screen->widgets.network_f = widget_new_select(set, 0, 0,
995                                                 COLS - screen->field_x - 1);
996
997         widget_select_add_option(screen->widgets.network_f,
998                                         NET_CONF_TYPE_DHCP_ALL,
999                                         _("DHCP on all active interfaces"),
1000                                         type == NET_CONF_TYPE_DHCP_ALL);
1001         widget_select_add_option(screen->widgets.network_f,
1002                                         NET_CONF_TYPE_DHCP_ONE,
1003                                         _("DHCP on a specific interface"),
1004                                         type == NET_CONF_TYPE_DHCP_ONE);
1005         widget_select_add_option(screen->widgets.network_f,
1006                                         NET_CONF_TYPE_STATIC,
1007                                         _("Static IP configuration"),
1008                                         type == NET_CONF_TYPE_STATIC);
1009
1010         widget_select_on_change(screen->widgets.network_f,
1011                         config_screen_network_change, screen);
1012
1013         screen->widgets.iface_l = widget_new_label(set, 0, 0, _("Device:"));
1014         screen->widgets.iface_f = widget_new_select(set, 0, 0, 50);
1015
1016         for (i = 0; i < sysinfo->n_interfaces; i++) {
1017                 struct interface_info *info = sysinfo->interfaces[i];
1018                 char str[50], mac[20];
1019                 bool is_default;
1020
1021                 is_default = ifcfg && !memcmp(ifcfg->hwaddr, info->hwaddr,
1022                                         sizeof(ifcfg->hwaddr));
1023
1024                 mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
1025                 snprintf(str, sizeof(str), "%s [%s, %s]", info->name, mac,
1026                                 info->link ? _("link up") : _("link down"));
1027
1028                 widget_select_add_option(screen->widgets.iface_f,
1029                                                 i, str, is_default);
1030         }
1031
1032         url = gw = ip = mask = NULL;
1033         if (ifcfg && ifcfg->method == CONFIG_METHOD_STATIC) {
1034                 char *sep;
1035
1036                 str = talloc_strdup(screen, ifcfg->static_config.address);
1037                 sep = strchr(str, '/');
1038                 ip = str;
1039
1040                 if (sep) {
1041                         *sep = '\0';
1042                         mask = sep + 1;
1043                 }
1044                 gw = ifcfg->static_config.gateway;
1045                 url = ifcfg->static_config.url;
1046         }
1047
1048         screen->net_override = ifcfg && ifcfg->override;
1049         if (screen->net_override) {
1050                 screen->widgets.net_override_l = widget_new_label(set, 0, 0,
1051                         _("Network Override Active! 'OK' will overwrite interface config"));
1052         }
1053
1054         screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, _("IP/mask:"));
1055         screen->widgets.ip_addr_f = widget_new_textbox(set, 0, 0, 16, ip);
1056         screen->widgets.ip_mask_l = widget_new_label(set, 0, 0, "/");
1057         screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 3, mask);
1058         screen->widgets.ip_addr_mask_help_l =
1059                 widget_new_label(set, 0, 0, _("(eg. 192.168.0.10 / 24)"));
1060
1061         widget_textbox_set_fixed_size(screen->widgets.ip_addr_f);
1062         widget_textbox_set_fixed_size(screen->widgets.ip_mask_f);
1063         widget_textbox_set_validator_ip(screen->widgets.ip_addr_f);
1064         widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 127);
1065
1066         screen->widgets.gateway_l = widget_new_label(set, 0, 0, _("Gateway:"));
1067         screen->widgets.gateway_f = widget_new_textbox(set, 0, 0, 16, gw);
1068         screen->widgets.gateway_help_l =
1069                 widget_new_label(set, 0, 0, _("(eg. 192.168.0.1)"));
1070
1071         widget_textbox_set_fixed_size(screen->widgets.gateway_f);
1072         widget_textbox_set_validator_ip(screen->widgets.gateway_f);
1073
1074         screen->widgets.url_l = widget_new_label(set, 0, 0, _("URL:"));
1075         screen->widgets.url_f = widget_new_textbox(set, 0, 0, 32, url);
1076         widget_textbox_set_validator_url(screen->widgets.url_f);
1077         screen->widgets.url_help_l =
1078                 widget_new_label(set, 0, 0, _("(eg. tftp://)"));
1079
1080         str = talloc_strdup(screen, "");
1081         for (i = 0; i < config->network.n_dns_servers; i++) {
1082                 str = talloc_asprintf_append(str, "%s%s",
1083                                 (i == 0) ? "" : " ",
1084                                 config->network.dns_servers[i]);
1085         }
1086
1087         screen->widgets.dns_l = widget_new_label(set, 0, 0,
1088                                         _("DNS Server(s):"));
1089         screen->widgets.dns_f = widget_new_textbox(set, 0, 0, 32, str);
1090         screen->widgets.dns_help_l =
1091                 widget_new_label(set, 0, 0, _("(eg. 192.168.0.2)"));
1092
1093         widget_textbox_set_validator_ip_multi(screen->widgets.dns_f);
1094
1095         screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0,
1096                         _("(if not provided by DHCP server)"));
1097
1098         screen->widgets.http_proxy_l = widget_new_label(set, 0, 0,
1099                                         _("HTTP Proxy:"));
1100         screen->widgets.http_proxy_f = widget_new_textbox(set, 0, 0, 32,
1101                                                 config->http_proxy);
1102         screen->widgets.https_proxy_l = widget_new_label(set, 0, 0,
1103                                         _("HTTPS Proxy:"));
1104         screen->widgets.https_proxy_f = widget_new_textbox(set, 0, 0, 32,
1105                                                 config->https_proxy);
1106
1107         if (config->safe_mode)
1108                 screen->widgets.safe_mode = widget_new_label(set, 0, 0,
1109                          _("Selecting 'OK' will exit safe mode"));
1110
1111         screen->widgets.allow_write_l = widget_new_label(set, 0, 0,
1112                         _("Disk R/W:"));
1113         screen->widgets.allow_write_f = widget_new_select(set, 0, 0,
1114                                                 COLS - screen->field_x - 1);
1115
1116         widget_select_add_option(screen->widgets.allow_write_f, 0,
1117                                 _("Prevent all writes to disk"),
1118                                 !config->allow_writes);
1119
1120         widget_select_add_option(screen->widgets.allow_write_f, 1,
1121                                 _("Allow bootloader scripts to modify disks"),
1122                                 config->allow_writes);
1123
1124         screen->widgets.boot_console_l = widget_new_label(set, 0, 0,
1125                         _("Boot console:"));
1126         screen->widgets.boot_console_f = widget_new_select(set, 0, 0,
1127                                                 COLS - screen->field_x - 1);
1128
1129         for (i = 0; i < config->n_consoles; i++){
1130                 found = config->boot_console &&
1131                         strncmp(config->boot_console, config->consoles[i],
1132                                 strlen(config->boot_console)) == 0;
1133                 widget_select_add_option(screen->widgets.boot_console_f, i,
1134                                         config->consoles[i], found);
1135         }
1136
1137         if (config->manual_console) {
1138                 label = talloc_asprintf(screen, _("Manually set: '%s'"),
1139                                         config->boot_console);
1140                 screen->widgets.manual_console_l = widget_new_label(set, 0, 0, label);
1141         }
1142
1143         tty = talloc_asprintf(screen, _("Current interface: %s"),
1144                                 ttyname(STDIN_FILENO));
1145         screen->widgets.current_console_l = widget_new_label(set, 0 , 0, tty);
1146
1147 #ifdef CRYPT_SUPPORT
1148         screen->widgets.update_password_l = widget_new_button(set, 0, 0, 30,
1149                         _("Update system password"), password_click, screen);
1150 #endif
1151
1152         screen->widgets.ok_b = widget_new_button(set, 0, 0, 10, _("OK"),
1153                         ok_click, screen);
1154         screen->widgets.help_b = widget_new_button(set, 0, 0, 10, _("Help"),
1155                         help_click, screen);
1156         screen->widgets.cancel_b = widget_new_button(set, 0, 0, 10, _("Cancel"),
1157                         cancel_click, screen);
1158 }
1159
1160 static void config_screen_widget_focus(struct nc_widget *widget, void *arg)
1161 {
1162         struct config_screen *screen = arg;
1163         int w_y, w_height, w_focus, s_max, adjust;
1164
1165         w_height = widget_height(widget);
1166         w_focus = widget_focus_y(widget);
1167         w_y = widget_y(widget) + w_focus;
1168         s_max = getmaxy(screen->scr.sub_ncw) - 1;
1169
1170         if (w_y < screen->scroll_y)
1171                 screen->scroll_y = w_y;
1172
1173         else if (w_y + screen->scroll_y + 1 > s_max) {
1174                 /* Fit as much of the widget into the screen as possible */
1175                 adjust = min(s_max - 1, w_height - w_focus);
1176                 if (w_y + adjust >= screen->scroll_y + s_max)
1177                         screen->scroll_y = max(0, 1 + w_y + adjust - s_max);
1178         } else
1179                 return;
1180
1181         pad_refresh(screen);
1182 }
1183
1184 static void config_screen_draw(struct config_screen *screen,
1185                 const struct config *config,
1186                 const struct system_info *sysinfo)
1187 {
1188         bool repost = false;
1189         int height;
1190
1191         /* The size of the pad we'll need depends on the number of interfaces.
1192          *
1193          * We use N_FIELDS (which is quite conservative, as some fields share
1194          * a line) as a base, then:
1195          * - add 6 (as the network select & boot device select fields take 3
1196          *   lines each),
1197          * - add n_interfaces for every field in the network select field, and
1198          * - add (n_blockdevs + n_interfaces) for every field in the boot device
1199          *   select field
1200          */
1201         height = N_FIELDS + 6;
1202         if (sysinfo) {
1203                 height += sysinfo->n_interfaces;
1204                 height += (sysinfo->n_blockdevs + sysinfo->n_interfaces);
1205         }
1206         if (!screen->pad || getmaxy(screen->pad) < height) {
1207                 if (screen->pad)
1208                         delwin(screen->pad);
1209                 screen->pad = newpad(height, COLS + 10);
1210         }
1211
1212         if (screen->widgetset) {
1213                 widgetset_unpost(screen->widgetset);
1214                 talloc_free(screen->widgetset);
1215                 repost = true;
1216         }
1217
1218         screen->widgetset = widgetset_create(screen, screen->scr.main_ncw,
1219                         screen->pad);
1220         widgetset_set_widget_focus(screen->widgetset,
1221                         config_screen_widget_focus, screen);
1222
1223         if (!config || !sysinfo) {
1224                 config_screen_setup_empty(screen);
1225         } else {
1226                 screen->net_conf_type = find_net_conf_type(config);
1227                 config_screen_setup_widgets(screen, config, sysinfo);
1228                 config_screen_layout_widgets(screen);
1229         }
1230
1231         if (repost)
1232                 widgetset_post(screen->widgetset);
1233 }
1234
1235 void config_screen_update(struct config_screen *screen,
1236                 const struct config *config,
1237                 const struct system_info *sysinfo)
1238 {
1239         if (screen->cui->current != config_screen_scr(screen)) {
1240                 screen->need_update = true;
1241                 return;
1242         }
1243
1244         config_screen_draw(screen, config, sysinfo);
1245         pad_refresh(screen);
1246 }
1247
1248 static int config_screen_post(struct nc_scr *scr)
1249 {
1250         struct config_screen *screen = config_screen_from_scr(scr);
1251
1252         /* We may have been posted after an auth action completed */
1253         if (screen->exit) {
1254                 screen->on_exit(screen->cui);
1255                 return 0;
1256         }
1257
1258         if (screen->need_update) {
1259                 config_screen_draw(screen, screen->cui->config,
1260                                    screen->cui->sysinfo);
1261                 screen->need_update = false;
1262         } else {
1263                 widgetset_post(screen->widgetset);
1264         }
1265
1266         nc_scr_frame_draw(scr);
1267         if (screen->need_redraw) {
1268                 redrawwin(scr->main_ncw);
1269                 screen->need_redraw = false;
1270         }
1271         wrefresh(screen->scr.main_ncw);
1272         pad_refresh(screen);
1273         return 0;
1274 }
1275
1276 static int config_screen_destroy(void *arg)
1277 {
1278         struct config_screen *screen = arg;
1279         if (screen->pad)
1280                 delwin(screen->pad);
1281         return 0;
1282 }
1283
1284 struct config_screen *config_screen_init(struct cui *cui,
1285                 const struct config *config,
1286                 const struct system_info *sysinfo,
1287                 void (*on_exit)(struct cui *))
1288 {
1289         struct config_screen *screen;
1290
1291         screen = talloc_zero(cui, struct config_screen);
1292         talloc_set_destructor(screen, config_screen_destroy);
1293         nc_scr_init(&screen->scr, pb_config_screen_sig, 0,
1294                         cui, config_screen_process_key,
1295                         config_screen_post, config_screen_unpost,
1296                         config_screen_resize);
1297
1298         screen->cui = cui;
1299         screen->on_exit = on_exit;
1300         screen->need_redraw = false;
1301         screen->need_update = false;
1302         screen->label_x = 2;
1303         screen->field_x = 17;
1304
1305         screen->ipmi_override = false;
1306
1307         screen->scr.frame.ltitle = talloc_strdup(screen,
1308                         _("Petitboot System Configuration"));
1309         screen->scr.frame.rtitle = NULL;
1310         screen->scr.frame.help = talloc_strdup(screen,
1311                         _("tab=next, shift+tab=previous, x=exit, h=help"));
1312         nc_scr_frame_draw(&screen->scr);
1313
1314         scrollok(screen->scr.sub_ncw, true);
1315
1316         config_screen_draw(screen, config, sysinfo);
1317
1318         return screen;
1319 }