Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ban
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NoCloud
docker
Ban
Commits
8c8acf6d
Commit
8c8acf6d
authored
4 months ago
by
Elian Loraux
Browse files
Options
Downloads
Patches
Plain Diff
remove first comma
parent
5dffd4d5
Branches
2404-disable-move-to-buttom-button
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ban.sh
+19
-6
19 additions, 6 deletions
ban.sh
with
19 additions
and
6 deletions
ban.sh
+
19
−
6
View file @
8c8acf6d
#!/bin/bash
#
Fonction pour valider une adresse
IP
v4
#
Check valid
IP
validate_ipv4
()
{
local
ip
=
"
$1
"
local
regex
=
'^([0-9]{1,3}\.){3}[0-9]{1,3}$'
#
Vérifier le format général avec une regex
#
Check Format
if
[[
!
$ip
=
~
$regex
]]
;
then
echo
"Invalid IPv4 address: inccorect format"
return
1
fi
#
Vérifier que chaque octet est entre 0 et
255
#
Chack bit between 0 and
255
IFS
=
'.'
read
-r
-a
octets
<<<
"
$ip
"
for
octet
in
"
${
octets
[@]
}
"
;
do
if
((
octet < 0
||
octet
>
255
))
;
then
...
...
@@ -23,18 +23,31 @@ validate_ipv4() {
return
0
}
#
Vérifier si un paramètre est fourni
#
Check if parms
if
[[
$#
-ne
1
]]
;
then
echo
"Usage:
$0
<ipv4 address>"
exit
1
fi
#
Vérifier l'adresse IPv4 fournie
#
Chack if is IP
validate_ipv4
"
$1
"
if
[[
$?
-eq
0
]]
;
then
domain
=
$(
docker ps
-qa
| xargs docker inspect |
awk
'/traefik.http.routers.*.rule/{print $2}'
|
sed
-e
's/^"Host(`//'
-e
's/`)",*//'
-e
's/`,`/\n/g'
|
grep
-v
'ClientIP'
|
sort
-u
|
sed
"s/^/
\`
/"
|
sed
"s/
$/
\`
/"
|
paste
-sd
","
)
sed
-i
"s/HOSTS=.*/HOSTS=
$domain
/"
.env
sed
-i
"s/^BAN_IPS=
\(
.*
\)
/BAN_IPS=
\1
,
\`
$1
\`
/"
.env
IP
=
"
$1
"
# if BAN_IPS is empt or note
if
grep
-q
"^BAN_IPS="
.env
&&
grep
-q
"^BAN_IPS=$"
.env
;
then
# if BAN_IPS empty, put ip
sed
-i
"s/^BAN_IPS=
$/
BAN_IPS=
\`
$IP
\`
/"
.env
else
# else, add comma between ip
sed
-i
-E
"/^BAN_IPS=/ s/
$/
,
\`
$IP
\`
/"
.env
fi
# sed -i "s/^BAN_IPS=\(.*\)/BAN_IPS=\1,\`$1\`/" .env
# sed "s/^BAN_IPS=\(.*\)/BAN_IPS=\1,\`79.85.55.114\`/" .env
docker-compose up
-d
else
exit
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment