Changed transmission to deluge. Simplify ufw rules
This commit is contained in:
83
root/etc/scripts/dnsleaktest.sh
Executable file
83
root/etc/scripts/dnsleaktest.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
api_domain='bash.ws'
|
||||
error_code=1
|
||||
|
||||
function increment_error_code {
|
||||
error_code=$((error_code + 1))
|
||||
}
|
||||
|
||||
function echo_bold {
|
||||
echo -e "${BOLD}${1}${NC}"
|
||||
}
|
||||
|
||||
function echo_error {
|
||||
(>&2 echo -e "${RED}${1}${NC}")
|
||||
}
|
||||
|
||||
function program_exit {
|
||||
command -v $1 > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo_error "Please, install \"$1\""
|
||||
exit $error_code
|
||||
fi
|
||||
increment_error_code
|
||||
}
|
||||
|
||||
function check_internet_connection {
|
||||
curl --silent --head --request GET "https://${api_domain}" | grep "200 OK" > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo_error "No internet connection."
|
||||
exit $error_code
|
||||
fi
|
||||
increment_error_code
|
||||
}
|
||||
|
||||
program_exit curl
|
||||
program_exit ping
|
||||
program_exit jq
|
||||
check_internet_connection
|
||||
|
||||
if hash shuf 2>/dev/null; then
|
||||
id=$(shuf -i 1000000-9999999 -n 1)
|
||||
else
|
||||
id=$(jot -w %i -r 1 1000000 9999999)
|
||||
fi
|
||||
|
||||
for i in {1..10};do
|
||||
ping -c 1 "${i}.${id}.${api_domain}" > /dev/null 2>&1
|
||||
done
|
||||
|
||||
result=$(curl --silent "https://${api_domain}/dnsleak/test/${id}?json")
|
||||
|
||||
function print_servers {
|
||||
jq --monochrome-output \
|
||||
--raw-output \
|
||||
".[] | select(.type == \"${1}\") | \"\(.ip)\(if .country_name != \"\" and .country_name != false then \" [\(.country_name)\(if .asn != \"\" and .asn != false then \" \(.asn)\" else \"\" end)]\" else \"\" end)\"" \
|
||||
<<< ${result}
|
||||
}
|
||||
|
||||
echo_bold "Your IP:"
|
||||
print_servers "ip"
|
||||
|
||||
echo ""
|
||||
dns_count=$(jq 'map(select(.type == "dns")) | length' <<< ${result})
|
||||
if [ ${dns_count} -eq "0" ];then
|
||||
echo_bold "No DNS servers found"
|
||||
else
|
||||
if [ ${dns_count} -eq "1" ];then
|
||||
echo_bold "You use ${dns_count} DNS server:"
|
||||
else
|
||||
echo_bold "You use ${dns_count} DNS servers:"
|
||||
fi
|
||||
print_servers "dns"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo_bold "Conclusion:"
|
||||
jq --monochrome-output --raw-output '.[] | select(.type == "conclusion") | .ip' <<< ${result}
|
||||
|
||||
exit 0
|
64
root/etc/scripts/healthcheck.sh
Executable file
64
root/etc/scripts/healthcheck.sh
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Network check
|
||||
# Ping uses both exit codes 1 and 2. Exit code 2 cannot be used for docker health checks,
|
||||
# therefore we use this script to catch error code 2
|
||||
HOST=${HEALTH_CHECK_HOST}
|
||||
|
||||
if [[ -z "$HOST" ]]
|
||||
then
|
||||
echo "Host not set! Set env 'HEALTH_CHECK_HOST'. For now, using default google.com"
|
||||
HOST="google.com"
|
||||
fi
|
||||
|
||||
ping -c 1 $HOST
|
||||
STATUS=$?
|
||||
if [[ ${STATUS} -ne 0 ]]
|
||||
then
|
||||
echo "Network is down"
|
||||
INTERFACE=$(ls /sys/class/net | grep tun)
|
||||
ISINTERFACE=$?
|
||||
|
||||
if [[ ${ISINTERFACE} -ne 0 ]]
|
||||
then
|
||||
echo "TUN Interface not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Resetting TUN"
|
||||
ip link set ${INTERFACE} down
|
||||
sleep 1
|
||||
ip link set ${INTERFACE} up
|
||||
echo "Sent kill SIGUSR1 to openvpn"
|
||||
pkill -SIGUSR1 openvpn
|
||||
sleep 20
|
||||
fi
|
||||
|
||||
ping -c 1 $HOST
|
||||
STATUS=$?
|
||||
if [[ ${STATUS} -ne 0 ]]
|
||||
then
|
||||
echo "Network is still down"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Network is up"
|
||||
|
||||
#Service check
|
||||
#Expected output is 2 for both checks, 1 for process and 1 for grep
|
||||
OPENVPN=$(pgrep openvpn | wc -l )
|
||||
DELUGE=$(pgrep deluged | wc -l)
|
||||
|
||||
if [[ ${OPENVPN} -ne 1 ]]
|
||||
then
|
||||
echo "Openvpn process not running"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ${DELUGE} -ne 1 ]]
|
||||
then
|
||||
echo "deluge-daemon process not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Openvpn and deluge-daemon processes are running"
|
||||
exit 0
|
Reference in New Issue
Block a user