This repository has been archived by the owner on Jun 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0072635
Showing
9 changed files
with
624 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Revision history for afraid-dyndns | ||
|
||
1.1 Thu Oct 15 15:02:30 PDT 2009 - Erick Calder <e@arix.com> | ||
- enhanced to allow refreshing a single host name | ||
- modifications for running on OSX | ||
|
||
1.0 2009/09/18 02:32:01 - Erick Calder <e@arix.com> | ||
- initial release |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
SYNOPSIS | ||
|
||
This utility implements a client for the afraid.org dynamic DNS service. | ||
A cron job is set up to check whether the external IP address has | ||
changed, and when it does, connects to afraid.org and updates the | ||
DNS entries of all the domains of the given account. | ||
|
||
SUPPORTED OPERATING SYSTEMS | ||
|
||
* Fedora | ||
* CentOS | ||
* RHEL | ||
* OSX | ||
|
||
INSTALL | ||
|
||
1. log in as root (needed to access config, cron and cache directories): | ||
# su - | ||
2. Download the tarball: | ||
# cd /tmp | ||
# wget ftp://arix.com/afraid-dyndns-x.x.tar.gz | ||
|
||
on OSX, you can use: | ||
# curl -O ftp://anon@arix.com/afraid-dyndns-x.x.tar.gz | ||
3. Untar: | ||
# tar xzvf afraid-dyndns-x.x.tgz | ||
4. Install: | ||
# cd afraid-dyndns-x.x | ||
# ./install | ||
|
||
CONFIGURATION | ||
|
||
To configure, edit the /etc/afraid-dyndns.conf file. The AccountHash | ||
field refers to the SHA value assigned to your afraid.org account. | ||
To get it, log into afraid.org and visit: | ||
|
||
http://freedns.afraid.org/api/ | ||
|
||
then click on either of your "ChoOsE YoUr WeApOn" links and take | ||
the value of the "sha" parameter (it's a long string). The Notify | ||
address (if present) will be sent e-mail whenever the DNS is | ||
refreshed. CacheFile is the file name where the external IP address | ||
will be cached. | ||
|
||
Additionally, the cron job checks the external IP address every 15 | ||
minutes. To modify this, edit /etc/cron.d/afraid-dyndns - on OSX you'll | ||
need to edit the file /Library/LaunchDaemons/org.afraid.dyndns.plist (and | ||
reboot) | ||
|
||
Unlink on Linux systems where all names on the account are refreshed with | ||
the IP of the host, on OSX the default configuration only names matching | ||
the host's name will be refreshed. The assumption here is that Linux | ||
hosts are likely to be used as servers (which may require multiple names | ||
as in the case of a webserver hosting multiple domains), whereas OSX | ||
hosts are likely to be used as clients e.g. laptops which we want | ||
accessible via a domain name but which roam. | ||
|
||
To change this behaviour on OSX, edit the plist, take out the | ||
hostname parameter (after the --quiet) and reboot. | ||
|
||
SYNTAX | ||
|
||
Call the script with --help | ||
|
||
LIMITATIONS | ||
|
||
At present, only one account is supported. | ||
|
||
AUTHOR/SUPPORT | ||
|
||
Erick Calder <e@arix.com> - For bugs, suggestions, etc. please | ||
feel free to contact me. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
#!/usr/bin/perl | ||
|
||
# | ||
# afraid-dyndns - a Dynamic DNS client for the afraid.org free service | ||
# Copyright (C) 2009 Erick Calder | ||
# | ||
# This program 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 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program 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 program; if not, write to the Free Software | ||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
# | ||
|
||
$|++; | ||
$\ = $/; | ||
|
||
use LWP::Simple; | ||
use XML::Simple; | ||
# use Data::Dumper; | ||
use Getopt::Long; | ||
|
||
Getopt::Long::Configure("no_ignore_case"); | ||
$args{"debug|D"} = "Debug mode"; | ||
$args{"quiet"} = "Suppresses normal output"; | ||
$args{"help"} = "Display syntax"; | ||
GetOptions(\%ARGV, keys %args); | ||
|
||
if ($ARGV{help}) { | ||
echo("Syntax: $0 [--quiet] [--debug|-D] [--help] [hostname]"); | ||
echo(" quiet: supresses all output"); | ||
echo(" debug: generates feedback on internal workings"); | ||
echo(" help: displays syntax"); | ||
echo(" hostname: indicates that only the specified name should be refreshed"); | ||
exit; | ||
} | ||
|
||
# afraid.org listing of urls | ||
|
||
$afraid = "http://freedns.afraid.org/api/?action=getdyndns&sha=%s&style=xml"; | ||
($VER = substr q$Revision: 2342 $, 10) =~ s/\s+$//; | ||
$CONF = "/etc/afraid-dyndns.conf"; | ||
($ME = $0) =~ s|.*/||; | ||
$hostname = shift; | ||
|
||
# get working parameters | ||
|
||
for (readfile($CONF)) { | ||
chomp; | ||
s/#.*//; | ||
split /\s*=\s*/; | ||
$ARGV{$_[0]} = $_[1]; | ||
} | ||
|
||
die "No AccountHash in configuration file - please see README for instructions. Done" unless $ARGV{AccountHash}; | ||
$ARGV{CacheFile} ||= "/var/cache/afraid-dyndns/IP"; | ||
|
||
echo("-- $0 (Ver: $VER) --"); | ||
echo("License: GPL"); | ||
echo("Notifications: " . $ARGV{Notify} || "None"); | ||
|
||
# | ||
# get external and cached IP addresses | ||
# | ||
|
||
$xml = get("http://ip-address.domaintools.com/myip.xml"); | ||
die "Failed fetching IP address!" unless $xml; | ||
|
||
$o = XMLin($xml); | ||
$extip = $o->{ip_address}; # external address | ||
$intip = readfile($ARGV{CacheFile}); # internal address (cached) | ||
chomp $intip; | ||
|
||
# | ||
# when these differ modify the DNS, cache the address and e-mail | ||
# | ||
|
||
if ($extip eq $intip) { | ||
echo("No change in address!"); | ||
} else { | ||
echo("Address changed: $intip => $extip"); | ||
|
||
$xml = get(sprintf($afraid, $ARGV{AccountHash})); | ||
die "Failed fetching update head!" unless $xml; | ||
$o = XMLin($xml); | ||
for (@{$o->{item}}) { | ||
next if $hostname && $_->{host} !~ /$hostname/; | ||
debug("- $_->{host}"); | ||
get($_->{url}) unless $ARGV{debug}; | ||
} | ||
writefile($ARGV{CacheFile}, $extip); | ||
|
||
if ($ARGV{Notify}) { | ||
eval { | ||
require MIME::Lite; | ||
import MIME::Lite; | ||
}; | ||
if ($@) { | ||
local $_ = "Notifications cannot be made without MIME::Lite"; | ||
$_ .= " - to enable please have your system administrator"; | ||
$_ .= " install that perl module"; | ||
echo(); | ||
} | ||
else { | ||
$msg = MIME::Lite->new( | ||
To => $ARGV{Notify}, | ||
Subject => "IP address change", | ||
Data => "Dynamic DNS has been refreshed" | ||
); | ||
$msg->send(); | ||
} | ||
} | ||
} | ||
|
||
exit; | ||
|
||
# | ||
# Syntax: | ||
# readfile [file-name = $_] | ||
# <scalar> = readfile [file-name = $_] | ||
# <list> = readfile [file-name = $_] | ||
# Synopsis: | ||
# returns the contents of a given file. if called in a void | ||
# context, this function sets $_; if called in a scalar context | ||
# the contents are returned as a single string with embedded | ||
# newlines; and if called in a list context the content comes | ||
# back as separate lines. | ||
# | ||
|
||
sub readfile { | ||
my $f = shift || $_; | ||
local $_ if defined wantarray(); | ||
-f $f || return; | ||
open(F, $f) || warn($!) && return; | ||
wantarray() && (@_ = <F>) || (local $/ = undef, $_ = <F>); | ||
close(F); | ||
wantarray() ? @_ : $_; | ||
} | ||
|
||
# | ||
# Syntax: | ||
# writefile <file-name> [content = $_] | ||
# Synopsis: | ||
# writes a string to a file, returns success/failure | ||
# | ||
|
||
sub writefile($@) { | ||
my $fn = shift; | ||
local $_ = shift || $_ || return; | ||
|
||
print ">> writefile(): $fn" if $::DEBUG; | ||
|
||
mkpath(path2fn($fn)); | ||
open(OUT, "> $fn") || warn(qq|writefile("> $fn"): "$!"|) && return; | ||
print OUT; | ||
close(OUT) || return; | ||
return 1; | ||
} | ||
|
||
# | ||
# could've used system("mkdir -p") but | ||
# that won't work on Win32 systems | ||
# | ||
|
||
sub mkpath { | ||
local $_ = shift; | ||
my @d = split m(/); | ||
my $d = ""; | ||
my $mkpath = 0; | ||
|
||
for (@d) { | ||
$d .= "$_/"; | ||
next if -d $d; # skip if it already exists | ||
print "- $d" if $::DEBUG > 1; | ||
mkdir($d) || warn(qq/mkdir("$d"): "$!"/) && return; | ||
$mkpath = 1; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
# | ||
# splits a path into directory, filename and extension | ||
# e.g. ($dir, $fn, $ext) = path2fn($path) | ||
# | ||
|
||
sub path2fn { | ||
my $path = shift; | ||
my ($dir, $fn, $ext); | ||
|
||
@x = split(/\//, $path); | ||
$fn = pop @x; | ||
$dir = join("/", @x); | ||
@x = split(/\./, $fn); | ||
if (@x > 1) { | ||
$ext = pop @x; | ||
$fn = join(".", @x); | ||
} | ||
|
||
return ($dir, $fn, $ext); | ||
} | ||
|
||
# | ||
# output functions | ||
# | ||
|
||
sub debug { | ||
print shift if $ARGV{debug} && !$ARGV{quiet}; | ||
} | ||
|
||
sub echo { | ||
print shift || $_ unless $ARGV{quiet}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Name: afraid-dyndns | ||
Version: 1.0 | ||
Release: 5%{?dist} | ||
Summary: A dynamic DNS client for the free service afraid.org | ||
Group: System Environment/Daemons | ||
License: GPLv3+ | ||
URL: http://perl.arix.com | ||
Source0: ftp://arix.com/afraid-dyndns-1.0.tar.gz | ||
Patch: %{name}.F10.patch | ||
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) | ||
BuildArch: noarch | ||
|
||
%description | ||
This utility implements a client for the free afraid.org dynamic DNS | ||
service. A cron job is set up to check whether the external IP address | ||
has changed, and when it does, connects to afraid.org and updates the | ||
DNS entries of all the domains of the given account. | ||
|
||
%prep | ||
%setup -q | ||
%if 0%{?fedora} <= 10 | ||
%patch -p0 -b .orig | ||
%endif | ||
|
||
%build | ||
|
||
%install | ||
rm -rf %{buildroot} | ||
./install %{buildroot} | ||
|
||
%clean | ||
rm -rf %{buildroot} | ||
|
||
%files | ||
%defattr(-,root,root,-) | ||
%doc README LICENSE | ||
%{_bindir}/* | ||
%config(noreplace) %{_sysconfdir}/afraid-dyndns.conf | ||
%config(noreplace) %{_sysconfdir}/cron.d/afraid-dyndns | ||
%dir %{_localstatedir}/cache/afraid-dyndns | ||
%ghost %{_localstatedir}/cache/afraid-dyndns/IP | ||
|
||
%changelog | ||
* Sat Oct 03 2009 Erick Calder <rpm@arix.com> - 1.0-5 | ||
- fix to application of patch, which breaks with the error 'missing header for unified diff at line 5 of patch | ||
|
||
* Sat Oct 03 2009 Erick Calder <rpm@arix.com> - 1.0-4 | ||
- fixed broken reference to patch | ||
|
||
* Sat Oct 03 2009 Erick Calder <rpm@arix.com> - 1.0-3 | ||
- added patch to fix issue with Makefile for F10 | ||
|
||
* Sun Sep 27 2009 Erick Calder <rpm@arix.com> - 1.0-2 | ||
- tarball extension changed | ||
|
||
* Sat Sep 12 2009 Erick Calder <rpm@arix.com> - 1.0-1 | ||
- Initial build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
AccountHash = # see README for how to get this value | ||
Notify = root@localhost # leave empty to suppress notifications | ||
CacheFile = /var/cache/afraid-dyndns/IP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*/15 * * * * root /usr/bin/afraid-dyndns --quiet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
DESTDIR=$1 | ||
OS=`uname -s` | ||
|
||
if [ "$OS" = "Darwin" ]; then | ||
install -pm 0755 afraid-dyndns /usr/bin/afraid-dyndns | ||
perl -lne 's|/var/cache/afraid-dyndns/IP|/Library/Caches/afraid-dyndns-IP|; s|root\@localhost||; print;' conf > /etc/afraid-dyndns.conf | ||
touch /Library/Caches/afraid-dyndns-IP | ||
chown root plist | ||
perl -lne 'print; chomp($h = qx/uname -n/), $h =~ s/\.local//, printf("\t\t<string>%s</string>\n", $h) if /--quiet/;' plist > /Library/LaunchDaemons/org.afraid.dyndns.plist | ||
launchctl load /Library/LaunchDaemons/org.afraid.dyndns.plist | ||
else | ||
install -Dpm 0755 afraid-dyndns ${DESTDIR}/usr/bin/afraid-dyndns | ||
install -DCm 0644 cron ${DESTDIR}/etc/cron.d/afraid-dyndns | ||
install -DCm 0644 conf ${DESTDIR}/etc/afraid-dyndns.conf | ||
install -dpm 0755 ${DESTDIR}/var/cache/afraid-dyndns | ||
touch ${DESTDIR}/var/cache/afraid-dyndns/IP | ||
fi | ||
|
||
echo "* Don't forget to configure the AccountHash (see README) *" |
Oops, something went wrong.