1
0
mirror of https://github.com/namibia/demo-sync.git synced 2024-11-24 20:27:33 +00:00

added the basic getip and changed all queries to header calls.

This commit is contained in:
Llewellyn van der Merwe 2017-07-21 16:47:10 +01:00
parent 6d497fcb43
commit 937f3330a3
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
2 changed files with 105 additions and 16 deletions

89
getip.sh Normal file
View File

@ -0,0 +1,89 @@
#!/bin/bash
# simple basic random
function getKey () {
echo $(tr -dc 'A-HJ-NP-Za-km-z2-9' < /dev/urandom | dd bs=128 count=1 status=none)
}
# Variables
TRUE=1
VDMUSER="vdm"
VDMHOME="/home/vdm"
VDMSCRIPT="https://raw.githubusercontent.com/vdm-io/dynamic-ip/master/getip.sh"
VDMIPSERVER="https://www.vdm.io/getip"
# Require script to be run via sudo, but not as root
#if [[ $EUID -ne 0 ]]; then
#
# echo "Script must be run with root privilages!"
# exit 1
#fi
# Set cronjob without removing existing
if [ -f $VDMHOME/getip.cron ]; then
echo "Crontab already configured for updates...Skipping"
else
echo -n "Adding crontab entry for continued updates..."
# check if user crontab is set
currentCron=$(crontab -u $VDMUSER -l 2>/dev/null)
if [[ -z "${currentCron// }" ]]; then
currentCron="# VDM crontab settings"
echo "$currentCron" > $VDMHOME/getip.cron
else
echo "$currentCron" > $VDMHOME/getip.cron
fi
# check if the MAILTO is already set
if [[ $currentCron != *"MAILTO"* ]]; then
echo "MAILTO=\"\"" >> $VDMHOME/getip.cron
echo "" >> $VDMHOME/getip.cron
fi
# check if the @reboot curl -s $VDMSCRIPT | sudo bash is already set
if [[ $currentCron != *"@reboot curl -s $VDMSCRIPT | sudo bash"* ]]; then
echo "@reboot curl -s $VDMSCRIPT | sudo bash" >> $VDMHOME/getip.cron
fi
# check if the @reboot curl -s $VDMSCRIPT | sudo bash is already set
if [[ $currentCron != *"*/7 * * * * curl -s $VDMSCRIPT | sudo bash"* ]]; then
echo "*/7 * * * * curl -s $VDMSCRIPT | sudo bash" >> $VDMHOME/getip.cron
fi
# set the user cron
crontab -u $VDMUSER $VDMHOME/getip.cron
echo "Done"
fi
# Set update key
if [ -f $VDMHOME/getip.key ]; then
echo "Update key already set!"
else
echo -n "Setting the update key..."
echo $(getKey) > $VDMHOME/getip.key
echo "Done"
fi
# Get update key
serverKey=$(<"$VDMHOME/getip.key")
# check if vdm access was set
accessToke=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "VDM-KEY: $serverKey" --silent $VDMIPSERVER)
if [[ "$accessToke" != "$TRUE" ]]; then
read -s -p "Please enter your VDM access key: " vdmAccessKey
echo ""
echo -n "One moment while we set your access to the VDM system..."
resultAccess=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "VDM-TRUST: $vdmAccessKey" -H "VDM-KEY: $serverKey" --silent $VDMIPSERVER)
if [[ "$resultAccess" != "$TRUE" ]]; then
echo " >> YOUR VDM ACCESS KEY IS INCORRECT! <<"
exit 1
fi
echo "Done"
else
echo "Access granted to the VDM system."
fi
# getting the dynamic ip from vdm system
echo -n "getting the Dynamic IP..."
resultUpdate=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "VDM-KEY: $serverKey" --silent $VDMIPSERVER)
if [[ "$resultUpdate" != "$TRUE" ]]; then
echo " >> YOUR SERVER KEY IS INCORRECT! <<"
exit 1
fi
echo "Done"

View File

