Exemple #1
0
static void conf_save(void)
{
	while (1) {
		int res;
		dialog_clear();
		res = dialog_inputbox(NULL, save_config_text,
				      11, 55, filename);
		switch(res) {
		case 0:
			if (!dialog_input_result[0])
				return;
			if (!conf_write(dialog_input_result)) {
				set_config_filename(dialog_input_result);
				return;
			}
			show_textbox(NULL, _("Can't create file!  Probably a nonexistent directory."), 5, 60);
			break;
		case 1:
			show_helptext(_("Save Alternate Configuration"), save_config_help);
			break;
		case KEY_ESC:
			return;
		}
	}
}
Exemple #2
0
static void search_conf(void)
{
	struct symbol **sym_arr;
	struct gstr res;
	int dres;
again:
	dialog_clear();
	dres = dialog_inputbox(_("Search Configuration Parameter"),
			      _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"),
			      10, 75, "");
	switch (dres) {
	case 0:
		break;
	case 1:
		show_helptext(_("Search Configuration"), search_help);
		goto again;
	default:
		return;
	}

	sym_arr = sym_re_search(dialog_input_result);
	res = get_relations_str(sym_arr);
	free(sym_arr);
	show_textbox(_("Search Results"), str_get(&res), 0, 0);
	str_free(&res);
}
Exemple #3
0
static void conf_load(void)
{

	while (1) {
		int res;
		dialog_clear();
		res = dialog_inputbox(NULL, load_config_text,
				      11, 55, filename);
		switch(res) {
		case 0:
			if (!dialog_input_result[0])
				return;
			if (!conf_read(dialog_input_result)) {
				set_config_filename(dialog_input_result);
				sym_set_change_count(1);
				return;
			}
			show_textbox(NULL, _("File does not exist!"), 5, 38);
			break;
		case 1:
			show_helptext(_("Load Alternate Configuration"), load_config_help);
			break;
		case KEY_ESC:
			return;
		}
	}
}
Exemple #4
0
static void search_conf(void)
{
	struct symbol **sym_arr;
	struct gstr res;
	char *dialog_input;
	int dres;
again:
	dialog_clear();
	dres = dialog_inputbox(_("Search Configuration Parameter"),
			      _("Enter CONFIG_ (sub)string to search for "
				"(with or without \"CONFIG\")"),
			      10, 75, "");
	switch (dres) {
	case 0:
		break;
	case 1:
		show_helptext(_("Search Configuration"), search_help);
		goto again;
	default:
		return;
	}

	/* strip CONFIG_ if necessary */
	dialog_input = dialog_input_result;
	if (strncasecmp(dialog_input_result, "CONFIG_", 7) == 0)
		dialog_input += 7;

	sym_arr = sym_re_search(dialog_input);
	res = get_relations_str(sym_arr);
	free(sym_arr);
	show_textbox(_("Search Results"), str_get(&res), 0, 0);
	str_free(&res);
}
Exemple #5
0
/* Put up a message in an input box and return the value */
char *
msgGetInput(char *buf, const char *fmt, ...)
{
    va_list args;
    char *errstr;
    static char input_buffer[256];
    int rval;
    WINDOW *w = savescr();

    errstr = (char *)alloca(FILENAME_MAX);
    va_start(args, fmt);
    vsnprintf(errstr, FILENAME_MAX, fmt, args);
    va_end(args);
    use_helpline(NULL);
    use_helpfile(NULL);
    if (buf)
	SAFE_STRCPY(input_buffer, buf);
    else
	input_buffer[0] = '\0';
    if (OnVTY) {
	ioctl(0, VT_ACTIVATE, 1);	/* Switch back */
	msgInfo(NULL);
    }
    rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
    restorescr(w);
    if (!rval)
	return input_buffer;
    else
	return NULL;
}
Exemple #6
0
static int
j_passwordbox(JUMPARGS)
{
    *offset_add = arg_rest(av);
    return show_result(dialog_inputbox(t,
				       av[1],
				       numeric_arg(av, 2),
				       numeric_arg(av, 3),
				       optional_str(av, 4, 0), 1));
}
Exemple #7
0
int _afi_manual(dialogMenuItem *self)
{
	char result[256];
	int ret;

	dialog_clear();
	bzero(result, sizeof(result));

	ret = dialog_inputbox("ClosedBSD: Manual IPFW rule addition", "Type in the rule manually.  These are some sample rules that illustrate the syntax\n\n 'add allow all from any to any'\n 'add deny tcp from echelon.gov'\n 'add deny all from evilcrackers.org'\n 'add allow all from 192.168.202.0 to any out'\n\n", -1, -1, result);

	if (ret == 0)
		raw_add_rule(result);

	return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
}
Exemple #8
0
static int ask_option_value(DC_Procedure *act, DC_OptionSetting *setting, DC_ProcedureOption *option) {
    char *suggested_value = setting->value;
    char entered_value[200];
    const char *param_type_str;
    char *config_supplied_value;
    char *config_suggested_value;
    char config_search_command[200];
    snprintf(config_search_command, sizeof(config_search_command),
            "grep ^%s.%s= ~/.whddrc 2>/dev/null | awk -F= '{print $2}' | tr -d '\\n'", act->name, option->name);
    config_supplied_value = cmd_output(config_search_command);
    if (config_supplied_value) {
        setting->value = config_supplied_value;
        return 0;
    }

    snprintf(config_search_command, sizeof(config_search_command),
            "grep ^%s.%s.suggest= ~/.whddrc 2>/dev/null | awk -F= '{print $2}' | tr -d '\\n'", act->name, option->name);
    config_suggested_value = cmd_output(config_search_command);
    if (config_suggested_value)
        suggested_value = config_suggested_value;

    switch (option->type) {
        case DC_ProcedureOptionType_eInt64:
            param_type_str = "numeric";
            break;
        case DC_ProcedureOptionType_eString:
            param_type_str = "string";
            break;
    }
    char prompt[500];
    snprintf(prompt, sizeof(prompt), "Please enter %s parameter: %s (%s)",
            param_type_str, option->name, option->help);

    dialog_vars.default_button = -1;  // Workaround for surprisingly unfocused input field on old libdialog
    dialog_vars.input_result = NULL;
    int r = dialog_inputbox("Input box", prompt, 0, 0, suggested_value, 0);
    if (r != 0) {
        dialog_msgbox("Info", "Action cancelled", 0, 0, 1);
        return 1;
    }
    // Wow, libdialog is awesomely sane and brilliantly documented lib, i f****n love it
    snprintf(entered_value, sizeof(entered_value), "%s", dialog_vars.input_result);
    if (entered_value[0] == '\0' || entered_value[0] == '\n')
        snprintf(entered_value, sizeof(entered_value), "%s", suggested_value);
    setting->value = strdup(entered_value);
    free(suggested_value);
    return 0;
}
Exemple #9
0
/* Kick it off, James! */
int
main(int argc, char **argv)
{
  int retval;
  unsigned char result[128];

  init_dialog();

  strcpy(result, "not this!");
  retval = dialog_inputbox("this is dialog_inputbox() in action, test #1",
		       "Enter something really profound below, please.",
		       -1, -1, result);
  dialog_clear();
  fprintf(stderr, "returned value for dialog_inputbox was %d (%s)\n", retval, result);

  end_dialog();
  return 0;
}
Exemple #10
0
static void conf_save(void)
{
	while (1) {
		switch (dialog_inputbox(NULL, save_config_text, 11, 55,
					filename)) {
		case 0:
			if (!dialog_input_result[0])
				return;
			if (!conf_write(dialog_input_result))
				return;
			show_textbox(NULL, "Can't create file!  Probably a nonexistent directory.", 5, 60);
			break;
		case 1:
			show_helptext("Save Alternate Configuration", save_config_help);
			break;
		case 255:
			return;
		}
	}
}
Exemple #11
0
static void conf_load(void)
{
	while (1) {
		switch (dialog_inputbox(NULL, load_config_text, 11, 55,
					filename)) {
		case 0:
			if (!dialog_input_result[0])
				return;
			if (!conf_read(dialog_input_result))
				return;
			show_textbox(NULL, "File does not exist!", 5, 38);
			break;
		case 1:
			show_helptext("Load Alternate Configuration", load_config_help);
			break;
		case 255:
			return;
		}
	}
}
Exemple #12
0
/* Kick it off, James! */
int
main(int argc, unsigned char *argv[])
{
  int retval;
  unsigned char result[128];

  init_dialog();

  result[0]='\0';
  DialogInputAttrs |= DITEM_NO_ECHO;
  retval = dialog_inputbox("this is dialog_inputbox() in action, test #2 (no echo)",
		       "Enter something really secret below, please.",
		       -1, -1, result);
  DialogInputAttrs &= DITEM_NO_ECHO;
  dialog_clear();
  fprintf(stderr, "returned value for dialog_inputbox was %d (%s)\n", retval, result);

  end_dialog();
  return 0;
}
Exemple #13
0
static void conf_string(struct menu *menu)
{
	const char *prompt = menu_get_prompt(menu);

	while (1) {
		int res;
		const char *heading;

		switch (sym_get_type(menu->sym)) {
		case S_INT:
			heading = _(inputbox_instructions_int);
			break;
		case S_HEX:
			heading = _(inputbox_instructions_hex);
			break;
		case S_STRING:
			heading = _(inputbox_instructions_string);
			break;
		default:
			heading = _("Internal mconf error!");
		}
		dialog_clear();
		res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
				      heading, 10, 75,
				      sym_get_string_value(menu->sym));
		switch (res) {
		case 0:
			if (sym_set_string_value(menu->sym, dialog_input_result))
				return;
			show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
			break;
		case 1:
			show_help(menu);
			break;
		case KEY_ESC:
			return;
		}
	}
}
Exemple #14
0
static void conf_string(struct menu *menu)
{
	const char *prompt = menu_get_prompt(menu);

	while (1) {
		char *heading;

		switch (sym_get_type(menu->sym)) {
		case S_INT:
			heading = (char *) inputbox_instructions_int;
			break;
		case S_HEX:
			heading = (char *) inputbox_instructions_hex;
			break;
		case S_STRING:
			heading = (char *) inputbox_instructions_string;
			break;
		default:
			heading = "Internal mconf error!";
			/* panic? */;
		}

		switch (dialog_inputbox(prompt ? prompt : "Main Menu",
					heading, 10, 75,
					sym_get_string_value(menu->sym))) {
		case 0:
			if (sym_set_string_value(menu->sym, dialog_input_result))
				return;
			show_textbox(NULL, "You have made an invalid entry.", 5, 43);
			break;
		case 1:
			show_help(menu);
			break;
		case 255:
			return;
		}
	}
}
Exemple #15
0
static void search_conf(void)
{
	struct symbol **sym_arr;
	struct gstr res;

again:
	switch (dialog_inputbox("Search Configuration Parameter",
				"Enter Keyword", 10, 75,
				NULL)) {
	case 0:
		break;
	case 1:
		show_helptext("Search Configuration", search_help);
		goto again;
	default:
		return;
	}

	sym_arr = sym_re_search(dialog_input_result);
	res = get_relations_str(sym_arr);
	free(sym_arr);
	show_textbox("Search Results", str_get(&res), 0, 0);
	str_free(&res);
}