Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
/*
 * Screen_PopHelpLine
 *
 */
static VALUE
rb_ext_Screen_PopHelpLine(VALUE self)
{
    newtPopHelpLine();

    return Qnil;
}
Exemplo n.º 3
0
Arquivo: ncce.c Projeto: bmybbs/bmybbs
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;
}
Exemplo n.º 4
0
// =======================================================
void CInterfaceNewt::StatusLine(char *str)
{
  char szBuf[1024];
  if (m_bPushDone)
    newtPopHelpLine(); // work only if there is a previous push
  snprintf(szBuf, sizeof(szBuf),
     i18n("%s [* to cancel, CtrlS to pause, CtrlQ to resume]"), str);
  newtPushHelpLine(szBuf); // str
  m_bPushDone = true;
}
Exemplo n.º 5
0
void newtResizeScreen(int redraw) {
    newtPushHelpLine("");

    SLtt_get_screen_size();
    SLang_init_tty(0, 0, 0);

    SLsmg_touch_lines (0, SLtt_Screen_Rows - 1);

    /* I don't know why I need this */
    SLsmg_refresh();

    newtPopHelpLine();

    if (redraw)
	SLsmg_refresh();
}
/**
 * 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);
	}
Exemplo n.º 7
0
static void sel_callback(newtComponent c, void *cbdata)
{
	int span;
	char info[256];
	char info2[256];
	cbdata = newtListboxGetCurrent(c);
	if (cbdata) {
		span = (long)(cbdata);
		snprintf(info, sizeof (info), "Span %d: %d total channels, %d configured", span, s[span].totalchans, s[span].numchans);
		snprintf(info2, sizeof(info2), "%-59s F1=Details F10=Quit", info);
	} else {
		span = -1;
		strcpy(info, "There are no DAHDI spans on this system.");
		snprintf(info2, sizeof(info2), "%-59s            F10=Quit", info);
	}
	newtPopHelpLine();
	newtPushHelpLine(info2);
}
Exemplo n.º 8
0
/* choice is the index of the chosen language in languages */
static int setupLanguage(int choice, int forced) {
    char * buf;
    int i;

    logMessage(DEBUGLVL, "going to set language to %s", languages[choice].lc_all);
    /* load the language only if it is displayable.  if they're using
     * a serial console or iSeries vioconsole, we hope it's smart enough */
    if ((strcmp(languages[choice].font, "latarcyrheb-sun16") && !FL_SERIAL(flags) && 
         !FL_VIRTPCONSOLE(flags) && !isVioConsole())) {
        if (forced == 1) return 0;

	newtWinMessage("Language Unavailable", "OK", 
		       "%s display is unavailable in text mode.  The "
		       "installation will continue in English until the "
		       "display of %s is possible.", languages[choice].lang,
		       languages[choice].lang);
        setLangEnv(english);
	return 0;
    }
    
    setLangEnv (choice);

    /* clear out top line */
    buf = alloca(80);
    for (i=0; i < 80; i++)
	buf[i] = ' ';
    newtDrawRootText(0, 0, buf);

    char *fmt = FL_RESCUE(flags) ? _(topLineWelcomeRescue) : _(topLineWelcome);
    if (asprintf(&buf, fmt, getProductName(), getProductArch()) == -1) {
        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
        abort();
    }

    newtDrawRootText(0, 0, buf);
    free(buf);
    newtPopHelpLine();
    newtPushHelpLine(_(bottomHelpLine));

    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;
	}
