summaryrefslogtreecommitdiff
path: root/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/log/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'att script/4(v6 DDoS)/code/辅助权威服务器/plugin/log/setup.go')
-rw-r--r--att script/4(v6 DDoS)/code/辅助权威服务器/plugin/log/setup.go101
1 files changed, 101 insertions, 0 deletions
diff --git a/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/log/setup.go b/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/log/setup.go
new file mode 100644
index 0000000..49a9fde
--- /dev/null
+++ b/att script/4(v6 DDoS)/code/辅助权威服务器/plugin/log/setup.go
@@ -0,0 +1,101 @@
+package log
+
+import (
+ "ohmydns2/core/dnsserver"
+ "ohmydns2/plugin"
+ "ohmydns2/plugin/pkg/replacer"
+ "ohmydns2/plugin/pkg/response"
+ "strings"
+
+ "github.com/coredns/caddy"
+ "github.com/miekg/dns"
+)
+
+func init() { plugin.Register("log", setup) }
+
+func setup(c *caddy.Controller) error {
+ rules, err := logParse(c)
+ if err != nil {
+ return plugin.Error("log", err)
+ }
+
+ dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
+ return Logger{Next: next, Rules: rules, repl: replacer.New()}
+ })
+
+ return nil
+}
+
+func logParse(c *caddy.Controller) ([]Rule, error) {
+ var rules []Rule
+
+ for c.Next() {
+ args := c.RemainingArgs()
+ length := len(rules)
+
+ switch len(args) {
+ case 0:
+ // Nothing specified; use defaults
+ rules = append(rules, Rule{
+ NameScope: ".",
+ Format: DefaultLogFormat,
+ Class: make(map[response.Class]struct{}),
+ })
+ case 1:
+ rules = append(rules, Rule{
+ NameScope: dns.Fqdn(args[0]),
+ Format: DefaultLogFormat,
+ Class: make(map[response.Class]struct{}),
+ })
+ default:
+ // Name scopes, and maybe a format specified
+ format := DefaultLogFormat
+
+ if strings.Contains(args[len(args)-1], "{") {
+ format = args[len(args)-1]
+ format = strings.Replace(format, "{common}", CommonLogFormat, -1)
+ format = strings.Replace(format, "{combined}", CombinedLogFormat, -1)
+ args = args[:len(args)-1]
+ }
+
+ for _, str := range args {
+ rules = append(rules, Rule{
+ NameScope: dns.Fqdn(str),
+ Format: format,
+ Class: make(map[response.Class]struct{}),
+ })
+ }
+ }
+
+ // Class refinements in an extra block.
+ classes := make(map[response.Class]struct{})
+ for c.NextBlock() {
+ switch c.Val() {
+ // class followed by combinations of all, denial, error and success.
+ case "class":
+ classesArgs := c.RemainingArgs()
+ if len(classesArgs) == 0 {
+ return nil, c.ArgErr()
+ }
+ for _, c := range classesArgs {
+ cls, err := response.ClassFromString(c)
+ if err != nil {
+ return nil, err
+ }
+ classes[cls] = struct{}{}
+ }
+ default:
+ return nil, c.ArgErr()
+ }
+ }
+ if len(classes) == 0 {
+ classes[response.All] = struct{}{}
+ }
+
+ for i := len(rules) - 1; i >= length; i-- {
+ rules[i].Class = classes
+ }
+ }
+
+ return rules, nil
+}