unknown 7 vuotta sitten
vanhempi
commit
a84a5790a6

BIN
pkg/windows_amd64/apiservice/config.a


BIN
pkg/windows_amd64/apiservice/oamanager.a


BIN
pkg/windows_amd64/apiservice/tools.a


+ 0 - 37
src/apiservice/config/config.go

@@ -2,47 +2,10 @@ package config
 
 import (
 	"qfw/util"
-	elastic "qfw/util/elastic"
-	"regexp"
-	"strings"
-	"time"
-
-	"github.com/go-xweb/xweb"
 )
 
-type Config struct {
-	*xweb.Action
-	article xweb.Mapper `xweb:"/article/(.*).html"`
-}
-
 var Sysconfig map[string]interface{}
-var regex = regexp.MustCompile("(Android|Mobile)")
 
 func init() {
-	xweb.AddAction(&Config{})
 	util.ReadConfig(&Sysconfig)
 }
-
-func (c *Config) Article(id string) {
-	bm := false
-	client := c.Header("User-Agent")
-	bm = regex.MatchString(client)
-	//解密id
-	sid_openid := util.DecodeArticleId2ByCheck(id)[0]
-	//sid_openid = "596c129d5d11e1c74547e6ff"
-	//查询数据
-	data := *elastic.GetByIdField("bidding", "bidding", sid_openid, `"detail","title","projectname","publishtime"`)
-	timeF := data["publishtime"].(float64)
-	time := time.Unix(int64(timeF), 0).Format("2006-01-02 15:04")
-	detail := strings.Replace(util.ObjToString(data["detail"]), " ", "", -1)
-	c.T["time"] = time
-	c.T["title"] = data["title"]
-	c.T["detail"] = detail
-	c.T["projectname"] = data["projectname"]
-	//返回页面
-	if bm { //手机访问
-		c.Render("/app/app.html", &c.T)
-	} else { //pc端访问
-		c.Render("/pc/pc.html", &c.T)
-	}
-}

+ 147 - 0
src/apiservice/oamanager/content.go

