Esempio n. 1
0
    def test_metadata_serialization(self):
        import time
        modelobject = ModelObject()
        modelobject.updateID = lambda *args: 'ModelObjectID'
        metadata = Metadata('')
        # {'create_time': 1417205460.253131,
        #          'creator': 'ninja_owner',
        #           'owner': 'ninja_owner',
        #            'update_time': 1417205460.253132,
        #             'update_user': '******'}

        modelobjectserialized = self.mapper.serialize(modelobject)
        metadataserialized = modelobjectserialized['metadata']
        # if serialization fails, returns None
        self.assertNotEqual(modelobjectserialized, None,
                            "Serialized ModelObejct shouldn't be None")
        # we check the cmd attributes
        self.assertEquals(modelobjectserialized.get("_id"),
                          modelobject.getID(),
                          "Serialized ID is not the same as metadata ID")
        self.assertEquals(
            metadataserialized.get("creator"),
            metadata.__getattribute__("creator"),
            "Serialized owner is not the same as metadata creator")
        self.assertEquals(
            metadataserialized.get("owner"),
            metadata.__getattribute__("owner"),
            "Serialized owner is not the same as metadata owner")

        self.assertTrue(
            isinstance(metadataserialized.get("create_time"), float),
            "Serialized create_time is not int")
        self.assertTrue(
            isinstance(metadataserialized.get("update_time"), float),
            "Serialized update_time is not int")
Esempio n. 2
0
    def __init__(self, name, status = "running", version = "unknonw"):
        ModelObject.__init__(self)

        self._name          = name
        self._status        = status
        self._version       = version
                                                    
        self._services      = {}
Esempio n. 3
0
    def __init__(self, name, status="running", version="unknonw"):
        ModelObject.__init__(self)

        self._name = name
        self._status = status
        self._version = version

        self._services = {}
Esempio n. 4
0
 def __init__(self, name, os="Unknown", default_gateway=None, dic=None):
     ModelObject.__init__(self)
     self._interfaces = {}
     self._applications = {}
     self.categories = []
     if dic is not None:
         self._fromDict(dic)
     else:
         self.__init(name, os, default_gateway)
Esempio n. 5
0
 def __init__(self, name, os = "Unknown", default_gateway=None, dic=None):
     ModelObject.__init__(self)
     self._interfaces            = {}
     self._applications          = {}
     self.categories             = []
     if dic is not None:
         self._fromDict(dic)
     else:
         self.__init(name, os, default_gateway)
Esempio n. 6
0
    def test_metadata_deserialization(self):
        import time
        modelobject = ModelObject()
        modelobject.updateID = lambda *args: 'ModelObjectID'
        # {'create_time': 1417205460.253131,
        #          'creator': 'ninja_owner',
        #           'owner': 'ninja_owner',
        #            'update_time': 1417205460.253132,
        #             'update_user': '******'}
        modelobjectserialized = {
            'name': '',
            'parent': None,
            'owner': '',
            '_id': None,
            'type': 'ModelObject',
            'metadata': {
                'update_time': 1417207650.761777,
                'update_user': '',
                'update_action': 0,
                'creator': '',
                'create_time': 1417207650.761777,
                'update_controller_action': 'No model controller call',
                'owner': ''
            },
            'owned': False,
            'description': ''
        }
        modelobject2 = self.mapper.unserialize(modelobject,
                                               modelobjectserialized)
        metadata = modelobject2._metadata
        metadataserialized = modelobjectserialized['metadata']
        # if serialization fails, returns None
        self.assertNotEqual(modelobjectserialized, None,
                            "Serialized ModelObejct shouldn't be None")
        # we check the cmd attributes
        self.assertEquals(modelobjectserialized.get("_id"),
                          modelobject.getID(),
                          "Serialized ID is not the same as metadata ID")
        import ipdb
        ipdb.set_trace()
        self.assertEquals(
            metadataserialized.get("owner"),
            metadata.__getattribute__("owner"),
            "Serialized owner is not the same as metadata owner")
        self.assertEquals(
            metadataserialized.get("creator"),
            metadata.__getattribute__("creator"),
            "Serialized owner is not the same as metadata creator")

        self.assertTrue(
            isinstance(metadataserialized.get("create_time"), float),
            "Serialized create_time is not int")
        self.assertTrue(
            isinstance(metadataserialized.get("update_time"), float),
            "Serialized update_time is not int")
