From 6b348c3940c3b87dd3a4d6f9393c690a8907d4b7 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 12 Sep 2016 15:21:02 -0400 Subject: [PATCH] API CHANGE: Add a new "action" for the new sysadm/firewall class: "action":"list_open" Returns an array of all the open port/type combinations for the firewall. REST Request (example): ------------------------------- PUT /sysadm/firewall { "action" : "list_open" } WebSocket Request: ------------------------------- { "args" : { "action" : "list_open" }, "id" : "fooid", "name" : "firewall", "namespace" : "sysadm" } Response: ------------------------------- { "args": { "openports": [ "5353/udp" ] }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 9 +++++++++ src/server/library/sysadm-firewall.cpp | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 79d68e7..e66954a 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -1121,6 +1121,15 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmFirewallRequest(const QJsonV } out->insert(obj.value("port").toString(), obj); //use the port number/type as the unique identifier } + + }else if(action=="list_open"){ + ok = true; + QList all = FMGR.OpenPorts(); //this is all ports currently opened + QStringList oports; + for(int i=0; iinsert("openports", QJsonArray::fromStringList(oports)); } diff --git a/src/server/library/sysadm-firewall.cpp b/src/server/library/sysadm-firewall.cpp index 0044729..c972ff9 100644 --- a/src/server/library/sysadm-firewall.cpp +++ b/src/server/library/sysadm-firewall.cpp @@ -211,6 +211,7 @@ void Firewall::readServicesFile() QList Firewall::LoadOpenPorts() { + //qDebug() << "Read open ports"; QList openports; QFile file("/etc/ipfw.openports"); if( file.open(QIODevice::ReadOnly) ){ @@ -219,13 +220,13 @@ QList Firewall::LoadOpenPorts() QString line = in.readLine(); if(line.startsWith("#") || line.simplified().isEmpty()){ continue; } //File format: " " (nice and simple) - openports << LookUpPort(line.section(" ",1,1).toInt(),line.section(" ",0,0)); + //qDebug() << "Found Port:" << line; + openports << LookUpPort(line.section(" ",1,1).toInt() ,line.section(" ",0,0)); } file.close(); } - //order them in ascending order by port then port type - std::sort(openports.begin(),openports.end()); - + //qDebug() << "Finished with open ports"; + return openports; } void Firewall::SaveOpenPorts(QList openports)