Beispiel #1
0
static TUI_MENU_CALLBACK(create_disk_image_callback)
{
    if (been_activated) {
        unsigned int drive;

        drive = (unsigned int)param;

        if (file_name == NULL) {
            tui_error("Specify a disk image name.");
            return NULL;
        }

        if (vdrive_internal_create_format_disk_image(file_name, format_name, image_type[file_type]) < 0) {
            tui_error("Could not create disk image!");
            return NULL;
        }

        if (drive > 0) {
            if (file_system_attach_disk(drive, file_name) < 0) {
                tui_error("Could not attach disk image!");
                return NULL;
            }
        }

        ui_update_menus();
    }

    return NULL;
}
Beispiel #2
0
static TUI_MENU_CALLBACK(attach_cartridge_callback)
{
    const char *s;
    int type = (int)param;

    if (been_activated) {
        char *default_item, *directory;
        char *name;

        s = cartridge_get_file_name(cartridge_type_to_address(type));
        if (s == NULL) {
            directory = default_item = NULL;
        } else {
            util_fname_split(s, &directory, &default_item);
        }

        name = tui_file_selector("Attach cartridge image", directory, "*", default_item, NULL, NULL, NULL);
        if (name != NULL && (s == NULL || strcasecmp(name, s) != 0) && cartridge_attach_image(type, name) < 0) {
            tui_error("Invalid cartridge image.");
        }
        ui_update_menus();
        lib_free(name);
    }

    /* This is redundant if `been_activated' is nonzero, but let's stay on
       the safe side.  */
    s = cartridge_get_file_name(cartridge_type_to_address(type));
    if (s == NULL || *s == '\0') {
        return "(none)";
    } else {
        return s;
    }
}
Beispiel #3
0
static char *screenshot_save_file(char *screenshot_type, char *screenshot_save_failed, char *screenshot_save_success)
{
    if (file_name == NULL || *file_name == 0) {
        tui_error("Specify a file name first.");
        return NULL;
    }

    if (!util_file_exists(file_name) || tui_ask_confirmation("The specified file already exists.  Replace?  (Y/N)")) {
        if (screenshot_save(screenshot_type, file_name, last_canvas) < 0) {
            tui_error(screenshot_save_failed);
        } else {
            tui_message(screenshot_save_success);
        }
    }
    return NULL;
}
Beispiel #4
0
static TUI_MENU_CALLBACK(change_workdir_callback)
{
    char s[256];

    if (!been_activated) {
        return NULL;
    }

    *s = '\0';

    if (tui_input_string("Change working directory", "New directory:", s, 255) == -1) {
        return NULL;
    }

    util_remove_spaces(s);
    if (*s == '\0') {
        return NULL;
    }

    if (ioutil_chdir(s) == -1) {
        tui_error("Invalid directory.");
    }

    return NULL;
}
Beispiel #5
0
static TUI_MENU_CALLBACK(attach_disk_callback)
{
    const char *s;

    if (been_activated) {
        char *default_item, *directory;
        char *name, *file;
        unsigned int file_number = 0;

        s = file_system_get_disk_name((unsigned int)param);
        util_fname_split(s, &directory, &default_item);

        name = tui_file_selector("Attach a disk image", directory, 
                                 "*.d64;*.d71;*.d81;*.g64;*.g41;*.x64;*.p64;*.d80;*.d82;*.d67;*.d1m;*.d2m;*.d4m;"
                                 "*.d6z;*.d7z;*.d8z;*.g6z;*.g4z;*.x6z;*.zip;*.gz;*.lzh",
                                 default_item, diskcontents_filesystem_read, &file,
                                 &file_number);
        if (file_number > 0) {
            if (autostart_disk(name, NULL, file_number, AUTOSTART_MODE_RUN) < 0) {
                tui_error("Cannot autostart disk image.");
            } else {
                *behavior = TUI_MENU_BEH_RESUME;
            }
        } else if (name != NULL && (s == NULL || strcasecmp(name, s) != 0) && file_system_attach_disk((int)param, name) < 0) {
            tui_error("Invalid disk image.");
        }

        lib_free(file);

        ui_update_menus();

        lib_free(directory);
        lib_free(default_item);
        lib_free(name);
    }

    s = file_system_get_disk_name((unsigned int)param);

    if (s == NULL || *s == '\0') {
        return "(none)";
    } else {
        return s;
    }
}
Beispiel #6
0
void saveoptions(void)
{
	int fd;
	int bw;

	fd = open(CONFIGFILE, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);

	if (fd < 0) {
		tui_error(ANYKEY_MSG, "Cannot create config file: %s %s",
			  CONFIGFILE, strerror(errno));
		return;
	}
	bw = write(fd, &options, sizeof(struct OPTIONS));

	if (bw < 0)
		tui_error(ANYKEY_MSG, "Unable to write config file");

	close(fd);
}
Beispiel #7
0
static TUI_MENU_CALLBACK(autostart_callback)
{
    if (been_activated) {
        if (autostart_device((int)param) < 0) {
            tui_error("Cannot autostart device #%d", (int)param);
        }
    }

    return NULL;
}
Beispiel #8
0
static TUI_MENU_CALLBACK(set_romset_callback)
{
    if (been_activated) {
        if (machine_romset_file_load((char *)param) < 0) {
            tui_error("Could not load ROM set '%s'", param);
        } else {
            tui_message("ROM set loaded successfully.");
        }
    }
    return NULL;
}
Beispiel #9
0
static TUI_MENU_CALLBACK(save_settings_callback)
{
    if (been_activated) {
        if (resources_save(NULL) < 0) {
            tui_error("Cannot save settings.");
        } else {
            tui_message("Settings saved successfully.");
        }
    }

    return NULL;
}
Beispiel #10
0
static TUI_MENU_CALLBACK(load_settings_callback)
{
    if (been_activated) {
        if (resources_load(NULL) < 0) {
            tui_error("Cannot load settings.");
        } else {
            tui_message("Settings loaded successfully.");
            ui_update_menus();
        }
    }

    return NULL;
}
Beispiel #11
0
static void settimeout(time_t *value, const char *units, int allow_zero,
		       int *aborted)
{
	WINDOW *dlgwin;
	PANEL *dlgpanel;
	struct FIELDLIST field;
	time_t tmval = 0;

	dlgwin = newwin(7, 40, (LINES - 7) / 2, (COLS - 40) / 4);
	dlgpanel = new_panel(dlgwin);

	wattrset(dlgwin, DLGBOXATTR);
	tx_colorwin(dlgwin);
	tx_box(dlgwin, ACS_VLINE, ACS_HLINE);

	wattrset(dlgwin, DLGTEXTATTR);
	wmove(dlgwin, 2, 2);
	wprintw(dlgwin, "Enter value in %s", units);
	wmove(dlgwin, 5, 2);
	stdkeyhelp(dlgwin);

	tx_initfields(&field, 1, 10, (LINES - 7) / 2 + 3, (COLS - 40) / 4 + 2,
		      DLGTEXTATTR, FIELDATTR);
	tx_addfield(&field, 3, 0, 0, "");

	do {
		tx_fillfields(&field, aborted);

		if (!(*aborted)) {
			unsigned int tm;

			tmval = 0;
			int ret = strtoul_ui(field.list->buf, 10, &tm);
			if ((ret == -1) || (!allow_zero && (tm == 0)))
				tui_error(ANYKEY_MSG, "Invalid timeout value");
			else
				tmval = tm;
		}
	} while (((!allow_zero) && (tmval == 0)) && (!(*aborted)));

	if (!(*aborted))
		*value = tmval;

	del_panel(dlgpanel);
	delwin(dlgwin);

	tx_destroyfields(&field);
	update_panels();
	doupdate();
}
Beispiel #12
0
static TUI_MENU_CALLBACK(attach_tape_callback)
{
    const char *s;

    if (been_activated) {
        char *directory, *default_item;
        char *name, *file;

        s = tape_get_file_name();
        util_fname_split(s, &directory, &default_item);

        name = tui_file_selector("Attach a tape image", directory, "*.t64;*.tap;*.t6z;*.taz;*.zip;*.gz;*.lzh", default_item, tapecontents_read, &file, NULL);

        if (file != NULL) {
            if (autostart_tape(name, file, 0, AUTOSTART_MODE_RUN) < 0) {
                tui_error("Cannot autostart tape image.");
            } else {
                *behavior = TUI_MENU_BEH_RESUME;
            }
            lib_free(file);
        } else if (name != NULL && (s == NULL || strcasecmp(s, name) != 0) && tape_image_attach(1, name) < 0) {
            tui_error("Invalid tape image.");
        }
        ui_update_menus();
        lib_free(directory);
        lib_free(default_item);
        lib_free(name);
    }

    s = tape_get_file_name();
    if (s == NULL || *s == '\0') {
        return "(none)";
    } else {
        return s;
    }
}
Beispiel #13
0
static TUI_MENU_CALLBACK(attach_cartridge_callback)
{
    if (been_activated) {
        char *name;
        int type = (int)param;

        name = tui_file_selector("Attach cartridge image", NULL, "*", NULL, NULL, NULL, NULL);
        if (name != NULL && cartridge_attach_image(type, name) < 0) {
            tui_error("Invalid cartridge image.");
        }
        ui_update_menus();
        lib_free(name);
    }

    return NULL;
}
Beispiel #14
0
void definefilter(int *aborted)
{
	struct filterfileent ffile;
	char fntemp[14];
	struct filterlist fl;

	int pfd;
	int bw;

	get_filter_description(ffile.desc, aborted, "");

	if (*aborted)
		return;

	genname(time(NULL), fntemp);

	pfd =
	    open(get_path(T_WORKDIR, fntemp), O_CREAT | O_WRONLY | O_TRUNC,
		 S_IRUSR | S_IWUSR);
	if (pfd < 0) {
		tui_error(ANYKEY_MSG, "Cannot create filter data file");
		*aborted = 1;
		return;
	}

	close(pfd);

	pfd =
	    open(OTHIPFLNAME, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);

	if (pfd < 0) {
		listfileerr(1);
		return;
	}
	strcpy(ffile.filename, fntemp);
	bw = write(pfd, &ffile, sizeof(struct filterfileent));
	if (bw < 0)
		listfileerr(2);

	close(pfd);

	init_filter_table(&fl);
	modify_host_parameters(&fl);
	savefilter(get_path(T_WORKDIR, fntemp), &fl);
	destroyfilter(&fl);
}
Beispiel #15
0
static TUI_MENU_CALLBACK(custom_palette_callback)
{
    char *resource = (char *)param;

    if (been_activated) {
        char *name;

        name = tui_file_selector("Load custom palette", NULL, "*.vpl", NULL, NULL, NULL, NULL);

        if (name != NULL) {
            if (resources_set_string(resource, name) < 0) {
                tui_error("Invalid palette file");
            }
            ui_update_menus();
            lib_free(name);
        }
    }
    return NULL;
}
Beispiel #16
0
void savefilter(char *filename, struct filterlist *fl)
{
	struct filterent *fe = fl->head;
	int pfd;
	int bw;

	pfd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);

	while (fe != NULL) {
		bw = write(pfd, &(fe->hp), sizeof(struct hostparams));

		if (bw < 0) {
			tui_error(ANYKEY_MSG, "Unable to save filter changes");
			return;
		}
		fe = fe->next_entry;
	}

	close(pfd);
}
Beispiel #17
0
static TUI_MENU_CALLBACK(attach_cartridge_callback)
{
    if (been_activated) {
        char *default_item, *directory;
        char *name;
        const char *s, *filter;
        int type = (int)param;

        s = cartridge_get_file_name((WORD)0);
        util_fname_split(s, &directory, &default_item);

        filter = (type == CARTRIDGE_CRT) ? "*.crt" : "*";

        name = tui_file_selector("Attach cartridge image", directory, filter, default_item, NULL, NULL, NULL);
        if (name != NULL && (s == NULL || strcasecmp(name, s) != 0) && cartridge_attach_image(type, name) < 0) {
            tui_error("Invalid cartridge image.");
        }
        ui_update_menus();
        lib_free(name);
    }

    return NULL;
}
Beispiel #18
0
static void initiflist(struct iflist **list)
{
	char ifname[IFNAMSIZ];

	*list = NULL;

	FILE *fd = open_procnetdev();
	if (fd == NULL) {
		tui_error(ANYKEY_MSG, "Unable to obtain interface list");
		return;
	}

	while (get_next_iface(fd, ifname, sizeof(ifname))) {
		if (!*ifname)
			continue;

		if (ifinlist(*list, ifname))	/* ignore entry if already in */
			continue;	/* interface list */

		/*
		 * Check if the interface is actually up running.  This prevents
		 * inactive devices in /proc/net/dev from actually appearing in
		 * interface lists used by IPTraf.
		 */

		if (!dev_up(ifname))
			continue;

		int ifindex = dev_get_ifindex(ifname);
		if (ifindex < 0)
			continue;
		/*
		 * At this point, the interface is now sure to be up and running.
		 */

		struct iflist *itmp = xmallocz(sizeof(struct iflist));
		strcpy(itmp->ifname, ifname);
		itmp->ifindex = ifindex;
		rate_init(&itmp->rate, 5);

		/* make the linked list sorted by ifindex */
		struct iflist *cur = *list, *last = NULL;
		while (cur != NULL && cur->ifindex < ifindex) {
			last = cur;
			cur = cur->next_entry;
		}
		itmp->prev_entry = last;
		itmp->next_entry = cur;
		if (cur)
			cur->prev_entry = itmp;
		if (last)
			last->next_entry = itmp;
		else
			*list = itmp;
	}
	fclose(fd);

	/* let the index follow the sorted linked list */
	unsigned int index = 1;
	struct iflist *cur;
	for (cur = *list; cur != NULL; cur = cur->next_entry)
		cur->index = index++;
}
Beispiel #19
0
void setoptions(struct OPTIONS *options, struct porttab **ports)
{
	int row = 1;
	int trow = 1;		/* row for timer submenu */
	int aborted;

	struct MENU menu;
	struct MENU timermenu;

	WINDOW *statwin;
	PANEL *statpanel;

	if (!is_first_instance) {
		tui_error(ANYKEY_MSG,
			  "Only the first instance of ipraf-ng"
			  " can configure");
		return;
	}
	makeoptionmenu(&menu);

	statwin = newwin(15, 35, (LINES - 19) / 2 - 1, (COLS - 40) / 16 + 40);
	statpanel = new_panel(statwin);

	wattrset(statwin, BOXATTR);
	tx_colorwin(statwin);
	tx_box(statwin, ACS_VLINE, ACS_HLINE);
	wmove(statwin, 9, 1);
	whline(statwin, ACS_HLINE, 33);
	mvwprintw(statwin, 0, 1, " Current Settings ");
	wattrset(statwin, STDATTR);
	mvwprintw(statwin, 1, 2, "Reverse DNS lookups:");
	mvwprintw(statwin, 2, 2, "Service names:");
	mvwprintw(statwin, 3, 2, "Promiscuous:");
	mvwprintw(statwin, 4, 2, "Color:");
	mvwprintw(statwin, 5, 2, "Logging:");
	mvwprintw(statwin, 6, 2, "Activity mode:");
	mvwprintw(statwin, 7, 2, "MAC addresses:");
	mvwprintw(statwin, 8, 2, "v6-in-v4 as IPv6:");
	mvwprintw(statwin, 10, 2, "TCP timeout:");
	mvwprintw(statwin, 11, 2, "Log interval:");
	mvwprintw(statwin, 12, 2, "Update interval:");
	mvwprintw(statwin, 13, 2, "Closed/idle persist:");
	showoptions(options, statwin);

	do {
		tx_showmenu(&menu);
		tx_operatemenu(&menu, &row, &aborted);

		switch (row) {
		case 1:
			options->revlook = ~(options->revlook);
			break;
		case 2:
			options->servnames = ~(options->servnames);
			break;
		case 3:
			options->promisc = ~(options->promisc);
			break;
		case 4:
			options->color = ~(options->color);
			break;
		case 5:
			options->logging = ~(options->logging);
			break;
		case 6:
			options->actmode = ~(options->actmode);
			break;
		case 7:
			options->mac = ~(options->mac);
			break;
		case 8:
			options->v6inv4asv6 = ~(options->v6inv4asv6);
			break;
		case 10:
			maketimermenu(&timermenu);
			trow = 1;
			do {
				tx_showmenu(&timermenu);
				tx_operatemenu(&timermenu, &trow, &aborted);

				switch (trow) {
				case 1:
					settimeout(&(options->timeout),
						   "minutes", DONT_ALLOW_ZERO,
						   &aborted);
					if (!aborted)
						updatetimes(options, statwin);
					break;
				case 2:
					settimeout(&(options->logspan),
						   "minutes", DONT_ALLOW_ZERO,
						   &aborted);
					if (!aborted) {
						options->logspan =
						    options->logspan * 60;
						updatetimes(options, statwin);
					}
					break;
				case 3:
					settimeout(&options->updrate, "seconds",
						   ALLOW_ZERO, &aborted);
					if (!aborted)
						updatetimes(options, statwin);
					break;
				case 4:
					settimeout(&options->closedint,
						   "minutes", ALLOW_ZERO,
						   &aborted);
					if (!aborted)
						updatetimes(options, statwin);
					break;
				}
			} while (trow != 6);

			tx_destroymenu(&timermenu);
			update_panels();
			doupdate();
			break;
		case 12:
			addmoreports(ports);
			break;
		case 13:
			removeaport(ports);
			break;
		case 15:
			manage_eth_desc(ARPHRD_ETHER);
			break;
		case 16:
			manage_eth_desc(ARPHRD_FDDI);
			break;
		}

		indicatesetting(row, options, statwin);
	} while (row != 18);

	tx_destroymenu(&menu);
	del_panel(statpanel);
	delwin(statwin);
	update_panels();
	doupdate();
}