/**
 * 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;
	}
/**
 * Pop up a list containing the filenames in @p source_file and the severity if they have changed since the
 * last backup. There can be no more than @p ARBITRARY_MAXIMUM files in @p source_file.
 * @param source_file The file containing a list of changed files.
 */
	void popup_changelist_from_file(char *source_file) {
		char *reason = NULL;
		newtComponent myForm;
		newtComponent bClose;
		newtComponent bSelect;
		newtComponent b_res;
		newtComponent fileListbox;
		newtComponent headerMsg;

		/*@ ???? ************************************************************ */
		void *curr_choice;
		void *keylist[ARBITRARY_MAXIMUM];

		/*@ int ************************************************************* */
		int i = 0;
		int currline = 0;
		int finished = FALSE;
		long lng = 0;

		/*@ buffers ********************************************************* */
		char *tmp;
		char *differ_sz;

		struct s_filelist *filelist;
		assert_string_is_neither_NULL_nor_zerolength(source_file);
		if (g_text_mode) {
			log_msg(2, "Text mode. Therefore, no popup list.");
			return;
		}
		log_msg(2, "Examining file %s", source_file);

		lng = count_lines_in_file(source_file);
		if (lng < 1) {
			log_msg(2, "No lines in file. Therefore, no popup list.");
			return;
		} else if (lng >= ARBITRARY_MAXIMUM) {
			log_msg(2, "Too many files differ for me to list.");
			return;
		}

		filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
		fileListbox =
			newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
		newtListboxClear(fileListbox);

		if (load_filelist_into_array(filelist, source_file)) {
			log_msg(2, "Can't open %s; therefore, cannot popup list",
					source_file);
			return;
		}
		log_msg(2, "%d files loaded into filelist array",
				filelist->entries);
		for (i = 0; i < filelist->entries; i++) {
			keylist[i] = (void *) i;
			newtListboxAppendEntry(fileListbox,
								   filelist_entry_to_string(&
															(filelist->
															 el[i])),
								   keylist[i]);
		}
		asprintf(&differ_sz,
				 _("  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list."),
				 i);
		newtPushHelpLine(differ_sz);
		paranoid_free(differ_sz);

		bClose = newtCompactButton(10, 15, _(" Close  "));
		bSelect = newtCompactButton(30, 15, _(" Select "));
		asprintf(&tmp, "%-10s               %-20s", _("Priority"),
				 _("Filename"));
		headerMsg = newtLabel(2, 1, tmp);
		paranoid_free(tmp);

		newtOpenWindow(5, 4, 70, 16, _("Non-matching files"));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
							  bSelect, NULL);
		while (!finished) {
			b_res = newtRunForm(myForm);
			if (b_res == bClose) {
				finished = TRUE;
			} else {
				curr_choice = newtListboxGetCurrent(fileListbox);
				for (i = 0;
					 i < filelist->entries && keylist[i] != curr_choice;
					 i++);
				if (i == filelist->entries && filelist->entries > 0) {
					log_to_screen(_("I don't know what that button does!"));
				} else {
					currline = i;
					if (filelist->entries > 0) {
						severity_of_difference(filelist->el[currline].
											   filename, reason);
						asprintf(&tmp, "%s --- %s",
								 filelist->el[currline].filename, reason);
						popup_and_OK(tmp);
						paranoid_free(tmp);
						paranoid_free(reason);
					}
				}
			}
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		newtPopHelpLine();
	}
