Last active
June 19, 2024 09:30
-
-
Save NP-compete/002e0053a7fb6937b636b0145de3086b to your computer and use it in GitHub Desktop.
Testing Turn servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function install_prerequisites() { | |
if ! command -v turnutils_uclient > /dev/null || ! command -v curl > /dev/null || ! command -v certbot > /dev/null; then | |
echo "Installing necessary dependencies..." | |
sudo apt-get remove --purge -y needrestart | |
sudo apt-get install -y gcc coturn openssl libcurl4-openssl-dev | |
sudo snap install core | |
sudo snap refresh core | |
sudo snap install --classic certbot | |
sudo ln -s /snap/bin/certbot /usr/bin/certbot | |
fi | |
} | |
function generate_certificate() { | |
REGISTRATION_EMAIL=$1 | |
DOMAIN=$2 | |
certbot_response=$(sudo certbot certonly -v --nginx --non-interactive --agree-tos -m $REGISTRATION_EMAIL -d $DOMAIN) | |
echo "certbot response - $certbot_response" | |
} | |
function start_turn_server() { | |
TURN_REALM=$1 | |
DOMAIN=$2 | |
STATIC_AUTH_SECRET=$3 | |
CLI_PASSWORD=$4 | |
LISTENING_PORT=$5 | |
TLS_LISTENING_PORT=$6 | |
PUBLIC_IP=$(curl -s ifconfig.me) | |
# https://manpages.debian.org/testing/coturn/turnserver.1.en.html | |
sudo turnserver -n -v -o -a -p $LISTENING_PORT --no-cli --tls-listening-port $TLS_LISTENING_PORT -r $TURN_REALM -X $PUBLIC_IP --cert /etc/letsencrypt/live/$DOMAIN/fullchain.pem --pkey /etc/letsencrypt/live/$DOMAIN/privkey.pem --use-auth-secret --static-auth-secret $STATIC_AUTH_SECRET --cli-password=$CLI_PASSWORD | |
} | |
function validate_turn_server() { | |
TURN_SERVER=$1 | |
TURN_PORT=$2 | |
TURN_USERNAME=$3 | |
TURN_PASSWORD=$4 | |
TURN_REALM=$5 | |
echo "Testing connection to TURN server..." | |
echo "QUIT" | telnet "$TURN_SERVER" "$TURN_PORT" 2>/dev/null | grep "Connected to" > /dev/null | |
if [[ $? -eq 0 ]]; then | |
echo "Connection to TURN server successful." | |
else | |
echo "Failed to connect to TURN server. Please check the server address and port." | |
exit 1 | |
fi | |
echo "Testing authentication with TURN server..." | |
echo "AUTH \"$TURN_USERNAME:$TURN_PASSWORD\"" | turnutils_uclient -t "$TURN_SERVER" -p "$TURN_PORT" -u "$TURN_USERNAME" -w "$TURN_PASSWORD" -r "$TURN_REALM" > /dev/null | |
if [[ $? -eq 0 ]]; then | |
echo "Authentication with TURN server successful." | |
else | |
echo "Failed to authenticate with TURN server. Please check the username, password, and realm." | |
exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment