2020-06-01 09:17:44 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
2022-01-10 21:35:04 +00:00
|
|
|
# This script is for manual skylink blocking. It accepts either a single
|
|
|
|
# skylink or a file containing list of skylinks. The script is intented
|
|
|
|
# for manual use and it should be run locally on each skynet webportal server.
|
2021-07-26 20:03:49 +00:00
|
|
|
|
2020-06-01 09:17:44 +00:00
|
|
|
set -e # exit on first error
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
2022-01-10 21:35:04 +00:00
|
|
|
echo "Please provide either a skylink or a file with skylinks separated by new lines" && exit 1
|
2020-06-01 09:17:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-11-24 11:39:44 +00:00
|
|
|
#########################################################
|
2021-04-27 09:13:41 +00:00
|
|
|
# read either a file containing skylinks separated by new
|
2020-11-24 11:39:44 +00:00
|
|
|
# lines or a single skylink and put them in an array
|
|
|
|
#########################################################
|
|
|
|
skylinks=()
|
|
|
|
if test -f "$1"; then
|
2020-11-24 14:14:22 +00:00
|
|
|
line_number=1
|
2021-10-25 14:51:27 +00:00
|
|
|
|
|
|
|
# Read file including the last line even when it doesn't end with newline
|
|
|
|
while IFS="" read -r line || [ -n "$line" ];
|
2020-11-24 11:39:44 +00:00
|
|
|
do
|
2021-10-25 14:51:27 +00:00
|
|
|
if [[ $line =~ (^[a-zA-Z0-9_-]{46}$) ]]; then
|
|
|
|
skylinks+=("$line")
|
2020-11-24 11:39:44 +00:00
|
|
|
else
|
2020-11-24 14:14:22 +00:00
|
|
|
echo "Incorrect skylink at line ${line_number}: $line" && exit 1
|
2020-11-24 11:39:44 +00:00
|
|
|
fi
|
2022-06-07 14:27:37 +00:00
|
|
|
(( line_number++ ))
|
|
|
|
done < "$1";
|
2020-11-24 11:39:44 +00:00
|
|
|
else
|
|
|
|
skylinks=("$1") # just single skylink passed as input argument
|
|
|
|
fi
|
|
|
|
|
2022-03-15 09:32:46 +00:00
|
|
|
# get local skyd ip adress
|
|
|
|
ipaddress=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sia)
|
|
|
|
|
|
|
|
# get sia api password either from env variable if exists or from apipassword file in sia-data directory
|
|
|
|
apipassword=$(docker exec sia sh -c '[ ! -z "${SIA_API_PASSWORD}" ] && echo ${SIA_API_PASSWORD} || $(cat /sia-data/apipassword | tr -d '\n')')
|
2021-12-13 16:35:00 +00:00
|
|
|
|
2022-01-10 21:35:04 +00:00
|
|
|
# iterate over provided skylinks and block them one by one
|
|
|
|
for skylink in "${skylinks[@]}"; do
|
2022-03-15 09:32:46 +00:00
|
|
|
echo "> Blocking ${skylink} ... "
|
|
|
|
|
|
|
|
# POST /skynet/blocklist always returns 200 and in case of failure print error message
|
|
|
|
curl -A Sia-Agent -u "":${apipassword} --data "{\"add\":[\"$skylink\"]}" "http://${ipaddress}:9980/skynet/blocklist"
|
2020-06-01 09:17:44 +00:00
|
|
|
done
|