Skip to content

Commit

Permalink
Integrate Celery in fir
Browse files Browse the repository at this point in the history
 Dockerfile for redis
 Create Celery app
  • Loading branch information
y9mo committed Nov 23, 2016
1 parent 861cf60 commit c001923
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Dockerfile for FIR development instance
#
# build command:
#
# docker build -t redis [path_to_Dockerfile]
# docker run -it -p 6379:6379 --name fir_broker redis

FROM redis:3.2.5

CMD ["redis-server"]
14 changes: 14 additions & 0 deletions fir/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fir.settings')

app = Celery('celery',
broker='redis://localhost:6379/0',
backend='',
include=[])

if __name__ == '__main__':
app.start()
2 changes: 2 additions & 0 deletions fir/config/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import, unicode_literals

import os
from pkgutil import find_loader
from importlib import import_module
Expand Down
1 change: 1 addition & 0 deletions fir_abuse/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from fir_abuse import views

urlpatterns = [
#url(r'^(?P<incident_id>\d+)/get_template/$', views.get_template, name='get_template'),
url(r'^emailform/$', views.emailform, name='emailform'),
url(r'^send_email/$', views.send_email, name='send_email'),
]
68 changes: 68 additions & 0 deletions fir_abuse/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,71 @@ def send_email(request):

return HttpResponseBadRequest(dumps({'status': 'ko'}), content_type="application/json")

'''
@login_required
@user_passes_test(is_incident_handler)
def get_template(request, incident_id, template_type, bl=None):
i = get_object_or_404(Incident, pk=incident_id)
try:
cat_template = CategoryTemplate.objects.get(incident_category=i.category, type=template_type)
except Exception, e:
cat_template = None
rec_template = None
if not bl:
q_bl = Q()
bls = i.concerned_business_lines.all()
for b in bls:
q_bl |= Q(business_line=b)
bl_name = i.get_business_lines_names()
else:
bl = get_object_or_404(BusinessLine, pk=bl)
q_bl = Q(business_line=bl)
bl_name = bl.name
try:
rec_template = RecipientTemplate.objects.get((q_bl | Q(business_line=None)) & Q(type=template_type))
except Exception, e:
print "Email template ERROR: ", e
parents = list(set(i.concerned_business_lines.all()))
while not rec_template and parents != [None]:
try:
parents = list(set([b.parent for b in parents]))
q_parent = Q()
for p in parents:
q_parent |= Q(business_line=p)
template = list(RecipientTemplate.objects.filter((q_parent | Q(business_line=None)) & Q(type=template_type)))
if len(template) > 0:
rec_template = template[0]
except Exception as e:
print "Email template ERROR 2: ", e
break
artifacts = {}
for a in i.artifacts.all():
if a.type not in artifacts:
artifacts[a.type] = []
artifacts[a.type].append(a.value.replace('http://', "hxxp://").replace('https://', 'hxxps://'))
c = Context({
'subject': i.subject.replace('http://', "hxxp://").replace('https://', 'hxxps://'),
'bl': bl_name,
'phishing_url': i.subject.replace('http://', "hxxp://").replace('https://', 'hxxps://'),
'artifacts': artifacts,
})
response = {
'behalf': rec_template.behalf if rec_template else "",
'to': rec_template.recipient_to if rec_template else "",
'cc': rec_template.recipient_cc if rec_template else "",
'bcc': rec_template.recipient_bcc if rec_template else "",
'subject': Template(cat_template.subject).render(c) if cat_template else "",
'body': Template(cat_template.body).render(c) if cat_template else "",
'bl': bl_name,
}
return HttpResponse(dumps(response), content_type="application/json")
'''

7 changes: 7 additions & 0 deletions fir_artifacts/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, unicode_literals
from . import app


@app.task
def add(x, y):
return x + y

0 comments on commit c001923

Please sign in to comment.