Skip to content

Commit

Permalink
Merge branch 'development' into 'master'
Browse files Browse the repository at this point in the history
Development

See merge request ddns-clients/pyGoDaddyAUpdater!2
  • Loading branch information
Javinator9889 committed Mar 31, 2019
2 parents 05aff13 + 94121f1 commit 7622df1
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/Javinator9889.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions LICENSE
Expand Up @@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

pyGoDaddyAUpdater
pyCloudFlareUpdater
Copyright (C) 2019 Javinator9889

This program is free software: you can redistribute it and/or modify
Expand All @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

pyGoDaddyAUpdater Copyright (C) 2019 Javinator9889
pyCloudFlareUpdater Copyright (C) 2019 Javinator9889
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
56 changes: 32 additions & 24 deletions README.md
@@ -1,11 +1,11 @@
# GoDaddy 'A' Record Updater
# CloudFlare 'A' Record Updater

*DDNS Service for updating dynamically your GoDaddy 'A' Records when your public IP changes*
*DDNS Service for updating dynamically your CloudFlare 'A' Records when your public IP changes*

[![PyPi](https://img.shields.io/badge/v1.1%20-PyPi-green.svg)](https://pypi.org/project/pyGoDaddyUpdater/)
[![ZIP](https://img.shields.io/badge/Package%20-Zip-green.svg)](https://gitlab.javinator9889.com/Javinator9889/pyGoDaddyAUpdater/repository/master/archive.zip)
[![GIT](https://img.shields.io/badge/Package%20-Git-green.svg)](https://gitlab.javinator9889.com/Javinator9889/pyGoDaddyAUpdater.git)
[![Downloads](https://pepy.tech/badge/pygodaddyupdater)](https://pepy.tech/project/pygodaddyupdater)
[![PyPi](https://img.shields.io/badge/v1.0%20-PyPi-green.svg)](https://pypi.org/project/pyCloudFlareUpdater/)
[![ZIP](https://img.shields.io/badge/Package%20-Zip-green.svg)](https://gitlab.javinator9889.com/ddns-clients/pyCloudFlareUpdater/repository/master/archive.zip)
[![GIT](https://img.shields.io/badge/Package%20-Git-green.svg)](https://gitlab.javinator9889.com/ddns-clients/pyCloudFlareUpdater.git)
[![Downloads](https://pepy.tech/badge/pycloudflareupdater)](https://pepy.tech/project/pycloudflareupdater)

## Index

Expand All @@ -18,7 +18,11 @@

### Purpose

If you are a *GoDaddy* user (you have your own domain, CNAMES, etc.) maybe you have noticed that there is no **Dynamic
As a continuation of the [recently created pyGoDaddyUpdater](https://gitlab.javinator9889.com/ddns-clients/pyGoDaddyAUpdater),
here you have *CloudFlare Updater*. This group aims to create *DDNS* OpenSource clients that are available for every
user/sysadmin with the most common DNS providers.

If you are a *CloudFlare* user (you have your own domain, CNAMES, etc.) maybe you have noticed that there is no **Dynamic
DNS** (*DDNS*) update service, so you have to manually put your **public IP** at your domain 'A' Record whenever it
changes.

Expand All @@ -39,7 +43,7 @@ There are two possibilities for installing this script:
Start by *cloning* this repository. For that, you will need to have
[Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed. Then, run on Git Bash:
```text
git clone https://gitlab.javinator9889.com/Javinator9889/pyGoDaddyAUpdater.git
git clone https://gitlab.javinator9889.com/ddns-clients/pyCloudFlareUpdater.git
```

There is another possibility so you can *directly download* a compressed file with all the necessary data. Just unzip
Expand All @@ -48,56 +52,59 @@ There are two possibilities for installing this script:
For installing, you will need **administrator** permissions, as the script is creating a new command so you can run
it from everywhere:
```text
cd pyGoDaddyAUpdater
cd pyCloudFlareUpdater
sudo python3 setup.py install
```

#### 2. Using *pip* (easier and faster)

I assume you have [**pip** installed](https://www.makeuseof.com/tag/install-pip-for-python/), so for using this package:
```text
sudo pip install pyGoDaddyUpdater
sudo pip install pyCloudFlareUpdater
# If you have any error saying that at least Python 3 is needed
# try with the following one:
sudo pip3 install pyGoDaddyUpdater
sudo pip3 install pyCloudFlareUpdater
```

### Usage

First of all, you need to create a [**GoDaddy Developer Account**](https://developer.godaddy.com/getstarted),
and obtaining your *key* and *secret*. The pair you need to create are the **Production** ones, which are hosted at
https://api.godaddy.com (https://api.ote-godaddy.com is not supported).
First of all, go to your *Cloudflare user account* options, and find the section (usually at the bottom of the page)
that says **API Keys**.

Obtain the *Global API Key* and save it on a safe location, we will use it later.

You can obtain the necessary data here: https://developer.godaddy.com/keys (use the name you want).
![API Keys](api_keys.png)

---------

Once you have installed the script, the execution is simple (from your command line):
```text
$ godaddy_ddns [OPTIONS]
$ cloudflare_ddns [OPTIONS]
```

The available options are:

+ `--domain DOMAIN`: specifies **which domain** will be updated. That is, if your site is hosted at www.example.com, then your
domain is *example.com*.

+ `--name NAME`: here the 'A' Record name must be included. In most cases, this name usually is `@` (the name pointing to
the host).
+ `--name NAME`: here the 'A' Record name must be included. In most cases, this name usually matches the domain.

+ `--time TIME`: change the *update check interval* time (in minutes). By default, it is 5 minutes.

+ `--key KEY`: the *GoDaddy Developer key* you obtained as explained before.
+ `--key KEY`: the *Cloudflare key* you obtained as explained before.

+ `--mail MAIL`: the *Cloudflare mail* you use to login into your account.

+ `--secret SECRET`: the *GoDaddy Developer secret* you obtained as explained before.
+ `--proxied`: use this option for making all the requests to your website **access first** Cloudflare servers (the
same as enabling this option ![Cloudflare proxy](cloud.png)).

+ `--no_daemonize`: include this option for running this script **only once**.

+ `--pid PID FILE`: define your own PID file, in which the running daemon PID will be saved. By default, it is:
`/var/run/pygoddady.pid`.
`/var/run/cloudflare.pid`.

+ `--log LOG FILE`: define your own LOG file, in which the running daemon logs will be saved. By default, it is:
`/var/log/pygoddady.log`.
`/var/log/cloudflare.log`.

+ `--preferences PREFERENCES FILE`: if you are planning to dynamically update **more than one** domain at the same
time, you can define a custom preferences file (if not, each time you run the daemon it will be overwritten).
Expand All @@ -112,15 +119,16 @@ The first time you execute this script (or for defining a new preferences file),
+ Domain.
+ Name.
+ Key.
+ Secret.
+ Mail.
+ Proxied.

Then, each time you execute the script with no *extra arguments* or *providing the preferences file* you will not need
to include the options mentioned above.

### License

```text
pyGoDaddyAUpdater
pyCloudFlareUpdater
Copyright (C) 2019 - Javinator9889
This program is free software: you can redistribute it and/or modify
Expand Down
Binary file added api_keys.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cloud.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,4 +1,4 @@
# pyGoDaddyAUpdater
# pyCloudFlareUpdater
# Copyright (C) 2019 - Javinator9889
#
# This program is free software: you can redistribute it and/or modify
Expand Down
66 changes: 42 additions & 24 deletions pyGoDaddyUpdater/__main__.py → pyCloudFlareUpdater/__main__.py
@@ -1,4 +1,4 @@
# pyGoDaddyAUpdater
# pyCloudFlareUpdater
# Copyright (C) 2019 - Javinator9889
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import traceback
from argparse import ArgumentParser
from argparse import SUPPRESS
from logging import getLogger
Expand All @@ -24,7 +25,7 @@

from .logging_utils import LoggingHandler
from .logging_utils import setup_logging
from .network import GoDaddy
from .network import CloudFlare
from .network import get_machine_public_ip
from .preferences import UserPreferences
from .values import description
Expand All @@ -33,21 +34,25 @@


def main():
log = LoggingHandler(logs=[getLogger("cloudflareLogger")])
loop_continuation = True
log = LoggingHandler(logs=[getLogger("appLogger")])
net = GoDaddy(preferences.get_domain(), preferences.get_name(), preferences.get_key(), preferences.get_secret())
try:
net = CloudFlare(domain=preferences.get_domain(),
name=preferences.get_name(),
key=preferences.get_key(),
mail=preferences.get_mail(),
proxied=preferences.is_record_behind_proxy())
while loop_continuation:
current_ip = get_machine_public_ip()
log.info("Current machine IP: \"{0}\"".format(current_ip))
if preferences.get_latest_ip() == "0.0.0.0":
preferences.set_latest_ip(net.get_godaddy_latest_ip())
log.warning("User saved latest IP is not up to date - downloading GoDaddy A Record value: \"{0}\""
preferences.set_latest_ip(net.get_cloudflare_latest_ip())
log.warning("User saved latest IP is not up to date - downloading CloudFlare A Record value: \"{0}\""
.format(preferences.get_latest_ip()))
if preferences.get_latest_ip() != current_ip:
log.info("IP needs an upgrade - OLD IP: {0} | NEW IP: {1}"
.format(preferences.get_latest_ip(), current_ip))
result = net.set_goddady_ip(current_ip)
result = net.set_cloudflare_ip(current_ip)
log.info("IP updated correctly! - Operation return code: {0}".format(result))
log.debug("Updating saved IP...")
preferences.set_latest_ip(current_ip)
Expand All @@ -63,8 +68,12 @@ def main():
sleep(preferences.get_time())
except KeyboardInterrupt:
log.warning("Received SIGINT - exiting...")
except Exception as e:
log.error("Exception registered! - " + str(e))
log.error("Stacktrace: " + traceback.format_exc())
finally:
preferences.save_preferences()
exit(1)
exit(0)


def parser():
Expand All @@ -74,24 +83,30 @@ def parser():
args.add_argument("--domain",
type=str,
required=is_first_execution,
help="GoDaddy domain to be updated.")
help="CloudFlare domain to be updated.")
args.add_argument("--name",
type=str,
required=is_first_execution,
help="GoDaddy 'A' Record name.")
help="CloudFlare 'A' Record name.")
args.add_argument("--time",
type=int,
default=SUPPRESS,
required=is_first_execution,
required=False,
help="Time (in minutes) to check for updated IP (defaults: 5 min.) - must be higher than 0.")
args.add_argument("--key",
type=str,
required=is_first_execution,
help="GoDaddy developer key.")
args.add_argument("--secret",
help="CloudFlare API key.")
args.add_argument("--mail",
type=str,
required=is_first_execution,
help="GoDaddy developer secret.")
help="CloudFlare sign-in mail.")
args.add_argument("--proxied",
action="store_true",
required=is_first_execution,
default=False,
help="Set this value if you want your 'A' Record to be behind the Cloudflare proxy "
"(disabled by default).")
args.add_argument("--no_daemonize",
action="store_true",
required=False,
Expand All @@ -112,7 +127,7 @@ def parser():
help="Specifies a custom LOG file for storing current daemon logs.")
args.add_argument("--preferences",
type=str,
default="user.preferences",
default="cloudflare.user.preferences",
required=False,
metavar="PREFERENCES FILE",
help="Provide a custom preferences file - useful for multiple running daemon for different 'A'"
Expand Down Expand Up @@ -146,8 +161,8 @@ def parser():
if p_args.key:
preferences.set_key(p_args.key)
should_save_preferences = True
if p_args.secret:
preferences.set_secret(p_args.secret)
if p_args.mail:
preferences.set_mail(p_args.mail)
should_save_preferences = True
if p_args.no_daemonize:
preferences.run_as_daemon(not p_args.no_daemonize)
Expand All @@ -156,36 +171,39 @@ def parser():
should_save_preferences = True
else:
if preferences.get_pid_file() is None:
preferences.set_pid_file("/var/run/pygoddady.pid")
preferences.set_pid_file("/var/run/cloudflare.pid")
if "log" in p_args:
preferences.set_log_file(p_args.log)
should_save_preferences = True
else:
if preferences.get_log_file() is None:
preferences.set_log_file("/var/log/pygoddady.log")
preferences.set_log_file("/var/log/cloudflare.log")
user = p_args.user
group = p_args.group

if preferences:
if not (p_args.domain and p_args.name and p_args.key and p_args.secret):
if p_args.preferences:
if not (p_args.domain and p_args.name and p_args.key and p_args.mail):
print("You must provide the required params for a new preferences file")
if should_save_preferences:
preferences.save_preferences(p_args.preferences)
if not is_first_execution:
preferences.load_preferences()
file_handler = setup_logging("appLogger", preferences.get_log_file())
if preferences.is_record_behind_proxy() != p_args.proxied:
preferences.record_behind_proxy(p_args.proxied)
preferences.save_preferences()
file_handler = setup_logging("cloudflareLogger", preferences.get_log_file())
fds = [file_handler.stream.fileno()]
pid_dir = path.dirname(path.abspath(preferences.get_pid_file()))
if not path.exists(pid_dir):
makedirs(path=pid_dir, exist_ok=True)

daemon = Daemonize(app="pyGoDaddyDaemon",
daemon = Daemonize(app="pyCloudFlareDaemon",
pid=preferences.get_pid_file(),
action=main,
keep_fds=fds,
user=user,
group=group,
logger=getLogger("appLogger"))
logger=getLogger("cloudflareLogger"))
daemon.start()


Expand Down
@@ -1,4 +1,4 @@
# pyGoDaddyAUpdater
# pyCloudFlareUpdater
# Copyright (C) 2019 - Javinator9889
#
# This program is free software: you can redistribute it and/or modify
Expand Down
@@ -1,4 +1,4 @@
# pyGoDaddyAUpdater
# pyCloudFlareUpdater
# Copyright (C) 2019 - Javinator9889
#
# This program is free software: you can redistribute it and/or modify
Expand Down
@@ -1,4 +1,4 @@
# pyGoDaddyAUpdater
# pyCloudFlareUpdater
# Copyright (C) 2019 - Javinator9889
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -13,5 +13,5 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ..network.network_utils import GoDaddy
from ..network.network_utils import CloudFlare
from ..network.network_utils import get_machine_public_ip

0 comments on commit 7622df1

Please sign in to comment.