## ------------------------------------------------------------------------
## PySilk - A python-based graphical user interface for SiLK
## ------------------------------------------------------------------------
## Copyright (c) 2007-2008 Carnegie Mellon University. All Rights Reserved.
## ------------------------------------------------------------------------
## Authors: Andrew Kompanek (ajk@cert.org)
## ------------------------------------------------------------------------
## GNU General Public License (GPL) Rights pursuant to Version 2, June 1991
## Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013
## ------------------------------------------------------------------------
## See LICENSE file included in this distribution
## ------------------------------------------------------------------------

import wx
import os
import logging
import config
from config import _xml_read_site_config
from config import _xml_save_site_config

opts = {}

def init(readOptions=True):
    global opts
    opts["RECVIEW_SHOW_NAMES"] = False
    opts["RECVIEW_SHOW_HOSTNAMES"] = True
    opts["RECVIEW_HIDE_COLUMNS"] = ["nhip", "class", "icmp_type", "icmp_code",
        "scc", "dcc", "sval", "dval"]
    opts["PROTO_NAMES"] = DEFAULT_PROTO_NAMES
    opts["PORT_NAMES"] = DEFAULT_PORT_NAMES
    if readOptions:
        _read_options()
        
def getPortName(port, default):
    global opts
    return opts["PORT_NAMES"].get(port, default)
    
def getProtoName(proto, default):
    global opts
    return opts["PROTO_NAMES"].get(proto, default)    
    
def _save_options():
    global opts
    _xml_save_site_config("recordview", opts)
    
def _read_options():
    global opts
    try:
        opts = _xml_read_site_config("recordview")
        return opts
    except IOError:
        return  None
        
DEFAULT_PROTO_NAMES = {
    "1"  : "ICMP",
    "6"  : "TCP",
    "17" : "UDP"
}

DEFAULT_PORT_NAMES = {
    "80"   : "http (80)",
    "8080" : "http (8080)",
    "443"  : "https (443)",
    "25"   : "smtp (25)",
    "53"   : "dns (53)",
    "22"   : "ssh (22)",
    "23"   : "telnet (23)",
    "19"   : "nntmp (19)"
}



