Metadata-Version: 2.1
Name: domains-api
Version: 0.1.4.5
Summary: Auto-updates your dynamic dns rules on Google Domains (domains.google.com)
Home-page: https://github.com/nihilok/domains-api
Author: Michael Jarvis
Author-email: mjfullstack@gmail.com
License: UNKNOWN
Description: # Google Domains API Client
        To facilitate running a home web server behind a router without a static IP, this package checks to see if external IP has changed and updates dynamic DNS rules on Google Domains, via the API; also notifies user by email if required.
        
        ### Installation (Python 3.6+):
        `pip install domains-api`
        
        ### Usage:
        Can be run from the command line like so:
        
        `python -m domains_api`
        
        or imported into your projects in the normal way*:
        ```
        >>>from domains_api import IPChanger
        >>>ipchanger = IPChanger()
        >>>ipchanger.user.domain
        example.com
        ```
        
        Windows/Mac or Linux, it will ask for your credentials on first run and then shouldn't need any input after that. I added command line options/arguments (see `python domains_api --help`) for loading/deleting a profile and changing credentials/settings more easily.
        
        You will need your Dynamic DNS autogenerated username and password as described in [this documentation.](https://support.google.com/domains/answer/6147083?hl=en-CA) For more info on how to set up Dynamic DNS and the process I went through writing this script check [this blog post.](https://mjfullstack.medium.com/running-a-home-web-server-without-a-static-ip-using-google-domains-python-saves-the-day-246570b26d88)
        
        If you choose to receive email notifications, you will be asked to input your gmail email address and password which will then be encoded before being saved as part of a User instance. (The notification is sent from the user's own email address via the gmail smtp server, you will need to allow less secure apps on your Google account to use.).
        
        On **Windows** you can use Task Scheduler; on **Linux/Mac**, add a line to your crontab and you can choose the frequency of the checks. An example hourly cron job would look like this:
        
        `0 * * * * python3 -m domains_api >> ~/cron.log 2>&1`
        
        If reducing downtime is essential, you could increase the frequency of checks to every 5 minutes, or even less, like this:
        
        `*/5 * * * * ...etc`
        
        On Google Domains the default TTL for Dynamic DNS is 1 min, but unless you expect your external IP to change very frequently, more regular cron jobs might be a slight waste of resources; even so, the script is very light weight and usually only takes just over a second to run normally on a Rasberry Pi 3 Ubuntu server.
        
        Check `~/cron.log` if the script does not run as expected, or to see when the IP was last checked.
        
        The logs are written to both `/.domains/.domains.log` in package directory (posix) or `%LOCALAPPDATA%/.domains/.domains.log` (win), and stdout, so that they also appear in the terminal (&/ cron log).
        
        After initial setup, the script takes care of everything: if your IP has changed since you last ran it, it will update your Dynamic DNS rule on domains.google.com.
        
        If you forget your IP or need to check it for any reason, running:
        
        `python -m domains_api -i` 
        
        ...will log your current external IP to the terminal without doing anything else.
        
        Other options include:
        
            domains-api help manual (command line options):
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            You will need your autogenerated Dynamic DNS keys from
            https://domains.google.com/registrar/example.com/dns
            to create a user profile.
        
            python -m domains_api                    || -run the script normally without arguments
            python -m domains_api -h --help          || -show this help manual
            python -m domains_api -i --ip            || -show current external IP address
            python -m domains_api -c --credentials   || -change API credentials
            python -m domains_api -e --email         || -email set up wizard > use to delete email credentials (choose 'n')
            python -m domains_api -n --notifications || -toggle email notification settings > will not delete email address
            python -m domains_api -d --delete_user   || -delete current user profile**
            python -m domains_api -u user.file       || (or "--user_load path/to/user.file") -load user from pickle file**
                                                     || **these options will remove any current user profile without warning!
                                                     || **Backup "./.domains.user" file to store multiple profiles.
        
        ### Example in Django/Apache2 application:
        
        In your Django virtual environment (recommended):
        
        `pip install domains-api APScheduler==3.6.3`
        
        Then, in your project you can create a new module called ipChanger in your project's root directory, with an empty `__init__.py` file and an `ip_changer.py` file.
        
        `ip_changer.py` should look something like this:
        
        ```
        from apscheduler.schedulers.background import BackgroundScheduler
        from domains_api import IPChanger
        
        
        def start():
            scheduler = BackgroundScheduler()
            scheduler.add_job(IPChanger, 'interval', minutes=10)
            scheduler.start()
        ```
        
        Careful not to call `IPChanger` within the `add_job()` method (no parentheses).
        
        Then you will need to add the following to your main app's `apps.py` file:
        
        ```
        class MainConfig(AppConfig):
            name = 'main'
        
            def ready(self):
                from ipChanger import ip_changer
                ip_changer.start()
        ```
        Before you fire up / restart your server you will need to run the script as sudo, so that the the appropriate permissions can be set to enable the web server user (www-data) to create/update the log and user configuration files (in `<venv path>/site-packages/domains-api/`). You might need to specify the virtual environment's python path or sudo will use the root-owned one (`sudo venv/bin/python -m domains_api`). You will then be asked to input your credentials as above. After this process is complete, you can restart your web server. Check `cat /var/log/apache2/error.log` and `<venv path>/site-packages/domains-api/domains-api.log` to see everything is working as expected.
        
        An alternative method is to do the following on the appropriate directory/files (as above):
        
        ```
        sudo chown -R :www-data /path/to/venv/lib/python3.8/site-packages/domains_api/.domains
        sudo chmod -R g+rw /path/to/venv/lib/python3.8/site-packages/domains_api/.domains
        ```
        
        This will set the permissions to read and write for Apache2.
        
        Change Log
        ==========
        
        0.1 - 0.1.2 (03/01/2020)
        ------------------------
        - First Release
        - Code review from:
        https://codereview.stackexchange.com/questions/254272/dynamic-dns-ip-checker-changer-for-google-domains-in-python
        
        0.1.3 - .1.3.6 (04/01/2020)
        -------------------------
        - Updated GitHub url and long description / readme.
        - Added option to show ip (only) from command line (domains_api -i --ip).
        - Added test function to master branch: simulate change in ip (commented in __main__.py)
        - Minor bugfixes
        
        0.1.4 - .1.4.1 (05/01/2020)
        ----------------
        - Fixed PermissionError when working with Apache2 & Django (must run script first as www-data e.g: "sudo -u www-data /venv/bin/python -m domains_api" - this will allow the apache server to be the owner of the log/user files when they are set up with least hassle. Missing this set the server will fail with an EOF error, as input is needed to initialize the first User instance. - bear in mind that running the script as a different user in the same environment will fail unless you change permissions on the log/user file located in the package directory)
        - Fixed absolute paths in `User.load_user()` and `User().save_user()` functions.
        - Updated README with Django/Apache2 example.
        
        0.1.4.2 (06/01/2020)
        ---------------------
        - Added email outbox for offline messages
        
        0.1.4.3 - .1.4.4 (07/01/2020)
        ---------------------
        - Refactored all file/log handling methods into file_handlers.FileHandlers
        - Fixed permissions issues (better than before) - run package with sudo the first time to initialize files.
        - Changed posix directory for logs and user files to `domains_api/.domains/`
        - `save_user`/`load_user` and `delete_user` methods are now part of the FileHandlers class.
        
        0.1.4.5 (08/01/2020)
        --------------------
        - Fixed relative import
        
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Description-Content-Type: text/markdown
