0

What kind of format is the below code written in and how do I get Python to interpret it? It's labeled as a policy file for firewall rules deployment.

#include '../../subnets/OFFICE_NETWORKS.inc'
term allow-internetwork-traffic {
    source-address:: SOURCE_ADDRESSES
    destination-address:: DESTINATION_ADDRESSES
    protocol:: tcp
    action:: accept
    counter:: allow.internetwork.traffic
}

term deny-to-accounting {
    source-address:: OFFICE_USERS
    destination-address:: ACCOUNTING_NETWORK
    destination-port:: TCP_8080
    protocol:: tcp
    logging:: true
    action:: deny
    counter:: deny.to.accounting
}
  • 1
    It looks similar to a dictionary but not exactly. It's got double colons. Not sure what the 'term' is or how it's read. – python_newbie Apr 08 '20 at 02:02
  • If its written in file then you will read it with open function and ultimately it will be interpreted as string in python. Question is what you actually want to do with it? – Jaskaran Singh Apr 08 '20 at 03:32
  • How would I read each term and "key" as a string? Is there an easier way than to parse this as plain text? – superloopnetworks Apr 08 '20 at 03:51
  • Do you know which firewall it is for? One hacky thing that you could try is to use a CSS parser to import it. – Joe Apr 08 '20 at 04:43
  • https://stackoverflow.com/a/11685846/7919597 – Joe Apr 08 '20 at 04:43
  • https://www.w3schools.com/html/html_css.asp – Joe Apr 08 '20 at 04:43
  • You might have to replace the `::` with a single `:` and append `;` to the end of a line. Not sure if that is enforced by CSS. – Joe Apr 08 '20 at 04:44
  • Also the comment line in the beginning needs to be removed. – Joe Apr 08 '20 at 04:50
  • You could also try to find out which firewall it is. There are other related pages for this https://security.stackexchange.com/ or https://serverfault.com/ or https://superuser.com/ – Joe Apr 08 '20 at 04:58
  • If you are lucky there is a parser available, maybe in C or something else that you could run from Python or wrap, e.g. with CFFI. – Joe Apr 08 '20 at 04:59

0 Answers0