from xml.etree import ElementTree as Elem
import os.path
from tkinter.filedialog import askopenfilename, asksaveasfilename, Tk
window = Tk()
window.withdraw()
window.focus_force()

# tree = Elem.parse("C:\\Users\\Jason\\Desktop\\bi-dir-test.xml")
tree = Elem.parse(
    askopenfilename(initialdir=os.path.expanduser("~/Desktop"),
                    title="Select Palo Alto xml configuration file."))
# root_tree = tree.getroot()

nat_dict = {}
nat_policy_count = 0
for elem in tree.iter(tag="nat"):
    for rules in elem:
        for entry in rules:
            nat_policy_count += 1
            rule_dic = {"bi_d": 'no'}
            # print(entry.tag, entry.attrib)
            nat_dict[entry.attrib["name"]] = rule_dic

            for member in entry.find("source"):
                nat_dict[entry.attrib["name"]]["source"] = member.text
                # print(member.text)

            for member in entry.find("destination"):
                nat_dict[entry.attrib["name"]]["destination"] = member.text
                # print(member.text)
import csv
import datetime
import os
import openpyxl
from openpyxl.styles import Font, PatternFill
from tkinter.filedialog import askopenfilename, asksaveasfilename, Tk
# from tkinter import messagebox
# Tk().withdraw()  # Prevents tkinter window from opening
root = Tk()
root.withdraw()
root.focus_force()
now = datetime.datetime.now().strftime("%m/%d/%Y")


def mode_1_import():
    """

    :return: dictionary {rulename: [set(apps), set(dest_port/protocol), hit value(T/F)]
    """
    rules_dict = None  # Eliminates Pycharm Error
    unk_tu_dict = {}  # dict for unknown tcp and udp log entries
    # parse ruleset and get rule names and details
    try:
        with open(
                askopenfilename(
                    initialdir=os.path.expanduser("~/Desktop"),
                    title=
                    "Select Security Rules CSV exported from Palo Alto firewall."
                )) as rules_file:
            # with open("C:\\Users\\Jason\\Desktop\\policies.csv") as rules_file: