I have a firewall configuration file that goes like this:
{
"javaClass": "some text",
"rules": {
"javaClass": "java.util.LinkedList",
"list": [
{
"block": true,
"conditions": {
"javaClass": "java.util.LinkedList",
"list": [
{
"conditionType": "DST_PORT",
"invert": false,
"javaClass": "some text",
"value": "21"
}
]
},
"description": "Block and flag all traffic destined to port 21",
"enabled": false,
"flag": true,
"javaClass": "some text",
"ruleId": 100018
},
{
"block": true,
"conditions": {
"javaClass": "java.util.LinkedList",
"list": [
{
"conditionType": "SRC_ADDR",
"invert": false,
"javaClass": "some text",
"value": "1.2.3.4/255.255.255.0"
}
]
},
"description": "Block and flag all TCP traffic from 1.2.3.0 netmask 255.255.255.0",
"enabled": false,
"flag": true,
"javaClass": "some text",
"ruleId": 100019
},
{
"block": true,
"conditions": {
"javaClass": "java.util.LinkedList",
"list": [
{
"conditionType": "DST_ADDR",
"invert": false,
"javaClass": "some text",
"value": "1.2.3.4/255.255.255.0"
},
{
"conditionType": "DST_PORT",
"invert": false,
"javaClass": "some text",
"value": "1000-5000"
}
]
},
"description": "Accept and flag all traffic to the range 1.2.3.1 - 1.2.3.10 to ports 1000-5000",
"enabled": false,
"flag": true,
"javaClass": "some text",
"ruleId": 100020
}
]
},
"version": 1
}
I'm trying to extract the list
part, then, extract parts of it for storing the data.
Now, I'm able to load the whole file using myConfigDetails.Text = File.ReadAllLines("firewall.settings_9.js");
, but I'm unable to extract the data I want .. The rule can have no conditions, single conditions or multiple conditions ...
I created the class below to store the data in temporarily for further usage:
public class fwDATA
{
public string ruleID;
public bool ruleBlock;
public string ruleValue;
public string ruleDesc;
public bool ruleEnabled;
public bool ruleFlag;
}
Can someone guide me to the correct way to extract the list parts (both the rule and conditions)
Parts I need:
- "block"
- "conditionType"
- "value"
- "description"
- "enabled"
- "flag"
- "ruleId"