def _get_taxii2_client_common_replace_dict(request): replace_dict = get_common_replace_dict(request) replace_dict['taxii2_clients'] = Taxii2Clients.objects.all() replace_dict['protocol_versions'] = Taxii2Clients.get_protocol_versions() replace_dict['communities'] = Communities.objects.all() replace_dict['users'] = STIPUser.objects.all() return replace_dict
def create(request): if request.method != 'POST': return error_page_free_format(request, 'invalid method') # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) # is_admin権限なしの場合はエラー if not request.user.is_admin: return error_page_no_view_permission(request) try: name = get_configuration_community_create_community_name(request) if(name is None or len(name) == 0): return error_page_free_format(request, 'No Community Name.') # community初期化処理 try: Communities.init_community(name) except Exception as e: return error_page_free_format(request, e.message) # 結果返却 replace_dict = get_common_replace_dict(request) replace_dict['communities'] = Communities.objects.all() replace_dict['info_msg'] = 'Create Success!!' # レンダリング return render(request, 'community.html', replace_dict) except Exception: # エラーページ return error_page(request)
def start(request, id_): if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) protocol_version = get_protocol_version(request) start = get_datetime_from_string(get_start_start(request)) end = get_datetime_from_string(get_start_end(request)) try: replace_dict = get_common_replace_dict(request) if protocol_version.startswith('1.'): taxii_client = TaxiiClients.objects.get(id=id_) replace_dict['taxii'] = taxii_client cl = Client(taxii_client=taxii_client) elif protocol_version.startswith('2.'): taxii2_client = Taxii2Clients.objects.get(id=id_) replace_dict['taxii'] = taxii2_client cl = Client(taxii2_client=taxii2_client) else: raise Exception('Invalid taxii protocol version.') if cl._can_read: cl.set_start_time(start) cl.set_end_time(end) count = cl.poll() replace_dict[ 'info_msg'] = 'Poll end successfully!! (Get %d stix files.)' % ( count) else: replace_dict['error_msg'] = 'This collection is not for polling' return render(request, 'poll_detail.html', replace_dict) except Exception: return error_page(request)
def delete_webhook(request): # POST以外はエラー if request.method != 'GET': return error_page_free_format(request, 'invalid method') # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) # is_admin権限なしの場合はエラー if not request.user.is_admin: return error_page_no_view_permission(request) # community_id取得 community_id = get_configuration_community_delete_webhook_community_id(request) # webhook_id取得 webhook_id = get_configuration_community_delete_webhook_webhook_id(request) if ((community_id is None) or (webhook_id is None)): return error_page_free_format(request, 'invalid arguments.') try: # Webhookドキュメント取得 w = Webhooks.objects.get(id=webhook_id) # communityドキュメント取得 c = Communities.objects.get(id=community_id) # webhooksリストからwebhookを削除 c.webhooks.remove(w) c.save() replace_dict = get_common_replace_dict(request) replace_dict['community'] = c # レンダリング return render(request, 'community_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)
def remove(request, taxii_id, job_id): if request.method != 'GET': return error_page_free_format(request, 'invalid method') #activeユーザー以外はエラー if request.user.is_active == False: return error_page_inactive(request) #is_admin権限なしの場合はエラー if request.user.is_admin == False: return error_page_no_view_permission(request) try: #mongoのtaxii_client情報から該当job_idを削除 taxii_client = TaxiiClients.objects.get(id=taxii_id) taxii_client.remove_job(job_id) #job停止 client = Client(taxii_id=taxii_id) client.remove_job(job_id) replace_dict = get_common_replace_dict(request) #mongoからtaxii_client情報を取得 replace_dict['client'] = TaxiiClients.objects.get(id=taxii_id) #レンダリング return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: #エラーページ return error_page(request)
def interval(request, taxii_id): if request.method != 'GET': return error_page_free_format(request, 'invalid method') if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) try: interval = get_configuartion_taxii_client_detail_interval_interval(request) taxii_client = TaxiiClients.objects.get(id=taxii_id) client = Client(taxii_client=taxii_client) client.remove_interval_job() taxii_client.interval_schedule_job = None taxii_client.save() if interval != 0: schedule_job = taxii_client.add_job(type_=ScheduleJobs.JOB_INTERVAL, seconds=interval) client.add_job(schedule_job) replace_dict = get_common_replace_dict(request) replace_dict['client'] = taxii_client if interval != 0: replace_dict['interval_info_msg'] = 'Set Interval %d sec' % (interval) else: replace_dict['interval_info_msg'] = 'Stop a job by interval' return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: return error_page(request)
def add_webhook(request): # POST以外はエラー if request.method != 'GET': return error_page_free_format(request, 'invalid method') # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) # is_admin権限なしの場合はエラー if not request.user.is_admin: return error_page_no_view_permission(request) # community_id取得 community_id = get_configuration_community_add_webhook_community_id(request) # url取得 url = get_configuration_community_add_webhook_url(request) if ((community_id is None) or (url is None)): return error_page_free_format(request, 'invalid arguments.') try: # webhook作成 webhook = Webhooks() webhook.url = url webhook.save() # communityに追加 c = Communities.objects.get(id=community_id) c.webhooks.append(webhook) c.save() replace_dict = get_common_replace_dict(request) replace_dict['community'] = c # レンダリング return render(request, 'community_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)
def get_success_replace_dict(request): replace_dict = get_common_replace_dict(request) try: replace_dict['system'] = System.objects.get() except BaseException: replace_dict['system'] = None return replace_dict
def create(request, taxii_id): if request.method != 'POST': return error_page_free_format(request, 'invalid method') #activeユーザー以外はエラー if request.user.is_active == False: return error_page_inactive(request) #is_admin権限なしの場合はエラー if request.user.is_admin == False: return error_page_no_view_permission(request) try: time = get_configuartion_taxii_client_detail_create_time(request) #mongoからtaxii_client情報を取得 taxii_client = TaxiiClients.objects.get(id=taxii_id) #Cron設定 times = time.split(':') schedule_job = taxii_client.add_job(type_=ScheduleJobs.JOB_CRON, hour=times[0], minute=times[1], second=times[2]) #job追加 client = Client(taxii_id=taxii_id) client.add_job(schedule_job) replace_dict = get_common_replace_dict(request) replace_dict['client'] = taxii_client #レンダリング return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: #エラーページ return error_page(request)
def change_password(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) try: replace_dict = get_common_replace_dict(request) old_password = get_profile_change_password_old_password(request) new_password = get_profile_change_password_new_password(request) user = request.user # 古いパスワードが正しいかチェック if not user.check_password(old_password): # 古いパスワードが間違っている replace_dict[ 'error_change_password_msg'] = 'Old Password is wrong!!' return render(request, 'profile.html', replace_dict) # 新しいパスワードに変更 user.set_password(new_password) if user.username == 'admin': # build_in account のパスワード変更 STIPUser.change_build_password(new_password) user.is_modified_password = True user.save() # レンダリング return render(request, 'change_password_done.html', replace_dict) except Exception: # エラーページ return error_page(request)
def top(request, taxii_id): if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) try: replace_dict = get_common_replace_dict(request) replace_dict['client'] = TaxiiClients.objects.get(id=taxii_id) return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: return error_page(request)
def detail(request, id_): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) try: replace_dict = get_common_replace_dict(request) replace_dict['taxii'] = TaxiiClients.objects.get(id=id_) # レンダリング return render(request, 'poll_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)
def top(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) try: replace_dict = get_common_replace_dict(request) replace_dict['communities'] = Communities.objects.all() # レンダリング return render(request, 'upload.html', replace_dict) except Exception: # エラーページ return error_page(request)
def top(request): if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) try: replace_dict = get_common_replace_dict(request) replace_dict['taxii_clients'] = TaxiiClients.objects.all() replace_dict['taxii2_clients'] = Taxii2Clients.objects.all() return render(request, 'poll.html', replace_dict) except Exception: return error_page(request)
def top(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) try: replace_dict = get_common_replace_dict(request) replace_dict['taxii_clients'] = TaxiiClients.objects.all() # レンダリング return render(request, 'poll.html', replace_dict) except Exception: # エラーページ return error_page(request)
def top(request, msg=None): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) try: replace_dict = get_common_replace_dict(request) if msg is not None: replace_dict['error_change_password_msg'] = msg # レンダリング return render(request, 'profile.html', replace_dict) except Exception: # エラーページ return error_page(request)
def isight_common_render(request, info_msg=None, error_msg=None): try: replace_dict = get_common_replace_dict(request) # mongoからisight情報を取得 ia = isightAdapter.get() replace_dict['isight'] = ia if info_msg is not None: replace_dict['interval_info_msg'] = info_msg if error_msg is not None: replace_dict['interval_error_msg'] = error_msg # レンダリング return render(request, 'isight_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)
def otx_common_render(request, info_msg=None, error_msg=None): try: replace_dict = get_common_replace_dict(request) # mongoからotx情報を取得 oa = OtxAdapter.get() replace_dict['otx'] = oa if info_msg is not None: replace_dict['interval_info_msg'] = info_msg if error_msg is not None: replace_dict['interval_error_msg'] = error_msg # レンダリング return render(request, 'otx_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)
def detail(request, mongo_id): #activeユーザー以外はエラー if request.user.is_active == False: return error_page_inactive(request) #is_admin権限なしの場合はエラー if request.user.is_admin == False: return error_page_no_view_permission(request) try: replace_dict = get_common_replace_dict(request) replace_dict['community'] = Communities.objects.get(id=mongo_id) #レンダリング return render(request, 'community_detail.html', replace_dict) except Exception: #エラーページ return error_page(request)
def top(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) # is_admin権限なしの場合はエラー if not request.user.is_admin: return error_page_no_view_permission(request) try: replace_dict = get_common_replace_dict(request) replace_dict['communities'] = Communities.objects.all() # レンダリング return render(request, 'community.html', replace_dict) except Exception: # エラーページ return error_page(request)
def misp_common_render(request, info_msg=None, error_msg=None): try: replace_dict = get_common_replace_dict(request) # mongo から misp 情報を取得 ma = MispAdapter.get() replace_dict['misp'] = ma if info_msg is not None: replace_dict['interval_info_msg'] = info_msg if error_msg is not None: replace_dict['interval_error_msg'] = error_msg # レンダリング return render(request, 'misp_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)
def top(request): #activeユーザー以外はエラー if request.user.is_active == False: return error_page_inactive(request) #is_admin権限なしの場合はエラー if request.user.is_admin == False: return error_page_no_view_permission(request) try: replace_dict = get_common_replace_dict(request) replace_dict['users'] = STIPUser.objects.all() #レンダリング return render(request, 'user.html', replace_dict) except Exception: #エラーページ return error_page(request)
def pause(request, taxii_id, job_id): if request.method != 'GET': return error_page_free_format(request, 'invalid method') if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) try: taxii_client = TaxiiClients.objects.get(id=taxii_id) client = Client(taxii_client=taxii_client) client.pause_job(job_id) replace_dict = get_common_replace_dict(request) replace_dict['client'] = taxii_client return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: return error_page(request)
def change_password_top(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) # is_admin権限なしの場合はエラー if not request.user.is_admin: return error_page_no_view_permission(request) try: username = get_configuration_user_change_password_top_username(request) replace_dict = get_common_replace_dict(request) replace_dict['change_pwd_username'] = username # レンダリング return render(request, 'change_pwd.html', replace_dict) except Exception: # エラーページ return error_page(request)
def detail(request, id_): if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) try: protocol_version = get_protocol_version(request) replace_dict = get_common_replace_dict(request) if protocol_version.startswith('1.'): replace_dict['taxii'] = TaxiiClients.objects.get(id=id_) elif protocol_version.startswith('2.'): replace_dict['taxii'] = Taxii2Clients.objects.get(id=id_) else: raise Exception('Invalid taxii protocol version.') return render(request, 'poll_detail.html', replace_dict) except Exception: return error_page(request)
def top(request, taxii_id): #activeユーザー以外はエラー if request.user.is_active == False: return error_page_inactive(request) #is_admin権限なしの場合はエラー if request.user.is_admin == False: return error_page_no_view_permission(request) try: replace_dict = get_common_replace_dict(request) #mongoからtaxii_client情報を取得 replace_dict['client'] = TaxiiClients.objects.get(id=taxii_id) #レンダリング return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: #エラーページ return error_page(request)
def upload(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) # post以外はエラー if request.method != 'POST': # エラー画面 raise Exception('Invalid HTTP Method') try: # uploaderIDを取得する uploader = int(request.user.id) # viaを取得 via = Vias.get_via_file_upload(uploader=uploader) # upload処理 upload_common(request, via) replace_dict = get_common_replace_dict(request) return render(request, 'success.html', replace_dict) except Exception: return error_page(request)
def change_screen_name(request): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) try: replace_dict = get_common_replace_dict(request) screen_name = get_profile_change_screen_name_screen_name(request) if len(screen_name) == 0: # スクリーン名長が0 return render(request, 'profile.html', replace_dict) user = request.user user.screen_name = screen_name user.save() replace_dict['info_change_screen_msg'] = 'Change Screen Name Success!!' # レンダリング return render(request, 'profile.html', replace_dict) except Exception: # エラーページ return error_page(request)
def create(request, taxii_id): if request.method != 'POST': return error_page_free_format(request, 'invalid method') if not request.user.is_active: return error_page_inactive(request) if not request.user.is_admin: return error_page_no_view_permission(request) try: time = get_configuartion_taxii_client_detail_create_time(request) taxii_client = TaxiiClients.objects.get(id=taxii_id) times = time.split(':') schedule_job = taxii_client.add_job(type_=ScheduleJobs.JOB_CRON, hour=times[0], minute=times[1], second=times[2]) client = Client(taxii_client=taxii_client) client.add_job(schedule_job) replace_dict = get_common_replace_dict(request) replace_dict['client'] = taxii_client return render(request, 'configuration_taxii_client_detail.html', replace_dict) except Exception: return error_page(request)
def start(request, id_): # activeユーザー以外はエラー if not request.user.is_active: return error_page_inactive(request) start = get_datetime_from_string(get_start_start(request)) end = get_datetime_from_string(get_start_end(request)) try: cl = Client(taxii_id=id_) cl.set_start_time(start) cl.set_end_time(end) count = cl.poll() replace_dict = get_common_replace_dict(request) replace_dict['taxii'] = TaxiiClients.objects.get(id=id_) replace_dict[ 'info_msg'] = 'Poll end successfully!! (Get %d stix files.)' % ( count) # レンダリング return render(request, 'poll_detail.html', replace_dict) except Exception: # エラーページ return error_page(request)