Esempio n. 7
0
    def test_metadata_deserialization(self):
        import time
        modelobject = ModelObject()
        modelobject.updateID = lambda *args : 'ModelObjectID'
        # {'create_time': 1417205460.253131,
        #          'creator': 'ninja_owner',
        #           'owner': 'ninja_owner',
        #            'update_time': 1417205460.253132,
        #             'update_user': '******'}
        modelobjectserialized = {'name': '',
                             'parent': None,
                             'owner': '',
                             '_id': None,
                             'type': 'ModelObject',
                             'metadata': {'update_time': 1417207650.761777,
                                     'update_user': '',
                                     'update_action': 0,
                                     'creator': '',
                                     'create_time': 1417207650.761777,
                                     'update_controller_action': 'No model controller call',
                                     'owner': ''},
                             'owned': False,
                             'description': ''}
        modelobject2 = self.mapper.unserialize(modelobject, modelobjectserialized)
        metadata = modelobject2._metadata
        metadataserialized = modelobjectserialized['metadata']
        # if serialization fails, returns None
        self.assertNotEqual(
            modelobjectserialized,
            None,
            "Serialized ModelObejct shouldn't be None")
        # we check the cmd attributes
        self.assertEquals(
            modelobjectserialized.get("_id"),
            modelobject.getID(),
            "Serialized ID is not the same as metadata ID")
        import ipdb; ipdb.set_trace()
        self.assertEquals(
            metadataserialized.get("owner"),
            metadata.__getattribute__("owner"),
            "Serialized owner is not the same as metadata owner")
        self.assertEquals(
            metadataserialized.get("creator"),
            metadata.__getattribute__("creator"),
            "Serialized owner is not the same as metadata creator")

        self.assertTrue(
            isinstance(metadataserialized.get("create_time"), float),
            "Serialized create_time is not int")
        self.assertTrue(
            isinstance(metadataserialized.get("update_time"), float),
            "Serialized update_time is not int")
Esempio n. 8
0
    def __init__(self, name, protocol="TCP", ports=None, status="running", version="unknown", description=""):
        ModelObject.__init__(self)

        self._name = name
        self.description = description
        self._protocol = protocol
        self._ports = []
        self.setPorts(ports)
        self._status = status
        self._version = version
        self._interfaces = {}
        self._applications = {}
        self._creds = {}
Esempio n. 9
0
    def __init__(self,
                 name="",
                 mac="00:00:00:00:00:00",
                 ipv4_address="0.0.0.0",
                 ipv4_mask="0.0.0.0",
                 ipv4_gateway="0.0.0.0",
                 ipv4_dns=[],
                 ipv6_address="0000:0000:0000:0000:0000:0000:0000:0000",
                 ipv6_prefix="00",
                 ipv6_gateway="0000:0000:0000:0000:0000:0000:0000:0000",
                 ipv6_dns=[],
                 network_segment="",
                 hostname_resolution=None):

        ModelObject.__init__(self)

        self._name = name
        self.mac = mac
        self.ipv4 = {
            "address": ipv4_address,
            "mask": ipv4_mask,
            "gateway": ipv4_gateway,
            "DNS": ipv4_dns
        }

        self.ipv6 = {
            "address": ipv6_address,
            "prefix": ipv6_prefix,
            "gateway": ipv6_gateway,
            "DNS": ipv6_dns
        }

        self._services = {}

        self.network_segment = network_segment

        self._hostnames = []
        if hostname_resolution is not None:
            if isinstance(hostname_resolution, (str, unicode)):
                self._hostnames.append(hostname_resolution)
            else:
                self._hostnames = hostname_resolution

        self.amount_ports_opened = 0
        self.amount_ports_closed = 0
        self.amount_ports_filtered = 0

        self.getMetadataHistory().pushMetadataForId(self.getID(),
                                                    self.getMetadata())
Esempio n. 10
0
    def __init__(self, name = "", mac = "00:00:00:00:00:00",
                 ipv4_address = "0.0.0.0", ipv4_mask = "0.0.0.0",
                 ipv4_gateway = "0.0.0.0", ipv4_dns = [],
                 ipv6_address = "0000:0000:0000:0000:0000:0000:0000:0000", ipv6_prefix = "00",
                 ipv6_gateway = "0000:0000:0000:0000:0000:0000:0000:0000", ipv6_dns = [],
                 network_segment = "", hostname_resolution = None):

        ModelObject.__init__(self)

                              
        self._name         = name
        self.mac           = mac
        self.ipv4          = {
                                "address" : ipv4_address,
                                "mask"    : ipv4_mask,
                                "gateway" : ipv4_gateway,
                                "DNS"     : ipv4_dns
                            }
             
        self.ipv6         = {
                                "address" : ipv6_address,
                                "prefix"    : ipv6_prefix,
                                "gateway" : ipv6_gateway,
                                "DNS"     : ipv6_dns
                            }

                                                    
        self._services      = {}

                                                                      
        self.network_segment       = network_segment

                                                     
        self._hostnames=[]
        if hostname_resolution is not None:
            if isinstance(hostname_resolution, (str,unicode)):
                self._hostnames.append(hostname_resolution)
            else:
                self._hostnames = hostname_resolution

                         
                                                                         
                                                                      
        self.amount_ports_opened   = 0
        self.amount_ports_closed   = 0
        self.amount_ports_filtered = 0

        self.getMetadataHistory().pushMetadataForId(self.getID(), self.getMetadata())