Exemplo n.º 12
0
static void show_span(int span)
{
	newtComponent form;
	newtComponent back;
	newtComponent loop;
	newtComponent label;
	newtComponent bitbox;
	newtComponent inuse;
	newtComponent levels;
	newtComponent bpvcount;
	newtComponent alarms;
	newtComponent syncsrc;
	newtComponent irqmisses;
	
	char s1[] = "         1111111111222222222233";
	char s2[] = "1234567890123456789012345678901";
	int x;
	int looped = 0;
	struct newtExitStruct es;

	void *ss;
	char info2[256];

	if (span < 0) {
		/* Display info on a span */
		ss = newtListboxGetCurrent(spans);
		if (ss) {
			span = (long)(ss);
		}
	}

	snprintf(info2, sizeof(info2), "%-59s            F10=Back", s[span].desc);
	newtOpenWindow(10,2,60,20, s[span].desc);
	newtPushHelpLine(info2);

	back = newtButton(48,8,"Back");
	loop = newtButton(48,14,"Loop");
	form = newtForm(NULL, NULL, 0);

	newtFormAddComponents(form, back, loop, NULL);

	span_max_chan_pos = s[span].totalchans;
	for (x=0;x<DAHDI_MAX_CHANNELS;x++) {
		DAHDI_PARAMS zp;
		int res;
		memset(&zp, 0, sizeof(zp));
		zp.channo = x;
		res = ioctl(ctl, DAHDI_GET_PARAMS, &zp);
		if (!res && zp.spanno == span && zp.chanpos > span_max_chan_pos )
			span_max_chan_pos = zp.chanpos;
	}

	if (span_max_chan_pos > 32)
		span_max_chan_pos = 32;

	s1[span_max_chan_pos] = '\0';
	s2[span_max_chan_pos] = '\0';

	bitbox = newtTextbox(8,10,span_max_chan_pos,9,0);
	newtFormAddComponent(form, bitbox);

	label = newtLabel(8,8,s1);
	newtFormAddComponent(form, label);

	label = newtLabel(8,9,s2);
	newtFormAddComponent(form, label);

	newtFormAddHotKey(form, NEWT_KEY_F10);
	newtFormSetTimer(form, 200);

	label = newtLabel(4,10,"TxA");
	newtFormAddComponent(form, label);

	label = newtLabel(4,11,"TxB");
	newtFormAddComponent(form, label);

	label = newtLabel(4,12,"TxC");
	newtFormAddComponent(form, label);

	label = newtLabel(4,13,"TxD");
	newtFormAddComponent(form, label);

	label = newtLabel(4,15,"RxA");
	newtFormAddComponent(form, label);

	label = newtLabel(4,16,"RxB");
	newtFormAddComponent(form, label);

	label = newtLabel(4,17,"RxC");
	newtFormAddComponent(form, label);

	label = newtLabel(4,18,"RxD");
	newtFormAddComponent(form, label);
	
	
	label = newtLabel(4,7,"Total/Conf/Act: ");
	newtFormAddComponent(form, label);
	
	inuse = newtTextbox(24,7,12,1,0);
	newtFormAddComponent(form, inuse);

	label = newtLabel(4,6,"Tx/Rx Levels: ");
	newtFormAddComponent(form, label);

	levels = newtTextbox(24,6,30,1,0);
	newtFormAddComponent(form, levels);
	
	label = newtLabel(4,5,"Bipolar Viol: ");
	newtFormAddComponent(form, label);

	bpvcount = newtTextbox(24,5,30,1,0);
	newtFormAddComponent(form, bpvcount);
	
	label = newtLabel(4,4,"IRQ Misses: ");
	newtFormAddComponent(form, label);

	irqmisses = newtTextbox(24,4,30,1,0);
	newtFormAddComponent(form, irqmisses);

	label = newtLabel(4,3,"Sync Source: ");
	newtFormAddComponent(form, label);

	syncsrc = newtTextbox(24,3,30,1,0);
	newtFormAddComponent(form, syncsrc);

	label = newtLabel(4,2,"Current Alarms: ");
	newtFormAddComponent(form, label);

	alarms = newtTextbox(24,2,30,1,0);
	newtFormAddComponent(form, alarms);
	
	for(;;) {
		/* Wait for user to select something */
		do {
			add_cards(NULL);
			show_bits(span, bitbox, inuse, levels, bpvcount, alarms, syncsrc, irqmisses);
			newtFormRun(form, &es);
		} while(es.reason == NEWT_EXIT_TIMER);
		switch(es.reason) {
		case NEWT_EXIT_COMPONENT:
			if (es.u.co == loop) {
				looped = !looped;
				do_loop(span, looped);
				newtFormSetTimer(form, 200);
			}
			if (es.u.co == back) {
				goto out;
			}
			break;
		case NEWT_EXIT_HOTKEY:
			switch(es.u.key) {
#if 0
			case NEWT_KEY_F1:
				show_span(-1);
				break;
#endif				
			case NEWT_KEY_F10:
				goto out;
			}
			break;
		default:
			break;
		}
	}	

out:	
	newtFormDestroy(form);
	newtPopWindow();
	newtPopHelpLine();
	span_max_chan_pos = 0;
}
/**
 * Pop up a dialog box with user-defined buttons.
 * @param p The text to put in the dialog box.
 * @param button1 The label on the first button.
 * @param button2 The label on the second button, or "" if you only want one button.
 * @return TRUE if @p button1 was pushed, FALSE otherwise.
 */
	bool popup_with_buttons(char *p, char *button1, char *button2) {

		/*@ buffers *********************************************************** */
		char *prompt;
		char *tmp = NULL;
		size_t n = 0;

		/*@ newt ************************************************************** */
		newtComponent myForm;
		newtComponent b_1;
		newtComponent b_2;
		newtComponent b_res;
		newtComponent text;

		assert_string_is_neither_NULL_nor_zerolength(p);
		assert(button1 != NULL);
		assert(button2 != NULL);
		if (g_text_mode) {
			if (strlen(button2) == 0) {
				printf("%s (%s) --> ", p, button1);
			} else {
				printf("%s (%s or %s) --> ", p, button1, button2);
			}
			for (asprintf(&tmp, " ");
				 strcmp(tmp, button1) && (strlen(button2) == 0
										  || strcmp(tmp, button2));) {
				printf("--> ");
				paranoid_free(tmp);
				(void) getline(&tmp, &n, stdin);
			}
			if (!strcmp(tmp, button1)) {
				paranoid_free(tmp);
				return (TRUE);
			} else {
				paranoid_free(tmp);
				return (FALSE);
			}
		}

		asprintf(&prompt, p);
		text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
		b_1 =
			newtButton(20 -
					   ((button2[0] !=
						 '\0') ? strlen(button1) +
						2 : strlen(button1) / 2),
					   newtTextboxGetNumLines(text) + 3, button1);
		if (button2[0] != '\0') {
			b_2 =
				newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
		} else {
			b_2 = NULL;
		}
		//  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
		newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, _("Alert"));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, text, b_1, b_2, NULL);
		/* BERLIOS: center_string is now broken replace it ! */
		//center_string(prompt, 80);
		newtPushHelpLine(prompt);
		paranoid_free(prompt);
		b_res = newtRunForm(myForm);
		newtPopHelpLine();
		newtFormDestroy(myForm);
		newtPopWindow();
		if (b_res == b_1) {
			return (TRUE);
		} else {
			return (FALSE);
		}
	}
