Exemple #1
0
func (p *Proxy) Command(commands string, f *profile.Profile, v *life.Life) {
	commandLines := strings.Split(commands, "\n")
	for _, line := range commandLines {
		line = strings.TrimSpace(line)
		if len(line) <= 0 || line[0] == '#' {
			continue
		}

		c, rest := cmd.TakeFirstArg(line)
		switch c {
		case "restart":
			if v != nil {
				v.Restart()
			}
		case "clear":
			f.Clear()
		case "delay":
			f.CommandDelay(rest)
		case "proxy":
			f.CommandProxy(rest)
		case "delete":
			f.CommandDelete(rest)
		case "domain":
			f.CommandDomain(rest)
		case "url":
			f.CommandUrl(rest)
		default:
			if ip, domain, ok := parseIPDomain(c, rest); ok {
				f.CommandDomain("redirect " + domain + " " + ip)
				break
			}
		}
	}
}
Exemple #2
0
func (p *Proxy) writeHistory(w http.ResponseWriter, profileIP string, f *life.Life) {
	t, err := template.ParseFiles("template/history.tmpl")
	list := formatHistoryEventDataList(f.HistoryEvents(), profileIP, f)
	err = t.Execute(w, historyData{profileIP, list})
	if err != nil {
		fmt.Fprintln(w, "内部错误:", err)
	}
}
Exemple #3
0
func formatHistoryEventDataList(events []*life.HistoryEvent, client string, f *life.Life) []historyEventData {
	list := make([]historyEventData, 0, len(events))
	even := true
	for _, e := range events {
		d := historyEventData{}
		d.OPs = make([]opData, 0)
		d.Client = client

		even = !even
		d.Even = even
		d.Time = e.Time.Format("2006-01-02 15:04:05")

		s := strings.Split(e.String, " ")
		if len(s) >= 3 && s[0] == "domain" {
			domain := s[2]
			d.Domain = "域名 " + s[1] + " " + domain
			d.OPs = append(d.OPs, opData{"代理域名", "domain/redirect", domain, client})
			if len(s) >= 4 {
				d.DomainIP = s[3]
			}
		} else if len(s) >= 3 && s[0] == "proxy" {
			url := s[1]
			d.URL = url
			if len(s) >= 4 {
				d.URL += " " + s[3]
			}

			d.URLID = s[2]
			if id, err := strconv.ParseInt(d.URLID, 10, 32); err == nil {
				h := f.LookHistoryByID(uint32(id))
				if h != nil {
					status := h.Method
					if h.ResponseCode >= 0 {
						status += " " + strconv.Itoa(h.ResponseCode)
					} else {
						status += " 出错"
					}

					d.HttpStatus = status
				}
			}

			if strings.HasPrefix(url, "http://") {
				d.URLBody = url[7:]
			} else {
				d.URLBody = url
			}

			d.OPs = append(d.OPs, opData{"缓存", "url/store", d.URLID, client})
		} else {
			d.EventString = e.String
		}

		list = append(list, d)
	}

	return list
}
Exemple #4
0
func (p *Proxy) saveContentToCache(fullUrl string, f *life.Life, c *cache.UrlCache, needCache bool) {
	id := f.SaveContentToCache(c, needCache)

	info := "proxy " + fullUrl + " " + strconv.FormatUint(uint64(id), 10)
	if len(c.RangeInfo) > 0 {
		info += " " + c.RangeInfo
	}

	f.Log(info)
}
Exemple #5
0
func (p *Proxy) writeDNSHistory(w http.ResponseWriter, f *life.Life, targetIP string) {
	t, err := template.ParseFiles("template/dnshistory.tmpl")
	list := formatDNSHistoryEventDataList(f.HistoryEvents(), f, targetIP)
	targetInfo := ""
	if len(targetIP) == 0 {
		targetInfo = "DNS 服务"
	} else {
		targetInfo = targetIP + " DNS"
	}

	err = t.Execute(w, dnsHistoryData{targetInfo, list})
	if err != nil {
		fmt.Fprintln(w, "内部错误:", err)
	}
}