Example #1
0
def main():
    global_parameters['UUID'] = get_local_uuid()
    lib.active_session = db['analysis'].get_last_session()
    if lib.active_session is None:
        # Cannot get any session ID =>
        # analysis.db is not accessible =>
        # 'install script has not been executed'
        log.err('Cannot get session ID. Did you run correct installation script?')
        exit_program(-1, None)
        
    db['analysis'].create_session(lib.active_session)
    log.info('Currently working with session #%d.' % lib.active_session)
    # check if already admin
    if is_admin():
        log.ok('Administrator privileges already granted on \'%s\'.' % (global_parameters['ACTIVEROOT']), dbnote=DBNOTE_UNIQUE)
    # if input from file, load commands into queue
    if args.input_file is not None:
        if os.access(args.input_file[0], os.R_OK):
            with open(args.input_file[0], 'r') as f:
                lib.commands = [x if x not in QUIT_STRINGS else 'force_exit' for x in f.read().splitlines()]
                lib.from_input_file = True
        else:
            log.err('Input file cannot be read!')

    # run all input commands
    while len(lib.commands) > 0:
        c = lib.commands[0]
        del lib.commands[0]
        if lib.from_input_file:
            log.prompt()            # print prompt
            log.attachline(c)       # print command
        execute_command(c)          # run the command

    lib.from_input_file = False
        
    # main loop
    while True:
        # input from stdin, piped or redirected
        log.prompt()
        if lib.python_version[0] == '2':
            func = raw_input
        elif lib.python_version[0] == '3':
            func = input
        else:
            log.err('Undefined python version (%s).' % lib.python_version)
            break
        # add command into queue
        #lib.commands.append(func())
        try:
            execute_command(func())
        except EOFError as e: # Ctrl+D => exit
            exit_program(None, None)
Example #2
0
def main():
    global_parameters['UUID'] = get_local_uuid()
    lib.active_session = db['analysis'].get_last_session()
    db['analysis'].create_session(lib.active_session)
    log.info('Currently working with session #%d.' % lib.active_session)
    # check if already admin
    if is_admin():
        log.ok('Administrator privileges already granted on \'%s\'.' % (global_parameters['ACTIVEROOT']), dbnote=DBNOTE_UNIQUE)
    # if input from file, load commands into queue
    if args.input_file is not None:
        if os.access(args.input_file[0], os.R_OK):
            with open(args.input_file[0], 'r') as f:
                lib.commands = f.read().splitlines()
                lib.from_input_file = True
        else:
            log.err('Input file cannot be read!')

    # run all input commands
    while len(lib.commands) > 0:
        c = lib.commands[0]
        del lib.commands[0]
        if lib.from_input_file:
            log.prompt()            # print prompt
            log.attachline(c)       # print command
        execute_command(c)          # run the command

    lib.from_input_file = False
        
    # main loop
    while True:
        # input from stdin
        log.prompt()
        if lib.python_version[0] == '2':
            func = raw_input
        elif lib.python_version[0] == '3':
            func = input
        else:
            log.err('Undefined python version (%s).' % lib.python_version)
            break
        # add command into queue
        #lib.commands.append(func())
        execute_command(func())
Example #3
0
 def create_system(self, root):
     #if self.create_session(sessionid) == DB_ERROR:
     #    return DB_ERROR
     select = self.execute(
         "SELECT * FROM System WHERE root = :r AND fk_sessionid=:sid AND local_uuid = :u",
         {
             'r': root,
             'sid': lib.active_session,
             'u': lib.global_parameters['UUID']
         })
     if select == DB_ERROR:
         return DB_ERROR
     if len(select) == 0:
         result = self.execute(
             "INSERT INTO System(root, this, fk_sessionid, local_uuid) VALUES(:r, :this, :sid, :u)",
             {
                 'r': root,
                 'this': 1 if root == '/' else 0,
                 'sid': lib.active_session,
                 'u': lib.global_parameters['UUID']
             })
         if result == DB_ERROR:
             return DB_ERROR
         # try to determine platform
         platform = None
         if root == '/':
             import sys
             platform = sys.platform
         if platform is not None:
             log.ok("Detected OS platform for '%s': %s" % (root, platform))
             #result = self.add_property(root, 'platform', platform)
             systemid = self.get_systemid(root)
             if systemid == DB_ERROR:
                 return DB_ERROR
             result = self.add_data('platform', systemid, platform)
             if result == DB_ERROR:
                 return DB_ERROR
     return True
Example #4
0
 def create_system(self, root):
     #if self.create_session(sessionid) == DB_ERROR:
     #    return DB_ERROR
     select = self.execute("SELECT * FROM System WHERE root = :r AND fk_sessionid=:sid AND local_uuid = :u", 
                           {'r': root, 'sid': lib.active_session, 'u': lib.global_parameters['UUID']})
     if select ==  DB_ERROR:
         return DB_ERROR
     if len(select) == 0:
         result = self.execute("INSERT INTO System(root, this, fk_sessionid, local_uuid) VALUES(:r, :this, :sid, :u)", 
                               {'r': root, 'this': 1 if root == '/' else 0, 'sid': lib.active_session, 'u': lib.global_parameters['UUID']})
         if result == DB_ERROR:
             return DB_ERROR
         # try to determine platform
         platform = None
         if root == '/':
             import sys
             platform = sys.platform
         if platform is not None:
             log.ok("Detected OS platform for '%s': %s" % (root, platform))
             result = self.add_property(root, 'platform', platform)
             if result == DB_ERROR:
                 return DB_ERROR
     return True