This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/scripts/blocklist-skylink.sh

52 lines
1.8 KiB
Bash
Raw Normal View History

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.
# The automatic script that is used to continuously sync an Airtable sheet
# list with the blocklist on the web portals is /setup-scripts/blocklist-airtable.py
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
#########################################################
# read either a file containing skylinks separated by new
# lines or a single skylink and put them in an array
#########################################################
skylinks=()
if test -f "$1"; then
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" ];
do
2021-10-25 14:51:27 +00:00
if [[ $line =~ (^[a-zA-Z0-9_-]{46}$) ]]; then
skylinks+=("$line")
else
echo "Incorrect skylink at line ${line_number}: $line" && exit 1
fi
let line_number+=1
done < $1;
else
skylinks=("$1") # just single skylink passed as input argument
fi
2022-01-10 21:35:04 +00:00
# get local nginx ip adress
nginx_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx)
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
printf "Blocking ${skylink} ... "
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null --data "{\"add\":[\"$skylink\"]}" "http://${nginx_ip}:8000/skynet/blocklist")
2021-12-13 16:35:00 +00:00
2022-01-10 21:35:04 +00:00
# print blocklist response status code
if [ $status_code = "204" ]; then
echo "done"
else
echo "error $status_code"
2021-12-13 16:35:00 +00:00
fi
2020-06-01 09:17:44 +00:00
done