05-08-2024

This commit is contained in:
2024-08-05 23:24:18 +02:00
parent e85e16190f
commit 4675acdd0d
3 changed files with 256 additions and 0 deletions

138
ovh_api.sh Executable file
View File

@@ -0,0 +1,138 @@
#!/bin/bash
source ovh_secrets.txt
HTTP_QUERY="https://api.ovh.com/1.0/domain"
TIME=$(curl -s https://api.ovh.com/1.0/auth/time)
ZONE_FILE="zone.photos-nas.ovh"
ZONE="photos-nas.ovh"
# zone export
export_zone() {
HTTP_METHOD="GET"
HTTP_BODY=""
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/export"
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY | sed 's/\\n/\n/g' | sed 's/\"//g' | grep 'CNAME'> $ZONE_FILE
#curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY | sed 's/\\n/\n/g' | grep 'CNAME'
# |sed 's/,//g' |sed 's/\\n/\'$'\n''/g'
# | sed 's/\\n/\n/g'
echo $?
if [ $? == 0 ]; then
echo "$ZONE_FILE have been created !"
fi
}
export_zone
cat $ZONE_FILE
refresh() {
HTTP_BODY=""
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/refresh"
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
echo $? # 0
if [ $? == 0 ]; then
echo "Zone $ZONE have been successfully refresh !"
else
echo "Error while refreshing zone $ZONE !"
fi
}
# ajout d'un cname
add_cname() {
HTTP_METHOD="POST"
HTTP_BODY="{\"fieldType\": \"CNAME\",\"subDomain\": \"$1\",\"target\": \"photos-nas.ovh.\",\"ttl\": 0}"
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/record"
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
echo $? # null
if [ $? == 0 ]; then
echo "CNAME $1 have been successfully added !"
else
echo "Error adding CNAME $1 !"
fi
HTTP_BODY=""
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/refresh"
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
echo $? # 0
if [ $? == 0 ]; then
echo "Zone $ZONE have been successfully refresh !"
else
echo "Error while refreshing zone $ZONE !"
fi
}
#add_cname "example_cname"
remove_cname() {
record=""
HTTP_METHOD="GET"
HTTP_BODY=""
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/record?fieldType=CNAME&subDomain=$1"
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
record=$(curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY | sed 's/.//;s/.$//')
#echo $? # 0
if [ $? == 0 ] && [ -n "$record" ]; then
echo "Record number for CNAME $1 is $record !"
HTTP_METHOD="DELETE"
HTTP_BODY=""
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/record/$record"
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
#echo $? # 0
if [ $? == 0 ]; then
echo "CNAME $1 have been successfully deleted !"
else
echo "Error while deleting CNAME $1 !"
fi
else
echo "No record number found for CNAME $1 !"
fi
}
remove_cname "kuma"
#curl -X POST "https://eu.api.ovh.com/v1/domain/zone/photos-nas.ovh/record" \
# -H "accept: application/json"\
# -H "authorization: Bearer eyJhbGciOiJFZERTQSIsImtpZCI6IkVGNThFMkUxMTFBODNCREFEMDE4OUUzMzZERTk3MDhFNjRDMDA4MDEiLCJraW5kIjoib2F1dGgyIiwidHlwIjoiSldUIn0.eyJBY2Nlc3NUb2tlbiI6ImY4MGU5NmQwZmFiZmM3ZWY0MmMzZjZjNjcxNjZiOWUzNWQwMDc3NTJiOTFhNGQ0NDQyNmY3NTM1MzhiM2M5N2EiLCJpYXQiOjE3MjIyNTk0NzF9.C4MFvrgfF53n87q3h1xny7NBYAOozwzA5t8ty9TqNprMTfWz0Fx5JwvFaCVi8jzDvjzwIYd4MLNm-WqTfLfsAw"\
# -H "content-type: application/json" \
# -d '{"fieldType":"CNAME","subDomain":"api-test","target":"photos-nas.ovh.","ttl":0}' \
# {"fieldType": "CNAME","subDomain": "api-test","target": "photos-nas.ovh.","ttl": 0}
# refresh
# curl -X POST "https://eu.api.ovh.com/v1/domain/zone/photos-nas.ovh/refresh" \
# -H "authorization: Bearer eyJhbGciOiJFZERTQSIsImtpZCI6IkVGNThFMkUxMTFBODNCREFEMDE4OUUzMzZERTk3MDhFNjRDMDA4MDEiLCJraW5kIjoib2F1dGgyIiwidHlwIjoiSldUIn0.eyJBY2Nlc3NUb2tlbiI6ImY4MGU5NmQwZmFiZmM3ZWY0MmMzZjZjNjcxNjZiOWUzNWQwMDc3NTJiOTFhNGQ0NDQyNmY3NTM1MzhiM2M5N2EiLCJpYXQiOjE3MjIyNTk0NzF9.C4MFvrgfF53n87q3h1xny7NBYAOozwzA5t8ty9TqNprMTfWz0Fx5JwvFaCVi8jzDvjzwIYd4MLNm-WqTfLfsAw"

42
update_container.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -e
# Our function to update containers based on their base image
update_container() {
local image=$1
docker pull $image
local updated_containers=0
# Loop through all running containers
for container in $(docker ps --format "{{.Names}}"); do
local container_image=$(docker inspect --format '{{.Config.Image}}' "$container")
# We check if the current container's image matches the updated image
if [[ "$container_image" == "$image" ]]; then
local latest=$(docker inspect --format "{{.Id}}" $image)
local running=$(docker inspect --format "{{.Image}}" $container)
if [[ "$running" != "$latest" ]]; then
echo "Upgrading $container"
#docker rm -f $container
# docker run --name $container $image
((updated_containers++))
fi
fi
done
if [[ $updated_containers -eq 0 ]]; then
echo "No containers updated for $image"
else
echo "$updated_containers container(s) updated for $image"
fi
}
# Our main script starts here
# Check for updates to all images used by running containers
for image in $(docker ps --format '{{.Image}}' | sort | uniq); do
echo "Checking updates for $image"
update_container $image
done
echo "Container update check complete."

76
wget-url-check.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/usr/bin/env bash
italic="\033[3m"
underline="\033[4m"
ita_under="\033[3;4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
bold="\033[1m"
bold_ita="\033[1;3m"
box="\033[1;41m"
redbold="\033[1;31m"
redbox="\033[1;41m"
green="\033[0;32m"
greenbold="\033[1;32m"
reset="\033[0m"
: << 'COMMENTS'
echo "toto"
COMMENTS
cat < /dev/null > /dev/tcp/1.1.1.1/53
if [[ $? -ne 0 ]]; then
echo -e "\n${red}No Internet connection !${reset}"
echo -e "Exit !"
exit 1
fi
#urls=("https://clicclac.info" "https://clicclac.info/wordpress" "https://sur-le-sentier.fr" "https://maboiteverte.fr"
# "https://ds923.photos-nas.ovh" "https://portainer.photos-nas.ovh/" "https://dockge.photos-nas.ovh/" "https://kuma.photos-nas.ovh/")
urls=()
while read -r line
do
urls+=("$line")
done < urls_list.txt
check() {
website=$(echo "$1" | awk -F "\/\/" '{print $2}')
# https://developer.mozilla.org/fr/docs/Web/HTTP/Status
if wget --no-verbose --tries=1 --spider "$1" 2>&1 | grep -w "200\|301" ; then
#echo -e "${greenbold}$1 is up${reset}\n"
echo -e "${greenbold}$website is up${reset}\n"
else
echo -e "${redbold}$1 is down${reset}\n"
fi
}
check2() {
website=$(echo "$1" | awk -F "\/\/" '{print $2}')
response=$(curl --write-out '%{http_code}' --silent --output /dev/null "$1")
if [ $(grep -w "200\|301\|302\|303" <<< "$response") ];then
echo -e "${greenbold}$website is up${reset} ($response)\n"
else
echo -e "${redbold}$1 is down${reset} ($response)\n"
fi
}
info_cn() {
cn=$(echo | openssl s_client -connect $1 2>/dev/null | openssl x509 -noout -subject -dates -issuer)
}
: << 'COMMENTS2'
COMMENTS2
for url in "${!urls[@]}"
do
#check "${urls[$url]}"
check2 "${urls[$url]}"
done
# curl --write-out "%{json}" https://nextcloud.photos-nas.ovh | jq