Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contrib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
blockchain
contrib
Commits
6ead63b8
Commit
6ead63b8
authored
6 years ago
by
Miguel Montes
Browse files
Options
Downloads
Patches
Plain Diff
Scripts auxiliares
parent
f28c5649
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scripts/hosts2ufw.py
+47
-0
47 additions, 0 deletions
scripts/hosts2ufw.py
scripts/mkhosts.py
+41
-0
41 additions, 0 deletions
scripts/mkhosts.py
scripts/resolve.py
+53
-0
53 additions, 0 deletions
scripts/resolve.py
with
141 additions
and
0 deletions
scripts/hosts2ufw.py
0 → 100755
+
47
−
0
View file @
6ead63b8
#!/usr/bin/env python3
import
re
,
subprocess
ufw
=
"
/usr/sbin/ufw
"
ufw_command
=
[
ufw
]
ufw_delete
=
ufw_command
+
[
"
--force
"
,
"
delete
"
]
def
read_hosts
():
hosts
=
set
()
pattern
=
re
.
compile
(
r
"
([0-9.:]+)\s+\w+-(sealer|gateway)
"
)
with
open
(
"
/etc/hosts
"
)
as
file
:
for
line
in
file
:
m
=
re
.
match
(
pattern
,
line
)
if
m
:
hosts
.
add
(
m
.
group
(
1
))
return
hosts
def
read_ufw
():
pattern
=
re
.
compile
(
r
"
\[ *(\d+)\] 30303.+ALLOW IN\s+([0-9.:]+)
"
)
rules
=
{}
ufw
=
subprocess
.
run
([
"
/usr/sbin/ufw
"
,
"
status
"
,
"
numbered
"
],
check
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
lines
=
ufw
.
stdout
.
decode
(
'
utf-8
'
).
split
(
"
\n
"
)
for
line
in
lines
:
m
=
re
.
match
(
pattern
,
line
)
if
m
:
rules
[
m
.
group
(
2
)]
=
m
.
group
(
1
)
return
rules
def
remove_old
(
allowed
,
actual
):
to_remove
=
list
(
set
(
actual
.
keys
())
-
allowed
)
to_remove
.
sort
(
reverse
=
True
,
key
=
actual
.
get
)
for
rule
in
to_remove
:
subprocess
.
run
(
ufw_delete
+
[
actual
[
rule
]],
check
=
True
)
def
add_allowed
(
allowed
):
for
host
in
allowed
:
command
=
ufw_command
+
[
"
allow
"
,
"
from
"
,
host
,
"
to
"
,
"
any
"
,
"
port
"
,
"
30303
"
]
subprocess
.
run
(
command
,
check
=
True
)
allowed
=
read_hosts
()
actual
=
read_ufw
()
remove_old
(
allowed
,
actual
)
add_allowed
(
allowed
)
This diff is collapsed.
Click to expand it.
scripts/mkhosts.py
0 → 100755
+
41
−
0
View file @
6ead63b8
#!/usr/bin/env python3
import
sys
,
json
base_content
=
"""
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# BFA nodes
"""
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
>
1
:
filename
=
sys
.
argv
[
1
]
file
=
open
(
filename
)
if
not
file
:
print
(
"
No se pudo abrir el archivo
'
{}
'"
.
format
(
filename
),
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
else
:
file
=
sys
.
stdin
try
:
json_contents
=
json
.
load
(
file
)
sealers
=
json_contents
[
'
sealers
'
]
print
(
base_content
)
for
k
,
v
in
sealers
.
items
():
nodes
=
v
.
get
(
'
nodes
'
,[])
k
=
k
.
lower
()
for
node
in
nodes
:
ipv4
=
node
.
get
(
'
ipv4
'
,
None
)
if
ipv4
:
print
(
"
{:30}
\t
{}-{}
"
.
format
(
ipv4
[
0
],
k
,
node
[
'
type
'
]))
ipv6
=
node
.
get
(
'
ipv6
'
,
None
)
if
ipv6
:
print
(
"
{:30}
\t
{}-{}-ipv6
"
.
format
(
ipv6
[
0
],
k
,
node
[
'
type
'
]))
except
json
.
decoder
.
JSONDecodeError
:
print
(
"
Error al decodificar JSON
"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
This diff is collapsed.
Click to expand it.
scripts/resolve.py
0 → 100755
+
53
−
0
View file @
6ead63b8
#!/usr/bin/env python3
import
sys
,
json
,
os
.
path
,
re
db
=
{}
account_pattern
=
re
.
compile
(
r
'
(
"
?0x[0-9a-f]{40}
"
?)
'
)
def
replace
(
m
,
length
):
account
=
m
.
group
(
0
)
quoted
=
False
if
account
[
0
]
==
'"'
and
account
[
-
1
]
==
'"'
:
quoted
=
True
account
=
account
[
1
:
-
1
]
replacement
=
db
.
get
(
account
,
account
)
if
quoted
:
return
'"
{}
"'
.
format
(
replacement
)
else
:
return
"
{0:{1}}
"
.
format
(
replacement
,
max_len
)
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
>
1
:
filename
=
sys
.
argv
[
1
]
file
=
open
(
filename
)
if
not
file
:
print
(
"
No se pudo abrir el archivo
'
{}
'"
.
format
(
filename
),
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
else
:
print
(
"
Uso: {} <lista_de_selladores.json>
"
.
format
(
os
.
path
.
basename
(
sys
.
argv
[
0
])),
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
try
:
json_contents
=
json
.
load
(
file
)
sealers
=
json_contents
[
'
sealers
'
]
max_len
=
0
for
k
,
v
in
sealers
.
items
():
nodes
=
v
.
get
(
'
nodes
'
,[])
k
=
k
.
lower
()
for
node
in
nodes
:
account
=
node
.
get
(
'
account
'
,
None
)
if
account
:
value
=
"
{}-{}
"
.
format
(
k
,
node
[
'
type
'
])
max_len
=
max
(
max_len
,
len
(
value
))
db
[
account
.
lower
()]
=
value
for
line
in
sys
.
stdin
.
readlines
():
print
(
re
.
sub
(
account_pattern
,
lambda
m
:
replace
(
m
,
max_len
),
line
),
end
=
""
)
except
json
.
decoder
.
JSONDecodeError
:
print
(
"
Error al decodificar JSON
"
,
file
=
sys
.
stderr
)
sys
.
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