mirror of
https://github.com/namibia/demo-sync.git
synced 2024-11-25 04:37:34 +00:00
Changed the poject so we can use it for the sentinal project.
This commit is contained in:
parent
63e5c010cb
commit
700807769e
@ -1,26 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
||||||
# __ __ _ _____ _ _ __ __ _ _ _
|
|
||||||
# \ \ / / | | | __ \ | | | | | \/ | | | | | | |
|
|
||||||
# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
|
|
||||||
# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
|
|
||||||
# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
|
|
||||||
# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
|
|
||||||
# | |
|
|
||||||
# |_|
|
|
||||||
#/-------------------------------------------------------------------------------------------------------------------------------/
|
|
||||||
#
|
#
|
||||||
# @version 1.0.0
|
# @version 1.0.0
|
||||||
# @build 21st July, 2017
|
# @build 16th Feb, 2020
|
||||||
# @package Dynamic IP
|
# @package setninal
|
||||||
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
||||||
# @copyright Copyright (C) 2015. All Rights Reserved
|
# @copyright Copyright (C) 2020. All Rights Reserved
|
||||||
# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
#
|
#
|
||||||
#/-----------------------------------------------------------------------------------------------------------------------------/
|
#/-----------------------------------------------------------------------------------------------------------------------------/
|
||||||
|
|
||||||
############################ GLOBAL ##########################
|
############################ GLOBAL ##########################
|
||||||
ACTION="getip"
|
ACTION="gedata"
|
||||||
|
OWNER="Llewellynvdm"
|
||||||
|
NAME="sentinel-client"
|
||||||
|
HOST="https://www.vdm.io"
|
||||||
######### DUE TO NOT BEING ABLE TO INCLUDE DYNAMIC ###########
|
######### DUE TO NOT BEING ABLE TO INCLUDE DYNAMIC ###########
|
||||||
|
|
||||||
#################### UPDATE TO YOUR NEEDS ####################
|
#################### UPDATE TO YOUR NEEDS ####################
|
||||||
@ -29,8 +23,8 @@ ACTION="getip"
|
|||||||
############## CONFIG ##########
|
############## CONFIG ##########
|
||||||
############## ##########
|
############## ##########
|
||||||
##############################################################
|
##############################################################
|
||||||
REPOURL="https://raw.githubusercontent.com/vdm-io/dynamic-ip/master/"
|
REPOURL="https://raw.githubusercontent.com/${OWNER}/${NAME}/master/"
|
||||||
VDMIPSERVER="https://www.vdm.io/$ACTION"
|
VDMIPSERVER="${HOST}/${ACTION}"
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
############## ##########
|
############## ##########
|
||||||
@ -49,10 +43,10 @@ function main () {
|
|||||||
getLocalKey
|
getLocalKey
|
||||||
## check access (set if not ready)
|
## check access (set if not ready)
|
||||||
setAccessToken
|
setAccessToken
|
||||||
## get the IPs
|
## get the data
|
||||||
getIPs
|
getData
|
||||||
## check the IPs and then set
|
## Work with the data
|
||||||
setDNS
|
storeLocalData
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
@ -174,99 +168,26 @@ function setAccessToken () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIPs () {
|
function getData () {
|
||||||
# store the IP in the HOSTNAME file
|
# getting the station data
|
||||||
echoTweak "Getting the Dynamic IPs..."
|
echoTweak "Getting the station data..."
|
||||||
THEIPS=$(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: $VDMSERVERKEY" -H "VDM-HOST-IP: $HOSTIP" -H "VDM-GET: 1" --silent $VDMIPSERVER)
|
THEDATA=$(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: $VDMSERVERKEY" -H "VDM-HOST-IP: $HOSTIP" -H "VDM-GET: 1" --silent $VDMIPSERVER)
|
||||||
# the IPs
|
# the data
|
||||||
if [[ "$THEIPS" == "$FALSE" || ${#THEIPS} -lt 15 ]]; then
|
if [[ "$THEDATA" == "$FALSE" || ${#THEDATA} -lt 15 ]]; then
|
||||||
echo "No IPs FOUND! "
|
echo "No data FOUND! "
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Done"
|
echo "Done"
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDNS () {
|
function storeLocalData () {
|
||||||
# check IPS
|
# load data
|
||||||
readarray -t rows <<< "$THEIPS"
|
readarray -t rows <<< "$THEDATA"
|
||||||
for rr in "${rows[@]}" ; do
|
for rr in "${rows[@]}" ; do
|
||||||
row=( $rr )
|
row=( $rr )
|
||||||
if [[ ${#row[@]} == 3 ]]; then
|
if [[ ${#row[@]} == 3 ]]; then
|
||||||
# first check IP
|
# start =>>>
|
||||||
echoTweak "Checking the Dynamic IP..."
|
echoTweak "This work needs to still be done...."
|
||||||
if [[ "${row[2]}" =~ ^([0-9]{1,3})[.]([0-9]{1,3})[.]([0-9]{1,3})[.]([0-9]{1,3})$ ]]
|
|
||||||
then
|
|
||||||
for (( i=1; i<${#BASH_REMATCH[@]}; ++i ))
|
|
||||||
do
|
|
||||||
if (( ${BASH_REMATCH[$i]} > 255 )); then
|
|
||||||
echo "bad IP"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo "bad IP"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
echo "Done"
|
|
||||||
echoTweak "Checking local DNS file..."
|
|
||||||
# check if the DNS file is found (CENTOS)
|
|
||||||
FILEPATH=0
|
|
||||||
if [ -f "/var/named/${row[1]}.${row[0]}.db" ]
|
|
||||||
then
|
|
||||||
FILEPATH="/var/named/${row[1]}.${row[0]}.db"
|
|
||||||
FILENAME="${row[1]}.${row[0]}"
|
|
||||||
elif [ -f "/var/named/${row[0]}.db" ]
|
|
||||||
then
|
|
||||||
FILEPATH="/var/named/${row[0]}.db"
|
|
||||||
FILENAME="${row[0]}"
|
|
||||||
fi
|
|
||||||
# confirm that it was found
|
|
||||||
if [[ "$FILEPATH" == 0 ]]
|
|
||||||
then
|
|
||||||
echo "not found"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
echo "Done"
|
|
||||||
# now add the IP A record if needed
|
|
||||||
if grep -Fq "${row[2]}" "$FILEPATH"
|
|
||||||
then
|
|
||||||
# IP already set
|
|
||||||
echoTweak "DNS IP (${row[2]})..."
|
|
||||||
echo "already set"
|
|
||||||
else
|
|
||||||
tmpFile=$(getKey)
|
|
||||||
# first remove old IPs
|
|
||||||
grep -v "^${row[1]} " "$FILEPATH" > "/tmp/vdm_$tmpFile"
|
|
||||||
# start notice
|
|
||||||
echoTweak "DNS Adding A Record for IP (${row[2]})"
|
|
||||||
echo "started"
|
|
||||||
# add new a record to tmp file
|
|
||||||
echoTweak "${row[1]}" 16 '\040' >> "/tmp/vdm_$tmpFile"
|
|
||||||
echoTweak "1" 8 '\040' >> "/tmp/vdm_$tmpFile"
|
|
||||||
echo "IN A ${row[2]}" >> "/tmp/vdm_$tmpFile"
|
|
||||||
# add new a record to zone file
|
|
||||||
mv "/tmp/vdm_$tmpFile" "$FILEPATH"
|
|
||||||
#remove tmp file
|
|
||||||
# rm "/tmp/vdm_$tmpFile"
|
|
||||||
# Only reload the rndc if found
|
|
||||||
if [ -f "/etc/rndc.conf" ]
|
|
||||||
then
|
|
||||||
cd /var/named
|
|
||||||
echoTweak "reload $FILENAME IN external"
|
|
||||||
rndc reload "$FILENAME" IN external 2>/dev/null
|
|
||||||
echoTweak "reload $FILENAME IN internal"
|
|
||||||
rndc reload "$FILENAME" IN internal 2>/dev/null
|
|
||||||
echoTweak "notify $FILENAME IN external"
|
|
||||||
rndc notify "$FILENAME" IN external 2>/dev/null
|
|
||||||
echoTweak "notify $FILENAME IN internal"
|
|
||||||
rndc notify "$FILENAME" IN internal 2>/dev/null
|
|
||||||
echoTweak "refresh $FILENAME IN external"
|
|
||||||
rndc refresh "$FILENAME" IN external 2>/dev/null
|
|
||||||
echoTweak "refresh $FILENAME IN internal"
|
|
||||||
rndc refresh "$FILENAME" IN internal 2>/dev/null
|
|
||||||
cd ~
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
20
readme.md
20
readme.md
@ -1,13 +1,13 @@
|
|||||||
Dynamic IP
|
Sential Basic client
|
||||||
============
|
============
|
||||||
This script will update the VDM system with your dynamic IP. To run this script, use the following command (as root):
|
This script will update the VDM system with a station data. To run this script, use the following command (as root):
|
||||||
|
|
||||||
*setip* = set IP to VDM system
|
*setdata* = set Station Data to VDM system
|
||||||
*getip* = will return all details related to this server
|
*gedata* = will return all details related to this watcher
|
||||||
|
|
||||||
# to set IP:
|
# to set Data:
|
||||||
```
|
```
|
||||||
bash <(curl -s https://raw.githubusercontent.com/vdm-io/dynamic-ip/master/setip.sh)
|
bash <(curl -s https://raw.githubusercontent.com/Llewellynvdm/sentinel-client/master/setdata.sh)
|
||||||
```
|
```
|
||||||
This script performs the following actions:
|
This script performs the following actions:
|
||||||
|
|
||||||
@ -15,13 +15,13 @@ This script performs the following actions:
|
|||||||
* Adds a cron entry to update this file on a scheduled basis.
|
* Adds a cron entry to update this file on a scheduled basis.
|
||||||
* Adds the server IP to VDM system.
|
* Adds the server IP to VDM system.
|
||||||
|
|
||||||
# to get IPs:
|
# to get Data:
|
||||||
```
|
```
|
||||||
bash <(curl -s https://raw.githubusercontent.com/vdm-io/dynamic-ip/master/getip.sh)
|
bash <(curl -s https://raw.githubusercontent.com/Llewellynvdm/sentinel-client/master/getdata.sh)
|
||||||
```
|
```
|
||||||
|
|
||||||
This script performs the following actions:
|
This script performs the following actions:
|
||||||
|
|
||||||
* Adds random Host Key.
|
* Adds random Host Key.
|
||||||
* Adds a cron entry to update this file on a scheduled basis.
|
* Adds a cron entry to update the data on a scheduled basis.
|
||||||
* Gets dynamic IPS for this serves DNS.
|
* Gets data of stations in the watchers scope.
|
||||||
|
@ -1,26 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
||||||
# __ __ _ _____ _ _ __ __ _ _ _
|
|
||||||
# \ \ / / | | | __ \ | | | | | \/ | | | | | | |
|
|
||||||
# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
|
|
||||||
# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
|
|
||||||
# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
|
|
||||||
# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
|
|
||||||
# | |
|
|
||||||
# |_|
|
|
||||||
#/-------------------------------------------------------------------------------------------------------------------------------/
|
|
||||||
#
|
#
|
||||||
# @version 1.0.0
|
# @version 1.0.0
|
||||||
# @build 21st July, 2017
|
# @build 16th Feb, 2020
|
||||||
# @package Dynamic IP
|
# @package setninal
|
||||||
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
||||||
# @copyright Copyright (C) 2015. All Rights Reserved
|
# @copyright Copyright (C) 2020. All Rights Reserved
|
||||||
# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
#
|
#
|
||||||
#/-----------------------------------------------------------------------------------------------------------------------------/
|
#/-----------------------------------------------------------------------------------------------------------------------------/
|
||||||
|
|
||||||
############################ GLOBAL ##########################
|
############################ GLOBAL ##########################
|
||||||
ACTION="setip"
|
ACTION="sedata"
|
||||||
|
OWNER="Llewellynvdm"
|
||||||
|
NAME="sentinel-client"
|
||||||
|
HOST="www.vdm.io"
|
||||||
######### DUE TO NOT BEING ABLE TO INCLUDE DYNAMIC ###########
|
######### DUE TO NOT BEING ABLE TO INCLUDE DYNAMIC ###########
|
||||||
|
|
||||||
#################### UPDATE TO YOUR NEEDS ####################
|
#################### UPDATE TO YOUR NEEDS ####################
|
||||||
@ -29,8 +23,8 @@ ACTION="setip"
|
|||||||
############## CONFIG ##########
|
############## CONFIG ##########
|
||||||
############## ##########
|
############## ##########
|
||||||
##############################################################
|
##############################################################
|
||||||
REPOURL="https://raw.githubusercontent.com/vdm-io/dynamic-ip/master/"
|
REPOURL="https://raw.githubusercontent.com/${OWNER}/${NAME}/master/"
|
||||||
VDMIPSERVER="https://www.vdm.io/$ACTION"
|
VDMIPSERVER="${HOST}/${ACTION}"
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
############## ##########
|
############## ##########
|
||||||
@ -47,8 +41,8 @@ function main () {
|
|||||||
getLocalKey
|
getLocalKey
|
||||||
## check access (set if not ready)
|
## check access (set if not ready)
|
||||||
setAccessToken
|
setAccessToken
|
||||||
## update IP
|
## update Data
|
||||||
setIP
|
setData
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
@ -166,8 +160,8 @@ function setAccessToken () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function setIP () {
|
function setData () {
|
||||||
# get this server IP
|
# get this station data (TODO we just do the IP for now)
|
||||||
IPNOW="$(dig +short myip.opendns.com @resolver1.opendns.com)"
|
IPNOW="$(dig +short myip.opendns.com @resolver1.opendns.com)"
|
||||||
# store the IP in the HOSTNAME file
|
# store the IP in the HOSTNAME file
|
||||||
echoTweak "Setting/Update the Dynamic IP..."
|
echoTweak "Setting/Update the Dynamic IP..."
|
Loading…
Reference in New Issue
Block a user