Il est possible d'héberger son propre serveur.
Ci-desous, le script pour installer un serveur : Docker obligatoire, Ubuntu 18.04 est recommandé.
Par défaut, c'est le port 80 qui est utilisé, mais il est possible de le modifier, toutefois dans de nombreuses entreprisen seuls deux ports sont ouverts : 80 et 443.
Je vais voir si il est pertinent que je propose un ou des serveurs de test de débit.
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"></head><body>#!/usr/bin/env bash
set -o nounset
set -o errexit
DEFAULT_SERVER_PORT="80"
SERVER_PORT=""
DEFAULT_SERVER_HOSTNAME="${HOSTNAME}"
SERVER_HOSTNAME=""
INSTALLATION_TOKEN=""
API_SERVER_URL="https://sp-dir.uwn.com"
DIRECTORY_SERVER_URL="wss://sp-dir.uwn.com/connect"
SPEEDTEST_IMAGE=${SPEEDTEST_IMAGE:-"ubnt/speedtest"}
SPEEDTEST_CONTAINER="ubnt-speedtest"
WATCHTOWER_CONTAINER="ubnt-speedtest-watchtower"
AUTH_HEADER="x-auth-token: ${INSTALLATION_TOKEN}"
ENDPOINT_IP="${API_SERVER_URL}/api/v1/ip"
ENDPOINT_INSTALL="${API_SERVER_URL}/api/v1/install"
if [ "x$@" != "x" ]; then
API_KEY="$@"
fi
fail() {
echo -e "ERROR: $1" >&2
exit 1
}
# usage: confirm <question>
# Prints given question and asks user to type Y or N.
# Returns 0 if user typed Y, 1 if user typed N.
# Exits if user failed to type Y or N too many times.
# examples:
# confirm "Do you want to continue?" || exit 1
confirm() {
local question="$1"
for i in 0 1 2 3 4 5 6 7 8 9 10; do
read -p "${question} [Y/N]" -n 1 -r
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
echo "Yes"
return 0
fi
if [[ ${REPLY} =~ ^[Nn]$ ]]; then
echo "No"
return 1
fi
echo "Please type Y or N."
done
fail "Too many failed attempts."
}
fetch_api_key() {
# maybe no need to fetch api key
if [ -n "${API_KEY:-}" ]; then
echo "Using provided API Key: ${API_KEY}"
return
fi
echo "Registering server..."
API_KEY=$(
curl -s -X POST \
-H "${AUTH_HEADER}" \
-H "Accept: text/plain" \
-F url="http://${SERVER_HOSTNAME}:${SERVER_PORT}" \
"${ENDPOINT_INSTALL}"
)
if [ -z "${API_KEY:-}" ]; then
fail "Cannot authorize new server (API_KEY invalid)"
fi
if ! echo "${API_KEY}" | grep -E -q
'^[0123456789ABCDFHKLMNPQRSTUVWXYZ]+$'; then
fail "Server generated invalid authentication key (API_KEY
${API_KEY})" >&2
fi
}
pull_docker_images() {
echo "Pulling docker images."
docker pull "$SPEEDTEST_IMAGE"
docker pull v2tec/watchtower
}
install_docker() {
if ! which docker > /dev/null 2>&1; then
echo "Download and install Docker"
export CHANNEL="stable"
curl -fsSL https://get.docker.com/ | sh
fi
DOCKER_VERSION=$(docker -v | sed 's/.*version \([0-9.]*\).*/\1/');
echo "Docker version: ${DOCKER_VERSION}"
if ! which docker > /dev/null 2>&1; then
fail "Docker not installed. Please check previous logs. Aborting."
fi
}
stop_docker_containers() {
echo "Stopping docker containers."
docker stop "${WATCHTOWER_CONTAINER}" 2>/dev/null || true
docker stop "${SPEEDTEST_CONTAINER}" 2>/dev/null || true
}
remove_old_docker_containers() {
echo "Removing docker containers."
docker rm "${WATCHTOWER_CONTAINER}" 2>/dev/null || true
docker rm "${SPEEDTEST_CONTAINER}" 2>/dev/null || true
}
ask_server_hostname() {
PUBLIC_IP=`curl -fs -H "Accept: text/plain" "${ENDPOINT_IP}" | cut -f1
|| echo -n ""`
if [ -n "${PUBLIC_IP:-}" ]; then
DEFAULT_SERVER_HOSTNAME=${PUBLIC_IP}
fi
read -r -p "Please enter hostname or public IP.
[${DEFAULT_SERVER_HOSTNAME}]: " SERVER_HOSTNAME
SERVER_HOSTNAME=${SERVER_HOSTNAME:-${DEFAULT_SERVER_HOSTNAME}}
echo "Using hostname ${SERVER_HOSTNAME}"
}
ask_server_port() {
read -r -p "Please enter HTTP port. [${DEFAULT_SERVER_PORT}]: "
SERVER_PORT
SERVER_PORT=${SERVER_PORT:-${DEFAULT_SERVER_PORT}}
if ! echo "${SERVER_PORT}" | grep -E -q '^[0-9]+$'; then
echo -e "${SERVER_PORT} is not a valid port number." >&2
ask_server_port
return
fi
echo "Checking available HTTP port"
if nc -z 127.0.0.1 "${SERVER_PORT}" >/dev/null 2>&1; then
echo -e "Port ${SERVER_PORT} is in use." >&2
ask_server_port
return
fi
echo "Using port ${SERVER_PORT}"
}
validate_server_info() {
local result=$(
curl -fs -X POST \
-w "%{http_code}" \
-o /dev/null \
-H "${AUTH_HEADER}" \
-F hostname="$SERVER_HOSTNAME" \
-F port="$SERVER_PORT" \
"${ENDPOINT_INSTALL}/validate"
)
case ${result} in
200)
return 0
;;
400)
echo "Please enter valid hostname and port"
;;
401)
fail "Authentication failed. Please make sure you have downloaded
the latest version of this installation script and try again"
;;
403)
echo "Server ${SERVER_HOSTNAME}:${SERVER_PORT} is already
registered. Please choose a different hostname and/or port"
;;
409)
echo "Server ${SERVER_HOSTNAME}:${SERVER_PORT} already exists."
if confirm "Do you want to replace it with current installation?";
then
return 0
fi
;;
429)
fail "Server limit reached. You can't have any more servers,
retire some and try again."
;;
*)
fail "Failed to connect to Speed Test API with an error code
${result:-"unknown"}"
esac
return 1
}
gather_server_info() {
ask_server_hostname
ask_server_port
if ! validate_server_info; then
gather_server_info;
fi
}
start_docker_containers() {
echo "Starting docker containers."
docker run -d \
--name "${WATCHTOWER_CONTAINER}" \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
v2tec/watchtower --label-enable --cleanup
docker run -d \
--name "${SPEEDTEST_CONTAINER}" \
--publish "${SERVER_PORT}:8050" \
-e API_KEY="${API_KEY}" \
-e DIRECTORY_SERVER_URL="${DIRECTORY_SERVER_URL}" \
-l "com.centurylinklabs.watchtower.enable=true" \
--restart unless-stopped \
"${SPEEDTEST_IMAGE}"
}
confirm_success() {
echo "Waiting for Speed Test Server to start"
local n=0
local running=false
until [ ${n} -ge 10 ]
do
sleep 3s
running=true
# env -i is to ensure that http[s]_proxy variables are not set
# Otherwise the check would go through proxy.
local status=`env -i curl -skL -H 'Accept: text/plain'
"http://${SERVER_HOSTNAME}:${SERVER_PORT}/diagnostics" | cut -f1`
if [ "${status}" = "1" ]; then
break
fi
echo "."
running=false
n=$((n+1))
done
docker ps
if [ "${running}" = true ]; then
echo "Speed Test Server is running"
else
echo ""
echo "Server failed to start or it can't connect to the Speed Test
Network."
echo " - Make sure your installation script is up to date. You can
always download the latest version from https://speed-admin.ui.com"
echo " - Make sure URL http://${SERVER_HOSTNAME}:${SERVER_PORT} is
publicly accessible"
echo " - Contact our support with output of
http://localhost:${SERVER_PORT}/diagnostics and 'docker logs
${SPEEDTEST_CONTAINER}'"
echo ""
fail "Speed Test Server installation failed"
fi
}
do_install() {
install_docker
pull_docker_images
stop_docker_containers
remove_old_docker_containers
gather_server_info
fetch_api_key
start_docker_containers
confirm_success
}
# wrapped up in a function so that we have some protection against only
getting
# half the file during "curl | sh"
do_install
</question></body></html>