Welcome to mirror list, hosted at ThFree Co, Russian Federation.

spDYN.sh « ncp-config.d « etc - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec27a3dc7d12f7dd904d35e56bc0ef96f0c24842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash

# spDYN setup for NextcloudPlus
#
#
# Copyleft 2017 by Timm Goldenstein
# https://github.com/TimmThaler/spdnsUpdater
#
# GPL licensed (see end of file) * Use at your own risk!
#

ACTIVE_=no
DOMAIN_=mycloud.spdns.de
TOKEN_=your-spdns-token

INSTALLDIR=spdnsupdater
INSTALLPATH=/usr/local/etc/$INSTALLDIR
CRONFILE=/etc/cron.d/spdnsupdater
DESCRIPTION="Free Dynamic DNS provider (need account from spdyn.de)"

install()
{
  apt-get update
  apt-get install -y --no-install-recommends curl # TODO use wget instead

  # Create the spdnsUpdater.sh
  mkdir -p "$INSTALLPATH"
  # Write the script to file
  cat > "$INSTALLPATH"/spdnsUpdater.sh <<'EOF' 
#!/bin/bash

### Usage
#
#	Recommended usage:	./spdnsUpdater.sh <hostname> <token>
#	Alternative usage:	./spdnsUpdater.sh <hostname> <user> <passwd>
#


### Configuration

# Get current IP address from
get_ip_url="https://api.ipify.org/"
update_url="https://update.spdyn.de/nic/update"


### Update procedure
function spdnsUpdater { 
	# Send the current IP address to spdyn.de
	# and show the response
	
	params=$1
	updater=$(curl -s $update_url $params)
	updater=$(echo $updater | grep -o '^[a-z]*')
	
	case "$updater" in
		abuse) echo "[$updater] Der Host kann nicht aktualisiert werden, da er aufgrund vorheriger fehlerhafter Updateversuche gesperrt ist."
			;;
		badauth) echo "[$updater] Ein ungültiger Benutzername und / oder ein ungültiges Kennwort wurde eingegeben."
			;;
		good) echo "[$updater] Die Hostname wurde erfolgreich auf die neue IP aktualisiert."
			;;
		yours) echo "[$updater] Der angegebene Host kann nicht unter diesem Benutzer-Account verwendet werden."
			;;
		notfqdn) echo "[$updater] Der angegebene Host ist kein FQDN."
			;;
		numhost) echo "[$updater] Es wurde versucht, mehr als 20 Hosts in einer Anfrage zu aktualisieren."
			;;
		nochg) echo "[$updater] Die IP hat sich zum letzten Update nicht geändert."
			;;
		nohost) echo "[$updater] Der angegebene Host existiert nicht oder wurde gelöscht."
			;;
		fatal) echo "[$updater] Der angegebene Host wurde manuell deaktiviert."
			;;
		*) echo "[$updater]"
			;;
	esac

}


if [ $# -eq 2 ]
  	then
  		# if hostname and token
  		# Get current IP address
		currip=$(curl -s "$get_ip_url");
		host=$1
		token=$2
    	params="-d hostname=$host -d myip=$currip -d user=$host -d pass=$token"
    	spdnsUpdater "$params"
	elif [ $# -eq 3 ]
		then
			# if hostname and user and passwd
			# Get current IP address
			currip=$(curl -s "$get_ip_url");
			host=$1
			user=$2
			pass=$3
			params="-d hostname=$host -d myip=$currip -d user=$user -d pass=$pass"
			spdnsUpdater "$params"
	else
		echo
		echo "Updater for Dynamic DNS at spdns.de"
		echo "==================================="
		echo
		echo "Usage:"
		echo "------"
		echo
		echo "Recommended:	./spdnsUpdater.sh <hostname> <token>"
		echo "Alternative:	./spdnsUpdater.sh <hostname> <user> <password>"
		echo
fi
EOF

    chmod 700 "$INSTALLPATH"/spdnsUpdater.sh
    chmod a+x "$INSTALLPATH"/spdnsUpdater.sh

}

configure() 
{
  if [[ $ACTIVE_ == "yes" ]]; then
    
    # Adds file to cron to run script for DNS record updates and change permissions 
    touch $CRONFILE
    echo "0 * * * * root $INSTALLPATH/spdnsUpdater.sh $DOMAIN_ $TOKEN_ >/dev/null 2>&1" > "$CRONFILE"
    chmod +x "$CRONFILE"

    # First-time execution of update script and print response from spdns.de server
    "$INSTALLPATH"/spdnsUpdater.sh "$DOMAIN_" "$TOKEN_"

    # Removes config files and cron job if ACTIVE_ is set to no
  elif [[ $ACTIVE_ == "no" ]]; then
    echo "... removing cronfile: $CRONFILE"
    rm -f "$CRONFILE"
    echo "spdnsUpdater is now disabled"
  fi
  service cron restart
}

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA