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; }
static int get_user_input(char *msg, char *buf, int buflen) { newtComponent form; newtComponent ok; newtComponent cancel; newtComponent inpfield; const char *input; int res = -1; struct newtExitStruct es; newtCenteredWindow(60,7, msg); inpfield = newtEntry(5, 2, "", 50, _NEWT_CAST &input, 0); ok = newtButton(22, 3, "OK"); cancel = newtButton(32, 3, "Cancel"); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, inpfield, ok, cancel, NULL); newtFormRun(form, &es); strncpy(buf, input, buflen - 1); if (es.u.co == ok) res = 0; else res = -1; newtPopWindow(); newtFormDestroy(form); return res; }
static void do_loop(int span, int looped) { newtComponent form; newtComponent label; char s1[256]; struct dahdi_maintinfo m; int res; struct newtExitStruct es; newtOpenWindow(20,12,40,4, s[span].desc); form = newtForm(NULL, NULL, 0); m.spanno = span; if (looped) { snprintf(s1, sizeof(s1), "Looping UP span %d...\n", span); m.command = DAHDI_MAINT_LOOPUP; } else { snprintf(s1, sizeof(s1), "Looping DOWN span %d...\n", span); m.command = DAHDI_MAINT_LOOPDOWN; } label = newtLabel(3,1,s1); newtFormAddComponent(form, label); newtPushHelpLine("Please wait..."); newtFormSetTimer(form, 200); newtFormRun(form, &es); res = ioctl(ctl, DAHDI_MAINT, &m); newtFormDestroy(form); newtPopWindow(); newtPopHelpLine(); }
int ui__popup_menu(int argc, char * const argv[]) { struct newtExitStruct es; int i, rc = -1, max_len = 5; newtComponent listbox, form = newt_form__new(); if (form == NULL) return -1; listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); if (listbox == NULL) goto out_destroy_form; newtFormAddComponent(form, listbox); for (i = 0; i < argc; ++i) { int len = strlen(argv[i]); if (len > max_len) max_len = len; if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) goto out_destroy_form; } newtCenteredWindow(max_len, argc, NULL); newtFormRun(form, &es); rc = newtListboxGetCurrent(listbox) - NULL; if (es.reason == NEWT_EXIT_HOTKEY) rc = -1; newtPopWindow(); out_destroy_form: newtFormDestroy(form); return rc; }
int ui_browser__show(struct ui_browser *self, const char *title, const char *helpline, ...) { va_list ap; if (self->form != NULL) { newtFormDestroy(self->form); newtPopWindow(); } ui_browser__refresh_dimensions(self); newtCenteredWindow(self->width, self->height, title); self->form = newt_form__new(); if (self->form == NULL) return -1; self->sb = newtVerticalScrollbar(self->width, 0, self->height, HE_COLORSET_NORMAL, HE_COLORSET_SELECTED); if (self->sb == NULL) return -1; newtFormAddHotKey(self->form, NEWT_KEY_UP); newtFormAddHotKey(self->form, NEWT_KEY_DOWN); newtFormAddHotKey(self->form, NEWT_KEY_PGUP); newtFormAddHotKey(self->form, NEWT_KEY_PGDN); newtFormAddHotKey(self->form, NEWT_KEY_HOME); newtFormAddHotKey(self->form, NEWT_KEY_END); newtFormAddHotKey(self->form, ' '); newtFormAddComponent(self->form, self->sb); va_start(ap, helpline); ui_helpline__vpush(helpline, ap); va_end(ap); return 0; }
void ui_browser__hide(struct ui_browser *self) { newtFormDestroy(self->form); newtPopWindow(); self->form = NULL; ui_helpline__pop(); }
int do_dict() { newtComponent form, label, entry, text; struct newtExitStruct es; char *entryValue, *wordlist; newtCenteredWindow(70, 20, NULL); newtPushHelpLine("输入要查找的词,回车确定,上下键滚动,^C退出"); label = newtLabel(2, 1, "请输入要查找的词"); entry = newtEntry(2, 2, "", 40, &entryValue, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); text = newtTextbox(2, 3, 66, 17, NEWT_FLAG_WRAP | NEWT_FLAG_SCROLL); newtTextboxSetText(text, ""); form = newtForm(NULL, NULL, 0); newtFormAddHotKey(form, Ctrl('c')); newtFormAddHotKey(form, Ctrl('\r')); newtFormAddHotKey(form, Ctrl('\n')); newtFormAddComponents(form, label, entry, text, NULL); while (1) { newtFormRun(form, &es); if ((es.u.key == Ctrl('c') || es.u.key == NEWT_KEY_F12) && es.reason == NEWT_EXIT_HOTKEY) break; wordlist = search_dict(entryValue); newtTextboxSetText(text, wordlist); } newtFormDestroy(form); newtPopHelpLine(); newtPopWindow(); return 0; }
static int ui_entry__read(const char *title, char *bf, size_t size, int width) { struct newtExitStruct es; newtComponent form, entry; const char *result; int err = -1; newtCenteredWindow(width, 1, title); form = newtForm(NULL, NULL, 0); if (form == NULL) return -1; entry = newtEntry(0, 0, "0x", width, &result, NEWT_FLAG_SCROLL); if (entry == NULL) goto out_free_form; newtFormAddComponent(form, entry); newtFormAddHotKey(form, NEWT_KEY_ENTER); newtFormAddHotKey(form, NEWT_KEY_ESCAPE); newtFormAddHotKey(form, NEWT_KEY_LEFT); newtFormAddHotKey(form, CTRL('c')); newtFormRun(form, &es); if (result != NULL) { strncpy(bf, result, size); err = 0; } out_free_form: newtPopWindow(); newtFormDestroy(form); return err; }
// ======================================================= void COptionsWindow::destroyForm() { BEGIN; newtFormDestroy(m_formMain); newtPopWindow(); RETURN; }
static int newtWinOkCancel(const char* title, const char* message, int width, int height, const char* btn_txt_ok, const char* btn_txt_cancel) { int ret = 1; unsigned int btn_width_ok = strlen(btn_txt_ok); unsigned int btn_width_cancel = strlen(btn_txt_cancel); // Maybe make the box wider to fix both buttons inside unsigned int min_width = btn_width_ok + btn_width_cancel + 5; if (width < min_width) width = min_width; unsigned int btn_pos_ok = (width / 3) - (btn_width_ok / 2) - 1; unsigned int btn_pos_cancel = (width * 2 / 3) - (btn_width_cancel / 2) - 1; // Move buttons a bit if they overlap while ((btn_pos_ok + btn_width_ok + 5) > btn_pos_cancel) { // Move the cancel button to the right if there is enough space left if ((btn_pos_cancel + btn_width_cancel + 2) < width) { ++btn_pos_cancel; continue; } // Move the OK button to the left if possible if (btn_pos_ok > 1) { --btn_pos_ok; continue; } // If they still overlap, we cannot fix the situtation // and break. Should actually never get here, because we // adjust the width of the window earlier. break; } newtCenteredWindow(width, height, title); newtComponent form = newtForm(NULL, NULL, 0); newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6, NEWT_FLAG_WRAP); newtTextboxSetText(textbox, message); newtFormAddComponent(form, textbox); newtComponent btn_ok = newtButton(btn_pos_ok, height - 4, btn_txt_ok); newtComponent btn_cancel = newtButton(btn_pos_cancel, height - 4, btn_txt_cancel); newtFormAddComponents(form, btn_ok, btn_cancel, NULL); newtComponent answer = newtRunForm(form); if (answer == btn_ok) { ret = 0; } newtFormDestroy(form); newtPopWindow(); return ret; }
void ui_progress__delete(struct ui_progress *self) { if (use_browser > 0) { newtFormDestroy(self->form); newtPopWindow(); } free(self); }
void end_progression_raw_newt(void) { if (size_progress) { newtPopWindow(); newtFormDestroy(form); } else remove_wait_message(); }
// ======================================================= int CInterfaceNewt::askLogin(char *szLogin, char *szPasswd, WORD size) { newtComponent editLoginText; newtComponent editPasswdText; newtComponent labelLoginText; newtComponent labelPasswdText; newtComponent form; newtComponent btnOk; newtComponent btnCancel; newtComponent temp; int nOk = 0; while (!nOk) { newtCenteredWindow(65, 20, i18n("Password required")); labelLoginText = newtTextbox(1, 5, 60, 1, 0); newtTextboxSetText(labelLoginText, i18n("Enter your login")); editLoginText = newtEntry(1, 6, "", 55, NULL, NEWT_ENTRY_SCROLL); labelPasswdText = newtTextbox(1, 9, 60, 1, 0); newtTextboxSetText(labelPasswdText, i18n("Enter your password")); editPasswdText = newtEntry(1, 10, "", 55, NULL, NEWT_FLAG_HIDDEN); btnOk = newtButton(15, 14, i18n("Ok")); btnCancel = newtButton(40, 14, i18n("Cancel")); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, labelLoginText, editLoginText, labelPasswdText, editPasswdText, btnOk, btnCancel, NULL); temp = newtRunForm(form); newtPopWindow(); if (temp == btnCancel) { newtFormDestroy(form); RETURN_int(-1); } strncpy(szLogin, newtEntryGetValue(editLoginText), size-1); *(szLogin+size-1) = '\0'; strncpy(szPasswd, newtEntryGetValue(editPasswdText), size-1); *(szPasswd+size-1) = '\0'; if (!(*szLogin) || !(*szPasswd)) msgBoxError(i18n("Text cannot be empty")); else nOk = 1; newtFormDestroy(form); } return 0; }
int urlinstFinishTransfer(struct iurlinfo * ui, int fd) { if (ui->protocol == URL_METHOD_FTP) close(ui->ftpPort); close(fd); if (!FL_CMDLINE(flags)) newtPopWindow(); return 0; }
// ============================================================================ unsigned int CExceptionsGUI::windowError(char *szTitle, char *szText, char *szButton, char *szCurPath) { BEGIN; //char szTemp[] = "/tmp/image"; unsigned int nRes; newtComponent btnOther; newtComponent formMain = newtForm(NULL, NULL, 0); if (szButton) btnOther = newtButton(30, 15, szButton); else btnOther = newtButton(30, 15, "(none)"); newtComponent btnOk = newtButton(10, 15, i18n("Change")); newtComponent btnCancel = newtButton(50, 15, i18n("Cancel")); newtComponent editFilename = newtEntry(5, 10, szCurPath, 45, NULL, 0); newtComponent labelFilename = newtLabel(5, 9, i18n("Enter new filename")); newtComponent labelText = newtTextbox(1, 1, 60, 7, 0); newtTextboxSetText(labelText, szText); newtComponent widgetTemp; newtCenteredWindow(67, 20, szTitle); if (szButton) newtFormAddComponents(formMain, editFilename, btnOk, btnOther, btnCancel, labelFilename, labelText, NULL); else newtFormAddComponents(formMain, editFilename, btnOk, btnCancel, labelFilename, labelText, NULL); widgetTemp = newtRunForm(formMain); if (widgetTemp == btnCancel) nRes = ERR_QUIT; else if (szButton && widgetTemp == btnOther) nRes = ERR_CONT; else { strncpy(szNewString, newtEntryGetValue(editFilename), 1023); *(szNewString+1023) = '\0'; while (szNewString[strlen(szNewString)-1] == '/') szNewString[strlen(szNewString)-1] = '\0'; nRes = ERR_RETRY; } newtFormDestroy(formMain); newtPopWindow(); RETURN_WORD(nRes); }
/* 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; }
/** * Ask the user how much compression they would like to use. * The choices are "None" (0), "Minimum" (1), "Average" (4), and "Maximum" (9). * @return The compression level (0-9) chosen, or -1 for "Exit". */ int which_compression_level() { /*@ char ************************************************************ */ int output = none; /*@ newt ************************************************************ */ newtComponent b1; newtComponent b2; newtComponent b3; newtComponent b4; newtComponent b5; newtComponent b_res; newtComponent myForm; newtDrawRootText(18, 0, WELCOME_STRING); newtPushHelpLine (_(" Please specify the level of compression that you want.")); // newtOpenWindow (23, 3, 34, 13, "How much compression?"); newtCenteredWindow(34, 13, _("How much compression?")); b1 = newtButton(4, 1, _("Maximum")); b2 = newtButton(18, 1, _("Average")); b3 = newtButton(4, 5, _("Minimum")); b4 = newtButton(18, 5, _(" None ")); b5 = newtButton(4, 9, _(" Exit ")); myForm = newtForm(NULL, NULL, 0); newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL); b_res = newtRunForm(myForm); newtFormDestroy(myForm); newtPopWindow(); if (b_res == b1) { output = 9; } else if (b_res == b2) { output = 4; } else if (b_res == b3) { output = 1; } else if (b_res == b4) { output = 0; } else if (b_res == b5) { output = -1; } newtPopHelpLine(); return (output); }
static int show_message(char *title, char *msg) { newtComponent form; newtComponent label; newtComponent ok; struct newtExitStruct es; newtCenteredWindow(60,7, title); label = newtLabel(4,1,msg); ok = newtButton(27, 3, "OK"); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, label, ok, NULL); newtFormRun(form, &es); newtPopWindow(); newtFormDestroy(form); return 0; }
// ======================================================= int CInterfaceNewt::askText(char *szMessage, char *szTitle, char *szDestText, WORD size) { newtComponent editText; newtComponent labelText; newtComponent form; newtComponent btnOk; newtComponent btnCancel; newtComponent temp; *szDestText = 0; while (!*szDestText) { newtCenteredWindow(65, 20, szTitle); labelText = newtTextbox(1, 1, 60, 7, 0/*NEWT_TEXTBOX_SCROLL*/); newtTextboxSetText(labelText, szMessage); editText = newtEntry(1, 9, "", 55, NULL, NEWT_ENTRY_SCROLL); btnOk = newtButton(15, 14, i18n("Ok")); btnCancel = newtButton(40, 14, i18n("Cancel")); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, labelText, editText, btnOk, btnCancel, NULL); temp = newtRunForm(form); newtPopWindow(); if (temp == btnCancel) { newtFormDestroy(form); RETURN_int(-1); } strncpy(szDestText, newtEntryGetValue(editText), size-1); *(szDestText+size-1) = '\0'; if (*szDestText == 0) msgBoxError(i18n("Text cannot be empty")); newtFormDestroy(form); } return 0; }
/** * Close the currently opened evalcall form. */ void close_evalcall_form(void) { if (g_text_mode) { return; } if (g_isoform_main == NULL) { return; } update_evalcall_form(100); usleep(500000); if (g_text_mode) { log_msg(2, "Closing evalcall form"); return; } newtPopHelpLine(); newtFormDestroy(g_isoform_main); newtPopWindow(); g_isoform_main = NULL; g_isoform_old_progress = -1; }
int ui__help_window(const char *text) { struct newtExitStruct es; newtComponent tb, form = newt_form__new(); int rc = -1; int max_len = 0, nr_lines = 0; const char *t; if (form == NULL) return -1; t = text; while (1) { const char *sep = strchr(t, '\n'); int len; if (sep == NULL) sep = strchr(t, '\0'); len = sep - t; if (max_len < len) max_len = len; ++nr_lines; if (*sep == '\0') break; t = sep + 1; } tb = newtTextbox(0, 0, max_len, nr_lines, 0); if (tb == NULL) goto out_destroy_form; newtTextboxSetText(tb, text); newtFormAddComponent(form, tb); newtCenteredWindow(max_len, nr_lines, NULL); newtFormRun(form, &es); newtPopWindow(); rc = 0; out_destroy_form: newtFormDestroy(form); return rc; }
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; }
/** * Close the currently opened progress form. */ void close_progress_form() { if (g_text_mode) { return; } if (g_current_progress == -999) { log_msg(2, "Trying to close the progress form when it ain't open!"); return; } g_current_progress = g_maximum_progress; update_progress_form("Complete"); sleep(1); if (g_text_mode) { log_msg(2, "Closing progress form"); return; } newtPopHelpLine(); newtFormDestroy(g_progressForm); newtPopWindow(); g_progressForm = NULL; g_current_progress = -999; }
// ======================================================= void CInterfaceNewt::askDescription(char *szDescription, DWORD dwMaxLen) { newtComponent editDesc; newtComponent labelText; newtComponent form; newtComponent btnOk; memset(szDescription, 0, dwMaxLen); newtCenteredWindow(65, 18, i18n("Partition description")); labelText = newtLabel(1, 1, i18n("You can enter a description of the saved partition:")); editDesc = newtEntry(1, 3, "", 60, NULL, NEWT_ENTRY_SCROLL); btnOk = newtButton(27, 13, i18n("Ok")); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, labelText, editDesc, btnOk, NULL); newtRunForm(form); newtPopWindow(); strncpy(szDescription, newtEntryGetValue(editDesc), dwMaxLen); newtFormDestroy(form); }
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 cleanup(void) { newtPopWindow(); }
/* Use SSL. Must be entirely different since the return * type is a pointer to an SSL structure. */ BIO * urlinstStartSSLTransfer(struct iurlinfo * ui, char * filename, char *extraHeaders, int silentErrors, int flags, char *nextServer) { extern void watchdog_reset(); int tries = 1; int rc; int errorcode = -1; int sleepmin = KS_RETRY_MIN; char *returnedHeaders; BIO *sbio = 0; logMessage(INFO, "ROCKS:transferring https://%s/%s\nHeaders:%s\n", ui->address, filename, extraHeaders); /* Add 'public' path element if we dont have a cert. */ if (!haveCertificate()) addPublic(&filename); while ((errorcode < 0) && (tries < 10)) { sbio = httpsGetFileDesc(ui->address, -1, filename, extraHeaders, &errorcode, &returnedHeaders); if (errorcode == 0) { char *ptr; char trackers[256]; char pkgservers[256]; if ((ptr = strstr(returnedHeaders, "X-Avalanche-Trackers:")) != NULL) { sscanf(ptr, "X-Avalanche-Trackers: %256s", trackers); } else { if (nextServer != NULL) { snprintf(trackers, sizeof(trackers) - 1, "%s", nextServer); } else { strcpy(trackers, "127.0.0.1"); } } if ((ptr = strstr(returnedHeaders, "X-Avalanche-Pkg-Servers:")) != NULL) { sscanf(ptr, "X-Avalanche-Pkg-Servers: %256s", pkgservers); } else { if (nextServer != NULL) { snprintf(pkgservers, sizeof(pkgservers) - 1, "%s", nextServer); } else { strcpy(pkgservers, "127.0.0.1"); } } writeAvalancheInfo(trackers, pkgservers); } else if (errorcode == FTPERR_FAILED_DATA_CONNECT) { /* * read the retry value from the return message */ char *ptr; int sleeptime = 0; if ((ptr = strstr(returnedHeaders, "Retry-After:")) != NULL) { sscanf(ptr, "Retry-After: %d", &sleeptime); } if (sleeptime <= 0) { /* * Backoff a random interval between * KS_RETRY_MIN and KS_RETRY_MAX */ sleeptime = sleepmin + ((KS_RETRY_MAX - sleepmin) * (rand()/(float)RAND_MAX)); } winStatus(55, 3, _("Server Busy"), _("I will retry " "for a ks file after a %d sec sleep..."), sleeptime, 0); /* * this must be in a loop, as the alarm associated * with the watchdog timer is sending a signal which * interrupts the sleep(). */ while ((sleeptime = sleep(sleeptime)) != 0) { ; } newtPopWindow(); tries = 1; /* Don't let the watchdog fire if the kickstart server is reporting busy */ watchdog_reset(); continue; } else if (errorcode == FTPERR_REFUSED) { /* * always accept the parent credentials */ forceParentAuth(); continue; } logMessage(INFO, "ROCKS:urlinstStartSSLTransfer:attempt (%d)", tries); sleep(1); ++tries; } if (errorcode < 0) { logMessage(ERROR, "ROCKS:urlinstStartSSLTransfer:Failed"); rc = 0; /* Go through the public door automatically, but only * if we have not tried it already. */ if (errorcode == FTPERR_SERVER_SECURITY && !addPublic(&filename)) { rc = 1; } else { rc = newtWinChoice(_("GET File Error"), _("Retry"), _("Cancel"), _("Could not get file:\n\nhttps://%s/%s\n\n%s"), ui->address, filename, ftpStrerror(errorcode, URL_METHOD_HTTP)); } if (rc==1) /* Retry */ return urlinstStartSSLTransfer(ui, filename, extraHeaders, silentErrors, flags, nextServer); else /* Cancel */ return NULL; } if (!FL_CMDLINE(flags)) winStatus(70, 3, _("Retrieving"), "%s %.*s...", _("Retrieving"), 60, filename); return sbio; }
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 (); }
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; }