📄 fltedit.c
字号:
spanel = new_panel(swin); wattrset(swin, DLGTEXTATTR); scrollok(swin, 0); sprintf(sp_buf, "%%%dc", COLS); mvwprintw(swin, 0, 0, sp_buf, ' '); } wattrset(bwin, BOXATTR); box(bwin, ACS_VLINE, ACS_HLINE); if (protocol != F_OTHERIP) { mvwprintw(bwin, 0, 2, " First Host/Mask:Port "); mvwprintw(bwin, 0, 38, " Second Host/Mask:Port "); mvwprintw(bwin, 0, 74, " I/E "); } else { mvwprintw(bwin, 0, 2, " Source Host/Mask "); mvwprintw(bwin, 0, 38, " Destination Host/Mask "); mvwprintw(bwin, 0, 74, "I/E"); wattrset(bwin, BOXATTR); } wmove(bwin, 14, 1); if (protocol == F_TCP) wprintw(bwin, " TCP"); else if (protocol == F_UDP) wprintw(bwin, " UDP"); else wprintw(bwin, " Misc IP"); wprintw(bwin, " Filter Data "); tx_stdwinset(win); scrollok(win, 0); wattrset(win, STDATTR); tx_colorwin(win); move(LINES - 1, 1); tx_printkeyhelp("Up/Down", "-move ptr ", stdscr, HIGHATTR, STATUSBARATTR); tx_printkeyhelp("I", "-insert ", stdscr, HIGHATTR, STATUSBARATTR); tx_printkeyhelp("A", "-add to list ", stdscr, HIGHATTR, STATUSBARATTR); tx_printkeyhelp("D", "-delete ", stdscr, HIGHATTR, STATUSBARATTR); tx_printkeyhelp("Enter", "-edit ", stdscr, HIGHATTR, STATUSBARATTR); tx_printkeyhelp("X/Ctrl+X", "-exit", stdscr, HIGHATTR, STATUSBARATTR); update_panels(); doupdate(); firstvisible = fl->head; update_hp_screen(protocol, fl, firstvisible, win); idx = 0; fe = firstvisible; update_panels(); doupdate(); do { if (fe != NULL) { print_hostparam_line(protocol, fe, idx, win, BARSTDATTR); if (protocol == F_OTHERIP) { show_matched_protocols(swin, fe); update_panels(); doupdate(); } } ch = wgetch(win); if (fe != NULL) print_hostparam_line(protocol, fe, idx, win, STDATTR); switch (ch) { case KEY_UP: if (fl->head != NULL) { if (fe->prev_entry != NULL) { if (idx > 0) idx--; else { scrollok(win, 1); wscrl(win, -1); firstvisible = firstvisible->prev_entry; } fe = fe->prev_entry; } } break; case KEY_DOWN: if (fl->head != NULL) { if (fe->next_entry != NULL) { if (idx < 12) idx++; else { scrollok(win, 1); wscrl(win, 1); firstvisible = firstvisible->next_entry; } fe = fe->next_entry; } } break; case 'i': case 'I': case KEY_IC: if (!new_hp_entry(&ftemp)) break; if (protocol != F_OTHERIP) gethostparams(&(ftemp->un.hp), &gh_aborted, "", "", "", "0.0.0.0", "0.0.0.0", "0", "I"); else get_othip_hostparams(&(ftemp->un.othipdata), "", "", "0.0.0.0", "0.0.0.0", &gh_aborted); if (gh_aborted) { free(ftemp); continue; } if (fl->head == NULL) { ftemp->next_entry = ftemp->prev_entry = NULL; fl->head = fl->tail = ftemp; firstvisible = fl->head; idx = 0; } else { ftemp->next_entry = fe; ftemp->prev_entry = fe->prev_entry; /* * Point firstvisible at new entry if we inserted at the * top of the list. */ if (ftemp->prev_entry == NULL) { fl->head = ftemp; firstvisible = ftemp; } else fe->prev_entry->next_entry = ftemp; fe->prev_entry = ftemp; } if (ftemp->next_entry == NULL) fl->tail = ftemp; fe = ftemp; update_hp_screen(protocol, fl, firstvisible, win); break; case 'a': case 'A': case 1: if (!new_hp_entry(&ftemp)) break; if (protocol != F_OTHERIP) gethostparams(&(ftemp->un.hp), &gh_aborted, "", "", "", "0.0.0.0", "0.0.0.0", "0", "I"); else get_othip_hostparams(&(ftemp->un.othipdata), "", "", "0.0.0.0", "0.0.0.0", &gh_aborted); if (gh_aborted) { free(ftemp); continue; } /* * Add new node to the end of the list (or to the head if the * list is empty. */ if (fl->tail != NULL) { fl->tail->next_entry = ftemp; ftemp->prev_entry = fl->tail; } else { fl->head = ftemp; fl->tail = ftemp; ftemp->prev_entry = ftemp->next_entry = NULL; firstvisible = fl->head; fe = ftemp; idx = 0; } ftemp->next_entry = NULL; fl->tail = ftemp; update_hp_screen(protocol, fl, firstvisible, win); break; case 'd': case 'D': case KEY_DC: if (fl->head != NULL) { /* * Move firstvisible down if it's pointing to the target * entry. */ if (firstvisible == fe) firstvisible = fe->next_entry; /* * Detach target node from list. */ if (fe->next_entry != NULL) fe->next_entry->prev_entry = fe->prev_entry; else fl->tail = fe->prev_entry; if (fe->prev_entry != NULL) fe->prev_entry->next_entry = fe->next_entry; else fl->head = fe->next_entry; /* * Move pointer up if we're deleting the last entry. * The list tail pointer has since been moved to the * previous entry. */ if (fe->prev_entry == fl->tail) { ftemp = fe->prev_entry; /* * Move screen pointer up. Really adjust the index if * the pointer is anywhere below the top of the screen. */ if (idx > 0) idx--; else { /* * Otherwise scroll the list down, and adjust the * firstvisible pointer to point to the entry * previous to the target. */ if (ftemp != NULL) { firstvisible = ftemp; } } } else /* * If we reach this point, we're deleting from before * the tail of the list. In that case, we point the * screen pointer at the entry following the target. */ ftemp = fe->next_entry; free(fe); fe = ftemp; update_hp_screen(protocol, fl, firstvisible, win); } break; case 13: if (fe != NULL) { if (protocol != F_OTHERIP) { sprintf(s_portstr, "%u", fe->un.hp.sport); sprintf(d_portstr, "%u", fe->un.hp.dport); inexstr[0] = toupper(fe->un.hp.reverse); inexstr[1] = '\0'; gethostparams(&(hptemp.ut_hp), &gh_aborted, fe->un.hp.s_fqdn, fe->un.hp.s_mask, s_portstr, fe->un.hp.d_fqdn, fe->un.hp.d_mask, d_portstr, inexstr); if (!gh_aborted) memcpy(&(fe->un.hp), &(hptemp.ut_hp), sizeof(struct hostparams)); } else { memcpy(&(hptemp.othip_data), &(fe->un.othipdata), sizeof(struct othipfltdata)); get_othip_hostparams(&(hptemp.othip_data), fe->un.othipdata.hp.s_fqdn, fe->un.othipdata.hp.s_mask, fe->un.othipdata.hp.d_fqdn, fe->un.othipdata.hp.d_mask, &gh_aborted); if (!gh_aborted) memcpy(&(fe->un.othipdata), &(hptemp.othip_data), sizeof(struct othipfltdata)); } update_hp_screen(protocol, fl, firstvisible, win); } break; case 'x': case 'X': case 'q': case 'Q': case 27: case 24: endloop_local = 1; break; case 'l': case 'L': tx_refresh_screen(); break; } update_panels(); doupdate(); } while (!endloop_local); if (protocol == F_OTHERIP) { del_panel(spanel); delwin(swin); } del_panel(panel); delwin(win); del_panel(bpanel); delwin(bwin); update_panels(); doupdate();}/* * Edit an existing filter */void editfilter(unsigned int protocol, int *aborted){ char filename[FLT_FILENAME_MAX]; struct filterlist fl; struct ffnode *flist; struct ffnode *ffile; struct filterfileent *ffe; if (!mark_filter_change(protocol)) return; if (loadfilterlist(protocol, &flist) == 1) { listfileerr(1); destroyfilterlist(flist); clear_flt_tag(protocol); return; } pickafilter(flist, &ffile, aborted); clear_flt_tag(protocol); if ((*aborted)) { destroyfilterlist(flist); clear_flt_tag(protocol); return; } ffe = &(ffile->ffe); get_filter_description(ffe->desc, aborted, ffe->desc); if (*aborted) { destroyfilterlist(flist); clear_flt_tag(protocol); return; } strncpy(filename, get_path(T_WORKDIR, ffe->filename), FLT_FILENAME_MAX - 1); if (loadfilter(protocol, filename, &fl, FLT_DONTRESOLVE)) return; modify_host_parameters(protocol, &fl); save_filterlist(protocol, flist); /* This also destroys it */ savefilter(protocol, filename, &fl); destroyfilter(&fl);}/* * Delete a filter record from the disk */void delfilter(unsigned int protocol, int *aborted){ struct ffnode *fltfile; struct ffnode *fltlist; if (!mark_filter_change(protocol)) return; if (loadfilterlist(protocol, &fltlist) == 1) { *aborted = 1; listfileerr(1); destroyfilterlist(fltlist); clear_flt_tag(protocol); return; } pickafilter(fltlist, &fltfile, aborted); if (*aborted) { clear_flt_tag(protocol); return; } unlink(get_path(T_WORKDIR, fltfile->ffe.filename)); if (fltfile->prev_entry == NULL) { fltlist = fltlist->next_entry; if (fltlist != NULL) fltlist->prev_entry = NULL; } else { fltfile->prev_entry->next_entry = fltfile->next_entry; if (fltfile->next_entry != NULL) fltfile->next_entry->prev_entry = fltfile->prev_entry; } free(fltfile); save_filterlist(protocol, fltlist); clear_flt_tag(protocol); *aborted = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -