def __init__(self):
     """
         here the main speech module is speech which is in the file
         here the dictionary modusle is PyDictionary which will be using 
     """
     self.speech = Speech()
     self.dictionary = PyDictionary()
     self.universal = Universal(self.speech)
     self.meaning = Meaning(self.speech)
     self.synonym = Synonym(self.speech)
     self.antonym = Antonym(self.speech)
    def save_dump(self, stack_trace):
        """
        Method to save the stack trace as a crash dump.
        
        Args:
            stack_trace: stack trace of exception.
            
        Returns:
            Path to the crash dump on success else False
        """

        univ = Universal()  #get Universal
        timestamp = int(time.time() *
                        1000)  #timestamp for the unique crash dump filename
        path = self.crash_dump_path + (
            'sealion-%s-%d.dmp' %
            (univ.config.agent.agentVersion, timestamp))  #crash dump filename
        f = None

        try:
            helper.Utils.get_safe_path(
                path)  #create dump directory if it is not available

            #dict continaing crash dump details
            report = {
                'timestamp': timestamp,
                'stack': stack_trace,
                'orgToken': univ.config.agent.orgToken,
                '_id': univ.config.agent._id,
                'os': {
                    'pythonVersion': univ.details['pythonVersion']
                },
                'process': {
                    'uid': os.getuid(),
                    'gid': os.getgid(),
                    'uptime': int(univ.get_run_time() * 1000),
                    'agentVersion': univ.config.agent.agentVersion,
                    'isProxy': univ.details['isProxy']
                }
            }

            #write dump
            f = open(path, 'w')
            json.dump(report, f)
        except:
            return None
        finally:
            f and f.close()

        return path
class Bot:
    def __init__(self):
        """
            here the main speech module is speech which is in the file
            here the dictionary modusle is PyDictionary which will be using 
        """
        self.speech = Speech()
        self.dictionary = PyDictionary()
        self.universal = Universal(self.speech)
        self.meaning = Meaning(self.speech)
        self.synonym = Synonym(self.speech)
        self.antonym = Antonym(self.speech)

    def speak(self):
        sent = self.speech.listen()
        print(sent)
        if 'meaning of' in sent:
            self.meaning.Start_Meaning(sent)
        elif 'synonyms' in sent:
            self.synonym.Start_Synonym(sent)
        elif 'antonyms' in sent:
            self.antonym.Start_Antonym(sent)
        else:
            if (self.universal.check(sent) == False):
                self.speech.speak("Invalid Response how can I help you")
        return sent
Exemple #4
0
 def save_dump(self, stack_trace):
     """
     Method to save the stack trace as a crash dump.
     
     Args:
         stack_trace: stack trace of exception.
         
     Returns:
         Path to the crash dump on success else False
     """
     
     univ = Universal()  #get Universal
     timestamp = int(time.time() * 1000)  #timestamp for the unique crash dump filename
     path = self.crash_dump_path + ('sealion-%s-%d.dmp' % (univ.config.agent.agentVersion, timestamp))  #crash dump filename
     f = None
     
     try:
         helper.Utils.get_safe_path(path)  #create dump directory if it is not available
         
         #dict continaing crash dump details
         report = {
             'timestamp': timestamp,
             'stack': stack_trace,
             'orgToken': univ.config.agent.orgToken,
             '_id': univ.config.agent._id,
             'os': {'pythonVersion': univ.details['pythonVersion']},
             'process': {
                 'uid': os.getuid(),
                 'gid': os.getgid(),
                 'uptime': int(univ.get_run_time() * 1000),
                 'agentVersion': univ.config.agent.agentVersion,
                 'isProxy': univ.details['isProxy']
             }
         }
         
         #write dump
         f = open(path, 'w')
         json.dump(report, f)
     except:
         return None
     finally:
         f and f.close()
     
     return path
Exemple #5
0
    def parse_universal(self):
        self.f.seek(0)
        # skip magic
        self.f.read(4)
        nmachos = get_int(self.f)
        u = Universal(nmachos=nmachos)
        u_size = self.file.size
        for i in range(u.nmachos):
            # skip cputype, subtype
            self.f.read(8)
            offset = get_int(self.f)
            size = get_int(self.f)
            # Abnormality OUT_OF_BOUNDS check
            if offset + size > u_size:
                data = {
                    'offset': offset,
                    'size': size,
                    'file_size': u_size
                }
                a = Abnormality(title='MACH-O OUT OF BOUNDS', data=data)
                self.add_abnormality(a)
                continue
            # skip align
            self.f.read(4)
            identity = self.identify_file(offset)
            # Abnormality BAD_MAGIC check
            if identity not in dictionary.machos.values():
                data = {
                    'offset': offset,
                    'magic': identity,
                }
                a = Abnormality(title='BAD MAGIC - MACH-O')
                self.add_abnormality(a)
                continue
            u.add_macho(MachO(archive=True, offset=offset, arch=identity[0],
                             endi=identity[1], size=size))

        for i in u.gen_machos():
            self.parse_macho(i)

        self.file.content = u
    def get_crash_dump_details(self):
        """
        Method to get crash dump count. It also reports any crash loop by examining the file timestamp.
        
        Returns:
            Tupple (is crah loop, crash dump count)
        """

        univ = Universal()  #get Universal
        t = int(time.time())  #current epoch time for crash loop detection
        crash_loop_timeout = self.crash_loop_count * self.monit_interval  #time span for crash loop detection
        file_count, loop_file_count = 0, 0

        #crash loop is detected only for the current agent version running
        loop_regex = '^sealion-%s-[0-9]+\.dmp$' % univ.config.agent.agentVersion.replace(
            '.', '\.')

        #agent version regex for finding valid crash dump files
        agent_version_regex = univ.config.agent.schema['agentVersion'].get(
            'regex', '.*')
        agent_version_regex = re.sub('^\^?([^\$]+)\$?$', '\g<1>',
                                     agent_version_regex)

        try:
            for f in os.listdir(
                    self.crash_dump_path
            ):  #loop though files in the crash dump directory
                #if it is a valid crash dump file name
                if os.path.isfile(self.crash_dump_path + f) and re.match(
                        '^sealion-%s-[0-9]+\.dmp$' % agent_version_regex,
                        f) != None:
                    file_count += 1

                    #is this file contribute to crash loop
                    if re.match(
                            loop_regex, f) != None and t - os.path.getmtime(
                                self.crash_dump_path + f) < crash_loop_timeout:
                        loop_file_count += 1
        except:
            pass

        return (loop_file_count >= 5, file_count)
Exemple #7
0
        if value:
            env_vars[match[0]] = value
        else:  #discard any unset variables
            try:
                del env_vars[match[
                    0]]  #it could be possible the key does not even exists
            except:
                pass

    return env_vars_count


try:
    #try to read the environment variables from sealion config
    env_vars = Universal().config.sealion.get_dict(('env', {}))['env']
except:
    env_vars = {}

try:
    env_vars_count, env_vars_regex, restart_agent = 0, re.compile(
        r'^--(e[a-zA-Z\_][a-zA-Z0-9\_]*)=?$'), False
    long_options = ['file=', 'restart', 'version', 'help']

    #add environment variables specified in the format --eENVIRONMENT_VAR
    #we identify them and add as long options
    for arg in sys.argv[1:]:
        match = env_vars_regex.match(arg)

        if not match:
            continue
Exemple #8
0
from grab_lyrics import *
from universal import Universal

import os

universe = Universal()

raw_counts_dir_name = universe.raw_counts_dir_name
normalized_dir_name = universe.normalized_dir_name
delimiter = universe.delimiter
links_dir_name = universe.links_dir_name

for filename in os.listdir(links_dir_name):
    file = open(links_dir_name + "/" + filename, "r")
    contents = file.read()
    file.close()

    genre = filename.split(".")[0]
    links = contents.split()
    write_dicts(genre, links)

write_normalized_counts()
Exemple #9
0
        helper.Utils.get_safe_path(exe_path + '/var/log/sealion.log'),
        maxBytes=1024 * 1024 * 10,
        backupCount=5)
    lf.setFormatter(formatter)
    logger.addHandler(lf)
except Exception as e:
    sys.stderr.write('Failed to open the log file; %s\n' % unicode(e))
    sys.exit(exit_status.AGENT_ERR_FAILED_OPEN_LOG)

try:
    #set the home folder for the process; do it before parsing config files so that user can override it in config file
    os.environ['HOME'] = exe_path or '/'

    #initialize Universal and create api sessions
    #this can raise exception if universal is failed to find/create config files
    univ = Universal()
    api.create_session()
    api.create_unauth_session()
except Exception as e:
    _log.error(unicode(e))
    sys.exit(exit_status.AGENT_ERR_FAILED_INITIALIZE)


class LoggingList(logging.Filter):
    """
    Class to filter module wise logging 
    """
    def __init__(self, *logging_filters):
        """
        Constructor
        """
Exemple #10
0
    def send_crash_dumps(self):
        """
        Method to send all crash dumps to server.
        This method runs in a seperate thread.
        """

        import api
        univ = Universal()  #get Universal

        #how much time the crash dump sender wait before start sending.
        #this is required not to affect crash loop detection, since crash loop detection is done by checking number crash dumps generated in a span of time
        crash_dump_timeout = (self.crash_loop_count * self.monit_interval) + 10

        #get the agent version regex to differentiate dumps from any other file
        agent_version_regex = univ.config.agent.schema['agentVersion'].get(
            'regex', '.*')
        agent_version_regex = re.sub('^\^?([^\$]+)\$?$', '\g<1>',
                                     agent_version_regex)

        _log.debug('CrashDumpSender waiting for stop event for %d seconds' %
                   crash_dump_timeout)
        univ.stop_event.wait(crash_dump_timeout)

        try:
            for file in os.listdir(
                    self.crash_dump_path
            ):  #loop though files in the crash dump directory
                file_name = self.crash_dump_path + file

                #is this a valid crash dump filename
                if os.path.isfile(file_name) and re.match(
                        '^sealion-%s-[0-9]+\.dmp$' % agent_version_regex,
                        file) != None:
                    report = None

                    while 1:
                        if univ.stop_event.is_set():  #do we need to stop now
                            _log.debug('CrashDumpSender received stop event')
                            return

                        #read the report from the dump, or retry the report
                        report = report if report != None else self.read_dump(
                            file_name)

                        if report == None or api.is_not_connected(
                                api.unauth_session.send_crash_report(
                                    report)) == False:  #send the dump
                            break

                        _log.debug(
                            'CrashDumpSender waiting for stop event for 10 seconds'
                        )
                        univ.stop_event.wait(
                            10)  #on failure, wait for some time

                    try:
                        os.remove(file_name)  #remove the dump as we sent it
                        _log.info('Removed dump %s' % file_name)
                    except Exception as e:
                        _log.error('Failed to remove dump %s; %s' %
                                   (file_name, unicode(e)))

                if univ.stop_event.is_set():  #do we need to stop now
                    _log.debug('CrashDumpSender received stop event')
                    return
        except:
            pass
 def __init__(self, speech):
     self.speech = speech
     self.universal = Universal(self.speech)
     self.dictionary = PyDictionary()