#!/usr/bin/python3
import json
import os
path="/etc/config/settings.json"
settings_file=open(path, "r")
config=settings_file.read()
config_json=json.loads(config)
interfaces=config_json["network"]["interfaces"]

for x in interfaces:
 type=x["type"]
 if type == "IPSEC":
  right=x["ipsec"]["remote"]["gateway"]
  role="Initiator"
  tunnel=x["device"]
  if right == "%any":
   role="Responder"
  print("Tunnel {} role: {}".format(tunnel,role))