/**
 * Ask the user to enter a value.
 * @param title The title of the dialog box.
 * @param b The blurb (e.g. what you want the user to enter).
 * @param output The string to put the user's answer in. It has to be freed by the caller
 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
 */
	bool popup_and_get_string(char *title, char *b, char *output) {

		/*@ newt ************************************************************ */
		newtComponent myForm;
		newtComponent b_1;
		newtComponent b_2;
		newtComponent b_res;
		newtComponent text;
		newtComponent type_here;

		/*@ pointers ********************************************************* */
		char *entry_value = NULL;

		/*@ buffers ********************************************************** */
		char *blurb = NULL;
		size_t n = 0;
		bool ret = TRUE;

		assert_string_is_neither_NULL_nor_zerolength(title);
		assert(b != NULL);

		if (g_text_mode) {
			printf
				("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
				 title, b);
			paranoid_free(output);
			(void) getline(&output, &n, stdin);
			if (output[strlen(output) - 1] == '\n')
				output[strlen(output) - 1] = '\0';
			return (ret);
		}
		asprintf(&blurb, b);
		text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);

		type_here =
			newtEntry(2, newtTextboxGetNumLines(text) + 2,
					  output, 50,
					  &entry_value, NEWT_FLAG_RETURNEXIT
			);
		b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _("  OK  "));
		b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel"));
		newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
		/* BERLIOS: center_string is now broken replace it ! */
		//center_string(blurb, 80);
		newtPushHelpLine(blurb);
		paranoid_free(blurb);

		b_res = newtRunForm(myForm);
		newtPopHelpLine();
		if (b_res == b_2) {
			ret = FALSE;
		} else {
			// Copy entry_value before destroying the form
			// clearing potentially output before
			paranoid_alloc(output,entry_value);
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		return(ret);
	}