Esempio n. 11
0
    def filterConditions(self, doc):
        model_object_types = [c.__name__ for c in ModelObject.__subclasses__()]
        ret = True
        ret = ret and not doc["id"].startswith("_")
        ret = ret and doc['doc']["type"] in model_object_types

        return ret
Esempio n. 12
0
 def defaultValues(self):
     defVals = ModelObject.defaultValues(self)
     defVals.extend([{
                             "address" :  "0.0.0.0",
                             "mask"    :  "0.0.0.0",
                             "gateway" :  "0.0.0.0",
                             "DNS"     :  []
                             }, {'prefix': '00', 'gateway': '0000:0000:0000:0000:0000:0000:0000:0000', 'DNS': [], 'address': '0000:0000:0000:0000:0000:0000:0000:0000'}])
     return defVals
Esempio n. 13
0
    def __init__(self,
                 name,
                 protocol="TCP",
                 ports=None,
                 status="running",
                 version="unknown",
                 description=""):
        ModelObject.__init__(self)

        self._name = name
        self.description = description
        self.setProtocol(protocol)
        self._ports = []
        self.setPorts(ports)
        self._status = status
        self._version = version
        self._interfaces = {}
        self._applications = {}
        self._creds = {}
Esempio n. 14
0
    def test_metadata_serialization(self):
        import time
        modelobject = ModelObject()
        modelobject.updateID = lambda *args : 'ModelObjectID'
        metadata = Metadata('')
        # {'create_time': 1417205460.253131,
        #          'creator': 'ninja_owner',
        #           'owner': 'ninja_owner',
        #            'update_time': 1417205460.253132,
        #             'update_user': '******'}

        modelobjectserialized = self.mapper.serialize(modelobject)
        metadataserialized = modelobjectserialized['metadata']
        # if serialization fails, returns None
        self.assertNotEqual(
            modelobjectserialized,
            None,
            "Serialized ModelObejct shouldn't be None")
        # we check the cmd attributes
        self.assertEquals(
            modelobjectserialized.get("_id"),
            modelobject.getID(),
            "Serialized ID is not the same as metadata ID")
        self.assertEquals(
            metadataserialized.get("creator"),
            metadata.__getattribute__("creator"),
            "Serialized owner is not the same as metadata creator")
        self.assertEquals(
            metadataserialized.get("owner"),
            metadata.__getattribute__("owner"),
            "Serialized owner is not the same as metadata owner")

        self.assertTrue(
            isinstance(metadataserialized.get("create_time"), float),
            "Serialized create_time is not int")
        self.assertTrue(
            isinstance(metadataserialized.get("update_time"), float),
            "Serialized update_time is not int")
Esempio n. 15
0
 def defaultValues(self):
     defVals = ModelObject.defaultValues(self)
     defVals.extend([{
         "address": "0.0.0.0",
         "mask": "0.0.0.0",
         "gateway": "0.0.0.0",
         "DNS": []
     }, {
         'prefix': '00',
         'gateway': '0000:0000:0000:0000:0000:0000:0000:0000',
         'DNS': [],
         'address': '0000:0000:0000:0000:0000:0000:0000:0000'
     }])
     return defVals
Esempio n. 16
0
 def defaultValues(self):
     defVals = ModelObject.defaultValues(self)
     defVals.extend(
         [
             {"address": "0.0.0.0", "mask": "0.0.0.0", "gateway": "0.0.0.0", "DNS": []},
             {
                 "prefix": "00",
                 "gateway": "0000:0000:0000:0000:0000:0000:0000:0000",
                 "DNS": [],
                 "address": "0000:0000:0000:0000:0000:0000:0000:0000",
             },
         ]
     )
     return defVals
