Exemplo n.º 1
0
func (p *proxyDomainOperator) Action(ip, domain string) *profile.DomainAction {
	if domain == "i.me" {
		p.p.LogDomain(ip, "init", domain, p.p.serveIP)
		return profile.NewDomainAction(domain, profile.DomainActRedirect, p.p.serveIP)
	}

	if p.p.profileOp != nil {
		if p.p.profileOp.FindByIp(ip) == nil {
			a := p.p.domainOp.Action("localhost", domain)
			if a != nil {
				b := *a
				a = &b
			}

			return a
		}
	}

	if p.p.domainOp != nil {
		act := "query"
		a := p.p.domainOp.Action(ip, domain)
		if a != nil {
			b := *a
			a = &b
		}

		if a != nil && a.Act == profile.DomainActRedirect && a.IP == "" {
			a.IP = p.p.serveIP
			act = "proxy"
		}

		resultIP := ""
		if a != nil && len(a.IP) > 0 {
			resultIP = a.IP
		}

		p.p.LogDomain(ip, act, domain, resultIP)
		return a
	} else {
		p.p.LogDomain(ip, "undef", domain, "")
		return nil
	}
}
Exemplo n.º 2
0
func (p *proxyDomainOperator) Action(ip, domain string) *profile.DomainAction {
	if domain == "i.me" {
		p.p.LogDomain(ip, ip, "init", domain, p.p.serveIP)
		return profile.NewDomainAction(domain, profile.DomainActNone, p.p.serveIP)
	}

	profIP := ip
	if p.p.profileOp != nil {
		if p.p.profileOp.FindByIp(ip) == nil {
			profIP = "localhost"
		}
	}

	if p.p.domainOp != nil {
		act := "query"
		a := p.p.domainOp.Action(profIP, domain)
		if a != nil {
			b := *a
			a = &b
		}

		if a != nil {
			if a.Act == profile.DomainActProxy {
				a.IP = p.p.serveIP
				act = "proxy"
			} else if a.Act == profile.DomainActBlock {
				act = "block"
			}
		}

		resultIP := ""
		if a != nil && len(a.IP) > 0 {
			resultIP = a.IP
		}

		p.p.LogDomain(profIP, ip, act, domain, resultIP)
		return a
	} else {
		p.p.LogDomain(profIP, ip, "undef", domain, "")
		return nil
	}
}