aidns

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

README

AIDNS

简体中文

A lightweight DNS server that provides HTTP management interface, based on CoreDNS

For learning and research purposes only

Characteristics

  • Based on CoreDNS development
  • Data stored in MySQL
  • Provide concise HttpApi ( Authentication can be configured )

TODO

  • Add read-through cache processing solution
  • Add web management page

AIDNS config

aidns {
    dsn DSN
    [table_prefix TABLE_PREFIX]
    [max_lifetime MAX_LIFETIME]
    [max_open_connections MAX_OPEN_CONNECTIONS]
    [max_idle_connections MAX_IDLE_CONNECTIONS]
    [ttl DEFAULT_TTL]
    [zone_update_interval ZONE_UPDATE_INTERVAL]
    [zone_update_interval ZONE_UPDATE_INTERVAL]
    [http_token HTTP_TOKEN]
    [http_addr HTTP_ADDR]
    [redis_url REDIS_URL]
}
  • dsn DSN for MySQL as per https://github.com/go-sql-driver/mysql#dsn-data-source-name examples. You can use $ENV_NAME format in the DSN, and it will be replaced with the environment variable value.
  • table_prefix Prefix for the MySQL tables. Defaults to aidns_.
  • max_lifetime Duration (in Golang format) for a SQL connection. Default is 1 minute.
  • max_open_connections Maximum number of open connections to the database server. Default is 10.
  • max_idle_connections Maximum number of idle connections in the database connection pool. Default is 10.
  • ttl Default TTL for records without a specified TTL in seconds. Default is 360 (seconds)
  • zone_update_interval Maximum time interval between loading all the zones from the database. Default is 10 minutes.
  • http_token Http Api Server authorization token. Default is empty, is no authorization.
  • http_addr Http Api Server Addr. Default is :8888.
  • redis_url URL for Redis as per https://github.com/redis/go-redis#connecting-via-a-redis-url examples. Default is empty, not cache.
  • redis_ttl Redis cache time. Default is 10 minutes.
CoreDNS full config example
.:53 {
    log
    health {
       lameduck 15s
    }
    ready
    aidns {
        dsn root:123456@(localhost:3306)/dev?charset=utf8mb4&parseTime=True&loc=Local
        http_token aidns
        http_addr :8888
        redis_url redis://:123456@localhost:30603/0?dial_timeout=3&read_timeout=6s&max_retries=2
        redis_ttl 10m
    }
    loop
    reload
    loadbalance
}

Supported Record Types

A, AAAA, CNAME, SOA, TXT, NS, MX, CAA and SRV. Wildcard records are supported as well. This backend doesn't support AXFR requests.

Build

$ make

Database Setup

This plugin doesn't create or migrate database schema for its use yet. To create the database and tables, use the following table structure (note the table name prefix):

CREATE TABLE `aidns_records`
(
    `id`          INT          NOT NULL AUTO_INCREMENT,
    `zone`        VARCHAR(255) NOT NULL,
    `name`        VARCHAR(255) NOT NULL,
    `ttl`         INT DEFAULT NULL,
    `content`     TEXT,
    `record_type` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = INNODB
  AUTO_INCREMENT = 6
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci;

Management Records API

API document

Acknowledgements and Credits

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AAAARecord

type AAAARecord struct {
	Ip net.IP `json:"ip"`
}

type ARecord

type ARecord struct {
	Ip net.IP `json:"ip"`
}

type AiDNS added in v0.2.0

type AiDNS struct {
	Next               plugin.Handler
	Dsn                string
	TablePrefix        string
	MaxLifetime        time.Duration
	MaxOpenConnections int
	MaxIdleConnections int
	Ttl                uint32
	HttpToken          string
	HttpAddr           string
	RedisURL           string
	RedisTTL           time.Duration
	// contains filtered or unexported fields
}

func (*AiDNS) Name added in v0.2.0

func (handler *AiDNS) Name() string

Name implements the Handler interface.

func (*AiDNS) ServeDNS added in v0.2.0

func (handler *AiDNS) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

func (*AiDNS) Server added in v0.2.0

func (handler *AiDNS) Server() (err error)

type CAARecord

type CAARecord struct {
	Flag  uint8  `json:"flag"`
	Tag   string `json:"tag"`
	Value string `json:"value"`
}

type CNAMERecord

type CNAMERecord struct {
	Host string `json:"host"`
}

type Locker added in v0.2.0

type Locker struct {
	// contains filtered or unexported fields
}

func NewLocker added in v0.2.0

func NewLocker(ctx context.Context, ad AiDNS, client *redis.Client) *Locker

func (Locker) Get added in v0.2.0

func (s Locker) Get(key string, v any, getFunc func() (any, error)) error

func (Locker) GetCache added in v0.2.0

func (s Locker) GetCache(key string, v any, getFunc func() (any, error)) error

type MXRecord

type MXRecord struct {
	Host       string `json:"host"`
	Preference uint16 `json:"preference"`
}

type NSRecord

type NSRecord struct {
	Host string `json:"host"`
}

type Record

type Record struct {
	Zone       string `json:"zone"`
	Name       string `json:"name"`
	RecordType string `json:"record_type"`
	Ttl        uint32 `json:"ttl"`
	Content    string `json:"content"`
	// contains filtered or unexported fields
}

func (*Record) AsAAAARecord

func (rec *Record) AsAAAARecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsARecord

func (rec *Record) AsARecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsCAARecord

func (rec *Record) AsCAARecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsCNAMERecord

func (rec *Record) AsCNAMERecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsMXRecord

func (rec *Record) AsMXRecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsNSRecord

func (rec *Record) AsNSRecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsSOARecord

func (rec *Record) AsSOARecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsSRVRecord

func (rec *Record) AsSRVRecord() (record dns.RR, extras []dns.RR, err error)

func (*Record) AsTXTRecord

func (rec *Record) AsTXTRecord() (record dns.RR, extras []dns.RR, err error)

type RecordApi

type RecordApi struct {
	ID         uint32 `json:"id"`
	Zone       string `json:"zone" binding:"required"`
	Name       string `json:"name" binding:"required"`
	RecordType string `json:"record_type" binding:"required"`
	Ttl        uint32 `json:"ttl" binding:"required"`
	Content    string `json:"content" binding:"required"`
}

type RecordDelete

type RecordDelete struct {
	ID   uint32 `json:"id" binding:"required"`
	Zone string `json:"zone" binding:"required"`
}

type SOARecord

type SOARecord struct {
	Ns      string `json:"ns"`
	MBox    string `json:"MBox"`
	Refresh uint32 `json:"refresh"`
	Retry   uint32 `json:"retry"`
	Expire  uint32 `json:"expire"`
	MinTtl  uint32 `json:"minttl"`
}

type SRVRecord

type SRVRecord struct {
	Priority uint16 `json:"priority"`
	Weight   uint16 `json:"weight"`
	Port     uint16 `json:"port"`
	Target   string `json:"target"`
}

type TXTRecord

type TXTRecord struct {
	Text string `json:"text"`
}

Jump to

Keyboard shortcuts

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