/* Get a password Return SUCCESS if OK Return FAILURE if CANCEL */ static int getpassword(char *password, char *text) { char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { {gettext("TR_PASSWORD_PROMPT"), &values[0], NEWT_FLAG_PASSWORD}, {gettext("TR_AGAIN_PROMPT"), &values[1], NEWT_FLAG_PASSWORD}, {NULL, NULL, 0} }; int rc; int done; do { done = 1; rc = newtWinEntries(gettext("TR_TITLE_PASSWORD"), text, 68, 5, 5, 40, entries, gettext("TR_OK"), (flag_is_state == setup) ? gettext("TR_GO_BACK") : NULL, NULL); if (rc == 2) { return FAILURE; } if (strlen(values[0]) == 0 || strlen(values[1]) == 0) { errorbox(gettext("TR_PASSWORD_CANNOT_BE_BLANK")); done = 0; } else if (strcmp(values[0], values[1]) != 0) { errorbox(gettext("TR_PASSWORDS_DO_NOT_MATCH")); done = 0; } else if (strchr(values[0], ' ')) { errorbox(gettext("TR_PASSWORD_CANNOT_CONTAIN_SPACES")); done = 0; } else if (strlen(values[0]) < 6) { errorbox(gettext("TR_PASSWORD_MINIMAL_LENGTH_IS_6")); done = 0; } else if (strchr(values[0], '"') || strstr(values[0], "'")) { errorbox(gettext("TR_PASSWORD_CANNOT_CONTAIN_SIMPLE_OR_DOUBLE_QUOTE")); done = 0; } if (done == 0) { strcpy(values[0], ""); strcpy(values[1], ""); } } while (!done); strncpy(password, values[0], STRING_SIZE); if (values[0]) free(values[0]); if (values[1]) free(values[1]); return SUCCESS; }
int handlehostname(void) { char hostname[STRING_SIZE] = ""; struct keyvalue *kv = initkeyvalues(); char *values[] = { hostname, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; int result; if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } strcpy(hostname, SNAME); findkey(kv, "HOSTNAME", hostname); for (;;) { rc = newtWinEntries(_("Hostname"), _("Enter the machine's hostname."), 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL); if (rc == 1) { strcpy(hostname, values[0]); if (!(strlen(hostname))) errorbox(_("Hostname cannot be empty.")); else if (strchr(hostname, ' ')) errorbox(_("Hostname cannot contain spaces.")); else if (strlen(hostname) != strspn(hostname, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")) errorbox(_("Hostname may only contain letters, numbers and hyphens.")); else { replacekeyvalue(kv, "HOSTNAME", hostname); writekeyvalues(kv, CONFIG_ROOT "/main/settings"); writehostsfiles(); result = 1; break; } } else { result = 0; break; } } free(values[0]); freekeyvalues(kv); return result; }
/* Taken from the cdrom one. */ int getpassword(char *password, char *text) { char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { _("Password:"******"Again:"), &values[1], 2 }, { NULL, NULL, 0 } }; char title[STRING_SIZE]; int rc; int done; do { done = 1; sprintf (title, "%s - %s", NAME, SLOGAN); rc = newtWinEntries(title, text, 65, 5, 5, 50, entries, _("OK"), _("Cancel"), NULL); if (rc != 2) { if (strlen(values[0]) == 0 || strlen(values[1]) == 0) { errorbox(_("Password cannot be blank.")); done = 0; strcpy(values[0], ""); strcpy(values[1], ""); } else if (strcmp(values[0], values[1]) != 0) { errorbox(_("Passwords do not match.")); done = 0; strcpy(values[0], ""); strcpy(values[1], ""); } else if (strchr(values[0], ' ')) { errorbox(_("Password cannot contain spaces.")); done = 0; strcpy(values[0], ""); strcpy(values[1], ""); } } } while (!done); strncpy(password, values[0], STRING_SIZE); if (values[0]) free(values[0]); if (values[1]) free(values[1]); return rc; }
static int nfsGetSetup(char ** hostptr, char ** dirptr) { struct newtWinEntry entries[3]; char * buf; char * newServer = *hostptr ? strdup(*hostptr) : NULL; char * newDir = *dirptr ? strdup(*dirptr) : NULL; int rc; entries[0].text = _("NFS server name:"); entries[0].value = &newServer; entries[0].flags = NEWT_FLAG_SCROLL; if (asprintf(&entries[1].text, _("%s directory:"), getProductName()) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } entries[1].value = &newDir; entries[1].flags = NEWT_FLAG_SCROLL; entries[2].text = NULL; entries[2].value = NULL; if (asprintf(&buf, _("Please enter the server name and path to your %s " "installation image."), getProductName()) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } do { rc = newtWinEntries(_("NFS Setup"), buf, 60, 5, 15, 24, entries, _("OK"), _("Back"), NULL); } while (!strcmp(newServer, "") || !strcmp(newDir, "")); free(buf); free(entries[1].text); if (rc == 2) { if (newServer) free(newServer); if (newDir) free(newDir); return LOADER_BACK; } if (*hostptr) free(*hostptr); if (*dirptr) free(*dirptr); *hostptr = newServer; *dirptr = newDir; return 0; }
/* Manual entry for gurus. */ int manualdriver(char *driver, char *driveroptions) { char *values[] = { NULL, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; char commandstring[STRING_SIZE]; char *driverend; strcpy(driver, ""); strcpy(driveroptions, ""); rc = newtWinEntries(_("Select network driver"), _("Set additional module parameters"), 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL); if (rc == 0 || rc == 1) { if (strlen(values[0])) { sprintf(commandstring, "/sbin/modprobe %s", values[0]); if (runcommandwithstatus(commandstring, _("Loading module..."), _("Loading module..."), NULL) == 0) { if ((driverend = strchr(values[0], ' '))) { *driverend = '\0'; strcpy(driver, values[0]); strcpy(driveroptions, driverend + 1); } else { strcpy(driver, values[0]); strcpy(driveroptions, ""); } } else errorbox(_("Unable to load driver module.")); } else errorbox(_("Module name cannot be blank.")); } free(values[0]); return 1; }
void handleisdnmsn(void) { struct keyvalue *kv = initkeyvalues(); char msn[STRING_SIZE] = ""; const char *values[] = { msn, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "MSN", msn); for (;;) { rc = newtWinEntries(TITLE, ctr[TR_ENTER_THE_LOCAL_MSN], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { if (!(strlen(values[0]))) errorbox(ctr[TR_PHONENUMBER_CANNOT_BE_EMPTY]); else { strcpy(msn, values[0]); replacekeyvalue(kv, "MSN", msn); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); break; } } else break; } freekeyvalues(kv); free((char *) values[0]); }
int nfsGetSetup(char ** hostptr, char ** dirptr, char ** optsptr) { struct newtWinEntry entries[4]; char * buf; char * newServer = *hostptr ? strdup(*hostptr) : NULL; char * newDir = *dirptr ? strdup(*dirptr) : NULL; char * newMountOpts = *optsptr ? strdup(*optsptr) : NULL; int rc; entries[0].text = _("NFS server name:"); entries[0].value = (const char **) &newServer; entries[0].flags = NEWT_FLAG_SCROLL; entries[1].text = sdupprintf(_("%s directory:"), getProductName()); entries[1].value = (const char **) &newDir; entries[1].flags = NEWT_FLAG_SCROLL; entries[2].text = _("NFS mount options (optional):"); entries[2].value = (const char **) &newMountOpts; entries[2].flags = NEWT_FLAG_SCROLL; entries[3].text = NULL; entries[3].value = NULL; buf = sdupprintf(_(nfsServerPrompt), getProductName()); rc = newtWinEntries(_("NFS Setup"), buf, 60, 5, 15, 24, entries, _("OK"), _("Back"), NULL); free(buf); if (rc == 2) { if (newServer) free(newServer); if (newDir) free(newDir); if (newMountOpts) free(newMountOpts); return LOADER_BACK; } if (*hostptr) free(*hostptr); if (*dirptr) free(*dirptr); if (*optsptr) free(*optsptr); *hostptr = newServer; *dirptr = newDir; *optsptr = newMountOpts; return 0; }
void handlemoduleparams(void) { struct keyvalue *kv = initkeyvalues(); char moduleparams[STRING_SIZE] = ""; const char *values[] = { moduleparams, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "MODULE_PARAMS", moduleparams); for (;;) { rc = newtWinEntries(TITLE, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { strcpy(moduleparams, values[0]); replacekeyvalue(kv, "MODULE_PARAMS", moduleparams); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); break; } else break; } free((char * ) values[0]); freekeyvalues(kv); }
/* DNS and default gateway.... */ int dnsgatewaymenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } entries[DNS1].text = _("Primary DNS:"); strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = _("Secondary DNS:"); strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = _("Default gateway:"); strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(_("DNS and Gateway settings"), _("Enter the DNS and gateway information. " "These settings are used only with Static IP (and DHCP if DNS set) on the RED interface."), 50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL); if (rc == 0 || rc == 1) { strcpy(message, _("The following fields are invalid:")); strcpy(message, "\n\n"); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, _("Primary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, _("Secondary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, _("Default gateway")); strcat(message, "\n"); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, _("Secondary DNS specified without a Primary DNS")); strcat(message, "\n"); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free(values[DNS1]); free(values[DNS2]); free(values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1; }
/* DNS and default gateway.... */ int dnsgatewaymenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (!CONFIG_TYPE_RED(configtype)) { freekeyvalues(kv); errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); return 0; } entries[DNS1].text = ctr[TR_PRIMARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = (const char **) &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = ctr[TR_SECONDARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = (const char **) &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = (const char **) &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { strcpy(message, ctr[TR_INVALID_FIELDS]); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, ctr[TR_PRIMARY_DNS_CR]); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, ctr[TR_SECONDARY_DNS_CR]); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free((char *) values[DNS1]); free((char *) values[DNS2]); free((char *) values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1; }
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; }