@ -20,7 +20,7 @@ VDMIPSERVER="https://www.vdm.io/setip"
#fi
# Set cronjob without removing existing
if [ -f $VDMHOME/vdmip.cron ]; then
if [ -f $VDMHOME/setip.cron ]; then
echo "Crontab already configured for updates...Skipping"
else
echo -n "Adding crontab entry for continued updates..."
@ -28,48 +28,48 @@ else
currentCron=$(crontab -u $VDMUSER -l 2>/dev/null)
if [[ -z "${currentCron// }" ]]; then
currentCron="# VDM crontab settings"
echo "$currentCron" > $VDMHOME/vdmip.cron
echo "$currentCron" > $VDMHOME/setip.cron
else
echo "$currentCron" > $VDMHOME/vdmip.cron
echo "$currentCron" > $VDMHOME/setip.cron
fi
# check if the MAILTO is already set
if [[ $currentCron != *"MAILTO"* ]]; then
echo "MAILTO=\"\"" >> $VDMHOME/vdmip.cron
echo "" >> $VDMHOME/vdmip.cron
echo "MAILTO=\"\"" >> $VDMHOME/setip.cron
echo "" >> $VDMHOME/setip.cron
fi
# check if the @reboot curl -s $VDMSCRIPT | sudo bash is already set
if [[ $currentCron != *"@reboot curl -s $VDMSCRIPT | sudo bash"* ]]; then
echo "@reboot curl -s $VDMSCRIPT | sudo bash" >> $VDMHOME/vdmip.cron
echo "@reboot curl -s $VDMSCRIPT | sudo bash" >> $VDMHOME/setip.cron
fi
# check if the @reboot curl -s $VDMSCRIPT | sudo bash is already set
if [[ $currentCron != *"*/30 * * * * curl -s $VDMSCRIPT | sudo bash"* ]]; then
echo "*/30 * * * * curl -s $VDMSCRIPT | sudo bash" >> $VDMHOME/vdmip.cron
if [[ $currentCron != *"*/5 * * * * curl -s $VDMSCRIPT | sudo bash"* ]]; then
echo "*/5 * * * * curl -s $VDMSCRIPT | sudo bash" >> $VDMHOME/setip.cron
fi
# set the user cron
crontab -u $VDMUSER $VDMHOME/vdmip.cron
crontab -u $VDMUSER $VDMHOME/setip.cron
echo "Done"
fi
# Set update key
if [ -f $VDMHOME/ip.key ]; then
if [ -f $VDMHOME/setip.key ]; then
echo "Update key already set!"
else
echo -n "Setting the update key..."
echo $(getKey) > $VDMHOME/ip.key
echo $(getKey) > $VDMHOME/setip.key
echo "Done"
fi
# Get update key
serverKey=$(<"$VDMHOME/ip.key")
serverKey=$(<"$VDMHOME/setip.key")
# check if vdm access was set
accessToke=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" --silent --data-urlencode "key=$serverKey" $VDMIPSERVER)
accessToke=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "VDM-KEY: $serverKey" --silent $VDMIPSERVER)
if [[ "$accessToke" != "$TRUE" ]]; then
read -s -p "Please enter your VDM access key: " vdmAccessKey
echo ""
echo -n "One moment while we set your access to the VDM system..."
resultAccess=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" --silent --data-urlencode "trust=$vdmAccessKey" --data-urlencode "key=$serverKey" $VDMIPSERVER)
resultAccess=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "VDM-TRUST: $vdmAccessKey" -H "VDM-KEY: $serverKey" --silent $VDMIPSERVER)
if [[ "$resultAccess" != "$TRUE" ]]; then
echo " >> YOUR VDM ACCESS KEY IS INCORRECT! <<"
exit 1
@ -83,9 +83,9 @@ fi
IPNOW="$(dig +short myip.opendns.com @resolver1.opendns.com)"
# store the IP in the HOSTNAME file
echo -n "Setting/Update the Dynamic IP..."
resultUpdate=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" --silent --data-urlencode "ip=$IPNOW" --data-urlencode "key=$serverKey" $VDMIPSERVER)
resultUpdate=$(curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "VDM-KEY: $serverKey" -H "VDM-IP: $IPNOW" --silent $VDMIPSERVER)
if [[ "$resultUpdate" != "$TRUE" ]]; then
echo " >> YOUR SERVER KEY IS INCORRECT! << $resultUpdate"
echo " >> YOUR SERVER KEY IS INCORRECT! <<"
exit 1
fi
echo "Done"