Skip to content

Commit

Permalink
* se elimina el uso de root fix #6
Browse files Browse the repository at this point in the history
* binario en vez de docker close #8
* cron opcional y logger fix #7
  • Loading branch information
develpudu committed Jan 24, 2022
1 parent 2df9078 commit a5fd4bd
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 36 deletions.
3 changes: 3 additions & 0 deletions config.dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"install_path": ""
}
File renamed without changes.
Binary file added dnscontrol
Binary file not shown.
2 changes: 1 addition & 1 deletion dnscontrol.crontab
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30 7 * * * install_path/run.sh update >> install_path/dnscontrol.log 2>&1
30 7 * * * install_path/run.sh update
7 changes: 0 additions & 7 deletions docker-compose.yml

This file was deleted.

11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Actualizador de IP publica para deSEC con dnscontrol via docker
# Actualizador de IP publica para todos los domiios de deSEC con dnscontrol

## Requisitos
* docker.io
* docker-compose
* jq
```bash
curl -sS https://webinstall.dev/jq | bash
```
* Ejecutar como root o que el user pueda usar docker sin sudo
* Ejecutar como root o sudo
* Token de acceso de deSEC

## Uso
* Clonar el repositorio
```bash
Expand All @@ -17,6 +17,9 @@ cd dnscontrol
* Ejecutar setup y agregar el token de deSEC
```bash
./run.sh setup

# Si se quiere automatizar con cron
./run.sh setup auto
```
* Ejecutar para actualizar la IP publica de todos los dominios:
```bash
Expand Down
63 changes: 39 additions & 24 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
#!/bin/bash
#
# Ejecutar como root o que el user pueda usar docker sin sudo
#!/bin/bash

CURRENT=`pwd`
BASENAME="$CURRENT"
VERSION="0.7.0"
RUN_PATH=$(dirname "$BASH_SOURCE")
LOG_FILE=$RUN_PATH/dnscontrol.log

if [[ $EUID -ne 0 ]]; then
echo "Este script se debe ejecutar como root o sudoer" 1>&2
exit 1
fi
logger(){
if [ $# -eq 0 ]
then cat - | while read -r message
do
echo "$(date +"[%F %T %Z] -") $message" | tee -a $LOG_FILE
done
else
echo -n "$(date +'[%F %T %Z]') - " | tee -a $LOG_FILE
echo $* | tee -a $LOG_FILE
fi
}

case $1 in
setup)
cd "$RUN_PATH"
# TODO: Agregar que descargue la ultima version de dnscontrol desde git
if [ -f "creds.json" ]; then
echo "--> Ya existe el archivo de credenciales"
while true; do
read -p "Actualizar el archivo: (y/n)" yn
case $yn in
[Yy]*)
read -p "--> Token de deSEC: " TOKEN
cp creds-deSEC.json creds.json
sed -i 's/auth-token": ""/auth-token": "'$TOKEN'"/g' creds.json
sed -i 's','install_path',''$CURRENT'','g' dnscontrol.crontab
crontab -u root dnscontrol.crontab
cp creds.dist.json creds.json
cp config.dist.json config.json
sed -i 's','auth-token": ""','auth-token": "'$TOKEN'"','g' creds.json
sed -i 's','install_path": ""','install_path": "'$RUN_PATH'"','g' config.json
echo "--> Ejecute ./run.sh update para actualizar los dns."
break
;;
Expand All @@ -34,15 +41,21 @@ case $1 in
esac
done
else
cp creds-deSEC.json creds.json
cp creds.dist.json creds.json
cp config.dist.json config.json
read -p "--> Token de deSEC: " TOKEN
sed -i 's/auth-token": ""/auth-token": "'$TOKEN'"/g' creds.json
sed -i 's','install_path',''$CURRENT'','g' dnscontrol.crontab
crontab -u root dnscontrol.crontab
sed -i 's','auth-token": ""','auth-token": "'$TOKEN'"','g' creds.json
sed -i 's','install_path": ""','install_path": "'$RUN_PATH'"','g' config.json
echo "--> Ejecute ./run.sh update para actualizar los dns."
fi
fi
if [ "$2" == "auto" ]; then
sed -i 's','install_path',''$RUN_PATH'','g' dnscontrol.crontab
crontab -u $USER dnscontrol.crontab
echo "--> Se agrego dnscontrol.crontab a crontab"
fi
;;
update)
cd "$RUN_PATH"
if [ ! -f "creds.json" ]; then
echo "--> No existe el archivo de credenciales"
echo "--> Ejecute el ./run.sh setup"
Expand All @@ -57,9 +70,9 @@ case $1 in
curl -o domains.json -k -X GET https://desec.io/api/v1/domains/ --header "Authorization: Token $auth"
echo "--> domains.json actualizado"
echo "--> Actualizando DNS con nueva IP"
docker-compose run --rm dnscontrol dnscontrol preview
./dnscontrol preview
echo "--> Aplicando los cambios a deSEC"
docker-compose run --rm dnscontrol dnscontrol push
./dnscontrol push | logger
echo "DNS de dominios actualizados"
;;
domains)
Expand All @@ -75,18 +88,20 @@ case $1 in
echo "--> domains.json actualizado"
;;
token)
cd "$RUN_PATH"
auth=`jq -r '.desec."auth-token"' creds.json`
echo "--> Token: $auth"
;;
terminal)
docker-compose run --rm dnscontrol sh
;;
version)
echo "--> Version: $VERSION"
;;
help)
echo "./run.sh setup: Crea el archivo creds.json con credenciales de deSEC"
echo "./run.sh setup auto: Crea el archivo creds.json con credenciales de deSEC y genera el crontab"
echo "./run.sh update: Actualiza la IP publica y los DNS de los dominios"
echo "./run.sh domains: Actualiza la lista de dominios"
echo "./run.sh token: Muestra el token de autenticacion"
echo "./run.sh terminal: Abre una terminal en el contenedor"
echo "./run.sh version: Muestra la version"
echo "./run.sh help: Muestra esta ayuda"
;;
*)
Expand Down

0 comments on commit a5fd4bd

Please sign in to comment.