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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
cfd5ca86
authored
Feb 19, 2013
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall/celery: added fw.py
parent
5d110470
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletions
+54
-1
firewall/tasks.py
+1
-1
miscellaneous/celery/fw.py
+53
-0
No files found.
firewall/tasks.py
View file @
cfd5ca86
...
@@ -56,7 +56,7 @@ class ReloadTask(Task):
...
@@ -56,7 +56,7 @@ class ReloadTask(Task):
if
not
sleep
:
if
not
sleep
:
sleep
=
True
sleep
=
True
time
.
sleep
(
10
)
time
.
sleep
(
10
)
reload_blacklist_task
(
ipset
(
))
reload_blacklist_task
.
delay
(
list
(
ipset
()
))
print
type
print
type
miscellaneous/celery/fw.py
0 → 100644
View file @
cfd5ca86
from
celery
import
Celery
,
task
import
subprocess
import
time
,
re
CELERY_CREATE_MISSING_QUEUES
=
True
celery
=
Celery
(
'tasks'
,
broker
=
'amqp://nyuszi:teszt@localhost:5672/django'
)
@task
(
name
=
"firewall.tasks.reload_firewall_task"
)
def
t
(
data4
,
data6
):
print
"fw"
# return
# print "\n".join(data6['filter']) + "\n"
process
=
subprocess
.
Popen
([
'/usr/bin/sudo'
,
'/sbin/ip6tables-restore'
,
'-c'
],
shell
=
False
,
stdin
=
subprocess
.
PIPE
)
process
.
communicate
(
"
\n
"
.
join
(
data6
[
'filter'
])
+
"
\n
"
)
process
=
subprocess
.
Popen
([
'/usr/bin/sudo'
,
'/sbin/iptables-restore'
,
'-c'
],
shell
=
False
,
stdin
=
subprocess
.
PIPE
)
process
.
communicate
(
"
\n
"
.
join
(
data4
[
'filter'
])
+
"
\n
"
+
"
\n
"
.
join
(
data4
[
'nat'
])
+
"
\n
"
)
@task
(
name
=
"firewall.tasks.reload_dhcp_task"
)
def
t
(
data
):
print
"dhcp"
# return
with
open
(
'/tools/dhcp3/dhcpd.conf.generated'
,
'w'
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
data
)
+
"
\n
"
)
subprocess
.
call
([
'sudo'
,
'/etc/init.d/isc-dhcp-server'
,
'restart'
],
shell
=
False
)
@task
(
name
=
"firewall.tasks.reload_blacklist_task"
)
def
t
(
data
):
print
"blacklist"
r
=
re
.
compile
(
r'^add blacklist ([0-9.]+)$'
)
data_new
=
data
data_old
=
[]
p
=
subprocess
.
Popen
([
'/usr/bin/sudo'
,
'/usr/sbin/ipset'
,
'save'
,
'blacklist'
],
shell
=
False
,
stdout
=
subprocess
.
PIPE
)
for
line
in
p
.
stdout
:
x
=
r
.
match
(
line
.
rstrip
())
if
x
:
data_old
.
append
(
x
.
group
(
1
))
l_add
=
list
(
set
(
data
)
.
difference
(
set
(
data_old
)))
l_del
=
list
(
set
(
data_old
)
.
difference
(
set
(
data
)))
ipset
=
[]
ipset
.
append
(
'create blacklist hash:ip family inet hashsize 4096 maxelem 65536'
)
ipset
=
ipset
+
[
'add blacklist
%
s'
%
x
for
x
in
l_add
]
ipset
=
ipset
+
[
'del blacklist
%
s'
%
x
for
x
in
l_del
]
print
"
\n
"
.
join
(
ipset
)
+
"
\n
"
p
=
subprocess
.
Popen
([
'/usr/bin/sudo'
,
'/usr/sbin/ipset'
,
'restore'
,
'-exist'
],
shell
=
False
,
stdin
=
subprocess
.
PIPE
)
p
.
communicate
(
"
\n
"
.
join
(
ipset
)
+
"
\n
"
)
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