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
5f095fae
Commit
5f095fae
authored
Jul 23, 2026
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal: secure Redis connection and error response
parent
187c91eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
8 deletions
+26
-8
int2.py
ban-internal-server/data/www/int2.py
+26
-8
No files found.
ban-internal-server/data/www/int2.py
View file @
5f095fae
import
socket
import
socket
import
struct
import
struct
import
logging
from
http.server
import
BaseHTTPRequestHandler
,
ThreadingHTTPServer
from
http.server
import
BaseHTTPRequestHandler
,
ThreadingHTTPServer
from
html
import
escape
from
html
import
escape
from
urllib.parse
import
quote
from
urllib.parse
import
quote
...
@@ -9,6 +10,9 @@ import configparser
...
@@ -9,6 +10,9 @@ import configparser
import
ipaddress
import
ipaddress
logger
=
logging
.
getLogger
(
__name__
)
# Чтение настроек из INI-файла
# Чтение настроек из INI-файла
def
read_settings
(
settings_file
):
def
read_settings
(
settings_file
):
config
=
configparser
.
ConfigParser
()
config
=
configparser
.
ConfigParser
()
...
@@ -16,6 +20,24 @@ def read_settings(settings_file):
...
@@ -16,6 +20,24 @@ def read_settings(settings_file):
return
config
[
'Settings'
]
return
config
[
'Settings'
]
def
redis_connection_options
(
settings
):
"""Build Redis options, including optional ACL credentials and TLS."""
options
=
{
'host'
:
settings
.
get
(
'redis_server'
,
'localhost'
),
'port'
:
settings
.
getint
(
'redis_port'
,
6379
),
'socket_timeout'
:
5
,
}
username
=
settings
.
get
(
'redis_username'
,
''
)
.
strip
()
password
=
settings
.
get
(
'redis_password'
,
''
)
.
strip
()
if
username
:
options
[
'username'
]
=
username
if
password
:
options
[
'password'
]
=
password
if
settings
.
getboolean
(
'redis_tls'
,
False
):
options
[
'ssl'
]
=
True
return
options
# Функция для получения оригинального адреса назначения
# Функция для получения оригинального адреса назначения
def
get_original_dst
(
sock
):
def
get_original_dst
(
sock
):
try
:
try
:
...
@@ -49,20 +71,16 @@ class OriginalDstHandler(BaseHTTPRequestHandler):
...
@@ -49,20 +71,16 @@ class OriginalDstHandler(BaseHTTPRequestHandler):
settings
=
read_settings
(
settings_file
)
settings
=
read_settings
(
settings_file
)
# Подключаемся к Redis
# Подключаемся к Redis
host_redis
=
settings
.
get
(
'redis_server'
,
'localhost'
)
try
:
try
:
r
=
redis
.
Redis
(
host
=
host_redis
,
port
=
6379
,
socket_timeout
=
5
)
r
=
redis
.
Redis
(
**
redis_connection_options
(
settings
)
)
r
.
xadd
(
'eterban:commands'
,
{
r
.
xadd
(
'eterban:commands'
,
{
'command'
:
'unban'
,
'ip'
:
ip
,
'command'
:
'unban'
,
'ip'
:
ip
,
'by'
:
f
"{ip} was unblocked by {client_ip}"
,
'by'
:
f
"{ip} was unblocked by {client_ip}"
,
})
})
r
.
close
()
r
.
close
()
except
Exception
as
e
:
except
(
redis
.
RedisError
,
ValueError
):
self
.
send_response
(
500
)
logger
.
exception
(
'Unable to enqueue internal unban request'
)
self
.
send_header
(
"Content-type"
,
"text/html"
)
self
.
send_error
(
503
,
'Unable to process unban request'
)
self
.
end_headers
()
self
.
wfile
.
write
(
f
"Error connecting to Redis: {e}"
.
encode
(
"utf-8"
))
return
return
# Возвращаем HTML-страницу с сообщением и JavaScript для перенаправления
# Возвращаем HTML-страницу с сообщением и JavaScript для перенаправления
...
...
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