mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
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"
}
This commit is contained in:
@@ -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<sysadm::PortInfo> all = FMGR.OpenPorts(); //this is all ports currently opened
|
||||
QStringList oports;
|
||||
for(int i=0; i<all.length(); i++){
|
||||
oports << QString::number(all[i].Port)+"/"+all[i].Type;
|
||||
}
|
||||
out->insert("openports", QJsonArray::fromStringList(oports));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@ void Firewall::readServicesFile()
|
||||
|
||||
QList<PortInfo> Firewall::LoadOpenPorts()
|
||||
{
|
||||
//qDebug() << "Read open ports";
|
||||
QList<PortInfo> openports;
|
||||
QFile file("/etc/ipfw.openports");
|
||||
if( file.open(QIODevice::ReadOnly) ){
|
||||
@@ -219,13 +220,13 @@ QList<PortInfo> Firewall::LoadOpenPorts()
|
||||
QString line = in.readLine();
|
||||
if(line.startsWith("#") || line.simplified().isEmpty()){ continue; }
|
||||
//File format: "<type> <port>" (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<PortInfo> openports)
|
||||
|
||||
Reference in New Issue
Block a user