def run(self): while True: dataRaw = None try: dataRaw = self.client_conn.recv(self.size) iv,dataEnc,dataHmac=dataRaw.split("nonce") dataAuth=verHmac(dataEnc,dataHmac) if not dataAuth: continue else: dataChecked=decrypt(dataEnc,iv) except socket.error, e: print(e.message) if dataRaw is not None: try: data = json.loads(dataChecked) print("Received : " + str(data)) dbutil = DBUtil() self.sema.acquire() dbutil.update_database(data) self.sema.release() except ValueError: continue self.client_conn.close() break
def run(self): global central_server_ip while True: data = None try: data = self.client_conn.recv(self.size) except socket.error, e: print(e.message) if data is not None: try: data = json.loads(data) print("Received : " + str(data)) db_util = DBUtil() db_util.update_database(data) except ValueError: continue serv_addr = (central_server_ip, MASTER_PORT) tcp_sock = None msg = {'op' : 'ACK'} try: tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_sock.connect(serv_addr) tcp_sock.sendto(json.dumps(msg), serv_addr) tcp_sock.close() except socket.error: print("Error in socket") if tcp_sock: tcp_sock.close() continue self.client_conn.close() break
def __init__(self, curr_directory, output_directory, max_file_size, plugins_file, es_url): """Initializes the Efetch Helper""" # Setup directory references self.curr_dir = curr_directory self.resource_dir = self.curr_dir + os.path.sep + u'resources' + os.path.sep self.icon_dir = self.resource_dir + u'icons' + os.path.sep self.output_dir = output_directory self.max_file_size = max_file_size if not os.path.isdir(self.icon_dir): logging.error(u'Could not find icon directory ' + self.icon_dir) self.pathspec_helper = PathspecHelper(output_directory, max_file_size) # Create plugin manager and begin polling for changes to plugins self.plugin_manager = EfetchPluginManager(plugins_file, self.curr_dir) self.poll = Poll(self.plugin_manager) self.poll.start() self.standard_office_2007_extensions = ['xlsx', 'docx', 'pptx', 'dotx', 'docm', 'doct', 'xlsm', 'xltx', 'xltm', 'pptx', 'pptm', 'potx', 'ppam', 'ppsx', 'ppsm', 'sldx', 'sldm'] # Elastic Search DB setup if es_url: self.db_util = DBUtil() else: self.db_util = DBUtil(es_url)
def test_validate_article_existence_ok_exists_status(self): result = DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[0]['article_id'], status=self.article_info_table_items[0]['status'] ) self.assertTrue(result)
def test_validate_article_existence_ok_exists_user(self): result = DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id=self.article_info_table_items[0]['user_id'], ) self.assertTrue(result)
def test_exists_article_ng_not_exists_article_id(self): result = DBUtil.exists_article( self.dynamodb, 'hogefugapiyo', user_id=self.article_info_table_items[0]['user_id'], ) self.assertFalse(result)
def test_put_article_content_edit_history_ok_exec_after_put_interval(self): user_id = 'test-user' article_id = 'test-article_id' body = 'test-body' article_content_edit_history_table = self.dynamodb.Table(os.environ['ARTICLE_CONTENT_EDIT_HISTORY_TABLE_NAME']) with freeze_time() as frozen_datetime: # 規定時間経過後に保存 version = '00' DBUtil.put_article_content_edit_history( dynamodb=self.dynamodb, user_id=user_id, article_id=article_id, sanitized_body=body + version, ) # 規定時間経過 frozen_datetime.tick(delta=datetime.timedelta(seconds=settings.ARTICLE_HISTORY_PUT_INTERVAL)) version = '01' DBUtil.put_article_content_edit_history( dynamodb=self.dynamodb, user_id=user_id, article_id=article_id, sanitized_body=body + version, ) # 2 件登録されていること expected_item_1 = { 'user_id': user_id, 'article_edit_history_id': article_id + '_01', 'body': body + '01', 'article_id': article_id, 'version': '01' } expected_item_2 = { 'user_id': user_id, 'article_edit_history_id': article_id + '_00', 'body': body + '00', 'article_id': article_id, 'version': '00' } items = article_content_edit_history_table.scan()['Items'] actual_items = sorted(items, key=lambda x: x['sort_key'], reverse=True) self.assertEqual(len(actual_items), 2) for key in expected_item_1.keys(): self.assertEqual(expected_item_1[key], actual_items[0][key]) for key in expected_item_2.keys(): self.assertEqual(expected_item_2[key], actual_items[1][key])
def __update_article_info(self): article_info_table = self.dynamodb.Table(os.environ['ARTICLE_INFO_TABLE_NAME']) expression_attribute_values = { ':title': TextSanitizer.sanitize_text(self.params.get('title')), ':overview': TextSanitizer.sanitize_text(self.params.get('overview')), ':eye_catch_url': self.params.get('eye_catch_url') } DBUtil.items_values_empty_to_none(expression_attribute_values) article_info_table.update_item( Key={ 'article_id': self.params['article_id'], }, UpdateExpression="set title = :title, overview=:overview, eye_catch_url=:eye_catch_url", ExpressionAttributeValues=expression_attribute_values )
def test_validate_not_exist_article(self): article_id = 'articleidxxx' user_id = 'purchaseuser001' self.assertTrue(DBUtil.validate_not_purchased( self.dynamodb, article_id, user_id ))
def test_main_ok_exists_content_edit_histories_one(self): params = { 'queryStringParameters': { 'article_id': 'publicId0001' }, 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******', 'phone_number_verified': 'true', 'email_verified': 'true' } } } } # 1件作成 test_body = 'test_body' DBUtil.put_article_content_edit_history( dynamodb=self.dynamodb, user_id=params['requestContext']['authorizer']['claims'] ['cognito:username'], article_id=params['queryStringParameters']['article_id'], sanitized_body=test_body, ) response = MeArticlesContentEditHistoriesIndex(params, {}, self.dynamodb).main() expected_item = { 'user_id': params['requestContext']['authorizer']['claims'] ['cognito:username'], 'article_edit_history_id': params['queryStringParameters']['article_id'] + '_' + '00', 'article_id': params['queryStringParameters']['article_id'], 'version': '00' } self.assertEqual(response['statusCode'], 200) actual_items = json.loads(response['body'])['Items'] self.assertEqual(len(actual_items), 1) for key in expected_item.keys(): self.assertEqual(expected_item[key], actual_items[0][key])
def exec_main_proc(self): # 下書き記事を保存 expression_attribute_values = { ':body': TextSanitizer.sanitize_article_body_v2(self.params.get('body')) } DBUtil.items_values_empty_to_none(expression_attribute_values) self.__update_article_content(expression_attribute_values) # 履歴を保存 DBUtil.put_article_content_edit_history( dynamodb=self.dynamodb, user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], article_id=self.params.get('article_id'), sanitized_body=expression_attribute_values[':body']) return {'statusCode': 200}
def test_exists_article_ok_exists_user_and_status(self): result = DBUtil.exists_article( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id=self.article_info_table_items[0]['user_id'], status=self.article_info_table_items[0]['status'] ) self.assertTrue(result)
def test_exists_article_ng_not_exists_status(self): result = DBUtil.exists_article( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id=self.article_info_table_items[0]['user_id'], status='draft' ) self.assertFalse(result)
def __update_article_content(self): article_content_table = self.dynamodb.Table( os.environ['ARTICLE_CONTENT_TABLE_NAME']) expression_attribute_values = { ':title': TextSanitizer.sanitize_text(self.params.get('title')), ':body': TextSanitizer.sanitize_article_body(self.params.get('body')) } DBUtil.items_values_empty_to_none(expression_attribute_values) article_content_table.update_item( Key={ 'article_id': self.params['article_id'], }, UpdateExpression="set title = :title, body=:body", ExpressionAttributeValues=expression_attribute_values)
def set_nickname(): logger = get_logger() if SessionKeys.NICKNAME in session: logger.debug( "Nickname already exists in session, so redirecting to home page" ) return redirect(URLs.HOME_PAGE) redirect_url = str(request.form['redirectURL']) if (not isinstance(redirect_url, str)) or (redirect_url == "None") or ( not redirect_url.strip()): redirect_url = "/" nickname = str(request.form['nickname']).strip() logger.debug( "Received setNickname request with parameters - redirect_url: '" + redirect_url + "', nickname: '" + nickname + "'") # make user reenter nickname if it's blank if not nickname: logger.debug("User needs to reenter nickname since it's blank") return redirect_to_nickname_page(redirect_url, True, False, False) # make user reenter nickname if it contains profanity lowercase_nickname_split = nickname.casefold().split() for bad_word in app_constants.BAD_WORDS: if bad_word in lowercase_nickname_split: logger.debug( "User needs to reenter nickname since they used profanity") return redirect_to_nickname_page(redirect_url, False, True, False) # make user reenter nickname if it already exists db_util = DBUtil(get_db_connection()) if db_util.does_nickname_exist(nickname): logger.debug( "User needs to reenter nickname since it already exists") return redirect_to_nickname_page(redirect_url, False, False, True) user_id = db_util.add_user(nickname) logger.debug("Added user with id: " + str(user_id) + " and nickname: '" + nickname + "'") session[SessionKeys.NICKNAME] = nickname session[SessionKeys.USER_ID] = user_id return redirect(redirect_url)
def test_validate_user_existence_in_thread_ok(self): for user_id in [ self.comment_items[0]['user_id'], self.comment_items[1]['user_id'] ]: result = DBUtil.validate_user_existence_in_thread( self.dynamodb, user_id, self.comment_items[0]['comment_id']) self.assertTrue(result)
def validate_params(self): validate(self.params, self.get_schema()) if self.params.get('tags'): ParameterUtil.validate_array_unique(self.params['tags'], 'tags', case_insensitive=True) TagUtil.validate_format(self.params['tags']) DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='draft') DBUtil.validate_topic(self.dynamodb, self.params['topic'])
def test_validate_not_purchased_only_fail(self): article_id = 'articleid003' user_id = 'purchaseuser001' self.assertTrue(DBUtil.validate_not_purchased( self.dynamodb, article_id, user_id ))
def get_user_info(cls, in_user_id): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 user_info_dict = dict() sql_stm = "select user_name,user_nick_name,user_signature,user_gender_id,user_birthday," \ "user_telephone,user_email,user_introduce,user_head,user_age,user_vocation," \ "user_nation_id,user_province_id,user_city_id,user_register_time " \ "from user_info where user_id={}".format(in_user_id) result = db.get_res(sql_stm) if result: user_info_dict['name'] = result[0][0] # 用户名 user_info_dict['nick_name'] = result[0][1] # 用户昵称 user_info_dict['signature'] = result[0][2] # 用户签名 user_info_dict['gender_id'] = result[0][3] # 用户性别,1为男,2为女,3为保密 if result[0][4] is None: user_info_dict['birthday'] = '' user_info_dict['age'] = 0 else: user_info_dict['birthday'] = str(result[0][4]) # 用户生日 user_info_dict['age'] = localtime(time())[0] - int( str(result[0][4]).split('-')[0]) # 用户年龄 user_info_dict['telephone'] = result[0][5] # 设置用户登录手机号,非空 user_info_dict['email'] = result[0][6] # 设置登录邮箱,非空 # self.introduce = result[0][7] # 用户介绍bbb # self.head = result[0][8] # 用户头像 user_info_dict['vocation'] = result[0][10] # 用户的职业信息 # self.nation_id = result[0][11] # 用户所属国家 # self.province_id = result[0][12] # 用户所属省 # self.city_id = result[0][13] # 用户所属城市 user_info_dict['register_time'] = str( result[0][14].date()) # 用户注册时间,非空 return str(user_info_dict)
def set_user_info(cls, in_user_id, user_info_dict): nick_name = user_info_dict['nick_name'] # 用户昵称 signature = user_info_dict['signature'] # 用户签名 gender_id = user_info_dict['gender_id'] # 用户性别,1为男,2为女,3为保密 birthday = user_info_dict['birthday'] # 用户生日 if birthday != '': age = user_info_dict['age'] = localtime(time())[0] - int( birthday.split('-')[0]) # 用户年龄 birthday = "'{}'".format(birthday) else: age = 0 birthday = 'null' telephone = user_info_dict['telephone'] # 设置用户登录手机号,非空 email = user_info_dict['email'] # 设置登录邮箱,非空 vocation = user_info_dict['vocation'] # 用户的职业信息 db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_nick_name='{}',user_signature='{}',user_gender_id={}," \ "user_birthday={},user_telephone='{}',user_email='{}'," \ "user_age={},user_vocation='{}' " \ "where user_id={}".format(nick_name, signature, gender_id, birthday, telephone, email, age, vocation, in_user_id) result = db.exc_sql(sql_stm) return result
def validate_params(self): if self.event.get('pathParameters') is None: raise ValidationError('pathParameters is required') validate(self.params, self.get_schema()) if self.params.get('tags'): ParameterUtil.validate_array_unique(self.params['tags'], 'tags', case_insensitive=True) TagUtil.validate_format(self.params['tags']) DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], user_id=self.event['requestContext']['authorizer']['claims']['cognito:username'], status='public' ) DBUtil.validate_topic(self.dynamodb, self.params['topic'])
def get_article_info(date_str): """ 查询publish_time在一定的时间之后的文章ID :param date_str: 给定的时间字符串,格式为 yyyy-mm-dd HH:MM:SS. :return: 返回的结果是一个list,其中每一项都是dict,利用列的名字进行索引即可。 """ sql = "SELECT id, url, image_url FROM t_article WHERE publish_time <= \"%s\"" % date_str result = DBUtil.select_datas(sql) return result
def test_validate_article_existence_ok_exists_user_and_status_and_is_purchased( self): result = DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[1]['article_id'], user_id=self.article_info_table_items[1]['user_id'], status=self.article_info_table_items[1]['status'], is_purchased=True) self.assertTrue(result)
def validate_params(self): if not self.event.get('pathParameters'): raise ValidationError('pathParameters is required') if not self.event.get('body') or not json.loads( self.event.get('body')): raise ValidationError('Request parameter is required') validate(self.params, self.get_schema(), format_checker=FormatChecker()) DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='public')
def test_put_article_content_edit_history_ok_with_loop(self): user_id = 'test-user' article_id = 'test-article_id' body = 'test-body' article_content_edit_history_table = self.dynamodb.Table( os.environ['ARTICLE_CONTENT_EDIT_HISTORY_TABLE_NAME']) settings.ARTICLE_HISTORY_PUT_INTERVAL = 0 # 合計で 101 回保存(ループさせる) for i in range(101): version = str(i).zfill(2) DBUtil.put_article_content_edit_history( dynamodb=self.dynamodb, user_id=user_id, article_id=article_id, sanitized_body=body + version, ) # 意図した順序でデータを取得できること # article_content_edit_history を取得。body 値も確認したいため index を利用せず scan で取得し、ソートは独自に実施する。 # (容量削減の観点で index には body を含めていないため scan で取得する必要がある) items = article_content_edit_history_table.scan()['Items'] actual_items = sorted(items, key=lambda x: x['sort_key'], reverse=True) # 100件登録されていること self.assertEqual(len(actual_items), 100) # loop 確認。101 回実行しているため version が 00、99、98.... となる順序でデータが取得される。 for i in range(100): # 先頭データはループしているため version は 00 となるが、body の内容は 101 回目に書き込んだデータが設定される if i == 0: test_version = '00' test_body = body + '100' # ループしていないデータは、99、98、.. 01 のように降順となる else: test_version = str(100 - i).zfill(2) test_body = body + test_version expected_item = { 'user_id': user_id, 'article_edit_history_id': article_id + '_' + test_version, 'body': test_body, 'article_id': article_id, 'version': test_version, } for key in expected_item.keys(): self.assertEqual(expected_item[key], actual_items[i][key])
def del_group(self): db = DBUtil() db.connect_db() db.cur_db() sql_stm = "delete from group_info where group_admin_id={} and group_name='{}'"\ .format(self.admin_id, self.group_name) result = db.exc_sql(sql_stm) return result
def add_friend_group(self): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "insert into friend_group(friend_group_name,friend_group_user_id) " \ "values('{}',{})".format(self.group_name, self.group_user_id) result = db.exc_sql(sql_stm) return result
def del_friend_group(self): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "delete from friend_group where friend_group_name='{}' and friend_group_user_id={}"\ .format(self.group_name, self.group_user_id) result = db.exc_sql(sql_stm) return result
def rename_group(self, new_group_name): db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update friend_group set friend_group_name='{}' where friend_group_user_id={}"\ .format(new_group_name, self.group_user_id) result = db.exc_sql(sql_stm) return result
def set_friend_policy(self, friendship_policy_id): self.friendship_policy_id = friendship_policy_id db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_friendship_policy_id={} " \ "where user_name='{}'".format(self.friendship_policy_id, self.name) return db.exc_sql(sql_stm)
def set_status(self, status_id): self.status_id = status_id db = DBUtil() # 创建数据库对象 db.connect_db() # 创建连接对象 db.cur_db() # 创建游标 sql_stm = "update user_info set user_status_id={} " \ "where user_name='{}'".format(self.status_id, self.name) return db.exc_sql(sql_stm)
def exec_main_proc(self): params = self.event.get('pathParameters') article_info_table = self.dynamodb.Table( os.environ['ARTICLE_INFO_TABLE_NAME']) article_content_table = self.dynamodb.Table( os.environ['ARTICLE_CONTENT_TABLE_NAME']) article_info = article_info_table.get_item( Key={ 'article_id': params['article_id'] }).get('Item') article_content = article_content_table.get_item( Key={ 'article_id': params['article_id'] }).get('Item') DBUtil.validate_article_existence( self.dynamodb, params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='draft') if 'price' in article_info: article_content['body'] = article_content['paid_body'] article_content.pop('paid_body', None) # version が指定されていた場合は、指定の version で body を上書き if self.params.get('version') is not None: article_content_edit_history = DBUtil.get_article_content_edit_history( self.dynamodb, self.event['requestContext']['authorizer'] ['claims']['cognito:username'], self.params['article_id'], self.params['version']) article_content['body'] = article_content_edit_history.get('body') if article_content is not None: article_info.update(article_content) return { 'statusCode': 200, 'body': json.dumps(article_info, cls=DecimalEncoder) }
def test_query_all_items_with_no_limit(self): article_pv_user_table = self.dynamodb.Table(os.environ['ARTICLE_PV_USER_TABLE_NAME']) query_params = { 'IndexName': 'target_date-sort_key-index', 'KeyConditionExpression': Key('target_date').eq('2018-05-01') } response = DBUtil.query_all_items(article_pv_user_table, query_params) self.assertEqual(len(response), 4)
def run(self): while True: data = None try: data = self.client_conn.recv(self.size) except socket.error, e: print(e.message) if data is not None: try: data = json.loads(data) print("Received : " + str(data)) dbutil = DBUtil() self.sema.acquire() dbutil.update_database(data) self.sema.release() except ValueError: continue self.client_conn.close() break
class EfetchHelper(object): """This class provides helper methods to be used in Efetch and its plugins""" def __init__(self, curr_directory, output_directory, max_file_size, plugins_file, es_url): """Initializes the Efetch Helper""" # Setup directory references self.curr_dir = curr_directory self.resource_dir = self.curr_dir + os.path.sep + u'resources' + os.path.sep self.icon_dir = self.resource_dir + u'icons' + os.path.sep self.output_dir = output_directory self.max_file_size = max_file_size if not os.path.isdir(self.icon_dir): logging.error(u'Could not find icon directory ' + self.icon_dir) self.pathspec_helper = PathspecHelper(output_directory, max_file_size) # Create plugin manager and begin polling for changes to plugins self.plugin_manager = EfetchPluginManager(plugins_file, self.curr_dir) self.poll = Poll(self.plugin_manager) self.poll.start() self.standard_office_2007_extensions = ['xlsx', 'docx', 'pptx', 'dotx', 'docm', 'doct', 'xlsm', 'xltx', 'xltm', 'pptx', 'pptm', 'potx', 'ppam', 'ppsx', 'ppsm', 'sldx', 'sldm'] # Elastic Search DB setup if es_url: self.db_util = DBUtil() else: self.db_util = DBUtil(es_url) def get_request_value(self, request, variable_name, default=None): """Gets the value of a variable in either a GET or POST request""" if variable_name in request.query: return request.query[variable_name] elif request.forms.get(variable_name): return request.forms.get(variable_name) return default def get_query_string(self, request, default_query=''): """Returns the query string of the given request""" if request.query_string: return "?" + request.query_string else: return default_query def get_query(self, request): """Gets the Kibana Query from the request""" return self.db_util.get_query(self.get_request_value(request, '_a', '()')) def get_theme(self, request): """Gets the Kibana Theme from the request""" return self.db_util.get_theme(self.get_request_value(request, '_a', '()')) def get_filters(self, request, must=[], must_not=[]): """Gets the Kibana Filter from the request""" return self.db_util.get_filters(self.get_request_value(request, '_a', '()'), self.get_request_value(request, '_g', '()'), self.get_request_value(request, 'timefield', 'datetime'), must, must_not) def is_expandable_evidence(self, evidence): """Returns True if evidence should be expandable and false if not""" # Separated for cleanliness, ordering matters here # Partitions and volume shadows are expandable if 'type_indicator' in evidence and evidence['type_indicator'] in ['TSK_PARTITION', 'VSHADOW']: return True # Volumes are expandable if 'volume_type' in evidence: return True # Most Storage types are expandable if 'storage_type' in evidence: # Not E02-E0N files if evidence['extension'].lower().startswith('e0') and evidence['extension'].lower() != 'e01': return False # All other storage types are expandable return True # Compression types are expandable if 'compression_type' in evidence: return True # Most archive types are expandable if 'archive_type' in evidence: # Not files with office 2007 mimetypes if evidence['mimetype'].startswith('application/vnd'): return False # Not files with office 2007 extensions if evidence['extension'].lower() in self.standard_office_2007_extensions: return False # All other archives are expandable return True # Everything else is not expandable return False def get_icon(self, evidence, resource=True): """Returns either an icon or thumbnail of the provided file""" if resource: curr_icon_dir = '/resources/icons/' else: curr_icon_dir = self.icon_dir if 'volume_type' in evidence or 'storage_type' in evidence or 'compression_type' in evidence \ or 'archive_type' in evidence: if not evidence['mimetype_known']: evidence['mimetype'] = self.pathspec_helper.get_mimetype(evidence['pathspec']) if self.is_expandable_evidence(evidence): return curr_icon_dir + '_evidence.png' if not 'meta_type' in evidence: return curr_icon_dir + '_blank.png' # If it is folder just return the folder icon if evidence['meta_type'] == 'Directory' or unicode(evidence['file_name']).strip() == "." or unicode( evidence['file_name']).strip() == "..": return curr_icon_dir + '_folder.png' if evidence['meta_type'] != 'File' and evidence['meta_type'] != 'Device': return curr_icon_dir + '_blank.png' # If the file is an image create a thumbnail if evidence['mimetype'].startswith('image') and resource: return '/plugins/thumbnail?' + evidence['url_query'] elif evidence['mimetype'].startswith('image'): self.pathspec_helper.create_thumbnail(evidence) if os.path.isfile(evidence['thumbnail_cache_path']): return evidence['thumbnail_cache_path'] else: return curr_icon_dir + '_missing.png' # TODO if mimetype is known, perform a mimetype to extension lookup instead of using extension # If file is not an image return the icon associated with the files extension else: if not os.path.isfile(self.icon_dir + str(evidence['extension']).lower() + '.png'): return curr_icon_dir + '_blank.png' else: return curr_icon_dir + evidence['extension'].lower() + '.png' def action_get(self, evidence, request, display_name, function, term, update_term = False): """Runs a function that takes an evidence item, updates the term in elastic, and returns the results""" index = self.get_request_value(request, 'index', False) value = '' # Only needed when using elasticsearch just else just return the OCR if index: # If using elasticsearch get the first entry query = {'_source': [term, evidence['pathspec']], 'query': {'term': {'pathspec.raw': evidence['pathspec']}}} first_elastic_entry = self.db_util.query_sources(query, index, 1) # If this plugin has not been run on this entry run it on all entries if term not in first_elastic_entry or update_term: # Not masking the exception, should be handled by plugin value = function(evidence, self) try: update = {term: value} events = self.db_util.scan(query, index) for item in events: logging.debug('Updating elasticsearch item: ' + str(item)) self.db_util.update(item['_id'], index, update, doc_type=item['_type']) except: logging.warn('Failed to update value in elasticsearch') else: value = first_elastic_entry[term] else: value = function(evidence, self) return value