Exemplo n.º 15
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);
}
/**
 * Ask the user which backup media type they would like to use.
 * The choices are @p none (exit to shell), @c cdr, @c cdrw, @c dvd,
 * @c tape, @c cdstream, @c udev (only when @p g_text_mode is TRUE), @c nfs,
 * and @c iso.
 * @param restoring TRUE if we're restoring, FALSE if we're backing up.
 * @return The backup type chosen, or @c none if the user chose "Exit to shell".
 */
	t_bkptype which_backup_media_type(bool restoring) {

		/*@ char ************************************************************ */
		t_bkptype output;


		/*@ newt ************************************************************ */
		char *title_sz;
		char *minimsg_sz;
		static t_bkptype possible_bkptypes[] =
			{ none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso };
		static char *possible_responses[] =
			{ "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
			"nfs", "iso", NULL
		};
		char *outstr = NULL;
		t_bkptype backup_type;
		int i;
		size_t n = 0;

		newtComponent b1;
		newtComponent b2;
		newtComponent b3;
		newtComponent b4;
		newtComponent b5;
		newtComponent b6;
		newtComponent b7;
		newtComponent b8;
		newtComponent b_res;
		newtComponent myForm;

		if (g_text_mode) {
			for (backup_type = none; backup_type == none;) {
				printf(_("Backup type ("));
				for (i = 0; possible_responses[i]; i++) {
					printf("%c%s", (i == 0) ? '\0' : ' ',
						   possible_responses[i]);
				}
				printf(")\n--> ");
				(void) getline(&outstr, &n, stdin);
				strip_spaces(outstr);
				for (i = 0; possible_responses[i]; i++) {
					if (!strcmp(possible_responses[i], outstr)) {
						backup_type = possible_bkptypes[i];
					}
				}
			}
			paranoid_free(outstr);
			return (backup_type);
		}
		newtDrawRootText(18, 0, WELCOME_STRING);
		if (restoring) {
			asprintf(&title_sz,
					 _("Please choose the backup media from which you want to read data."));
			asprintf(&minimsg_sz, _("Read from:"));
		} else {
			asprintf(&title_sz,
					 _("Please choose the backup media to which you want to archive data."));
			asprintf(&minimsg_sz, _("Backup to:"));
		}
		newtPushHelpLine(title_sz);
		paranoid_free(title_sz);

		//  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
		newtCenteredWindow(34, 17, minimsg_sz);
		paranoid_free(minimsg_sz);

		b1 = newtButton(1, 1, _("CD-R disks "));
		b2 = newtButton(17, 1, _("CD-RW disks"));
		b3 = newtButton(1, 9, _("Tape drive "));
		b4 = newtButton(17, 5, _("CD streamer"));
		b5 = newtButton(1, 5, _(" DVD disks "));
		b6 = newtButton(17, 9, _(" NFS mount "));
		b7 = newtButton(1, 13, _(" Hard disk "));
		b8 = newtButton(17, 13, _("    Exit   "));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8,
							  NULL);
		b_res = newtRunForm(myForm);
		newtFormDestroy(myForm);
		newtPopWindow();
		if (b_res == b1) {
			output = cdr;
		} else if (b_res == b2) {
			output = cdrw;
		} else if (b_res == b3) {
			output = tape;
		} else if (b_res == b4) {
			output = cdstream;
		} else if (b_res == b5) {
			output = dvd;
		} else if (b_res == b6) {
			output = nfs;
		} else if (b_res == b7) {
			output = iso;
		} else {
			output = none;
		}
		newtPopHelpLine();
		return (output);
	}
