Select Git revision
update_i42_domain.py
Forked from an inaccessible project.
update_i42_domain.py 2.09 KiB
#! /usr/bin/python3
import requests
import logging
from modules.args import Args
from modules.config import Config
class Data:
def __init__(self, prefix, token, ip_address, validate=0):
self.prefix = prefix
self.token = token
self.ip_address = ip_address
self.validate = validate
class App:
def __init__(self):
self.args = Args.get_args()
def set_logger(self, logfile, level):
log_format = "%(levelname)s: %(message)s"
try:
if args.log_file is not None:
log_file = args.log_file
except NameError:
LOG_FILE = ""
logging.basicConfig(filename=LOG_FILE, level=level, format=log_format)
def send_data(self, data, host):
response = requests.post(host, data.__dict__, timeout=30)
if response.status_code != 200:
logging.warn(response.text)
def update(self):
#Get configuration
config = Config.get_configuration(self.args)
# Set up logging
self.set_logger(config['LOGGING']['path'], config['LOGGING']['level'])
# Validate configuration
Config.check_configuration(config)
# Get variables
logging.info("Setting prefix to: " + config['DEFAULT']['prefix'])
logging.info("Setting token to: " + (config['DEFAULT']['token']))
logging.info("Updating IPv4 to: " + config['IP']['refresh_to_ipv4'])
logging.info("Updating IPv6 to: " + config['IP']['refresh_to_ipv6'])
prefix = config['DEFAULT']['prefix']
token = config['DEFAULT']['token']
if config['IP'].get('refresh_to_ipv4') is not None:
data = Data(prefix, token, config['IP'].get('refresh_to_ipv4'), config['DEFAULT'].get('validate', 0))
self.send_data(data, config['SERVER']['v4'])
if config['IP'].get('refresh_to_ipv6') is not None:
data = Data(prefix, token, config['IP'].get('refresh_to_ipv6'), config['DEFAULT'].get('validate', 0))
self.send_data(data, config['SERVER']['v6'])
if __name__=="__main__":
app = App()
app.update()