Browse Source

allow deletion of IP addresses through TUI

master
Brad Parker 11 years ago
parent
commit
9177d2eeae
  1. 113
      tui/main.cpp

113
tui/main.cpp

@ -6,6 +6,8 @@
#include <QStringList> #include <QStringList>
#include <QHash> #include <QHash>
#define COLOR_DARK_GRAY 9
void red(WINDOW *window) { void red(WINDOW *window) {
wattron(window, COLOR_PAIR(1)); wattron(window, COLOR_PAIR(1));
} }
@ -22,6 +24,39 @@ void magenta(WINDOW *window) {
wattron(window, COLOR_PAIR(6)); wattron(window, COLOR_PAIR(6));
} }
void quit(WINDOW *window) {
delwin(window);
endwin();
}
void msgbox(const char *text) {
//WINDOW *msgbox = newwin(LINES / 2, COLS / 2, LINES / 4, COLS / 4);
WINDOW *msgbox = newwin(8, COLS / 2, LINES / 4, COLS / 4);
wbkgd(msgbox, COLOR_PAIR(8));
box(msgbox, 0, 0);
mvwaddstr(msgbox, 1, 2, text);
move(3, 5);
wrefresh(msgbox);
WINDOW *ok = derwin(msgbox, 3, 6, msgbox->_maxy / 2 + 1, msgbox->_maxx / 2);
box(ok, 0, 0);
wattron(ok, COLOR_PAIR(5));
mvwaddstr(ok, 1, 2, "OK");
touchwin(msgbox);
wrefresh(ok);
check_return:
char c = getch();
if(c != '\r') {
goto check_return;
}
delwin(ok);
delwin(msgbox);
}
void interfaceMenu(WINDOW *window); void interfaceMenu(WINDOW *window);
void interfaceSelect(WINDOW *window, QString interface); void interfaceSelect(WINDOW *window, QString interface);
@ -29,16 +64,14 @@ void mainmenu(WINDOW *window) {
wclear(window); wclear(window);
cyan(window); cyan(window);
box(window, 0 , 0); box(window, 0, 0);
red(window); red(window);
mvwaddstr(window, 1, 2, "System Configuration:"); mvwaddstr(window, 1, 2, "System Configuration:");
green(window); green(window);
mvwaddstr(window, 3, 2, "1. Interfaces"); mvwaddstr(window, 3, 2, "1. Interfaces");
mvwaddstr(window, 4, 2, "2. ARP"); mvwaddstr(window, 4, 2, "2. ARP");
mvwaddstr(window, 5, 2, "3. Wireless"); mvwaddstr(window, 5, 2, "3. Wireless");
cyan(window); cyan(window);
@ -64,7 +97,7 @@ void interfaceMenu(WINDOW *window) {
wclear(window); wclear(window);
cyan(window); cyan(window);
box(window, 0 , 0); box(window, 0, 0);
red(window); red(window);
mvwaddstr(window, 1, 2, "Interfaces:"); mvwaddstr(window, 1, 2, "Interfaces:");
@ -120,7 +153,7 @@ void interfaceSelect(WINDOW *window, QString interface) {
wclear(window); wclear(window);
cyan(window); cyan(window);
box(window, 0 , 0); box(window, 0, 0);
red(window); red(window);
QString title = QString("IP Addresses on: ") + interface; QString title = QString("IP Addresses on: ") + interface;
@ -148,17 +181,72 @@ void interfaceSelect(WINDOW *window, QString interface) {
++count; ++count;
} }
if(count == 1) {
mvwaddstr(window, y, 2, "No IP addresses found.");
++y;
}
cyan(window); cyan(window);
mvwaddstr(window, y + 1, 2, "0. Back to interfaces"); mvwaddstr(window, y + 1, 2, "0. Back to interfaces");
magenta(window); magenta(window);
mvwaddstr(window, y + 3, 2, "Enter selection: "); mvwaddstr(window, y + 3, 2, "a. Add IP address");
mvwaddstr(window, y + 4, 2, "d. Delete IP address");
mvwaddstr(window, y + 5, 2, "q. Quit");
mvwaddstr(window, y + 7, 2, "Enter selection: ");
wrefresh(window); wrefresh(window);
char c = getch(); char c = getch();
if(c < '0' || c > '3') { if(c < '0' || c > (count + '0' - 1)) {
interfaceMenu(window); if(c == 'q') {
quit(window);
exit(0);
}else if(c == 'd') {
wdeleteln(window);
mvwaddstr(window, y + 7, 2, "Enter number of IP address to delete: ");
wrefresh(window);
char ipToDelete = getch();
if(ipToDelete < '1' || ipToDelete > '9') {
interfaceSelect(window, interface);
return;
}
if(!(ipList.count() >= ipToDelete - '0')) {
interfaceSelect(window, interface);
return;
}
wdeleteln(window);
QString confirm = "Are you sure you want to delete ";
confirm += ipList[ipToDelete - '0' - 1];
confirm += " [y/n]? ";
QByteArray arr = confirm.toLatin1();
const char *confirmStr = arr.constData();
mvwaddstr(window, y + 7, 2, confirmStr);
wrefresh(window);
c = getch();
if(c == 'y') {
if(obj.deleteAddress(ipList[ipToDelete - '0' - 1])) {
msgbox("Could not delete IP address. Not enough permissions?");
}else{
msgbox("IP address deleted successfully.");
}
interfaceSelect(window, interface);
}else{
interfaceSelect(window, interface);
}
}else{
interfaceSelect(window, interface);
}
}else{ }else{
if(c == '0') { if(c == '0') {
interfaceMenu(window); interfaceMenu(window);
@ -185,6 +273,8 @@ int main(int argc, char *argv[]) {
* pair as for the foreground color, though of course that is not * pair as for the foreground color, though of course that is not
* necessary: * necessary:
*/ */
//init_color(COLOR_DARK_GRAY, 256, 256, 256);
init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK);
@ -192,6 +282,8 @@ int main(int argc, char *argv[]) {
init_pair(5, COLOR_CYAN, COLOR_BLACK); init_pair(5, COLOR_CYAN, COLOR_BLACK);
init_pair(6, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
init_pair(7, COLOR_WHITE, COLOR_BLACK); init_pair(7, COLOR_WHITE, COLOR_BLACK);
init_pair(8, COLOR_WHITE, COLOR_BLUE);
//init_pair(9, COLOR_WHITE, COLOR_GREEN);
}else{ }else{
printf("Your terminal does not support colors\n"); printf("Your terminal does not support colors\n");
return 1; return 1;
@ -203,10 +295,7 @@ int main(int argc, char *argv[]) {
mainmenu(window); mainmenu(window);
delwin(window); quit(window);
endwin();
/*int ret = app.exec(); /*int ret = app.exec();
return ret;*/ return ret;*/

Loading…
Cancel
Save