Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
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):
'address'
:
address
}
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
)
host
=
models
.
ForeignKey
(
'Host'
,
blank
=
True
,
null
=
True
)
reason
=
models
.
TextField
(
blank
=
True
)
snort_message
=
models
.
TextField
(
blank
=
True
)
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.http
import
HttpResponse
from
django.shortcuts
import
render_to_response
from
firewall.models
import
*
from
firewall.fw
import
*
from
django.views.decorators.csrf
import
csrf_exempt
...
...
@@ -9,12 +8,15 @@ from django.db import IntegrityError
from
tasks
import
*
from
celery.task.control
import
inspect
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.template.loader
import
render_to_string
import
re
import
base64
import
json
import
sys
import
datetime
from
django.utils.timezone
import
utc
def
reload_firewall
(
request
):
if
request
.
user
.
is_authenticated
():
...
...
@@ -41,11 +43,27 @@ def firewall_api(request):
if
command
==
"blacklist"
:
obj
,
created
=
Blacklist
.
objects
.
get_or_create
(
ipv4
=
data
[
"ip"
])
obj
.
reason
=
data
[
"reason"
]
obj
.
snort_message
=
data
[
"snort_message"
]
if
created
:
obj
.
reason
=
data
[
"reason"
]
obj
.
snort_message
=
data
[
"snort_message"
]
try
:
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
()
return
HttpResponse
(
unicode
(
_
(
"OK"
)))
;
return
HttpResponse
(
unicode
(
_
(
"OK"
)))
if
not
(
data
[
"vlan"
]
==
"vm-net"
or
data
[
"vlan"
]
==
"war"
):
raise
Exception
(
_
(
"Only vm-net and war can be used."
))
...
...
one/templates/mails/base.txt
View file @
d02be623
{% load i18n %}
{% blocktrans with name=user.name %}
{% blocktrans with name=user.
get_full_
name %}
Dear {{name}},
{% 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 %}
{% 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
at {{date}}.
{% 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