/* Constructs newt screens showing server certificate credentials. * Returns 1 if user says ok, 2 if not. */ static int show_cert (X509 *cert) { X509_NAME *name; newtGrid grid, serverGrid, issuerGrid, certGrid; newtComponent form; grid = newtCreateGrid(1,2); certGrid = newtCreateGrid(2,2); /* Subject */ name = X509_get_subject_name(cert); serverGrid = show_names(name); newtGridSetField(certGrid, 0,0, NEWT_GRID_COMPONENT, newtLabel(-1,-1, _("Installation Server:")), 2, 0, 0, 0, NEWT_ANCHOR_LEFT | NEWT_ANCHOR_TOP, 0); /* Issuer (CA) */ name = X509_get_issuer_name(cert); issuerGrid = show_names(name); newtGridSetField(certGrid, 1,0, NEWT_GRID_COMPONENT, newtLabel(-1,-1, _("Certified by:")), 2, 0, 0, 0, NEWT_ANCHOR_LEFT | NEWT_ANCHOR_TOP, 0); newtGridSetField(certGrid, 0, 1, NEWT_GRID_SUBGRID, serverGrid, 0, 0, 2, 0, NEWT_ANCHOR_LEFT | NEWT_ANCHOR_TOP, 0); newtGridSetField(certGrid, 1, 1, NEWT_GRID_SUBGRID, issuerGrid, 0, 0, 0, 0, NEWT_ANCHOR_RIGHT | NEWT_ANCHOR_TOP, 0); newtGridSetField(grid, 0, 0, NEWT_GRID_SUBGRID, certGrid, 0, 0, 0, 1, NEWT_ANCHOR_LEFT, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, _("Authenticate Installation Server")); form = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, form, 1); newtDrawForm(form); newtRefresh(); sleep(10); newtPopWindow(); return 1; }
/* this handles up to 50 items */ static newtGrid stackem(int isVert, enum newtGridElement type1, void * what1, va_list args, int close) { struct item { enum newtGridElement type; void * what; } items[50]; int i, num; newtGrid grid; items[0].type = type1, items[0].what = what1, num = 1; while (1) { items[num].type = va_arg(args, enum newtGridElement); if (items[num].type == NEWT_GRID_EMPTY) break; items[num].what = va_arg(args, void *); num++; } grid = newtCreateGrid(isVert ? 1 : num, isVert ? num : 1); for (i = 0; i < num; i++) { newtGridSetField(grid, isVert ? 0 : i, isVert ? i : 0, items[i].type, items[i].what, close ? 0 : (i ? (isVert ? 0 : 1) : 0), close ? 0 : (i ? (isVert ? 1 : 0) : 0), 0, 0, 0, 0); } return grid; }
newtGrid newtGridSimpleWindow(newtComponent text, newtComponent middle, newtGrid buttons) { newtGrid grid; grid = newtCreateGrid(1, 3); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, middle, 0, 1, 0, 0, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX); return grid; }
static char *newKickstartLocation(const char *origLocation) { const char *location; char *retval = NULL; newtComponent f, okay, cancel, answer, locationEntry; newtGrid grid, buttons; startNewt(); locationEntry = newtEntry(-1, -1, NULL, 60, &location, NEWT_FLAG_SCROLL); newtEntrySet(locationEntry, origLocation, 1); /* button bar at the bottom of the window */ buttons = newtButtonBar(_("OK"), &okay, _("Cancel"), &cancel, NULL); grid = newtCreateGrid(1, 3); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, newtTextboxReflowed(-1, -1, _("Unable to download the kickstart file. Please modify the kickstart parameter below or press Cancel to proceed as an interactive installation."), 60, 0, 0, 0), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, locationEntry, 0, 1, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX); f = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, f, 1); newtGridWrappedWindow(grid, _("Error downloading kickstart file")); newtGridFree(grid, 1); /* run the form */ answer = newtRunForm(f); if (answer != cancel) retval = strdup(location); newtFormDestroy(f); newtPopWindow(); return retval; }
void vwait_message_newt(const char *msg, va_list ap) { int width, height; const char title[] = "Please wait..."; newtComponent c, f; newtGrid grid; char * buf = NULL; char * flowed; int size = 0; int i = 0; do { size += 1000; if (buf) free(buf); buf = (char*)malloc(size); i = vsnprintf(buf, size, msg, ap); } while (i >= size || i == -1); flowed = newtReflowText(buf, 60, 5, 5, &width, &height); c = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); newtTextboxSetText(c, flowed); grid = newtCreateGrid(1, 1); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, c, 0, 0, 0, 0, 0, 0); newtGridWrappedWindow(grid, (char*)title); free(flowed); free(buf); f = newtForm(NULL, NULL, 0); newtFormAddComponent(f, c); newtDrawForm(f); newtRefresh(); newtFormDestroy(f); }
int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol) { newtComponent form, okay, cancel, answer, text, accountEntry = NULL; newtComponent passwordEntry = NULL, proxyEntry = NULL; newtComponent proxyPortEntry = NULL; char * account, * password, * proxy, * proxyPort; newtGrid buttons, entryGrid, grid; char * reflowedText = NULL; int width, height; if (protocol == URL_METHOD_FTP) { reflowedText = newtReflowText( _("If you are using non anonymous ftp, enter the account name and " "password you wish to use below."), 47, 5, 5, &width, &height); } else { reflowedText = newtReflowText( _("If you are using a HTTP proxy server " "enter the name of the HTTP proxy server to use."), 47, 5, 5, &width, &height); } text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); newtTextboxSetText(text, reflowedText); free(reflowedText); if (protocol == URL_METHOD_FTP) { accountEntry = newtEntry(-1, -1, NULL, 24, (const char **) &account, NEWT_FLAG_SCROLL); passwordEntry = newtEntry(-1, -1, NULL, 24, (const char **) &password, NEWT_FLAG_SCROLL | NEWT_FLAG_PASSWORD); } proxyEntry = newtEntry(-1, -1, ui->proxy, 24, (const char **) &proxy, NEWT_ENTRY_SCROLL); proxyPortEntry = newtEntry(-1, -1, ui->proxyPort, 6, (const char **) &proxyPort, NEWT_FLAG_SCROLL); entryGrid = newtCreateGrid(2, 4); if (protocol == URL_METHOD_FTP) { newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("Account name:")), 0, 0, 2, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("Password:"******"OK"), &okay, _("Back"), &cancel, NULL); grid = newtCreateGrid(1, 3); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, entryGrid, 0, 1, 0, 0, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX); if (protocol == URL_METHOD_FTP) { newtGridWrappedWindow(grid, _("Further FTP Setup")); } else { if (protocol == URL_METHOD_HTTP) newtGridWrappedWindow(grid, _("Further HTTP Setup")); } form = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, form, 1); newtGridFree(grid, 1); answer = newtRunForm(form); if (answer == cancel) { newtFormDestroy(form); newtPopWindow(); return LOADER_BACK; } if (protocol == URL_METHOD_FTP) { if (ui->login) free(ui->login); if (strlen(account)) ui->login = strdup(account); else ui->login = NULL; if (ui->password) free(ui->password); if (strlen(password)) ui->password = strdup(password); else ui->password = NULL; } newtFormDestroy(form); newtPopWindow(); return 0; }
int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol, char * doSecondarySetup) { newtComponent form, okay, cancel, siteEntry, dirEntry; newtComponent answer, text; newtComponent cb = NULL; char * site, * dir; char * reflowedText = NULL; int width, height; newtGrid entryGrid, buttons, grid; char * chptr; char * buf = NULL; if (ui->address) { site = ui->address; dir = ui->prefix; } else { site = ""; dir = ""; } if (ui->login || ui->password || ui->proxy || ui->proxyPort) *doSecondarySetup = '*'; else *doSecondarySetup = ' '; buttons = newtButtonBar(_("OK"), &okay, _("Back"), &cancel, NULL); switch (protocol) { case URL_METHOD_FTP: buf = sdupprintf(_(netServerPrompt), _("FTP"), getProductName()); reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height); free(buf); break; case URL_METHOD_HTTP: buf = sdupprintf(_(netServerPrompt), _("Web"), getProductName()); reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height); free(buf); break; #ifdef ROCKS case URL_METHOD_HTTPS: buf = sdupprintf(_(netServerPrompt), "Secure Web", getProductName()); reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height); free(buf); break; #endif /* ROCKS */ } text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); newtTextboxSetText(text, reflowedText); free(reflowedText); siteEntry = newtEntry(22, 8, site, 24, (const char **) &site, NEWT_ENTRY_SCROLL); dirEntry = newtEntry(22, 9, dir, 24, (const char **) &dir, NEWT_ENTRY_SCROLL); entryGrid = newtCreateGrid(2, 2); newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT, newtLabel(-1, -1, (protocol == URL_METHOD_FTP) ? _("FTP site name:") : _("Web site name:")), 0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT, newtLabel(-1, -1, sdupprintf(_("%s directory:"), getProductName())), 0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(entryGrid, 1, 0, NEWT_GRID_COMPONENT, siteEntry, 0, 0, 0, 0, 0, 0); newtGridSetField(entryGrid, 1, 1, NEWT_GRID_COMPONENT, dirEntry, 0, 0, 0, 0, 0, 0); grid = newtCreateGrid(1, 4); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, entryGrid, 0, 0, 0, 1, 0, 0); if (protocol == URL_METHOD_FTP) { cb = newtCheckbox(3, 11, _("Use non-anonymous ftp"), *doSecondarySetup, NULL, doSecondarySetup); newtGridSetField(grid, 0, 2, NEWT_GRID_COMPONENT, cb, 0, 0, 0, 1, NEWT_ANCHOR_LEFT, 0); } newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, (protocol == URL_METHOD_FTP) ? _("FTP Setup") : _("HTTP Setup")); form = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, form, 1); do { answer = newtRunForm(form); if (answer != cancel) { if (!strlen(site)) { newtWinMessage(_("Error"), _("OK"), _("You must enter a server name.")); continue; } if (!strlen(dir)) { newtWinMessage(_("Error"), _("OK"), _("You must enter a directory.")); continue; } if (!addrToIp(site)) { newtWinMessage(_("Unknown Host"), _("OK"), _("%s is not a valid hostname."), site); continue; } } break; } while (1); if (answer == cancel) { newtFormDestroy(form); newtPopWindow(); return LOADER_BACK; } if (ui->address) free(ui->address); ui->address = strdup(site); if (ui->prefix) free(ui->prefix); /* add a slash at the start of the dir if it is missing */ if (*dir != '/') { if (asprintf(&(ui->prefix), "/%s", dir) == -1) ui->prefix = strdup(dir); } else { ui->prefix = strdup(dir); } /* Get rid of trailing /'s */ chptr = ui->prefix + strlen(ui->prefix) - 1; while (chptr > ui->prefix && *chptr == '/') chptr--; chptr++; *chptr = '\0'; if (*doSecondarySetup != '*') { if (ui->login) free(ui->login); if (ui->password) free(ui->password); if (ui->proxy) free(ui->proxy); if (ui->proxyPort) free(ui->proxyPort); ui->login = ui->password = ui->proxy = ui->proxyPort = NULL; } ui->protocol = protocol; newtFormDestroy(form); newtPopWindow(); return 0; }
static void nmt_newt_dialog_g_log_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data) { const char *level_name; char *full_message; int screen_width, screen_height; newtComponent text, ok, form; newtGrid grid; g_assert (!(log_level & G_LOG_FLAG_RECURSION)); if (log_level & G_LOG_LEVEL_DEBUG) return; switch (log_level & G_LOG_LEVEL_MASK) { case G_LOG_LEVEL_ERROR: level_name = "ERROR"; break; case G_LOG_LEVEL_CRITICAL: level_name = "CRITICAL"; break; case G_LOG_LEVEL_WARNING: level_name = "WARNING"; break; case G_LOG_LEVEL_MESSAGE: level_name = "Message"; break; default: level_name = NULL; } full_message = g_strdup_printf ("%s%s%s%s%s", log_domain ? log_domain : "", log_domain && level_name ? " " : "", level_name ? level_name : "", log_domain || level_name ? ": " : "", message); /* newtWinMessage() wraps the window too narrowly by default, so * we don't want to use that. But we intentionally avoid using any * NmtNewt classes, to avoid possible error recursion. */ newtGetScreenSize (&screen_width, &screen_height); text = newtTextboxReflowed (-1, -1, full_message, MAX (70, screen_width - 10), 0, 0, 0); g_free (full_message); ok = newtButton (-1, -1, "OK"); grid = newtCreateGrid (1, 2); newtGridSetField (grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0); newtGridSetField (grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0, NEWT_ANCHOR_RIGHT, 0); newtGridWrappedWindow (grid, (char *) (level_name ? level_name : "")); newtGridFree (grid, TRUE); form = newtForm (NULL, NULL, 0); newtFormAddComponents (form, text, ok, NULL); newtRunForm (form); newtFormDestroy (form); newtPopWindow (); }
/* only supports up to 50 buttons and entries -- shucks! */ static int mynewtWinEntries(char * title, char * text, int suggestedWidth, int flexDown, int flexUp, int dataWidth, void (*callback_func)(char ** strings), struct newtWinEntry * items, char * button1, ...) { newtComponent buttons[50], result, form, textw; newtGrid grid, buttonBar, subgrid; int numItems; int rc, i; int numButtons; char * buttonName; newtComponent entries[50]; va_list args; textw = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown, flexUp, 0); for (numItems = 0; items[numItems].text; numItems++); buttonName = button1, numButtons = 0; va_start(args, button1); while (buttonName) { buttons[numButtons] = newtButton(-1, -1, buttonName); numButtons++; buttonName = va_arg(args, char *); } va_end(args); buttonBar = newtCreateGrid(numButtons, 1); for (i = 0; i < numButtons; i++) { newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT, buttons[i], i ? 1 : 0, 0, 0, 0, 0, 0); } if (callback_func) { callback_real_function = callback_func; entries[numItems] = NULL; } else callback_real_function = NULL; subgrid = newtCreateGrid(2, numItems); for (i = 0; i < numItems; i++) { newtComponent entr = newtEntry(-1, -1, items[i].value ? *items[i].value : NULL, dataWidth, (const char**)items[i].value, items[i].flags); newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT, newtLabel(-1, -1, items[i].text), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(subgrid, 1, i, NEWT_GRID_COMPONENT, entr, 1, 0, 0, 0, 0, 0); if (callback_func) { entries[i] = entr; newtComponentAddCallback(entr, default_callback, entries); } } grid = newtCreateGrid(1, 3); form = newtForm(NULL, 0, 0); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, textw, 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 1, 0, 0, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttonBar, 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridAddComponentsToForm(grid, form, 1); newtGridWrappedWindow(grid, title); newtGridFree(grid, 1); result = newtRunForm(form); for (rc = 0; rc < numItems; rc++) *items[rc].value = strdup(*items[rc].value); for (rc = 0; result != buttons[rc] && rc < numButtons; rc++); if (rc == numButtons) rc = 0; /* F12 */ else rc++; newtFormDestroy(form); newtPopWindow(); return rc; }
int main(void) { newtComponent b1, b2, b3, b4; newtComponent answer, f, t; newtGrid grid, subgrid; char * flowedText; int textWidth, textHeight, rc; char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL }; char * entries[10]; struct newtWinEntry autoEntries[] = { { "An entry", entries + 0, 0 }, { "Another entry", entries + 1, 0 }, { "Third entry", entries + 2, 0 }, { "Fourth entry", entries + 3, 0 }, { NULL, NULL, 0 } }; memset(entries, 0, sizeof(entries)); newtInit(); newtCls(); b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL); b2 = newtButton(-1, -1, "Another Button"); b3 = newtButton(-1, -1, "But, but"); b4 = newtButton(-1, -1, "But what?"); f = newtForm(NULL, NULL, 0); grid = newtCreateGrid(2, 2); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, NEWT_ANCHOR_RIGHT, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0); newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0); newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0); newtFormAddComponents(f, b1, b2, b3, b4, NULL); newtGridWrappedWindow(grid, "first window"); newtGridFree(grid, 1); answer = newtRunForm(f); newtFormDestroy(f); newtPopWindow(); flowedText = newtReflowText("This is a quite a bit of text. It is 40 " "columns long, so some wrapping should be " "done. Did you know that the quick, brown " "fox jumped over the lazy dog?\n\n" "In other news, it's pretty important that we " "can properly force a line break.", 40, 5, 5, &textWidth, &textHeight); t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP); newtTextboxSetText(t, flowedText); free(flowedText); b1 = newtButton(-1, -1, "Okay"); b2 = newtButton(-1, -1, "Cancel"); grid = newtCreateGrid(1, 2); subgrid = newtCreateGrid(2, 1); newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0); newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, "another example"); newtGridDestroy(grid, 1); f = newtForm(NULL, NULL, 0); newtFormAddComponents(f, b1, t, b2, NULL); answer = newtRunForm(f); newtPopWindow(); newtFormDestroy(f); newtWinMessage("Simple", "Ok", "This is a simple message window"); newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window"); textWidth = 0; rc = newtWinMenu("Test Menu", "This is a sample invovation of the " "newtWinMenu() call. It may or may not have a scrollbar, " "depending on the need for one.", 50, 5, 5, 3, menuContents, &textWidth, "Ok", "Cancel", NULL); rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of " "newtWinEntries() call. It lets you get a lot of input " "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", "Cancel", NULL); newtFinished(); printf("rc = 0x%x item = %d\n", rc, textWidth); return 0; }
static newtGrid show_names(X509_NAME *name) { char value[1024]; const char *element; char *label; int i, nameCount, nid; X509_NAME_ENTRY *entry; newtGrid grid; nameCount = X509_NAME_entry_count(name); grid = newtCreateGrid(2, nameCount+1); for (i=0; i<nameCount; i++) { entry = X509_NAME_get_entry(name, i); if (!entry) { logMessage(ERROR, "Could not find a certificate name"); return NULL; } nid = OBJ_obj2nid(entry->object); element = OBJ_nid2sn(nid); switch (*element) { case 'C': if (!strcmp(element, "CN")) label = _("Name"); else label = _("Country"); break; case 'S': label =_("State"); break; case 'L': label = _("Locality"); break; case 'e': case 'E': label = _("Contact"); break; case 'O': if (!strcmp(element, "OU")) label = _("Org Unit"); else label = _("Org"); break; default: label = (char*) element; } snprintf(value, sizeof(value), "%*s", entry->value->length, entry->value->data); newtGridSetField(grid, 0, i+1, NEWT_GRID_COMPONENT, newtLabel(-1,-1, _(label)), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 1, i+1, NEWT_GRID_COMPONENT, newtLabel(-1,-1, _(value)), 2, 0, 0, 0, NEWT_ANCHOR_LEFT, NEWT_FLAG_WRAP); } return grid; }
/* Browse through a directory structure looking for a file. * Returns the full path to the file. * * Parameters: * title: Title for newt dialog window * dirname: Directory to use for root of browsing. NOTE: you cannot go * up above this root. * filterfunc: An (optional) function to filter out files based on whatever * criteria you want. Returns 1 if it passes, 0 if not. * Function should take arguments of the directory name and * the dirent for the file. */ char * newt_select_file(char * title, char * text, char * dirname, int (*filterfunc)(char *, struct dirent *)) { char ** files; char * fn = NULL; int i, done = 0; char * topdir = dirname; char * dir = malloc(PATH_MAX); char * path = NULL; newtGrid grid, buttons; newtComponent f, tb, listbox, ok, cancel; struct stat sb; struct newtExitStruct es; dir = realpath(dirname, dir); do { files = get_file_list(dir, filterfunc); f = newtForm(NULL, NULL, 0); grid = newtCreateGrid(1, 4); tb = newtTextboxReflowed(-1, -1, text, 60, 0, 10, 0); listbox = newtListbox(12, 65, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); newtListboxSetWidth(listbox, 55); buttons = newtButtonBar(_("OK"), &ok, _("Cancel"), &cancel, NULL); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, tb, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); /* if this isn't our topdir, we want to let them go up a dir */ if (strcmp(topdir, dir)) newtListboxAppendEntry(listbox, "../", ".."); for (i = 0; (files[i] != NULL); i++) { if ((files[i] == NULL) || (strlen(files[i]) == 0)) continue; path = malloc(strlen(files[i]) + strlen(dir) + 2); sprintf(path, "%s/%s", dir, files[i]); stat(path, &sb); free(path); if (S_ISDIR(sb.st_mode)) { char *dir = malloc(strlen(files[i]) + 2); sprintf(dir, "%s/", files[i]); newtListboxAppendEntry(listbox, dir, files[i]); } else { newtListboxAppendEntry(listbox, files[i], files[i]); } } newtGridWrappedWindow(grid, title); newtGridAddComponentsToForm(grid, f, 1); newtFormRun(f, &es); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == cancel) { fn = NULL; done = -1; } else { fn = (char *) newtListboxGetCurrent(listbox); path = malloc(strlen(fn) + strlen(dir) + 2); sprintf(path, "%s/%s", dir, fn); stat(path, &sb); if (!S_ISDIR(sb.st_mode)) { fn = path; done = 1; } else { dir = realpath(path, dir); free(path); } } newtGridFree(grid, 1); newtFormDestroy(f); newtPopWindow(); } while (done == 0); return fn; }
static int getManualModuleArgs(struct moduleInfo * mod, char *** moduleArgs) { newtGrid grid, buttons; newtComponent text, f, ok, back, entry; struct newtExitStruct es; int done = 0, i; char * buf; char *argsEntry = ""; if (*moduleArgs) { for (i = 0; (*moduleArgs)[i]; i++) argsEntry = strcat(argsEntry, (*moduleArgs)[i]); } f = newtForm(NULL, NULL, 0); if (asprintf(&buf, _("Please enter any parameters which you wish to pass " "to the %s module separated by spaces. If you don't " "know what parameters to supply, skip this screen " "by pressing the \"OK\" button."), mod->moduleName) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } text = newtTextboxReflowed(-1, -1, buf, 60, 0, 10, 0); entry = newtEntry(-1, -1, argsEntry, 50, (const char **) &argsEntry, NEWT_ENTRY_SCROLL); newtFormAddHotKey(f, NEWT_KEY_F12); buttons = newtButtonBar(_("OK"), &ok, _("Back"), &back, NULL); grid = newtCreateGrid(1, 3); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, entry, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, _("Enter Module Parameters")); newtGridAddComponentsToForm(grid, f, 1); do { newtFormRun(f, &es); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == back) { done = -1; } else { done = 1; } } while (done == 0); free(buf); newtGridFree(grid, 1); if (done == -1) { newtFormDestroy(f); newtPopWindow(); return LOADER_BACK; } logMessage(INFO, "specified args of %s for %s", argsEntry, mod->moduleName); if (strlen(argsEntry) > 0) { int numAlloced = 5; char * start; char * end; i = 0; *moduleArgs = malloc((numAlloced + 1) * sizeof(*moduleArgs)); start = argsEntry; while (start && *start) { end = start; while (!isspace(*end) && *end) end++; *end = '\0'; (*moduleArgs)[i++] = strdup(start); start = end + 1; *end = ' '; start = strchr(end, ' '); if (start) start++; if (i >= numAlloced) { numAlloced += 5; *moduleArgs = realloc(*moduleArgs, sizeof(*moduleArgs) * (numAlloced + 1)); } } (*moduleArgs)[i] = NULL; } newtFormDestroy(f); newtPopWindow(); return LOADER_OK; }
/* setup hard drive based install from a partition with a filesystem and * ISO images on that filesystem */ char * mountHardDrive(struct installMethod * method, char * location, struct loaderData_s * loaderData) { int rc; int i; newtComponent listbox, label, dirEntry, form, okay, back, text; struct newtExitStruct es; newtGrid entryGrid, grid, buttons; int done = 0; char * dir = strdup(""); char * tmpDir; char * url = NULL; char * buf, *substr; int numPartitions; char **partition_list; char *selpart; char *kspartition = NULL, *ksdirectory = NULL; /* handle kickstart/stage2= data first if available */ if (loaderData->method == METHOD_HD && loaderData->stage2Data) { kspartition = ((struct hdInstallData *)loaderData->stage2Data)->partition; ksdirectory = ((struct hdInstallData *)loaderData->stage2Data)->directory; logMessage(INFO, "partition is %s, dir is %s", kspartition, ksdirectory); /* if exist, duplicate */ if (kspartition) kspartition = strdup(kspartition); if (ksdirectory) { ksdirectory = strdup(ksdirectory); } else { ksdirectory = strdup("/images/install.img"); } if (!kspartition || !ksdirectory) { logMessage(ERROR, "missing partition or directory specification"); loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { /* if we start with /dev, strip it (#121486) */ char *kspart = kspartition; if (!strncmp(kspart, "/dev/", 5)) kspart = kspart + 5; url = setupIsoImages(kspart, ksdirectory, location); if (!url) { logMessage(ERROR, "unable to find %s installation images on hd", getProductName()); loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { free(kspartition); free(ksdirectory); return url; } } } else { kspartition = NULL; ksdirectory = NULL; } /* if we're here its either because this is interactive, or the */ /* hd kickstart directive was faulty and we have to prompt for */ /* location of harddrive image */ partition_list = NULL; while (!done) { /* if we're doing another pass free this up first */ if (partition_list) freePartitionsList(partition_list); partition_list = getPartitionsList(NULL); numPartitions = lenPartitionsList(partition_list); /* no partitions found, try to load a device driver disk for storage */ if (!numPartitions) { rc = newtWinChoice(_("Hard Drives"), _("Yes"), _("Back"), _("You don't seem to have any hard drives on " "your system! Would you like to configure " "additional devices?")); if (rc == 2) { loaderData->stage2Data = NULL; return NULL; } rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0); continue; } /* now find out which partition has the stage2 image */ checked_asprintf(&buf, _("What partition and directory on that " "partition holds the installation image " "for %s? If you don't see the disk drive " "you're using listed here, press F2 to " "configure additional devices."), getProductName()); text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0); free(buf); listbox = newtListbox(-1, -1, numPartitions > 5 ? 5 : numPartitions, NEWT_FLAG_RETURNEXIT | (numPartitions > 5 ? NEWT_FLAG_SCROLL : 0)); for (i = 0; i < numPartitions; i++) newtListboxAppendEntry(listbox,partition_list[i],partition_list[i]); /* if we had ks data around use it to prime entry, then get rid of it*/ if (kspartition) { newtListboxSetCurrentByKey(listbox, kspartition); free(kspartition); kspartition = NULL; } label = newtLabel(-1, -1, _("Directory holding image:")); dirEntry = newtEntry(28, 11, dir, 28, (const char **) &tmpDir, NEWT_ENTRY_SCROLL); /* if we had ks data around use it to prime entry, then get rid of it*/ if (ksdirectory) { newtEntrySet(dirEntry, ksdirectory, 1); free(ksdirectory); ksdirectory = NULL; } entryGrid = newtGridHStacked(NEWT_GRID_COMPONENT, label, NEWT_GRID_COMPONENT, dirEntry, NEWT_GRID_EMPTY); buttons = newtButtonBar(_("OK"), &okay, _("Back"), &back, NULL); grid = newtCreateGrid(1, 4); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, entryGrid, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, _("Select Partition")); form = newtForm(NULL, NULL, 0); newtFormAddHotKey(form, NEWT_KEY_F2); newtFormAddHotKey(form, NEWT_KEY_F12); newtGridAddComponentsToForm(grid, form, 1); newtGridFree(grid, 1); newtFormRun(form, &es); selpart = newtListboxGetCurrent(listbox); free(dir); if (tmpDir && *tmpDir) { /* Protect from form free. */ dir = strdup(tmpDir); } else { dir = strdup(""); } newtFormDestroy(form); newtPopWindow(); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == back) { loaderData->stage2Data = NULL; return NULL; } else if (es.reason == NEWT_EXIT_HOTKEY && es.u.key == NEWT_KEY_F2) { rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0); continue; } logMessage(INFO, "partition %s selected", selpart); /* If the user-provided URL points at a repo instead of a stage2 * image, fix that up now. */ substr = strstr(dir, ".img"); if (!substr || (substr && *(substr+4) != '\0')) { checked_asprintf(&dir, "%s/images/install.img", dir); } loaderData->invalidRepoParam = 1; url = setupIsoImages(selpart, dir, location); if (!url) { newtWinMessage(_("Error"), _("OK"), _("Device %s does not appear to contain " "an installation image."), selpart, getProductName()); continue; } done = 1; } free(dir); return url; }