diff --git a/src/library/library.pro b/src/library/library.pro index e599734..769fca9 100644 --- a/src/library/library.pro +++ b/src/library/library.pro @@ -1,4 +1,4 @@ - +CONFIG += c++11 QT += core network TARGET=sysadm diff --git a/src/library/sysadm-firewall.cpp b/src/library/sysadm-firewall.cpp index faa20ce..e1a2213 100644 --- a/src/library/sysadm-firewall.cpp +++ b/src/library/sysadm-firewall.cpp @@ -6,6 +6,9 @@ #include "sysadm-firewall.h" #include +#include +#include + using namespace sysadm; PortInfo Firewall::LookUpPort(int portNumber, QString portType) { @@ -78,24 +81,19 @@ PortInfo Firewall::LookUpPort(int portNumber, QString portType) void Firewall::OpenPort(int port, QString type) { - openports << QString::number(port)+"::::"+type; + openports.append(LookUpPort(port,type)); SaveOpenPorts(); } void Firewall::ClosePort(int port, QString type) { - openports.removeAll( QString::number(port)+"::::"+type); + openports.removeAll(LookUpPort(port,type)); SaveOpenPorts(); } QVector Firewall::OpenPorts() { - QVector returnValue = QVector(openports.length()); - - for(int i=0; ireadLine(); //jump down past the comments - if(line[0] == '#') + if(line[0] == '#' || line.simplified().isEmpty()) continue; //remove all of the extraneous whitespace in the line @@ -183,20 +181,22 @@ void Firewall::LoadOpenPorts() QString line = in.readLine(); if(line.startsWith("#") || line.simplified().isEmpty()){ continue; } //File format: " " (nice and simple) - openports << line.section(" ",1,1)+"::::"+line.section(" ",0,0); + openports.append(LookUpPort(line.section(" ",1,1).toInt(),line.section(" ",0,0))); } file.close(); } - openports.sort(); //order them in ascending port order + //order them in ascending order by port then port type + std::sort(openports.begin(),openports.end()); } void Firewall::SaveOpenPorts() { //Convert to file format - openports.sort(); //make sure they are still sorted by port + std::sort(openports.begin(), openports.end()); //make sure they are still sorted by port QStringList fileout; for(int i=0; i(const PortInfo lhs, const PortInfo rhs) + { return rhs < lhs;} + friend bool operator==(const PortInfo lhs, const PortInfo rhs) + { + return lhs.Port == rhs.Port && lhs.PortType == rhs.PortType; + } + friend bool operator !=(const PortInfo lhs, const PortInfo rhs) + { return !(lhs == rhs);} }; const static int recommendedPorts[] = {22, 80}; @@ -91,7 +102,7 @@ private: void readServicesFile(); QStringList* portStrings; - QStringList openports; + QVector openports; void LoadOpenPorts(); void SaveOpenPorts();