Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d02be623
authored
Mar 04, 2013
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: Blacklist.host, ban notification added
parent
54cd2c2f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
8 deletions
+37
-8
firewall/migrations/0032_auto__add_field_blacklist_host.py
+0
-0
firewall/models.py
+2
-1
firewall/views.py
+22
-4
one/templates/mails/base.txt
+1
-1
one/templates/mails/notification-ban-now.txt
+10
-0
one/templates/mails/notification-delete-now.txt
+2
-2
No files found.
firewall/migrations/0032_auto__add_field_blacklist_host.py
0 → 100644
View file @
d02be623
This diff is collapsed.
Click to expand it.
firewall/models.py
View file @
d02be623
...
@@ -336,8 +336,9 @@ class Record(models.Model):
...
@@ -336,8 +336,9 @@ class Record(models.Model):
'address'
:
address
}
'address'
:
address
}
class
Blacklist
(
models
.
Model
):
class
Blacklist
(
models
.
Model
):
CHOICES_type
=
((
'permban'
,
'permanent ban'
),
(
'tempban'
,
'temporary ban'
),
(
'whitelist'
,
'whitelist'
))
CHOICES_type
=
((
'permban'
,
'permanent ban'
),
(
'tempban'
,
'temporary ban'
),
(
'whitelist'
,
'whitelist'
)
,
(
'tempwhite'
,
'tempwhite'
)
)
ipv4
=
models
.
GenericIPAddressField
(
protocol
=
'ipv4'
,
unique
=
True
)
ipv4
=
models
.
GenericIPAddressField
(
protocol
=
'ipv4'
,
unique
=
True
)
host
=
models
.
ForeignKey
(
'Host'
,
blank
=
True
,
null
=
True
)
reason
=
models
.
TextField
(
blank
=
True
)
reason
=
models
.
TextField
(
blank
=
True
)
snort_message
=
models
.
TextField
(
blank
=
True
)
snort_message
=
models
.
TextField
(
blank
=
True
)
type
=
models
.
CharField
(
max_length
=
10
,
choices
=
CHOICES_type
,
default
=
'tempban'
)
type
=
models
.
CharField
(
max_length
=
10
,
choices
=
CHOICES_type
,
default
=
'tempban'
)
...
...
firewall/views.py
View file @
d02be623
from
django.shortcuts
import
render_to_response
from
django.shortcuts
import
render_to_response
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.shortcuts
import
render_to_response
from
firewall.models
import
*
from
firewall.models
import
*
from
firewall.fw
import
*
from
firewall.fw
import
*
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
...
@@ -9,12 +8,15 @@ from django.db import IntegrityError
...
@@ -9,12 +8,15 @@ from django.db import IntegrityError
from
tasks
import
*
from
tasks
import
*
from
celery.task.control
import
inspect
from
celery.task.control
import
inspect
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.template.loader
import
render_to_string
import
re
import
re
import
base64
import
base64
import
json
import
json
import
sys
import
sys
import
datetime
from
django.utils.timezone
import
utc
def
reload_firewall
(
request
):
def
reload_firewall
(
request
):
if
request
.
user
.
is_authenticated
():
if
request
.
user
.
is_authenticated
():
...
@@ -41,11 +43,27 @@ def firewall_api(request):
...
@@ -41,11 +43,27 @@ def firewall_api(request):
if
command
==
"blacklist"
:
if
command
==
"blacklist"
:
obj
,
created
=
Blacklist
.
objects
.
get_or_create
(
ipv4
=
data
[
"ip"
])
obj
,
created
=
Blacklist
.
objects
.
get_or_create
(
ipv4
=
data
[
"ip"
])
obj
.
reason
=
data
[
"reason"
]
obj
.
snort_message
=
data
[
"snort_message"
]
if
created
:
if
created
:
obj
.
reason
=
data
[
"reason"
]
try
:
obj
.
snort_message
=
data
[
"snort_message"
]
obj
.
host
=
models
.
Host
.
objects
.
get
(
ipv4
=
data
[
"ip"
])
user
=
obj
.
host
.
owner
lang
=
user
.
person_set
.
all
()[
0
]
.
language
s
=
render_to_string
(
'mails/notification-ban-now.txt'
,
{
'user'
:
user
,
'bl'
:
obj
}
)
print
s
# send_mail(settings.EMAIL_SUBJECT_PREFIX + (_('New project: %s') % p.identifier), s, settings.SERVER_EMAIL, [])
except
Host
.
DoesNotExist
,
ValidationError
,
IntegrityError
,
AttributeError
as
e
:
pass
except
:
raise
print
"ok"
print
obj
.
modified_at
+
datetime
.
timedelta
(
minutes
=
5
)
print
datetime
.
datetime
.
utcnow
()
.
replace
(
tzinfo
=
utc
)
if
obj
.
type
==
'tempwhite'
and
obj
.
modified_at
+
datetime
.
timedelta
(
minutes
=
1
)
<
datetime
.
datetime
.
utcnow
()
.
replace
(
tzinfo
=
utc
):
obj
.
type
=
'tempban'
obj
.
save
()
obj
.
save
()
return
HttpResponse
(
unicode
(
_
(
"OK"
)))
;
return
HttpResponse
(
unicode
(
_
(
"OK"
)))
if
not
(
data
[
"vlan"
]
==
"vm-net"
or
data
[
"vlan"
]
==
"war"
):
if
not
(
data
[
"vlan"
]
==
"vm-net"
or
data
[
"vlan"
]
==
"war"
):
raise
Exception
(
_
(
"Only vm-net and war can be used."
))
raise
Exception
(
_
(
"Only vm-net and war can be used."
))
...
...
one/templates/mails/base.txt
View file @
d02be623
{% load i18n %}
{% load i18n %}
{% blocktrans with name=user.name %}
{% blocktrans with name=user.
get_full_
name %}
Dear {{name}},
Dear {{name}},
{% endblocktrans %}
{% endblocktrans %}
...
...
one/templates/mails/notification-ban-now.txt
0 → 100644
View file @
d02be623
{% extends "mails/base.txt" %}
{% load i18n %}
{% block body %}
{% blocktrans with reason=bl.reason snort_message=bl.snort_message %}
{{reason}} {{snort_message}}
{% endblocktrans %}
{% endblock %}
one/templates/mails/notification-delete-now.txt
View file @
d02be623
{%
base base.txt
%}
{%
extends "mails/base.txt"
%}
{% load i18n %}
{% load i18n %}
{% block body %}
{% block body %}
{% blocktrans with vm=instance.name state=instance.state date=
exp
%}
{% blocktrans with vm=instance.name state=instance.state date=
instance.time_of_delete
%}
Your {{state}} virtual machine "{{vm}}" has been DELETED
Your {{state}} virtual machine "{{vm}}" has been DELETED
at {{date}}.
at {{date}}.
{% endblocktrans %}
{% endblocktrans %}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment