Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eterban
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
eterban
Commits
f321c3cb
Commit
f321c3cb
authored
Nov 10, 2019
by
Ruzal Gimazov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add configparser, 2 functions with it, changed config name to settings.ini, created logfile
parent
b468c17a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
19 deletions
+77
-19
unban.php
ban-server/data/www/unban.php
+1
-1
eterban_switcher.py
gateway/usr/share/eterban/eterban_switcher.py
+76
-18
No files found.
ban-server/data/www/unban.php
View file @
f321c3cb
<?php
$ip
=
$_SERVER
[
'REMOTE_ADDR'
];
$old_addr
=
$_SERVER
[
'HTTP_REFERER'
];
$host_redis
=
'1
92.168.101
.101'
;
$host_redis
=
'1
0.20.30
.101'
;
$redis
=
new
Redis
();
$redis
->
pconnect
(
$host_redis
,
6379
);
$redis
->
publish
(
'unban'
,
$ip
);
...
...
gateway/usr/share/eterban/eterban_switcher.py
View file @
f321c3cb
#!/usr/bin/python3
import
redis
import
subprocess
import
time
import
sys
import
configparser
import
os
f
=
open
(
'/etc/eterban/eterban.conf'
,
'r'
)
line
=
f
.
readline
()
f
.
close
()
if
line
[:
10
]
==
"host_redis"
:
i
=
10
while
(
line
[
i
]
==
" "
):
i
+=
1
i
+=
1
while
(
line
[
i
]
==
" "
):
i
+=
1
if
line
[
-
1
]
==
'
\n
'
:
host_redis
=
line
[
i
:
-
1
]
def
createConfig
(
path_to_config
,
path_to_log
):
"""
Create a config file
"""
config
=
configparser
.
ConfigParser
()
config
.
add_section
(
"Settings"
)
config
.
set
(
"Settings"
,
"redis_server"
,
"10.20.30.101"
)
config
.
set
(
"Settings"
,
"hostname"
,
""
)
with
open
(
path_to_config
,
"w"
)
as
config_file
:
config
.
write
(
config_file
)
info
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
info
+=
" Created a config file ("
+
path_to_config
+
"). Update him!"
with
open
(
path_to_log
,
"a"
)
as
log_file
:
log_file
.
write
(
info
)
sys
.
exit
()
def
get_ip_redis_server
(
path_to_config
,
path_to_log
):
if
not
os
.
path
.
exists
(
path_to_config
):
createConfig
(
path_to_config
,
path_to_log
)
config
=
configparser
.
ConfigParser
()
config
.
read
(
path_to_config
)
# Читаем некоторые значения из конфиг. файла.
redis_server
=
config
.
get
(
"Settings"
,
"redis_server"
,
fallback
=
"No such things as redis_server"
)
if
redis_server
==
"No such things as monsters"
:
config
.
set
(
"Settings"
,
"redis_server"
,
"10.20.30.101"
)
with
open
(
path_to_config
,
"w"
)
as
config_file
:
config_file
.
write
(
config
)
info
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
info
+=
" "
+
redis_server
+
". Added to config file ("
+
path_to_config
+
") redis_server. Update him!"
with
open
(
path_to_log
,
"a"
)
as
log_file
:
log_file
.
write
(
info
)
sys
.
exit
()
else
:
host_redis
=
line
[
i
:]
del
(
line
)
del
(
f
)
return
(
redis_server
)
try
:
path_to_log
=
'/var/log/eterban/eterban.log'
log
=
open
(
path_to_log
,
'a'
)
log
.
close
()
except
:
try
:
path_to_log
=
'/var/log/eterban.log'
log
=
open
(
path_to_log
,
'a'
)
log
.
close
()
except
:
print
(
"Unknown error with logfile"
)
sys
.
exit
()
path_to_config
=
'/etc/eterban/settings.ini'
redis_server
=
get_ip_redis_server
(
path_to_config
,
path_to_log
)
print
(
"done!"
)
#print (time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()))
#subprocess.call ('ipset create blacklist hash:ip', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True)
r
=
redis
.
Redis
(
host
=
host_redis
)
r
=
redis
.
Redis
(
host
=
redis_server
)
p
=
r
.
pubsub
()
p
.
subscribe
(
'ban'
,
'unban'
)
p
.
subscribe
(
'ban'
,
'unban'
,
'by'
)
for
message
in
p
.
listen
():
if
message
is
not
None
and
message
[
'type'
]
==
'message'
and
message
[
'channel'
]
==
b
'ban'
:
...
...
@@ -47,8 +94,19 @@ for message in p.listen():
tcp_drop
=
'conntrack -D -s '
+
ip
subprocess
.
Popen
(
tcp_drop
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
#subprocess.Popen(tcp_drop, shell = True)
elif
message
is
not
None
and
message
[
'type'
]
==
'message'
and
message
[
'channel'
]
==
b
'by'
:
info
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
info
+=
" "
+
message
[
'data'
]
.
decode
(
'utf-8'
)
+
"
\n
"
#print (info)
log
.
write
(
info
)
log
.
flush
()
elif
message
is
not
None
:
#print ("AHTUNG!!1!", message)
pass
info
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
())
info
+=
" Unknown message: "
+
str
(
message
)
+
"
\n
"
#print (info)
log
.
write
(
info
)
log
.
flush
()
else
:
pass
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