App-DDFlare
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
script/ddflare view on Meta::CPAN
$ ddflare path_to_config
The following flags are accepted
--version Verssion info
-?|--help Usage info
-v|--verbose Verbose output
-o|--output=file Append output to file
-e|--error=file Append error to file
=head1 CONFIG
The configuration file is YAML in the following structure
--- # Credentials
user: cloudflare-user
key: cloudflare-api-key
--- # Updates dom.com and sub1.dom1.com
zone: dom.com
domains:
-
- sub1
--- # Updates sub1.dom2.com and sub2.dom2.com
zone: dom2.com
domains:
- sub1
- sub2
=head1 FUNCTIONS
=cut
GetOptions(\my %OPTS,
'verbose|v',
'output|o=s',
'error|e=s');
Readonly my $VERBOSE => $OPTS{verbose};
Readonly my $O_FILE => $OPTS{output};
Readonly my $E_FILE => $OPTS{error};
# Redirect output if needed
open STDOUT, '>>', $O_FILE
or die "Couldn't open $O_FILE for output"
if defined $O_FILE;
open STDERR, '>>', $E_FILE
or die "Couldn't open $E_FILE for output"
if defined $E_FILE;
die "Invalid arguments"
unless @ARGV == 1;
Readonly my $CONFIG_FILE => shift;
=head2 loadConfig
Loads in the configuration file, which is YAML, the structure
is an array of hashrefs.
The first element being { user => ..., key => ... } which are
CloudFlare credentials.
Subsequent elements are { zone => ..., domains => [ ... ] } which are
cloudflare zones, and the subdomains within them to update. An
undefined value in domains represents the zone itself.
loadConfig($PATH_TO_CONFIG);
=cut
sub loadConfig {
say "Loading config from $CONFIG_FILE" if $VERBOSE;
LoadFile($CONFIG_FILE);
}
# Get cloudflare settings and zone info
my @conf = loadConfig();
# How long to wait before updates, seconds
Readonly my $UPDATE_INTERVAL => 300;
Readonly my $updater => Net::DNS::CloudFlare::DDNS->new(
user => $conf[0]{user},
apikey => $conf[0]{key},
zones => [ @conf[1 .. $#conf] ],
verbose => $VERBOSE
);
# We are a daemon
while(1) {
$updater->update;
say "Going to sleep for $UPDATE_INTERVAL seconds" if $VERBOSE;
# Don't check too often!
sleep $UPDATE_INTERVAL;
}
=head1 AUTHOR
Peter Roberts, C<< <me+ddflare at peter-r.co.uk> >>
=head1 COPYRIGHT/LICENSE
Copyright (c) 2014 Peter Roberts
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.466 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )