czm

package module
v0.0.0-...-102946d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

README

Cloudflare Zone Manager

This is a Docker image that uses Cloudflare Zone Management to effectively works as a DDNS on top of Cloudflare.

Run on Docker

docker pull golinux/cloudflare-zone-manager

Enviroment Variables
export CONFIG_MAP_PATH=path/to/config/map.yaml
export CONFIG_MOD_PATH=../modules # Default path to built-in modules
Config map

This is a config example for CZM to identify your zones and configurations

cloudflare:
    email: "your@example.com"
    api_key: "YourCloudflareAPIKey"
zones:
    -   id: "0000000000000000000"
        hostname: "example.com"
        dns:
            -   name: "subdomain.example.com"
                dtype: "A"
                proxied: false
                ttl: 120
                rules:
                    not-exist: "create"
                    update: "always"
                module:
                    name: "external-ip"
                    metadata:
                        -   key: "route"
                            data: "eno1"
            -   name: "anothersubdomain.example.comk"
                dtype: "A" 
                content: "10.0.0.1"
                proxied: false
                ttl: 120
                rules:
                    not-exist: "create"
                    update: "always"
Rules

Existent rules are:

  • not-exist with keys "create" | "skip"
  • update with "always" | "never"

Update its for when CZM found a diff over DNS on Cloudflare and Config Map

Modules

Modules its a tools to create DNSRecord content procedurally

Included modules

  • external-ip - This module fetch your external ip to create DDNS Service
How to create a Module

For your module can be compatible they need some things

  • Main function named as Resolve(args interface{})
  • a export named Plugin as type of your module name

Example: modulename.go

package main

type modulename string

func (e modulename) Resolve(args interface{}) (string) {
	return "192.168.0.1"
}

var Plugin modulename

How to build: go build -buildmode=plugin -o modulename.so -o modulename.go

Contributing

Feel free to fork this project and send pull request or open a issue.

Thanks!

Documentation

Index

Constants

View Source
const (
	RULES_NEXISTS_TAG    = "NOTEXIST"
	RULES_NEXISTS_CREATE = "create"
	RULES_NEXISTS_SKIP   = "skip"

	RULES_UPDATE_TAG    = "UPDATE"
	RULES_UPDATE_ALWAYS = "always"
	RULES_UPDATE_NEVER  = "never"
)

Variables

View Source
var (
	CONFIG_MAP_PATH = os.Getenv("CONFIG_MAP_PATH")
	CONFIG_MOD_PATH = os.Getenv("CONFIG_MOD_PATH")
)

Functions

This section is empty.

Types

type Cloudflare

type Cloudflare struct {
	Email    string `yaml:"email"`
	APIKey   string `yaml:"api_key"`
	SLog     *slog.Instance
	Api      *cfgo.API
	UserInfo cfgo.User
}

func (*Cloudflare) CreateDNSRecord

func (cf *Cloudflare) CreateDNSRecord(zone *Zone, dns *Dns) error

func (*Cloudflare) DNSRecordHasDiff

func (cf *Cloudflare) DNSRecordHasDiff(zone *Zone, dns *Dns) bool

func (*Cloudflare) ExistsDNSRecord

func (cf *Cloudflare) ExistsDNSRecord(zone *Zone, dns *Dns) bool

func (*Cloudflare) ExistsZone

func (cf *Cloudflare) ExistsZone(zone *Zone) bool

func (*Cloudflare) Initialize

func (cf *Cloudflare) Initialize() *Cloudflare

func (*Cloudflare) LoadDNSRecords

func (cf *Cloudflare) LoadDNSRecords(zone *Zone)

func (*Cloudflare) UpdateDNSRecord

func (cf *Cloudflare) UpdateDNSRecord(zone *Zone, dns *Dns) error

type CloudflareZoneManager

type CloudflareZoneManager struct {
	ConfigMap ConfigMap
	SLog      *slog.Instance
	Srv       struct {
		CF       *Cloudflare
		Reporter string
		Mods     Modules
	}
}

func (*CloudflareZoneManager) Init

func (e *CloudflareZoneManager) Init()

func (*CloudflareZoneManager) InitServices

func (e *CloudflareZoneManager) InitServices()

func (*CloudflareZoneManager) VerifyAndUpdateZones

func (e *CloudflareZoneManager) VerifyAndUpdateZones()

type ConfigMap

type ConfigMap struct {
	Cloudflare Cloudflare `yaml:"cloudflare"`
	Zones      []Zone     `yaml:"zones"`
}

func (*ConfigMap) ReadConfigMap

func (cMap *ConfigMap) ReadConfigMap()

type DNSMetadata

type DNSMetadata struct {
	Key  string `yaml:"key"`
	Data string `yaml:"data"`
}

type Dns

type Dns struct {
	ID      string
	Name    string `yaml:"name"`
	Dtype   string `yaml:"dtype"`
	Content string `yaml:"content"`
	Proxied bool   `yaml:"proxied"`
	Rules   Rules  `yaml:"rules"`
	TTL     int    `yaml:"ttl"`
	Module  Module `yaml:"module"`
}

type Module

type Module struct {
	Name     string        `yaml:"name"`
	Metadata []DNSMetadata `yaml:"metadata"`
	Mods     *Modules
}

func (*Module) Resolve

func (m *Module) Resolve() string

type ModuleLoad

type ModuleLoad struct {
	Name   string
	Plugin *plugin.Plugin
}

type Modules

type Modules struct {
	Loaded []*ModuleLoad
	SLog   *slog.Instance
}

func (*Modules) LoadAllModules

func (m *Modules) LoadAllModules()

type Plugin

type Plugin interface {
	Resolve(interface{}) string
}

type Rules

type Rules struct {
	NotExist string `yaml:"not-exist"` // create | skip
	Update   string `yaml:"update"`    // always | if-different | never
}

func (*Rules) VerifyRule

func (r *Rules) VerifyRule(tag string) bool

type Zone

type Zone struct {
	Id         string `yaml:"id"`
	Hostname   string `yaml:"hostname"`
	Dns        []Dns  `yaml:"dns"`
	DNSRecords []cfgo.DNSRecord
}

Directories

Path Synopsis
modules

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL