Exemple #1
0
 def setup_local_chop(self, name="ChopShop", pid=-1):
     #This allows Process 1 to access Chops, note that it has
     #a hardcoded id of -1 since otherwise it might overlap
     #with the other chops, only use a custom id if you know
     #what you're doing
     chophelper = ChopHelper(self.tocaller, self.options)
     self.chop = chophelper.setup_module(name, pid)
Exemple #2
0
 def setup_local_chop(self, name = "ChopShop", pid = -1):
     #This allows Process 1 to access Chops, note that it has
     #a hardcoded id of -1 since otherwise it might overlap
     #with the other chops, only use a custom id if you know
     #what you're doing
     chophelper = ChopHelper(self.tocaller, self.options)
     self.chop = chophelper.setup_module(name, pid)
Exemple #3
0
    def __nids_core_runner_(self, inq, outq, dataq, autostart=True):
        #Note that even though this is within the class it is being used irrespective
        #of the Process 1 class, so 'self' is never used for data

        os.setpgrp()

        #Responsible for creating "chop" classes and
        #keeping track of the individual output handlers
        chophelper = None
        chop = None

        options = None
        module_list = []
        ccore = None
        mod_dir = []
        ext_dir = []
        chopgram = None
        abort = False

        #Initialization
        while (True):
            try:
                data = inq.get(True, .1)
            except Queue.Empty, e:
                continue

            if data[0] == 'init':

                try:
                    f = open('/dev/null', 'w')
                    os.dup2(f.fileno(), 1)
                    g = open('/dev/null', 'r')
                    os.dup2(g.fileno(), 0)
                except:
                    outq.put("Unable to assign /dev/null as stdin/stdout")
                    sys.exit(-1)

                options = data[1]

                #Set up the module directory and the external libraries directory
                if options['base_dir'] is not None:
                    for base in options['base_dir']:
                        real_base = os.path.realpath(base)
                        mod_dir.append(real_base + "/modules/")
                        ext_dir.append(real_base + "/ext_libs")
                else:
                    mod_dir = options['mod_dir']
                    ext_dir = options['ext_dir']

                for ed_path in ext_dir:
                    sys.path.append(os.path.realpath(ed_path))

                #Setup the chophelper
                chophelper = ChopHelper(dataq, options)
                chop = chophelper.setup_main()

                #Setup the modules
                chopgram = ChopGrammar()
                try:
                    all_modules = chopgram.parseGrammar(options['modules'])
                except Exception, e:
                    outq.put(traceback.format_exc())
                    sys.exit(1)

                if len(all_modules) == 0:
                    outq.put('Zero Length Module List')
                    sys.exit(1)

                try:
                    for mod in all_modules:
                        mod.code = self.__loadModules_(mod.name, mod_dir)
                        minchop = '0'
                        try:
                            mod_version = mod.code.moduleVersion
                            minchop = mod.code.minimumChopLib

                        except:  #Legacy Module
                            mod.legacy = True
                            chop.prnt("Warning Legacy Module %s!" %
                                      mod.code.moduleName)

                        try:
                            #TODO more robust version checking
                            if str(minchop) > str(VERSION):
                                raise Exception(
                                    "Module requires ChopLib Version %s or greater"
                                    % minchop)
                        except Exception, e:
                            outq.put(e.args)
                            sys.exit(1)

                except Exception, e:
                    outq.put(e)
                    sys.exit(1)
Exemple #4
0
    def __nids_core_runner_(self, inq, outq, dataq, autostart = True):
        #Note that even though this is within the class it is being used irrespective
        #of the Process 1 class, so 'self' is never used for data

        #Responsible for creating "chop" classes and
        #keeping track of the individual output handlers
        chophelper = None
        chop = None

        options = None
        module_list = []
        ccore = None
        mod_dir = None

        #Initialization
        while (True):
            try:
                data = inq.get(True, .1)
            except Queue.Empty, e:
                continue

            if data[0] == 'init':

                try:
                    f = open('/dev/null', 'w')
                    os.dup2(f.fileno(), 1)
                    g = open('/dev/null', 'r')
                    os.dup2(g.fileno(), 0)
                except:
                    outq.put("Unable to assign /dev/null as stdin/stdout")
                    sys.exit(-1)

                options = data[1]

                #Set up the module directory and the external libraries directory
                if options['base_dir'] is not None:
                    base_dir = os.path.realpath(options['base_dir'])
                    mod_dir = base_dir + "/modules/" 
                    ext_dir = base_dir + "/ext_libs" 
                else:
                    mod_dir = options['mod_dir'] 
                    ext_dir = options['ext_dir']

                sys.path.append(os.path.realpath(ext_dir))

                #Setup the chophelper 
                chophelper = ChopHelper(dataq, options)
                chop = chophelper.setup_main()

                #Setup the modules
                args = options['modules']
                mods = args.split(';')
                try:
                    for mod in mods:
                        mod = mod.strip()
                        sindex = mod.find(' ')
                        if sindex != -1:
                            modl = []
                            modl.append(self.__loadModules_(mod[0:sindex],mod_dir))
                            modl.append(mod[sindex + 1:])
                            modl.append(mod[0:sindex])
                            module_list.append(modl)
                        else:
                            modl = []
                            modl.append(self.__loadModules_(mod,mod_dir))
                            modl.append("")
                            modl.append(mod)
                            module_list.append(modl)
                except Exception, e:
                    outq.put(e)
                    sys.exit(-1)

                if len(module_list) == 0:
                    outq.put('Zero Length Module List')
                    sys.exit(-1)


                #It got this far, everything should be okay
                outq.put('ok')
Exemple #5
0
    def __nids_core_runner_(self, inq, outq, dataq, autostart = True):
        #Note that even though this is within the class it is being used irrespective
        #of the Process 1 class, so 'self' is never used for data

        os.setpgrp()

        #Responsible for creating "chop" classes and
        #keeping track of the individual output handlers
        chophelper = None
        chop = None

        options = None
        module_list = []
        ccore = None
        mod_dir = []
        ext_dir = []
        chopgram = None
        abort = False

        #Initialization
        while (True):
            try:
                data = inq.get(True, .1)
            except Queue.Empty, e:
                continue

            if data[0] == 'init':

                try:
                    f = open('/dev/null', 'w')
                    os.dup2(f.fileno(), 1)
                    g = open('/dev/null', 'r')
                    os.dup2(g.fileno(), 0)
                except:
                    outq.put("Unable to assign /dev/null as stdin/stdout")
                    sys.exit(-1)

                options = data[1]

                #Set up the module directory and the external libraries directory
                if options['base_dir'] is not None:
                    for base in options['base_dir']:
                        real_base = os.path.realpath(base)
                        mod_dir.append(real_base + "/modules/")
                        ext_dir.append(real_base + "/ext_libs")
                else:
                    mod_dir = options['mod_dir']
                    ext_dir = options['ext_dir']

                for ed_path in ext_dir:
                    sys.path.append(os.path.realpath(ed_path))

                #Setup the chophelper
                chophelper = ChopHelper(dataq, options)
                chop = chophelper.setup_main()

                #Setup the modules
                chopgram = ChopGrammar()
                try:
                    all_modules = chopgram.parseGrammar(options['modules'])
                except Exception, e:
                    outq.put(traceback.format_exc())
                    sys.exit(1)


                if len(all_modules) == 0:
                    outq.put('Zero Length Module List')
                    sys.exit(1)

                try:
                    for mod in all_modules:
                        mod.code = self.__loadModules_(mod.name, mod_dir)
                        minchop = '0'
                        try:
                            mod_version = mod.code.moduleVersion
                            minchop = mod.code.minimumChopLib

                        except: #Legacy Module
                            mod.legacy = True
                            chop.prnt("Warning Legacy Module %s!" % mod.code.moduleName)
                    
                        try:
                            #TODO more robust version checking
                            if str(minchop) > str(VERSION):
                                raise Exception("Module requires ChopLib Version %s or greater" % minchop)
                        except Exception, e:
                            outq.put(e.args)
                            sys.exit(1)

                except Exception, e:
                    outq.put(e)
                    sys.exit(1)
Exemple #6
0
    def __nids_core_runner_(self, inq, outq, dataq, autostart=True):
        #Note that even though this is within the class it is being used irrespective
        #of the Process 1 class, so 'self' is never used for data

        #Responsible for creating "chop" classes and
        #keeping track of the individual output handlers
        chophelper = None
        chop = None

        options = None
        module_list = []
        ccore = None
        mod_dir = None

        #Initialization
        while (True):
            try:
                data = inq.get(True, .1)
            except Queue.Empty, e:
                continue

            if data[0] == 'init':

                try:
                    f = open('/dev/null', 'w')
                    os.dup2(f.fileno(), 1)
                    g = open('/dev/null', 'r')
                    os.dup2(g.fileno(), 0)
                except:
                    outq.put("Unable to assign /dev/null as stdin/stdout")
                    sys.exit(-1)

                options = data[1]

                #Set up the module directory and the external libraries directory
                if options['base_dir'] is not None:
                    base_dir = os.path.realpath(options['base_dir'])
                    mod_dir = base_dir + "/modules/"
                    ext_dir = base_dir + "/ext_libs"
                else:
                    mod_dir = options['mod_dir']
                    ext_dir = options['ext_dir']

                sys.path.append(os.path.realpath(ext_dir))

                #Setup the chophelper
                chophelper = ChopHelper(dataq, options)
                chop = chophelper.setup_main()

                #Setup the modules
                args = options['modules']
                mods = args.split(';')
                try:
                    for mod in mods:
                        mod = mod.strip()
                        sindex = mod.find(' ')
                        if sindex != -1:
                            modl = []
                            modl.append(
                                self.__loadModules_(mod[0:sindex], mod_dir))
                            modl.append(mod[sindex + 1:])
                            modl.append(mod[0:sindex])
                            module_list.append(modl)
                        else:
                            modl = []
                            modl.append(self.__loadModules_(mod, mod_dir))
                            modl.append("")
                            modl.append(mod)
                            module_list.append(modl)
                except Exception, e:
                    outq.put(e)
                    sys.exit(-1)

                if len(module_list) == 0:
                    outq.put('Zero Length Module List')
                    sys.exit(-1)

                #It got this far, everything should be okay
                outq.put('ok')