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
0beb4a7d
Commit
0beb4a7d
authored
Mar 26, 2022
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ban.py: drop config creating
parent
d7af677b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
27 deletions
+8
-27
ban.py
prod-server/usr/share/eterban/ban.py
+8
-27
No files found.
prod-server/usr/share/eterban/ban.py
View file @
0beb4a7d
#!/usr/bin/python3
#!/usr/bin/python3
import
redis
import
redis
import
sys
import
sys
import
configparser
import
configparser
import
os
import
os
import
socket
import
socket
def
createConfig
(
path_to_config
):
def
get_settings
(
path_to_config
):
"""
Create a config file
"""
config
=
configparser
.
ConfigParser
()
config
.
add_section
(
"Settings"
)
config
.
set
(
"Settings"
,
"redis_server"
,
"10.20.30.101"
)
config
.
set
(
"Settings"
,
"hostname"
,
socket
.
gethostname
())
with
open
(
path_to_config
,
"w"
)
as
config_file
:
config
.
write
(
config_file
)
sys
.
exit
()
def
get_ip_redis_server
(
path_to_config
):
if
not
os
.
path
.
exists
(
path_to_config
):
if
not
os
.
path
.
exists
(
path_to_config
):
createConfig
(
path_to_config
)
print
(
"Missed config file"
)
sys
.
exit
()
config
=
configparser
.
ConfigParser
()
config
=
configparser
.
ConfigParser
()
config
.
read
(
path_to_config
)
config
.
read
(
path_to_config
)
# Читаем некоторые значения из конфиг. файла.
# Читаем некоторые значения из конфиг. файла.
redis_server
=
config
.
get
(
"Settings"
,
"redis_server"
,
fallback
=
"localhost"
)
redis_server
=
config
.
get
(
"Settings"
,
"redis_server"
,
fallback
=
"No such things as redis_server"
)
hostname
=
config
.
get
(
"Settings"
,
"hostname"
,
fallback
=
socket
.
gethostname
())
hostname
=
config
.
get
(
"Settings"
,
"hostname"
,
fallback
=
socket
.
gethostname
())
if
redis_server
==
"No such things as redis_server"
:
return
(
redis_server
,
hostname
)
config
.
set
(
"Settings"
,
"redis_server"
,
"10.20.30.101"
)
with
open
(
path_to_config
,
"a"
)
as
config_file
:
config_file
.
write
(
config
)
sys
.
exit
()
else
:
return
(
redis_server
,
hostname
)
path_to_config
=
'/etc/eterban/settings.ini'
path_to_config
=
'/etc/eterban/settings.ini'
redis_server
,
hostname
=
get_
ip_redis_server
(
path_to_config
)
redis_server
,
hostname
=
get_
settings
(
path_to_config
)
r
=
redis
.
Redis
(
host
=
redis_server
)
r
=
redis
.
Redis
(
host
=
redis_server
)
r
.
publish
(
'ban'
,
sys
.
argv
[
1
])
r
.
publish
(
'ban'
,
sys
.
argv
[
1
])
...
@@ -47,4 +29,4 @@ try:
...
@@ -47,4 +29,4 @@ try:
except
:
except
:
message
=
sys
.
argv
[
1
]
+
" was blocked by "
+
hostname
+
" (set block: [name=NAME_OF_RULE] on "
+
hostname
+
":/etc/fail2ban/jail.conf)"
message
=
sys
.
argv
[
1
]
+
" was blocked by "
+
hostname
+
" (set block: [name=NAME_OF_RULE] on "
+
hostname
+
":/etc/fail2ban/jail.conf)"
r
.
publish
(
'by'
,
message
)
r
.
publish
(
'by'
,
message
)
\ No newline at end of file
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