Skip to content
Snippets Groups Projects
Commit 3e927f3b authored by root's avatar root
Browse files

Fixed Dockerfile

parent b37ff59b
No related branches found
No related tags found
No related merge requests found
FROM centos:7
COPY i42/ /i42
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm \
&& yum install -y python36u python36u-devel python36u-pip \
&& pip3.6 install yacron \
&& pip3.6 install -r /i42/requirements.txt
CMD ["yacron", "-c", "i42/yacron.yaml"]
[DEFAULT]
;Your prefix
prefix = <change_me>
domain = i42.hu
ip_version = 4
;Token for accessing the resource
token = <change_me>
validate = 0
[SERVER]
v4 = https://updaterv4.i42.hu:10053
v6 = https://updaterv6.i42.hu:10053
[LOGGING]
path = "i42.log"
level = DEBUG
[IP]
;IP Addresses to update to. If not set, the source IP of the request will be used.
refresh_to_ipv4 =
refresh_to_ipv6 =
import argparse
class Args:
@staticmethod
def get_args():
parser = argparse.ArgumentParser(description="Updates your domain records on i42.hu.")
parser.add_argument("-4", "--ipv4_only", action="store_true", help="Use only IPv4")
parser.add_argument("-6", "--ipv6_only", action="store_true", help="Use only IPv6")
parser.add_argument("-p", "--prefix", action="store", help="Prefix to update")
parser.add_argument("-l", "--log-file", action="store", help="Path to the log file")
parser.add_argument("-t","--token",action="store", help="Authentication token")
parser.add_argument("-v", "--validate", action="store_true", help="Validate the configuration")
parser.add_argument("-c", "--configuration", action="store", help="Path to the config file. Default: config.ini", dest="config")
args = parser.parse_args()
return args
import configparser
import logging
class Config:
@staticmethod
def get_configuration(args):
# Get configuration
config = configparser.ConfigParser()
# Get config file
if args.config is not None:
config.read(args.config)
else:
config.read('config.ini')
# Arguments have higher precedence, if not set, config will decide
if args.ipv4_only is True:
config['DEFAULT']['ip_version'] = 4
if args.ipv6_only is True:
config['DEFAULT']['ip_version'] = 6
if args.prefix is not None:
config['DEFAULT']['prefix'] = args.prefix
if args.log_file is not None:
config['LOGGING']['path'] = args.log_file
if args.token is not None:
config['DEFAULT']['token'] = args.token
return config
@staticmethod
def check_configuration(config):
if int(config['DEFAULT']['ip_version']) != 4 and int(config['DEFAULT']['ip_version']) !=6:
raise ValueError("IP version to refresh must be either 4 or 6 Current is: " + str(config['DEFAULT']['ip_version']))
if config['DEFAULT'].get('prefix', "") == "":
raise ValueError("Prefix to update must not be empty!")
if config['DEFAULT'].get('token', "") == "":
raise ValueError("Token must be set!")
if config['SERVER'].get('v4', "") == "" and config['SERVER'].get('v6', "") == "":
raise ValueError("IPv4 and IPv6 server must be set!")
requests
#! /usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import argparse
import logging
import sys
from modules.args import Args
from modules.config import Config
import configparser
import base64
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()
jobs:
- name: "Update i42"
command: /i42/update_i42_domain.py
schedule:
minute: "*/5"
dayOfMonth: "*"
month: "*"
year: "*"
dayOfWeek: "*"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment