Beispiel #1
0
func secondaryParse(c *Controller) (file.Zones, error) {
	z := make(map[string]*file.Zone)
	names := []string{}
	for c.Next() {
		if c.Val() == "secondary" {
			// secondary [origin]
			origins := c.ServerBlockHosts
			args := c.RemainingArgs()
			if len(args) > 0 {
				origins = args
			}
			for i, _ := range origins {
				origins[i] = middleware.Host(origins[i]).Normalize()
				z[origins[i]] = file.NewZone(origins[i], "stdin")
				names = append(names, origins[i])
			}

			for c.NextBlock() {
				t, f, e := transferParse(c)
				if e != nil {
					return file.Zones{}, e
				}
				for _, origin := range origins {
					if t != nil {
						z[origin].TransferTo = append(z[origin].TransferTo, t...)
					}
					if f != nil {
						z[origin].TransferFrom = append(z[origin].TransferFrom, f...)
					}
				}
			}
		}
	}
	return file.Zones{Z: z, Names: names}, nil
}
Beispiel #2
0
func dnssecParse(c *Controller) ([]string, []*dnssec.DNSKEY, error) {
	zones := []string{}

	keys := []*dnssec.DNSKEY{}
	for c.Next() {
		if c.Val() == "dnssec" {
			// dnssec [zones...]
			zones = c.ServerBlockHosts
			args := c.RemainingArgs()
			if len(args) > 0 {
				zones = args
			}

			for c.NextBlock() {
				k, e := keyParse(c)
				if e != nil {
					return nil, nil, e
				}
				keys = append(keys, k...)
			}
		}
	}
	for i, _ := range zones {
		zones[i] = middleware.Host(zones[i]).Normalize()
	}
	return zones, keys, nil
}
Beispiel #3
0
func cacheParse(c *Controller) (int, []string, error) {
	var (
		err error
		ttl int
	)

	for c.Next() {
		if c.Val() == "cache" {
			// cache [ttl] [zones..]
			origins := c.ServerBlockHosts
			args := c.RemainingArgs()
			if len(args) > 0 {
				origins = args
				// first args may be just a number, then it is the ttl, if not it is a zone
				t := origins[0]
				ttl, err = strconv.Atoi(t)
				if err == nil {
					origins = origins[1:]
					if len(origins) == 0 {
						// There was *only* the ttl, revert back to server block
						origins = c.ServerBlockHosts
					}
				}
			}

			for i, _ := range origins {
				origins[i] = middleware.Host(origins[i]).Normalize()
			}
			return ttl, origins, nil
		}
	}
	return 0, nil, nil
}
Beispiel #4
0
func fileParse(c *Controller) (file.Zones, error) {
	z := make(map[string]*file.Zone)
	names := []string{}
	for c.Next() {
		if c.Val() == "file" {
			// file db.file [zones...]
			if !c.NextArg() {
				return file.Zones{}, c.ArgErr()
			}
			fileName := c.Val()

			origins := c.ServerBlockHosts
			args := c.RemainingArgs()
			if len(args) > 0 {
				origins = args
			}

			reader, err := os.Open(fileName)
			if err != nil {
				// bail out
				return file.Zones{}, err
			}

			for i, _ := range origins {
				origins[i] = middleware.Host(origins[i]).Normalize()
				zone, err := file.Parse(reader, origins[i], fileName)
				if err == nil {
					z[origins[i]] = zone
				} else {
					return file.Zones{}, err
				}
				names = append(names, origins[i])
			}

			noReload := false
			for c.NextBlock() {
				t, _, e := transferParse(c)
				if e != nil {
					return file.Zones{}, e
				}
				switch c.Val() {
				case "no_reload":
					noReload = true
				}
				// discard from, here, maybe check and show log when we do?
				for _, origin := range origins {
					if t != nil {
						z[origin].TransferTo = append(z[origin].TransferTo, t...)
					}
					z[origin].NoReload = noReload
				}
			}
		}
	}
	return file.Zones{Z: z, Names: names}, nil
}
Beispiel #5
0
func parsePrometheus(c *Controller) (metrics.Metrics, error) {
	var (
		met metrics.Metrics
		err error
	)

	for c.Next() {
		if len(met.ZoneNames) > 0 {
			return metrics.Metrics{}, c.Err("metrics: can only have one metrics module per server")
		}
		met = metrics.Metrics{ZoneNames: c.ServerBlockHosts}
		for i, _ := range met.ZoneNames {
			met.ZoneNames[i] = middleware.Host(met.ZoneNames[i]).Normalize()
		}
		args := c.RemainingArgs()

		switch len(args) {
		case 0:
		case 1:
			met.Addr = args[0]
		default:
			return metrics.Metrics{}, c.ArgErr()
		}
		for c.NextBlock() {
			switch c.Val() {
			case "address":
				args = c.RemainingArgs()
				if len(args) != 1 {
					return metrics.Metrics{}, c.ArgErr()
				}
				met.Addr = args[0]
			default:
				return metrics.Metrics{}, c.Errf("metrics: unknown item: %s", c.Val())
			}

		}
	}
	if met.Addr == "" {
		met.Addr = addr
	}
	return met, err
}