Example #1
0
    def sqlite3(self, sql, data, output_type, number_of_row, database):
        import sqlite3
        try:
            db = sqlite3.connect(database)
            if output_type != 'Dict':
                db_cursor = db.cursor()
                db.row_factory = self.dict_factory
            else:
                db_cursor = db.cursor()

            if data is None:
                db_instance = db_cursor.execute(sql)
                if number_of_row == 1:
                    raw_data = db_instance.fetchone()
                elif number_of_row > 0:
                    raw_data = db_instance.fetchmany(number_of_row)
                else:
                    raw_data = db_instance.fetchall()
                if output_type == "List":
                    return DaPr.merge_multi_tuple_list(object, raw_data)
                else:
                    return raw_data
            else:
                db_cursor.execute(sql, data)
                db.commit()
        finally:
            # print("[!!]数据库写入失败请联系[email protected]")
            return False
Example #2
0
 def get_event_data(self,
                    server,
                    event_channel,
                    start,
                    end,
                    print_event_item=False,
                    event_filter=None,
                    enable_message=False):
     channels = []
     processed_data = []
     if type(event_channel) is not list:
         channels.append(event_channel)
     elif type(event_channel) is list:
         channels = event_channel
     else:
         raise TypeError
     for channel in channels:
         core, flags = self.gen_event_log_core(server, channel)
         event_log_data = self.get_win_event_log(core, flags)
         single_channel_data = self.process_win_event_log(
             event_log_data, start, end, print_event_item, event_filter,
             enable_message)
         processed_data.append(single_channel_data)
     processed_data = DaPr.merge_lists(processed_data)
     return processed_data
Example #3
0
 def open_file(self, program, selected_dir, param):
     if param is None:
         param_x = ' '
     else:
         param_x = param
     os.system("{} {} {}".format(program,
                                 DaPr.replace_dir_slash(selected_dir),
                                 param_x))
Example #4
0
    def process_win_event_log(self,
                              events,
                              start,
                              end,
                              print_event_item=False,
                              event_filter=None,
                              enable_message=False):
        package = []
        event_filter_x = []
        # print(event_filter_x)
        if event_filter is None:
            for k, v in self.event_dict:
                event_filter_x.append(v)
        elif type(event_filter) is list:
            for item in event_filter:
                event_filter_x.append(self.event_dict[item])

        timestamp_start = DaPr.datetime_to_timestamp(
            DaPr.string_to_datetime(start))
        timestamp_end = DaPr.datetime_to_timestamp(
            DaPr.string_to_datetime(end))
        for event in events:
            # print(event.TimeGenerated,event.SourceName)
            timestamp_event_time = DaPr.datetime_to_timestamp(
                event.TimeGenerated)
            if timestamp_start < timestamp_event_time > timestamp_end:
                # print(start, event.TimeGenerated, end)
                data_set = {
                    self.item_category: event.EventCategory,
                    self.item_time: event.TimeGenerated,
                    self.item_source_name: event.SourceName,
                    self.item_id: str(event.EventID),
                    self.event_type: event.EventType,
                    self.event_message: "disabled",
                }
                if enable_message:
                    data_set[self.event_message] = event.StringInserts
                if event.EventType in event_filter_x:
                    if print_event_item:
                        print(data_set)
                    package.append(data_set)
        return package
Example #5
0
 def Make(self, OprType, Config):
     Unziped = {
         'Temp': [],
         'Cols': None,
         'Values': None,
         'WhereIsNotNull': None,
         'PrimeryKey': None,
         'WhereValues': None,
     }
     Primery = ['WhereValues']
     GUA = ['Cols', 'WhereIsNotNull',
            'PrimeryKey']  # The gourp is using '[]'
     GUB = []  # The gourp is using ''''
     GUC = ['Values']
     for DataSet in Primery + GUA + GUB + GUC:
         if len(Config[DataSet]) > 0:
             for Element in Config[DataSet]:
                 if DataSet in GUA:
                     Unziped['Temp'].append("[%s]" % Element)
                 elif DataSet in GUB:
                     Unziped['Temp'].append("'%s'" % Element)
                 elif DataSet in GUC and Primery:
                     Unziped['Temp'].append(" %s = '%s' " % (Element))
             Unziped[DataSet] = reduce(
                 lambda x, y: x + y,
                 DaPr.insert_values_to_list(Unziped['Temp'], ","))
             Unziped['Temp'].clear()
         else:
             pass
     SQLTemplats = {
         'SelectRaw':
         "SELECT %s FROM [%s].[%s].[%s] " %
         (Config['SelectType'], Config['Database'], Config['DBO'],
          Config['TableName']),
         'Select':
         "SELECT %s %s FROM [%s].[%s].[%s] WHERE %s IS NOT NULL " %
         (Config['SelectType'], Unziped['Cols'], Config['Database'],
          Config['DBO'], Config['TableName'], Unziped['WhereIsNotNull']),
         'Insert':
         "INSERT INTO [%s].[%s].[%s](%s) VALUES(%s)" %
         (Config['Database'], Config['DBO'], Config['TableName'],
          Unziped['Cols'], Unziped['Values']),
         'Update':
         "UPDATE [%s].[%s].[%s] SET %s WHERE %s" %
         (Config['Database'], Config['DBO'], Config['TableName'],
          Unziped['Values'], Unziped['WhereValues'])
     }
     return SQLTemplats[OprType]
Example #6
0
 def vba_con(self, vba_file, vba_function, excel_visible, save_changes,
             result_path, result_file_type):
     print("CreatExcelApp")
     excel_book = ExlCom(vba_file, is_visible=excel_visible)
     print("Execute VBAFunction")
     excel_book.run_vba(vba_function)
     print("CloseExcelFile")
     excel_book.close(save_changes=save_changes)  # 关闭excel,不保存
     if result_path is None:
         pass
     else:
         print("OpenResult")
         Infra.open_file(
             'start',
             DaPr.find_newest_file_in_windows(result_path,
                                              result_file_type), None)
     print("JobDone")
Example #7
0
    def sqlite3_debug(self, sql, data, output_type, number_of_row, database):
        db = sqlite3.connect(database)
        if output_type != 'Dict':
            db_cursor = db.cursor()
            db.row_factory = self.dict_factory
        else:
            db_cursor = db.cursor()

        if data is None:
            db_instance = db_cursor.execute(sql)
            if number_of_row == 1:
                raw_data = db_instance.fetchone()
            elif number_of_row > 0:
                raw_data = db_instance.fetchmany(number_of_row)
            else:
                raw_data = db_instance.fetchall()
            if output_type == "List":
                return DaPr.merge_multi_tuple_list(raw_data)
            else:
                return raw_data
        else:
            db_cursor.execute(sql, data)
            db.commit()
Example #8
0
 def open_dir(self, selected_dir):
     os.system("explorer %s" % DaPr.replace_dir_slash(selected_dir))
Example #9
0
import os
import shutil
import time
import urllib.parse as parse
import uuid

from lfcomlib.Jessica import DaPr
from lfcomlib.Jessica.Err import logger_i

DaPr = DaPr.Core()


class Core:
    def __init__(self):
        self.db_opr_type = {
            "close": "close",
            "insert": "insert",
            "commit": "commit",
            "update": "update",
            "select": "select"
        }
        self.db_cfg_save = None
        self.db_instance = None
        self.db_controller = None
        self.db_connect_error = None
        self.log_cfg = {}

    def get_mac_address(self):
        mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
        return ":".join([mac[e:e + 2] for e in range(0, 11, 2)])