@@ -0,0 +1,147 @@
+package oamanager
+
+import (
+	"net"
+	"qfw/util"
+	elastic "qfw/util/elastic"
+	"regexp"
+	"strings"
+	"sync"
+	"time"
+
+	"github.com/go-xweb/xweb"
+)
+
+type Content struct {
+	*xweb.Action
+	article xweb.Mapper `xweb:"/article/(.*).html"`
+}
+
+var regex = regexp.MustCompile("(Android|Mobile)")
+
+//对map的同步
+var lock sync.Mutex
+
+func init() {
+	xweb.AddAction(&Content{})
+}
+func (c *Content) Article(id string) {
+	bm := false
+	client := c.Header("User-Agent")
+	c.Request.Proto = GetIp(c)
+	addLog(c)
+	bm = regex.MatchString(client)
+	//解密id
+	sid_openid := util.DecodeArticleId2ByCheck(id)[0]
+	//sid_openid = "596c129d5d11e1c74547e6ff"
+	//查询数据
+	data := *elastic.GetByIdField("bidding", "bidding", sid_openid, `"detail","title","projectname","publishtime"`)
+	timeF := data["publishtime"].(float64)
+	time := time.Unix(int64(timeF), 0).Format("2006-01-02 15:04")
+	detail := strings.Replace(util.ObjToString(data["detail"]), " ", "", -1)
+	c.T["time"] = time
+	c.T["title"] = data["title"]
+	c.T["detail"] = detail
+	c.T["projectname"] = data["projectname"]
+	//返回页面
+	if bm { //手机访问
+		c.Render("/app/app.html", &c.T)
+	} else { //pc端访问
+		c.Render("/pc/pc.html", &c.T)
+	}
+}
+
+func addLog(c *Content) {
+	req := c.Request
+	timeNow := time.Now()
+	agent := req.Header.Get("user-agent")
+	ref := req.Referer()
+	s_url := req.RequestURI
+	date := timeNow.Unix()
+	logs := map[string]interface{}{
+		"l_date":    date,
+		"s_ip":      req.Proto,
+		"s_refer":   ref,
+		"i_year":    timeNow.Year(),
+		"i_month":   timeNow.Month(),
+		"i_day":     timeNow.Day(),
+		"i_hour":    timeNow.Hour(),
+		"i_minutes": timeNow.Minute(),
+		//"s_describe": req.Form,
+		"s_client": agent,
+		"s_os":     GetOS(agent),
+		"s_browse": GetBrowse(agent),
+		"s_method": req.Method,
+		"s_url":    s_url,
+	}
+	lock.Lock()
+	mongodb.SaveBulk("log", logs)
+	lock.Unlock()
+}
+
+//获取平台类型
+func GetOS(useros string) string {
+	osVersion := "其他"
+	if strings.Contains(useros, "NT 6.0") {
+		osVersion = "Windows Vista/Server 2008"
+	} else if strings.Contains(useros, "NT 5.2") {
+		osVersion = "Windows Server 2003"
+	} else if strings.Contains(useros, "NT 5.1") {
+		osVersion = "Windows XP"
+	} else if strings.Contains(useros, "NT 5") {
+		osVersion = "Windows 2000"
+	} else if strings.Contains(useros, "Mac") {
+		osVersion = "Mac"
+	} else if strings.Contains(useros, "Unix") {
+		osVersion = "UNIX"
+	} else if strings.Contains(useros, "Linux") {
+		osVersion = "Linux"
+	} else if strings.Contains(useros, "SunOS") {
+		osVersion = "SunOS"
+	} else if strings.Contains(useros, "NT 6.3") {
+		osVersion = "Window8"
+	} else if strings.Contains(useros, "NT 6.1") {
+		osVersion = "Window7"
+	} else if strings.Contains(useros, "NT 10.0") {
+		osVersion = "Window10"
+	}
+	return osVersion
+}
+
+//获取浏览器类型
+func GetBrowse(userbrowser string) string {
+	browserVersion := "其他"
+	if strings.Contains(userbrowser, "MSIE") {
+		browserVersion = "IE"
+	} else if strings.Contains(userbrowser, "Firefox") {
+		browserVersion = "Firefox"
+	} else if strings.Contains(userbrowser, "Chrome") {
+		browserVersion = "Chrome"
+	} else if strings.Contains(userbrowser, "Safari") {
+		browserVersion = "Safari"
+	} else if strings.Contains(userbrowser, "rv:11.0") {
+		browserVersion = "IE11"
+	}
+
+	return browserVersion
+}
+
+//获取请求ip
+func GetIp(c *Content) string {
+	req := c.Request
+	ip_for := req.Header.Get("x-forwarded-for")
+	ip_client := req.Header.Get("http_client_ip")
+	ip_addr := req.Header.Get("Remote_addr")
+	un := "unknown"
+	if (ip_for != un) && (len(strings.TrimSpace(ip_for)) > 0) {
+		return ip_for
+	}
+	if (ip_client != un) && (len(strings.TrimSpace(ip_client)) > 0) {
+		return ip_client
+	}
+	if (ip_addr != un) && (len(strings.TrimSpace(ip_addr)) > 0) {
+		return ip_addr
+	}
+	ip, _, _ := net.SplitHostPort(req.RemoteAddr)
+	return ip
+}

+ 1 - 1
src/web/templates/pc/pc.html

@@ -25,7 +25,7 @@
 						<div class="title">
 							<h3>{{.T.title}}</h3>
 							<div class="sub-title">
-								<a href="#">jianyu360.com&nbsp;&nbsp;&gt;</a>
+								<a href="https://www.jianyu360.com/">jianyu360.com&nbsp;&nbsp;&gt;</a>
 								<span class="date">{{.T.time}}</span>
 							</div>
 						</div>