Browse Source

add add IP address command

master
Brad Parker 11 years ago
parent
commit
81af4f74d6
  1. 45
      tui/main.cpp

45
tui/main.cpp

@ -2,6 +2,7 @@
#include <stdio.h>
#include <curses.h>
#include <QCoreApplication>
#include <QRegularExpression>
#include <interface.h>
#include <QStringList>
#include <QHash>
@ -203,6 +204,50 @@ void interfaceSelect(WINDOW *window, QString interface) {
if(c == 'q') {
quit(window);
exit(0);
}else if(c == 'a') {
wdeleteln(window);
mvwaddstr(window, y + 7, 2, "Enter IP address to add: ");
wrefresh(window);
char ipToAdd[19] = {0};
echo();
wgetnstr(window, ipToAdd, sizeof(ipToAdd) / sizeof(char) - 1);
noecho();
QString ip = ipToAdd;
if(!ip.contains(QRegularExpression("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([5-9]|[1-2][0-9]|3[0-2])$"))) {
msgbox("Invalid IP address. Please try again.");
interfaceSelect(window, interface);
return;
}
wdeleteln(window);
QString confirm = "Are you sure you want to add ";
confirm += ip;
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.addAddress(ip)) {
msgbox("Could not add IP address. Not enough permissions?");
}else{
msgbox("IP address added successfully.");
}
interfaceSelect(window, interface);
}else{
interfaceSelect(window, interface);
}
}else if(c == 'd') {
wdeleteln(window);
mvwaddstr(window, y + 7, 2, "Enter number of IP address to delete: ");

Loading…
Cancel
Save