Exemplo n.º 17
0
static int wtCmd(ClientData clientData, Tcl_Interp * interp, int argc,
                  char ** argv) {
    enum mode mode = MODE_NONE;
    poptContext optCon;
    int arg;
    const char * optArg;
    const char * text;
    const char * nextArg;
    char * end;
    int height;
    int width;
    int noCancel = 0;
    int noItem = 0;
    int scrollText = 0;
    int rc = 0;
    int flags = 0;
    int defaultNo = 0;
    char * result;
    char ** selections, ** next;
    char * title = NULL;
    struct poptOption optionsTable[] = {
	    { "checklist", '\0', 0, 0, OPT_CHECKLIST },
	    { "defaultno", '\0', 0, &defaultNo, 0 },
	    { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
	    { "menu", '\0', 0, 0, OPT_MENU },
	    { "msgbox", '\0', 0, 0, OPT_MSGBOX },
	    { "nocancel", '\0', 0, &noCancel, 0 },
	    { "noitem", '\0', 0, &noItem, 0 },
	    { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
	    { "scrolltext", '\0', 0, &scrollText, 0 },
	    { "title", '\0', POPT_ARG_STRING, &title, 0 },
	    { "yesno", '\0', 0, 0, OPT_YESNO },
	    { 0, 0, 0, 0, 0 } 
    };
    
    optCon = poptGetContext("whiptcl", argc, argv, optionsTable, 0);

    while ((arg = poptGetNextOpt(optCon)) > 0) {
	optArg = poptGetOptArg(optCon);

	switch (arg) {
	  case OPT_MENU:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_MENU;
	    break;

	  case OPT_MSGBOX:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_MSGBOX;
	    break;

	  case OPT_RADIOLIST:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_RADIOLIST;
	    break;

	  case OPT_CHECKLIST:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_CHECKLIST;
	    break;

	  case OPT_YESNO:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_YESNO;
	    break;

	  case OPT_INPUTBOX:
	    if (mode != MODE_NONE) rc = -1;
	    mode = MODE_INPUTBOX;
	    break;
	}
    }
    
    if (arg < -1) {
	/* this could buffer oveflow, bug we're not setuid so I don't care */
	interp->result = malloc(200);
	interp->freeProc = TCL_DYNAMIC;
	sprintf(interp->result, "%s: %s\n", 
		poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
		poptStrerror(arg));

	return TCL_ERROR;
    }

    if (mode == MODE_NONE) {
	interp->result = "no dialog mode was specified";
	return TCL_ERROR;
    } else if (rc) {
	interp->result = "multiple modes were specified";
	return TCL_ERROR;
    }

    if (!(text = poptGetArg(optCon))) {
	interp->result = "missing text parameter";
	return TCL_ERROR;
    }

    if (!(nextArg = poptGetArg(optCon))) {
	interp->result = "height missing";
	return TCL_ERROR;
    }
    height = strtoul(nextArg, &end, 10);
    if (*end) {
	interp->result = "height is not a number";
	return TCL_ERROR;
    }

    if (!(nextArg = poptGetArg(optCon))) {
	interp->result = "width missing";
	return TCL_ERROR;
    }
    width = strtoul(nextArg, &end, 10);
    if (*end) {
	interp->result = "width is not a number";
	return TCL_ERROR;
    }

    width -= 2;
    height -= 2;
    newtOpenWindow((80 - width) / 2, (24 - height) / 2, width, height, title);

    if (noCancel) flags |= FLAG_NOCANCEL;
    if (noItem) flags |= FLAG_NOITEM;
    if (scrollText) flags |= FLAG_SCROLL_TEXT;
    if (defaultNo) flags |= FLAG_DEFAULT_NO;

    switch (mode) {
      case MODE_MSGBOX:
	rc = messageBox(text, height, width, MSGBOX_MSG, flags);
	break;

      case MODE_YESNO:
	rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
	if (rc == DLG_OKAY)
	    interp->result = "yes";
	else 
	    interp->result = "no";
	if (rc == DLG_ERROR) rc = 0;
	break;

      case MODE_INPUTBOX:
	rc = inputBox(text, height, width, optCon, flags, &result);
	if (!rc) {
	    interp->result = strdup(result);
	    interp->freeProc = TCL_DYNAMIC;
	}
	break;

      case MODE_MENU:
	rc = listBox(text, height, width, optCon, flags, &result);
	if (!rc) {
	    interp->result = strdup(result);
	    interp->freeProc = TCL_DYNAMIC;
	}
	break;

      case MODE_RADIOLIST:
	rc = checkList(text, height, width, optCon, 1, flags, &selections);
	if (!rc) {
	    interp->result = strdup(selections[0]);
	    interp->freeProc = TCL_DYNAMIC;
	}
	break;

      case MODE_CHECKLIST:
	rc = checkList(text, height, width, optCon, 0, flags, &selections);

	if (!rc) {
	    for (next = selections; *next; next++) 
		Tcl_AppendElement(interp, *next);

	    free(selections);
	}
	break;

      case MODE_NONE:
	/* this can't happen */
    }

    newtPopWindow();

    if (rc == DLG_ERROR) {
	interp->result = "bad paramter for whiptcl dialog box";
	return TCL_ERROR;
    } 

    Tcl_SetVar(interp, "whiptcl_canceled", (rc == DLG_CANCEL) ? "1" : "0",
		0);

    return TCL_OK;
}

static char * setBacktext(ClientData data, Tcl_Interp * interp, 
			  char * name1, char * name2, int flags) {
    static char blankLine[81] = "                                        "
                         "                                        ";

    newtDrawRootText(0, 0, blankLine);
    newtDrawRootText(0, 0, Tcl_GetVar(interp, "whiptcl_backtext",
		                      TCL_GLOBAL_ONLY));

    return NULL;
}

static char * setHelptext(ClientData data, Tcl_Interp * interp, 
			  char * name1, char * name2, int flags) {
    char * text = Tcl_GetVar(interp, "whiptcl_helpline", TCL_GLOBAL_ONLY);

    if (!text)
	text = "";
    else if (!strlen(text))
	text = NULL;

    newtPopHelpLine();
    newtPushHelpLine(text);

    return NULL;
}