// ======================================================= int CRestoreOptWindow::create(char *szDevice, char *szImageFile, COptions options) { BEGIN; char szTemp[1024]; SNPRINTF(szTemp, i18n("restore partition from image file")); newtCenteredWindow(78, 20, szTemp); m_labelOptions = newtLabel(1, 1, i18n("Options")); m_checkEraseWithNull = newtCheckbox(1, 3, i18n("Erase free blocks with zero values"), (!!options.bEraseWithNull ? 'X' : ' '), " X", NULL); m_checkSimulateMode = newtCheckbox(1, 2, i18n("Simulation of the restoration (nothing is written)"), (!!options.bSimulateMode ? 'X' : ' '), " X", NULL); m_labelFinish = newtLabel(1, 5, i18n("If finished successfully:")); m_radioFinishWait = newtRadiobutton(1, 6, i18n("Wait"), options.dwFinish == FINISH_WAIT, NULL); m_radioFinishHalt = newtRadiobutton(1, 7, i18n("Halt"), options.dwFinish == FINISH_HALT, m_radioFinishWait); m_radioFinishReboot = newtRadiobutton(1, 8, i18n("Reboot"), options.dwFinish == FINISH_REBOOT, m_radioFinishHalt); m_radioFinishQuit = newtRadiobutton(1, 9, i18n("Quit"), options.dwFinish == FINISH_QUIT, m_radioFinishReboot); addButtons(); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelOptions, m_checkSimulateMode, m_checkEraseWithNull, NULL); newtFormAddComponents(m_formMain, m_labelFinish, m_radioFinishWait, m_radioFinishHalt, m_radioFinishReboot, m_radioFinishQuit, NULL); //newtFormAddComponents(m_formMain, m_btnRestore, m_btnExit, NULL); addHotKeys(); newtDrawForm(m_formMain); RETURN_int(0); }
static int newtLicenseBox(const char* title, const char* text, int width, int height) { int ret = 1; newtCenteredWindow(width, height, title); newtComponent form = newtForm(NULL, NULL, 0); newtComponent textbox = newtTextbox(1, 1, width - 2, height - 7, NEWT_FLAG_WRAP|NEWT_FLAG_SCROLL); newtTextboxSetText(textbox, text); newtFormAddComponent(form, textbox); char choice; newtComponent checkbox = newtCheckbox(3, height - 3, _("I accept this license"), ' ', " *", &choice); newtComponent btn = newtButton(width - 15, height - 4, _("OK")); newtFormAddComponents(form, checkbox, btn, NULL); newtComponent answer = newtRunForm(form); if (answer == btn && choice == '*') ret = 0; newtFormDestroy(form); newtPopWindow(); return ret; }
newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault, newtComponent prevButton) { newtComponent co; newtComponent curr; struct checkbox * rb; char initialValue; if (isDefault) initialValue = '*'; else initialValue = ' '; co = newtCheckbox(left, top, text, initialValue, " *", NULL); rb = co->data; rb->type = RADIO; rb->prevButton = prevButton; for (curr = co; curr; curr = rb->prevButton) { rb = curr->data; rb->lastButton = co; } return co; }
// ======================================================= int CSaveOptWindow::create(char *szImageFile, COptions options) { BEGIN; char szTemp[2048]; newtCenteredWindow(78, 20, i18n("save partition to image file")); m_labelCompression = newtLabel(1, 1, i18n("Compression level")); m_radioCompNone = newtRadiobutton(1, 2, i18n("None (very fast + very big file)"), options.dwCompression == COMPRESS_NONE, NULL); m_radioCompGzip = newtRadiobutton(1, 3, "Gzip (.gz: medium speed + small image file)", options.dwCompression == COMPRESS_GZIP, m_radioCompNone); m_radioCompBzip2 = newtRadiobutton(1, 4, "Bzip2 (.bz2: very slow + very small image file)", options.dwCompression == COMPRESS_BZIP2, m_radioCompGzip); m_labelOptions = newtLabel(1, 7, i18n("Options")); m_checkCheckBeforeSaving = newtCheckbox(1, 8, i18n("Check partition before saving"), (!!options.bCheckBeforeSaving ? 'X' : ' '), " X", NULL); m_checkAskDesc = newtCheckbox(1, 9, i18n("Enter description"), (!!options.bAskDesc ? 'X' : ' '), " X", NULL); m_checkOverwrite = newtCheckbox(1, 10, i18n("Overwrite without prompt"), (!!options.bOverwrite ? 'X' : ' '), " X", NULL); m_labelSplit = newtLabel(1, 12, i18n("Image split mode")); m_radioSplitAuto = newtRadiobutton(1, 13, i18n("Automatic split (when no space left)"), !options.qwSplitSize, NULL); m_radioSplitSize = newtRadiobutton(1, 14, i18n("Into files whose size is:............"), !!options.qwSplitSize, m_radioSplitAuto); SNPRINTF(szTemp, "%llu", (!!options.qwSplitSize) ? (options.qwSplitSize/1024/1024) : 2048); m_editSplitSize = newtEntry(43, 14, szTemp, 8, NULL, 0); m_labelSplitSizeKB = newtLabel(52, 14, i18n("MiB")); m_checkSplitWait = newtCheckbox(1, 15, i18n("Wait after each volume change"), (!!options.bSplitWait ? 'X' : ' '), " X", NULL); m_labelFinish = newtLabel(43, 7, i18n("If finished successfully:")); m_radioFinishWait = newtRadiobutton(43, 8, i18n("Wait"), options.dwFinish == FINISH_WAIT, NULL); m_radioFinishHalt = newtRadiobutton(43, 9, i18n("Halt"), options.dwFinish == FINISH_HALT, m_radioFinishWait); m_radioFinishReboot = newtRadiobutton(43, 10, i18n("Reboot"), options.dwFinish == FINISH_REBOOT, m_radioFinishHalt); m_radioFinishQuit = newtRadiobutton(43,11,i18n("Quit"), options.dwFinish == FINISH_QUIT, m_radioFinishReboot); m_radioFinishLast = newtRadiobutton(43,12,i18n("Last"), options.dwFinish == FINISH_LAST, m_radioFinishQuit); addButtons(); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelCompression, m_labelOptions, m_labelSplit, NULL); newtFormAddComponents(m_formMain, m_radioCompNone, m_radioCompGzip, m_radioCompBzip2, m_checkCheckBeforeSaving, m_checkAskDesc, m_checkOverwrite, NULL); newtFormAddComponents(m_formMain, m_labelFinish, m_radioFinishWait, m_radioFinishHalt, m_radioFinishReboot, m_radioFinishQuit, m_radioFinishLast, NULL); newtFormAddComponents(m_formMain, m_radioSplitAuto, m_radioSplitSize, m_labelSplitSizeKB, m_editSplitSize, m_checkSplitWait, NULL); addHotKeys(); newtDrawForm(m_formMain); RETURN_int(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 int newtChecklist(const char* title, const char* message, unsigned int width, unsigned int height, unsigned int num_entries, const char** entries, int* states) { int ret; const int list_height = 4; char cbstates[num_entries]; for (unsigned int i = 0; i < num_entries; i++) { cbstates[i] = states[i] ? '*' : ' '; } newtCenteredWindow(width, height, title); newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6 - list_height, NEWT_FLAG_WRAP); newtTextboxSetText(textbox, message); int top = newtTextboxGetNumLines(textbox) + 2; newtComponent form = newtForm(NULL, NULL, 0); newtComponent sb = NULL; if (list_height < num_entries) { sb = newtVerticalScrollbar( width - 4, top + 1, list_height, NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX); newtFormAddComponent(form, sb); } newtComponent subform = newtForm(sb, NULL, 0); newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX); newtFormSetHeight(subform, list_height); newtFormSetWidth(subform, width - 10); for (unsigned int i = 0; i < num_entries; i++) { newtComponent cb = newtCheckbox(4, top + i, entries[i], cbstates[i], NULL, &cbstates[i]); newtFormAddComponent(subform, cb); } newtFormAddComponents(form, textbox, subform, NULL); newtComponent btn_okay = newtButton((width - 18) / 3, height - 4, _("OK")); newtComponent btn_cancel = newtButton((width - 18) / 3 * 2 + 9, height - 4, _("Cancel")); newtFormAddComponents(form, btn_okay, btn_cancel, NULL); newtComponent answer = newtRunForm(form); if ((answer == NULL) || (answer == btn_cancel)) { ret = -1; } else { ret = 0; for (unsigned int i = 0; i < num_entries; i++) { states[i] = (cbstates[i] != ' '); if (states[i]) ret++; } } newtFormDestroy(form); newtPopWindow(); return ret; }
int checkList(const char * text, int height, int width, poptContext optCon, int useRadio, int flags, char *** selections) { newtComponent form, okay, tb, subform, answer; newtComponent sb = NULL, cancel = NULL; const char * arg; char * end; int listHeight; int numBoxes = 0; int allocedBoxes = 5; int i; int numSelected; int rc = DLG_OKAY; char buf[80], format[20]; int maxWidth = 0; int top; struct { const char * text; const char * tag; newtComponent comp; } * cbInfo = malloc(allocedBoxes * sizeof(*cbInfo)); char * cbStates = malloc(allocedBoxes * sizeof(cbStates)); if (!(arg = poptGetArg(optCon))) return DLG_ERROR; listHeight = strtoul(arg, &end, 10); if (*end) return DLG_ERROR; while ((arg = poptGetArg(optCon))) { if (allocedBoxes == numBoxes) { allocedBoxes += 5; cbInfo = realloc(cbInfo, sizeof(*cbInfo) * allocedBoxes); cbStates = realloc(cbStates, sizeof(*cbStates) * allocedBoxes); } cbInfo[numBoxes].tag = arg; if (!(arg = poptGetArg(optCon))) return DLG_ERROR; if (!(flags & FLAG_NOITEM)) { cbInfo[numBoxes].text = arg; if (!(arg = poptGetArg(optCon))) return DLG_ERROR; } else cbInfo[numBoxes].text = ""; if (!strcmp(arg, "1") || !strcasecmp(arg, "on") || !strcasecmp(arg, "yes")) cbStates[numBoxes] = '*'; else cbStates[numBoxes] = ' '; if (wstrlen(cbInfo[numBoxes].tag,-1) > (unsigned int)maxWidth) maxWidth = wstrlen(cbInfo[numBoxes].tag,-1); numBoxes++; } form = newtForm(NULL, NULL, 0); tb = textbox(height - 3 - buttonHeight - listHeight, width - 2, text, flags, &top); if (listHeight < numBoxes) { sb = newtVerticalScrollbar(width - 4, top + 1, listHeight, NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX); newtFormAddComponent(form, sb); } subform = newtForm(sb, NULL, 0); newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX); sprintf(format, "%%-%ds %%s", maxWidth); for (i = 0; i < numBoxes; i++) { sprintf(buf, format, cbInfo[i].tag, cbInfo[i].text); if (useRadio) cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf, cbStates[i] != ' ', i ? cbInfo[i - 1].comp : NULL); else cbInfo[i].comp = newtCheckbox(4, top + 1 + i, buf, cbStates[i], NULL, cbStates + i); newtFormAddComponent(subform, cbInfo[i].comp); } newtFormSetHeight(subform, listHeight); newtFormSetWidth(subform, width - 10); newtFormAddComponents(form, tb, subform, NULL); addButtons(height, width, form, &okay, &cancel, flags); answer = newtRunForm(form); if (answer == cancel) rc = DLG_CANCEL; if (useRadio) { answer = newtRadioGetCurrent(cbInfo[0].comp); for (i = 0; i < numBoxes; i++) if (cbInfo[i].comp == answer) { *selections = malloc(sizeof(char *) * 2); (*selections)[0] = cbInfo[i].tag; (*selections)[1] = NULL; break; } } else { numSelected = 0; for (i = 0; i < numBoxes; i++) { if (cbStates[i] != ' ') numSelected++; } *selections = malloc(sizeof(char *) * (numSelected + 1)); numSelected = 0; for (i = 0; i < numBoxes; i++) { if (cbStates[i] != ' ') (*selections)[numSelected++] = cbInfo[i].tag; } (*selections)[numSelected] = NULL; } return rc; }
int handledhcp(void) { char *results[MAX_BOXES]; char enabledresult; char startenabled; struct newtExitStruct es; newtComponent header; newtComponent labels[MAX_BOXES]; newtComponent ok, cancel; char message[1000]; char *labeltexts[MAX_BOXES] = { _("Start address:"), _("End address:"), _("Primary DNS:"), _("Secondary DNS:"), _("Default lease (mins):"), _("Max lease (mins):"), _("Domain name suffix:") }; char *varnames[MAX_BOXES] = { "START_ADDR_GREEN", "END_ADDR_GREEN", "DNS1_GREEN", "DNS2_GREEN", "DEFAULT_LEASE_TIME_GREEN", "MAX_LEASE_TIME_GREEN", "DOMAIN_NAME_GREEN" }; char defaults[MAX_BOXES][STRING_SIZE]; int result; int c; char temp[STRING_SIZE]; struct keyvalue *mainkv = initkeyvalues(); struct keyvalue *dhcpkv = initkeyvalues(); struct keyvalue *ethernetkv = initkeyvalues(); int error; FILE *file; char greenaddress[STRING_SIZE]; char greennetaddress[STRING_SIZE]; char greennetmask[STRING_SIZE]; memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES); if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } /* Set default values. */ findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]); findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]); strcpy(defaults[DEFAULT_LEASE_TIME], "60"); strcpy(defaults[MAX_LEASE_TIME], "120"); newtCenteredWindow(55, 18, _("DHCP server configuration")); dhcpform = newtForm(NULL, NULL, 0); header = newtTextboxReflowed(1, 1, _("Configure the DHCP server by entering the settings information."), 52, 0, 0, 0); newtFormAddComponent(dhcpform, header); strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp); if (strcmp(temp, "on") == 0) startenabled = '*'; else startenabled = ' '; enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult); newtFormAddComponent(dhcpform, enabledcheckbox); newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL); for (c = 0; c < MAX_BOXES; c++) { labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0); newtTextboxSetText(labels[c], labeltexts[c]); newtFormAddComponent(dhcpform, labels[c]); strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp); entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0); newtFormAddComponent(dhcpform, entries[c]); if (startenabled == ' ') newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); } ok = newtButton(10, c + 7, _("OK")); cancel = newtButton(34, c + 7, _("Cancel")); newtFormAddComponents(dhcpform, ok, cancel, NULL); do { error = 0; newtFormRun(dhcpform, &es); if (es.u.co == ok) { /* OK was pressed; verify the contents of each entry. */ if (enabledresult == '*') { strcpy(message, _("The following fields are invalid:\n\n")); if (inet_addr(results[START_ADDRESS]) == INADDR_NONE) { strcat(message, _("Start address")); strcat(message, "\n"); error = 1; } if (inet_addr(results[END_ADDRESS]) == INADDR_NONE) { strcat(message, _("End address")); strcat(message, "\n"); error = 1; } if (strlen(results[SECONDARY_DNS])) { if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE) { strcat(message, _("Primary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(results[SECONDARY_DNS])) { if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE) { strcat(message, _("Secondary DNS")); strcat(message, "\n"); error = 1; } } if (!(atol(results[DEFAULT_LEASE_TIME]))) { strcat(message, _("Default lease time")); strcat(message, "\n"); error = 1; } if (!(atol(results[MAX_LEASE_TIME]))) { strcat(message, _("Max. lease time")); strcat(message, "\n"); error = 1; } } if (error) errorbox(message); else { for (c = 0; c < MAX_BOXES; c++) replacekeyvalue(dhcpkv, varnames[c], results[c]); if (enabledresult == '*') { replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on"); fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w")); chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99); mysystem(NULL, "/usr/local/bin/dhcpctrl enable"); } else { replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off"); unlink(CONFIG_ROOT "/dhcp/enable_green"); mysystem(NULL, "/usr/local/bin/dhcpctrl disable"); } replacekeyvalue(dhcpkv, "VALID", "yes"); writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings"); findkey(ethernetkv, "GREEN_ADDRESS", greenaddress); findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress); findkey(ethernetkv, "GREEN_NETMASK", greennetmask); file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w"); fprintf(file, "ddns-update-style none;\n"); fprintf(file, "authoritative;\n"); fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask); fprintf(file, "{\n"); fprintf(file, "\toption subnet-mask %s;\n", greennetmask); fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]); fprintf(file, "\toption routers %s;\n", greenaddress); if (strlen(results[PRIMARY_DNS])) { fprintf(file, "\toption domain-name-servers "); fprintf(file, "%s", results[PRIMARY_DNS]); if (strlen(results[SECONDARY_DNS])) fprintf(file, ", %s", results[SECONDARY_DNS]); fprintf(file, ";\n"); } fprintf(file, "\trange %s %s;\n", results[START_ADDRESS], results[END_ADDRESS]); fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60); fprintf(file, "\tmax-lease-time %d;\n", (int) atol(results[MAX_LEASE_TIME]) * 60); fprintf(file, "}\n"); fclose(file); chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); if (automode == 0) mysystem(NULL, "/usr/local/bin/dhcpctrl enable"); } result = 1; } else result = 0; } while (error); newtFormDestroy(dhcpform); newtPopWindow(); freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); freekeyvalues(mainkv); return result; }
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; }
// ======================================================= int CInterfaceNewt::guiInitMainWindow(char *szDevice, char *szImageFile, char *szNetworkIP, DWORD *dwServerPort, bool *bSsl) { newtComponent formMain, btnContinue, btnExit, btnAbout; newtComponent labelPartition, labelImage, editPartition, editImage, btnImage; newtComponent widgetTemp, labelAction, radioSave, radioRestore, radioMbr; newtComponent checkNetwork, labelNetwork, labelPort, editNetwork, editPort, checkSsl; newtExitStruct event; char szTemp[1024]; int nAction; int nRes; showDebug(8, "guiInitMainWindow\n"); SNPRINTF(szTemp, "Partition Image %s", PACKAGE_VERSION); newtCenteredWindow(67, 20, szTemp); labelPartition = newtLabel(1, 0, i18n("* Partition to save/restore")); editPartition = newtListbox(3, 1, 7, NEWT_FLAG_SCROLL); labelImage = newtLabel(1, 9, i18n("* Image file to create/use")); editImage = newtEntry(3, 10, szImageFile, 59, NULL, NEWT_FLAG_SCROLL); btnImage = newtCompactButton(62, 10, "*"); labelAction = newtLabel(1, 12, i18n("Action to be done:")); radioSave = newtRadiobutton(1, 13, i18n("Save partition into a new image file"), true, NULL); radioRestore = newtRadiobutton(1, 14, i18n("Restore partition from an image file"), false, radioSave); radioMbr = newtRadiobutton(1, 15, i18n("Restore an MBR from the image file"), false, radioRestore); checkNetwork = newtCheckbox(1, 17, i18n("Connect to server"), (!!(*szNetworkIP) ? 'X' : ' '), " X", NULL); #ifdef HAVE_SSL checkSsl = newtCheckbox(5, 19, i18n("Encrypt data on the network with SSL"), (*bSsl ? 'X' : ' '), " X", NULL); #else #ifdef MUST_LOGIN checkSsl = newtLabel(5, 19,i18n("SSL disabled at compile time")); #else checkSsl = newtLabel(5, 19,i18n("SSL&login disabled at compile time")); #endif #endif labelNetwork = newtLabel(5, 18, i18n("IP/name of the server:")); editNetwork = newtEntry(28, 18, szNetworkIP, 25, NULL, 0); labelPort = newtLabel(54, 18, i18n("Port:")); SNPRINTF(szTemp, "%u", *dwServerPort); editPort = newtEntry(60, 18, szTemp, 6, NULL, 0); btnContinue = newtCompactButton(50, 12, i18n("Next (F5)")); btnAbout = newtCompactButton(50, 14, i18n("About")); btnExit = newtCompactButton(50, 16, i18n("Exit (F6)")); nRes = fillPartitionList(editPartition); if (nRes == -1) RETURN_int(-1); formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(formMain, labelPartition, labelImage, editPartition, editImage, btnImage, labelAction, radioSave, radioRestore, radioMbr, checkNetwork, labelNetwork, editNetwork, labelPort, editPort, checkSsl, btnContinue, btnAbout, btnExit, NULL); newtFormAddHotKey(formMain, KEY_EXIT); // Exit newtFormAddHotKey(formMain, KEY_OKAY); // Okay begin: /*widgetTemp = */newtFormRun(formMain, &event); widgetTemp = newtFormGetCurrent(formMain); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_EXIT)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnExit))) //if(widgetTemp == btnExit) return OPERATION_EXIT; if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnAbout)) { showAboutDialog(); goto begin; } if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnImage)) { char *fs_; fs_=filesel(newtEntryGetValue(editImage)); if(fs_) { newtEntrySet(editImage, fs_, 1); // free(fs_); } goto begin; } if (strcmp(newtEntryGetValue(editImage), "") == 0) // if "image" field empty { msgBoxError(i18n("The \"Image\" field is empty. Cannot continue")); goto begin; } if (newtCheckboxGetValue(checkNetwork) == 'X') { if (!(*newtEntryGetValue(editNetwork))) { msgBoxError(i18n("The \"Server IP/Name\" field is empty. Cannot continue")); goto begin; } if (!atoi((char*)newtEntryGetValue(editPort))) { msgBoxError(i18n("The \"Server Port\" field is not a valid integer. Cannot continue")); goto begin; } } // get device strcpy(szDevice, (char*)newtListboxGetCurrent(editPartition)); // image file strcpy(szImageFile, newtEntryGetValue(editImage)); // network if (newtCheckboxGetValue(checkNetwork) == 'X') // If network is activated { strcpy(szNetworkIP, (char*)newtEntryGetValue(editNetwork)); *dwServerPort = atoi((char*)newtEntryGetValue(editPort)); #ifdef HAVE_SSL *bSsl = (newtCheckboxGetValue(checkSsl) == 'X'); #endif } else // no network { *szNetworkIP = 0; *dwServerPort = OPTIONS_DEFAULT_SERVERPORT; } nAction = 0; if (newtRadioGetCurrent(radioRestore) == radioSave) { nAction = OPERATION_SAVE; } else if (newtRadioGetCurrent(radioRestore) == radioRestore) { nAction = OPERATION_RESTORE; } else if (newtRadioGetCurrent(radioRestore) == radioMbr) { nAction = OPERATION_RESTMBR; } newtFormDestroy(formMain); newtPopWindow(); return nAction; }
int main(void) { newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale; newtComponent lb, t, rsf, answer, timeLabel; newtComponent cs[10]; newtComponent f, chklist, e1; struct callbackInfo cbis[3]; char results[10]; char * enr2, * enr3, * scaleVal; void ** selectedList; int i, numsel; char buf[20]; const char * spinner = "-\\|/\\|/"; const char * spinState; struct newtExitStruct es; newtInit(); newtCls(); newtSetSuspendCallback(suspend, NULL); newtSetHelpCallback(helpCallback); newtDrawRootText(0, 0, "Newt test program"); newtPushHelpLine(NULL); newtDrawRootText(-50, 0, "More root text"); newtOpenWindow(2, 2, 30, 10, "first window"); newtOpenWindow(10, 5, 65, 16, "window 2"); f = newtForm(NULL, "This is some help text", 0); chklist = newtForm(NULL, NULL, 0); b1 = newtButton(3, 1, "Exit"); b2 = newtButton(18, 1, "Update"); r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL); r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1); r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2); rsf = newtForm(NULL, NULL, 0); newtFormAddComponents(rsf, r1, r2, r3, NULL); newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX); for (i = 0; i < 10; i++) { sprintf(buf, "Check %d", i); cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]); newtFormAddComponent(chklist, cs[i]); } l1 = newtLabel(3, 6, "Scale:"); l2 = newtLabel(3, 7, "Scrolls:"); l3 = newtLabel(3, 8, "Hidden:"); e1 = newtEntry(12, 6, "", 20, &scaleVal, 0); e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL); /* e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */ e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD); cbis[0].state = &results[0]; cbis[0].en = e1; newtComponentAddCallback(cs[0], disableCallback, &cbis[0]); scale = newtScale(3, 14, 32, 100); newtFormSetHeight(chklist, 3); newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL); newtFormAddComponents(f, rsf, scale, NULL); lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER | NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR); newtListboxAppendEntry(lb, "First", (void *) 1); newtListboxAppendEntry(lb, "Second", (void *) 2); newtListboxAppendEntry(lb, "Third", (void *) 3); newtListboxAppendEntry(lb, "Fourth", (void *) 4); newtListboxAppendEntry(lb, "Sixth", (void *) 6); newtListboxAppendEntry(lb, "Seventh", (void *) 7); newtListboxAppendEntry(lb, "Eighth", (void *) 8); newtListboxAppendEntry(lb, "Ninth", (void *) 9); newtListboxAppendEntry(lb, "Tenth", (void *) 10); newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4); newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10); newtListboxDeleteEntry(lb, (void *) 11); spinState = spinner; timeLabel = newtLabel(45, 8, "Spinner: -"); t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP); newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed"); newtFormAddComponents(f, lb, timeLabel, t, NULL); newtRefresh(); newtFormSetTimer(f, 200); do { newtFormRun(f, &es); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) { newtScaleSet(scale, atoi(scaleVal)); newtRefresh(); answer = NULL; } else if (es.reason == NEWT_EXIT_TIMER) { spinState++; if (!*spinState) spinState = spinner; sprintf(buf, "Spinner: %c", *spinState); newtLabelSetText(timeLabel, buf); } } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2); scaleVal = strdup(scaleVal); enr2 = strdup(enr2); enr3 = strdup(enr3); selectedList = newtListboxGetSelection(lb, &numsel); newtFormDestroy(f); newtPopWindow(); newtPopWindow(); newtFinished(); printf("got string 1: %s\n", scaleVal); printf("got string 2: %s\n", enr2); printf("got string 3: %s\n", enr3); if(selectedList) { printf("\nSelected listbox items:\n"); for(i = 0; i < numsel; i++) puts(selectedList[i]); } return 0; }
int main(void){ newtComponent hForm, button1, button2; newtComponent astIpLabel, astPortLabel, astUserLabel, astPassLabel; newtComponent astIpEntry, astPortEntry, astUserEntry, astPassEntry; const char *astIpVal, *astPortVal, *astUserVal, *astPassVal; newtComponent humbugHostLabel, humbugPortLabel, humbugApiLabel; newtComponent humbugHostEntry, humbugPortEntry, humbugApiEntry; const char *humbugHostVal, *humbugPortVal, *humbugApiVal; int i, y; newtComponent eventsLabel, eventsChk[EVENTS_SIZE], chkList; newtComponent encChk, encLabel, encEntry, chkLog; char encVal, logVal; const char *encKey; char eventsList[EVENTS_SIZE][16]; char eventsResults[EVENTS_SIZE]; strcpy(eventsList[0], "CDR"); strcpy(eventsList[1], "NewExten"); strcpy(eventsList[2], "Reload"); strcpy(eventsList[3], "Shutdown"); strcpy(eventsList[4], "Alarm"); strcpy(eventsList[5], "AlarmClear"); strcpy(eventsList[6], "CollectorAlarm"); struct newtExitStruct es; params = (parameters*) calloc(1, sizeof(parameters)); if(readHumbugConfig() < 0) { exit(EXIT_FAILURE); } newtInit(); newtCls(); newtDrawRootText(1, 0, "Text Mode Setup for humbug-collector (c) 2011 Humbug Telecom Labs, Ltd."); newtPushHelpLine(" <Tab>/<Alt-Tab> between elements | <ESC> exits without save | <F12> for help"); newtCenteredWindow(66, 17, "Humbug Setup"); astIpLabel = newtLabel(1, 1, " Manager IP:"); astIpEntry = newtEntry(19, 1, params->astIpVal, 20, &astIpVal, 0); astPortLabel = newtLabel(1, 2, " Manager Port:"); astPortEntry = newtEntry(19, 2, params->astPortVal, 20, &astPortVal, 0); astUserLabel = newtLabel(1, 3, "Manager Username:"******"Manager Password:"******" Humbug Host:"); humbugHostEntry = newtEntry(19, 6, params->humbugHost, 20, &humbugHostVal, 0); humbugPortLabel = newtLabel(1, 7, " Humbug Port:"); humbugPortEntry = newtEntry(19, 7, params->humbugPort, 20, &humbugPortVal, 0); humbugApiLabel = newtLabel(1, 8, " Humbug API key:"); humbugApiEntry = newtEntry(19, 8, params->humbugApikey, 20, &humbugApiVal, NEWT_FLAG_SCROLL); if(1 == params->encrypted){ encChk = newtCheckbox(19, 10, "Encrypted", 'X', " X", &encVal); }else{ encChk = newtCheckbox(19, 10, "Encrypted", ' ', " X", &encVal); } encLabel = newtLabel(1, 11, " Encryption key:"); encEntry = newtEntry(19, 11, params->humbugKey, 42, &encKey, NEWT_FLAG_SCROLL); if(strlen(params->log_file) > 0 ){ chkLog = newtCheckbox(19, 13, "Log ON/OFF", 'X', " X", &logVal); }else{ chkLog = newtCheckbox(19, 13, "Log ON/OFF", ' ', " X", &logVal); } eventsLabel = newtLabel(42, 1, "Events for analyze:"); button1 = newtButton(36, 13, "Save & Exit"); button2 = newtButton(53, 13, "Quit"); chkList = newtForm(NULL, NULL, 0); newtFormSetBackground(chkList, NEWT_COLORSET_CHECKBOX); for(i=0; i<EVENTS_SIZE; i++) { int selected = 0; for(y=0; y<params->eventsSize; y++){ if(0 == strcasecmp(eventsList[i], params->events[y])){ selected = 1; break; } } if (1 == selected) { eventsChk[i] = newtCheckbox(47, 2 + i, eventsList[i], 'X', " X", &eventsResults[i]); } else { eventsChk[i] = newtCheckbox(47, 2 + i, eventsList[i], ' ', " X", &eventsResults[i]); } newtFormAddComponent(chkList, eventsChk[i]); } hForm = newtForm(NULL, NULL, 0); newtFormAddComponents(hForm, button1, button2, astIpLabel, astPortLabel, astUserLabel, astPassLabel, astIpEntry, astPortEntry, astUserEntry, astPassEntry, humbugHostLabel, humbugPortLabel, humbugApiLabel, humbugHostEntry, humbugPortEntry, humbugApiEntry, eventsLabel, chkList, encChk, encLabel, encEntry, chkLog, NULL); for(;;){ do{ newtFormRun(hForm, &es); }while(es.reason == NEWT_EXIT_TIMER); if (es.reason == NEWT_EXIT_HOTKEY) { int done = 0; switch (es.u.key) { case NEWT_KEY_ESCAPE: done = 1; break; case NEWT_KEY_F12: show_help(); break; } if(done) break; }else if (es.reason == NEWT_EXIT_COMPONENT) { if(es.u.co == button1){ strcpy(params->astIpVal, astIpVal); strcpy(params->astPortVal, astPortVal); strcpy(params->astUserVal, astUserVal); strcpy(params->astPassVal, astPassVal); strcpy(params->humbugApikey, humbugApiVal); params->eventsSize = 0; for(i=0; i<EVENTS_SIZE; i++) { if(eventsResults[i] == 'X') { strcpy(params->events[params->eventsSize], eventsList[i]); params->eventsSize++; } } params->encrypted = (encVal == 'X') ? 1 : 0; strcpy(params->humbugKey, encKey); strcpy(params->log_file, HBG_LOG_FILE); saveHumbugConfig(); } break; } } newtPopWindow(); newtPopHelpLine(); newtFinished(); newtFormDestroy(hForm); free(params); return(EXIT_SUCCESS); }