Esempio n. 1
0
 def __init__(self, filename, requests_and_responses=False):
     self._filename = filename
     self._requests_and_responses = requests_and_responses
     json_ext = '.json'
     yaml_ext = '.yaml'
     if filename[-len(json_ext):] == json_ext:
         self._scan = json.loads(open(filename).read().decode('utf-8-sig'),
                                 object_pairs_hook=UnsortableOrderedDict)
     elif filename[-len(yaml_ext):] == yaml_ext:
         self._scan = yaml_load(
             open(filename).read(), yaml.SafeLoader, UnsortableOrderedDict)
     else:
         # xml
         #self._xml = etree.parse(filename)
         etree_parser = etree.XMLParser(huge_tree=True)
         self._xml = etree.parse(filename, parser=etree_parser)
         root = self._xml.getroot()
         if root.tag == 'Sessions':
             self._webinspect_import()
         elif root.tag == 'issues':
             self._burp_import()
         elif root.tag == 'items':
             self._burp_items_import()
         else:
             raise Exception('Unknown scan format!')
Esempio n. 2
0
 def Load(self, content, expand=True):
     if content == None:
         return
     if isinstance(content, UnsortableOrderedDict):
         data = content
         self.filename = None
         self.file_changed = None
     else:
         data = yaml_load(open(content).read(), yaml.SafeLoader, UnsortableOrderedDict)
         self.filename = os.path.abspath(content)
         self.file_changed = False
     self.orig = data
     #print data
     #print yaml.dump(data, default_flow_style=False, allow_unicode=True).decode('utf-8').encode('utf-8')
     def walk(data, parent=None, level=0):
         #print level, data
         if isinstance(data, UnsortableOrderedDict):
             for i in data:
                 item = self.AppendNode(i+':', '', None, parent)
                 if parent != None:
                     self.SetData(parent, UnsortableOrderedDict())
                 walk(data[i], item, level=level+1)
         elif isinstance(data, list):
             if len(data) == 0:
                 self.SetValue(parent, '')
                 self.SetData(parent, '')
             elif isinstance(data[0], UnsortableOrderedDict):
                 #keys = data[0].keys()
                 keys = []
                 for i in data:
                     for j in i.keys():
                         if j not in keys:
                             keys += [j]
                 self.SetData(parent, keys)
                 for i in data:
                     #print
                     #print keys, i.keys()
                     #if i.keys() != keys:
                     #    raise Exception('List keys differ!')
                     list_item = self.AppendNode(self.SPACER+keys[0]+':', '', None, parent, bold=True)
                     #self.tree.SetPyData(list_item, None)
                     if self.T:
                         self.tree.SetItemImage(list_item, self.dotlist) #, wx.TreeItemIcon_Normal)
                     walk(i[keys[0]], list_item, level=level+1)
                     for j in keys[1:]:
                         item = self.AppendNode(j+':', '', None, list_item)
                         if j in i:
                             walk(i[j], item, level=level+1)
                         #else:
                         #    self.SetValue(parent, '')
                         #    self.SetData(parent, '')
         else:
             if parent != None:
                 self.SetValue(parent, data)
                 self.SetData(parent, data)
     walk(data)
     
     self.menu_file_save_as.Enable(True)
     self.menu_file_close.Enable(True)
     self._title_update(contents_changed=False)
     if expand:
         self.tree.ExpandAll()
Esempio n. 3
0
    def Load(self, content, expand=True):
        if content == None:
            return
        if isinstance(content, UnsortableOrderedDict):
            data = content
            self.filename = None
            self.file_changed = None
        else:
            data = yaml_load(
                open(content).read(), yaml.SafeLoader, UnsortableOrderedDict)
            self.filename = os.path.abspath(content)
            self.file_changed = False
        self.orig = data

        #print data
        #print yaml.dump(data, default_flow_style=False, allow_unicode=True).decode('utf-8').encode('utf-8')
        def walk(data, parent=None, level=0):
            #print level, data
            if isinstance(data, UnsortableOrderedDict):
                for i in data:
                    item = self.AppendNode(i + ':', '', None, parent)
                    if parent != None:
                        self.SetData(parent, UnsortableOrderedDict())
                    walk(data[i], item, level=level + 1)
            elif isinstance(data, list):
                if len(data) == 0:
                    self.SetValue(parent, '')
                    self.SetData(parent, '')
                elif isinstance(data[0], UnsortableOrderedDict):
                    #keys = data[0].keys()
                    keys = []
                    for i in data:
                        for j in i.keys():
                            if j not in keys:
                                keys += [j]
                    self.SetData(parent, keys)
                    for i in data:
                        #print
                        #print keys, i.keys()
                        #if i.keys() != keys:
                        #    raise Exception('List keys differ!')
                        list_item = self.AppendNode(self.SPACER + keys[0] +
                                                    ':',
                                                    '',
                                                    None,
                                                    parent,
                                                    bold=True)
                        #self.tree.SetPyData(list_item, None)
                        if self.T:
                            self.tree.SetItemImage(
                                list_item,
                                self.dotlist)  #, wx.TreeItemIcon_Normal)
                        walk(i[keys[0]], list_item, level=level + 1)
                        for j in keys[1:]:
                            item = self.AppendNode(j + ':', '', None,
                                                   list_item)
                            if j in i:
                                walk(i[j], item, level=level + 1)
                            #else:
                            #    self.SetValue(parent, '')
                            #    self.SetData(parent, '')
            else:
                if parent != None:
                    self.SetValue(parent, data)
                    self.SetData(parent, data)

        walk(data)

        self.menu_file_save_as.Enable(True)
        self.menu_file_close.Enable(True)
        self._title_update(contents_changed=False)
        if expand:
            self.tree.ExpandAll()