我正在尝试为我们的防火墙创建一个报告功能。防火墙规则以 json 格式存储。
这是字符串的示例。
[{"id":1,"enabled":true,"description":"TEMP","matchers":{"javaClass":"java.util.LinkedList","list":[{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"1.1.1.1","matcherType":"DST_ADDR"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"80","matcherType":"DST_PORT"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"1,3,2","matcherType":"DST_INTF"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"2.2.2.2","matcherType":"SRC_ADDR"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"1,2,wan","matcherType":"SRC_INTF"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"UDP,TCP,any","matcherType":"PROTOCOL"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"svrbjgu","matcherType":"DIRECTORY_CONNECTOR_USERNAME"},{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"intern-it","matcherType":"DIRECTORY_CONNECTOR_GROUP"}]},"ruleId":5001,"javaClass":"com.untangle.node.firewall.FirewallRule","block":false,"log":true}]
我有 preg_match_all 过滤器:
preg_match_all('/\"description":"(.*?)\","matchers"/',$str,$description);
preg_match_all('/\"id":(.*?)\,"/',$str,$id);
preg_match_all('/\"ruleId":(.*?)\,"/',$str,$rule_id);
preg_match_all('/\"enabled":(.*?)\,"description"/',$str,$enable);
preg_match_all('/\"block":(.*?)\,"/',$str,$block);
preg_match_all('/\"log":(.*?)\}/',$str,$log);
preg_match_all('/\"value":"(.*?)\","matcherType":"DST_ADDR"/',$str,$dest_add);
preg_match_all('/\"value":"(.*?)\","matcherType":"DST_PORT"/',$str,$dest_port);
preg_match_all('/\"value":"(.*?)\","matcherType":"DST_INTF"/',$str,$dest_int);
preg_match_all('/\"value":"(.*?)\,","matcherType":"SRC_ADDR"/',$str,$src_add);
preg_match_all('/\"value":"(.*?)\","matcherType":"SRC_INTF"/',$str,$src_int);
preg_match_all('/\"value":"(.*?)\","matcherType":"PROTOCOL"/',$str,$protocol);
preg_match_all('/\"value":"(.*?)\","matcherType":"DIRECTORY_CONNECTOR_USERNAME"/',$str,$user);
preg_match_all('/\"value":"(.*?)\","matcherType":"DIRECTORY_CONNECTOR_GROUP"/',$str,$group);
发生的情况是每个匹配器的开始都是 VALUE":" 当我打印 $dest_port 我得到"1.1.1.1","matcherType":"DST_ADDR"},
{"invert":false,"javaClass":"com.untangle.node.firewall.FirewallRuleMatcher","value":"80 ” 而不是只有 80 个。
任何有 preg_match_all 的人先找到 matchertype,然后将 backwords 读取到“value”:“?
任何帮助都会很棒!