Esempio n. 17
0
    def __init__(self, name, qapp, gui_parent, model_controller,
                 plugin_controller, close_callback=None):

        ModelObject.__init__(self)
        self._id = self.get_id()
        self.name = name

        # a reference used to add new hosts
        self._model_controller = model_controller

        # create the widget
        self.widget = ShellWidget(qapp,gui_parent,name)
        self.widget.setupLayout()

        # For safesty we don't use the user shell, we force it to bash
        progname = "/bin/bash"
        # create the session
        #Session(gui, pgm, args, term, sessionid='session-1', cwd=None):
        #self.process_controller = ProcessController()
        self.session = Session(self.widget, progname, [], "xterm", name);

        self.session.setConnect(True)
        self.session.setHistory(HistoryTypeBuffer(1000))
        self._setUpSessionSinalHandlers()

        #self.__last_user_input = None
        #self.__user_input_signal = False

        # flag that determines if output has to be ignored
        self.__ignore_process_output = False
        self.__ignore_process_output_once = False
        self.__first_process_output = True
        self.__save_output_prompt_format = False

        # determines if input is for an interactive command or not
        self.__interactive = False

        #TODO: check if we need to connect to this signal
        self.session.myconnect('done', self.close)

        # instance a new plugin controller
        self.plugin_controller = plugin_controller(self.id)

        self._initial_prompt = ""
        #self._custom_prompt_format = re.compile("\\x1B\[1;32m\[.+@.+\s.+\]>(\$|#)\s+\\x1B\[m")
        #self._custom_prompt_format = re.compile("\[.+@.+\s.+\]>(\$|#)\s+")
        self._custom_prompt_format = re.compile("\[(?P<user>.+)@(?P<host>.+):(?P<path>.+)\]>(\$|#)")
        #TODO: somewhere in the config there should be a list of regexes used to match
        # prompts. Be careful with this because if regexes are too generic they will
        # match more that is needed.
        self._generic_prompt_formats = []
        #XXX: adding this format just as a test! This should be in the config somehow
        # Also this may be is too generic to use...
        self._generic_prompt_formats.append(re.compile("^.+@.+:.+(\$|#)$"))
        
        #This is a reference to MainApplication.deleteShellEnvironment
        self._close_callback = close_callback 
        
        # flag that determines if shell environment is running
        self.__running = False
        
        #Autocomplete
        self._options=[] #only keys
        self._tname="" # last tool executed
        self._lcount=0
        self._optionsh={} #keys + help
        self.__command = ''
Esempio n. 18
0
    def __init__(self, name, qapp, gui_parent, model_controller,
                 plugin_controller, close_callback=None):

        ModelObject.__init__(self)
        self._id = self.get_id()
        self.name = name

        # a reference used to add new hosts
        self._model_controller = model_controller

        # create the widget
        self.widget = ShellWidget(qapp,gui_parent,name)
        self.widget.setupLayout()

        # For safesty we don't use the user shell, we force it to bash
        progname = "/bin/bash"
        # create the session
        #Session(gui, pgm, args, term, sessionid='session-1', cwd=None):
        #self.process_controller = ProcessController()
        self.session = Session(self.widget, progname, [], "xterm", name);

        self.session.setConnect(True)
        self.session.setHistory(HistoryTypeBuffer(1000))
        self._setUpSessionSinalHandlers()

        #self.__last_user_input = None
        #self.__user_input_signal = False

        # flag that determines if output has to be ignored
        self.__ignore_process_output = False
        self.__ignore_process_output_once = False
        self.__first_process_output = True
        self.__save_output_prompt_format = False

        # determines if input is for an interactive command or not
        self.__interactive = False

        #TODO: check if we need to connect to this signal
        self.session.myconnect('done', self.close)

        # instance a new plugin controller
        self.plugin_controller = plugin_controller(self.id)

        self._initial_prompt = ""
        #self._custom_prompt_format = re.compile("\\x1B\[1;32m\[.+@.+\s.+\]>(\$|#)\s+\\x1B\[m")
        #self._custom_prompt_format = re.compile("\[.+@.+\s.+\]>(\$|#)\s+")
        self._custom_prompt_format = re.compile("\[(?P<user>.+)@(?P<host>.+):(?P<path>.+)\]>(\$|#)")
        #TODO: somewhere in the config there should be a list of regexes used to match
        # prompts. Be careful with this because if regexes are too generic they will
        # match more that is needed.
        self._generic_prompt_formats = []
        #XXX: adding this format just as a test! This should be in the config somehow
        # Also this may be is too generic to use...
        self._generic_prompt_formats.append(re.compile("^.+@.+:.+(\$|#)$"))
        
        #This is a reference to MainApplication.deleteShellEnvironment
        self._close_callback = close_callback 
        
        # flag that determines if shell environment is running
        self.__running = False
        
        #Autocomplete
        self._options=[] #only keys
        self._tname="" # last tool executed
        self._lcount=0
        self._optionsh={} #keys + help
        self.__command = ''